Home > atmlab > arts > xml > xmlWriteMatrix.m

xmlWriteMatrix

PURPOSE ^

Writes a Matrix to an XML file.

SYNOPSIS ^

function xmlWriteMatrix(fid, fidb, data, precision, attrlist)

DESCRIPTION ^

 Writes a Matrix to an XML file.

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

 FORMAT   xmlWriteMatrix(fid, fidb, data, precision)

 IN    fid        File descriptor
 IN    fidb       File descriptor for binary file
 IN    data       Matrix
 IN    precision  Precision for floats

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

xmlWriteMatrix.m

SOURCE CODE ^

0001 % Writes a Matrix to an XML file.
0002 %
0003 %    Internal function that should never be called directly.
0004 %    Use *xmlStore* instead.
0005 %
0006 % FORMAT   xmlWriteMatrix(fid, fidb, data, precision)
0007 %
0008 % IN    fid        File descriptor
0009 % IN    fidb       File descriptor for binary file
0010 % IN    data       Matrix
0011 % IN    precision  Precision for floats
0012 
0013 % 2002-12-13  Created by Oliver Lemke.
0014 
0015 function xmlWriteMatrix(fid, fidb, data, precision, attrlist)
0016 
0017 if nargin < 5
0018   attrlist = [];
0019 end
0020 
0021 s = size (data);
0022 
0023 for i = (ndims (data)+1):2
0024   s(i) = 1;
0025 end
0026 
0027 nr = s(1);
0028 nc = s(2);
0029 
0030 attrlist = xmlAddAttribute (attrlist, 'nrows', sprintf ('%d', nr));
0031 attrlist = xmlAddAttribute (attrlist, 'ncols', sprintf ('%d', nc));
0032 
0033 xmlWriteTag (fid, 'Matrix', attrlist);
0034 
0035 data = reshape (data, [nr nc]);
0036 data = data';
0037 
0038 if (strcmp(precision, 'BINARY'))
0039     fwrite (fidb, data, 'double');
0040 else
0041     format=xmlGetPrecisionFormatString (precision);
0042     form=format;
0043     for i = 1:(nc-1)
0044       form = sprintf ('%s %s', form, format);
0045     end
0046     form = [form '\n'];
0047 
0048     fprintf (fid, form, data);
0049 end
0050 
0051 xmlWriteCloseTag (fid, 'Matrix');
0052 
0053 clear attrlist form format nr nc;
0054

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