Home > atmlab > retrieval > qpack2 > qp2_rel2vmr.m

qp2_rel2vmr

PURPOSE ^

QP2_REL2VMR Convert 'rel' or 'logrel' data to VMR

SYNOPSIS ^

function L2 = qp2_rel2vmr(L2)

DESCRIPTION ^

 QP2_REL2VMR  Convert 'rel' or 'logrel' data to VMR

    If one or several absorption species have been retrieved with 'rel' or
    'logrel' as unit, but prefer to have the L2 data as VMR values, this
    function makes the conversion.
    
    The L2 data must contain the a priori state (species1_xa etc.). This field
    is used to determine the retrieval unit used. A field holding the a priori
    VMR (species1_vmr0 etc.) must also exist (added automatically by
    *qp2_l2*). After the conversion, the a priori field (xa) is modified and
    the VMR field is removed.

    IMPORTANT: Only fields starting with "species" are treated. This means
    that e.g. the Jacobian (J) and covariance matrices are not converted.
    Averaging kernels are converted as they are stored separately among the
    species. 

    Note that if L2_RANGE has been used to include parts outside the range of
    the retrieval grids, the obtained VMR profile is not representing those
    parts correctly (the L2 data will only have a straight line for those
    parts). 

    For 'logrel', errors are converted simply as e_vmr = e*x_vmr.

 FORMAT   L2 = qp2_rel2vmr( L2 )
        
 OUT      L2   Modified L2 data structure.
 IN       L2   Original L2 data structure.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

qp2_rel2vmr.m

SOURCE CODE ^

0001 % QP2_REL2VMR  Convert 'rel' or 'logrel' data to VMR
0002 %
0003 %    If one or several absorption species have been retrieved with 'rel' or
0004 %    'logrel' as unit, but prefer to have the L2 data as VMR values, this
0005 %    function makes the conversion.
0006 %
0007 %    The L2 data must contain the a priori state (species1_xa etc.). This field
0008 %    is used to determine the retrieval unit used. A field holding the a priori
0009 %    VMR (species1_vmr0 etc.) must also exist (added automatically by
0010 %    *qp2_l2*). After the conversion, the a priori field (xa) is modified and
0011 %    the VMR field is removed.
0012 %
0013 %    IMPORTANT: Only fields starting with "species" are treated. This means
0014 %    that e.g. the Jacobian (J) and covariance matrices are not converted.
0015 %    Averaging kernels are converted as they are stored separately among the
0016 %    species.
0017 %
0018 %    Note that if L2_RANGE has been used to include parts outside the range of
0019 %    the retrieval grids, the obtained VMR profile is not representing those
0020 %    parts correctly (the L2 data will only have a straight line for those
0021 %    parts).
0022 %
0023 %    For 'logrel', errors are converted simply as e_vmr = e*x_vmr.
0024 %
0025 % FORMAT   L2 = qp2_rel2vmr( L2 )
0026 %
0027 % OUT      L2   Modified L2 data structure.
0028 % IN       L2   Original L2 data structure.
0029 
0030 % 2012-02-07   Created by Patrick Eriksson.
0031 
0032 function L2 = qp2_rel2vmr(L2)
0033   
0034 i     = 0;
0035 ready = false;
0036 
0037 while ~ready
0038   
0039   i = i + 1;
0040   
0041   nx = sprintf( 'species%d_x', i );
0042   
0043   if ~isfield( L2, nx )
0044     ready = true;
0045   
0046   else
0047     
0048     % Define name strings
0049     %
0050     na = sprintf( 'species%d_xa', i );
0051     nv    = sprintf( 'species%d_vmr0', i );
0052     nA    = sprintf( 'species%d_A', i );
0053     nmr   = sprintf( 'species%d_mr', i );
0054     ns{1} = sprintf( 'species%d_e', i );
0055     ns{2} = sprintf( 'species%d_eo', i );
0056     ns{3} = sprintf( 'species%d_es', i );
0057     nsx   = sprintf( 'species%d_ex', i );
0058     
0059     rqre_field( L2, nv, 'sub-field vmr0' );
0060 
0061     if isfield( L2, nmr )  &  ~isfield( L2, nA )
0062       error( 'Handling of measurement response requires that A is part of L2' );
0063     end
0064 
0065     
0066     % Retrieval unit determined for each L2 element, to be safe
0067     
0068     for j = 1: length(L2)
0069 
0070       % Use xa to determine retrieval unit
0071       %
0072       xa = L2(j).(na);
0073       %
0074       rel    = false;
0075       logrel = false;
0076       mval   = max(xa);
0077       %
0078       if mval == 0
0079         logrel = true;
0080       elseif mval < 1
0081         % VMR
0082       elseif mval == 1  &  min(xa) == 1
0083         rel = true;
0084       end  % Remaining option mval>1 equals nd
0085     
0086       % Ready if VMR or ND
0087 
0088       if rel | logrel  
0089     
0090         vmr0       = L2(j).(nv);
0091 
0092         % rel
0093         if rel
0094           L2(j).(nx) = L2(j).(nx) .* vmr0;
0095           L2(j).(na) = vmr0;
0096           %
0097           if isfield( L2, nA )
0098             L2(j).(nA) = L2(j).(nA) .* (vmr0*(1./vmr0'));
0099             if isfield( L2, nmr )
0100               L2(j).(nmr) = mrespA( L2(j).(nA), [1 length(vmr0)] );
0101             end
0102           end
0103           %
0104           for k = 1 : length(ns)
0105             if isfield( L2, ns{k} )
0106               L2(j).(ns{k}) = L2(j).(ns{k}) .* vmr0;
0107             end
0108           end
0109           %
0110           if isfield( L2, nsx )
0111             L2(j).(nsx) = L2(j).(nsx) .* vmr0;
0112           end
0113 
0114           
0115         % logrel
0116         else
0117           L2(j).(nx) = exp(L2(j).(nx)) .* vmr0;
0118           L2(j).(na) = vmr0;
0119           %
0120           if isfield( L2, nA )
0121             L2(j).(nA) = L2(j).(nA) .* (L2(j).(nx)*(1./L2(j).(nx)'));
0122             if isfield( L2, nmr )
0123               L2(j).(nmr) = mrespA( L2(j).(nA), [1 length(vmr0)] );
0124             end
0125           end
0126           %
0127           for k = 1 : length(ns)
0128             if isfield( L2, ns{k} )
0129               L2(j).(ns{k}) = L2(j).(ns{k}) .* L2(j).(nx);
0130             end
0131           end
0132           %
0133           if isfield( L2, nsx )
0134             L2(j).(nsx) = L2(j).(nsx) .* vmr0;
0135           end
0136         end
0137 
0138       end  
0139     end  
0140     
0141     L2 = rmfield( L2, nv );
0142 
0143   end   % if "species exist"
0144 end   % while

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