/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_misc/annualmean.m
ViewVC logotype

Diff of /MITgcm_contrib/gael/matlab_class/gcmfaces_misc/annualmean.m

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

revision 1.1 by gforget, Wed Apr 18 01:58:42 2012 UTC revision 1.2 by gforget, Mon Sep 10 18:57:27 2012 UTC
# Line 11  function [myMean,myAnom]=annualmean(myTi Line 11  function [myMean,myAnom]=annualmean(myTi
11  %  - prepare list of records to average (depending on myYear, lYear and nYears)  %  - prepare list of records to average (depending on myYear, lYear and nYears)
12  %  - in case when lYear<2 we use records as years  %  - in case when lYear<2 we use records as years
13  %  %
14  %by assumption:  %by assumption:
15  %  - the time dimension is last in myFld, and matches the length of myTimes  %  - the time dimension is last in myFld, and matches the length of myTimes
16    
17  %determine the number of records in one year (lYear)  %determine the number of records in one year (lYear)
# Line 27  nYears=floor(length(myTimes)/lYear); Line 27  nYears=floor(length(myTimes)/lYear);
27  %determine records that correspond to myYear, which  %determine records that correspond to myYear, which
28  %  may be 'first','last',n (an integer) or 'all'  %  may be 'first','last',n (an integer) or 'all'
29  if ischar(myYear);  if ischar(myYear);
30    if strcmp(myYear,'first');      if strcmp(myYear,'first');
31      recInAve=[1:lYear];          recInAve=[1:lYear];
32    elseif strcmp(myYear,'last');      elseif strcmp(myYear,'last');
33      recInAve=[1:lYear]+(nYears-1)*lYear;          recInAve=[1:lYear]+(nYears-1)*lYear;
34    elseif strcmp(myYear,'all');      elseif strcmp(myYear,'all');
35      recInAve=[1:nYears*lYear];          recInAve=[1:nYears*lYear];
36    else;      else;
37      error('inconsistent specification of myYear');          error('inconsistent specification of myYear');
38    end;      end;
39  elseif (myYear>=1)&(myYear<=nYears);  elseif (myYear>=1)&(myYear<=nYears);
40    recInAve=[1:lYear]+(myYear-1)*lYear;      recInAve=[1:lYear]+(myYear-1)*lYear;
41  else;  else;
42    error('inconsistent specification of myYear');      error('inconsistent specification of myYear');
43  end;  end;
44  nRecs=length(recInAve);  nRecs=length(recInAve);
45    
46  %determine last dimension, which need to match the length myTimes  %determine last dimension, which need to match the length myTimes
47  if strcmp(class(myFld),'gcmfaces'); nDim=size(myFld{1}); else; nDim=size(myFld); end;  if strcmp(class(myFld),'gcmfaces'); nDim=size(myFld{1}); else; nDim=size(myFld); end;
48  if nDim(end)~=length(myTimes); error('last dimensopn should match the length of myTimes'); end;  if length(myTimes)>1;
49  nDim=length(nDim); tt=''; for jj=1:nDim-1; tt=[tt ':,']; end;      if nDim(end)~=length(myTimes);
50            error('last dimension should match the length of myTimes');
51        end;
52        nDim=length(nDim); tt=''; for jj=1:nDim-1; tt=[tt ':,']; end;
53    else;
54        nDim=length(nDim)+1; tt=''; for jj=1:nDim-1; tt=[tt ':,']; end;
55    end;
56    
57  %compute time mean:  %compute time mean:
58  eval(['myMean=mean(myFld(' tt 'recInAve),nDim);']);  eval(['myMean=mean(myFld(' tt 'recInAve),nDim);']);
59    
60  %compute anomaly:  %compute anomaly:
61  if nargout>1;  if nargout>1;
62  myAnom=myFld-repmat(myMean,[ones(1:nDim-1) length(myTimes)]);      myAnom=myFld-repmat(myMean,[ones(1:nDim-1) length(myTimes)]);
63  end;  end;
64    

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

  ViewVC Help
Powered by ViewVC 1.1.22