Home > atmlab > math > column_integrate.m

column_integrate

PURPOSE ^

% COLUMN_INTEGRATE

SYNOPSIS ^

function INT = column_integrate(in,field)

DESCRIPTION ^

% COLUMN_INTEGRATE
 Purpose: To column integrate any data. (e.g. IWC -> IWP). Assumes that missing
          data is represented by negative numbers (or NaNs)

 IN: 1) in = structure containing all data fields
     2) field = {'data','z'}; The first field is the data, the second is the
     height (z) component (same size as the data). Z component can be either ascending or descending

 OUT: INT = column integrated in.(field{1})

 NOTE: The data and height fields must be the same size! e.g. you may need
 to use repmat on the height variable

 NOTE: See at the bottom of the file what the indexed loops look like when they
 are expanded. Indexing the loops is much more efficient. E.g. Indexing here is
 a factor 300 times faster (600s -> 2s for one day of CloudSat data)

 USAGE: IWP = column_integrate(in,{'RO_ice_water_content','Height'})

 $Id: column_integrate.m 8371 2013-04-23 15:42:12Z gerrit $
 Salomon Eliasson

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

column_integrate.m

SOURCE CODE ^

0001 function INT = column_integrate(in,field)
0002 %% COLUMN_INTEGRATE
0003 % Purpose: To column integrate any data. (e.g. IWC -> IWP). Assumes that missing
0004 %          data is represented by negative numbers (or NaNs)
0005 %
0006 % IN: 1) in = structure containing all data fields
0007 %     2) field = {'data','z'}; The first field is the data, the second is the
0008 %     height (z) component (same size as the data). Z component can be either ascending or descending
0009 %
0010 % OUT: INT = column integrated in.(field{1})
0011 %
0012 % NOTE: The data and height fields must be the same size! e.g. you may need
0013 % to use repmat on the height variable
0014 %
0015 % NOTE: See at the bottom of the file what the indexed loops look like when they
0016 % are expanded. Indexing the loops is much more efficient. E.g. Indexing here is
0017 % a factor 300 times faster (600s -> 2s for one day of CloudSat data)
0018 %
0019 % USAGE: IWP = column_integrate(in,{'RO_ice_water_content','Height'})
0020 %
0021 % $Id: column_integrate.m 8371 2013-04-23 15:42:12Z gerrit $
0022 % Salomon Eliasson
0023 
0024 D = field{1};
0025 H = field{2};
0026 assert(isequal(size(in.(D)),size(in.(H))),['atmlab:' mfilename ':badInput'],...
0027 'data component in.%s is not the same size as the z-component in.%s',D,H)
0028 
0029 logtext(atmlab('OUT'),'Column integrating in.%s over z-component: in.%s...\n',D,H)
0030 if any(~strcmp('double',{class(in.(D)),class(in.(H))}))
0031     in.(D) = double(in.(D));
0032     in.(H) = double(in.(H));
0033 end
0034 
0035 %% Mask missing data (i.e., defined as less than zero) with NaNs
0036 in.(D)(in.(D) < 0)=NaN;
0037 in.(H)(in.(H) < 0)=NaN;
0038 
0039 h = 1:size(in.(D),2)-1;
0040 INT = nansum(abs((in.(H)(:,h)-in.(H)(:,h+1))).*(in.(D)(:,h)+in.(D)(:,h+1))/2,2)';
0041 
0042 
0043 %% See below for expanded loops
0044 % for i = 1:size(in.(D),1)
0045 %     %% In the dimension along the swath/ day
0046 %     for h = 1:size(in.(D),2)-1
0047 %         %% z_2-z_1 * (m_2+m_1)/2
0048 %         PROFILE(h) = (in.(H)(i, h) - in.(H)(i, h+1)) * ...
0049 %             (in.(D)(i, h) + in.(D)(i, h+1)) / 2;
0050 %     end
0051 %     INT(i) = sum(PROFILE);
0052 % end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005