function [profOut]=MITprof_resample(profIn,fldIn,filOut,method); % %[profOut]=MITPROF_RESAMPLE(profIn,fldIn,filOut,method); % % resamples a set of fields (fldIn) to profile 3D locations (profIn) % and output the result to nc file (filOut) and memory (profOut). % using a chosen interpolation method (method). % % profIn (structure) should contain: prof_depth, prof_lon, prof_lat, prof_date % fldIn (structure) should contain: fil, name, long_name, units, tim, % missing_value, and FillValue (for nc output). % % fldIn.tim can be set to % 'const' (for time invariant climatology), % 'monclim' (for monthly climatology) % 'monser' (for monthly time series) % 'monloop' (for cyclic monthly time series) % % method can be set to % 'polygons' (linear in space) % 'bindata' (nearest neighbor in space) % %note to self: add case when fldIn is a gcmfaces field; nctiles input % % Example: % grid_load; gcmfaces_global; MITprof_global; addpath matlab/; % profIn=idma_float_plot('4900828'); % % % fldIn.fil=fullfile(myenv.MITprof_climdir,filesep,'T_OWPv1_M_eccollc_90x50.bin'); % fldIn.name='prof_Towp'; % fldIn.long_name='pot. temp. estimate (OCCA-WOA-PHC combination)'; % fldIn.units='degree C'; % fldIn.tim='monclim'; % fldIn.missing_value=-9999.; % fldIn.FillValue=-9999.; % % % profOut=MITprof_resample(profIn,fldIn); gcmfaces_global; doOut=~isempty(who('filOut')); doOutInit=false; if doOut; doOut=~isempty(filOut); end; if doOut; doOutInit=isempty(dir(filOut)); end; if isempty(who('method')); method='polygons'; end; %1) deal with time line if strcmp(fldIn.tim,'monclim'); tim_fld=[-0.5:12.5]; rec_fld=[12 1:12 1]; tmp1=datevec(profIn.prof_date); tmp2=datenum([tmp1(:,1) ones(profIn.np,2) zeros(profIn.np,3)]); tim_prof=(profIn.prof_date-tmp2); tim_prof(tim_prof>365)=365; tim_prof=tim_prof/365*12;%neglecting differences in months length elseif strcmp(fldIn.tim,'monloop'); tmp1=dir(fldIn.fil); nt=tmp1.bytes/prod(mygrid.ioSize)/length(mygrid.RC)/4; tmp1=[1:nt]'; tmp2=ones(nt,1)*[1992 1 15 0 0 0]; tmp2(:,2)=tmp1; tim_fld=datenum(tmp2); tim_fld=[tim_fld(1)-31 tim_fld' tim_fld(end)+31]; rec_fld=[nt 1:nt 1]; tmp1=datenum([1992 1 1 0 0 0]); tmp2=datenum([1992+nt/12 1 1 0 0 0]);; tim_prof=tmp1+mod(profIn.prof_date-tmp1,tmp2-tmp1); %round up tim_prof to prevent interpolation in time: % tmp3=tim_prof*ones(1,length(tim_fld))-ones(length(tim_prof),1)*tim_fld; % tmp4=sum(tmp3>0,2); % tim_prof=tim_fld(tmp4)'; elseif strcmp(fldIn.tim,'const')|strcmp(fldIn.tim,'std'); tim_fld=[1 2]; rec_fld=[1 1]; tim_prof=1.5*ones(profIn.np,1); else; error('this case remains to be implemented'); end; lon=profIn.prof_lon; lat=profIn.prof_lat; depIn=-mygrid.RC; depOut=profIn.prof_depth; profOut=NaN*ones(profIn.np,profIn.nr); %2) loop over record pairs if ~strcmp(method,'bindata'); gcmfaces_bindata; end; for tt=1:length(rec_fld)-1; tt % fld0=mygrid.mskC.*read_bin(fldIn.fil,rec_fld(tt)); fld1=mygrid.mskC.*read_bin(fldIn.fil,rec_fld(tt+1)); ndim=length(size(fld0{1})); fld=cat(ndim+1,fld0,fld1); % ii=find(tim_prof>=tim_fld(tt)&tim_prof0; profOut=setfield(profIn,fldIn.name,profOut); end;