Home > atmlab > arts > qarts_vmr_field.m

qarts_vmr_field

PURPOSE ^

QARTS_VMR_FIELD Extracts vmr field from Q.ABS_SPECIES.ATMDATA

SYNOPSIS ^

function vmr_field = qarts_vmr_field( Q, varargin )

DESCRIPTION ^

 QARTS_VMR_FIELD   Extracts vmr field from Q.ABS_SPECIES.ATMDATA

   Performs an interpolation of Q.ABS_SPECIES.ATMDATA. The field ATMDATA must
   be set for all species. For 3D cases, P_GRID, LAT_GRID and LON_GRID are
   used as interpolation grids. For 1D and 2D, LAT_TRUE and LON_TRUE replace
   LAT_GRID and LON_GRID.

   The interpolation is made as using *atmdata_regrid*. That is, the data are
   assumed to be defined everywhere (end values valid all the way to +-INF).
   This is also valid for singleton dimensions. The grid for empty/singleton
   dimensions can be empty or a scalar.

   It is also possible to handle atmdata having date and hour dimensions. The
   optional arguments must then be set.

   The following fields must always be set:
      Q.ATMOSPHERE_DIM
      Q.P_GRID
      Q.ABS_SPECIES

 FORMAT   vmr_field = qarts_vmr_field( Q [, mjd, ltime] )
        
 OUT   vmr_field   Obtained vmr field.
 IN    Q           Qarts setting structure.
 OPT   mjd         Date as MJD. A scalar.
       ltime       Local (solar) time, in hours. A scalar.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

qarts_vmr_field.m

SOURCE CODE ^

0001 % QARTS_VMR_FIELD   Extracts vmr field from Q.ABS_SPECIES.ATMDATA
0002 %
0003 %   Performs an interpolation of Q.ABS_SPECIES.ATMDATA. The field ATMDATA must
0004 %   be set for all species. For 3D cases, P_GRID, LAT_GRID and LON_GRID are
0005 %   used as interpolation grids. For 1D and 2D, LAT_TRUE and LON_TRUE replace
0006 %   LAT_GRID and LON_GRID.
0007 %
0008 %   The interpolation is made as using *atmdata_regrid*. That is, the data are
0009 %   assumed to be defined everywhere (end values valid all the way to +-INF).
0010 %   This is also valid for singleton dimensions. The grid for empty/singleton
0011 %   dimensions can be empty or a scalar.
0012 %
0013 %   It is also possible to handle atmdata having date and hour dimensions. The
0014 %   optional arguments must then be set.
0015 %
0016 %   The following fields must always be set:
0017 %      Q.ATMOSPHERE_DIM
0018 %      Q.P_GRID
0019 %      Q.ABS_SPECIES
0020 %
0021 % FORMAT   vmr_field = qarts_vmr_field( Q [, mjd, ltime] )
0022 %
0023 % OUT   vmr_field   Obtained vmr field.
0024 % IN    Q           Qarts setting structure.
0025 % OPT   mjd         Date as MJD. A scalar.
0026 %       ltime       Local (solar) time, in hours. A scalar.
0027 
0028 % 2010-01-09   Created by Patrick Eriksson.
0029 
0030 function vmr_field = qarts_vmr_field( Q, varargin )
0031 
0032   
0033 %- Variable checks
0034 %
0035 strict_assert = atmlab( 'STRICT_ASSERT' );
0036 %
0037 if strict_assert
0038 
0039   rqre_nargin( 1, nargin );
0040   for i = 1 : length( varargin )
0041     rqre_datatype( varargin{i}, @istensor0, ...
0042                                      'Optional arguments *mjd* and *ltime*.' ); 
0043   end
0044   
0045   if ~qarts_isset( Q.ATMOSPHERE_DIM )
0046     error( 'Q.ATMOSPHERE_DIM must be set when using this function' );
0047   end
0048   if ~qarts_isset( Q.P_GRID )
0049     error( 'Q.P_GRID must be set when using this function' );
0050   end
0051   if Q.ATMOSPHERE_DIM < 3
0052     if ~qarts_isset( Q.LAT_TRUE )
0053       error( 'For 1D and 2D, Q.LAT_TRUE must be set when using this function' );
0054     end
0055     if ~qarts_isset( Q.LON_TRUE )
0056       error( 'For 1D and 2D, Q.LON_TRUE must be set when using this function' );
0057     end
0058   else
0059     if ~qarts_isset( Q.LAT_GRID )
0060       error( 'For 3D, Q.LAT_GRID must be set when using this function' );
0061     end
0062     if ~qarts_isset( Q.LON_GRID )
0063       error( 'For 3D, Q.LON_GRID must be set when using this function' );
0064     end
0065   end
0066 
0067   if ~qarts_isset( Q.ABS_SPECIES )
0068     error( 'Q.ABS_SPECIES must be set when using this function' );
0069   end
0070   rqre_field( Q.ABS_SPECIES(1), 'ATMDATA', 'Q.ABS_SPECIES' );
0071 end
0072 
0073 
0074 
0075 %- Set and check interpolation grids (some special tricks for 2D!)
0076 %
0077 grids{1} = qarts_get( Q.P_GRID );
0078 %
0079 if Q.ATMOSPHERE_DIM == 1
0080   grids{2} = qarts_get( Q.LAT_TRUE );
0081   grids{3} = qarts_get( Q.LON_TRUE );
0082   if strict_assert  & ( length(grids{2}) ~= 1  |  length(grids{3}) ~= 1 )
0083       error( 'For 1D, Q.LAT_TRUE and Q.LON_TRUE must have length 1.' );
0084   end
0085 elseif Q.ATMOSPHERE_DIM == 2
0086   lat_true = qarts_get( Q.LAT_TRUE );
0087   lon_true = qarts_get( Q.LON_TRUE );
0088   if strict_assert  &  length(lat_true) ~= length(lon_true)
0089     error( 'For 2D, Q.LAT_TRUE and Q.LON_TRUE must have the same length.' );
0090   end   
0091   grids{2} = lat_true;
0092   grids{3} = lon_true(1);
0093 else
0094   grids{2} = qarts_get( Q.LAT_GRID );
0095   grids{3} = qarts_get( Q.LON_GRID );
0096 end
0097 %
0098 for i = 1 : length( varargin )
0099   rqre_datatype( varargin{i}, @istensor0, ...                               %&%
0100                                  'Optional arguments *mjd* and *ltime*.' ); %&%
0101   grids{3+i} = varargin{i};
0102 end
0103 
0104 
0105 %- Allocate vmr_field
0106 %
0107 ns = length( Q.ABS_SPECIES );
0108 n  = [ ns ones(1,3) ];
0109 %
0110 for i = 1 : length(grids)
0111   l = length( grids{i} );
0112   if l > 1
0113     n(i+1) = l;
0114   end
0115 end
0116 %
0117 vmr_field = zeros( n );
0118 
0119 
0120 %- Standard "regrid" can be applied for 1D and 3D
0121 %
0122 if Q.ATMOSPHERE_DIM ~= 2
0123   %
0124   for i = 1 : ns
0125     vname = sprintf( 'Q.ABS_SPECIES(%d).ATMDATA', i );
0126     G     = qarts_get_gformat( Q.ABS_SPECIES(i).ATMDATA );
0127     %
0128     if strict_assert
0129        rqre_datatype( G, @isatmdata, vname );
0130     end
0131     %
0132     % Minimum dimension for interpolation is Q.ATMOSPHERE_DIM
0133     dim = max( [ G.DIM Q.ATMOSPHERE_DIM ] );
0134     %
0135     G                  = atmdata_regrid( G, {grids{1:dim}}, vname );
0136     vmr_field(i,:,:,:) = G.DATA;
0137   end
0138 
0139   
0140 %- For 2D we perform repeated 1D regridding
0141 %
0142 else
0143   %
0144   for i = 1 : ns
0145     vname = sprintf( 'Q.ABS_SPECIES(%d).ATMDATA', i );
0146     G     = qarts_get_gformat( Q.ABS_SPECIES(i).ATMDATA );
0147     %
0148     if strict_assert
0149        rqre_datatype( G, @isatmdata, vname );
0150     end
0151     %
0152     % Minimum dimension for interpolation is Q.ATMOSPHERE_DIM
0153     dim = max( [ G.DIM Q.ATMOSPHERE_DIM ] );
0154     %
0155     for j = 1 : length( lat_true )
0156       grids{2}         = lat_true(j);
0157       grids{3}         = lon_true(j);
0158       Gtemp                = atmdata_regrid( G, {grids{1:dim}}, vname );
0159       vmr_field(i,:,j) = Gtemp.DATA;
0160     end
0161   end
0162 end
0163   
0164     
0165

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