Ejemplo n.º 1
0
/*-------------------------------------------------------------------------
 * Function:	test_type_conv
 *
 * Purpose:	If we call DBWrite() for an existing variable but the memory
 *		data type is different than what was previously registered
 *		then a type conversion should occur.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors.
 *
 * Programmer:	Robb Matzke
 *              Tuesday, February  9, 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_type_conv(DBfile *dbfile)
{
    char	cdata_out[TEST_NELMTS];
    int		i, dims[3], nerrors=0, idata_in[TEST_NELMTS];

    puts("=== Type conversions ===");
    
    /* Initialize output arrays */
    for (i=0; i<TEST_NELMTS; i++, cntr_g++) {
	idata_g[i] = cdata_out[i] = cntr_g%128;
    }

    /* Write char data to the 3d_int array */
    puts("DBWrite()");
    puts("    3d_int");
    dims[0] = 12;
    dims[1] = 30;
    dims[2] = TEST_NELMTS/(dims[0]*dims[1]);
    if (DBWrite(dbfile, "3d_int", cdata_out, dims, 3, DB_CHAR)<0) {
	puts("        failed");
	nerrors++;
    }

    /* Read integer data back out */
    puts("DBRead()");
    puts("    3d_int");
    memset(idata_in, 0xff, sizeof idata_in);
    if (DBReadVar(dbfile, "3d_int", idata_in)<0) {
	puts("        failed");
	nerrors++;
    } else {
	for (i=0; i<TEST_NELMTS; i++) {
	    if (idata_g[i]!=idata_in[i]) {
		printf("        failed at i=%d: out=%d, in=%d\n",
		       i, idata_g[i], idata_in[i]);
	    }
	}
    }

    return nerrors;
}
Ejemplo n.º 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);

}
Ejemplo n.º 3
0
int
main(int argc, char *argv[])
{
    
    int            nerrors = 0;
    int            i, j, ndims=1; 
    int            driver=DB_HDF5;
    char          *filename="largefile.h5";
    DBfile        *dbfile;

    /* Parse command-line */
    for (i=1; i<argc; i++) {
        if (!strcmp(argv[i], "DB_PDB")) {
            fprintf(stderr, "This test only supported on HDF5 driver\n");
            exit(1);
        } else if (!strcmp(argv[i], "DB_HDF5")) {
            driver = DB_HDF5;
            filename = "largefile.h5";
        } else {
            fprintf(stderr, "%s: ignored argument '%s'\n", argv[0], argv[i]);
        }
    }

    DBShowErrors(DB_TOP, NULL);
    DBForceSingle(1);

    /*
     * Create a file that contains a simple variables.
     */
    printf("Creating file: '%s'\n", filename);
    dbfile = DBCreate(filename, 0, DB_LOCAL, "Simple Test", driver);

    for (j = 0; j < 2500; j++)
    {
        char tmpname[64];

        if (j % 100 == 0)
            printf("Iterations %04d to %04d of %04d\n", j, j+100-1, 2500);

        sprintf(tmpname, "simple_%04d", j);

        for (i = 0; i < dims[0]; i++)
            val[i] = (float) dims[0] * j + i;

        if (DBWrite(dbfile, tmpname, val, dims, ndims, DB_FLOAT) != 0)
        {
            DBClose(dbfile);
            exit(1);
        }
    }

   /*
    * Put some objects VisIt can process at the end of the file
    */
    build_curve(dbfile, driver);

    DBClose(dbfile);

    /*
     * Now try opening the file again and reading the simple
     * variable.
     */
    printf("Reopening '%s'\n", filename);
    dbfile = DBOpen(filename, driver, DB_READ);

    if (dbfile == 0)
    {
        printf("Unable to Reopen file for reading\n");
        exit(1);
    }

    /*
     * Randomly examine 50 arrays from the first and last 500
     */
    srand(0xBabeFace);
    for (j = 0; j < 100; j++)
    {
        char tmpname[64];

        int n = rand() % 500 + (j >= 50 ? 200 : 0);

        sprintf(tmpname, "simple_%04d", n);

        if (DBReadVar(dbfile, tmpname, rval) < 0)
        {
            nerrors++;
            if (nerrors < 10) printf("DBReadVar for \"%s\" failed\n", tmpname);
            if (nerrors == 10) printf("Further errors will be suppressed\n");
        }

        for (i = 0; i < dims[0]; i++)
        {
            val[i] = (float) dims[0] * n + i;
            if (val[i] != rval[i])
            {
                nerrors++;
                if (nerrors < 10) printf("Read error in \"%s\" at position %04d. Expected %f, got %f\n",
                                          tmpname, i, val[i], rval[i]);
                if (nerrors == 10) printf("Further errors will be suppressed\n");
                break;
            }
        }
    }

    DBClose(dbfile);

    exit(nerrors > 0);
}
Ejemplo n.º 4
0
/*-------------------------------------------------------------------------
 * Function:        main
 *
 * Purpose:
 *
 * Return:        0
 *
 * Programmer:
 *      Thomas R. Treadway, Mon Mar 12 14:13:51 PDT 2007
 *      Test of HDF5 compression.
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
int
main(int argc, char *argv[])
{

    int            nerrors = 0;
    int            verbose = 0;
    int            usefloat = 0;
    int            readonly = 0;
    int            i, j, ndims=1;
    int            fdims[]= {ONE_MEG/sizeof(float)};
    int            ddims[]= {ONE_MEG/sizeof(double)};
    float          *fval;
    float          *frval;
    double         *dval;
    double         *drval;
    int            driver=DB_HDF5;
    char          *filename="compression.h5";
    char          *ptr;
    char           tmpname[64];
    DBfile        *dbfile;
#if !defined(_WIN32)
    struct         timeval tim;
    double         t1, t2;
#endif
    struct stat    buffer;
    off_t          fsize;
    int            has_loss = 0;
    int            show_errors = DB_TOP;

    /* Parse command-line */
    for (i=1; i<argc; i++) {
        if (!strncmp(argv[i], "DB_PDB",6)) {
            fprintf(stderr, "This test only supported on HDF5 driver\n");
            exit(1);
        } else if (!strncmp(argv[i], "DB_HDF5", 7)) {
            driver = StringToDriver(argv[i]);
            filename = "compression.h5";
        } else if (!strcmp(argv[i], "compress")) {
            if ((i+1<argc) && ((ptr=strstr(argv[i+1], "METHOD=")) != NULL))
            {
                DBSetCompression(argv[i+1]);
                i++;
            }
            else
                DBSetCompression("METHOD=GZIP");
        } else if (!strcmp(argv[i], "szip")) {
            DBSetCompression("METHOD=SZIP");
        } else if (!strcmp(argv[i], "gzip")) {
            DBSetCompression("METHOD=GZIP");
        } else if (!strcmp(argv[i], "fpzip")) {
            DBSetCompression("METHOD=FPZIP");
        } else if (!strcmp(argv[i], "single")) {
            usefloat = 1;
        } else if (!strcmp(argv[i], "verbose")) {
            verbose = 1;
        } else if (!strcmp(argv[i], "lossy1")) {
            DBSetCompression("METHOD=FPZIP LOSS=1");
            has_loss = 1;
        } else if (!strcmp(argv[i], "lossy2")) {
            DBSetCompression("METHOD=FPZIP LOSS=2");
            has_loss = 1;
        } else if (!strcmp(argv[i], "lossy3")) {
            DBSetCompression("METHOD=FPZIP LOSS=3");
            has_loss = 1;
        } else if (!strcmp(argv[i], "minratio1000")) {
            DBSetCompression("ERRMODE=FAIL MINRATIO=1000 METHOD=FPZIP");
        } else if (!strcmp(argv[i], "minratio1001")) {
            DBSetCompression("ERRMODE=FALLBACK MINRATIO=1000 METHOD=FPZIP");
        } else if (!strcmp(argv[i], "readonly")) {
            readonly = 1;
        } else if (!strcmp(argv[i], "help")) {
            printf("Usage: %s [compress [\"METHOD=...\"]|single|verbose|readonly]\n",argv[0]);
            printf("Where: compress - enables compression, followed by compression information string\n");
            printf("                  default is compress \"METHOD=GZIP LEVEL=1\"\n");
            printf("       single   - writes data as floats not doubles\n");
            printf("       verbose  - displays more feedback\n");
            printf("       readonly - checks an existing file (used for cross platform test)\n");
            printf("       DB_HDF5  - enable HDF5 driver, the default\n");
            return (0);
        } else if (!strcmp(argv[i], "show-all-errors")) {
            show_errors = DB_ALL_AND_DRVR;
        } else if (argv[i][0] != '\0') {
            fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]);
        }
    }

    /* get some temporary memory */
    fval = (float*) malloc(ONE_MEG);
    frval = (float*) malloc(ONE_MEG);
    dval = (double*) malloc(ONE_MEG);
    drval = (double*) malloc(ONE_MEG);

    DBShowErrors(show_errors, 0);

    if (!readonly)
    {
        /*
         * Create a file that contains a simple variables.
         */
        if (verbose)
            printf("Creating file: `%s'\n", filename);
        dbfile = DBCreate(filename, 0, DB_LOCAL, "Compression Test", driver);

#if !defined(_WIN32)
        gettimeofday(&tim, NULL);
        t1=tim.tv_sec+(tim.tv_usec/1000000.0);
#endif
        if (usefloat)
        {
            for (j = 0; j < INTERATE; j++)
            {
                if (verbose)
                    if (j % 100 == 0)
                        printf("Iterations %04d to %04d of %04d\n", j,j+100-1,INTERATE);

                sprintf(tmpname, "compression_%04d", j);

                for (i = 0; i < fdims[0]; i++)
                    fval[i] = (float) fdims[0] * j + i;

                if (DBWrite(dbfile, tmpname, fval, fdims, ndims, DB_FLOAT) < 0)
                {
                    nerrors++;
                    break;
                }
            }
        }
        else
        {
            for (j = 0; j < INTERATE; j++)
            {
                if (verbose)
                    if (j % 100 == 0)
                        printf("Iterations %04d to %04d of %04d\n",j,j+100-1,INTERATE);

                sprintf(tmpname, "compression_%04d", j);

                for (i = 0; i < ddims[0]; i++)
                    dval[i] = (double) ddims[0] * j + i;

                if (DBWrite(dbfile, tmpname, dval, ddims, ndims, DB_DOUBLE) < 0)
                {
                    nerrors++;
                    break;
                }
            }
        }
#if !defined(_WIN32)
        gettimeofday(&tim, NULL);
        t2=tim.tv_sec+(tim.tv_usec/1000000.0);
        stat(filename, &buffer);
        fsize = buffer.st_size;
        printf("Write took %.6lf seconds and %.6g bytes/second\n",
               t2-t1,fsize/(t2-t1));
#endif

        DBClose(dbfile);
    }
    else
    {
        stat(filename, &buffer);
        fsize = buffer.st_size;
    }

    if (nerrors)
        return nerrors;

    /*
     * Now try opening the file again and verify the simple
     * variable.
     */
    if (verbose)
        printf("Reopening `%s'\n", filename);
    dbfile = DBOpen(filename, driver, DB_READ);

    if (dbfile == 0)
    {
        printf("Unable to Open file for reading\n");
        exit(1);
    }

#if !defined(_WIN32)
    gettimeofday(&tim, NULL);
    t1=tim.tv_sec+(tim.tv_usec/1000000.0);
#endif
    if (usefloat)
    {
        for (j = 0; j < INTERATE; j++)
        {
            if (verbose)
                if (j % 100 == 0)
                    printf("Iterations %04d to %04d of %04d\n", j,j+100-1,INTERATE);

            sprintf(tmpname, "compression_%04d", j);

            if (DBReadVar(dbfile, tmpname, frval) < 0)
            {
                if (!has_loss) nerrors++;
                if (!has_loss && nerrors <= 10) printf("DBReadVar for \"%s\" failed\n", tmpname);
                if (!has_loss && nerrors == 10) printf("Further errors will be suppressed\n");
            }
            for (i = 0; i < fdims[0]; i++)
            {
                fval[i] = (float) fdims[0] * j + i;
                if (fval[i] != frval[i])
                {
                    if (!has_loss) nerrors++;
                    if (!has_loss && nerrors <= 10)
                        printf("Read error in \"%s\" at position %04d. Expected %f, got %f\n",
                               tmpname, i, fval[i], frval[i]);
                    if (!has_loss && nerrors == 10) printf("Further errors will be suppressed\n");
                    break;
                }
            }
        }
    }
    else
    {
        for (j = 0; j < INTERATE; j++)
        {
            if (verbose)
                if (j % 100 == 0)
                    printf("Iterations %04d to %04d of %04d\n",j,j+100-1,INTERATE);

            sprintf(tmpname, "compression_%04d", j);

            if (DBReadVar(dbfile, tmpname, drval) < 0)
            {
                if (!has_loss) nerrors++;
                if (!has_loss && nerrors <= 10) printf("DBReadVar for \"%s\" failed\n", tmpname);
                if (!has_loss && nerrors == 10) printf("Further errors will be suppressed\n");
            }
            for (i = 0; i < ddims[0]; i++)
            {
                dval[i] = (double) ddims[0] * j + i;
                if (dval[i] != drval[i])
                {
                    if (!has_loss) nerrors++;
                    if (!has_loss && nerrors <= 10)
                        printf("Read error in \"%s\" at position %04d. Expected %f, got %f\n",
                               tmpname, i, dval[i], drval[i]);
                    if (!has_loss && nerrors == 10) printf("Further errors will be suppressed\n");
                    break;
                }
            }
        }
    }
#if !defined(_WIN32)
    gettimeofday(&tim, NULL);
    t2=tim.tv_sec+(tim.tv_usec/1000000.0);
    printf("Read took %.6lf seconds and %.6g bytes/second\n",
           t2-t1,fsize/(t2-t1));
#endif
    DBClose(dbfile);

    free(fval);
    free(frval);
    free(dval);
    free(drval);

    CleanupDriverStuff();
    return nerrors;
}
Ejemplo n.º 5
0
/*-------------------------------------------------------------------------
 * Function:	test_dirs
 *
 * Purpose:	Test directory operations
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Wednesday, February 10, 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_dirs(DBfile *dbfile)
{
    int		nerrors=0;
    char	curdir[1024];
    static int	in[1]={911}, value[1]={0};
    static int	dims[1]={1};

    puts("=== Directories ===");

    /* Make some directories */
    if (DBMkDir(dbfile, "dir1")<0) {
	puts("DBMkDir(dir1) failed");
	nerrors++;
    }
    if (DBMkDir(dbfile, "dir1/d1a")<0) {
	puts("DBMkDir(dir1/d1a) failed");
	nerrors++;
    }
    if (DBMkDir(dbfile, "/dir1/d1b")<0) {
	puts("DBMkDir(dir1/d1b) failed");
	nerrors++;
    }
    if (DBMkDir(dbfile, "/dir1/d1c/")<0) {
	puts("DBMkDir(dir1/d1c) failed");
	nerrors++;
    }
    if (DBMkdir(dbfile, "//dir2//")<0) {
	puts("DBMkDir(dir2) failed");
	nerrors++;
    }

    /* Set the CWD to /dir1/d1c and write a variable */
    if (DBSetDir(dbfile, "//dir1//d1c//")<0) {
	puts("DBSetDir(/dir1/d1c) failed");
	nerrors++;
    }
    if (DBWrite(dbfile, "d1c_A", value, dims, 1, DB_INT)<0) {
	puts("DBWrite(d1c_A) failed");
	nerrors++;
    }
    if (DBGetDir(dbfile, curdir)<0 || strcmp(curdir, "/dir1/d1c")) {
	puts("DBGetDir() failed");
	nerrors++;
    }
    if (DBReadVar(dbfile, "../d1c/..//..////dir1/d1c//d1c_A", in)<0 ||
	in[0]!=value[0]) {
	puts("DBReadVar(d1c_A) failed");
	nerrors++;
    }

    /* Test table of contents */
    if (NULL==DBGetToc(dbfile)) {
	puts("DBGetToc() failed");
	nerrors++;
    }
    
    /* Set CWD to top */
    if (DBSetDir(dbfile, "/")<0) {
	puts("DBSetDir(/) failed");
	nerrors++;
    }
    if (DBGetDir(dbfile, curdir)<0 || strcmp(curdir, "/")) {
	puts("DBetDir() failed");
	nerrors++;
    }

    return nerrors;
}
Ejemplo n.º 6
0
/*-------------------------------------------------------------------------
 * Function:	test_read_all
 *
 * Purpose:	Tests DBReadVar() by reading each of the variables that were
 *		written by test_write_all() and comparing the results to what
 *		is stored in memory.
 *
 *		This step is skipped if the architecture is not DB_LOCAL
 *		because the data might be read back as some other type than
 *		what was written. Unfortunately silo doesn't give the caller
 *		any control over how data is read.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Tuesday, February  9, 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_read_all(DBfile *dbfile)
{
    int		i, nerrors=0;
    char	cdata_in[TEST_NELMTS];
    short	sdata_in[TEST_NELMTS];
    int		idata_in[TEST_NELMTS];
    long	ldata_in[TEST_NELMTS];
    float	fdata_in[TEST_NELMTS];
    double	ddata_in[TEST_NELMTS];

    puts("DBReadVar():");
    if (DB_LOCAL!=arch_g) {
	puts("    Skipped because target is not DB_LOCAL"
	     " -- use browser instead");
	return 0;
    }
    
    /* 1d char */
    puts("    1d_char");
    memset(cdata_in, 0xff, sizeof cdata_in);
    if (DBReadVar(dbfile, "1d_char", cdata_in)<0) {
	puts("        DBReadVar() failed");
	nerrors++;
    } else {
	for (i=0; i<TEST_NELMTS; i++) {
	    if (cdata_g[i]!=cdata_in[i]) {
		printf("        failed at i=%d: out=%d, in=%d\n",
		       i, cdata_g[i], cdata_in[i]);
		nerrors++;
	    }
	}
    }

    /* 2d short */
    puts("    2d_short");
    memset(sdata_in, 0xff, sizeof sdata_in);
    if (DBReadVar(dbfile, "2d_short", sdata_in)<0) {
	puts("        DBReadVar() failed");
	nerrors++;
    } else {
	for (i=0; i<TEST_NELMTS; i++) {
	    if (sdata_g[i]!=sdata_in[i]) {
		printf("        failed at i=%d: out=%d, in=%d\n",
		       i, sdata_g[i], sdata_in[i]);
		nerrors++;
	    }
	}
    }


    /* 3d int */
    puts("    3d_int");
    memset(idata_in, 0xff, sizeof idata_in);
    if (DBReadVar(dbfile, "3d_int", idata_in)<0) {
	puts("        DBReadVar() failed");
	nerrors++;
    } else {
	for (i=0; i<TEST_NELMTS; i++) {
	    if (idata_g[i]!=idata_in[i]) {
		printf("        failed at i=%d: out=%d, in=%d\n",
		       i, idata_g[i], idata_in[i]);
	    }
	}
    }

    /* 3d long */
    puts("    3d_long");
    memset(ldata_in, 0xff, sizeof ldata_in);
    if (DBReadVar(dbfile, "3d_long", ldata_in)<0) {
	puts("        DBReadVar() failed");
	nerrors++;
    } else {
	for (i=0; i<TEST_NELMTS; i++) {
	    if (ldata_g[i]!=ldata_in[i]) {
		printf("        failed at i=%d: out=%ld, in=%ld\n",
		       i, ldata_g[i], ldata_in[i]);
	    }
	}
    }

    /* 4d float */
    DBForceSingle(TRUE);
    puts("    4d_float");
    memset(fdata_in, 0xff, sizeof fdata_in);
    if (DBReadVar(dbfile, "4d_float", fdata_in)<0) {
	puts("        DBReadVar() failed");
	nerrors++;
    } else {
        printf("checking read of first 4d_float\n");
	for (i=0; i<TEST_NELMTS; i++) {
	    if (fdata_g[i]!=fdata_in[i]) {
		printf("        failed at i=%d: out=%g, in=%g\n",
		       i, fdata_g[i], fdata_in[i]);
	    }
	}
    }
    DBForceSingle(FALSE);

    /* 5d double */
    puts("    5d_double");
    memset(ddata_in, 0xff, sizeof ddata_in);
    if (DBReadVar(dbfile, "5d_double", ddata_in)<0) {
	puts("        DBReadVar() failed");
	nerrors++;
    } else {
	for (i=0; i<TEST_NELMTS; i++) {
	    if (ddata_g[i]!=ddata_in[i]) {
		printf("        failed at i=%d: out=%g, in=%g\n",
		       i, ddata_g[i], ddata_in[i]);
	    }
	}
    }
    return nerrors;
}
Ejemplo n.º 7
0
int Restart_read_driver(char *dmpname, int mdmpflag, int memflag)
{
   char *me = "Restart_read_driver";
   char *kern, *rem, *infostr;
   char msg[MAXLINE];
   int  i, error = 0, ierr;
   int  num, mycyc, iblk, gblk, namelen;
   int  mynblk;
   int  numBlocks, numDomains;
   int *domainFiles;
   DBfile *idbid;
   RGST_AttributeElem_t *func;
   if (memflag == 1) {
      memclr() ;
   }
   comlock(dmp_nbaton);
   if (mdmpflag) {
     kern = strtok(dmpname,"-");
     rem = strtok(NULL,"-");
     mycyc = atoi(rem);
     RestartCycle = mycyc;
     strcpy(RestartKernel,kern);
     rootfile_read(kern,mycyc);
   } else {
      namelen = strlen(dmpname);
      if (namelen > 10) {
	 memset(msg,'\0',MAXLINE);
         strncpy(RestartKernel,dmpname,namelen - 10);
         RestartKernel[namelen - 9] = '\0';
	 i = strlen(dmpname) - 10;
         strncpy(msg,&(dmpname[i]), 5);
         RestartCycle = atoi(msg);
      } else {
      } 
      idbid = DBOpen (dmpname, DB_PDB, DB_READ);
      if (idbid == NULL) {
         error = 1 ;
         sprintf(msg,"Can't open dump %s\n",dmpname);
         ctlwarning(me,msg);
         return(error) ;
      }
      infostr = DBGetVar (idbid, "_fileinfo");
      namelen = strlen(codename);
      if (strncmp (infostr, codename, namelen) != 0) {
	sprintf(msg,"Restarting from a dump which is not %s.  This is EVIL!\n",
		codename);
	ctlwarning(me,msg);
      }
      FREEMEM(infostr);
      decomp_setdir(idbid);
      ierr  = DBReadVar(idbid,"NumBlocks",&numBlocks);
      ierr += DBReadVar(idbid,"NumDomains",&numDomains);
      if (ierr != 0) ctlerror(me,gv_errmsg_DBReadVar);
      decomp_new(numBlocks, numDomains);
      decomp_read(idbid, msg, 0, 0);
      if (DBSetDir(idbid, "/") != 0) ctlerror(me,gv_errmsg_DBSetDir);
      error += Restart_read_global(idbid); 
      dmpattr_set();
      domainFiles = MALLOT(int, gnblk);
      for (gblk = 0; gblk < gnblk; gblk++) {  
         domainFiles[gblk] = gmap[gblk].lblk;
      }
      calculate_mappings();
      mynblk = 0;
      for (gblk = 0; gblk < gnblk; gblk++) {
         if (gmap[gblk].proc != myid) continue;
         iblk = gmap[gblk].lblk;
         Restart_read_domain(idbid, domainFiles[gblk], iblk); 
         mynblk++;
      }
      nblk = mynblk;
      DBClose(idbid);
      FREEMEM(domainFiles);
   }
   dmpattr_unset();
   comunlock(dmp_nbaton);
   ifparallel = 0;
   nblk = gnblk;
   initcom(NULL,0);
   sprintf(msg,"dump '%s' read",dmpname);
   ctlmsg(msg);
   printtc() ;
   func = rgst_list_attr(A_OBJECT, "Function_Gen");
   while (func != NULL) {
      Command_t *cp = (Command_t *) func->rgst_obj->obj;
      (*(cp->proc))();  
      func = func->next;
   }
   blknum = 0 ;
   genmd = -1;
   error += qbnd(FULL_STEP,COM_RECV);
   error += qbnd(FULL_STEP,COM_SEND);
   error += qbnd(FULL_STEP,COM_WAIT_RECV);
   TimeStepControl_initialize() ;
   for ( iblk = 0 ; iblk < nblk ; iblk++ ) {
      updateblk( &domains[iblk], 0, 0.0 ) ;
   }
 ; 
   error += qbnd(FULL_STEP,COM_WAIT_SEND);
   editor(FULL_STEP);
   genmd = 0;
   hash_optimize_all();
   return(0);
}
Ejemplo n.º 8
0
int Restart_read_global(DBfile *idbid)
{
  char *me = "Restart_read_global";
  int ierr = 0, error = 0;
  int index, itest ;
  int i, j, k, n, gblk, irestart, num_ipas, num_fpas;
  int iblk,len2, length, nsplines;
  int numGroups, numSpec;
  int pdmdsav,npsave,nisave,nfsave,nppsave,ifthreadsave;
  char dirname[128], msg[256], pbnm_save[256], outstring[32];
  int nhead[NHEAD_NUM];
  int inttemp[100];      
  double doubtemp[100];  
  double myflops = 0.0;
  Stringnam_t *palistn;
  int         *palistv;
  VersionData_t  *file_ver;
  TimePlot_t     *my_tpd;
  RGST_AttributeElem_t *func;
  FT_INITIALIZE(me, gv_hash_tbl) 
  genmd   = 0 ;
  pdmdsav = pdmd ;
  strcpy(pbnm_save,pbnm);
  if (DBSetDir(idbid, "/Global") != 0) ctlerror(me,gv_errmsg_DBSetDir);
  file_ver = rgst_read_struct_in_dir(idbid,"Version","VersionData_t",NULL,NULL);
  if (file_ver == NULL) ctlerror(me,gv_errmsg_rgst_read_struct_in_dir);
  if (strcmp(file_ver->dump_version,VER_DUMP) != 0) {
    sprintf(msg,"Dump version %s may be incompatible with current version %s",
                 file_ver->dump_version,VER_DUMP);
    ctlnotice(me,msg);
  }
  VersionData_destruct(file_ver);
  if (DBReadVar(idbid, "nhead", nhead) != 0) ctlerror(me,gv_errmsg_DBReadVar);
  ifthreadsave = ifthreads;
  ierr = rdparms(idbid);
  if (ierr != 0) {
    ctlwarning(me,"rdparms failed");
  }
  ifthreads = ifthreadsave;
  pdmd = pdmdsav ;
  strcpy(pbnm,pbnm_save);
  memexp();
  DBShowErrors(DB_NONE, NULL);
  ierr = DBSetDir(idbid,"Nodelists");
  if (ierr == 0) {
     NodeList_rdsilo(idbid,0);
     ierr = DBSetDir(idbid,"../");
  }
  DBShowErrors(DB_TOP, NULL);
  DBShowErrors(DB_NONE, NULL);
  ierr = DBSetDir(idbid,"Tracers");
  if (ierr == 0) {
     ierr = DBSetDir(idbid,"../");
  }
  DBShowErrors(DB_TOP, NULL);
  DBShowErrors(DB_NONE, NULL);
  ierr = DBSetDir(idbid,"Probes");
  if (ierr == 0) {
     ierr = DBSetDir(idbid,"../");
  }
  DBShowErrors(DB_TOP, NULL);
  conditionals_rdsilo(idbid);
  TimeStepControl_rdsilo(idbid);
  if (DBSetDir(idbid, "/Global") != 0) ctlerror(me,gv_errmsg_DBSetDir); 
  FunctionTimer_rdsilo(idbid, gv_hash_tbl);
  spline_rdsilo(idbid);
  UserList_rdsilo(idbid);
  func = rgst_list_attr(A_OBJECT, "Function_ReadSilo");
  while (func != NULL) {
     Command_t *cp = (Command_t *) func->rgst_obj->obj;
     (*(cp->proc))(idbid);  
     func = func->next;
  }
  num_ipas = nhead[NHEAD_NUM_IPA];
  num_fpas = nhead[NHEAD_NUM_FPA];
  n        = MAX(num_ipas, num_fpas);
  if ( n > 0 ) {
     palistn = ALLOT(Stringnam_t, n);
     palistv = ALLOT(int,         n);
  }
Ejemplo n.º 9
0
Databox         *ReadSilo(char *filename, double default_value)
{
#ifdef HAVE_SILO
   Databox         *v;

   double          X,  Y,  Z;
   int             NX, NY, NZ;
   double          DX, DY, DZ;

   int             x,  y,  z;
   int             nx, ny, nz;

   int             j, k;

   double         *ptr;
   
   int             err = -1;

   DBfile         *db;
    double         epsi = 1.0E-16;
   char *current_path = NULL;
   char *path = NULL;
   char *slash = strchr(filename, '/');
    float *localcoords[3];
    
   if(slash) {
      path = (char *)malloc(MAXPATHLEN);
      strncpy(path, filename, slash - filename);
      path[slash - filename] = 0;
      filename = strdup(slash + 1);
   } else {
      filename = strdup(filename);
   }

   if(path) { 	
      current_path = (char *)malloc(MAXPATHLEN);
      getwd(current_path);
      chdir(path);
   }

//   db = DBOpen(filename, DB_PDB, DB_READ);
   db = DBOpen(filename, DB_UNKNOWN, DB_READ);
   if(db == NULL)
   {
      printf("Failed to open SILO file %s\n", filename);
      return NULL;
   }

   double origin[3];
   err = DBReadVar(db, "origin", &origin);
   if(err < 0) {
      printf("Failed to read meta data\n");
      return NULL;
   } 
   X = origin[0];
   Y = origin[1];
   Z = origin[2];

   int size[3];
   err = DBReadVar(db, "size", &size);
   if(err < 0) {
      printf("Failed to read meta data\n");
      return NULL;
   } 
   NX = size[0];
   NY = size[1];
   NZ = size[2];

   double delta[3];
   err = DBReadVar(db, "delta", &delta);
   if(err < 0) {
      printf("Failed to read meta data\n");
      return NULL;
   } 
   DX = delta[0];
   DY = delta[1];
   DZ = delta[2];

   /* create the new databox structure */
   if ((v = NewDataboxDefault(NX, NY, NZ, X, Y, Z, DX, DY, DZ, default_value)) == NULL)
   {
      return((Databox *)NULL);
   }

   DBtoc *toc = DBGetToc(db);
   if ( toc == NULL ) {      
      printf("Error: Silo get get TOC failed for %s\n", filename);
      return NULL;
   }

   char **multivar_names = toc -> multivar_names;
   int    nmultivar      = toc -> nmultivar;

    /* Check to see if file has a multivar in it to determine file format being used */
   if(nmultivar == 0) 
   {
      DBquadvar  *var = DBGetQuadvar(db, "variable");
      if(var == NULL) 
      {
	 printf("Error: Silo failed to get quadvar %s \n", "variable");
	 return NULL;
      }

      memcpy(DataboxCoeff(v, 0, 0, 0), var -> vals[0], NX*NY*NZ * sizeof(double));

      DBFreeQuadvar(var);

   } else {

      DBmultivar *multivar = DBGetMultivar(db, multivar_names[0]);
      if ( multivar == NULL ) {      
	 printf("Error: Silo get multivar failed for %s\n", multivar_names[0]);
	 return NULL;
      }
      
      
      int    nvars         = multivar -> nvars;  
      char **varnames      = multivar -> varnames;
      
      int i;

      int m;
      for(m = 0; m < nvars; m++) 
      {
	 char *proc_filename;
	 char *seperator = ":";
      
	 proc_filename = strtok(varnames[m], seperator);
	 char *proc_varname;
	 proc_varname = strtok(NULL, seperator);
        /*  printf("multivar nvar:  %d  \n", nvars);
          printf("multivar proc_varname:  %s  \n", proc_varname);
          printf("multivar proc_filename:  %s  \n", proc_filename); */

	 if(proc_filename == NULL)
	 {
	    printf("Error malformed multivar name %s in SILO file \n", varnames[m]);
	    return NULL;
	 }
      
	 DBfile *proc_db;
//	 proc_db = DBOpen(proc_filename, DB_PDB, DB_READ);
	 proc_db = DBOpen(proc_filename, DB_UNKNOWN, DB_READ);
	 if(db == NULL)
	 {
	    printf("Failed to open SILO file %s\n", filename);
	    return NULL;
	 }
      
	 if(proc_varname == NULL)
	 {
	    printf("Error malformed multivar name %s in SILO file \n", varnames[m]);
	    return NULL;
	 }

	 DBquadvar  *var = DBGetQuadvar(proc_db, proc_varname);
	 if(var == NULL) 
	 {
	    printf("Error: Silo failed to get quadvar %s \n", varnames[m]);
	    return NULL;
	 }

          /* now we need to get the mesh, for PMPIO compat */
	 DBquadmesh  *mesh = DBGetQuadmesh(proc_db, var -> meshname);
	 if(mesh == NULL) 
	 {
	    printf("Error: Silo failed to get quadmesh %s \n", varnames[m]);
	    return NULL;
	 }        
	 
	 nx = var -> dims[0];
	 ny = var -> dims[1];
	 nz = var -> dims[2];

	 /* Casting here is a dangerous */
	 localcoords[0] = (float *)mesh -> coords[0];
	 localcoords[1] = (float *)mesh -> coords[1];
	 localcoords[2] = (float *)mesh -> coords[2];
	  
	 int index_origin[3];
	 err = DBReadVar(proc_db, "index_origin", &index_origin);
	 if(err < 0) {
	    printf("Failed to read meta data\n");
	    return NULL;
	 }  

	 /* becuase of multi or single file compatibility we need to 
	  * grab the actual mesh from that variable.  Then we need to
	  * determine the origin from the mesh[0][0], [1][0] and [2][0]
	  * divided by DX, DY and DZ since there are multiple origins 
	  * in a single file and this is now ambiguous. */
	 
	 x = index_origin[0];
	 y = index_origin[1];
	 z = index_origin[2];
	 
	 x = round( (localcoords[0][0] - (X - DX / 2.0))  / DX);
	 y = round( (localcoords[1][0] - (Y - DY / 2.0))  / DY);
	 z = round( (localcoords[2][0] - (Z - DZ / 2.0))  / DZ);
	 int index = 0;
	 double *vals =  (double *)var -> vals[0];
	 for (k = 0; k < nz; k++) {
	    for (j = 0; j < ny; j++) {
	       for (i = 0; i < nx; i++) {
		  ptr = DataboxCoeff(v, x + i, y + j, z + k);
		  *ptr = vals[index];
               index++;
	       }
	    }
	 }

	 DBFreeQuadvar(var);
     
	 DBClose(proc_db);
      }

      DBFreeMultivar(multivar);
   }


   DBClose(db);

    

   if(path) { 	
      free(path);
   }

   if(current_path) { 	
      chdir(current_path);
      free(current_path);
   }

   free(filename);
 /*   free(localcoords[0]);
    free(localcoords[1]);
    free(localcoords[2]); */
    
   return v;
#else

#endif

}