Home > atmlab > geographical > area_weighting.m

area_weighting

PURPOSE ^

AREA_WEIGHTING returns a matrix of weights for geodata based on latitude

SYNOPSIS ^

function weights = area_weighting(varargin)

DESCRIPTION ^

 AREA_WEIGHTING returns a matrix of weights for geodata based on latitude

 In   
       lat:       [%f ...]            latitude  vector
       lon:       [%f ...]            longitude  vector
 
 OPT:  vec        logical             true if the weighting matrix should
                                      be a vector (same size as latitude)
                                  

 Out: A matrix of area wieghts the same size as se.datafield;
      where each element is cosd(latitude)

 USAGE: weights = area_weighting('lat',[%f,...],'lon',[...]) %for 2D output
        or
        weights = area_weighting('lat',[%f,...],'vec',true) %for 1D output
 Created by Salomon Eliasson
 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

area_weighting.m

SOURCE CODE ^

0001 function weights = area_weighting(varargin)
0002 % AREA_WEIGHTING returns a matrix of weights for geodata based on latitude
0003 %
0004 % In
0005 %       lat:       [%f ...]            latitude  vector
0006 %       lon:       [%f ...]            longitude  vector
0007 %
0008 % OPT:  vec        logical             true if the weighting matrix should
0009 %                                      be a vector (same size as latitude)
0010 %
0011 %
0012 % Out: A matrix of area wieghts the same size as se.datafield;
0013 %      where each element is cosd(latitude)
0014 %
0015 % USAGE: weights = area_weighting('lat',[%f,...],'lon',[...]) %for 2D output
0016 %        or
0017 %        weights = area_weighting('lat',[%f,...],'vec',true) %for 1D output
0018 % Created by Salomon Eliasson
0019 % $Id$
0020 
0021 errID = 'atmlab:area_weighting:badInput';
0022 for arg = 1:2:length(varargin)
0023     S.(varargin{arg}) = varargin{arg+1};
0024 end
0025 assert(isfield(S,'lat'),errID,'input ''lat'' is missing')
0026 assert(isfield(S,'lon') || isfield(S,'vec'),errID,....
0027     'input ''lon'' is required to make weighting matrix if logical ''vec'' is not set')
0028 
0029 if isfield(S,'vec') && S.vec
0030     weights = cosd(S.lat);
0031 else
0032     S.lat = sort(S.lat,'descend');
0033     [y,latmatrix] = meshgrid(S.lon,S.lat);
0034     weights = cosd(latmatrix);
0035 end

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