function [profOut]=MITprof_resample(profIn,fldIn,filOut,method,varargin); %object: resample a set of fields in file filFldIn with specified time % line timeIn to the positions of profIn and add to file filOut %inputs: profIn is a gcmfaces field (nan-masked; up to N3,N4 dimensions) % fldIn is a description of the fields being resampled including % the corresponding file name and additional specs : % fldIn.name, fldIn.long_name, fldIn.units, fldIn.fil (file % name) and fldIn.tim (time axis specification). Supported % fldIn.tim spec: 'const' (for time invariant climatology), % 'monclim' (for monthly climatology), 'monser' (for monthly % time series) % filOut is the output MITprof file name (if un-specified % the resul may only be returned as a function argument) % method may be 'polygons' (or 'TriScatteredInterp' ... via % gcmfaces_interp_2d in a loop ... to be implemented later) %outputs: profOut is the MITprof structure where the interpolated values % were appended to profIn (if un-specified the result % may only be returned to output file) % %filFldIn is assumed to be 3D and binary at this point 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); 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;