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....



Interface of SDL_DataTable


const
  DT_NameWidth = 50;                         { maximum length of col/row names }
  DT_MaxColOrRows = 2000000000 div (DT_NameWidth+1);
  DT_NominalID_Width = 10;     // maximum length of nominal/ordinal identifiers
  DT_MaxNominalIDs = 150;       // maximum number of nominal/ordinal identifiers
{$IFDEF PAIDVERS}
  SDLVersionInfo = 'datatable_r1050_full';
  IsLightEd = false;
{$ELSE}
  SDLVersionInfo = 'datatable_r1050_lighted';
  IsLightEd = true;
{$ENDIF}
  release = 1050;

  csNAN       = $01;                               { cell states: not a number }
  csUndefined = $02;                                 { undefined or empty cell }
  csUser1     = $04;                                  { user defined cell type }
  csUser2     = $08;                                  { user defined cell type }
  csUser3     = $10;                                  { user defined cell type }
  csImputed   = $20;                              { cell contains imputed data }
  csMarkedA   = $40;                                  { cell is marked, type 1 }
  csMarkedB   = $80;                                  { cell is marked, type 2 }

  csReset     = $00;                               { cell is not marked at all }
  csNone      = $00;                               { cell is not marked at all }
  csAll       = $FF;                                        { any kind of mark }

type
  TCSVDelimiters = (csvComma, csvColon, csvSemicolon, csvTab, csvUnknown);
  TMScaleType = (stUnknown, stNominal, stOrdinal, stInterval, stRatio);
  TNominalIDStr = string[DT_NominalID_Width];
  TVTypeSpec = record
                 MScaleType : TMScaleType; // measurement scale type of variable
                 IDs        : array[1..DT_MaxNominalIDs] of TNominalIDStr;
               end;
  TDTxmlTags = (xmlDataTableId, xmlDataTableEndId, xmlComment, xmlSize, xmlColNames,
                xmlRowNames, xmlColAttrib, xmlRowAttrib, xmlColId, xmlRowId, 
                xmlDataCells, xmlCellID, xmlVarType, xmlVarIdentifier, xmlInvalid);

const
  CSVDelimiters : array [TCSVDelimiters] of char =
           (',',':',';',#9, #0);
  MScaleTypeNames : array[TMScaleType] of string =
           ('Unknown', 'Nominal', 'Ordinal', 'Interval', 'Ratio');

type
  TDTNameStr = string[DT_NameWidth];                     { col/row header type }
  ESDLDataTableError = class(ESDLError);   { exception type to indicate errors }
  TDataTableResizeEvent = procedure (Sender: TObject; OldColumns, OldRows,
                                     NewColumns, NewRows: integer) of object;
  TDataTable = class(TComponent)
            private
              FOnChange       : TNotifyEvent;
              FOnChangeSetup  : TNotifyEvent;
              FOnChangeNames  : TNotifyEvent;
              FOnChangeCellSt : TNotifyEvent;
              FOnChangeAttrib : TNotifyEvent;
              FOnPercentDone  : TOnPercentDoneEvent;
              FOnResize       : TDataTableResizeEvent;
              FComment        : string;                      { comment on data }
              FRowAtt         : array of integer; { class information on objects }
              FColAtt         : array of integer; { class information on features }
              FVType          : array of TVTypeSpec;  { measurement scale type }
              FCState         : array of array of byte; { array of cell states }
              FColName        : array of TDTNameStr;            { column names }
              FRowName        : array of TDTNameStr;               { row names }
              FNrOfCols       : longint;    { number of columns of data matrix }
              FNrOfRows       : longint;    { number of columns of data matrix }
{$IFDEF PAIDVERS}
              FVNState        : TQuotedStrState;         { state of var parser }
              FVNName         : string;   { intermediary name for var. parsing }
{$ENDIF}
              FSortIncludeHd  : boolean;       { flag to indicate sorting mode }
              FOnSortExchange : TSortExchgEvent;
              FExtMatAssigned : boolean;
              procedure ExchangeDuringSort (Sender: TObject; ExchgWhat: byte;
                            index1, index2, first, last: longint);
              function  GetRowAttrib (RowNr: longint): integer;
              function  GetCellState (ACol, ARow: longint): byte;
              function  GetColAttrib (ColNr: longint): integer;
              function  GetMScaleType (ColNr: longint): TMScaleType;
              function  GetColName (ColNr: longint): TDTNameStr;
              function  GetElem (ACol, ARow: longint): double;
              function  GetElemNominal (ACol, ARow: longint): TNominalIDStr;
              function  GetIsNumber (ACol, ARow: longint): boolean;
              function  GetIsEmpty (ACol, ARow: longint): boolean;
              function  GetIsImputed (ACol, ARow: longint): boolean;
              function  GetRowName (RowNr: longint): TDTNameStr;
              function  GetNominalID (ColIx, OrdVal: integer): TNominalIDStr;
              procedure DataHasChanged (Sender: TObject);
              procedure MakeValidColRange (var LowCol, HighCol: integer);
              procedure MakeValidRowRange (var LowRow, HighRow: integer);
              procedure PercDone (Sender: TObject; Percent: longint);
              function  ProcessXmlTag (xmlTag: TDTXmlTags; attr, cont: string;
                           default: string; ParentTag: integer): integer;
              procedure SetRowAttrib (RowNr: longint; Attrib: integer);
              procedure SetCellState (ACol, ARow: longint; const Value: byte);
              procedure SetColAttrib (ColNr: longint; Attrib: integer);
              procedure SetMScaleType (ColNr: longint; MScaleType: TMScaleType);
              procedure SetColName (ColNr: longint; HLine: TDTNameStr);
              procedure SetElem (ACol, ARow: longint; const Value: double);
              procedure SetElemNominal (ACol, ARow: longint;
                            const Value: TNominalIDStr);
              procedure SetFComment (cmt: string);
              procedure SetIsEmpty (ACol, ARow: longint; const Value: boolean);
              procedure SetIsImputed (ACol, ARow: longint; const Value: boolean);
              procedure SetNrCols (NrCols: longint);
              procedure SetNrRows (NrRows: longint);
              procedure SetRowName (RowNr: longint; HLine: TDTNameStr);
              procedure SetNominalID (ColIx, OrdVal: integer;
                            MScaleID: TNominalIDStr);
            protected
            public
              NumericData : TMatrix;                             { data matrix }
              constructor Create(AOwner: TComponent); override;
              destructor  Destroy; override;
              function  AddNominalID (Col: integer;
                            MScaleID: TNominalIDStr): integer;
              procedure AssignAnotherDataMatrix (NewDMat: TMatrix);
              function  CalcCovar (CovarMat: TMatrix; LoC, HiC, LoR, HiR: integer;
                            Mode: integer): boolean;
              procedure ChangedData;
              procedure ChangedSetup;
              procedure ChangedNames;
              procedure ChangedAttrib;
              procedure ChangedCellStates;
              procedure Clear;
              procedure ClearNominalIDs (Col: integer);
              function  CRCofNamesAndAttributes: string;
              function  CRCofCellStates: string;
              function  ExportAsASC (FName: string;
                           Precision: integer): string; overload;
              function  ExportAsASC (const OutFile: TextFile;
                           Precision: integer): string; overload;
              function  ExportAsASC (OutStream: TStream;
                           Precision: integer): string; overload;
              function  ImportASC (FName: string): integer; overload;
              function  ImportASC (InStream: TStream): integer; overload;
              function  ImportASC (ClipBd: TClipBoard): integer; overload;
{$IFNDEF DOTNET}
              function  ExportAsCSV (FName: string; Precision: integer;
                          Delimiter: TCSVDelimiters; IncludeColHeaders,
                          IncludeRowHeaders: boolean): string; overload;
              function  ExportAsCSV (FName: string; Precision: integer;
                          Delimiter: TCSVDelimiters; IncludeColHeaders,
                          IncludeRowHeaders,
                          IncludeRowAttributes: boolean): string; overload;
              function  ExportAsCSV (FName: string; Precision: integer;
                          Delimiter: TCSVDelimiters; IncludeColHeaders,
                          IncludeRowHeaders, IncludeRowAttributes,
                          IncludeComment: boolean): string; overload;
              function  ImportFromCSV (FName: string; Delimiter: TCSVDelimiters;
                           IncludeColHeaders, IncludeRowHeaders: boolean): integer;
{$ENDIF}
              property  Elem[ACol, ARow: longint]: double
                           read GetElem write SetElem; default;
              property  ElemNominal[ACol, ARow: longint]: TNominalIDStr
                           read GetElemNominal write SetElemNominal;
              property  CellState[ACol, ARow: longint]: byte
                           read GetCellState write SetCellState;
              procedure Resize (NrCols, NrRows: longint);
              property  RowAttrib [ix: longint]: integer
                           read GetRowAttrib write SetRowAttrib;
              function  CheckDichotomousColumn (col: integer;
                           var v1, v2: double): boolean;
              property  ColAttrib [ix: longint]: integer
                           read GetColAttrib write SetColAttrib;
              function  CountMarkedCellsInColumn (Col: integer;
                           StateMask: byte): integer;
              function  CountMarkedCellsInRow (Row: integer;
                           StateMask: byte): integer;
              function  FillMarkedCells (Value: double; StateMask: byte): integer;
              function  IfColHasCellState (col: longint; CellState: byte): boolean;
              function  IfRowHasCellState (row: longint; CellState: byte): boolean;
              procedure InsertRow (ix: longint);
              procedure InsertColumn (ix: longint);
              property  IsNumber[ACol, ARow: longint]: boolean read GetIsNumber;
              property  IsEmpty[ACol, ARow: longint]: boolean
                           read GetIsEmpty write SetIsEmpty;
              property  IsImputed[ACol, ARow: longint]: boolean
                           read GetIsImputed write SetIsImputed;
              property  ColName[ix: longint]: TDTNameStr
                           read GetColName write SetColName;
              function  CopyCellStatesFrom (ExtTab: TDataTable): boolean;
              function  CopyCellsToVector (LowCol,LowRow,HighCol,HighRow: integer;
                           CellState: byte; DestVect: TVector): integer;
              procedure CopyContentsFrom (ExtTab: TDataTable);
              procedure CopyFrom (ExtTab: TDataTable; SourceColLo,
                           SourceRowLo, SourceColHi, SourceRowHi,
                           DestCol, DestRow: integer);
              function  CountEmptyCells (LowCol, LowRow, HighCol,
                           HighRow: integer): integer;
              function  CountImputedCells (LowCol, LowRow, HighCol,
                           HighRow: integer): integer;
              function  CountNumCells (LowCol, LowRow, HighCol,
                           HighRow: integer): integer;
              function  CountValidCells (LowCol, LowRow, HighCol,
                           HighRow: integer): integer;
              procedure ExchangeColumns (c1, c2: integer);
              procedure ExchangeMarkings;
              procedure ExchangeRows (r1, r2: integer);
              function  FindHighestMLevel (FirstCol, LastCol: longint): TMScaleType;
              function  FindLowestMLevel (FirstCol, LastCol: longint): TMScaleType;
              function  GeometricMeanOfNumCells (LowCol, LowRow, HighCol,
                           HighRow: integer; var NumData: integer): double;
              function  HarmonicMeanOfNumCells  (LowCol, LowRow, HighCol,
                           HighRow: integer; var NumData: integer): double;
              procedure InvertCellStates (StateMask: byte);
              function  IsConstantColumn (ColIx: longint): boolean;
              function  ListOfCategorialVars: TIntArray;
              function  LoadFromXMLFile (FName: string; DataID: string): boolean;
              function  MaxColNameLength: integer;
              function  MaxRowNameLength: integer;
              function  MaxRowAttrib (FirstRow, LastRow: longint;
                           var Row: integer): integer;
              function  MinRowAttrib (FirstRow, LastRow: longint;
                           var Row: integer): integer;
              function  MaxColAttrib (FirstCol, LastCol: longint;
                           var Col: integer): integer;
              function  MinColAttrib (FirstCol, LastCol: longint;
                           var Col: integer): integer;
              procedure MeanCenterNumCellColumns (Means: TVector);
              procedure MeanCenterNumCellRows (Means: TVector);
              function  MeanVarOfNumCells (LowCol, LowRow, HighCol,
                           HighRow: integer; var Mean, Variance: double): integer;
              function  MeanVarOfMarkedCells (LowCol, LowRow, HighCol,
                           HighRow: integer; CellState: byte;
                           var Mean, Variance: double): integer;
              function  MinMaxOfNumCells (LowCol, LowRow, HighCol,
                           HighRow: integer; var Minimum, Maximum: double): integer;
              function  MinMaxOfMarkedCells (LowCol, LowRow, HighCol,
                           HighRow: integer; CellState: byte;
                           var Minimum, Maximum: double): integer;
              function  MinMaxOfValidCells (LowCol, LowRow, HighCol,
                           HighRow: integer; var Minimum, Maximum: double): integer;
              procedure MirrorColumns;
              procedure MirrorRows;
              property  MScaleType [Col: longint]: TMScaleType
                           read GetMScaleType write SetMScaleType;
              property  NominalID [Col, Ord: longint]: TNominalIDStr
                           read GetNominalID write SetNominalID;
              function  OrdinalOfNominalID (Col: longint; ID: TNominalIDStr;
                           IgnoreCase: boolean): integer;
              function  PercentileOfNumCells (prob: double; LowCol, LowRow, HighCol,
                           HighRow: integer; var NumData: integer): double;
              function  PercentileOfMarkedCells (prob: double; LowCol, LowRow,
                           HighCol, HighRow: integer; CellState: byte;
                           var NumData: integer): double;
              function  QuartilesOfNumCells (LowCol, LowRow, HighCol,
                           HighRow: integer; var Q1, Q2, Q3: double;
                           var NumData: integer): boolean;
              procedure Serialize (ColHeadsAsVar, IncludeColRowNumbers: boolean);
              procedure StandardizeNumCellColumns (Means, StdDevs: TVector);
              procedure StandardizeNumCellRows (Means, StdDevs: TVector);
              function  SumOfNumCells (LowCol,LowRow,HighCol,HighRow: integer;
                           var NumData: integer): double;
              function  SumOfMarkedCells (LowCol,LowRow,HighCol,HighRow: integer;
                           CellState: byte; var NumData: integer): double;
              function  ReadFromOpenXMLFile (var InFile: TextFile;
                           DataID: string): boolean;
              function  ReadFromXMLStream (InStream: TStream;
                           DataID: string): boolean;
              function  ReadFromXMLString (InString: string; var StartAt: integer;
                           DataID: string): boolean;
              procedure RemoveRow (ix: longint);
              procedure RemoveColumn (ix: longint);
              function  RowAttribLevels: integer;
              function  ColAttribLevels: integer;
              property  RowName[ix: longint]: TDTNameStr
                           read GetRowName write SetRowName;
              procedure SortCols (SortRowIx: integer; Ascending: boolean;
                           LowCol, LowRow, HighCol, HighRow: integer;
                           IncludeHeaders: boolean);
              procedure SortRows (SortColIx: integer; Ascending: boolean;
                           LowCol, LowRow, HighCol, HighRow: integer;
                           IncludeHeaders: boolean);
              procedure SortColAttributes (Ascending: boolean;
                           LowCol, LowRow, HighCol, HighRow: integer);
              procedure SortColNames (Ascending: boolean;
                           LowCol, LowRow, HighCol, HighRow: integer); overload;
              procedure SortColNames (Ascending, IgnoreCase: boolean;
                           LowCol, LowRow, HighCol, HighRow: integer); overload;
              procedure SortRowAttributes (Ascending: boolean;
                           LowCol, LowRow, HighCol, HighRow: integer);
              procedure SortRowNames (Ascending: boolean;
                           LowCol, LowRow, HighCol, HighRow: integer); overload;
              procedure SortRowNames (Ascending, IgnoreCase: boolean;
                           LowCol, LowRow, HighCol, HighRow: integer); overload;
              procedure SetAllCellStates (CellState: byte);
              procedure SetColAttributes (Attrib: integer); overload;
              procedure SetColAttributes (Attrib: integer; Mask: longword); overload;
              procedure SetRowAttributes (Attrib: integer); overload;
              procedure SetRowAttributes (Attrib: integer; Mask: longword); overload;
              function  FindColIndex (ColID: TDTNameStr): integer;
              function  FindRowIndex (RowID: TDTNameStr): integer;
              function  ReadFromASC (FName: string; PosX, PosY: longint;
                           ReplaceIDs: boolean): integer; overload;
              function  ReadFromASC (InStream: TStream; PosX, PosY: longint;
                           ReplaceIDs: boolean): integer; overload;
              function  ReadFromASC (ClipBd: TClipBoard; PosX, PosY: longint;
                           ReplaceIDs: boolean): integer; overload;
              procedure UnmarkAllCells;
              procedure SaveAsXMLFile (FName: string; Precision: integer;
                           DataID: string);
              procedure WriteToOpenXMLFile (const OutFile: TextFile;
                           CreateHeader: boolean; Precision: integer;
                           DataID: string);
              procedure WriteToXMLStream (OutStream: TStream;
                           CreateHeader: boolean; Precision: integer;
                           DataID: string);
            published
              property Comment: string
                          read FComment write SetFComment;
              property NrOfColumns: longint
                          read FNrOfCols write SetNrCols;
              property NrOfRows: longint
                          read FNrOfRows write SetNrRows;
              property OnChange: TNotifyEvent
                          read FOnChange write FOnChange;
              property OnChangeSetup: TNotifyEvent
                            read FOnChangeSetup write FOnChangeSetup;
              property OnChangeNames: TNotifyEvent
                            read FOnChangeNames write FOnChangeNames;
              property OnChangeAttrib: TNotifyEvent
                            read FOnChangeAttrib write FOnChangeAttrib;
              property OnChangeCellState: TNotifyEvent
                            read FOnChangeCellSt write FOnChangeCellSt;
              property OnPercentDone: TOnPercentDoneEvent
                            read FOnPercentDone write FOnPercentDone;
              property OnResize: TDataTableResizeEvent
                          read FOnResize write FOnResize;
              property OnSortExchange: TSortExchgEvent
                          read FOnSortExchange write FOnSortExchange;
            end;




Last Update: 2012-Oct-20