The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....



ExportAsASC


Unit:SDL_matrix
Class: TMatrix, TIntMatrix
Declaration: [1] function ExportAsASC (FName: string; Precision: integer; Comment: string): integer; { class TMatrix }
[2] function ExportAsASC (FName: string; Precision: integer; Comment: string; CustData: TStr2DArray): Integer; { class TMatrix }

[1] function ExportAsASC (FName: string; Comment: string): integer; { class TIntMatrix }
[2] function ExportAsASC (FName: string; Comment: string; CustData: TStr2DArray): Integer; { class TIntMatrix }

The method ExportAsASC writes the contents of the matrix along with all additional information (headers, etc.) to a readable ASCII text. The format of the text is the same as used by the method ImportASC. Version [2] additionally exports user-defined data which are stored in the parameter CustData. CustData has to be a two-column string array containing the name of a particular user item in the first column and its value in the second column. CustData can have any number of rows.

The method returns the following error codes:

 0 ... everything is OK
-1 ... a problem occurred during opening the file (e.g. 'file access denied' for read-only files
-2 ... the custom data array CustData does not have two columns

The parameter Precision (in the case of TMatrix) specifies the number of decimal places to be used in the text file. Note that the numeric values of a table will be altered if the precision for exporting is too low. The parameter Comment contains an arbitrary one-line comment.

Example: The following code snippet creates a small matrix, fills it with a constant value of 8.762813 und fills the custom data with five items called "KEY-1" to "KEY-5". The exported ASC file is shown below.
const
  NCUSTDATA = 5;
  PRECISION = 3;
  MATNCOL = 3;
  MATNROW = 6;

var
  row      : integer;
  InMat    : TMatrix;
  CustData : TStr2DArray;

begin
InMat := TMatrix.CReate(nil);
InMat.Resize (MATNCOL,MATNROW);
InMat.Fill (8.762813);
SetLength (CustData, 2, NCUSTDATA);
for row:=1 to NCUSTDATA do
  begin
  CustData[0,row-1] := 'KEY-'+IntToStr(row);
  CustData[1,row-1] := 'Value of key '+IntToStr(row);
  end;
Inmat.ExportAsAsc('c:\temp\testexpo.asc', PRECISION, 'my special comment', Custdata);
InMat.free;
end;
The generated ASC file looks like this (see the ASC format specification for details):
my special comment
3         ;nr. of columns
6         ;nr. of rows
FALSE FALSE FALSE FALSE    ;row attributes, column names, row names, nominal variables
8.763       8.763       8.763
8.763       8.763       8.763
8.763       8.763       8.763
8.763       8.763       8.763
8.763       8.763       8.763
8.763       8.763       8.763
<CUSTDATA>
<KEY-1>Value of key 1</KEY-1>
<KEY-2>Value of key 2</KEY-2>
<KEY-3>Value of key 3</KEY-3>
<KEY-4>Value of key 4</KEY-4>
<KEY-5>Value of key 5</KEY-5>
</CUSTDATA>



Last Update: 2023-Feb-06