Home > atmlab > arts > scenegen > asg_fixed_relhumid.m

asg_fixed_relhumid

PURPOSE ^

ASG_FIXED_RELHUMID Sets a fixed relative humidity

SYNOPSIS ^

function G = asg_fixed_relhumid( D, G )

DESCRIPTION ^

 ASG_FIXED_RELHUMID   Sets a fixed relative humidity

    Water VMR profiles are set to the selected relative humidity inside
    selected altitude range. This is done for all items of G where 
    G.NAME starts with 'Water'.

    The calculations are controled by the following fields
       SPCFC.FIXED_RH    Boolean
       SPCFC.RH          Relative humidity [-] (not %, a value around 1)
       SPCFC.RH_BRAKEP   Brake point [Pa or m]
       SPCFC.RH_TOPP     Top altitude [Pa or m]

    Nothing is done if H2O.FIXED_RH is false. Otherwise:

    The profiles are set to SPCFC.RH up to the altitude corresponding to
    SPCFC.RH_BRAKEP. A linear transition to the original profile is 
    performed between SPCFC.RH_BRAKEP and SPCFC.RH_TOPP.

    Two options exist for SPCFC.RH_BRAKEP and SPCFC.RH_TOPP:
       1. Given as pressure levels.
       2. Distance to local tropopause
    Option 1 is assumed if SPCFC.RH_TOPP <=  SPCFC.RH_BRAKEP, and vice versa.
    Read header of *tropoapuse* before selecting option 2.

    The relative humidity with respect to water is considered for 
    temperatures above 0C, and the humidity with respect to ice for 
    lower temperatures.

 FORMAT   G = asg_fixed_relhumid( D, G )
        
 OUT   G   Modified ASG data.
 IN    D   Gformat definition structure.
       G   ASG data.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

asg_fixed_relhumid.m

SOURCE CODE ^

0001 % ASG_FIXED_RELHUMID   Sets a fixed relative humidity
0002 %
0003 %    Water VMR profiles are set to the selected relative humidity inside
0004 %    selected altitude range. This is done for all items of G where
0005 %    G.NAME starts with 'Water'.
0006 %
0007 %    The calculations are controled by the following fields
0008 %       SPCFC.FIXED_RH    Boolean
0009 %       SPCFC.RH          Relative humidity [-] (not %, a value around 1)
0010 %       SPCFC.RH_BRAKEP   Brake point [Pa or m]
0011 %       SPCFC.RH_TOPP     Top altitude [Pa or m]
0012 %
0013 %    Nothing is done if H2O.FIXED_RH is false. Otherwise:
0014 %
0015 %    The profiles are set to SPCFC.RH up to the altitude corresponding to
0016 %    SPCFC.RH_BRAKEP. A linear transition to the original profile is
0017 %    performed between SPCFC.RH_BRAKEP and SPCFC.RH_TOPP.
0018 %
0019 %    Two options exist for SPCFC.RH_BRAKEP and SPCFC.RH_TOPP:
0020 %       1. Given as pressure levels.
0021 %       2. Distance to local tropopause
0022 %    Option 1 is assumed if SPCFC.RH_TOPP <=  SPCFC.RH_BRAKEP, and vice versa.
0023 %    Read header of *tropoapuse* before selecting option 2.
0024 %
0025 %    The relative humidity with respect to water is considered for
0026 %    temperatures above 0C, and the humidity with respect to ice for
0027 %    lower temperatures.
0028 %
0029 % FORMAT   G = asg_fixed_relhumid( D, G )
0030 %
0031 % OUT   G   Modified ASG data.
0032 % IN    D   Gformat definition structure.
0033 %       G   ASG data.
0034 
0035 % 2007-10-19   Created by Patrick Eriksson
0036 
0037 function G = asg_fixed_relhumid( D, G )
0038 
0039 
0040 %- Find temperature
0041 %
0042 it = min( find( strncmp( lower({G.NAME}), 'temperature', 11 ) ) );
0043 %
0044 if isempty( it )
0045   error( 'Could not locate any temperature data in G.' );
0046 end
0047 
0048 
0049 %- Find water species
0050 %
0051 ih2o = find( strncmp( lower({G.NAME}), 'water', 5 ) );
0052 %
0053 if isempty( it )
0054   error( 'Could not locate any water vapour data in G.' );
0055 end
0056 
0057 
0058 iz = [];
0059 
0060 
0061 for ig = ih2o
0062   
0063   rqre_field( G(ig).SPCFC, 'FIXED_RH', 0, 'G.SPCFC for water' );
0064 
0065   if ~G(ig).SPCFC.FIXED_RH
0066     continue       % ---->
0067   end
0068   
0069   rqre_field( G(ig).SPCFC, 'RH', 0, 'G.SPCFC' );
0070   rqre_in_range( G(ig).SPCFC.RH, 0, 2, 'G.SPCFC.RH',  );
0071   rqre_field( G(ig).SPCFC, 'RH_BRAKEP', 0, 'G.SPCFC' );
0072   rqre_field( G(ig).SPCFC, 'RH_TOPP', 0, 'G.SPCFC' );
0073 
0074   if G(ig).SPCFC.RH_TOPP >  G(ig).SPCFC.RH_BRAKEP
0075     do_z = 1;
0076   else
0077     do_z = 0;
0078   end
0079 
0080   %- Find altitude
0081   %
0082   if do_z  &  isempty(iz)
0083     %
0084     iz = min( find( strncmp( lower({G.NAME}), 'altitude', 8 ) ) );
0085     %
0086     if isempty( iz )
0087       error( 'Could not locate any altitude data in G.' );
0088     end
0089     %
0090     if isempty( G(iz).DATA )
0091       error( 'Empty G.DATA for altitude field.' );
0092     end
0093   end
0094   
0095   
0096   for ic = 1:size(G(ig).DATA,4)
0097     
0098     %- Find matching temperature case (take last case if necessary)
0099     ic_t = size(G(it).DATA,4);
0100     %
0101     if ic <= ic_t
0102       ic_t = ic;  
0103     end
0104 
0105     %- Find matching temperature case (take last case if necessary)
0106     ic_z = size(G(iz).DATA,4);
0107     %
0108     if ic <= ic_z
0109       ic_z = ic;  
0110     end
0111 
0112     for ilon = 1:size(G(ig).DATA,3)
0113       for ilat = 1:size(G(ig).DATA,2)
0114           
0115         %- Find range of interest and obtain relavant data
0116         %
0117         if do_z
0118           z = interpp( G(iz).GRID1, G(iz).DATA(:,ilat,ilon,ic_z), G(ig).GRID1 );
0119           t = interpp( G(it).GRID1, G(it).DATA(:,ilat,ilon,ic_t), G(ig).GRID1 );
0120           z   = z - tropopause( z, t );
0121           ind = find( z <= G(ig).SPCFC.RH_TOPP ); 
0122           z   = z(ind);
0123           t   = t(ind);
0124         else
0125           ind = find( G(ig).GRID1 >= G(ig).SPCFC.RH_TOPP );
0126           t = interpp( G(it).GRID1, G(it).DATA(:,ilat,ilon,ic_t), ...
0127                                                             G(ig).GRID1(ind) );
0128         end
0129         %
0130         ei = e_eq_ice( t );
0131         ew = e_eq_water( t );
0132         
0133         %- Determine relative weight for ew
0134         %
0135         ww = t >= 273.15;
0136         
0137         %- VMR for selected relative humidity
0138         %
0139         vmr = G(ig).SPCFC.RH * ( ww.*ew + (1-ww).*ei ) ./ G(ig).GRID1(ind);
0140           
0141         %- Determine weight for vmr
0142         %
0143         if do_z
0144           ww = ( z - G(ig).SPCFC.RH_TOPP ) /...
0145                          ( G(ig).SPCFC.RH_BRAKEP - G(ig).SPCFC.RH_TOPP );
0146         else
0147           ww = ( log10(G(ig).GRID1(ind)) - log10(G(ig).SPCFC.RH_TOPP) ) /...
0148                ( -log10(G(ig).SPCFC.RH_TOPP) + log10(G(ig).SPCFC.RH_BRAKEP)  );
0149         end
0150         %
0151         ww(find(ww>1)) = 1;
0152 
0153         %- Create new profile
0154         %
0155         G(ig).DATA(ind,ilat,ilon,ic) = vec2col(ww.*vmr) + ...
0156                     vec2col((1-ww)).*G(ig).DATA(ind,ilat,ilon, ...
0157                                                           ic);
0158       end
0159     end
0160   end
0161 end

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