Home > atmlab > geophysics > z2p_cira86.m

z2p_cira86

PURPOSE ^

Z2P_CIRA86 Converts altitude to pressure and temperature

SYNOPSIS ^

function [p,t,Gc86z,Gc86t]=z2p_cira86(z,lat,doy,Gc86z,Gc86t)

DESCRIPTION ^

 Z2P_CIRA86    Converts altitude to pressure and temperature

    Converts altitude to pressure and temperature assuming cira86
    climataology. Linear interpolation between log(pressure),
    latitude, and day of year is performed.

    The function optionally returns the gridded fields for cira 86z and t.
    This is useful if you need to call Z2P_CIRA86 very often.
    Store Gc86z and G86t on the first call, then pass them in with every
    following call. This avoids reading the XML data over and over again.

 FORMAT   [P,T,Gc86z,Gc86t] = z2p_cira86( Z , LAT , DOY, Gc86z, Gc86t )

 OUT   P     Pressure in pascal, for all combinations of Z, LAT, DOY
             Size is [np,nlat,ndoy]
   OPTIONAL
       T     Temperature in kelvin, for all combinations of Z, LAT, DOY
             Size is [nz,nlat,ndoy]
       Gc86z Original cira86 z_field
       Gc86t Original cira86 t_field
 IN    Z     Altitude in meter. Can be a scalar or column vector
       LAT   Latitude. Can be a scalar or column vector [-90 to 90].
       DOY   Day of year. Can be a scalar or column vector
   OPTIONAL
       Gc86z Original cira86 z_field
       Gc86t Original cira86 t_field

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

z2p_cira86.m

SOURCE CODE ^

0001 % Z2P_CIRA86    Converts altitude to pressure and temperature
0002 %
0003 %    Converts altitude to pressure and temperature assuming cira86
0004 %    climataology. Linear interpolation between log(pressure),
0005 %    latitude, and day of year is performed.
0006 %
0007 %    The function optionally returns the gridded fields for cira 86z and t.
0008 %    This is useful if you need to call Z2P_CIRA86 very often.
0009 %    Store Gc86z and G86t on the first call, then pass them in with every
0010 %    following call. This avoids reading the XML data over and over again.
0011 %
0012 % FORMAT   [P,T,Gc86z,Gc86t] = z2p_cira86( Z , LAT , DOY, Gc86z, Gc86t )
0013 %
0014 % OUT   P     Pressure in pascal, for all combinations of Z, LAT, DOY
0015 %             Size is [np,nlat,ndoy]
0016 %   OPTIONAL
0017 %       T     Temperature in kelvin, for all combinations of Z, LAT, DOY
0018 %             Size is [nz,nlat,ndoy]
0019 %       Gc86z Original cira86 z_field
0020 %       Gc86t Original cira86 t_field
0021 % IN    Z     Altitude in meter. Can be a scalar or column vector
0022 %       LAT   Latitude. Can be a scalar or column vector [-90 to 90].
0023 %       DOY   Day of year. Can be a scalar or column vector
0024 %   OPTIONAL
0025 %       Gc86z Original cira86 z_field
0026 %       Gc86t Original cira86 t_field
0027 
0028 % 2007-11-01   Created by Bengt Rydberg
0029 
0030 function [p,t,Gc86z,Gc86t]=z2p_cira86(z,lat,doy,Gc86z,Gc86t)
0031 
0032 if atmlab('STRICT_ASSERT')
0033     rqre_datatype( z, @istensor1 );                                    %&%
0034     rqre_datatype( lat, @istensor1 );                                  %&%
0035     rqre_datatype( doy, @istensor1 );                                  %&%
0036     
0037     errid = ['atmlab:' mfilename ':badInput'];
0038     
0039     
0040     if any(doy)>367 || any(doy<1)                                      %&%
0041         error(errid,'doy range is [1,367]')              %&%
0042     end                                                                %&%
0043     if any(lat)>90 || any(lat<-90)                                     %&%
0044         error(errid,'latitude range is -90 to 90')      %&%
0045     end                                                                %&%
0046 end
0047 
0048 % Create a a mjd matching the given doy (ie. the inverse of mjd2doy)
0049 mjd = date2mjd( 2000, 1, 1, 0, 0, 0 ) + doy - 1;
0050 
0051 if (nargin < 4 || isempty(Gc86z))
0052     cira86 = fullfile( atmlab('ARTS_XMLDATA_PATH'), 'climatology', ...
0053         'cira86', 'cira86.z.xml' );
0054     Gc86z = gf_artsxml( cira86, 'CIRA86', 'z_field' );
0055 end
0056 G    = atmdata_regrid( Gc86z, { Gc86z.GRID1, lat, 0, mjd } );
0057 Z    = G.DATA;
0058 p    = zeros( length(z), size(Z,2), size(Z,4) );
0059 logp = log( G.GRID1 );
0060 
0061 if nargout > 1
0062     if (nargin < 5 || isempty(Gc86t))
0063         cira86 = fullfile( atmlab('ARTS_XMLDATA_PATH'), 'climatology', ...
0064             'cira86', 'cira86.t.xml' );
0065         Gc86t = gf_artsxml( cira86, 'CIRA86', 't_field' );
0066     end
0067     G = atmdata_regrid( Gc86t, { Gc86t.GRID1, lat, 0, mjd } );
0068     T = G.DATA;
0069     t = zeros( length(z), size(T,2), size(T,4) );
0070 end
0071 
0072 for ilat = 1 : size(Z,2)
0073     for imjd = 1 : size(Z,4)
0074         if nargout < 2
0075             p(:,ilat,imjd) = exp( interp1( Z(:,ilat,1,imjd), logp, z ) );
0076         else
0077             pnew           = interp1( Z(:,ilat,1,imjd), logp, z );
0078             t(:,ilat,imjd) = interp1( logp, T(:,ilat,1,imjd), pnew );
0079             p(:,ilat,imjd) = exp( pnew );
0080         end
0081     end
0082 end
0083 
0084 % ------------
0085 % NOTES
0086 % These are the same assertion as given by the rqre functions at the beginnig of
0087 % the function. The following are much faster, but if you run is stable you
0088 % should set atmlab('STRICT_ASSERT',0) to skip the assertions all together
0089 
0090 %     assert(isnumeric(z) && size(z,1) >=1 && size(z,2) == 1 && ndims(z)==2,...
0091 %         errid, '*grid* must pass the test @isempty || @istensor1')
0092 %     assert(isnumeric(lat) && size(lat,1) >=1 && size(lat,2) == 1 && ndims(lat)==2,...
0093 %         errid, '*grid* must pass the test @isempty || @istensor1')
0094 %     assert(isnumeric(doy) && size(doy,1) >=1 && size(doy,2) == 1 && ndims(doy)==2,...
0095 %         errid, '*grid* must pass the test @isempty || @istensor1')

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