Пример #1
0
/*-------------------------------------------------------------------------
 * Function:	test_inqvar
 *
 * Purpose:	Tests variable inquiry functions.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Thursday, February 11, 1999
 *
 * Modifications:
 *		Robb Matzke, 2000-01-12
 *		Changed hyphens to underscores in object names because silo
 *		now fails when underscores are present in the name.
 *-------------------------------------------------------------------------
 */
static int
test_inqvar(DBfile *dbfile)
{
    int		nerrors=0;
    
    puts("DBGetVarLength()");
    
    puts("    1d_char");
    if (DBGetVarLength(dbfile, "1d_char")!=TEST_NELMTS) {
	puts("        failed");
	nerrors++;
    }
    
    
    puts("    2d_short");
    if (DBGetVarLength(dbfile, "2d_short")!=TEST_NELMTS) {
	puts("        failed");
	nerrors++;
    }
    
    
    puts("    3d_int");
    if (DBGetVarLength(dbfile, "3d_int")!=TEST_NELMTS) {
	puts("        failed");
	nerrors++;
    }
    
    
    puts("    3d_long");
    if (DBGetVarLength(dbfile, "3d_long")!=TEST_NELMTS) {
	puts("        failed");
	nerrors++;
    }
    
    
    puts("    4d_float");
    if (DBGetVarLength(dbfile, "4d_float")!=TEST_NELMTS) {
	puts("        failed");
	nerrors++;
    }
    
    
    puts("    5d_double");
    if (DBGetVarLength(dbfile, "5d_double")!=TEST_NELMTS) {
	puts("        failed");
	nerrors++;
    }

    return nerrors;
}
Пример #2
0
/* We examine all of Silo's data by traversing the all the "simple" arrays
   in the file. Ultimately, the data associated with all of Silo's abstract
   objects, excpet for object headers, is implemented in terms of simple
   arrays. This function finds all the simple arrays in the current dir
   and for each float or double array, reads it and examines it for NaNs.
   To avoid constantly allocating and freeing the buffers for arrays, we
   simply keep a growing buffer that grows to the largest array in the file
   and is freed only upon exit. We use Silo's non-allocating simple array
   read function. To make the loops for checking a NaN as fast as possible,
   we have two versions of the loop, one where progress is checked and 
   one where progress is not checked. We first examine all the simple
   arrays in the current dir, then we loop over subdirs and recurse */
static void
scanSiloDir(DBfile *siloFile, char *theDir)
{
   char **dirNames;
   int i,nDirs,nObjects;
   DBtoc *toc;

   DBNewToc(siloFile);
   toc = DBGetToc(siloFile);

   if (toc == NULL)
      return ;

   nObjects = toc->nvar + toc->ndir;

   if (!nObjects)
      return ;

   /* process the simple arrays in this dir */
   for (i = 0; i < toc->nvar; i++)
   {
      char *varName = toc->var_names[i];
      int n         = DBGetVarLength(siloFile, varName);
      int dbType    = DBGetVarType(siloFile, varName);
      int j;

      if (!disableVerbose)
      {
         if (dbType == DB_FLOAT || dbType == DB_DOUBLE)
            printf("CHECKING array %-56s\r", varName);
         else
            printf("skipping array %-56s\r", varName);
      }

      /* for float arrays */
      if (dbType == DB_FLOAT)
      {

         /* increase allocated buffer if necessary */
         if (n*sizeof(float) > fBufSize)
         {
            if (fBuf != NULL)
               free(fBuf);
            fBuf = (float *) malloc(n * sizeof(float));
            fBufSize = n;
         }

         DBReadVar(siloFile, varName, fBuf);

         if (disableProgress)
         {
            for (j = 0; j < n; j++)
               if (!IS_VALID_FLOAT(fBuf[j]))
                  handleInvalidValue(theDir, varName, j, (double) fBuf[j]);
         }
         else
         {
            for (j = 0; j < n; j++)
            {
               if (!IS_VALID_FLOAT(fBuf[j]))
                  handleInvalidValue(theDir, varName, j, (double) fBuf[j]);
               updateProgress(sizeof(float));
            }
         }
      }

      /* for double arrays */
      if (dbType == DB_DOUBLE)
      {
         /* increase allocated buffer if necessary */
         if (n*sizeof(double) > dBufSize)
         {
            if (dBuf != NULL)
               free(dBuf);
            dBuf = (double *) malloc(n * sizeof(double));
            dBufSize = n;
         }

         DBReadVar(siloFile, varName, dBuf);

         if (disableProgress)
         {
            for (j = 0; j < n; j++)
               if (!IS_VALID_DOUBLE(dBuf[j]))
                  handleInvalidValue(theDir, varName, j, dBuf[j]);
         }
         else
         {
            for (j = 0; j < n; j++)
            {
               if (!IS_VALID_DOUBLE(dBuf[j]))
                  handleInvalidValue(theDir, varName, j, dBuf[j]);
               updateProgress(sizeof(double));
            }
         }
      }
   } /* for i */

   /* save off the dir-stuff out of the toc so we don't loose it during the
      recursions */
   nDirs = toc->ndir;
   dirNames = (char **) malloc(nDirs * sizeof(char*));
   for (i = 0; i < nDirs; i++)
   {
      dirNames[i] = (char *) malloc(strlen(toc->dir_names[i])+1);
      strcpy(dirNames[i], toc->dir_names[i]);
   }

   /* recurse on any subdirs */
   for (i = 0; i < nDirs; i++)
   {
      DBSetDir(siloFile, dirNames[i]);
      scanSiloDir(siloFile, dirNames[i]); 
      DBSetDir(siloFile, "..");
      free(dirNames[i]);
   }

   /* free the dir-stuff we set aside */
   free(dirNames);

}