/*----------------------------------------------------------- * PURPOSE : * if environment variable H5TOOLS_BUFSIZE is set, * update H5TOOLS_BUFSIZE and H5TOOLS_MALLOCSIZE from the env * This can be called from each tools main() as part of initial act. * Note: this is more of debugging purpose for now. */ int h5tools_getenv_update_hyperslab_bufsize(void) { const char *env_str = NULL; long hyperslab_bufsize_mb; /* check if environment variable is set for the hyperslab buffer size */ if (NULL != (env_str = HDgetenv ("H5TOOLS_BUFSIZE"))) { errno = 0; hyperslab_bufsize_mb = HDstrtol(env_str, (char**)NULL, 10); if (errno != 0 || hyperslab_bufsize_mb <= 0) { /* TODO: later when pubilshed HDfprintf(rawerrorstream,"Error: Invalid environment variable \"H5TOOLS_BUFSIZE\" : %s\n", env_str); */ goto error; } /* convert MB to byte */ H5TOOLS_BUFSIZE = hyperslab_bufsize_mb * 1024 * 1024; H5TOOLS_MALLOCSIZE = MAX(H5TOOLS_BUFSIZE, H5TOOLS_MALLOCSIZE); } return (1); error: return (-1); }
/*------------------------------------------------------------------------- * Function: HDfprintf * * Purpose: Prints the optional arguments under the control of the format * string FMT to the stream STREAM. This function takes the * same format as fprintf(3c) with a few added features: * * The conversion modifier `H' refers to the size of an * `hsize_t' or `hssize_t' type. For instance, "0x%018Hx" * prints an `hsize_t' value as a hex number right justified and * zero filled in an 18-character field. * * The conversion `a' refers to an `haddr_t' type. * * Return: Success: Number of characters printed * * Failure: -1 * * Programmer: Robb Matzke * Thursday, April 9, 1998 * * Modifications: * Robb Matzke, 1999-07-27 * The `%a' format refers to an argument of `haddr_t' type * instead of `haddr_t*' and the return value is correct. *------------------------------------------------------------------------- */ int HDfprintf(FILE *stream, const char *fmt, ...) { int n=0, nout = 0; int fwidth, prec; int zerofill; int leftjust; int plussign; int ldspace; int prefix; char modifier[8]; int conv; char *rest, format_templ[128]; int len; const char *s; va_list ap; HDassert(stream); HDassert(fmt); va_start (ap, fmt); while (*fmt) { fwidth = prec = 0; zerofill = 0; leftjust = 0; plussign = 0; prefix = 0; ldspace = 0; modifier[0] = '\0'; if ('%'==fmt[0] && '%'==fmt[1]) { HDputc ('%', stream); fmt += 2; nout++; } else if ('%'==fmt[0]) { s = fmt + 1; /* Flags */ while(HDstrchr("-+ #", *s)) { switch(*s) { case '-': leftjust = 1; break; case '+': plussign = 1; break; case ' ': ldspace = 1; break; case '#': prefix = 1; break; default: HDassert(0 && "Unknown format flag"); } /* end switch */ /*lint !e744 Switch statement doesn't _need_ default */ s++; } /* end while */ /* Field width */ if(HDisdigit(*s)) { zerofill = ('0' == *s); fwidth = (int)HDstrtol (s, &rest, 10); s = rest; } /* end if */ else if ('*'==*s) { fwidth = va_arg (ap, int); if(fwidth < 0) { leftjust = 1; fwidth = -fwidth; } s++; } /* Precision */ if('.'==*s) { s++; if(HDisdigit(*s)) { prec = (int)HDstrtol(s, &rest, 10); s = rest; } else if('*'==*s) { prec = va_arg(ap, int); s++; }
/*------------------------------------------------------------------------- * Function: h5_fileaccess * * Purpose: Returns a file access template which is the default template * but with a file driver set according to the constant or * environment variable HDF5_DRIVER * * Return: Success: A file access property list * * Failure: -1 * * Programmer: Robb Matzke * Thursday, November 19, 1998 * * Modifications: * *------------------------------------------------------------------------- */ hid_t h5_fileaccess(void) { const char *val = NULL; const char *name; char s[1024]; hid_t fapl = -1; /* First use the environment variable, then the constant */ val = HDgetenv("HDF5_DRIVER"); #ifdef HDF5_DRIVER if (!val) val = HDF5_DRIVER; #endif if ((fapl=H5Pcreate(H5P_FILE_ACCESS))<0) return -1; if (!val || !*val) return fapl; /*use default*/ HDstrncpy(s, val, sizeof s); s[sizeof(s)-1] = '\0'; if (NULL==(name=HDstrtok(s, " \t\n\r"))) return fapl; if (!HDstrcmp(name, "sec2")) { /* Unix read() and write() system calls */ if (H5Pset_fapl_sec2(fapl)<0) return -1; } else if (!HDstrcmp(name, "stdio")) { /* Standard C fread() and fwrite() system calls */ if (H5Pset_fapl_stdio(fapl)<0) return -1; } else if (!HDstrcmp(name, "core")) { /* In-memory driver settings (backing store on, 1 MB increment) */ if (H5Pset_fapl_core(fapl, (size_t)1, TRUE)<0) return -1; } else if (!HDstrcmp(name, "core_paged")) { /* In-memory driver with write tracking and paging on */ if (H5Pset_fapl_core(fapl, (size_t)1, TRUE)<0) return -1; if (H5Pset_core_write_tracking(fapl, TRUE, (size_t)4096)<0) return -1; } else if (!HDstrcmp(name, "split")) { /* Split meta data and raw data each using default driver */ if (H5Pset_fapl_split(fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT)<0) return -1; } else if (!HDstrcmp(name, "multi")) { /* Multi-file driver, general case of the split driver */ H5FD_mem_t memb_map[H5FD_MEM_NTYPES]; hid_t memb_fapl[H5FD_MEM_NTYPES]; const char *memb_name[H5FD_MEM_NTYPES]; char sv[H5FD_MEM_NTYPES][1024]; haddr_t memb_addr[H5FD_MEM_NTYPES]; H5FD_mem_t mt; HDmemset(memb_map, 0, sizeof memb_map); HDmemset(memb_fapl, 0, sizeof memb_fapl); HDmemset(memb_name, 0, sizeof memb_name); HDmemset(memb_addr, 0, sizeof memb_addr); HDassert(HDstrlen(multi_letters)==H5FD_MEM_NTYPES); for(mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t, mt)) { memb_fapl[mt] = H5P_DEFAULT; sprintf(sv[mt], "%%s-%c.h5", multi_letters[mt]); memb_name[mt] = sv[mt]; memb_addr[mt] = (haddr_t)MAX(mt - 1, 0) * (HADDR_MAX / 10); } /* end for */ if (H5Pset_fapl_multi(fapl, memb_map, memb_fapl, memb_name, memb_addr, FALSE)<0) { return -1; } } else if (!HDstrcmp(name, "family")) { hsize_t fam_size = 100*1024*1024; /*100 MB*/ /* Family of files, each 1MB and using the default driver */ if ((val=HDstrtok(NULL, " \t\n\r"))) fam_size = (hsize_t)(HDstrtod(val, NULL) * 1024*1024); if (H5Pset_fapl_family(fapl, fam_size, H5P_DEFAULT)<0) return -1; } else if (!HDstrcmp(name, "log")) { unsigned log_flags = H5FD_LOG_LOC_IO | H5FD_LOG_ALLOC; /* Log file access */ if ((val = HDstrtok(NULL, " \t\n\r"))) log_flags = (unsigned)HDstrtol(val, NULL, 0); if (H5Pset_fapl_log(fapl, NULL, log_flags, (size_t)0) < 0) return -1; } else if (!HDstrcmp(name, "direct")) { #ifdef H5_HAVE_DIRECT /* Linux direct read() and write() system calls. Set memory boundary, file block size, * and copy buffer size to the default values. */ if (H5Pset_fapl_direct(fapl, 1024, 4096, 8*4096)<0) return -1; #endif } else if(!HDstrcmp(name, "latest")) { /* use the latest format */ if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) return -1; } else { /* Unknown driver */ return -1; } return fapl; }
/* * Function: main * Purpose: Run the program * Return: EXIT_SUCCESS or EXIT_FAILURE * Programmer: Bill Wendling, 05. June 2002 * Modifications: */ int main(int argc, char **argv) { unsigned long min_buf_size = 128 * ONE_KB, max_buf_size = ONE_MB; unsigned long file_size = 64 * ONE_MB; int opt; prog = argv[0]; /* Initialize h5tools lib */ h5tools_init(); while ((opt = get_option(argc, (const char **)argv, s_opts, l_opts)) > 0) { switch ((char)opt) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': compress_level = opt - '0'; break; case 'B': max_buf_size = parse_size_directive(opt_arg); break; case 'b': min_buf_size = parse_size_directive(opt_arg); break; case 'c': compress_percent = (int)HDstrtol(opt_arg, NULL, 10); if (compress_percent < 0) compress_percent = 0; else if (compress_percent > 100) compress_percent = 100; break; case 'p': option_prefix = opt_arg; break; case 'r': random_test = TRUE; break; case 's': file_size = parse_size_directive(opt_arg); break; case '?': usage(); exit(EXIT_FAILURE); break; case 'h': default: usage(); exit(EXIT_SUCCESS); break; } } if (min_buf_size > max_buf_size) error("minmum buffer size (%d) exceeds maximum buffer size (%d)", min_buf_size, max_buf_size); HDfprintf(stdout, "Filesize: %ld\n", file_size); if (compress_level == Z_DEFAULT_COMPRESSION) HDfprintf(stdout, "Compression Level: 6\n"); else HDfprintf(stdout, "Compression Level: %d\n", compress_level); get_unique_name(); do_write_test(file_size, min_buf_size, max_buf_size); cleanup(); return EXIT_SUCCESS; }
/*------------------------------------------------------------------------- * Function: parse_command_line * * Purpose: Parse the command line for h5watch (take only long options) * * Return: Success: Set the corresponding command flags and return void * Failure: Exits program with EXIT_FAILURE value. * * Programmer: Vailin Choi; August 2010 * * Modifications: * *------------------------------------------------------------------------- */ static void parse_command_line(int argc, const char *argv[]) { int opt; /* Command line option */ int tmp; /* no arguments */ if (argc == 1) { usage(h5tools_getprogname()); leave(EXIT_FAILURE); } /* parse command line options */ while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) { switch ((char)opt) { case '?': case 'h': /* --help */ usage(h5tools_getprogname()); leave(EXIT_SUCCESS); case 'V': /* --version */ print_version(progname); leave(EXIT_SUCCESS); break; case 'w': /* --width=N */ g_display_width = (int)HDstrtol(opt_arg, NULL, 0); if(g_display_width < 0) { usage(h5tools_getprogname()); leave(EXIT_FAILURE); } break; case 'd': /* --dim */ g_monitor_size_only = TRUE; break; case 'S': /* --simple */ g_simple_output = TRUE; break; case 'l': /* --label */ g_label = TRUE; break; case 'p': /* --polling=N */ /* g_polling_interval = HDstrtod(opt_arg, NULL); */ if((tmp = (int)HDstrtol(opt_arg, NULL, 10)) <= 0) { usage(h5tools_getprogname()); leave(EXIT_FAILURE); } g_polling_interval = (unsigned)tmp; break; case 'f': /* --fields=<list_of_fields> */ if(g_list_of_fields == NULL) { if((g_list_of_fields = HDstrdup(opt_arg)) == NULL) { error_msg("memory allocation failed (file %s:line %d)\n", __FILE__, __LINE__); leave(EXIT_FAILURE); } } else { char *str; if((str = HDstrdup(opt_arg)) == NULL) { error_msg("memory allocation failed (file %s:line %d)\n", __FILE__, __LINE__); leave(EXIT_FAILURE); } if((g_list_of_fields = (char *)HDrealloc(g_list_of_fields, HDstrlen(g_list_of_fields) + HDstrlen(str) + 2)) == NULL) { error_msg("memory allocation failed (file %s:line %d)\n", __FILE__, __LINE__); leave(EXIT_FAILURE); } HDstrcat(g_list_of_fields, FIELD_SEP); HDstrcat(g_list_of_fields, str); } break; default: usage(h5tools_getprogname()); leave(EXIT_FAILURE); } } /* check for object to be processed */ if (argc <= opt_ind) { error_msg("missing dataset name\n"); usage(h5tools_getprogname()); leave(EXIT_FAILURE); } } /* parse_command_line() */
/*------------------------------------------------------------------------- * 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; }