Home > atmlab > arts > xml > xmlReadArrayOfLineRecord.m

xmlReadArrayOfLineRecord

PURPOSE ^

Reads an ARTS cataloguefrom an XML file.

SYNOPSIS ^

function result = xmlReadArrayOfLineRecord(fid,attrlist,itype,ftype,binary,fid2)

DESCRIPTION ^

 Reads an ARTS cataloguefrom an XML file.

    Internal function that should never be called directly.
    Use *xmlLoad* instead.

 FORMAT   result = xmlReadArrayOfLineRecord(fid,attrlist,itype,ftype,binary,fid2)

 OUT   result     Array
 IN    fid        File descriptor of XML file
 IN    attrlist   List of tag attributes
 IN    itype      Integer type of input file
 IN    ftype      Floating point type of input file
 IN    binary     Flag. 1 = binary file, 0 = ascii
 IN    fid2       File descriptor of binary file

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

DOWNLOAD ^

xmlReadArrayOfLineRecord.m

SOURCE CODE ^

0001 % Reads an ARTS cataloguefrom an XML file.
0002 %
0003 %    Internal function that should never be called directly.
0004 %    Use *xmlLoad* instead.
0005 %
0006 % FORMAT   result = xmlReadArrayOfLineRecord(fid,attrlist,itype,ftype,binary,fid2)
0007 %
0008 % OUT   result     Array
0009 % IN    fid        File descriptor of XML file
0010 % IN    attrlist   List of tag attributes
0011 % IN    itype      Integer type of input file
0012 % IN    ftype      Floating point type of input file
0013 % IN    binary     Flag. 1 = binary file, 0 = ascii
0014 % IN    fid2       File descriptor of binary file
0015 
0016 % 2002-09-25   Created by Oliver Lemke.
0017 
0018 function result = xmlReadArrayOfLineRecord(fid,attrlist,itype,ftype,binary,fid2)
0019 
0020 ne = str2num (xmlGetAttrValue (attrlist, 'nelem'));
0021 
0022 %=== Some old setting varaibles
0023 %
0024 flims  = [0 Inf];
0025 sorted = 0;
0026 ilim   = 0;
0027 
0028 
0029 %=== Present version number
0030 %
0031 vers = 3;
0032 
0033 
0034 %=== Check that this is a ARTSCAT file and the version number is correct
0035 %
0036 s = xmlGetAttrValue (attrlist, 'version');
0037 
0038 %
0039 if ~strncmp( s, 'ARTSCAT-', 8 )
0040   error('An ARTS line file must start with "ARTSCAT-"');
0041 end
0042 %
0043 stest = sprintf('ARTSCAT-%d', vers );
0044 %
0045 if ~strncmp( s, stest, length(stest) )
0046   serr = sprintf('The line file has not the correct version number\n');
0047   serr = sprintf('%s(it should be %d)',serr,vers);
0048   error( serr );
0049 end
0050 
0051 
0052 
0053 %=== Read lines
0054 %
0055 S = next_line( fid );
0056 while isempty(S) & ~feof(fid)
0057   S = next_line( fid );
0058 end
0059 
0060 n     = 0;
0061 %
0062 result     = [];
0063 %
0064 while ~isempty(S)
0065 
0066   f = sscanf( S{2}, '%f' );
0067 
0068   if sorted  &  f >= flims(2)
0069     break
0070   end
0071   
0072   i0 = sscanf( S{4}, '%f' );
0073   
0074   if f >= flims(1)  &  f <= flims(2)  &  i0 >= ilim
0075     %
0076     n = n + 1;
0077     %
0078     for i = 1:length(S)
0079   
0080       switch i
0081   
0082        case 1
0083          result{n}.name = S{i};
0084         
0085        case 2
0086          result{n}.f = f;
0087      
0088        case 3
0089          result{n}.psf = sscanf( S{i}, '%f' );
0090      
0091        case 4
0092          result{n}.i0 = i0;
0093      
0094        case 5
0095          result{n}.t_i0 = sscanf( S{i}, '%f' );
0096      
0097        case 6
0098          result{n}.elow = sscanf( S{i}, '%f' );
0099      
0100        case 7
0101          result{n}.agam = sscanf( S{i}, '%f' );
0102      
0103        case 8
0104          result{n}.sgam = sscanf( S{i}, '%f' );
0105      
0106        case 9
0107          result{n}.nair = sscanf( S{i}, '%f' );
0108      
0109        case 10
0110          result{n}.nself = sscanf( S{i}, '%f' );
0111      
0112        case 11
0113          result{n}.t_gam = sscanf( S{i}, '%f' );
0114      
0115        case 12
0116          result{n}.n_aux = sscanf( S{i}, '%f' );
0117          n_aux      = result{n}.n_aux;
0118          %
0119          % Aux variables are handled below otherwise
0120      
0121        case 13 + n_aux
0122          result{n}.df = sscanf( S{i}, '%f' );
0123      
0124        case 14 + n_aux
0125          result{n}.di0 = sscanf( S{i}, '%f' );
0126      
0127        case 15 + n_aux
0128          result{n}.dagam = sscanf( S{i}, '%f' );
0129      
0130        case 16 + n_aux
0131          result{n}.dsgam = sscanf( S{i}, '%f' );
0132      
0133        case 17 + n_aux
0134          result{n}.dnair = sscanf( S{i}, '%f' );
0135      
0136        case 18 + n_aux
0137          result{n}.dnself = sscanf( S{i}, '%f' );
0138      
0139        case 19 + n_aux
0140          result{n}.dpsf = sscanf( S{i}, '%f' );
0141      
0142        case 20 + n_aux
0143          result{n}.qcode = sscanf( S{i}, '%s' );
0144      
0145        case 21 + n_aux
0146          result{n}.qlower = sscanf( S{i}, '%s' );
0147      
0148        case 22 + n_aux
0149          result{n}.qlower = sscanf( S{i}, '%s' );
0150      
0151        case 23 + n_aux
0152          result{n}.if = sscanf( S{i}, '%s' );
0153      
0154        case 24 + n_aux
0155          result{n}.ii0 = sscanf( S{i}, '%s' );
0156      
0157        case 25 + n_aux
0158          result{n}.ilw = sscanf( S{i}, '%s' );
0159      
0160        case 26 + n_aux
0161          result{n}.ipsf = sscanf( S{i}, '%s' );
0162      
0163        case 27 + n_aux
0164          result{n}.iaux = sscanf( S{i}, '%s' );
0165       
0166        otherwise
0167          %
0168          if i <= 12+n_aux
0169            eval(['result{i}.aux',int2str(i-11)]) = sscanf( S{i}, '%f' );
0170          else
0171            error(sprintf('To many fields found for line %d.',n));
0172          end
0173       end
0174     end 
0175   end
0176   %
0177   S = next_line( fid );
0178   %
0179 end
0180 
0181 if n ~= ne
0182   error('Number of lines in catalogue (%d) doesnt match nelem attribute (%d)', n, ne);
0183 end
0184 
0185 return
0186 
0187 
0188 
0189 %------------------------------------------------------------------------------
0190 
0191 function S = next_line( fid )
0192 
0193   S = [];
0194 
0195   %= Just return if EOF
0196   if feof(fid)
0197     return
0198   end
0199 
0200   %= Read next line
0201   sin = fgets( fid );
0202 
0203   %= Return if empty line
0204   if length(sin) < 2
0205     return
0206   end
0207 
0208   %= Read until next line that starts with @ and replace line feeds
0209   %= with a blank
0210   %
0211   if sin(1) ~= '@'
0212     serr = sprintf('Could not read linefile at:\n%s',sin);
0213     error( serr );
0214   end
0215   %
0216   s = [ sin( 3 : (length(sin)-1) ), ' ' ];
0217   %
0218   c1 = fscanf(fid,'%c',1);
0219   %
0220   while ~isempty(c1) & c1~='@'
0221     %
0222     fseek(fid,-1,'cof');   
0223     %
0224     sin = fgets( fid );
0225     s   = [ s, sin( 1 : (length(sin)-1) ), ' ' ];
0226     %
0227     c1 = fscanf(fid,'%c',1);
0228   end
0229 
0230   %= Back one step in the file
0231   fseek(fid,-1,'cof');   
0232 
0233   %= Field index
0234   i = 0;
0235 
0236   while 1
0237 
0238     i = i + 1;
0239 
0240     %= Text field inside " "
0241     %
0242     if s(1) == '"'
0243       %
0244       iprims = find( s == '"' );
0245       %
0246       if length(iprims) < 2
0247         error('Unmatched " found.');
0248       end
0249       %
0250       S{i} = s(2:(iprims(2)-1));
0251       %
0252       l = iprims(2);
0253 
0254     %= Closing tag reached
0255     %
0256     elseif s(1) == '<' & s(2) == '/'
0257       return
0258     %= Other field
0259     %
0260     else
0261 
0262       %= Find field seperations
0263       iblank = find( s == ' ' );
0264 
0265       %= Pick out text until first blank
0266       l    = iblank(1) - 1;    
0267       S{i} = s(1:l);
0268 
0269     end
0270 
0271     %= Remove used text
0272     s = s( (l+1):length(s) );
0273 
0274     %= Remove blanks at the start of s (if no-blanks, we are ready)
0275     ichars = find( s ~= ' ' );
0276     if isempty( ichars )
0277       return;
0278     end
0279     s = s( ichars(1):length(s) );
0280  
0281   end
0282 return
0283

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