#!/bin/bash

#We found that the direction of the wind at the ERA5_intrp was wrong. The wind vectors from ERA5 do not agree with the one from the old
#atmospheric forcing, used in the old A4 application in METROMS. We need to rotate the wind considering the angle from the 
#/projects/NS9081K/NORSTORE_OSL_DISK/NS9081K/A4_fram/metroms/apps/common/grid/arctic4km_grd.nc

#We are using the following formula:

#u = u_EW*cos(angle) + v_NS*sin(angle)

#v = v_NS*cos(angle) - u_EW*sin(angle)

ncks -A -v angle /projects/NS9081K/NORSTORE_OSL_DISK/NS9081K/A4_fram/metroms/apps/common/grid/arctic4km_grd.nc /cluster/work/users/andriani/metroms_run/arctic-4km/era5_A4_intrp/era5_2009_intrp.nc

ncap2 -A -s 'Uwind=Uwind*cos(angle)+Vwind*sin(angle)' -s 'Vwind=Vwind*cos(angle)-Uwind*sin(angle)' era5_2009_intrp.nc

#cdo -selname,angle -expr,'Uwind=Uwind*cos(angle)+Vwind*sin(angle);Vwind=Vwind*cos(angle)-Uwind*sin(angle)' -merge /projects/NS9081K/NORSTORE_OSL_DISK/NS9081K/A4_fram/era5_A4_intrp/era5_2007_intrp.nc /projects/NS9081K/NORSTORE_OSL_DISK/NS9081K/A4_fram/metroms/apps/common/grid/arctic4km_grd.nc era5_2007_intrp_c.nc

