Home > atmlab > arts > arts_abcde.m

arts_abcde

PURPOSE ^

ARTS_ABCDE Extracting selectable variables from an ARTS run

SYNOPSIS ^

function [V1,V2] = arts_abcde(Q,vnames1,vnames2,workfolder)

DESCRIPTION ^

 ARTS_ABCDE   Extracting selectable variables from an ARTS run

    The purpose of this function is to make it possible to extract any
    (or at least almost all) variable created during an ARTS run.

    A "normal" calculation is performed, corresponding to *arts_y*. Such
    an ARTS run include yCalc and calculation of jacobians (pending on
    state of Q.J). At the end of the control file, saving of the 
    variables specified in *vnames1* is added. These files are later 
    loaded into Matlab and the content is copied to the output argument
    V1.

    To extract y and ppath for the case in *qarts_demo*:

       Q = qarts_demo;
       vnames1 = {'y','z_field'};
       V1 = arts_abcde(Q,vnames1);

    First element of V1 (V1{1}) will then be y, and the second element
    z_field.

    The stuff below is presently not working, but will be updated later:

    It is also possible to extract indexed files. That is, file stored
    by the WSM WriteXMLIndexed. This is done with the second pair of
    arguments. Here the saving of the files must be included by existing
    Q fields. WriteXMLIndexed must be called with "" as keyword argument.
    First file is assumed to have number 1.    

    All this is best described by an example. To also extract the propagation
    path for each pencil beam direction used in *qarts_demo*:

       Q.PRE_RTE_WSMS{end+1} = 'IndexSet(file_index){0}';
       Q.RTE_AGENDA{end+1}   = 'IndexStep(file_index,file_index){}';
       Q.RTE_AGENDA{end+1}   = 'WriteXMLIndexed(ppath){""}';
       vnames2 = {'ppath'};
       [V1,V2] = arts_abcde(Q,vnames1,vnames2);
    
    V2{1}{i} will here be the propogation path for pencil beam i.

 FORMAT   [V1,V2] = arts_y( Q, vnames1 [,vnames2, workfolder] )
        
 OUT   V1        Array, containing the variables specied by *vnames1*.
       V2        Array of arrays, corresponding to *vnames2*.
 IN    Q         Qarts structure.
       vnames1   A string array with variable names. See further above.
 OPT   vnames2   A string array with variable names. See further above.
       workfolder   If not defined or empty, a temporary folder is created.
                    Otherwise this is interpreted as the path to a folder 
                    where calculation output can be stored. These files
                    will be left in the folder. The files are not read if
                    corresponding output argument not is considered.
                    Default is [].

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

arts_abcde.m

SOURCE CODE ^

0001 % ARTS_ABCDE   Extracting selectable variables from an ARTS run
0002 %
0003 %    The purpose of this function is to make it possible to extract any
0004 %    (or at least almost all) variable created during an ARTS run.
0005 %
0006 %    A "normal" calculation is performed, corresponding to *arts_y*. Such
0007 %    an ARTS run include yCalc and calculation of jacobians (pending on
0008 %    state of Q.J). At the end of the control file, saving of the
0009 %    variables specified in *vnames1* is added. These files are later
0010 %    loaded into Matlab and the content is copied to the output argument
0011 %    V1.
0012 %
0013 %    To extract y and ppath for the case in *qarts_demo*:
0014 %
0015 %       Q = qarts_demo;
0016 %       vnames1 = {'y','z_field'};
0017 %       V1 = arts_abcde(Q,vnames1);
0018 %
0019 %    First element of V1 (V1{1}) will then be y, and the second element
0020 %    z_field.
0021 %
0022 %    The stuff below is presently not working, but will be updated later:
0023 %
0024 %    It is also possible to extract indexed files. That is, file stored
0025 %    by the WSM WriteXMLIndexed. This is done with the second pair of
0026 %    arguments. Here the saving of the files must be included by existing
0027 %    Q fields. WriteXMLIndexed must be called with "" as keyword argument.
0028 %    First file is assumed to have number 1.
0029 %
0030 %    All this is best described by an example. To also extract the propagation
0031 %    path for each pencil beam direction used in *qarts_demo*:
0032 %
0033 %       Q.PRE_RTE_WSMS{end+1} = 'IndexSet(file_index){0}';
0034 %       Q.RTE_AGENDA{end+1}   = 'IndexStep(file_index,file_index){}';
0035 %       Q.RTE_AGENDA{end+1}   = 'WriteXMLIndexed(ppath){""}';
0036 %       vnames2 = {'ppath'};
0037 %       [V1,V2] = arts_abcde(Q,vnames1,vnames2);
0038 %
0039 %    V2{1}{i} will here be the propogation path for pencil beam i.
0040 %
0041 % FORMAT   [V1,V2] = arts_y( Q, vnames1 [,vnames2, workfolder] )
0042 %
0043 % OUT   V1        Array, containing the variables specied by *vnames1*.
0044 %       V2        Array of arrays, corresponding to *vnames2*.
0045 % IN    Q         Qarts structure.
0046 %       vnames1   A string array with variable names. See further above.
0047 % OPT   vnames2   A string array with variable names. See further above.
0048 %       workfolder   If not defined or empty, a temporary folder is created.
0049 %                    Otherwise this is interpreted as the path to a folder
0050 %                    where calculation output can be stored. These files
0051 %                    will be left in the folder. The files are not read if
0052 %                    corresponding output argument not is considered.
0053 %                    Default is [].
0054 
0055 % 2005-06-14   Created by Patrick Eriksson.
0056 
0057 
0058 function [V1,V2] = arts_abcde(Q,vnames1,vnames2,workfolder)
0059 %
0060 if nargin < 4
0061   workfolder = [];
0062 end
0063                                                                  %&%
0064                                                                  %&%
0065 %= Check input                                                   %&%
0066 %                                                                %&%
0067 rqre_nargin(2,nargin);                                           %&%
0068 %                                                                %&%
0069 rqre_datatype( Q, @isstruct );                                   %&%
0070 rqre_datatype( vnames1, @iscellstr );                            %&%
0071 if nargin >=3                                                    %&%
0072   rqre_datatype( vnames2, @iscellstr );                          %&%
0073 end                                                              %&%
0074 %                                                                %&%
0075 rqre_datatype( workfolder, {@isempty,@ischar} );                 %&%
0076 
0077 
0078 if isempty( workfolder )
0079   workfolder = create_tmpfolder;
0080   cu = onCleanup( @()delete_tmpfolder( workfolder ) );
0081 end
0082 
0083 
0084 %= Get text for control file, but remove ending '}'
0085 %
0086 parts = qarts2cfile( 'y' );
0087 S     = qarts2cfile( Q, parts, workfolder );
0088 S     = S(1:end-1);
0089 
0090 %= Add saving of variables
0091 %
0092 for i = 1:length(vnames1)
0093   filename = fullfile( workfolder, [ vnames1{i}, '.xml' ] ); 
0094   S{end+1} = sprintf('WriteXML("%s",%s,"%s")', Q.OUTPUT_FILE_FORMAT, ...
0095                                                         vnames1{i}, filename );
0096 end
0097 
0098 %= Add closing
0099 %
0100 S{end+1}  = '}';
0101 
0102 %= Create control file and run
0103 %
0104 cfile = fullfile( workfolder, 'cfile.arts' );
0105 strs2file( cfile, S );
0106 arts( cfile );
0107 
0108 
0109 %= Read stored variables
0110 %
0111 for i = 1:length(vnames1)
0112   filename = fullfile( workfolder, [ vnames1{i}, '.xml' ] ); 
0113   V1{i}     = xmlLoad( filename );
0114 end
0115 
0116 
0117 % Read numbered variables
0118 %
0119 V2 = [];
0120 %
0121 if nargin >= 3
0122   for i = 1:length(vnames2)
0123     j     = 1;
0124     ready = 0;
0125     while ~ready 
0126       filename = fullfile( workfolder, 'cfile' );
0127       filename = sprintf( '%s.%s.%d.xml', filename, vnames2{i}, j );
0128       if exist( filename, 'file' )
0129         V2{i}{j} = xmlLoad( filename );
0130         j = j + 1;
0131       else
0132         ready = 1;
0133       end
0134     end
0135   end
0136 end
0137 
0138

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