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

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

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


Revision 1.5 - (hide annotations) (download)
Sun Jun 2 16:48:20 2013 UTC (12 years, 1 month ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65x, checkpoint65r, checkpoint65p, checkpoint65q, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, HEAD
Changes since 1.4: +1 -1 lines
- MITprof_struct.m	replace prof_depth arg with dataset arg, add prof_D/Destim
- MITprof_subset.m	refine conditionality

1 gforget 1.1 function [MITprofSub]=MITprof_subset(MITprof,varargin);
2 gforget 1.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 gforget 1.1 % [MITprofSub]=MITprof_subset(MITprof,'depth',[50 150]);
13     % returns the subset of MITprof that has prof_depth>=50 and <150
14     % [MITprofSub]=MITprof_subset(MITprof,'depth',[50 150],'descr',platformName);
15     % ... and prof_descr=platformName;
16    
17     MITprofSub=MITprof;
18     fldNames=fieldnames(MITprof);
19    
20     nSub=(nargin-1)/2;
21     for iSub=1:nSub;
22 gforget 1.2 if ~strcmp('list',varargin{(iSub-1)*2+1});
23     eval(['prof_sub=MITprofSub.prof_' varargin{(iSub-1)*2+1} ';']);
24     range_sub=varargin{(iSub-1)*2+2};
25     if strcmp('descr',varargin{(iSub-1)*2+1});
26     KK=find(strcmp(prof_sub,range_sub));
27     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 gforget 1.1 else;
35 gforget 1.2 KK=varargin{(iSub-1)*2+2};
36 roquet 1.3 prof_sub=[1:length(MITprofSub.prof_lon)]';
37 gforget 1.2 if iSub~=1; error('''list'' subset should come first'); end;
38 gforget 1.1 end;
39 roquet 1.3 KK=reshape(KK,length(KK),1);
40 gforget 1.2
41 gforget 1.1 % [varargin{(iSub-1)*2+1} ' -- ' num2str(length(KK))]
42     for iFld=1:length(fldNames);
43     eval(['tmp1=MITprofSub.' fldNames{iFld} ';']);
44     if strcmp('depth',varargin{(iSub-1)*2+1}) & strcmp(fldNames{iFld},'prof_depth');
45     tmp1=tmp1(KK);
46     elseif strcmp('depth',varargin{(iSub-1)*2+1});
47 gforget 1.4 if size(tmp1,2)==length(MITprof.prof_depth); tmp1=tmp1(:,KK); end;
48 gforget 1.5 elseif ~strcmp(fldNames{iFld},'prof_depth');;
49 gforget 1.1 if size(tmp1,1)==size(prof_sub,1); tmp1=tmp1(KK,:); end;
50     end;
51     eval(['MITprofSub.' fldNames{iFld} '=tmp1;']);
52     end;
53 gforget 1.2
54     %add a couple things:
55     %--------------------
56     MITprofSub.np=length(MITprofSub.prof_lon);
57     MITprofSub.nr=length(MITprofSub.prof_depth);
58     MITprofSub.list_descr=unique(MITprofSub.prof_descr);
59     MITprofSub.nd=length(MITprofSub.list_descr);
60 gforget 1.1
61     end;

  ViewVC Help
Powered by ViewVC 1.1.22