STATISTICA







Using STADEV with C/C++
Reading of data

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 C/C++ you must include the Development Environment include file ( #include "stadev.h" ) into the source file where you will call the library functions; call the desired functions,and link stadev.dll (for 16-bit programs) or stadev32.dll (for 32-bit programs) to your program.


   HSTAFILE hSta;
   FILE * hOut;

   hOut = fopen ("c:\\stat\\sdevout.txt", "w+");
   if ( hOut == NULL ) {
      MessageBox (NULL, "Cannot open text output file !!!", "Error", MB_OK);
      return;
   }
   hSta = StaOpenFile ("c:\\stat\\examples\\adstudy.sta");
   if ( hSta == 0 ) {
      MessageBox (NULL, "Cannot open requested STATISTICA file !!!", "Error", MB_OK);
      fclose (hOut);
      return;
   }
   fputs ("STATISTICA file information\n\n", hOut);
   fputs ("File name: ", hOut);
   fputs (FileName, hOut);
   fputc ('\n', hOut);

   short nv = StaGetNVars (hSta);
   fprintf (hOut, "Number of variables: %d\n", nv);

   long nc = StaGetNCases (hSta);
   fprintf (hOut, "Number of cases: %ld\n", nc);

   char fh[STAMAX_HEADERLEN+1];
   StaGetFileHeader (hSta, fh, sizeof(fh));
   fprintf (hOut, "File header: %s\n", fh);

   char Varname[STAMAX_VARNAMELEN+1],
        LongVN[STAMAX_LONGVARNAMELEN+1];
   Varname[STAMAX_VARNAMELEN] = 0;
   LongVN[STAMAX_LONGVARNAMELEN] = 0;
   short wid, dec, type, subt;
   double MD;
   short i;
   fprintf (hOut, "\nVariable specs:\n");
   for (i=1; i <= nv; i++ ) {
      StaGetVarName (hSta, i, Varname);
      if ( RES_ERR == StaGetVarLongName (hSta, i, LongVN, sizeof(LongVN)) )
         *LongVN = 0;
      fprintf (hOut, "Variable %d: %s, %s\n", i, Varname, LongVN);
      StaGetVarFormat (hSta, i, &wid, &dec, &type, &subt);
      fprintf (hOut, "Format: %d.%d; Type: %d, Subtype: %d\n", wid, dec, type, subt);
      StaGetVarMD (hSta, i, &MD);
      fprintf (hOut, "Missing Data: %f\n\n", MD);
   }

   fprintf (hOut, "Case names:\n");
   short cnl = StaGetCaseNameLength (hSta);
   long j;
   char Casename[STAMAX_CASENAMELEN+1];
   Casename[STAMAX_CASENAMELEN] = 0;
   if ( cnl == 0 )
      fputs ("No case names in this file", hOut);
   else {
      fprintf (hOut, "Case name length: %d\n", cnl);
      for (j=1; j <= nc; j++ ) {
         StaGetCaseName (hSta, j, Casename, sizeof(Casename));
         fprintf (hOut, "Case # %d: %s\n", j, Casename);
      }
   }

   double d;
   char lab[STAMAX_SLABELLEN+1],
        llab[STAMAX_LLABELLEN+1];
   lab[STAMAX_SLABELLEN] = 0;
   fputs ("\nData dump:\n\n", hOut);
   for ( j=1; j <= nc; j++ ) {
      fprintf (hOut, "\nCase # %d:\n", j);
      for ( i=1; i <= nv; i++ ) {
         StaGetData (hSta, i, j, &d);
         fprintf (hOut, " %5.1f", d);
         if ( 0 != StaGetLabelForValue (hSta, i, d, lab) ) {
            fprintf (hOut, "(%s", lab);
            memset (llab, 0, STAMAX_LLABELLEN+1);
            if ( 0 != StaGetLongLabelForValue (hSta, i, d, llab, sizeof(llab)) )
               fprintf (hOut, ", %s", llab);
            fputs (")   ", hOut);
         }
      }
   }

   StaCloseFile (hSta);
   fclose (hOut);
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.