Home > atmlab > arts > various > arts_write_linefile.m

arts_write_linefile

PURPOSE ^

------------------------------------------------------------------------

SYNOPSIS ^

function arts_write_linefile( filename, L, do_quanta, do_source, do_append )

DESCRIPTION ^

------------------------------------------------------------------------
 NAME:     arts_write_linefile

           Creates a line file in the ARTS format.

           The line data shall be given by an array of structures. The
           field names of the structures shall equal the label name of
           the table in absorption.h defining the ARTS line format.
           The field names are throughout in lower case.
           No unit conversions are performed, thus the data shall have 
           the same unit as in the line file.

 FORMAT:   arts_write_linefile( filename, L [, do_quanta, do_source, do_append ])

 OUT:      -
 IN:       filename   Name on file to create.
           L          Structure array with line data (see above)
 OPTIONAL: do_quanta  Flag for writing of quantum data. Default is 1. 
           do_source  Flag for writing of source information. Default is 1.
           do_append  Flag for appending to an existing file instead of
                      creating a new file. Default is 0.
------------------------------------------------------------------------

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

arts_write_linefile.m

SOURCE CODE ^

0001 %------------------------------------------------------------------------
0002 % NAME:     arts_write_linefile
0003 %
0004 %           Creates a line file in the ARTS format.
0005 %
0006 %           The line data shall be given by an array of structures. The
0007 %           field names of the structures shall equal the label name of
0008 %           the table in absorption.h defining the ARTS line format.
0009 %           The field names are throughout in lower case.
0010 %           No unit conversions are performed, thus the data shall have
0011 %           the same unit as in the line file.
0012 %
0013 % FORMAT:   arts_write_linefile( filename, L [, do_quanta, do_source, do_append ])
0014 %
0015 % OUT:      -
0016 % IN:       filename   Name on file to create.
0017 %           L          Structure array with line data (see above)
0018 % OPTIONAL: do_quanta  Flag for writing of quantum data. Default is 1.
0019 %           do_source  Flag for writing of source information. Default is 1.
0020 %           do_append  Flag for appending to an existing file instead of
0021 %                      creating a new file. Default is 0.
0022 %------------------------------------------------------------------------
0023 
0024 % HISTORY:  040908  Copied to Atmlab from AMI by PE.
0025 %           020101  Created by Patrick Eriksson (PE).
0026 
0027 
0028 function arts_write_linefile( filename, L, do_quanta, do_source, do_append )
0029 
0030 
0031 if ~exist('do_quanta','var'),   do_quanta = 0;   end
0032 if ~exist('do_source','var'),   do_source = 0;   end
0033 if ~exist('do_append','var'),   do_append = 0;   end
0034 
0035 
0036 %=== Present version number
0037 %
0038 vers = 3;
0039 
0040 
0041 %=== Open the file
0042 if do_append   
0043   fid = fopen( filename, 'a' );
0044 else
0045   fid = fopen( filename, 'w' );
0046 end
0047 if fid < 0
0048   error(sprintf('The file %s could not be opened.',filename));
0049 end
0050 
0051 
0052 %=== Write version number
0053 %
0054 if ~do_append
0055   fprintf(fid, 'ARTSCAT-%d\n', vers );
0056 end
0057 
0058 
0059 %=== Write data
0060 %
0061 for i = 1:length(L)
0062 
0063   fprintf(fid, '@ %s',   L{i}.name );
0064   fprintf(fid, ' %.9e',  L{i}.f );
0065   if L{i}.psf == 0
0066     fprintf(fid, ' 0');
0067   else  
0068     fprintf(fid, ' %.e',  L{i}.psf );
0069   end
0070   fprintf(fid, ' %e',  L{i}.i0 );
0071   fprintf(fid, ' %f',  L{i}.t_i0 );
0072   fprintf(fid, ' %e',  L{i}.elow );
0073   fprintf(fid, ' %f',  L{i}.agam );
0074   fprintf(fid, ' %f',  L{i}.sgam );
0075   fprintf(fid, ' %f',  L{i}.nair );
0076   fprintf(fid, ' %f',  L{i}.nself );
0077   fprintf(fid, ' %f',  L{i}.t_gam );
0078   fprintf(fid, ' %d',  L{i}.n_aux );
0079   for j = 1:L{i}.n_aux
0080     fprintf(fid, ' %e',  eval(['L{i}.aux',int2str(j)]) );
0081   end
0082   if L{i}.df < 0
0083     fprintf(fid, ' %f',  L{i}.df );
0084   else
0085     fprintf(fid, ' %e',  L{i}.df );
0086   end
0087   if L{i}.di0 < 0
0088     fprintf(fid, ' %f',  L{i}.di0 );
0089   else
0090     fprintf(fid, ' %f',  L{i}.di0 );
0091   end
0092   if L{i}.dagam < 0
0093     fprintf(fid, ' %f',  L{i}.dagam );
0094   else
0095     fprintf(fid, ' %f',  L{i}.dagam );
0096   end
0097   if L{i}.dsgam < 0
0098     fprintf(fid, ' %f',  L{i}.dsgam );
0099   else
0100     fprintf(fid, ' %f',  L{i}.dsgam );
0101   end
0102   if L{i}.dnair < 0
0103     fprintf(fid, ' %f',  L{i}.dnair );
0104   else
0105     fprintf(fid, ' %f',  L{i}.dnair );
0106   end
0107   if L{i}.dnself < 0
0108     fprintf(fid, ' %f',  L{i}.dnself );
0109   else
0110     fprintf(fid, ' %f',  L{i}.dnself );
0111   end
0112   if L{i}.dpsf < 0
0113     fprintf(fid, ' %f',  L{i}.dpsf );
0114   else
0115     fprintf(fid, ' %f',  L{i}.dpsf );
0116   end
0117 
0118   if do_quanta  &  isfield( L{i}, 'qcode' )
0119     fprintf(fid, ' "%s"',  L{i}.qcode );
0120     fprintf(fid, ' "%s"',  L{i}.qlower );
0121     fprintf(fid, ' "%s"',  L{i}.qupper );
0122 
0123     if do_source  &  isfield( L{i}, 'if' )
0124       fprintf(fid, ' "%s"',  L{i}.if );
0125       fprintf(fid, ' "%s"',  L{i}.ii0 );
0126       fprintf(fid, ' "%s"',  L{i}.ilw );
0127       fprintf(fid, ' "%s"',  L{i}.ipsf );
0128       fprintf(fid, ' "%s"',  L{i}.iaux );
0129     end
0130   end
0131 
0132   fprintf(fid, '\n');
0133 
0134 end
0135 
0136 
0137 %=== Close the file
0138 fclose( fid );

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