Home > atmlab > arts > scenegen > asg_hydrostat.m

asg_hydrostat

PURPOSE ^

ASG_HYDROSTAT Calculates hydrostatic equilibrium for ASG data

SYNOPSIS ^

function G = asg_hydrostat( G, Q )

DESCRIPTION ^

 ASG_HYDROSTAT   Calculates hydrostatic equilibrium for ASG data

    The function demands that *G* contains temperature and water vapour
    data. These quantities are found by searching for the names 'Temperature'
    and 'Water vapour', respectively. If several items exist, the first one is
    used. The number of cases created will match the maximum number of cases
    among the involved variables (altitude, temperature and water vapour).

    The G array must further contain an item for altitudes. The field NAME
    is expected to start as 'Altitude'. This is item of G can be empty,
    beside the field SPCFC, where settings for this functions is stored,
    as described below.

    Hydrostatic equilibrium is calculated for each geographical position
    individually. The reference point (see *pt2z*) is taken from
    G.SPCFC. The same pressure of the reference point is applied for all
    positions, and is taken from G.SPCFC.P0 (should be a scalar). The
    altitude of the reference point is described by G.SPCFC.Z0, which is
    expected to be a surface described in gformat. The input can here be
    for lower data dimension. For example, a constant altitude can be set
    as:
       G(i).SPCFC.Z0        = gf_set( D, asgG, [], 0, [], ...
                                     'Altitude at P0', 'Altitude', 'm' );

 FORMAT   G = asg_hydrostat( G, Q )
        
 OUT   G   Expanded gformat array, appended with an item holding
           altitudes. Name set to 'Altitude'.
 IN   
       G   Data (in gformat).
       Q   Qarts setting structure.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

asg_hydrostat.m

SOURCE CODE ^

0001 % ASG_HYDROSTAT   Calculates hydrostatic equilibrium for ASG data
0002 %
0003 %    The function demands that *G* contains temperature and water vapour
0004 %    data. These quantities are found by searching for the names 'Temperature'
0005 %    and 'Water vapour', respectively. If several items exist, the first one is
0006 %    used. The number of cases created will match the maximum number of cases
0007 %    among the involved variables (altitude, temperature and water vapour).
0008 %
0009 %    The G array must further contain an item for altitudes. The field NAME
0010 %    is expected to start as 'Altitude'. This is item of G can be empty,
0011 %    beside the field SPCFC, where settings for this functions is stored,
0012 %    as described below.
0013 %
0014 %    Hydrostatic equilibrium is calculated for each geographical position
0015 %    individually. The reference point (see *pt2z*) is taken from
0016 %    G.SPCFC. The same pressure of the reference point is applied for all
0017 %    positions, and is taken from G.SPCFC.P0 (should be a scalar). The
0018 %    altitude of the reference point is described by G.SPCFC.Z0, which is
0019 %    expected to be a surface described in gformat. The input can here be
0020 %    for lower data dimension. For example, a constant altitude can be set
0021 %    as:
0022 %       G(i).SPCFC.Z0        = gf_set( D, asgG, [], 0, [], ...
0023 %                                     'Altitude at P0', 'Altitude', 'm' );
0024 %
0025 % FORMAT   G = asg_hydrostat( G, Q )
0026 %
0027 % OUT   G   Expanded gformat array, appended with an item holding
0028 %           altitudes. Name set to 'Altitude'.
0029 % IN
0030 %       G   Data (in gformat).
0031 %       Q   Qarts setting structure.
0032 
0033 % 2007-10-09   Created by Patrick Eriksson
0034 
0035 function G = asg_hydrostat( G, Q )
0036 
0037 
0038 %- Locate position of 'Altitude field'
0039 %
0040 % Take first index if several found
0041 %
0042 iz = min( find( strncmp( lower({G.NAME}), 'altitude', 8 ) ) );
0043 %
0044 if isempty( iz )
0045   error( 'Could not locate any altitude data in G.' );
0046 end
0047 %
0048 %rqre_field( G(iz).SPCFC, 'P0', false, 'G.SPCFC' );
0049 %rqre_field( G(iz).SPCFC, 'Z0', false, 'G.SPCFC' );
0050 %qcheck( @asgG, G(iz).SPCFC.Z0 );
0051 
0052 
0053 %- Locate also position of temperature and water vapour
0054 %
0055 it = min( find( strncmp( lower({G(:).NAME}), 'temperature', 11 ) ) );
0056 if isempty( it )
0057   error( 'Could not locate temperature in G.' );
0058 end
0059 %
0060 iw = min( find( strcmp( lower({G(:).NAME}), 'h2o' ) ) );
0061 if isempty( iw )
0062   error( 'Could not locate water vapour in G.' );
0063 end
0064 
0065 
0066 %- Set string fields
0067 %
0068 G(iz).NAME      = 'Altitude field';
0069 G(iz).SOURCE    = 'asg_hydrostat';
0070 G(iz).DATA_NAME = 'Altitude';
0071 G(iz).DATA_UNIT = 'm';
0072 
0073 
0074 %- Latitudes
0075 %
0076 if G(it).DIM>=2
0077   lats = G(it).GRID2;
0078 else
0079   lats = 45;
0080 end
0081 
0082 
0083 %- Re-grid SPCFC.ZO
0084 %
0085 Z0 = asg_dimadd( G(iz).SPCFC.Z0, Q );
0086 Z0 = asg_regrid( Z0, Q );
0087 
0088 
0089 %- Run HSE
0090 %
0091 G(iz).DIM = G(it).DIM;
0092 %
0093 G(iz).GRID1 = G(it).GRID1; 
0094 G(iz).GRID2 = G(it).GRID2; 
0095 G(iz).GRID3 = G(it).GRID3; 
0096 %
0097 nc = max( [ size(G(it).DATA,4), size(G(it).DATA,4), size(G(iw).DATA,4) ] );
0098 %
0099 if nc > 1
0100   if G(iz).DIMS(end) ~= 4
0101     G(iz).DIMS(end+1) = 4;
0102   end
0103   G(iz).GRID4       = 1:nc; 
0104 end
0105 %
0106 G(iz).DATA = zeros( size(G(it).DATA,1), size(G(it).DATA,2), ...
0107                     size(G(it).DATA,3), nc );
0108 %
0109 for ic = 1 : nc
0110   
0111   %- Find matching temperature case (take last case if necessary)
0112   ic_t = size(G(it).DATA,4);
0113   %
0114   if ic <= ic_t
0115     ic_t = ic;  
0116   end
0117 
0118   %- Find matching water vapour case (take last case if necessary)
0119   ic_w = size(G(iw).DATA,4);
0120   %
0121   if ic <= ic_w
0122     ic_w = ic;  
0123   end
0124   for ilon = 1 : size(G(it).DATA,3)
0125     for ilat = 1 : size(G(it).DATA,2)
0126 
0127       G(iz).DATA(:,ilat,ilon,ic) = pt2z( G(it).GRID1, ...
0128                                          G(it).DATA(:,ilat,ilon,ic_t), ...
0129                                          G(iw).DATA(:,ilat,ilon,ic_w), ...
0130                                          G(iz).SPCFC.P0, ...
0131                                          Z0.DATA(1,ilat,ilon), ...
0132                                          lats(ilat) );
0133       end
0134   end
0135 end
0136 
0137

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