function [mystruct_out]=ecmwf_load_fluxes(ycur,hcur); %loads the fields and does the interpolation to the 1x1 ECCO grid domaine_global_def; mask=squeeze(tmask3D(:,:,1)); if ycur<2002 rep_in='/net/altix3700/raid4/king/data_1x1_92-03/forcing_ECMWF/'; files_ecmwf=strvcat('ERA40g_ustr_r1_','ERA40g_vstr_r1_','ERA40g_emp_r1_','ERA40g_turbflux_r1_','ERA40g_sw_r1_'); var_ecco=strvcat('ustress','vstress','emp','turbflux','swflux'); else rep_in='/net/altix3700/raid4/king/data_1x1_92-03/forcing_ECMWF/'; files_ecmwf=strvcat('EAG_ustr_r1_','EAG_vstr_r1_','EAG_emp_r1_','EAG_turbflux_r1_','EAG_sw_r1_'); var_ecco=strvcat('ustress','vstress','emp','turbflux','swflux'); end ecmwf_grid; jpig=length(x); jpjg=length(y); lon2D_g=x'*ones(1,jpjg); lat2D_g=ones(jpig,1)*y; mask_g=ones(jpig,jpjg); recl=jpig*jpjg*4; [x1,y1] = meshgrid([lon2D_g(end,1)-360 lon2D_g(:,1)' lon2D_g(1:2,1)'+360],lat2D_g(1,:)); [x2,y2] = meshgrid(lon2D_t(:,1),lat2D_t(1,:)); for fcur=1:size(files_ecmwf,1) fid=fopen([rep_in deblank(files_ecmwf(fcur,:)) num2str(ycur)],'r','b'); recl=jpig*jpjg*4; position0=recl*(hcur-1); status=fseek(fid,position0,'bof'); field_mod=fread(fid,[jpig jpjg],'float32'); fclose(fid); %field_mod=fread(fid,jpig*jpjg*4,'float32'); fclose(fid); field_mod=squeeze(mean(reshape(field_mod,[jpig jpjg 4]),3)); %there are a few NaNs in the files: fix it here by extrapolation tmp1=find(isnan(field_mod)); while ~isempty(tmp1); tmp2=field_mod; tmp2(tmp1)=0; tmp3=1*(~isnan(field_mod)); tmp2=tmp2+circshift(tmp2,[0 1])+circshift(tmp2,[0 -1])+circshift(tmp2,[-1 0])+circshift(tmp2,[1 0]); tmp3=tmp3+circshift(tmp3,[0 1])+circshift(tmp3,[0 -1])+circshift(tmp3,[-1 0])+circshift(tmp3,[1 0]); tmp1=find(isnan(field_mod)&tmp3>0); field_mod(tmp1)=tmp2(tmp1)./tmp3(tmp1); tmp1=find(isnan(field_mod)); end tmp1=[field_mod(end,:);field_mod;field_mod(1,:);field_mod(2,:)]'; field_int=interp2(x1,y1,tmp1,x2,y2)'; eval([deblank(var_ecco(fcur,:)) '=field_int.*mask;']); end rhoConstFresh=999.8; emp=emp*rhoConstFresh; %m/s->kg/m^2/s ustress=-ustress.*mask; vstress=-vstress.*mask; turbflux=turbflux.*mask; emp=emp.*mask; swflux=swflux.*mask; mystruct_out=struct('ustress',ustress,'vstress',vstress,'emp',emp,'turbflux',turbflux,'swflux',swflux);