/* * Copyright (C) 1997 NCSA * All rights reserved. * * Programmer: Robb Matzke * Wednesday, October 15, 1997 * * Purpose: Tests various aspects of indexed raw data storage. */ #include #include #include #include #include #include #define FILENAME "istore.h5" #define TEST_SMALL 0x0001 #define TEST_MEDIUM 0x0002 #define AT() printf (" at %s:%d in %s()...\n", \ __FILE__, __LINE__, __FUNCTION__); /*------------------------------------------------------------------------- * Function: print_array * * Purpose: Prints the values in an array * * Return: void * * Programmer: Robb Matzke * Friday, October 10, 1997 * * Modifications: * *------------------------------------------------------------------------- */ static void print_array (uint8 *array, size_t nx, size_t ny, size_t nz) { int i, j, k; for (i=0; i1) { printf ("i=%d:\n", i); } else { printf ("%03d:", i); } for (j=0; j1) printf ("%03d:", j); for (k=0; k1) printf ("\n"); } printf ("\n"); } } /*------------------------------------------------------------------------- * Function: new_object * * Purpose: Creates a new object that refers to a indexed storage of raw * data. No raw data is stored. * * Return: Success: Handle to a new open object. * * Failure: NULL, error message printed. * * Programmer: Robb Matzke * Wednesday, October 15, 1997 * * Modifications: * *------------------------------------------------------------------------- */ static H5G_entry_t * new_object (H5F_t *f, const char *name, size_t ndims) { H5G_entry_t *handle = NULL; H5O_istore_t istore; size_t alignment[H5O_ISTORE_NDIMS]; intn i; /* Create the object symbol table entry and header */ if (NULL==(handle=H5G_create (f, name, 64))) { puts ("*FAILED*"); if (!isatty (1)) { AT (); printf (" H5G_create (f, name=\"%s\") = NULL\n", name); } return NULL; } /* Add the indexed-storage message */ for (i=0; i1) printf (",%d", offset[1]); if (ndims>2) printf (",%d", offset[2]); printf ("), size=(%d", size[0]); if (ndims>1) printf (",%d", size[1]); if (ndims>2) printf (",%d", size[2]); printf ("), %d element%s", nelmts, 1==nelmts?"":"s"); if (0==nelmts) printf (" *SKIPPED*"); printf ("\n"); fflush (stdout); #endif /* Fill the source array */ if (0==nelmts) continue; memset (buf, 128+ctr, nelmts); /* Write to disk */ if (H5F_istore_write (f, &istore, offset, size, buf)<0) { puts ("*FAILED*"); if (!isatty (1)) { AT (); printf (" Write failed: ctr=%d\n", ctr); } goto error; } /* Read from disk */ memset (check, 0xff, nelmts); if (H5F_istore_read (f, &istore, offset, size, check)<0) { puts ("*FAILED*"); if (!isatty (1)) { AT (); printf (" Read failed: ctr=%d\n", ctr); } goto error; } if (memcmp (buf, check, nelmts)) { puts ("*FAILED*"); if (!isatty (1)) { AT (); printf (" Read check failed: ctr=%d\n", ctr); printf (" Wrote:\n"); print_array (buf, size[0], size[1], size[2]); printf (" Read:\n"); print_array (buf, size[0], size[1], size[2]); } goto error; } /* Write to `whole' buffer for later checking */ H5V_hyper_copy (ndims, size, whole_size, offset, whole, /*dst*/ size, H5V_ZERO, buf); /*src*/ /* Update max corner */ for (i=0; i1) printf (", j=%d", j); if (ndims>2) printf (", k=%d", k); printf ("\n Check array is:\n"); print_array (whole, nx, ny, nz); printf (" Value read is:\n"); print_array (buf, nx, ny, nz); } goto error; } } } } H5G_close (f, handle); puts (" PASSED"); H5MM_xfree (buf); H5MM_xfree (check); H5MM_xfree (whole); return SUCCEED; error: H5MM_xfree (buf); H5MM_xfree (check); H5MM_xfree (whole); return FAIL; } /*------------------------------------------------------------------------- * Function: test_sparse * * Purpose: Creates a sparse matrix consisting of NBLOCKS randomly placed * blocks each of size NX,NY,NZ. * * Return: Success: SUCCEED * * Failure: FAIL * * Programmer: Robb Matzke * Wednesday, October 22, 1997 * * Modifications: * *------------------------------------------------------------------------- */ static herr_t test_sparse (H5F_t *f, const char *prefix, size_t nblocks, size_t nx, size_t ny, size_t nz) { intn ndims, ctr; char dims[64], s[256], name[256]; size_t offset[3], size[3]; H5G_entry_t *handle = NULL; H5O_istore_t istore; uint8 *buf = NULL; if (!nz) { if (!ny) { ndims = 1; ny = nz = 1; sprintf (dims, "%d", nx); } else { ndims = 2; nz = 1; sprintf (dims, "%dx%d", nx, ny); } } else { ndims = 3; sprintf (dims, "%dx%dx%d", nx, ny, nz); } sprintf (s, "Testing istore sparse: %s", dims); printf ("%-70s", s); fflush (stdout); buf = H5MM_xmalloc (nx*ny*nz); /* Build the new empty object */ sprintf (name, "%s_%s", prefix, dims); if (NULL==(handle=new_object (f, name, ndims))) { if (!isatty (1)) { AT (); printf (" Cannot create %d-d object `%s'\n", ndims, name); } goto error; } if (NULL==H5O_read (f, H5O_NO_ADDR, handle, H5O_ISTORE, 0, &istore)) { puts ("*FAILED*"); if (!isatty (1)) { AT (); printf (" Unable to read istore message\n"); } goto error; } for (ctr=0; ctr1) printf (",%d", offset[1]); if (ndims>2) printf (",%d", offset[2]); printf ("), size=(%d", size[0]); if (ndims>1) printf (",%d", size[1]); if (ndims>2) printf (",%d", size[2]); printf (")\n"); } goto error; } /* We don't test reading yet.... */ } H5G_close (f, handle); puts (" PASSED"); H5MM_xfree (buf); return SUCCEED; error: H5MM_xfree (buf); return FAIL; } /*------------------------------------------------------------------------- * Function: main * * Purpose: Tests indexed storage stuff. * * Return: Success: exit(0) * * Failure: exit(non-zero) * * Programmer: Robb Matzke * Wednesday, October 15, 1997 * * Modifications: * *------------------------------------------------------------------------- */ int main (int argc, char *argv[]) { H5F_t *f; herr_t status; int nerrors = 0; uintn size_of_test; /* Parse arguments or assume `small' */ if (1==argc) { size_of_test = TEST_SMALL; } else { intn i; for (i=1,size_of_test=0; i