/[MITgcm]/MITgcm_contrib/gael/profilesMatlabProcessing/profiles_misc/MITprof_resample.m
ViewVC logotype

Diff of /MITgcm_contrib/gael/profilesMatlabProcessing/profiles_misc/MITprof_resample.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.5 by gforget, Sun Oct 11 13:37:09 2015 UTC revision 1.7 by gforget, Thu Jan 28 23:18:26 2016 UTC
# Line 1  Line 1 
1  function [profOut]=MITprof_resample(profIn,fldIn,filOut,method,varargin);  function [profOut]=MITprof_resample(profIn,fldIn,filOut,method);
 %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)  
2  %  %
3  %filFldIn is assumed to be 3D and binary at this point  %[profOut]=MITPROF_RESAMPLE(profIn,fldIn,filOut,method);
4    %
5    %     resamples a set of fields (fldIn) to profile 3D locations (profIn)
6    %     and output the result to nc file (filOut) and memory (profOut).
7    %     using a chosen interpolation method (method).
8    %
9    %     profIn (structure) should contain: prof_depth, prof_lon, prof_lat, prof_date
10    %     fldIn (structure) should contain: fil, name, long_name, units, tim,
11    %         missing_value, and FillValue (for nc output).
12    %
13    %     fldIn.tim can be set to
14    %         'const' (for time invariant climatology),
15    %         'monclim' (for monthly climatology)
16    %         'monser' (for monthly time series)
17    %         'monloop' (for cyclic monthly time series)
18    %
19    %     method can be set to
20    %         'polygons' (linear in space)
21    %         'bindata' (nearest neighbor in space)
22    %
23    %note to self: add case when fldIn is a gcmfaces field; nctiles input
24    %
25    % Example:
26    %  grid_load; gcmfaces_global; MITprof_global; addpath matlab/;
27    %  profIn=idma_float_plot('4900828');
28    %  %
29    %  fldIn.fil=fullfile(myenv.MITprof_climdir,filesep,'T_OWPv1_M_eccollc_90x50.bin');
30    %  fldIn.name='prof_Towp';
31    %  fldIn.long_name='pot. temp. estimate (OCCA-WOA-PHC combination)';
32    %  fldIn.units='degree C';
33    %  fldIn.tim='monclim';
34    %  fldIn.missing_value=-9999.;
35    %  fldIn.FillValue=-9999.;
36    %  %
37    %  profOut=MITprof_resample(profIn,fldIn);
38    
39    
40  gcmfaces_global;  gcmfaces_global;
41    
# Line 44  elseif strcmp(fldIn.tim,'monloop'); Line 62  elseif strcmp(fldIn.tim,'monloop');
62      rec_fld=[nt 1:nt 1];      rec_fld=[nt 1:nt 1];
63      tmp1=datenum([1992 1 1 0 0 0]);      tmp1=datenum([1992 1 1 0 0 0]);
64      tmp2=datenum([1992+nt/12 1 1 0 0 0]);;      tmp2=datenum([1992+nt/12 1 1 0 0 0]);;
65      tim_prof=tmp1+mod(profIn.prof_date-tmp1,tmp2);      tim_prof=tmp1+mod(profIn.prof_date-tmp1,tmp2-tmp1);
66        %round up tim_prof to prevent interpolation in time:
67        %  tmp3=tim_prof*ones(1,length(tim_fld))-ones(length(tim_prof),1)*tim_fld;
68        %  tmp4=sum(tmp3>0,2);
69        %  tim_prof=tim_fld(tmp4)';
70  elseif strcmp(fldIn.tim,'const')|strcmp(fldIn.tim,'std');  elseif strcmp(fldIn.tim,'const')|strcmp(fldIn.tim,'std');
71      tim_fld=[1 2]; rec_fld=[1 1];      tim_fld=[1 2]; rec_fld=[1 1];
72      tim_prof=1.5*ones(profIn.np,1);      tim_prof=1.5*ones(profIn.np,1);
# Line 69  for tt=1:length(rec_fld)-1; Line 91  for tt=1:length(rec_fld)-1;
91      ii=find(tim_prof>=tim_fld(tt)&tim_prof<tim_fld(tt+1));      ii=find(tim_prof>=tim_fld(tt)&tim_prof<tim_fld(tt+1));
92      if ~isempty(ii);      if ~isempty(ii);
93        if ~strcmp(method,'bindata');        if ~strcmp(method,'bindata');
94          arr=gcmfaces_interp(fld,lon(ii),lat(ii),method);          arr=gcmfaces_interp_2d(fld,lon(ii),lat(ii),method);
95          arr2=gcmfaces_interp_1d(2,depIn,arr,depOut);          arr2=gcmfaces_interp_1d(2,depIn,arr,depOut);
96          %now linear in time:          %now linear in time:
97          k0=floor(tim_prof(ii)); k1=k0+1;          k0=floor(tim_prof(ii)); k1=k0+1;

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.7

  ViewVC Help
Powered by ViewVC 1.1.22