/*------------------------------------------------------------------------- * Function: insert_libhdf5_settings * * Purpose: insert the contents of libhdf5.settings into a file * represented by flibinfo. * Make it an empty string if H5_HAVE_EMBEDDED_LIBINFO is not * defined, i.e., not enabled. * * Return: void *------------------------------------------------------------------------- */ static void insert_libhdf5_settings(FILE *flibinfo) { #ifdef H5_HAVE_EMBEDDED_LIBINFO FILE *fsettings; /* for files libhdf5.settings */ int inchar; int bol = 0; /* indicates the beginning of a new line */ if(NULL == (fsettings = HDfopen(LIBSETTINGSFNAME, "r"))) { HDperror(LIBSETTINGSFNAME); HDexit(EXIT_FAILURE); } /* end if */ /* print variable definition and the string */ /* Do not use const else AIX strings does not show it. */ fprintf(flibinfo, "char H5libhdf5_settings[]=\n"); bol++; while(EOF != (inchar = HDgetc(fsettings))) { if(bol) { /* Start a new line */ fprintf(flibinfo, "\t\""); bol = 0; } /* end if */ if(inchar == '\n') { /* end of a line */ fprintf(flibinfo, "\\n\"\n"); bol++; } /* end if */ else HDputc(inchar, flibinfo); } /* end while */ if(HDfeof(fsettings)) { /* wrap up */ if(!bol) /* EOF found without a new line */ fprintf(flibinfo, "\\n\"\n"); fprintf(flibinfo, ";\n\n"); } /* end if */ else { fprintf(stderr, "Read errors encountered with %s\n", LIBSETTINGSFNAME); HDexit(EXIT_FAILURE); } /* end else */ if(0 != HDfclose(fsettings)) { HDperror(LIBSETTINGSFNAME); HDexit(EXIT_FAILURE); } /* end if */ #else /* print variable definition and an empty string */ /* Do not use const else AIX strings does not show it. */ fprintf(flibinfo, "char H5libhdf5_settings[]=\"\";\n"); #endif } /* insert_libhdf5_settings() */
/*------------------------------------------------------------------------- * * Function: error_version_macros * * Purpose: Test H5E version compatibility macros. * * Return: Success: 0 * Failure: -1 * * Programmer: Neil Fortner * Saturday, October 11, 2008 * *------------------------------------------------------------------------- */ static int error_version_macros(void) { H5E_walk1_t walk_cb = &error_version_macros_cb; /* H5Ewalk callback function (test H5E_walk1_t) */ H5E_auto1_t auto_func; /* Automatic error handler (test H5E_auto1_t) */ void *client_data; /* Automatic error handler data */ FILE *file; /* File to redirect output to */ char filename[NAME_BUF_SIZE]; /* Output message about test being performed */ TESTING("H5E version compatibility macros"); /* Create the test file (used to prevent output of H5Eprint to the terminal) */ h5_fixname(ERR_VERS_NAME, H5P_DEFAULT, filename, sizeof filename); if (NULL == (file = HDfopen(filename, "w"))) TEST_ERROR; /* Print error stack (check H5Eprint1) */ if (H5Eprint1(file) < 0) TEST_ERROR; /* Get automatic error traversal function (check H5Eget_auto1) */ if (H5Eget_auto1(&auto_func, &client_data) < 0) TEST_ERROR; /* Set automatic error traversal function (check H5Eset_auto1) */ if (H5Eset_auto1(auto_func, client_data) < 0) TEST_ERROR; /* Push an error message (check H5Epush1) */ if (H5Epush1("somefile", "somefunc", 13241, H5E_STORAGE, H5E_BADATOM, "Hi! I'm an error message!") < 0) TEST_ERROR; /* Clear error stack (check H5Eclear1) */ if (H5Eclear1() < 0) TEST_ERROR; /* Walk the error stack (check H5Ewalk1) */ if (H5Ewalk1(H5E_WALK_DOWNWARD, walk_cb, NULL) < 0) TEST_ERROR; /* Close the file */ HDfclose(file); HDremove(filename); PASSED(); return 0; error: HDfclose(file); HDremove(filename); return -1; } /* end error_version_macros() */
/* * Class: hdf_hdf5lib_exceptions_HDFLibraryException * Method: printStackTrace0 * Signature: (Ljava/lang/Object;)V * * Call the HDF-5 library to print the HDF-5 error stack to 'file_name'. */ JNIEXPORT void JNICALL Java_hdf_hdf5lib_exceptions_HDF5LibraryException_printStackTrace0 (JNIEnv *env, jobject obj, jstring file_name) { FILE *stream = NULL; const char *file = NULL; if(file_name == NULL) { H5Eprint2(H5E_DEFAULT, stderr); } /* end if */ else { file = ENVPTR->GetStringUTFChars(ENVPAR file_name, 0); stream = HDfopen(file, "a+"); if(stream) { H5Eprint2(H5E_DEFAULT, stream); HDfclose(stream); } /* end if */ ENVPTR->ReleaseStringUTFChars(ENVPAR file_name, file); } /* end else */ } /* end Java_hdf_hdf5lib_exceptions_HDF5LibraryException_printStackTrace0() */
/*------------------------------------------------------------------------- * Function: main * * Purpose: Main entry point. * * Return: Success: EXIT_SUCCESS *------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { char *fname = NULL; FILE *f; /* temporary holding place for the stream pointer * so that rawoutstream is changed only when succeeded */ if(argc > 1) fname = argv[1]; /* First check if filename is string "NULL" */ if(fname != NULL) { /* binary output */ if((f = HDfopen(fname, "w")) != NULL) rawoutstream = f; } if(!rawoutstream) rawoutstream = stdout; print_header(); /* Generate embedded library information variable definition */ make_libinfo(); print_footer(); if(rawoutstream && rawoutstream != stdout) { if(HDfclose(rawoutstream)) fprintf(stderr, "closing rawoutstream"); else rawoutstream = NULL; } HDexit(EXIT_SUCCESS); }
/* * Function: main * Purpose: Start things up. * Return: EXIT_SUCCESS or EXIT_FAILURE * Programmer: Bill Wendling, 30. October 2001 * Modifications: */ int main(int argc, char **argv) { int exit_value = EXIT_SUCCESS; struct options *opts = NULL; #ifndef STANDALONE /* Initialize h5tools lib */ h5tools_init(); #endif output = stdout; opts = parse_command_line(argc, argv); if (!opts) { exit_value = EXIT_FAILURE; goto finish; } if (opts->output_file) { if ((output = HDfopen(opts->output_file, "w")) == NULL) { fprintf(stderr, "%s: cannot open output file\n", progname); perror(opts->output_file); goto finish; } } report_parameters(opts); run_test_loop(opts); finish: free(opts); return exit_value; }
/*------------------------------------------------------------------------- * Function: test_family_compat * * Purpose: Tests the backward compatibility for FAMILY driver. * See if we can open files created with v1.6 library. * The source file was created by the test/file_handle.c * of the v1.6 library. Then tools/misc/h5repart.c was * used to concantenated. The command was "h5repart -m 5k * family_file%05d.h5 family_v16_%05d.h5". * * Return: Success: 0 * Failure: -1 * * Programmer: Raymond Lu * June 3, 2005 * *------------------------------------------------------------------------- */ static herr_t test_family_compat(void) { hid_t file = (-1), fapl; hid_t dset; char dname[]="dataset"; char filename[1024]; char pathname[1024], pathname_individual[1024]; char newname[1024], newname_individual[1024]; FILE *tmp_fp, *old_fp; /* Pointers to temp & old files */ int counter = 0; TESTING("FAMILY file driver backward compatibility"); /* Set property list and file name for FAMILY driver */ fapl = h5_fileaccess(); if(H5Pset_fapl_family(fapl, (hsize_t)FAMILY_SIZE2, H5P_DEFAULT) < 0) TEST_ERROR; h5_fixname(COMPAT_BASENAME, fapl, filename, sizeof filename); h5_fixname(FILENAME[3], fapl, newname, sizeof newname); pathname[0] = '\0'; HDstrcat(pathname, filename); /* The following code makes the copies of the family files in the source directory. * Since we're going to open the files with write mode, this protects the original * files. */ sprintf(newname_individual, newname, counter); sprintf(pathname_individual, pathname, counter); while (h5_make_local_copy(pathname_individual, newname_individual) >= 0) { counter++; sprintf(newname_individual, newname, counter); sprintf(pathname_individual, pathname, counter); } if ((NULL != (old_fp = HDfopen(pathname_individual,"rb"))) && (NULL != (tmp_fp = HDfopen(newname_individual,"wb")))) TEST_ERROR; /* Make sure we can open the file. Use the read and write mode to flush the * superblock. */ if((file = H5Fopen(newname, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR; if((dset = H5Dopen2(file, dname, H5P_DEFAULT)) < 0) TEST_ERROR; if(H5Dclose(dset) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; /* Open the file again to make sure it isn't corrupted. */ if((file = H5Fopen(newname, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR; if((dset = H5Dopen2(file, dname, H5P_DEFAULT)) < 0) TEST_ERROR; if(H5Dclose(dset) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; h5_cleanup(FILENAME, fapl); PASSED(); return 0; error: H5E_BEGIN_TRY { H5Fclose(file); H5Pclose(fapl); } H5E_END_TRY; return -1; } /* end test_family_compat() */
static int read_info(const char *filename, pack_opt_t *options) { char stype[10]; char comp_info[1024]; FILE *fp = NULL; char c; int i, rc = 1; int ret_value = EXIT_SUCCESS; if ((fp = HDfopen(filename, "r")) == (FILE *) NULL) { error_msg("cannot open options file %s\n", filename); h5tools_setstatus(EXIT_FAILURE); ret_value = EXIT_FAILURE; goto done; } /* cycle until end of file reached */ while (1) { rc = fscanf(fp, "%s", stype); if (rc == -1) break; /*------------------------------------------------------------------------- * filter *------------------------------------------------------------------------- */ if (HDstrcmp(stype,"-f") == 0) { /* find begining of info */ i = 0; c = '0'; while (c != ' ') { fscanf(fp, "%c", &c); if (HDfeof(fp)) break; } c = '0'; /* go until end */ while (c != ' ') { fscanf(fp, "%c", &c); comp_info[i] = c; i++; if (HDfeof(fp)) break; if (c == 10 /*eol*/) break; } comp_info[i - 1] = '\0'; /*cut the last " */ if (h5repack_addfilter(comp_info, options) == -1) { error_msg("could not add compression option\n"); h5tools_setstatus(EXIT_FAILURE); ret_value = EXIT_FAILURE; goto done; } } /*------------------------------------------------------------------------- * layout *------------------------------------------------------------------------- */ else if (HDstrcmp(stype,"-l") == 0) { /* find begining of info */ i = 0; c = '0'; while (c != ' ') { fscanf(fp, "%c", &c); if (HDfeof(fp)) break; } c = '0'; /* go until end */ while (c != ' ') { fscanf(fp, "%c", &c); comp_info[i] = c; i++; if (HDfeof(fp)) break; if (c == 10 /*eol*/) break; } comp_info[i - 1] = '\0'; /*cut the last " */ if (h5repack_addlayout(comp_info, options) == -1) { error_msg("could not add chunck option\n"); h5tools_setstatus(EXIT_FAILURE); ret_value = EXIT_FAILURE; goto done; } } /*------------------------------------------------------------------------- * not valid *------------------------------------------------------------------------- */ else { error_msg("bad file format for %s", filename); h5tools_setstatus(EXIT_FAILURE); ret_value = EXIT_FAILURE; goto done; } } done: if (fp) HDfclose(fp); return ret_value; }
static int read_palette(const char* fname, rgb_t *palette, size_t palette_size) { FILE *file; char buffer[80]; unsigned u; unsigned int red; unsigned int green; unsigned int blue; unsigned nentries; char *srcdir = getenv("srcdir"); /* the source directory */ char data_file[512]; /* buffer to hold name of existing data file */ /*------------------------------------------------------------------------- * compose the name of the file to open, using "srcdir", if appropriate *------------------------------------------------------------------------- */ HDstrcpy(data_file, ""); if (srcdir) { HDstrcpy(data_file, srcdir); HDstrcat(data_file, "/"); } HDstrcat(data_file,fname); /* ensure the given palette is valid */ if (!palette) return -1; /* open the input file */ if (!(file = HDfopen(data_file, "r"))) { printf( "Could not open file %s. Try set $srcdir \n", data_file ); return -1; } /* read the file ident string */ if (HDfgets(buffer, sizeof(buffer), file) == NULL) { HDfclose(file); return -1; } /* ensure it matches the palette file ident string */ if ( HDstrncmp(buffer, STRING_JASC, sizeof(STRING_JASC) - 1) != 0 && HDstrncmp(buffer, STRING_CWPAL, sizeof(STRING_CWPAL) - 1) != 0 ) { HDfclose(file); return -1; } /* read the version string */ if (HDfgets(buffer, sizeof(buffer), file) == NULL) { HDfclose(file); return -1; } /* ensure it matches the palette file version string */ if ( HDstrncmp(buffer, VERSION_JASC, sizeof(VERSION_JASC) - 1) != 0 && HDstrncmp(buffer, VERSION_CWPAL, sizeof(VERSION_CWPAL) - 1) != 0 ) { HDfclose(file); return -1; } /* read the number of colors */ if (HDfgets(buffer, sizeof(buffer), file) == NULL) { HDfclose(file); return -1; } /* extract the number of colors. check for missing version or number of colors in this case it reads the first entry */ if ( HDstrlen( buffer ) > 4 ) { HDfclose(file); return -1; } if (sscanf(buffer, "%u", &nentries) != 1) { HDfclose(file); return -1; } /* ensure there are a sensible number of colors in the palette */ if ((nentries > 256) || (nentries > palette_size)) { HDfclose(file); return(-1); } /* read the palette entries */ for (u = 0; u < nentries; u++) { /* extract the red, green and blue color components. */ if (fscanf(file, "%u %u %u", &red, &green, &blue) != 3) { HDfclose(file); return -1; } /* store this palette entry */ palette[u].r = (unsigned char)red; palette[u].g = (unsigned char)green; palette[u].b = (unsigned char)blue; } /* close file */ HDfclose(file); return (int)nentries; }
static int read_data( const char* fname, /*IN*/ hsize_t *width, /*OUT*/ hsize_t *height /*OUT*/ ) { int i, n; int color_planes; char str[20]; FILE *f = NULL; int w, h; int n_elements; const char *data_file = H5_get_srcdir_filename(fname); int ret_val = -1; /*------------------------------------------------------------------------- * read *------------------------------------------------------------------------- */ if(NULL == (f = HDfopen(data_file, "r"))) { printf( "Could not open file %s. Try set $srcdir \n", data_file ); goto out; } fscanf(f, "%s", str); fscanf(f, "%d", &color_planes); fscanf(f, "%s", str); fscanf(f, "%d", &h); fscanf(f, "%s", str); fscanf(f, "%d", &w); /* Check product for overflow */ if(w < 1 || h < 1 || color_planes < 1) goto out; if(w > INT_MAX / h) goto out; if(w * h > INT_MAX / color_planes) goto out; /* Compute buffer size */ n_elements = w * h * color_planes; /* Check buffer size for overflow */ if(n_elements > INT_MAX / (int)sizeof(unsigned char)) goto out; /* Release the buffer, if it was previously allocated */ if(image_data) HDfree(image_data); /* Allocate the image data buffer */ image_data = (unsigned char *)HDmalloc((size_t)n_elements * sizeof(unsigned char)); if(NULL == image_data) goto out; *width = (hsize_t)w; *height = (hsize_t)h; /* Read data elements */ for(i = 0; i < n_elements; i++) { fscanf(f, "%d",&n); image_data[i] = (unsigned char)n; } /* end for */ /* Indicate success */ ret_val = 1; out: if(f) HDfclose(f); return ret_val; } /* end read_data() */
static int test_generate(void) { hid_t fid; hsize_t pal_dims[2] = { 256, 3 }; float *data; int imax, jmax, kmax; int n_elements; float valex, xmin, xmax, value; FILE *f = NULL; char *srcdir = getenv("srcdir"); /* the source directory */ char data_file[512]=""; /* buffer to hold name of existing data file */ int i; int retval = FAIL; /* create a file using default properties */ if ((fid=H5Fcreate(FILE3,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT))<0) goto out; printf("Testing read and process data and make indexed images\n"); /*------------------------------------------------------------------------- * compose the name of the file to open, using the srcdir, if appropriate *------------------------------------------------------------------------- */ if ( srcdir ) { HDstrcpy(data_file, srcdir); HDstrcat(data_file, "/"); } HDstrcat(data_file,DATA_FILE4); /*------------------------------------------------------------------------- * read data; the file data format is described below *------------------------------------------------------------------------- */ f = HDfopen( data_file, "r" ) ; if ( f == NULL ) { printf( "Could not find file %s. Try set $srcdir \n", data_file ); goto out; } /* !The first line of the ASCII file contains the dimension of the array : ! IMAX, JMAX, KMAX. The integers are stored with the FORTRAN format I5. !The second line contains the exclusion value, the minimum and the maximum value of this ! file. These numbers are stored with the FORTRAN format E12.5. ! The remaining lines contains the data of the array, with 5 numbers per line ! (except the last line for each I-line). ! The array is stored in horizontal slices from sea surface to sea bottom and from ! north to south. So the indexes go from : ! ! DO K = KMAX to 1 ! DO J = JMAX to 1 ! DO I = 1 to IMAX ! read ! OD ! OD ! OD ! ! ____________________________ ! / /| (imax,jmax,kmax) ! / sea surface / | ! / / | ! /__________________________ / | ! | | | ! | | | (imax,jmax,1) n ! | | / / ! | | / / ! ^ j | | / w <-----o-----> e ! k | / |__________________________|/ / ! | / (imax,1,1) / ! |----------> s ! i ! */ fscanf( f, "%d %d %d", &imax, &jmax, &kmax ); fscanf( f, "%f %f %f", &valex, &xmin, &xmax ); /* Sanity check on scanned-in values */ if(imax < 1 || jmax < 1 || kmax < 1) goto out; /* Test product for integer overflow */ if(imax > INT_MAX / jmax) goto out; if(imax * jmax > INT_MAX / kmax) goto out; n_elements = imax * jmax * kmax; /* Test buffer sizes for overflow */ if(n_elements > INT_MAX / (int)sizeof(unsigned char)) goto out; if(n_elements > INT_MAX / (int)sizeof(float)) goto out; data = (float *)HDmalloc((size_t)n_elements * sizeof(float)); if(NULL == data) goto out; image_data = (unsigned char *)HDmalloc((size_t)n_elements * sizeof(unsigned char)); if(NULL == image_data) goto out; for ( i = 0; i < n_elements; i++ ) { fscanf( f, "%f ", &value ); data[i] = value; } HDfclose(f); f = NULL; /*------------------------------------------------------------------------- * transform the data from floating point to unsigned char * we are processing all the data here *------------------------------------------------------------------------- */ TESTING2("make indexed image from all the data"); for ( i = 0; i < n_elements; i++ ) image_data[i] = (unsigned char)(( 255 * (data[i] - xmin ) ) / (xmax - xmin )); /* Make the image */ if ((H5IMmake_image_8bit(fid,"All data",(hsize_t)imax,(hsize_t)jmax,image_data))<0) goto out; PASSED(); /*------------------------------------------------------------------------- * transform the data from floating point to unsigned char * here we just process the land data *------------------------------------------------------------------------- */ TESTING2("make indexed image from land data"); for ( i = 0; i < n_elements; i++ ) { if ( data[i] < 0 ) image_data[i] = 0; else image_data[i] = (unsigned char)(( 255 * (data[i] ) ) / xmax ); } /* make the image */ if ((H5IMmake_image_8bit(fid,"Land data",(hsize_t)imax,(hsize_t)jmax,image_data))<0) goto out; PASSED(); /*------------------------------------------------------------------------- * transform the data from floating point to unsigned char * here we just process the sea data *------------------------------------------------------------------------- */ TESTING2("make indexed image from sea data"); for ( i = 0; i < n_elements; i++ ) { if ( data[i] > 0 ) image_data[i] = 0; else image_data[i] = (unsigned char)(( 255 * (data[i] - xmin ) ) / xmin ); } /* make the image */ if ((H5IMmake_image_8bit(fid,"Sea data",(hsize_t)imax,(hsize_t)jmax,image_data))<0) goto out; PASSED(); /*------------------------------------------------------------------------- * make a palette and attach it to the datasets *------------------------------------------------------------------------- */ TESTING2("attaching palettes"); /* make a palette */ if ((H5IMmake_palette(fid,PAL1_NAME,pal_dims,pal_rgb))<0) goto out; /* attach the palette to the image datasets */ if ((H5IMlink_palette(fid,"All data",PAL1_NAME))<0) goto out; if ((H5IMlink_palette(fid,"Land data",PAL1_NAME))<0) goto out; if ((H5IMlink_palette(fid,"Sea data",PAL1_NAME))<0) goto out; PASSED(); /*------------------------------------------------------------------------- * close *------------------------------------------------------------------------- */ if (H5Fclose(fid)<0) goto out; /* Release memory buffers */ HDfree(data); HDfree(image_data); /* Indicate success */ return 0; /* error zone, gracefully close */ out: /* Release memory buffers */ if(data) HDfree(data); if(image_data) HDfree(image_data); H5E_BEGIN_TRY { H5Fclose(fid); } H5E_END_TRY; if(f) HDfclose(f); H5_FAILED(); return retval; }
/*------------------------------------------------------------------------- * Function: reader * * Purpose: Reads some data from random locations in the dataset. * * Return: Success: 0 * * Failure: >0 * * Programmer: Robb Matzke * Friday, April 10, 1998 * * Modifications: * *------------------------------------------------------------------------- */ static int reader(char *filename, hid_t fapl) { FILE *script = NULL; hid_t file = -1, mspace = -1, fspace = -1, d2 = -1; char ln[128], *s; hsize_t hs_offset[1]; hsize_t hs_size[1] = {WRT_SIZE}; int *buf = (int *)HDmalloc(sizeof(int) * WRT_SIZE); int i, j, zero, wrong, nerrors = 0; /* Open script file */ script = HDfopen(DNAME, "r"); /* Open HDF5 file */ if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) FAIL_STACK_ERROR /* Open the dataset */ if((d2 = H5Dopen2(file, "d2", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR if((fspace = H5Dget_space(d2)) < 0) FAIL_STACK_ERROR /* Describe `buf' */ if((mspace = H5Screate_simple(1, hs_size, hs_size)) < 0) FAIL_STACK_ERROR /* Read each region */ while(HDfgets(ln, (int)sizeof(ln), script)) { if('#' != ln[0]) break; i = (int)HDstrtol(ln + 1, &s, 10); hs_offset[0] = HDstrtoll(s, NULL, 0); HDfprintf(stdout, "#%03d 0x%016Hx%47s", i, hs_offset[0], ""); HDfflush(stdout); if(H5Sselect_hyperslab(fspace, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL) < 0) FAIL_STACK_ERROR if(H5Dread(d2, H5T_NATIVE_INT, mspace, fspace, H5P_DEFAULT, buf) < 0) FAIL_STACK_ERROR /* Check */ for(j = zero = wrong = 0; j < WRT_SIZE; j++) { if(0 == buf[j]) zero++; else if(buf[j] != i + 1) wrong++; } if(zero) { H5_FAILED(); printf(" %d zero%s\n", zero, 1 == zero ? "" : "s"); } else if(wrong) { SKIPPED(); HDputs(" Possible overlap with another region."); nerrors++; } else { PASSED(); } } if(H5Dclose(d2) < 0) FAIL_STACK_ERROR if(H5Sclose(mspace) < 0) FAIL_STACK_ERROR if(H5Sclose(fspace) < 0) FAIL_STACK_ERROR if(H5Fclose(file) < 0) FAIL_STACK_ERROR HDfree(buf); HDfclose(script); return nerrors; error: H5E_BEGIN_TRY { H5Dclose(d2); H5Sclose(mspace); H5Sclose(fspace); H5Fclose(file); } H5E_END_TRY; if(buf) HDfree(buf); if(script) HDfclose(script); return 1; }
/*------------------------------------------------------------------------- * Function: writer * * Purpose: Creates a *big* dataset. * * Return: Success: 0 * * Failure: >0 * * Programmer: Robb Matzke * Wednesday, April 8, 1998 * * Modifications: * Robb Matzke, 15 Jul 1998 * Addresses are written to the file DNAME instead of stdout. * *------------------------------------------------------------------------- */ static int writer (char* filename, hid_t fapl, fsizes_t testsize, int wrt_n) { hsize_t size1[4] = {8, 1024, 1024, 1024}; hsize_t size2[1] = {GB8LL}; hsize_t hs_start[1]; hsize_t hs_size[1]; hid_t file=-1, space1=-1, space2=-1, mem_space=-1, d1=-1, d2=-1; int *buf = (int*)HDmalloc (sizeof(int) * WRT_SIZE); int i, j; FILE *out = HDfopen(DNAME, "w"); hid_t dcpl; switch(testsize){ case LFILE: TESTING("Large dataset write(2GB)"); /* reduce size1 to produce a 2GB dataset */ size1[1] = 1024/16; size2[0] /= 16; break; case XLFILE: TESTING("Extra large dataset write(4GB)"); /* reduce size1 to produce a 4GB dataset */ size1[1] = 1024/8; size2[0] /= 8; break; case HUGEFILE: TESTING("Huge dataset write"); /* Leave size1 as 32GB */ break; case SFILE: TESTING("small dataset write(1GB)"); /* reduce size1 to produce a 1GB dataset */ size1[1] = 1024/32; size2[0] /= 32; break; case NOFILE: /* what to do?? */ HDfprintf(stdout, "Unexpected file size of NOFILE\n"); goto error; break; default: HDfprintf(stdout, "Unexpected file size(%d)\n", testsize); goto error; break; } /* * We might be on a machine that has 32-bit files, so create an HDF5 file * which is a family of files. Each member of the family will be 1GB */ if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) { goto error; } /* Create simple data spaces according to the size specified above. */ if ((space1 = H5Screate_simple (4, size1, size1)) < 0 || (space2 = H5Screate_simple (1, size2, size2)) < 0) { goto error; } /* Create the datasets */ /* * The fix below is provided for bug#921 * H5Dcreate with H5P_DEFAULT creation properties * will create a set of solid 1GB files; test will crash if quotas are enforced * or it will take some time to write a file. * We should create a dataset allocating space late and never writing fill values. * EIP 4/8/03 */ dcpl = H5Pcreate(H5P_DATASET_CREATE); H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_LATE); H5Pset_fill_time(dcpl, H5D_FILL_TIME_NEVER); if((d1 = H5Dcreate2(file, "d1", H5T_NATIVE_INT, space1, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0 || (d2 = H5Dcreate2(file, "d2", H5T_NATIVE_INT, space2, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) { goto error; } /* Write some things to them randomly */ hs_size[0] = WRT_SIZE; if ((mem_space = H5Screate_simple (1, hs_size, hs_size)) < 0) goto error; for (i=0; i<wrt_n; i++) { /* start position must be at least hs_size from the end */ hs_start[0] = randll (size2[0]-hs_size[0], i); HDfprintf (out, "#%03d 0x%016Hx\n", i, hs_start[0]); if (H5Sselect_hyperslab (space2, H5S_SELECT_SET, hs_start, NULL, hs_size, NULL) < 0) goto error; for (j=0; j<WRT_SIZE; j++) { buf[j] = i+1; } if (H5Dwrite (d2, H5T_NATIVE_INT, mem_space, space2, H5P_DEFAULT, buf) < 0) goto error; } if (H5Dclose (d1) < 0) goto error; if (H5Dclose (d2) < 0) goto error; if (H5Sclose (mem_space) < 0) goto error; if (H5Sclose (space1) < 0) goto error; if (H5Sclose (space2) < 0) goto error; if (H5Fclose (file) < 0) goto error; HDfree (buf); HDfclose(out); PASSED(); return 0; error: H5E_BEGIN_TRY { H5Dclose(d1); H5Dclose(d2); H5Sclose(space1); H5Sclose(space2); H5Sclose(mem_space); H5Fclose(file); } H5E_END_TRY; if (buf) HDfree(buf); if (out) HDfclose(out); return 1; }
static int read_data( const char* fname, /*IN*/ hsize_t *width, /*OUT*/ hsize_t *height /*OUT*/ ) { int i, n; int color_planes; char str[20]; FILE *f; int w, h; char *srcdir = getenv("srcdir"); /* the source directory */ char data_file[512]=""; /* buffer to hold name of existing data file */ /*------------------------------------------------------------------------- * compose the name of the file to open, using "srcdir", if appropriate *------------------------------------------------------------------------- */ HDstrcpy(data_file, ""); if (srcdir) { HDstrcpy(data_file, srcdir); HDstrcat(data_file, "/"); } HDstrcat(data_file,fname); /*------------------------------------------------------------------------- * read *------------------------------------------------------------------------- */ f = HDfopen(data_file, "r"); if ( f == NULL ) { printf( "Could not open file %s. Try set $srcdir \n", data_file ); return -1; } fscanf( f, "%s", str ); fscanf( f, "%d", &color_planes ); fscanf( f, "%s", str ); fscanf( f, "%d", &h); fscanf( f, "%s", str ); fscanf( f, "%d", &w); *width = (hsize_t)w; *height = (hsize_t)h; if ( image_data ) { HDfree( image_data ); image_data=NULL; } image_data = (unsigned char*) HDmalloc (w * h * color_planes * sizeof( unsigned char )); for (i = 0; i < h * w * color_planes ; i++) { fscanf( f, "%d",&n ); image_data[i] = (unsigned char)n; } HDfclose(f); return 1; }
int main(void) { int nrow = 3, ncol = 4, npln = 5; int i, j, k; FILE *sp; char machine_order[3] = {0, 0, 0}; float row4[3], col4[4], pln4[5]; float rowo4 = 11.0F, colo4 = 21.0F, plno4 = 51.0F; float rowi4 = 1.0F, coli4 = 2.0F, plni4 = 5.0F; int b32i3[5][3][4]; int row4i[3], col4i[4], pln4i[5]; int rowo4i = 11 , colo4i = 21 , plno4i = 51 ; int rowi4i = 1 , coli4i = 2 , plni4i = 5 ; #ifdef H5_SIZEOF_LONG_LONG long long row4i64[3], col4i64[4], pln4i64[5]; long long rowo4i64 = (long long)11 , colo4i64 = (long long)21 , plno4i64 = (long long)51 ; long long rowi4i64 = (long long)1 , coli4i64 = (long long)2 , plni4i64 = (long long)5 ; #endif short b16i3[5][3][4]; short row4i16[3], col4i16[4], pln4i16[5]; short rowo4i16 = (short)11 , colo4i16 = (short)21 , plno4i16 = (short)51 ; short rowi4i16 = (short)1 , coli4i16 = (short)2 , plni4i16 = (short)5 ; char b8i3[5][3][4]; char row4i8[3], col4i8[4], pln4i8[5]; char rowo4i8 = (char)11 , colo4i8 = (char)21 , plno4i8 = (char)51 ; char rowi4i8 = (char)1 , coli4i8 = (char)2 , plni4i8 = (char)5 ; double b64r3[5][3][4]; double row8[3], col8[4], pln8[5]; double rowo8 = 11.0F, colo8 = 21.0F, plno8 = 51.0F; double rowi8 = 1.0F, coli8 = 2.0F, plni8 = 5.0F; /* Initialize machine endian */ volatile uint32_t ibyte=0x01234567; /* 0 for big endian, 1 for little endian. */ if ((*((uint8_t*)(&ibyte))) == 0x67) HDstrncpy(machine_order, "LE", 2); else HDstrncpy(machine_order, "BE", 2); /* * initialize the row, column, and plane vectors * * row values start at 11 and increment by 1 => 11, 12, 13 * column values start at 21 and increment by 2 => 21, 23, 25, 27 * plane values start at 51 and increment by 5 => 51, 56, 61, 66, 71 */ /* * build array elements - rank 2 * * element value = sum of row value and col values */ row4[0] = rowo4; col4[0] = colo4; pln4[0] = plno4; row8[0] = rowo8; col8[0] = colo8; pln8[0] = plno8; row4i[0] = rowo4i; col4i[0] = colo4i; pln4i[0] = plno4i; #ifdef H5_SIZEOF_LONG_LONG row4i64[0] = rowo4i64; col4i64[0] = colo4i64; pln4i64[0] = plno4i64; #endif row4i16[0] = rowo4i16; col4i16[0] = colo4i16; pln4i16[0] = plno4i16; row4i8[0] = rowo4i8; col4i8[0] = colo4i8; pln4i8[0] = plno4i8; for (i = 1; i < nrow; i++) { row4[i] = row4[i - 1] + rowi4; row8[i] = row8[i - 1] + rowi8; row4i[i] = row4i[i - 1] + rowi4i; #ifdef H5_SIZEOF_LONG_LONG row4i64[i] = row4i64[i - 1] + rowi4i64; #endif row4i16[i] = (short)(row4i16[i - 1] + rowi4i16); row4i8[i] = (char)(row4i8[i - 1] + rowi4i8); } for (j = 1; j < ncol; j++) { col4[j] = col4[j - 1] + coli4; col8[j] = col8[j - 1] + coli8; col4i[j] = col4i[j - 1] + coli4i; #ifdef H5_SIZEOF_LONG_LONG col4i64[j] = col4i64[j - 1] + coli4i64; #endif col4i16[j] = (short)(col4i16[j - 1] + coli4i16); col4i8[j] = (char)(col4i8[j - 1] + coli4i8); } for (k = 1; k < npln; k++) { pln4[k] = pln4[k - 1] + plni4; pln8[k] = pln8[k - 1] + plni8; pln4i[k] = pln4i[k - 1] + plni4i; #ifdef H5_SIZEOF_LONG_LONG pln4i64[k] = pln4i64[k - 1] + plni4i64; #endif pln4i16[k] = (short)(pln4i16[k - 1] + plni4i16); pln4i8[k] = (char)(pln4i8[k - 1] + plni4i8); } /* * build array elements - rank 3 * * element value = sum of row value, col, and plane values */ for (i = 0; i < nrow; i++) for (j = 0; j < ncol; j++) for (k = 0; k < npln; k++) { b64r3[k][i][j] = row8[i] + col8[j] + pln8[k]; b32i3[k][i][j] = row4i[i] + col4i[j] + pln4i[k]; b16i3[k][i][j] = (short)(row4i16[i] + col4i16[j] + pln4i16[k]); b8i3[k][i][j] = (char)(row4i8[i] + col4i8[j] + pln4i8[k]); } #ifndef UNICOS #ifdef REBUILDTEXTFILES /*------------------------------------------------------------------------- * TOOLTEST txtin8.txt -c $srcdir/testfiles/txtin8.conf -o txtin8.h5 *------------------------------------------------------------------------- */ sp = HDfopen("txtin8.txt", "w"); for (k = 0; k < npln; k++) { for (i = 0; i < nrow; i++) { for (j = 0; j < ncol; j++) (void) fprintf(sp, "%10u", b8i3[k][i][j]); (void) fprintf(sp, "\n"); } } (void) HDfclose(sp); /*------------------------------------------------------------------------- * TOOLTEST txtin16.txt -c $srcdir/testfiles/txtin16.conf -o txtin16.h5 *------------------------------------------------------------------------- */ sp = HDfopen("txtin16.txt", "w"); for (k = 0; k < npln; k++) { for (i = 0; i < nrow; i++) { for (j = 0; j < ncol; j++) (void) fprintf(sp, "%10u", b16i3[k][i][j]); (void) fprintf(sp, "\n"); } } (void) HDfclose(sp); /*------------------------------------------------------------------------- * TOOLTEST txtin32.txt -c $srcdir/testfiles/textin32.conf -o textin32.h5 *------------------------------------------------------------------------- */ sp = HDfopen("txtin32.txt", "w"); for (k = 0; k < npln; k++) { for (i = 0; i < nrow; i++) { for (j = 0; j < ncol; j++) (void) fprintf(sp, "%10d", b32i3[k][i][j]); (void) fprintf(sp, "\n"); } } (void) HDfclose(sp); #endif /*------------------------------------------------------------------------- * TOOLTEST binin32.bin -c binin32.conf -o binin32.h5 *------------------------------------------------------------------------- */ sp = HDfopen("binin32.bin", OPEN_FLAGS); for (k = 0; k < npln; k++) { for (i = 0; i < nrow; i++) { for (j = 0; j < ncol; j++) { (void) HDfwrite((char *) &b32i3[k][i][j], sizeof(int), 1, sp); } } } (void) HDfclose(sp); sp = HDfopen("binin32.conf", "w"); (void) fprintf(sp, "PATH /int/bin/32-bit\n"); (void) fprintf(sp, "INPUT-CLASS IN\n"); (void) fprintf(sp, "INPUT-SIZE 32\n"); (void) fprintf(sp, "INPUT-BYTE-ORDER %s\n", machine_order); (void) fprintf(sp, "RANK 3\n"); (void) fprintf(sp, "OUTPUT-ARCHITECTURE STD\n"); (void) fprintf(sp, "OUTPUT-BYTE-ORDER BE\n"); (void) fprintf(sp, "DIMENSION-SIZES 5 3 4\n"); (void) fprintf(sp, "CHUNKED-DIMENSION-SIZES 1 2 1\n"); (void) fprintf(sp, "\n"); (void) HDfclose(sp); /*------------------------------------------------------------------------- * TOOLTEST binuin32.bin -c binuin32.conf -o binuin32.h5 *------------------------------------------------------------------------- */ sp = HDfopen("binuin32.bin", OPEN_FLAGS); for (k = 0; k < npln; k++) { for (i = 0; i < nrow; i++) { for (j = 0; j < ncol; j++) { (void) HDfwrite((char *) &b32i3[k][i][j], sizeof(unsigned int), 1, sp); } } } (void) HDfclose(sp); sp = HDfopen("binuin32.conf", "w"); (void) fprintf(sp, "PATH /int/buin/32-bit\n"); (void) fprintf(sp, "INPUT-CLASS UIN\n"); (void) fprintf(sp, "INPUT-SIZE 32\n"); (void) fprintf(sp, "INPUT-BYTE-ORDER %s\n", machine_order); (void) fprintf(sp, "RANK 3\n"); (void) fprintf(sp, "OUTPUT-ARCHITECTURE STD\n"); (void) fprintf(sp, "OUTPUT-BYTE-ORDER LE\n"); (void) fprintf(sp, "DIMENSION-SIZES 5 3 4\n"); (void) fprintf(sp, "\n"); (void) HDfclose(sp); /*------------------------------------------------------------------------- * TOOLTEST binin16.bin -c binin16.conf -o binin16.h5 *------------------------------------------------------------------------- */ sp = HDfopen("binin16.bin", OPEN_FLAGS); for (k = 0; k < npln; k++) { for (i = 0; i < nrow; i++) { for (j = 0; j < ncol; j++) { (void) HDfwrite((char *) &b16i3[k][i][j], sizeof(short), 1, sp); } } } (void) HDfclose(sp); sp = HDfopen("binin16.conf", "w"); (void) fprintf(sp, "PATH /int/bin/16-bit\n"); (void) fprintf(sp, "INPUT-CLASS IN\n"); (void) fprintf(sp, "INPUT-SIZE 16\n"); (void) fprintf(sp, "INPUT-BYTE-ORDER %s\n", machine_order); (void) fprintf(sp, "RANK 3\n"); (void) fprintf(sp, "OUTPUT-ARCHITECTURE STD\n"); (void) fprintf(sp, "OUTPUT-BYTE-ORDER LE\n"); (void) fprintf(sp, "DIMENSION-SIZES 2 3 4\n"); (void) fprintf(sp, "CHUNKED-DIMENSION-SIZES 2 2 2\n"); (void) fprintf(sp, "MAXIMUM-DIMENSIONS -1 -1 8\n"); (void) fprintf(sp, "\n"); (void) HDfclose(sp); /*------------------------------------------------------------------------- * TOOLTEST binuin16.bin -c binuin16.conf -o binuin16.h5 *------------------------------------------------------------------------- */ sp = HDfopen("binuin16.bin", OPEN_FLAGS); for (k = 0; k < npln; k++) { for (i = 0; i < nrow; i++) { for (j = 0; j < ncol; j++) { (void) HDfwrite((char *) &b16i3[k][i][j], sizeof(unsigned short), 1, sp); } } } (void) HDfclose(sp); sp = HDfopen("binuin16.conf", "w"); (void) fprintf(sp, "PATH /int/buin/16-bit\n"); (void) fprintf(sp, "INPUT-CLASS UIN\n"); (void) fprintf(sp, "INPUT-SIZE 16\n"); (void) fprintf(sp, "INPUT-BYTE-ORDER %s\n", machine_order); (void) fprintf(sp, "RANK 3\n"); (void) fprintf(sp, "OUTPUT-ARCHITECTURE STD\n"); (void) fprintf(sp, "OUTPUT-BYTE-ORDER BE\n"); (void) fprintf(sp, "DIMENSION-SIZES 2 3 4\n"); (void) fprintf(sp, "CHUNKED-DIMENSION-SIZES 2 2 2\n"); (void) fprintf(sp, "MAXIMUM-DIMENSIONS -1 -1 8\n"); (void) fprintf(sp, "\n"); (void) HDfclose(sp); /*------------------------------------------------------------------------- * TOOLTEST binin8.bin -c binin8.conf -o binin8.h5 *------------------------------------------------------------------------- */ sp = HDfopen("binin8.bin", OPEN_FLAGS); for (k = 0; k < npln; k++) { for (i = 0; i < nrow; i++) { for (j = 0; j < ncol; j++) { (void) HDfwrite((char *) &b8i3[k][i][j], sizeof(char), 1, sp); } } } (void) HDfclose(sp); sp = HDfopen("binin8.conf", "w"); (void) fprintf(sp, "PATH /int/bin/8-bit\n"); (void) fprintf(sp, "INPUT-CLASS IN\n"); (void) fprintf(sp, "INPUT-SIZE 8\n"); (void) fprintf(sp, "INPUT-BYTE-ORDER %s\n", machine_order); (void) fprintf(sp, "RANK 3\n"); (void) fprintf(sp, "OUTPUT-CLASS IN\n"); (void) fprintf(sp, "OUTPUT-SIZE 16\n"); (void) fprintf(sp, "OUTPUT-ARCHITECTURE STD\n"); (void) fprintf(sp, "OUTPUT-BYTE-ORDER LE\n"); (void) fprintf(sp, "DIMENSION-SIZES 5 3 4\n"); (void) fprintf(sp, "CHUNKED-DIMENSION-SIZES 2 2 2\n"); (void) fprintf(sp, "MAXIMUM-DIMENSIONS -1 -1 -1\n"); (void) fprintf(sp, "COMPRESSION-PARAM 3\n"); (void) fprintf(sp, "\n"); (void) HDfclose(sp); #endif /* UNICOS */ /*------------------------------------------------------------------------- * TOOLTEST binfp64.bin -c binfp64.conf -o binfp64.h5 *------------------------------------------------------------------------- */ /* * binary 64-bit file - rank 2 & 3 */ sp = HDfopen("binfp64.bin", OPEN_FLAGS); for (k = 0; k < npln; k++) { for (i = 0; i < nrow; i++) { for (j = 0; j < ncol; j++) { (void) HDfwrite((char *) &b64r3[k][i][j], sizeof(double), 1, sp); } } } (void) HDfclose(sp); sp = HDfopen("binfp64.conf", "w"); (void) fprintf(sp, "PATH /fp/bin/64-bit\n"); (void) fprintf(sp, "INPUT-CLASS FP\n"); (void) fprintf(sp, "INPUT-SIZE 64\n"); (void) fprintf(sp, "INPUT-BYTE-ORDER %s\n", machine_order); (void) fprintf(sp, "RANK 3\n"); (void) fprintf(sp, "OUTPUT-ARCHITECTURE IEEE\n"); (void) fprintf(sp, "OUTPUT-BYTE-ORDER LE\n"); (void) fprintf(sp, "DIMENSION-SIZES 5 3 4\n"); (void) fprintf(sp, "CHUNKED-DIMENSION-SIZES 2 2 2\n"); (void) fprintf(sp, "MAXIMUM-DIMENSIONS -1 6 7\n"); (void) fprintf(sp, "COMPRESSION-PARAM 8\n"); (void) fprintf(sp, "\n"); (void) HDfclose(sp); /*------------------------------------------------------------------------- * TOOLTEST binin8w.bin -c binin8w.conf -o binin8w.h5 *------------------------------------------------------------------------- */ { /* test CR+LF (13,10) and EOF (26) in windows */ char bin8w[4] = {13,10,26,0}; sp = HDfopen("binin8w.bin", OPEN_FLAGS); for (i = 0; i < 4; i++) { char c = bin8w[i]; if ( HDfwrite( &c, sizeof(char), 1, sp) != 1 ) printf("error writing file\n"); } HDfclose(sp); sp = HDfopen("binin8w.conf", "w"); (void) fprintf(sp, "INPUT-CLASS IN\n"); (void) fprintf(sp, "INPUT-SIZE 8\n"); (void) fprintf(sp, "INPUT-BYTE-ORDER %s\n", machine_order); (void) fprintf(sp, "RANK 1\n"); (void) fprintf(sp, "OUTPUT-CLASS IN\n"); (void) fprintf(sp, "OUTPUT-SIZE 8\n"); (void) fprintf(sp, "OUTPUT-ARCHITECTURE STD\n"); (void) fprintf(sp, "OUTPUT-BYTE-ORDER LE\n"); (void) fprintf(sp, "DIMENSION-SIZES 4\n"); (void) fprintf(sp, "\n"); (void) HDfclose(sp); } return (EXIT_SUCCESS); }
int main(void) { int nrow = 3, ncol = 4, npln = 5; int i, j, k; FILE *sp; float row4[3], col4[4], pln4[5]; float rowo4 = (float)11.0e0, colo4 = (float)21.0e0, plno4 = (float)51.0e0; float rowi4 = (float)1.0e0, coli4 = (float)2.0e0, plni4 = (float)5.0e0; int b32i3[5][3][4]; int row4i[3], col4i[4], pln4i[5]; int rowo4i = (int)11 , colo4i = (int)21 , plno4i = (int)51 ; int rowi4i = (int)1 , coli4i = (int)2 , plni4i = (int)5 ; #ifdef H5_SIZEOF_LONG_LONG long long row4i64[3], col4i64[4], pln4i64[5]; long long rowo4i64 = (long long)11 , colo4i64 = (long long)21 , plno4i64 = (long long)51 ; long long rowi4i64 = (long long)1 , coli4i64 = (long long)2 , plni4i64 = (long long)5 ; #endif short b16i3[5][3][4]; short row4i16[3], col4i16[4], pln4i16[5]; short rowo4i16 = (short)11 , colo4i16 = (short)21 , plno4i16 = (short)51 ; short rowi4i16 = (short)1 , coli4i16 = (short)2 , plni4i16 = (short)5 ; char b8i3[5][3][4]; char row4i8[3], col4i8[4], pln4i8[5]; char rowo4i8 = (char)11 , colo4i8 = (char)21 , plno4i8 = (char)51 ; char rowi4i8 = (char)1 , coli4i8 = (char)2 , plni4i8 = (char)5 ; double b64r3[5][3][4]; double row8[3], col8[4], pln8[5]; double rowo8 = 11.0e0, colo8 = 21.0e0, plno8 = 51.0e0; double rowi8 = 1.0e0, coli8 = 2.0e0, plni8 = 5.0e0; /* * initialize the row, column, and plane vectors * * row values start at 11 and increment by 1 => 11, 12, 13 * column values start at 21 and increment by 2 => 21, 23, 25, 27 * plane values start at 51 and increment by 5 => 51, 56, 61, 66, 71 */ /* * build array elements - rank 2 * * element value = sum of row value and col values */ row4[0] = rowo4; col4[0] = colo4; pln4[0] = plno4; row8[0] = rowo8; col8[0] = colo8; pln8[0] = plno8; row4i[0] = rowo4i; col4i[0] = colo4i; pln4i[0] = plno4i; #ifdef H5_SIZEOF_LONG_LONG row4i64[0] = rowo4i64; col4i64[0] = colo4i64; pln4i64[0] = plno4i64; #endif row4i16[0] = rowo4i16; col4i16[0] = colo4i16; pln4i16[0] = plno4i16; row4i8[0] = rowo4i8; col4i8[0] = colo4i8; pln4i8[0] = plno4i8; for (i = 1; i < nrow; i++) { row4[i] = row4[i - 1] + rowi4; row8[i] = row8[i - 1] + rowi8; row4i[i] = row4i[i - 1] + rowi4i; #ifdef H5_SIZEOF_LONG_LONG row4i64[i] = row4i64[i - 1] + rowi4i64; #endif row4i16[i] = row4i16[i - 1] + rowi4i16; row4i8[i] = row4i8[i - 1] + rowi4i8; } for (j = 1; j < ncol; j++) { col4[j] = col4[j - 1] + coli4; col8[j] = col8[j - 1] + coli8; col4i[j] = col4i[j - 1] + coli4i; #ifdef H5_SIZEOF_LONG_LONG col4i64[j] = col4i64[j - 1] + coli4i64; #endif col4i16[j] = col4i16[j - 1] + coli4i16; col4i8[j] = col4i8[j - 1] + coli4i8; } for (k = 1; k < npln; k++) { pln4[k] = pln4[k - 1] + plni4; pln8[k] = pln8[k - 1] + plni8; pln4i[k] = pln4i[k - 1] + plni4i; #ifdef H5_SIZEOF_LONG_LONG pln4i64[k] = pln4i64[k - 1] + plni4i64; #endif pln4i16[k] = pln4i16[k - 1] + plni4i16; pln4i8[k] = pln4i8[k - 1] + plni4i8; } /* * build array elements - rank 3 * * element value = sum of row value, col, and plane values */ for (i = 0; i < nrow; i++) for (j = 0; j < ncol; j++) for (k = 0; k < npln; k++) { b64r3[k][i][j] = row8[i] + col8[j] + pln8[k]; b32i3[k][i][j] = row4i[i] + col4i[j] + pln4i[k]; b16i3[k][i][j] = row4i16[i] + col4i16[j] + pln4i16[k]; b8i3[k][i][j] = row4i8[i] + col4i8[j] + pln4i8[k]; } #ifndef UNICOS /*------------------------------------------------------------------------- * TOOLTEST txtin16.txt -c $srcdir/testfiles/txtin16.conf -o txtin16.h5 *------------------------------------------------------------------------- */ sp = HDfopen("txtin16.txt", "w"); for (k = 0; k < npln; k++) { for (i = 0; i < nrow; i++) { for (j = 0; j < ncol; j++) (void) fprintf(sp, "%10u", b16i3[k][i][j]); (void) fprintf(sp, "\n"); } } (void) HDfclose(sp); /*------------------------------------------------------------------------- * TOOLTEST txtin32.txt -c $srcdir/testfiles/textin32.conf -o textin32.h5 *------------------------------------------------------------------------- */ sp = HDfopen("txtin32.txt", "w"); for (k = 0; k < npln; k++) { for (i = 0; i < nrow; i++) { for (j = 0; j < ncol; j++) (void) fprintf(sp, "%10d", b32i3[k][i][j]); (void) fprintf(sp, "\n"); } } (void) HDfclose(sp); /*------------------------------------------------------------------------- * TOOLTEST binin32.bin -c $srcdir/testfiles/binin32.conf -o binin32.h5 *------------------------------------------------------------------------- */ sp = HDfopen("binin32.bin", OPEN_FLAGS); for (k = 0; k < npln; k++) { for (i = 0; i < nrow; i++) { for (j = 0; j < ncol; j++) { (void) HDfwrite((char *) &b32i3[k][i][j], sizeof(int), 1, sp); } } } (void) HDfclose(sp); /*------------------------------------------------------------------------- * TOOLTEST binuin32.bin -c $srcdir/testfiles/binuin32.conf -o binuin32.h5 *------------------------------------------------------------------------- */ sp = HDfopen("binuin32.bin", OPEN_FLAGS); for (k = 0; k < npln; k++) { for (i = 0; i < nrow; i++) { for (j = 0; j < ncol; j++) { (void) HDfwrite((char *) &b32i3[k][i][j], sizeof(unsigned int), 1, sp); } } } (void) HDfclose(sp); /*------------------------------------------------------------------------- * TOOLTEST binin16.bin -c $srcdir/testfiles/binin16.conf -o binin16.h5 *------------------------------------------------------------------------- */ sp = HDfopen("binin16.bin", OPEN_FLAGS); for (k = 0; k < npln; k++) { for (i = 0; i < nrow; i++) { for (j = 0; j < ncol; j++) { (void) HDfwrite((char *) &b16i3[k][i][j], sizeof(short), 1, sp); } } } (void) HDfclose(sp); /*------------------------------------------------------------------------- * TOOLTEST binuin16.bin -c $srcdir/testfiles/binuin16.conf -o binuin16.h5 *------------------------------------------------------------------------- */ sp = HDfopen("binuin16.bin", OPEN_FLAGS); for (k = 0; k < npln; k++) { for (i = 0; i < nrow; i++) { for (j = 0; j < ncol; j++) { (void) HDfwrite((char *) &b16i3[k][i][j], sizeof(unsigned short), 1, sp); } } } (void) HDfclose(sp); /*------------------------------------------------------------------------- * TOOLTEST binin8.bin -c $srcdir/testfiles/binin8.conf -o binin8.h5 *------------------------------------------------------------------------- */ sp = HDfopen("binin8.bin", OPEN_FLAGS); for (k = 0; k < npln; k++) { for (i = 0; i < nrow; i++) { for (j = 0; j < ncol; j++) { (void) HDfwrite((char *) &b8i3[k][i][j], sizeof(char), 1, sp); } } } (void) HDfclose(sp); #endif /* UNICOS */ /*------------------------------------------------------------------------- * TOOLTEST binfp64.bin -c $srcdir/testfiles/binfp64.conf -o binfp64.h5 *------------------------------------------------------------------------- */ /* * binary 64-bit file - rank 2 & 3 */ sp = HDfopen("binfp64.bin", OPEN_FLAGS); for (k = 0; k < npln; k++) { for (i = 0; i < nrow; i++) { for (j = 0; j < ncol; j++) { (void) HDfwrite((char *) &b64r3[k][i][j], sizeof(double), 1, sp); } } } (void) HDfclose(sp); /*------------------------------------------------------------------------- * TOOLTEST binin8w.bin -c $srcdir/testfiles/binin8w.conf -o binin8w.h5 *------------------------------------------------------------------------- */ { /* test CR+LF (13,10) and EOF (26) in windows */ char bin8w[4] = {13,10,26,0}; sp = HDfopen("binin8w.bin", OPEN_FLAGS); for (i = 0; i < 4; i++) { char c = bin8w[i]; if ( HDfwrite( &c, sizeof(char), 1, sp) != 1 ) printf("error writing file\n"); } HDfclose(sp); } return (EXIT_SUCCESS); }
static void read_info(const char *filename, pack_opt_t *options) { char stype[10]; char comp_info[1024]; FILE *fp; char c; int i, rc=1; char *srcdir = getenv("srcdir"); /* the source directory */ char data_file[512]=""; /* buffer to hold name of existing file */ /* compose the name of the file to open, using the srcdir, if appropriate */ if (srcdir){ HDstrcpy(data_file,srcdir); HDstrcat(data_file,"/"); } HDstrcat(data_file,filename); if ((fp = HDfopen(data_file, "r")) == (FILE *)NULL) { error_msg("cannot open options file %s\n", filename); HDexit(EXIT_FAILURE); } /* cycle until end of file reached */ while( 1 ) { rc=fscanf(fp, "%s", stype); if (rc==-1) break; /*------------------------------------------------------------------------- * filter *------------------------------------------------------------------------- */ if (HDstrcmp(stype,"-f") == 0) { /* find begining of info */ i=0; c='0'; while( c!=' ' ) { fscanf(fp, "%c", &c); if (HDfeof(fp)) break; } c='0'; /* go until end */ while( c!=' ' ) { fscanf(fp, "%c", &c); comp_info[i]=c; i++; if (HDfeof(fp)) break; if (c==10 /*eol*/) break; } comp_info[i-1]='\0'; /*cut the last " */ if (h5repack_addfilter(comp_info,options)==-1){ error_msg("could not add compression option\n"); HDexit(EXIT_FAILURE); } } /*------------------------------------------------------------------------- * layout *------------------------------------------------------------------------- */ else if (HDstrcmp(stype,"-l") == 0) { /* find begining of info */ i=0; c='0'; while( c!=' ' ) { fscanf(fp, "%c", &c); if (HDfeof(fp)) break; } c='0'; /* go until end */ while( c!=' ' ) { fscanf(fp, "%c", &c); comp_info[i]=c; i++; if (HDfeof(fp)) break; if (c==10 /*eol*/) break; } comp_info[i-1]='\0'; /*cut the last " */ if (h5repack_addlayout(comp_info,options)==-1){ error_msg("could not add chunck option\n"); HDexit(EXIT_FAILURE); } } /*------------------------------------------------------------------------- * not valid *------------------------------------------------------------------------- */ else { error_msg("bad file format for %s", filename); HDexit(EXIT_FAILURE); } } HDfclose(fp); return; }