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

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

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

revision 1.1 by gforget, Mon Nov 8 19:46:01 2010 UTC revision 1.2 by gforget, Thu Jan 27 05:10:42 2011 UTC
# Line 1  Line 1 
1  function [MITprofSub]=MITprof_subset(MITprof,varargin);  function [MITprofSub]=MITprof_subset(MITprof,varargin);
2    % [MITprofSub]=MITprof_subset(MITprof,'PropertyName',PropertyValue,...)
3    %   load a subset of profiles from MITprof into MITprofSub
4    %
5    %   if PropertyName = 'list' : PropertyValue contains the list of profiles
6    %   otherwise PropertyName = 'field' : selection on MITprof.prof_field,
7    %       range or unique value given in PropertyValue.
8    %   if PropertyName = 'list' is used, then it needs to be the first one.
9    %
10    %   [MITprofSub]=MITprof_subset(MITprof,'list',1:50);
11    %       returns the 50th first profiles in MITprof
12  %   [MITprofSub]=MITprof_subset(MITprof,'depth',[50 150]);  %   [MITprofSub]=MITprof_subset(MITprof,'depth',[50 150]);
13  %       returns the subset of MITprof that has prof_depth>=50 and <150  %       returns the subset of MITprof that has prof_depth>=50 and <150
14  %   [MITprofSub]=MITprof_subset(MITprof,'depth',[50 150],'descr',platformName);  %   [MITprofSub]=MITprof_subset(MITprof,'depth',[50 150],'descr',platformName);
# Line 9  fldNames=fieldnames(MITprof); Line 19  fldNames=fieldnames(MITprof);
19    
20  nSub=(nargin-1)/2;  nSub=(nargin-1)/2;
21  for iSub=1:nSub;  for iSub=1:nSub;
22      eval(['prof_sub=MITprof.prof_' varargin{(iSub-1)*2+1} ';']);      if ~strcmp('list',varargin{(iSub-1)*2+1});
23      range_sub=varargin{(iSub-1)*2+2};          eval(['prof_sub=MITprofSub.prof_' varargin{(iSub-1)*2+1} ';']);
24      if strcmp('descr',varargin{(iSub-1)*2+1});          range_sub=varargin{(iSub-1)*2+2};
25          KK=find(strcmp(prof_sub,range_sub));          if strcmp('descr',varargin{(iSub-1)*2+1});
26      elseif strcmp('depth',varargin{(iSub-1)*2+1});              KK=find(strcmp(prof_sub,range_sub));
27          KK=find(prof_sub>=range_sub(1)&prof_sub<range_sub(2));          elseif length(range_sub)==2 & range_sub(1)<range_sub(2);
28                KK=find(prof_sub>=range_sub(1)&prof_sub<range_sub(2));
29            elseif length(range_sub)==1;
30                KK=find(prof_sub==range_sub);
31            else
32                error('MITprof_subset: wrong arguments');
33            end;
34      else;      else;
35          KK=find(prof_sub>=range_sub(1)&prof_sub<range_sub(2));          KK=varargin{(iSub-1)*2+2};
36            prof_sub=[1:MITprofSub.np]';
37            if iSub~=1; error('''list'' subset should come first'); end;
38      end;      end;
39        
40      %  [varargin{(iSub-1)*2+1} ' -- ' num2str(length(KK))]      %  [varargin{(iSub-1)*2+1} ' -- ' num2str(length(KK))]
41      for iFld=1:length(fldNames);      for iFld=1:length(fldNames);
42          eval(['tmp1=MITprofSub.' fldNames{iFld} ';']);          eval(['tmp1=MITprofSub.' fldNames{iFld} ';']);
43          if strcmp('depth',varargin{(iSub-1)*2+1}) & strcmp(fldNames{iFld},'prof_depth');          if strcmp('depth',varargin{(iSub-1)*2+1}) & strcmp(fldNames{iFld},'prof_depth');
44              tmp1=tmp1(KK);              tmp1=tmp1(KK);
45          elseif strcmp('depth',varargin{(iSub-1)*2+1});          elseif strcmp('depth',varargin{(iSub-1)*2+1});
46              if size(tmp1,2)==length(MITprof.prof_depth); tmp1=tmp1(:,KK); end;              if size(tmp1,2)==length(MITprofSub.prof_depth); tmp1=tmp1(:,KK); end;
47          else;          else;
48              if size(tmp1,1)==size(prof_sub,1); tmp1=tmp1(KK,:); end;              if size(tmp1,1)==size(prof_sub,1); tmp1=tmp1(KK,:); end;
49          end;          end;
50          eval(['MITprofSub.' fldNames{iFld} '=tmp1;']);          eval(['MITprofSub.' fldNames{iFld} '=tmp1;']);
51      end;      end;
52            
53        %add a couple things:
54        %--------------------
55        MITprofSub.np=length(MITprofSub.prof_lon);
56        MITprofSub.nr=length(MITprofSub.prof_depth);
57        MITprofSub.list_descr=unique(MITprofSub.prof_descr);
58        MITprofSub.nd=length(MITprofSub.list_descr);
59            
60  end;  end;
   
 %add a couple things:  
 %--------------------  
 MITprofSub.np=length(MITprofSub.prof_lon);  
 MITprofSub.nr=length(MITprofSub.prof_depth);  
   

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.22