Home > atmlab > gformat > griddedfield2gf.m

griddedfield2gf

PURPOSE ^

GRIDDEDFIELD2GF CREATES A STANDARD GFORMAT OF A GRIDDED FIELD

SYNOPSIS ^

function G = griddedfield2gf( GF, name, type )

DESCRIPTION ^

 GRIDDEDFIELD2GF   CREATES A STANDARD GFORMAT OF A GRIDDED FIELD

   Takes in a arts GriddedField format and creates a Gformat 
   structure of it. 

 NOTE: To import directly from an xml file use gf_artsxml instead

 FORMAT   G = griddedfield2gf( GF [, name, type ] )
        
 OUT   G       Gformat structure
 IN    GF      Arts GriddedField structure
 OPT   name    Name of data. Will replace with is read from file if not
               empty. Default is [].
       type    Type of data. Default is []. Recognised options are
                  'vmr_field' : volume mixing ratio field
                  't_field'   : temperature (atmospheric) field
                  'z_field'   : altitude (atmospheric) field
                  'mag_field' : magnetic  field
                  'wind_field': wind field

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

DOWNLOAD ^

griddedfield2gf.m

SOURCE CODE ^

0001 % GRIDDEDFIELD2GF   CREATES A STANDARD GFORMAT OF A GRIDDED FIELD
0002 %
0003 %   Takes in a arts GriddedField format and creates a Gformat
0004 %   structure of it.
0005 %
0006 % NOTE: To import directly from an xml file use gf_artsxml instead
0007 %
0008 % FORMAT   G = griddedfield2gf( GF [, name, type ] )
0009 %
0010 % OUT   G       Gformat structure
0011 % IN    GF      Arts GriddedField structure
0012 % OPT   name    Name of data. Will replace with is read from file if not
0013 %               empty. Default is [].
0014 %       type    Type of data. Default is []. Recognised options are
0015 %                  'vmr_field' : volume mixing ratio field
0016 %                  't_field'   : temperature (atmospheric) field
0017 %                  'z_field'   : altitude (atmospheric) field
0018 %                  'mag_field' : magnetic  field
0019 %                  'wind_field': wind field
0020 
0021 % 2011-02-09   Created by Ole Martin Christensen.
0022 
0023 function G = griddedfield2gf( GF, name, type )
0024 %
0025 if nargin < 2, name = []; end
0026 if nargin < 3, type = []; end
0027   
0028 if atmlab('STRICT_ASSERT')
0029   rqre_nargin( 1, 3 );
0030   rqre_datatype( GF, @isstruct );
0031   rqre_field( GF, {'name','grids','gridnames','data','dataname'},...
0032                                                               'GriddedField' ); 
0033   rqre_datatype( name, {@isempty,@ischar} ); 
0034   rqre_datatype( type, {@isempty,@ischar} ); 
0035 end
0036 
0037 G = gf2gf_sub( GF, name, type );
0038 
0039 return
0040 
0041 
0042 
0043 % This stuff in sub-function due to historical reasons:
0044 function G = gf2gf_sub( X, name, type )
0045 
0046 %- Add user provided data (using some "false" fields)
0047 %
0048 if ~isempty( name )
0049   X.name = name;
0050 end
0051 %
0052 if isempty( type )
0053   T.TYPE       = 'unknown';
0054   T.gridnames  = { [], [], [], [], [], [], [], [] };
0055   T.GRIDUNITS  = { [], [], [], [], [], [], [], [] };
0056   T.dataname   = [];
0057   T.DATAUNIT   = [];
0058 elseif strcmpi( type, 'vmr_field' )
0059   T.TYPE       = 'atmdata';
0060   T.gridnames  = { 'Pressure', 'Latitude', 'Longitude', [], 'Hour' };
0061   T.GRIDUNITS  = { 'Pa', 'deg', 'deg', '', '' };
0062   T.dataname   = 'Volume mixing ratio';
0063   T.DATAUNIT   = '-';
0064 elseif strcmpi( type, 't_field' )
0065   T.TYPE       = 'atmdata';
0066   T.gridnames  = { 'Pressure', 'Latitude', 'Longitude', [], 'Hour' };
0067   T.GRIDUNITS  = { 'Pa', 'deg', 'deg', '', '' };
0068   T.dataname   = 'Temperature';
0069   T.DATAUNIT   = 'K';
0070 elseif strcmpi( type, 'z_field' )
0071   T.TYPE       = 'atmdata';
0072   T.gridnames  = { 'Pressure', 'Latitude', 'Longitude', [], 'Hour' };
0073   T.GRIDUNITS  = { 'Pa', 'deg', 'deg', '', '' };
0074   T.dataname   = 'Altitude';
0075   T.DATAUNIT   = 'm';
0076 elseif strcmpi( type, 'mag_field' )
0077   T.TYPE       = 'atmdata';
0078   T.gridnames  = { 'Pressure', 'Latitude', 'Longitude', [], 'Hour' };
0079   T.GRIDUNITS  = { 'Pa', 'deg', 'deg', '', '' };
0080   T.dataname   = 'a magnetic component';
0081   T.DATAUNIT   = 'T';
0082 elseif strcmpi( type, 'wind_field' )
0083   T.TYPE       = 'atmdata';
0084   T.gridnames  = { 'Pressure', 'Latitude', 'Longitude', [], 'Hour' };
0085   T.GRIDUNITS  = { 'Pa', 'deg', 'deg', '', '' };
0086   T.dataname   = 'A wind component';
0087   T.DATAUNIT   = 'm/s';
0088 else 
0089   error( ['atmlab:' mfilename], ' Unknown selection for *type*.' ); 
0090 end
0091 
0092 %- Transfer to G (set only up to max "active" dimension)
0093 %
0094 G.TYPE      = T.TYPE;
0095 G.NAME      = X.name;
0096 %
0097 G.DIM       = max( find( size(X.data) > 1 ) );
0098 G.DATA      = X.data;
0099 if isempty( X.dataname )
0100   G.DATA_NAME = T.dataname;
0101 else
0102   G.DATA_NAME = X.dataname;
0103 end
0104 G.DATA_UNIT = T.DATAUNIT;
0105 %
0106 for d = 1 : G.DIM
0107   if length(X.gridnames) < d  ||  isempty( X.gridnames{d} )
0108     G = gf_set_grid( G, d, vec2col(X.grids{d}), T.gridnames{d}, ...
0109                                                              T.GRIDUNITS{d} );
0110   else    
0111     G = gf_set_grid( G, d, vec2col(X.grids{d}), X.gridnames{d}, ...
0112                                                              T.GRIDUNITS{d} );
0113   end
0114 end
0115 
0116 return

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