Home > atmlab > arts > scenegen > asg2q.m

asg2q

PURPOSE ^

ASG2Q Maps ASG data to qarts structure

SYNOPSIS ^

function Q = asg2q( G, Q, workfolder )

DESCRIPTION ^

 ASG2Q   Maps ASG data to qarts structure

    The function searches the input gformat data and sets corresponding qarts
    fields. Data type is primarily determined by the field NAME, as follows:

        NAME                  ARTS variable
        ----                  ----
        temperature           t_field
        altitude              z_field
        vmr                   vmr_field
        volume mixing ratio   vmr_field
        geoid radius          r_geoid
        surface altitude      z_surface

    The NAME text string can include uppercase lettters. Not all these
    variables must be covered. There can only exist one element in G that 
    gives a match, beside for vmr data. 

    For vmr, each match adds a species to ABS_SPECIES. For such cases, G
    must contain the field TAG that must match ABS_SPECIES.TAG directly.
    ABS_SPECIES.RETRIEVE is set to false.


 FORMAT   Q = asg2q( G, Q, workfolder )
        
 OUT   Q            Qarts structure with some fields set.
 IN    G            ASG data.
       Q            Original qarts structure.
       workfolder   Folder where created files shall be saved.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

asg2q.m

SOURCE CODE ^

0001 % ASG2Q   Maps ASG data to qarts structure
0002 %
0003 %    The function searches the input gformat data and sets corresponding qarts
0004 %    fields. Data type is primarily determined by the field NAME, as follows:
0005 %
0006 %        NAME                  ARTS variable
0007 %        ----                  ----
0008 %        temperature           t_field
0009 %        altitude              z_field
0010 %        vmr                   vmr_field
0011 %        volume mixing ratio   vmr_field
0012 %        geoid radius          r_geoid
0013 %        surface altitude      z_surface
0014 %
0015 %    The NAME text string can include uppercase lettters. Not all these
0016 %    variables must be covered. There can only exist one element in G that
0017 %    gives a match, beside for vmr data.
0018 %
0019 %    For vmr, each match adds a species to ABS_SPECIES. For such cases, G
0020 %    must contain the field TAG that must match ABS_SPECIES.TAG directly.
0021 %    ABS_SPECIES.RETRIEVE is set to false.
0022 %
0023 %
0024 % FORMAT   Q = asg2q( G, Q, workfolder )
0025 %
0026 % OUT   Q            Qarts structure with some fields set.
0027 % IN    G            ASG data.
0028 %       Q            Original qarts structure.
0029 %       workfolder   Folder where created files shall be saved.
0030 
0031 % 2010-01-25   Created by Patrick Eriksson
0032 
0033 
0034 function Q = asg2q( G, Q, workfolder )
0035 
0036 %- Basic checks of input                                                    %&%
0037 %                                                                           %&%
0038 rqre_nargin( 3, nargin );                                                   %&%
0039 if isempty(workfolder)  |  ~exist(workfolder,'dir')                         %&%
0040   error( 'Empty or not existing folder in *workfolder*.' );                 %&%
0041 end                                                                         %&%
0042                                                                             %&%
0043                                                                             %&%
0044 %- Check that atmospheric grids are set                                     %&%
0045 %                                                                           %&%
0046 if ~qarts_isset( Q.ATMOSPHERE_DIM )                                         %&%
0047   error( 'Q.ATMOSPHERE_DIM must be set.' );                                 %&%
0048 end                                                                         %&%
0049 if ~qarts_isset( Q.P_GRID )                                                 %&%
0050   error( 'Q.P_GRID must be set.' );                                         %&%
0051 end                                                                         %&%
0052 %                                                                           %&%
0053 dim    = qarts_get( Q.ATMOSPHERE_DIM );
0054 p_grid = qarts_get( Q.P_GRID );
0055 np     = length( p_grid );
0056 %                                                                           %&%
0057 rqre_in_range( dim, 1, 3, 'Q.ATMOSPHERE_DIM' );                             %&%
0058 if ~istensor1(p_grid)  |  np < 2                                            %&%
0059   error( 'Q.P_GRID must be a tensor1 with length > 1.' );                   %&%
0060 end                                                                         %&%
0061 %                                                                           %&%
0062 if dim >= 2 
0063   if ~qarts_isset( Q.LAT_GRID )                                             %&%
0064     error( 'Q.LAT_GRID must be set.' );                                     %&%
0065   end                                                                       %&%
0066   %lat_grid = qarts_grid( Q.LAT_GRID );
0067   lat_grid = Q.LAT_GRID;
0068   nlat     = length( lat_grid );  
0069   if ~istensor1(lat_grid)  |  nlat < 2                                      %&%
0070     error( 'Q.LAT_GRID must be a tensor1 with length > 1.' );               %&%
0071   end                                                                       %&%
0072   if Q.ATMOSPHERE_DIM >= 3 
0073     if ~qarts_isset( Q.LON_GRID )                                           %&%
0074       error( 'Q.LON_GRID must be set.' );                                   %&%
0075     end                                                                     %&%
0076     %lon_grid = qarts_grid( Q.LON_GRID );
0077     lon_grid = Q.LON_GRID;
0078     nlon     = length( lon_grid );  
0079     if ~istensor1(lon_grid)  |  nlon < 2                                    %&%
0080       error( 'Q.LON_GRID must be a tensor1 with length > 1.' );             %&%
0081     end                                                                     %&%
0082   end
0083 end
0084 
0085 
0086 %- Determine expected variable sizes
0087 %
0088 if Q.ATMOSPHERE_DIM == 1
0089   sfield = [ np    1    1    1 ];
0090   ssurf  = [ 1     1    1    1 ];
0091 elseif Q.ATMOSPHERE_DIM == 2
0092   sfield = [ np   nlat  1    1 ];
0093   ssurf  = [ 1    nlat  1    1 ];
0094 else
0095   sfield = [ np   nlat nlon  1 ];
0096   ssurf  = [ 1    nlat nlon  1 ];
0097 end
0098 
0099 
0100 
0101 %--- Clear sky profiles -------------------------------------------------------
0102 
0103 %- t_field
0104 %
0105 i = find( strncmp( lower({G.NAME}), 'temperature', 11 ) );
0106 %
0107 if ~isempty(i)
0108   if length(i) > 1                                                          %&%
0109     error('Multiple matches between G.NAME and ''temperature'' was found'); %&%
0110   end                                                                       %&%
0111   if G(i).DIM ~= dim                                                        %&%
0112     error( sprintf('Wrong dimension of G(%d).',i) );                        %&%
0113   end                                                                       %&%
0114   s = [ size(G(i).DATA) 1 1 ];                                              %&%
0115   if any( s(1:4) ~= sfield )                                                %&%
0116     error( sprintf('Wrong size of G(%d).DATA',i) );                         %&%
0117   end                                                                       %&%
0118   %                                                                         %&%
0119   Q.T_FIELD = fullfile( workfolder, 't_field.xml' );
0120   xmlStore( Q.T_FIELD, G(i).DATA, 'Tensor3' );
0121   %
0122 end
0123 
0124 
0125 %- z_field
0126 %
0127 i = min( find( strncmp( lower({G.NAME}), 'altitude', 8 ) ) );
0128 %
0129 if ~isempty(i)
0130   if length(i) > 1                                                          %&%
0131     error('Multiple matches between G.NAME and ''altitude'' was found');    %&%
0132   end                                                                       %&%
0133   if G(i).DIM ~= dim                                                        %&%
0134     error( sprintf('Wrong dimension of G(%d).',i) );                        %&%
0135   end                                                                       %&%
0136   s = [ size(G(i).DATA) 1 1 ];                                              %&%
0137   if any( s(1:4) ~= sfield )                                                %&%
0138     error( sprintf('Wrong size of G(%d).DATA',i) );                         %&%
0139   end                                                                       %&%
0140   %                                                                         %&%
0141   Q.Z_FIELD = fullfile( workfolder, 'z_field.xml' );
0142   xmlStore( Q.Z_FIELD, G(i).DATA, 'Tensor3' );
0143   %
0144 end
0145 
0146 
0147 
0148 %- vmr_field
0149 %
0150 %ind = find( strcmp( lower({G.DATA_NAME}), {'vmr' 'volume mixing ratio'} ) );
0151 ind = find( strcmp( lower({G.DATA_NAME}), {'volume mixing ratio'} ) );
0152 %
0153 if ~isempty(ind)
0154   %
0155   vmr_field = zeros( [ length(ind) sfield ] );
0156   %
0157   for i = 1 : length(ind)
0158     if G(ind(i)).DIM ~= dim                                                 %&%
0159       error( sprintf('Wrong dimension of G(%d).',ind(i)) );                 %&%
0160     end                                                                     %&%
0161     s = [ size(G(ind(i)).DATA) 1 1 ];                                       %&%
0162     if any( s(1:4) ~= sfield )                                              %&%
0163       error( sprintf('Wrong size of G(%d).DATA',ind(i)) );                  %&%
0164     end                                                                     %&%
0165     %                                                                       %&%
0166     vmr_field(i,:,:,:)        = G(ind(i)).DATA;
0167     if i==1
0168        Q.ABS_SPECIES=[];
0169     end
0170     Q.ABS_SPECIES(i).TAG      = G(ind(i)).PROPS;
0171     Q.ABS_SPECIES(i).RETRIEVE = false;
0172   end
0173   %
0174   Q.VMR_FIELD = fullfile( workfolder, 'vmr_field.xml' );
0175   xmlStore( Q.VMR_FIELD, vmr_field, 'Tensor4' );
0176   %
0177 end
0178 
0179 
0180 
0181 
0182 
0183 %--- Surface and geoid -----------------------------------------------------
0184 
0185 %- r_geiod
0186 %
0187 i = find( strcmp( lower({G.NAME}), 'geoid radius' ) );
0188 %
0189 if ~isempty(i)
0190   if length(i) > 1                                                          %&%
0191     error('Multiple matches between G.NAME and ''geoid radius'' was found');%&%
0192   end                                                                       %&%
0193   if G(i).DIM ~= dim-1                                                      %&%
0194     error( sprintf('Wrong dimension of G(%d).',i) );                        %&%
0195   end                                                                       %&%
0196   s = [ size(G(i).DATA) 1 1 ];                                              %&%
0197   if any( s(1:4) ~= ssurf )                                                 %&%
0198     error( sprintf('Wrong size of G(%d).DATA',i) );                         %&%
0199   end                                                                       %&%
0200   %                                                                         %&%
0201   Q.R_GEOID = fullfile( workfolder, 'r_geoid.xml' );
0202   xmlStore( Q.R_GEOID, G(i).DATA, 'Matrix' );
0203   %
0204 end
0205 
0206 
0207 %- z_surface
0208 %
0209 i = min( find( strcmp( lower({G.NAME}), 'surface altitude' ) ) );
0210 %
0211 if ~isempty(i)
0212   if length(i) > 1                                                          %&%
0213     error( ...                                                              %&%
0214       'Multiple matches between G.NAME and ''surface altitude'' was found');%&%
0215   end                                                                       %&%
0216   if G(i).DIM ~= dim-1                                                      %&%
0217     error( sprintf('Wrong dimension of G(%d).',i) );                        %&%
0218   end                                                                       %&%
0219   s = [ size(G(i).DATA) 1 1 ];                                              %&%
0220   if any( s(1:4) ~= ssurf )                                                 %&%
0221     error( sprintf('Wrong size of G(%d).DATA',i) );                         %&%
0222   end                                                                       %&%
0223   %                                                                         %&%
0224   Q.Z_SURFACE = fullfile( workfolder, 'z_surface.xml' );
0225   xmlStore( Q.Z_SURFACE, G(i).DATA, 'Matrix' );
0226   %
0227 end
0228 
0229 
0230 %--- Cloud box variables -----------------------------------------------------
0231 
0232 ind = find( strncmp( lower({G.DATA_NAME}), 'particle', 8 ) );
0233 %
0234 
0235 if ~isempty(ind)
0236   Q.CLOUDBOX_DO        = true;
0237   Q.CLOUDBOX.PND_FIELD = [];
0238   Q.CLOUDBOX.SCAT_DATA = [];
0239   %
0240   for i = 1 : length(ind)
0241     if G(ind(i)).DIM ~= dim                                                 %&%
0242       error( sprintf('Wrong dimension of G(%d).',ind(i)) );                 %&%
0243     end                                                                     %&%
0244     s = [ size(G(ind(i)).DATA) 1 1 ];                                       %&%
0245     if any( s(1:4) ~= sfield )                                              %&%
0246       error( sprintf('Wrong size of G(%d).DATA',ind(i)) );                  %&%
0247     end                                                                     %&%
0248     %
0249     Q.CLOUDBOX.SCAT_DATA{i} = ...
0250                          fullfile( workfolder, sprintf('scat_data%d.xml',i) );
0251     xmlStore( Q.CLOUDBOX.SCAT_DATA{i}, G(ind(i)).PROPS, ...
0252                                                      'SingleScatteringData' );
0253     Q.CLOUDBOX.PND_FIELD{i} = ...
0254                      fullfile( workfolder, sprintf('pnd_field_raw%d.xml',i) );
0255     A.data= G(ind(i)).DATA;
0256     A.grids{1}= G(ind(i)).GRID1;
0257     A.grids{2}= G(ind(i)).GRID2;
0258     A.grids{3}= G(ind(i)).GRID3;
0259     A.gridnames{1}='pressure';
0260     A.gridnames{2}='latitude';
0261     A.gridnames{3}='longitude';
0262     xmlStore(Q.CLOUDBOX.PND_FIELD{i},A,'GriddedField3');  
0263  end
0264 
0265 else
0266  Q.CLOUDBOX_DO        = false;
0267 end
0268 
0269 
0270 
0271 
0272

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