Back to home page

MITgcm

 
 

    


Warning, /utils/matlab/Graphix/GraphixAverage.m is written in an unsupported language. File is not indexed.

view on githubraw file Latest commit 4cf7d6e4 on 2006-06-29 18:52:07 UTC
5bbd0d07c9 Dani*0001 function data = GraphixAverage(data,fln,avg,absmonths,ddf,Dim);
                0002 
                0003 % Function: GraphixAverage
                0004 % Author:   Daniel Enderton
                0005 %
                0006 % Input Fields:
                0007 %
                0008 %   Field       Type        (Brief) Description
                0009 %   -----------------------------------------------------------------------
                0010 %   data        array       Data
                0011 %   fln         string      Field name
                0012 %   avg         string      Averaging scheme ('Ann','DJF', 'JJA',...)
                0013 %   absmonths   array       Absolute months (time axis of data)
                0014 %
                0015 % Output Fields:
                0016 %
                0017 %   Field       Type        (Brief) Description
                0018 %   -----------------------------------------------------------------------
                0019 %   data        array       Averaged data.
                0020 %
                0021 % Descripton:
                0022 %   This function averages the data.  The field to average is defined by
                0023 %   'fln', and the loaded, pre-averaged data is 'data'.  The field
                0024 %   'absmonths' is the time axis given in months (1,13,25,... are assumed
                0025 %   to be Janurary), and is returned in 'datatime' so that there can be a
                0026 %   time axis for every experiment / configuration setting.  It is
                0027 %   important to remember that this function assumed monthly data!
                0028 
                0029 % Load parameters (here only general parameters).
                0030 GraphixGenParam;
                0031 
                0032 % Calcuate months of year.
                0033 months = mod(absmonths-1,12)+1;
                0034 
                0035 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                0036 %                       Take monthly average of data                      %
                0037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                0038 
                0039 % Take monthly average of data.  The result has the same dimensions of the
                0040 % time-independent field (2D or 3D), and the last dimension is the time,
                0041 % which has a length of 12, running from 1 to 12, representing January
                0042 % through December respectively.  If there is no data for a months, that
                0043 % months values are set to NaN.
                0044 if isequal(avg,'Non')
                0045     temp = data;
                0046 elseif isequal(avg,'Avg')
                0047     if     isequal(Dim,2), temp = meanovernan(data,3);
                0048     elseif isequal(Dim,3), temp = meanovernan(data,4); end
4cf7d6e47a Dani*0049 elseif isequal(avg,'Tse')
                0050     temp = data;
5bbd0d07c9 Dani*0051 else
                0052         for imon = 1:12
                0053         if isequal(Dim,2)
                0054             if isempty(find(months == imon))
                0055                 dataMonAvg(:,:,imon) = NaN * zeros(size(data(:,:,1)));
                0056             else
                0057                 inds=find(months==imon);
                0058                 dataMonAvg(:,:,imon) = meanovernan(data(:,:,absmonths(inds)),3);
                0059             end
                0060         elseif isequal(Dim,3)
                0061             if isempty(find(months == imon))
                0062                 dataMonAvg(:,:,:,imon) = NaN * zeros(size(data(:,:,:,1)));
                0063             else
                0064                 inds=find(months==imon);
                0065                 dataMonAvg(:,:,:,imon) = meanovernan(data(:,:,:,absmonths(inds)),4);
                0066             end
                0067         else
                0068             error('Field not accounted for in ''fields2D'' of ''fields3D''');
                0069         end
                0070         end
                0071 end
                0072 
                0073 
                0074 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                0075 %                               Average data                              %
                0076 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                0077 
                0078 % If 'avg' (the averaging scheme) is time-sequential, merely return the
                0079 % data, if it is time-year, merely return the monthly averaged data.  Note
                0080 % that these options are for a contour plot of a property which is only a
                0081 % function of latitude, that is you can only use  this for a zonally
                0082 % averaged to i=# slice of a 2D field.
4cf7d6e47a Dani*0083 if ismember(avg,{'Non','Avg','Tse'})
5bbd0d07c9 Dani*0084     dummy = 1;
                0085 elseif isequal(avg,'Tyr')
                0086     temp = dataMonAvg;
                0087     temp(:,:,13) = temp(:,:,1);
                0088 
                0089 
                0090 
                0091 % Average along certain month combinations, or just select a month itself.
                0092 % Here we pick the month index number(s) based on the averaging parameter,
                0093 % and then select those indecies of the monthly averaged data and take a
                0094 % mean over the time axis.
                0095 else
                0096     if     isequal(avg,'Jan'), index = [1];
                0097     elseif isequal(avg,'Feb'), index = [2];
                0098     elseif isequal(avg,'Mar'), index = [3];
                0099     elseif isequal(avg,'Apr'), index = [4];
                0100     elseif isequal(avg,'May'), index = [5];
                0101     elseif isequal(avg,'Jun'), index = [6];
                0102     elseif isequal(avg,'Jul'), index = [7];
                0103     elseif isequal(avg,'Aug'), index = [8];
                0104     elseif isequal(avg,'Sep'), index = [9];
                0105     elseif isequal(avg,'Oct'), index = [10];
                0106     elseif isequal(avg,'Nov'), index = [11];
                0107     elseif isequal(avg,'Dec'), index = [12];
                0108     elseif isequal(avg,'DJF'), index = [12,1,2];
                0109     elseif isequal(avg,'MAM'), index = [3,4,5];
                0110     elseif isequal(avg,'JJA'), index = [6,7,8];
                0111     elseif isequal(avg,'SON'), index = [9,10,11];
                0112     elseif isequal(avg,'Ann'), index = [1:12];
                0113     else
                0114         error(['Unaccounted for averaging scheme:  ',avg]);
                0115     end
                0116     
                0117     % Make an array 'newindex' which has all the values as in 'index', but
                0118     % with the emission those months with no data (all NaNs).  Note that
                0119     % sometimes the edges of the U and V velocity fields can be NaN from
                0120     % the interpolation, so check for NaN months a few horizontal indecies
                0121     % into the array.
                0122     umonths = unique(months);
                0123     newindex = umonths(ismember(umonths,index));
                0124     
                0125     % Cast a warning or error for all or some missing data, respectively.
                0126     if isempty(newindex)
                0127         error(['No data for the averaging sceheme:  ',avg,]);
                0128     elseif length(newindex) ~= length(index)
                0129         disp(['***Warning***  Missing data for averaging scheme:  ',avg]);
                0130         disp(['               Month(s) with data:      ',mat2str(newindex)]);
                0131         disp(['               Month(s) for averaging:  ',mat2str(index)]);
                0132     end
                0133     
                0134     % Perform time averaging.
                0135     if isequal(Dim,2)
                0136         temp = meanovernan(dataMonAvg(:,:,newindex),3);
                0137     elseif isequal(Dim,3)
                0138         temp = meanovernan(dataMonAvg(:,:,:,newindex),4);
                0139     end
                0140     
                0141 end
                0142 
                0143 data = temp;