Home > atmlab > arts > arts_tgs_cnvrt.m

arts_tgs_cnvrt

PURPOSE ^

ARTS_TGS_CNVRT Convert species tag information

SYNOPSIS ^

function b = arts_tgs_cnvrt( a )

DESCRIPTION ^

 ARTS_TGS_CNVRT   Convert species tag information 

    The function convert species tag data between Atmlab and ARTS
    formats. The ARTS format is a string, with each group inside 
    " " and group items seperated with commas. Tags are stored in Atmlab
    as string arrays, such as a = {ClO}. For example,
       b = arts_tgs_cnvrt({'H2O-*-490e9-510e9','H2O-PWR98'})
    gives
       b = '"H2O-*-490e9-510e9,H2O-PWR98"';
    
    The function handles also definition of multiple species. The data must
    then be packed into the field 'TAG' of a structure array:  
       a.TAG{1} = 'ClO';
       a.TAG{1} = 'O3';
       a,TAG{1} = 'H2O';
       a.TAG{2} = 'H2O-MPM89';
    which results in the string
       '"ClO","O3","H2O,H2O-MPM89"'

    The conversion from ARTS to atmlab format produces always the later 
    format (a.TAG).

    The function performs conversion in both directions, where the input
    format is determined by the type of the input argument *a*.

 FORMAT   b = arts_tgs_cnvrt( a )
        
 OUT   b   Species tag data information in output format.
 IN    a   Species tag data information in input format.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

arts_tgs_cnvrt.m

SOURCE CODE ^

0001 % ARTS_TGS_CNVRT   Convert species tag information
0002 %
0003 %    The function convert species tag data between Atmlab and ARTS
0004 %    formats. The ARTS format is a string, with each group inside
0005 %    " " and group items seperated with commas. Tags are stored in Atmlab
0006 %    as string arrays, such as a = {ClO}. For example,
0007 %       b = arts_tgs_cnvrt({'H2O-*-490e9-510e9','H2O-PWR98'})
0008 %    gives
0009 %       b = '"H2O-*-490e9-510e9,H2O-PWR98"';
0010 %
0011 %    The function handles also definition of multiple species. The data must
0012 %    then be packed into the field 'TAG' of a structure array:
0013 %       a.TAG{1} = 'ClO';
0014 %       a.TAG{1} = 'O3';
0015 %       a,TAG{1} = 'H2O';
0016 %       a.TAG{2} = 'H2O-MPM89';
0017 %    which results in the string
0018 %       '"ClO","O3","H2O,H2O-MPM89"'
0019 %
0020 %    The conversion from ARTS to atmlab format produces always the later
0021 %    format (a.TAG).
0022 %
0023 %    The function performs conversion in both directions, where the input
0024 %    format is determined by the type of the input argument *a*.
0025 %
0026 % FORMAT   b = arts_tgs_cnvrt( a )
0027 %
0028 % OUT   b   Species tag data information in output format.
0029 % IN    a   Species tag data information in input format.
0030 
0031 % 2004-09-08   Created by Patrick Eriksson.
0032 
0033 
0034 function b = arts_tgs_cnvrt( a )
0035 %                                                                      %&%
0036 rqre_datatype( a, {@iscellstr,@isstruct,@ischar} );                    %&%
0037 
0038 
0039 
0040 if iscellstr( a )
0041   %
0042   b = '"';
0043   for i = 1 : length(a)-1
0044     b = sprintf( '%s%s,', b, a{i} );
0045   end
0046   b = sprintf( '%s%s"', b, a{end} );
0047 
0048 elseif isstruct( a )
0049   %                                                                    %&%
0050   if ~isfield( a, 'TAG' )                                              %&%
0051     error( 'If *a* is a structure, it must have the field ''TAG''.' ); %&%
0052   end                                                                  %&%
0053   %
0054   b = '';
0055   for i = 1 : length(a)-1
0056     b = sprintf( '%s%s,', b, arts_tgs_cnvrt( a(i).TAG ) );
0057   end
0058   b = sprintf( '%s%s', b, arts_tgs_cnvrt( a(end).TAG ) );
0059 
0060 else
0061   %
0062   ind = find( a == '"' );
0063   if isodd( length(ind) )                                              %&%
0064     error( ...                                                         %&%
0065     'This is not a valid ARTS species tag string (odd number of ").'); %&%
0066   end
0067   %
0068   for i = 1 : 2 : length(ind)
0069     s = a( (ind(i)+1) : (ind(i+1)-1) );
0070     ind2 = [0 find( s == ',' ) length(s)+1];
0071     for j = 1 : (length(ind2)-1)
0072       b(round(0.5+i/2)).TAG{j} = s( (ind2(j)+1) : (ind2(j+1)-1) );
0073     end
0074   end
0075 end

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