%%Selecet the datasets in the first 5 days of each month, 120 is the count
%%number

uwind_jan_5days = ncread('era5_2009_intrp_c.nc','Uwind',[1 1 1],[1602 1202 480]);
uwind_feb_5days = ncread('era5_2009_intrp_c.nc','Uwind',[1 1 745],[1602 1202 480]);
uwind_mar_5days = ncread('era5_2009_intrp_c.nc','Uwind',[1 1 1416],[1602 1202 480]);
uwind_apr_5days = ncread('era5_2009_intrp_c.nc','Uwind',[1 1 2160],[1602 1202 480]);
uwind_may_5days = ncread('era5_2009_intrp_c.nc','Uwind',[1 1 2880],[1602 1202 480]);
uwind_jun_5days = ncread('era5_2009_intrp_c.nc','Uwind',[1 1 3625],[1602 1202 480]);
uwind_jul_5days = ncread('era5_2009_intrp_c.nc','Uwind',[1 1 4345],[1602 1202 480]);
uwind_aug_5days = ncread('era5_2009_intrp_c.nc','Uwind',[1 1 5090],[1602 1202 480]);
uwind_sep_5days = ncread('era5_2009_intrp_c.nc','Uwind',[1 1 5835],[1602 1202 480]);
uwind_oct_5days = ncread('era5_2009_intrp_c.nc','Uwind',[1 1 6555],[1602 1202 480]);
uwind_nov_5days = ncread('era5_2009_intrp_c.nc','Uwind',[1 1 7299],[1602 1202 480]);
uwind_dec_5days = ncread('era5_2009_intrp_c.nc','Uwind',[1 1 8019],[1602 1202 480]);

%%Do the same for the vwind
vwind_jan_5days = ncread('era5_2009_intrp_c.nc','Vwind',[1 1 1],[1602 1202 480]);
vwind_feb_5days = ncread('era5_2009_intrp_c.nc','Vwind',[1 1 745],[1602 1202 480]);
vwind_mar_5days = ncread('era5_2009_intrp_c.nc','Vwind',[1 1 1416],[1602 1202 360]);
vwind_apr_5days = ncread('era5_2009_intrp_c.nc','Vwind',[1 1 2161],[1602 1202 360]);
vwind_may_5days = ncread('era5_2009_intrp_c.nc','Vwind',[1 1 2881],[1602 1202 360]);
vwind_jun_5days = ncread('era5_2009_intrp_c.nc','Vwind',[1 1 3625],[1602 1202 360]);
vwind_jul_5days = ncread('era5_2009_intrp_c.nc','Vwind',[1 1 4345],[1602 1202 360]);
vwind_aug_5days = ncread('era5_2009_intrp_c.nc','Vwind',[1 1 5090],[1602 1202 360]);
vwind_sep_5days = ncread('era5_2009_intrp_c.nc','Vwind',[1 1 5835],[1602 1202 360]);
vwind_oct_5days = ncread('era5_2009_intrp_c.nc','Vwind',[1 1 6555],[1602 1202 360]);
vwind_nov_5days = ncread('era5_2009_intrp_c.nc','Vwind',[1 1 7299],[1602 1202 360]);
vwind_dec_5days = ncread('era5_2009_intrp_c.nc','Vwind',[1 1 8019],[1602 1202 360]);

uwind_jan_1 = ncread('era5_2009_intrp.nc','Uwind',[1 1 1],[1602 1202 480]);
uwind_feb_1 = ncread('era5_2009_intrp.nc','Uwind',[1 1 745],[1602 1202 360]);
uwind_mar_1 = ncread('era5_2009_intrp.nc','Uwind',[1 1 1416],[1602 1202 360]);
uwind_apr_1 = ncread('era5_2009_intrp.nc','Uwind',[1 1 2161],[1602 1202 360]);
uwind_may_1 = ncread('era5_2009_intrp.nc','Uwind',[1 1 2881],[1602 1202 360]);
uwind_jun_1 = ncread('era5_2009_intrp.nc','Uwind',[1 1 3625],[1602 1202 360]);
uwind_jul_1 = ncread('era5_2009_intrp.nc','Uwind',[1 1 4345],[1602 1202 360]);
uwind_aug_1 = ncread('era5_2009_intrp.nc','Uwind',[1 1 5090],[1602 1202 360]);
uwind_sep_1 = ncread('era5_2009_intrp.nc','Uwind',[1 1 5835],[1602 1202 360]);
uwind_oct_1 = ncread('era5_2009_intrp.nc','Uwind',[1 1 6555],[1602 1202 360]);
uwind_nov_1 = ncread('era5_2009_intrp.nc','Uwind',[1 1 7299],[1602 1202 360]);
uwind_dec_1 = ncread('era5_2009_intrp.nc','Uwind',[1 1 8019],[1602 1202 360]);

%%Do the same for the vwind
vwind_jan_1 = ncread('era5_2009_intrp.nc','Vwind',[1 1 1],[1602 1202 360]);
vwind_feb_1 = ncread('era5_2009_intrp.nc','Vwind',[1 1 745],[1602 1202 360]);
vwind_mar_1 = ncread('era5_2009_intrp.nc','Vwind',[1 1 1416],[1602 1202 360]);
vwind_apr_1 = ncread('era5_2009_intrp.nc','Vwind',[1 1 2161],[1602 1202 360]);
vwind_may_1 = ncread('era5_2009_intrp.nc','Vwind',[1 1 2881],[1602 1202 360]);
vwind_jun_1 = ncread('era5_2009_intrp.nc','Vwind',[1 1 3625],[1602 1202 360]);
vwind_jul_1 = ncread('era5_2009_intrp.nc','Vwind',[1 1 4345],[1602 1202 360]);
vwind_aug_1 = ncread('era5_2009_intrp.nc','Vwind',[1 1 5090],[1602 1202 360]);
vwind_sep_1 = ncread('era5_2009_intrp.nc','Vwind',[1 1 5835],[1602 1202 360]);
vwind_oct_1 = ncread('era5_2009_intrp.nc','Vwind',[1 1 6555],[1602 1202 360]);
vwind_nov_1 = ncread('era5_2009_intrp.nc','Vwind',[1 1 7299],[1602 1202 360]);
vwind_dec_1 = ncread('era5_2009_intrp.nc','Vwind',[1 1 8019],[1602 1202 360]);

%cd /nird/projects/NS9081K/NORSTORE_OSL_DISK/NS9081K/A4_fram/metroms/apps/common/grid
 
angle = ncread('arctic4km_grd.nc','angle');
lon = ncread('era5_2009_intrp_c.nc','lon');

lat = ncread('era5_2009_intrp_c.nc','lat');

[X,Y] = meshgrid(lat,lon);

cd ../../A4_2005-2018_from_APN/A4_forcing/A4_stasj_fra_stallo/A4_stasj/a4_full_domain

uwind_old_jan_5days = ncread('AN_2009_unlim.nc','Uwind',[1 1 1],[1602 1202 60]);
uwind_old_feb_5days = ncread('AN_2009_unlim.nc','Uwind',[1 1 125],[1602 1202 60]);
uwind_old_mar_5days = ncread('AN_2009_unlim.nc','Uwind',[1 1 237],[1602 1202 80]);
uwind_old_apr_5days = ncread('AN_2009_unlim.nc','Uwind',[1 1 361],[1602 1202 20]);
uwind_old_may_5days = ncread('AN_2009_unlim.nc','Uwind',[1 1 481],[1602 1202 80]);
uwind_old_jun_5days = ncread('AN_2009_unlim.nc','Uwind',[1 1 605],[1602 1202 20]);
uwind_old_jul_5days = ncread('AN_2009_unlim.nc','Uwind',[1 1 725],[1602 1202 20]);
uwind_old_aug_5days = ncread('AN_2009_unlim.nc','Uwind',[1 1 849],[1602 1202 80]);
uwind_old_sep_5days = ncread('AN_2009_unlim.nc','Uwind',[1 1 973],[1602 1202 20]);
uwind_old_oct_5days = ncread('AN_2009_unlim.nc','Uwind',[1 1 1093],[1602 1202 20]);
uwind_old_nov_5days = ncread('AN_2009_unlim.nc','Uwind',[1 1 1216],[1602 1202 20]);
uwind_old_dec_5days = ncread('AN_2008_unlim.nc','Uwind',[1 1 1336],[1602 1202 20]);

%uwind_old_nov_5days = ncread('AN_2013-14-15_unlim_P1.nc','Uwind',[1 1 1],[1602 1202 20]);
%uwind_old_dec_5days = ncread('AN_2013-14-15_unlim_P1.nc','Uwind',[1 1 121],[1602 1202 20]);

vwind_old_jan_5days = ncread('AN_2009_unlim.nc','Vwind',[1 1 1],[1602 1202 60]);
vwind_old_feb_5days = ncread('AN_2008_unlim.nc','Vwind',[1 1 125],[1602 1202 60]);
vwind_old_mar_5days = ncread('AN_2008_unlim.nc','Vwind',[1 1 237],[1602 1202 20]);
vwind_old_apr_5days = ncread('AN_2009_unlim.nc','Vwind',[1 1 361],[1602 1202 60]);
vwind_old_may_5days = ncread('AN_2008_unlim.nc','Vwind',[1 1 481],[1602 1202 20]);
vwind_old_jun_5days = ncread('AN_2008_unlim.nc','Vwind',[1 1 605],[1602 1202 20]);
vwind_old_jul_5days = ncread('AN_2008_unlim.nc','Vwind',[1 1 725],[1602 1202 20]);
vwind_old_aug_5days = ncread('AN_2008_unlim.nc','Vwind',[1 1 849],[1602 1202 20]);
vwind_old_sep_5days = ncread('AN_2008_unlim.nc','Vwind',[1 1 973],[1602 1202 20]);
vwind_old_oct_5days = ncread('AN_2008_unlim.nc','Vwind',[1 1 1093],[1602 1202 20]);
vwind_old_nov_5days = ncread('AN_2008_unlim.nc','Vwind',[1 1 1216],[1602 1202 20]);
vwind_old_dec_5days = ncread('AN_2008_unlim.nc','Vwind',[1 1 1336],[1602 1202 20]);

%vwind_old_nov_5days = ncread('AN_2013-14-15_unlim_P1.nc','Vwind',[1 1 1],[1602 1202 20]);
%vwind_old_dec_5days = ncread('AN_2013-14-15_unlim_P1.nc','Vwind',[1 1 121],[1602 1202 20]);

cd 
cd /nird/projects/NS9081K/NORSTORE_OSL_DISK/NS9081K/A4_fram/metroms/apps/common/grid
 
angle = ncread('arctic4km_grd.nc','angle');

uwind_era5_mean = mean(uwind_aug_5days,3);
vwind_era5_mean = mean(vwind_aug_5days,3);
uwind_old_mean = mean(uwind_old_aug_5days,3);
vwind_old_mean = mean(vwind_old_aug_5days,3);
%uwind_era5 = mean(uwind_jan_1,3);
%vwind_era5 = mean(vwind_jan_1,3);

%uwind_era5_mean_c = uwind_era5.*cos(angle) + vwind_era5.*sin(angle);
%vwind_era5_mean_c = vwind_era5.*cos(angle) - uwind_era5.*sin(angle);

figure
%quiver(X(1:100:1602,1:100:1202),Y(1:100:1602,1:100:1202),uwind_era5_mean_c(1:100:1602,1:100:1202),vwind_era5_mean_c(1:100:1602,1:100:1202),'r')
%hold on
quiver(X(1:100:1602,1:100:1202),Y(1:100:1602,1:100:1202),uwind_old_mean(1:100:1602,1:100:1202),vwind_old_mean(1:100:1602,1:100:1202),'b')
hold on
quiver(X(1:100:1602,1:100:1202),Y(1:100:1602,1:100:1202),uwind_era5_mean(1:100:1602,1:100:1202),vwind_era5_mean(1:100:1602,1:100:1202),'black')
