STATISTICA







Using STADEV with Delphi
Reading a file

This example dumps to a text file all information about the STATISTICA data file, including variable specifications and data values with labels.

Note that to use STADEV from Delphi, you must include the stadev32 unit into your compilation: uses StaDev32, call the desired functions, and put stadev32.dll in your path and in the Delphi search path


procedure TestReadData;
const
   StatFileName = 'c:\stat\examples\adstudy.sta';
var
   hSF: HSTAFILE;
   Outfile: text;
   NVars: smallint;
   NCases: longint;
   fh: array[0..STAMAX_HEADERLEN] of char;
   VarName: array[0..STAMAX_VARNAMELEN] of char;
   LongVN: array[0..STAMAX_LONGVARNAMELEN] of char;
   Width, Decs, Typ, Subt: smallint;
   MD: double;
   i: integer;
   CaseNameLen: smallint;
   CaseName: array[0..STAMAX_CASENAMELEN] of char;
   j: longint;
   d: double;
   lab: array[0..STAMAX_SLABELLEN] of char;
   llab: array[0..STAMAX_LLABELLEN] of char;
begin
   AssignFile(OutFile, 'sdevout.txt');
   Rewrite(Outfile);

   hSF := StaOpenFile(StatFileName);
   if (hSF = 0) then
      begin
      writeln('ERROR: Could not open STATISTICA file');
      Close(Outfile);
      exit;
      end;

   writeln(Outfile, 'STATISTICA file information'); writeln(Outfile);
   writeln(Outfile, 'File name:', StatFileName);

   NVars := StaGetNVars(hSF);
   writeln(Outfile, 'Number of variables = ', NVars);

   NCases := StaGetNCases(hSF);
   writeln(Outfile, 'Number of cases = ', NCases);

   StaGetFileHeader(hSF, fh, sizeof(fh));
   writeln(Outfile, 'File Header: ', fh);

   writeln(Outfile); writeln(Outfile, 'Variable specs:');
   for i := 1 to NVars do
      begin
      StaGetVarName(hSF, i, VarName);
      if (RES_ERR = StaGetVarLongName(hSF, i, LongVN, sizeof(LongVN))) then
         LongVN[0] := chr(0);
      writeln(Outfile, 'Variable ', i, ' ', VarName, ', ', LongVN);
      StaGetVarFormat(hSF, i, @Width, @Decs, @Typ, @Subt);
      writeln(Outfile, 'Format: ',Width,'.',Decs,'; Type: ', Typ, ', Subtype: ', Subt);
      StaGetVarMD(hSF, i, @MD);
      writeln(Outfile, 'Missing Data: ', MD); writeln(Outfile);
      end;

   writeln(Outfile, 'Case names:');
   CaseNameLen := StaGetCaseNameLength(hSF);
   CaseName[0] := chr(0);
   if (CaseNameLen = 0) then
      writeln(Outfile, 'No case names in this file')
   else
      begin
      writeln(Outfile, 'Case name length: ', CaseNameLen);
      for j := 1 to NCases do
         begin
         StaGetCaseName(hSF, j, CaseName, sizeof(CaseName));
         writeln(Outfile, 'Case # ', j, ': ', CaseName);
         end;
      end;

   lab[0] := chr(0);
   writeln(Outfile);writeln(Outfile,'Data dump:'); writeln(Outfile);

   for j:= 1 to NCases do
      begin
      writeln(Outfile,chr(13),chr(10), 'Case # ', j,':');
      for i := 1 to NVars do
         begin
         StaGetData(hSF, i, j, @d);
         write(Outfile, d:5:1);
         FillChar(lab, sizeof(lab), 0);
         if (0 <> StaGetLabelForValue(hSF, i, d, lab)) then
            begin
            write(Outfile, '(', lab);
            FillChar(llab, sizeof(llab), 0);
            if (0 <> StaGetLongLabelForValue(hSF, i, d, llab, sizeof(llab))) then
               write(Outfile, ', ', llab);
            write(Outfile, ')   ');
            end;
         end;
      end;

   StaCloseFile(hSF);
   Close(Outfile);
end;
Back to List of Programs



[StatSoft]
2300 East 14th Street, Tulsa, OK 74104
Phone: (918) 749-1119; Fax: (918) 749-2217

[StatSoft]e-mail: info@statsoft.com

©Copyright StatSoft, Inc., 1984-2004.
StatSoft, StatSoft logo, STATISTICA, SEWSS, SEDAS, Data Miner, SEPATH and GTrees are trademarks of StatSoft, Inc.