예제 #1
0
/*-------------------------------------------------------------------------
 * Function:	test_write_bad
 *
 * Purpose:	Try writing to an existing data but using an incompatible
 *		size or data type.
 *
 * 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_write_bad(DBfile *dbfile)
{
    int		i, data[TEST_NELMTS], dims[4], nerrors=0;

#ifdef HAVE_HDF5_H
    H5E_BEGIN_TRY {
#endif

	puts("=== Error conditions ===");

	for (i=0; i<TEST_NELMTS; i++) data[i] = 911;

	/* Write to "3d_int" but supply only 1 dimension */
	dims[0] = TEST_NELMTS;
	if (DBWrite(dbfile, "3d_int", data, dims, 1, DB_INT)>=0) {
	    puts("DBWrite() to 3d_int with 1d data should have failed");
	    nerrors++;
	}

	/* Write to "3d_int" but with the wrong sizes */
	dims[0] = 3;
	dims[2] = 4;
	dims[1] = TEST_NELMTS/(dims[0]*dims[2]);
	if (DBWrite(dbfile, "3d_int", data, dims, 3, DB_INT)>=0) {
	    puts("DBWrite() to 3d_int with wrong dims should have faild");
	    nerrors++;
	}

	/* Write to "4d_float" but with integer data */
	DBForceSingle(TRUE);
	dims[0] = 6;
	dims[1] = 5;
	dims[2] = 4;
	dims[3] = TEST_NELMTS/(dims[0]*dims[1]*dims[2]);
	if (DBWrite(dbfile, "4d_float", data, dims, 4, DB_INT)>=0) {
	    puts("DBWrite() to 4d_float with integer data should have failed");
	    nerrors++;
	}
	DBForceSingle(FALSE);

#ifdef HAVE_HDF5_H
    } H5E_END_TRY;
#endif

    return nerrors;
}
예제 #2
0
/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose: Test various read operations.	
 *
 * Return:	0
 *
 * Programmer:Mark C. Miller, Thu Jul 15 08:23:56 PDT 2010
 *-------------------------------------------------------------------------
 */
int
main(int argc, char *argv[])
{
    int            driver = DB_PDB, driverType = DB_PDB;
    int            i, err = 0;
    DBfile        *dbfile;
    int            show_all_errors = FALSE;
    char           filename[256];
    char          *obj_names[13];
    int            ordering[13];

    /* Parse command-line */
    for (i=1; i<argc; i++) {
        if (!strncmp(argv[i], "DB_PDB", 6)) {
            driver = StringToDriver(argv[i]);
            driverType = DB_PDB;
        } else if (!strncmp(argv[i], "DB_HDF5", 7)) {
            driver = StringToDriver(argv[i]);
            driverType = DB_HDF5;
        } else if (!strcmp(argv[i], "show-all-errors")) {
            show_all_errors = 1;
	} else if (argv[i][0] != '\0') {
	    fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]);
	}
    }
    
    DBShowErrors(show_all_errors?DB_ALL_AND_DRVR:DB_TOP, NULL);
    DBForceSingle(1);

    sprintf(filename, "multi_rect2d.%s", driverType==DB_PDB?"pdb":"h5");
    dbfile = DBOpen(filename, DB_UNKNOWN, DB_READ);
    DBSetDir(dbfile, "block7");

    obj_names[0] = "cycle";
    obj_names[1] = "d";
    obj_names[2] = "../_fileinfo";
    obj_names[3] = "otherfile:block7/u";
    obj_names[4] = "v";
    obj_names[5] = "u";
    obj_names[6] = "/.silo/#000005";
    obj_names[7] = "../block7/d";
    obj_names[8] = "../block9/d";
    obj_names[9] = "../block4/d";
    obj_names[10] = "../mesh1_hidden";
    obj_names[11] = "../mesh1";
    obj_names[12] = "../block11/u";

    DBSortObjectsByOffset(dbfile, 13, obj_names, ordering);
    printf("UNsorted objects...\n");
    for (i = 0; i < 13; i++)
        printf("\t\"%s\"\n", obj_names[i]);
    printf("Sorted objects...\n");
    for (i = 0; i < 13; i++)
        printf("\t\"%s\"\n", obj_names[ordering[i]]);

    DBClose(dbfile);

    return err;
}
예제 #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);
}
예제 #4
0
/*----------------------------------------------------------------------------
 *----------------------------------------------------------------------------
 *                              Main Program
 *----------------------------------------------------------------------------
 *----------------------------------------------------------------------------
 * Modifications:
 * 	Robb Matzke, 1999-04-09
 *	Added argument parsing to control the driver which is used.
 *
 *---------------------------------------------------------------------------*/
int main(int argc, char *argv[]) {
  int x,y;
  int m,s;
  int err, mixc;
  int i, driver=DB_PDB, reorder=0;
  char filename[64], *file_ext=".pdb";
  int show_all_errors = FALSE;
  DBfile *db;

  /* Parse command-line */
  for (i=1; i<argc; i++) {
      if (!strncmp(argv[i], "DB_PDB", 6)) {
	  driver = StringToDriver(argv[i]);
	  file_ext = ".pdb";
      } else if (!strncmp(argv[i], "DB_HDF5", 7)) {
          driver = StringToDriver(argv[i]);
	  file_ext = ".h5";
      } else if (!strcmp(argv[i], "reorder")) {
	  reorder = 1;
      } else if (!strcmp(argv[i], "show-all-errors")) {
          show_all_errors = 1;
      } else if (!strcmp(argv[i], "difftol")) {
          difftol = strtod(argv[i+1], 0);
          i++;
      } else if (argv[i][0] != '\0') {
	  fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]);
      }
  }
    
  if (show_all_errors) DBShowErrors(DB_ALL_AND_DRVR, 0);

  Mesh_Create(&mesh,20,20);
  
  /* -=-=-=-=-=-=-=-=-=- */
  /*  Setup Coordinates  */
  /* -=-=-=-=-=-=-=-=-=- */
  printf("Creating the mesh\n");

  for (x=0;x<mesh.nx;x++) {
    for (y=0;y<mesh.ny;y++) {
      float xx = (x-10);
      float yy = ((xx-8.5)*xx*(xx+8.5))/40. + (y-10);
      mesh.node[x][y].x = xx*2+(yy*yy/50 - 3);
      mesh.node[x][y].y = yy;
    }
  }


  /* -=-=-=-=-=-=-=-=-=- */
  /*  Do Mesh Variables  */
  /* -=-=-=-=-=-=-=-=-=- */
  printf("Creating the variables\n");

  /* do zone vars */
  for (x=0;x<mesh.zx;x++) {
    for (y=0;y<mesh.zy;y++) {
      mesh.zone[x][y].vars[ZV_P] = sqrt((mesh.node[x][y].x*mesh.node[x][y].x) +
                                        (mesh.node[x][y].y*mesh.node[x][y].y));
      mesh.zone[x][y].vars[ZV_D] = 10. / (mesh.zone[x][y].vars[ZV_P]+5);
    }
  }

  /* do node vars */
  for (x=0;x<mesh.nx;x++) {
    for (y=0;y<mesh.ny;y++) {
      mesh.node[x][y].vars[NV_U] = mesh.node[x][y].x;
      mesh.node[x][y].vars[NV_V] = mesh.node[x][y].y;
    }
  }


  /* -=-=-=-=-=-=-=-=-=- */
  /*    Do Materials     */
  /* -=-=-=-=-=-=-=-=-=- */
  printf("Overlaying materials\n");


  /* initialize */
  for (x=0;x<mesh.zx;x++) {
    for (y=0;y<mesh.zy;y++) {
      mesh.zone[x][y].nmats=0;
    }
  }
	  
  /* do it */
  for (m=1; m<=nmat; m++) {
    for (x=0;x<mesh.zx;x++) {
      for (y=0;y<mesh.zy;y++) {
	float x00=mesh.zone[x][y].n[0][0]->x;
	float y00=mesh.zone[x][y].n[0][0]->y;
	float x10=mesh.zone[x][y].n[1][0]->x;
	float y10=mesh.zone[x][y].n[1][0]->y;
	float x01=mesh.zone[x][y].n[0][1]->x;
	float y01=mesh.zone[x][y].n[0][1]->y;
	float x11=mesh.zone[x][y].n[1][1]->x;
	float y11=mesh.zone[x][y].n[1][1]->y;

	int   i,j;
	int   c=0;
	float vf=0.;
        double vfd=0.;
	const int RES=40; /* subsampling resolution */

	/* Subsample the zone at RESxRES to    *
	 * get a more accurate volume fraction */
	for (i=0;i<=RES;i++) {
	  for (j=0;j<=RES;j++) {
	    float ii=(float)i/(float)RES;
	    float jj=(float)j/(float)RES;
	    float xc = (x00*ii + x10*(1.-ii))*jj + 
	               (x01*ii + x11*(1.-ii))*(1.-jj);
	    float yc = (y00*ii + y10*(1.-ii))*jj + 
                       (y01*ii + y11*(1.-ii))*(1.-jj);

	    switch (m) {
	    case 1:
	      if (xc>-15 && yc>2) vf++;
	      break;
	    case 2:
	      if (xc>-15 && yc<=2 && xc-5>yc) vf++;
	      break;
	    case 3:
	      if (xc>-15 && yc<=2 && xc-5<=yc) vf++;
	      break;
	    case 4:
	      if (xc<= -15) vf++;
	      break;
	    default:
	      break;
	    }

	    c++;
	  }
	}

        vfd = vf;
	vf /= (float)c;
        vfd /= (double)c;

	mesh.zone[x][y].matvf[m]=vf;
	mesh.zone[x][y].matvfd[m]=vfd;
	if (vf)
	  mesh.zone[x][y].nmats++;
      }
    }
  }
  
  /* check for errors in mat-assigning code! */
  err=0;
  for (x=0;x<mesh.zx;x++) {
    for (y=0;y<mesh.zy;y++) {
      float vf=0;
      for (m=1; m<=nmat; m++) {
	vf += mesh.zone[x][y].matvf[m];
      }
      if (vf<.99 || vf>1.01) {
	printf("Error in zone x=%d y=%d: vf = %f\n",x,y,vf);
	err++;
      }
    }
  }
  if (err) exit(err);


  /* -=-=-=-=-=-=-=-=-=- */
  /*  do species stuff!  */
  /* -=-=-=-=-=-=-=-=-=- */
  printf("Overlaying material species\n");


  err=0;
  for (m=1;m<=nmat;m++) {
    for (x=0;x<mesh.zx;x++) {
      for (y=0;y<mesh.zy;y++) {
	if (mesh.zone[x][y].matvf[m]>0.) {
	  float mftot=0.;
	  for (s=0; s<nspec[m-1]; s++) {
	    float x00=mesh.zone[x][y].n[0][0]->x;
	    float y00=mesh.zone[x][y].n[0][0]->y;
	    float x10=mesh.zone[x][y].n[1][0]->x;
	    float y10=mesh.zone[x][y].n[1][0]->y;
	    float x01=mesh.zone[x][y].n[0][1]->x;
	    float y01=mesh.zone[x][y].n[0][1]->y;
	    float x11=mesh.zone[x][y].n[1][1]->x;
	    float y11=mesh.zone[x][y].n[1][1]->y;
	    float xx=(x00+x10+x01+x11)/4.;
	    float yy=(y00+y10+y01+y11)/4.;
	    double xxd=(x00+x10+x01+x11)/4.;
	    double yyd=(y00+y10+y01+y11)/4.;
	    
	    float mf=0.;
	    double mfd=0.;
	    float g,g1,g2; /* gradient values */
	    double gd,g1d,g2d; /* gradient values */
	    switch (m) {
	    case 1:
	      g=lim01((xx+20.)/40.);
	      gd=lim01((xxd+20.)/40.);
	      switch (s) {
	      case 0: mf=g;    mfd=gd;    break;
	      case 1: mf=1.-g; mfd=1.-gd; break;
	      default: exit(-1);
	      }
	      break;
	    case 2:
	      g=lim01((yy+20.)/40.);
	      gd=lim01((yyd+20.)/40.);
	      switch (s) {
	      case 0: mf=.2+g/2.; mfd=.2+gd/2.; break;
	      case 1: mf=.5-g/2.; mfd=.5-gd/2.; break;
	      case 2: mf=.2;      mfd=.2;       break;
	      case 3: mf=.1;      mfd=.1;       break;
	      default: exit(-1);
	      }
	      break;
	    case 3:
	      g1=lim01((xx-5+yy+40.)/80.);
	      g2=lim01((xx-5-yy+40.)/80.);
	      g1d=lim01((xxd-5+yyd+40.)/80.);
	      g2d=lim01((xxd-5-yyd+40.)/80.);
	      switch (s) {
	      case 0: mf=g1/2.;	    mfd=g1d/2.;     break;
	      case 1: mf=g2/4.;	    mfd=g2d/4.;     break;
	      case 2: mf=.5-g1/2.;  mfd=.5-g1d/2.;  break;
	      case 3: mf=.25-g2/4.; mfd=.25-g2d/4.; break;
	      case 4: mf=.25;	    mfd=.25;        break;
	      default: exit(-1);
	      }
	      break;
	    case 4:
	      switch (s) {
	      case 0: mf=1.0; mfd=1.0;  break;
	      default: exit(-1);
	      }
	      break;
	    default:
		exit(-1);
	      break;
	    }
	    
	    mesh.zone[x][y].specmf[m][s] = mf;
	    mesh.zone[x][y].specmfd[m][s] = mfd;
	    mftot += mf;
	  }
	  if (mftot < .99 || mftot > 1.01) {
	    printf("Error in zone x=%d y=%d mat=%d: mf = %f\n",x,y,m,mftot);
	    err++;
	  }
	}
      }
    }
  }
  if (err) exit(err);


  /* -=-=-=-=-=-=-=-=-=- */
  /* write to silo files */
  /* -=-=-=-=-=-=-=-=-=- */

  sprintf(filename, "specmix_quad%s", file_ext);
  printf("Writing %s using curvilinear mesh.\n", filename);
  db=DBCreate(filename, DB_CLOBBER, DB_LOCAL, "Mixed zone species test", driver);
  mixc=domatspec(db, doWrite, 0);
  writemesh_curv2d(db,mixc,reorder);
  DBClose(db);

  sprintf(filename, "specmix_ucd%s", file_ext);
  printf("Writing %s using unstructured mesh.\n", filename);
  db=DBCreate(filename, DB_CLOBBER, DB_LOCAL, "Mixed zone species test", driver);
  mixc=domatspec(db, doWrite, 0);
  writemesh_ucd2d(db,mixc,reorder);
  DBClose(db);

  /* Test read-back of species */
  printf("Reading %s with Force Single off.\n", filename);
  db=DBOpen(filename, driver, DB_READ);
  domatspec(db, doReadAndCheck, 0);
  DBClose(db);
  printf("Reading %s with Force Single ON.\n", filename);
  DBForceSingle(1);
  db=DBOpen(filename, driver, DB_READ);
  domatspec(db, doReadAndCheck, 1);
  DBClose(db);

  printf("Done!\n");

  for (x=0;x<mesh.nx;x++)
      free(mesh.node[x]);
  free(mesh.node);

  for (x=0;x<mesh.zx;x++)
    free(mesh.zone[x]);
  free(mesh.zone);

  CleanupDriverStuff();
  return 0;
}
예제 #5
0
/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:	
 *
 * Return:	0
 *
 * Programmer:	
 *
 * Modifications:
 * 	Robb Matzke, 1999-04-09
 *	Added argument parsing to control the driver which is used.
 *
 *      Mark C. Miller, Mon Sep 21 15:20:30 PDT 2009
 *      Added code to test long long type.
 *
 *      Mark C. Miller, Wed Sep 23 11:57:24 PDT 2009
 *      Added logic to test DBInqFile.
 *
 *      Mark C. Miller, Fri Nov 13 15:40:35 PST 2009
 *      Test long long on PDB driver too.
 *-------------------------------------------------------------------------
 */
int
main(int argc, char *argv[])
{
    
    int            i, j, k;
    int            ndims, dims[3];
    float          val[NX * NY * NZ];
    long long      lval[NX * NY * NZ];
    int            offset[3], length[3], stride[3];
    float          val2[NX * NY * NZ];
    long long      *lval2 = 0;
    int            cnt, driver=DB_PDB;
    char	  *filename="simple.pdb";
    int            k1, k2;
    int            err = 0;
    int            inqval;
    DBfile        *dbfile;
    int            show_all_errors = FALSE;

    /* Parse command-line */
    for (i=1; i<argc; i++) {
	if (!strncmp(argv[i], "DB_PDB", 6)) {
	    driver = StringToDriver(argv[i]);
	    filename = "simple.pdb";
	} else if (!strncmp(argv[i], "DB_HDF5", 7)) {
            driver = StringToDriver(argv[i]);
	    filename = "simple.h5";
        } else if (!strcmp(argv[i], "show-all-errors")) {
            show_all_errors = 1;
	} else if (argv[i][0] != '\0') {
	    fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]);
	}
    }
    
    DBShowErrors(show_all_errors?DB_ALL_AND_DRVR:DB_TOP, NULL);
    DBForceSingle(1);

    /*
     * Build a simple variables.
     */
    ndims = 3;

    dims[0] = NZ;
    dims[1] = NY;
    dims[2] = NX;

    for (k = 0; k < NZ; k++) {
        for (j = 0; j < NY; j++) {
            for (i = 0; i < NX; i++) {
                val[i + j * NX + k * NX * NY] = i + j * NX + k * NX * NY;
                lval[i + j * NX + k * NX * NY] = ((long long) 1 << 35) + i + j * NX + k * NX * NY;
            }
        }
    }

    /* Test InqFile on a PDB (but not Silo) file */
    if (driver == DB_PDB)
        inqval = DBInqFile("not_a_silo_file.pdb");
    else
        inqval = DBInqFile("not_a_silo_file.h5");
    if (inqval < 0)
    {
        fprintf(stderr, "Error in InqFile attempting to identify not_a_silo_file");
        err = 1;
    }
    else if (inqval > 0)
    {
        fprintf(stderr, "InqFile incorrectly identified not_a_silo_file");
        err = 1;
    }

    /* Create empty silo file to test InqFile */
    dbfile = DBCreate(filename, 0, DB_LOCAL, "Empty Silo File", driver);
    DBClose(dbfile);
    if (DBInqFile(filename) <= 0)
    {
        fprintf(stderr, "InqFile says file created via DBCreate is NOT a silo file");
        err = 1;
    }
    unlink(filename);

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

    DBWrite(dbfile, "simple", val, dims, ndims, DB_FLOAT);
    DBWrite(dbfile, "longlong", lval, dims, ndims, DB_LONG_LONG);

    DBClose(dbfile);

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

    offset[0] = 0;
    offset[1] = 0;
    offset[2] = 0;
    length[0] = NZ2;
    length[1] = NY2;
    length[2] = NX2;
    stride[0] = 1;
    stride[1] = 1;
    stride[2] = 1;

    for (i = 0; i < NX * NY * NZ; i++)
        val2[i] = 0;

    DBReadVarSlice(dbfile, "simple", offset, length, stride, ndims, val2);
    lval2 = DBGetVar(dbfile, "longlong");

    DBClose(dbfile);

    /*
     * Check the data.
     */
    cnt = 0;
    for (k = 0; k < NZ2; k++) {
        for (j = 0; j < NY2; j++) {
            for (i = 0; i < NX2; i++) {
                if (val2[i + j * NX2 + k * NX2 * NY2] != val[i + j * NX + k * NX * NY])
                    cnt++;
            }
        }
    }
    err += cnt;
    printf("%d values don't match\n", cnt);

    cnt = 0;
    k1 = NX2 * NY2 * NZ2;
    k2 = NX * NY * NZ;
    for (i = k1; i < k2; i++)
        if (val2[i] != 0)
            cnt++;
    printf("%d values were overwritten\n", cnt);

    cnt = 0;
    for (k = 0; k < NZ && lval2; k++) {
        for (j = 0; j < NY; j++) {
            for (i = 0; i < NX; i++) {
                if (lval2[i + j * NX + k * NX * NY] != lval[i + j * NX + k * NX * NY])
                    cnt++;
            }
        }
    }
    err += cnt;
        printf("%d long long values don't match\n", cnt);

    if (lval2) free(lval2);

    CleanupDriverStuff();
    return err;
}
예제 #6
0
/*-------------------------------------------------------------------------
 * Function:	test_write_all
 *
 * Purpose:	Write complete arrays from file to disk with DBWrite(). This
 *		only tests that DBWrite() returns success -- it doesn't
 *		attempt to read the data and compare it to what was written.
 *
 * 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_write_all(DBfile *dbfile)
{
    int		i, dims[5], nerrors=0;

    puts("DBWrite():");
    
    /* Initialize output arrays */
    for (i=0; i<TEST_NELMTS; i++, cntr_g++) {
	cdata_g[i] = cntr_g%128; /*`char' has unknown sign so play it safe*/
	sdata_g[i] = cntr_g-TEST_NELMTS/2;
	idata_g[i] = cntr_g-TEST_NELMTS/2;
	ldata_g[i] = cntr_g-TEST_NELMTS/2;
	fdata_g[i] = (cntr_g-TEST_NELMTS/2)/10.0;
	ddata_g[i] = (cntr_g-TEST_NELMTS/2)/10.0;
    }
    
    /* 1d char */
    puts("    1d_char");
    dims[0] = TEST_NELMTS;
    if (DBWrite(dbfile, "1d_char", cdata_g, dims, 1, DB_CHAR)<0) {
	puts("        DBWrite() failed");
	nerrors++;
    }

    /* 2d short */
    puts("    2d_short");
    dims[0] = 2;
    dims[1] = TEST_NELMTS/dims[0];
    if (DBWrite(dbfile, "2d_short", sdata_g, dims, 2, DB_SHORT)<0) {
	puts("        DBWrite() failed");
	nerrors++;
    }

    /* 3d int */
    puts("    3d_int");
    dims[0] = 12;
    dims[1] = 30;
    dims[2] = TEST_NELMTS/(dims[0]*dims[1]);
    if (DBWrite(dbfile, "3d_int", idata_g, dims, 3, DB_INT)<0) {
	puts("        DBWrite() failed");
	nerrors++;
    }

    /* 3d long */
    puts("    3d_long");
    dims[0] = 5;
    dims[1] = 6;
    dims[2] = TEST_NELMTS/(dims[0]*dims[1]);
    if (DBWrite(dbfile, "3d_long", ldata_g, dims, 3, DB_LONG)<0) {
	puts("        DBWrite() failed");
	nerrors++;
    }

    /* 4d float */
    DBForceSingle(TRUE);
    puts("    4d_float");
    dims[0] = 6;
    dims[1] = 5;
    dims[2] = 4;
    dims[3] = TEST_NELMTS/(dims[0]*dims[1]*dims[2]);
    if (DBWrite(dbfile, "4d_float", fdata_g, dims, 4, DB_FLOAT)<0) {
	puts("        DBWrite() failed");
	nerrors++;
    }
    DBForceSingle(FALSE);

    /* 5d double */
    puts("    5d_double");
    dims[0] = 3;
    dims[1] = 2;
    dims[2] = 6;
    dims[3] = 5;
    dims[4] = TEST_NELMTS/(dims[0]*dims[1]*dims[2]*dims[3]);
    if (DBWrite(dbfile, "5d_double", ddata_g, dims, 5, DB_DOUBLE)<0) {
	puts("        DBWrite() failed");
	nerrors++;
    }

    return nerrors;
}
예제 #7
0
/*-------------------------------------------------------------------------
 * Function:	test_get_all
 *
 * Purpose:	Tests DBGetVar() 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_get_all(DBfile *dbfile)
{
    int		i, nerrors=0;

    char	*cdata_in=NULL;
    short	*sdata_in=NULL;
    int		*idata_in=NULL;
    long	*ldata_in=NULL;
    float	*fdata_in=NULL;
    double	*ddata_in=NULL;

    puts("DBGetVar():");
    if (DB_LOCAL!=arch_g) {
	puts("    Skipped because target is not DB_LOCAL"
	     " -- use browser instead");
	return 0;
    }
    
    /* 1d char */
    puts("    1d_char");
    if (NULL==(cdata_in=DBGetVar(dbfile, "1d_char"))) {
	puts("        DBGetVar() 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++;
	    }
	}
	free(cdata_in);
    }

    /* 2d short */
    puts("    2d_short");
    if (NULL==(sdata_in=DBGetVar(dbfile, "2d_short"))) {
	puts("        DBGetVar() 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++;
	    }
	}
	free(sdata_in);
    }


    /* 3d int */
    puts("    3d_int");
    if (NULL==(idata_in=DBGetVar(dbfile, "3d_int"))) {
	puts("        DBGetVar() 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]);
	    }
	}
	free(idata_in);
    }

    /* 3d long */
    puts("    3d_long");
    if (NULL==(ldata_in=DBGetVar(dbfile, "3d_long"))) {
	puts("        DBGetVar() 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]);
	    }
	}
	free(ldata_in);
    }

    /* 4d float */
    DBForceSingle(TRUE);
    puts("    4d_float");
    if (NULL==(fdata_in=DBGetVar(dbfile, "4d_float"))) {
	puts("        DBGetVar() failed");
	nerrors++;
    } else {
        printf("testing DBGetVar of 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]);
	    }
	}
	free(fdata_in);
    }
    DBForceSingle(FALSE);

    /* 5d double */
    puts("    5d_double");
    if (NULL==(ddata_in=DBGetVar(dbfile, "5d_double"))) {
	puts("        DBGetVar() 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]);
	    }
	}
	free(ddata_in);
    }
    return nerrors;
}
예제 #8
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;
}