ssize_t h5trav_getindex(const trav_info_t *info, const char *obj) { size_t u; /* Local index variable */ /* Loop over all paths in 'info' struct, looking for object */ for(u = 0; u < info->nused; u++) { /* Check for object name having full path (with leading '/') */ if(HDstrcmp(obj, info->paths[u].path) == 0) return((ssize_t)u); /* Check for object name without leading '/' */ if(HDstrcmp(obj, (info->paths[u].path + 1)) == 0) return((ssize_t)u); } /* end for */ return((ssize_t)-1); } /* end h5trav_getindex() */
int hrepack_addcomp(const char* str, options_t *options) { obj_list_t *obj_list=NULL; /*one object list for the -t and -c option entry */ comp_info_t comp; /*compression info for the current -t option entry */ int n_objs; /*number of objects in the current -t or -c option entry */ int i; if (options->all_comp==1){ printf("Error: Invalid compression input: '*' is present with other objects <%s>\n",str); return FAIL; } /* initialize parse struct to FAIL */ HDmemset(&comp,FAIL,sizeof(comp_info_t)); /* parse the -t option */ if ((obj_list = parse_comp(str,&n_objs,&comp)) == NULL) return FAIL; /* searh for the "*" all objects character */ for (i = 0; i < n_objs; i++) { if (HDstrcmp("*",obj_list[i].obj)==0) { /* if we are compressing all set the global comp type */ options->all_comp=1; options->comp_g=comp; } } if (i>1 && options->all_comp==1) { printf("\nError: '*' cannot be with other objects, <%s>. Exiting...\n",str); goto out; } if (options->all_comp==0) { if (options_add_comp(obj_list,n_objs,comp,options->op_tbl)<0) goto out; } HDfree(obj_list); return SUCCEED; out: HDfree(obj_list); return FAIL; }
/*------------------------------------------------------------------------- * Function: long_desc_cb * * Purpose: Callback function to help test long description handling * * Return: Success: 0 * * Failure: -1 * * Programmer: Quincey Koziol * January 19, 2005 * *------------------------------------------------------------------------- */ static herr_t long_desc_cb(unsigned H5_ATTR_UNUSED n, const H5E_error2_t *err_desc, void *client_data) { char *real_desc = (char *)client_data; if(err_desc->desc != NULL && HDstrcmp(err_desc->desc, real_desc) == 0) return(0); else return(-1); } /* end long_desc_cb() */
int hrepack_addchunk(const char* str, options_t *options) { obj_list_t *obj_list=NULL; /*one object list for the -t and -c option entry */ int n_objs; /*number of objects in the current -t or -c option entry */ int32 chunk_lengths[H4_MAX_VAR_DIMS]; /* chunk lengths along each dimension */ int chunk_rank; /*global rank for chunks */ int i, j; if (options->all_chunk==1){ printf("Error: Invalid chunking input: '*' is present with other objects <%s>\n",str); return FAIL; } /* parse the -c option */ if ((obj_list = parse_chunk(str,&n_objs,chunk_lengths,&chunk_rank)) == NULL) return FAIL; /* searh for the "*" all objects character */ for (i = 0; i < n_objs; i++) { if (HDstrcmp("*",obj_list[i].obj)==0) { /* if we are chunking all set the global chunking type */ options->all_chunk=1; options->chunk_g.rank=chunk_rank; for (j = 0; j < chunk_rank; j++) options->chunk_g.chunk_lengths[j] = chunk_lengths[j]; } } if (i>1) { printf("\nError: '*' cannot be with other objects, <%s>. Exiting...\n",str); goto out; } if (options->all_chunk==0) { if (options_add_chunk(obj_list,n_objs,chunk_lengths,chunk_rank,options->op_tbl)<0) goto out; } HDfree(obj_list); return SUCCEED; out: HDfree(obj_list); return FAIL; }
/*------------------------------------------------------------------------- * Function: main * * Purpose: h5repack main program * * Return: Success: EXIT_SUCCESS(0) * * Failure: EXIT_FAILURE(1) * * Programmer: Pedro Vicente, [email protected] * * Date: May 9, 2003 * * Comments: * *------------------------------------------------------------------------- */ int main(int argc, const char **argv) { pack_opt_t options; /*the global options */ h5tools_setprogname(PROGRAMNAME); h5tools_setstatus(EXIT_SUCCESS); /* Initialize h5tools lib */ h5tools_init(); /* update hyperslab buffer size from H5TOOLS_BUFSIZE env if exist */ if (h5tools_getenv_update_hyperslab_bufsize() < 0) { h5tools_setstatus(EXIT_FAILURE); goto done; } /* initialize options */ h5repack_init(&options, 0); if (parse_command_line(argc, argv, &options) < 0) goto done; /* get file names if they were not yet got */ if (has_i_o == 0) { if (argv[opt_ind] != NULL && argv[opt_ind + 1] != NULL) { infile = argv[opt_ind]; outfile = argv[opt_ind + 1]; if ( HDstrcmp( infile, outfile ) == 0) { error_msg("file names cannot be the same\n"); usage(h5tools_getprogname()); h5tools_setstatus(EXIT_FAILURE); goto done; } } else { error_msg("file names missing\n"); usage(h5tools_getprogname()); h5tools_setstatus(EXIT_FAILURE); goto done; } } /* pack it */ h5tools_setstatus(h5repack(infile, outfile, &options)); done: /* free tables */ h5repack_end(&options); leave(h5tools_getstatus()); return 0; }
/*------------------------------------------------------------------------- * Function: main * * Purpose: h5repack main program * * Return: Success: EXIT_SUCCESS(0) * * Failure: EXIT_FAILURE(1) * * Programmer: Pedro Vicente, [email protected] * * Date: May 9, 2003 * * Comments: * *------------------------------------------------------------------------- */ int main(int argc, const char **argv) { pack_opt_t options; /*the global options */ int ret=-1; h5tools_setprogname(PROGRAMNAME); h5tools_setstatus(EXIT_SUCCESS); /* Initialize h5tools lib */ h5tools_init(); /* initialize options */ h5repack_init(&options,0); parse_command_line(argc, argv, &options); /* get file names if they were not yet got */ if ( has_i_o == 0 ) { if ( argv[ opt_ind ] != NULL && argv[ opt_ind + 1 ] != NULL ) { infile = argv[ opt_ind ]; outfile = argv[ opt_ind + 1 ]; if ( HDstrcmp( infile, outfile ) == 0 ) { error_msg("file names cannot be the same\n"); usage(h5tools_getprogname()); HDexit(EXIT_FAILURE); } } else { error_msg("file names missing\n"); usage(h5tools_getprogname()); HDexit(EXIT_FAILURE); } } /* pack it */ ret=h5repack(infile,outfile,&options); /* free tables */ h5repack_end(&options); if (ret==-1) return 1; else return 0; }
/* * Set (control) which test will be tested. * SKIPTEST: skip this test * ONLYTEST: do only this test * BEGINETEST: skip all tests before this test * */ void SetTest(const char *testname, int action) { int Loop; switch (action){ case SKIPTEST: for (Loop = 0; Loop < Index; Loop++) if (HDstrcmp(testname, Test[Loop].Name) == 0){ Test[Loop].SkipFlag = 1; break; } break; case BEGINTEST: for (Loop = 0; Loop < Index; Loop++) { if (HDstrcmp(testname, Test[Loop].Name) != 0) Test[Loop].SkipFlag = 1; else{ /* Found it. Set it to run. Done. */ Test[Loop].SkipFlag = 0; break; } } break; case ONLYTEST: for (Loop = 0; Loop < Index; Loop++) { if (HDstrcmp(testname, Test[Loop].Name) != 0) Test[Loop].SkipFlag = 1; else { /* Found it. Set it to run. Break to skip the rest. */ Test[Loop].SkipFlag = 0; break; } } /* skip the rest */ while (++Loop < Index) Test[Loop].SkipFlag = 1; break; default: /* error */ printf("*** ERROR: Unknown action (%d) for SetTest\n", action); break; } }
/*------------------------------------------------------------------------- * function that compares one particle * Comparing floating point should be safe here; HDF5 should store the * fields verbatim and not lose any bits. -JML *------------------------------------------------------------------------- */ static int cmp_par(size_t i, size_t j, particle_t *rbuf, particle_t *wbuf ) { if ( ( HDstrcmp( rbuf[i].name, wbuf[j].name ) != 0 ) || rbuf[i].lati != wbuf[j].lati || rbuf[i].longi != wbuf[j].longi || !FLT_ABS_EQUAL(rbuf[i].pressure,wbuf[j].pressure) || !DBL_ABS_EQUAL(rbuf[i].temperature,wbuf[j].temperature) ) { return -1; } return 0; }
/*------------------------------------------------------------------------- * Function: main * * Purpose: Part 2 of a two-part H5Fflush() test. * * Return: Success: 0 * * Failure: 1 * * Programmer: Robb Matzke * Friday, October 23, 1998 * * Modifications: * Leon Arber * Sept. 26, 2006, expand to check for case where the was file not flushed. * *------------------------------------------------------------------------- */ int main(int argc, char* argv[]) { hid_t fapl1, fapl2; H5E_auto2_t func; char name[1024]; const char *envval = NULL; int mpi_size, mpi_rank; MPI_Comm comm = MPI_COMM_WORLD; MPI_Info info = MPI_INFO_NULL; MPI_Init(&argc, &argv); MPI_Comm_size(comm, &mpi_size); MPI_Comm_rank(comm, &mpi_rank); fapl1 = H5Pcreate(H5P_FILE_ACCESS); H5Pset_fapl_mpio(fapl1, comm, info); fapl2 = H5Pcreate(H5P_FILE_ACCESS); H5Pset_fapl_mpio(fapl2, comm, info); if(mpi_rank == 0) TESTING("H5Fflush (part2 with flush)"); /* Don't run this test using the core or split file drivers */ envval = HDgetenv("HDF5_DRIVER"); if (envval == NULL) envval = "nomatch"; if (HDstrcmp(envval, "core") && HDstrcmp(envval, "split")) { /* Check the case where the file was flushed */ h5_fixname(FILENAME[0], fapl1, name, sizeof name); if(check_file(name, fapl1)) { H5_FAILED() goto error; } else if(mpi_rank == 0)
/*------------------------------------------------------------------------- * Function: symlink_is_visited * * Purpose: Check if an symbolic link has already been visited * * Return: TRUE/FALSE *------------------------------------------------------------------------- */ H5_ATTR_PURE hbool_t symlink_is_visited(symlink_trav_t *visited, H5L_type_t type, const char *file, const char *path) { size_t u; /* Local index variable */ /* Look for symlink */ for(u = 0; u < visited->nused; u++) { /* Check for symlink values already in array */ /* check type and path pair to distingush between symbolic links */ if((visited->objs[u].type == type) && !HDstrcmp(visited->objs[u].path, path)) { /* if external link, file need to be matched as well */ if(visited->objs[u].type == H5L_TYPE_EXTERNAL) if(!HDstrcmp(visited->objs[u].file, file)) return(TRUE); return (TRUE); } /* end if */ } /* end for */ /* Didn't find symlink */ return(FALSE); } /* end symlink_is_visited() */
/*-------------------------------------------------------------------------- NAME DFPputpal -- Write palette to file USAGE intn DFPputpal(filename,palette,overwrite,filemode) char *filename; IN: name of HDF file void * palette; IN: ptr to the buffer retrieve the palette from intn overwrite; IN: whether to (1) overwrite last palette written, or (0) write it as a fresh palette char *filemode; IN: if "a" append palette to file, "w" create new file RETURNS SUCCEED on success, FAIL on failure. DESCRIPTION Stores a palette in an HDF file, with options for creating new file or appending, and overwriting last palette written. GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS To overwrite, the filename must be the same as for the previous call. EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ intn DFPputpal(const char *filename, const void * palette, intn overwrite, const char *filemode) { CONSTR(FUNC, "DFPputpal"); int32 file_id; intn ret_value = SUCCEED; HEclear(); if (!palette) HGOTO_ERROR(DFE_ARGS, FAIL); if (overwrite && HDstrcmp(filename, Lastfile)) HGOTO_ERROR(DFE_BADCALL, FAIL); file_id = DFPIopen(filename, (*filemode == 'w') ? DFACC_CREATE : DFACC_WRITE); if (file_id == FAIL) HGOTO_ERROR(DFE_BADOPEN, FAIL); /* if we want to overwrite, Lastref is the ref to write. If not, if Writeref is set, we use that ref. If not we get a fresh ref. The ref to write is placed in Lastref */ if (!overwrite) Lastref = (uint16) (Writeref ? Writeref : Htagnewref(file_id,DFTAG_IP8)); if (Lastref == 0) HGOTO_ERROR(DFE_NOREF, FAIL); Writeref = 0; /* don't know ref to write after this */ /* write out palette */ if (Hputelement(file_id, DFTAG_IP8, Lastref, (const uint8 *) palette, (int32) 768) < 0) { ret_value = (HDerr(file_id)); goto done; } /* Check for the tag/ref before creating it willy-nilly */ if(Hexist(file_id,DFTAG_LUT,Lastref)==FAIL) Hdupdd(file_id, DFTAG_LUT, Lastref, DFTAG_IP8, Lastref); ret_value = (Hclose(file_id)); done: if(ret_value == FAIL) { /* Error condition cleanup */ } /* end if */ /* Normal function cleanup */ return ret_value; } /* end DFPputpal() */
/* * test_vl_string * Tests variable-length string datatype with UTF-8 strings. */ void test_vl_string(hid_t fid, const char *string) { hid_t type_id, space_id, dset_id; hsize_t dims = 1; hsize_t size; /* Number of bytes used */ char *read_buf[1]; herr_t ret; /* Create dataspace for datasets */ space_id = H5Screate_simple(RANK, &dims, NULL); CHECK(space_id, FAIL, "H5Screate_simple"); /* Create a datatype to refer to */ type_id = H5Tcopy(H5T_C_S1); CHECK(type_id, FAIL, "H5Tcopy"); ret = H5Tset_size(type_id, H5T_VARIABLE); CHECK(ret, FAIL, "H5Tset_size"); /* Create a dataset */ dset_id = H5Dcreate2(fid, VL_DSET1_NAME, type_id, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(dset_id, FAIL, "H5Dcreate2"); /* Write dataset to disk */ ret = H5Dwrite(dset_id, type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, &string); CHECK(ret, FAIL, "H5Dwrite"); /* Make certain the correct amount of memory will be used */ ret = H5Dvlen_get_buf_size(dset_id, type_id, space_id, &size); CHECK(ret, FAIL, "H5Dvlen_get_buf_size"); VERIFY(size, (hsize_t)HDstrlen(string) + 1, "H5Dvlen_get_buf_size"); /* Read dataset from disk */ ret = H5Dread(dset_id, type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_buf); CHECK(ret, FAIL, "H5Dread"); /* Compare data read in */ VERIFY(HDstrcmp(string, read_buf[0]), 0, "strcmp"); /* Reclaim the read VL data */ ret = H5Dvlen_reclaim(type_id, space_id, H5P_DEFAULT, read_buf); CHECK(ret, FAIL, "H5Dvlen_reclaim"); /* Close all */ ret = H5Dclose(dset_id); CHECK(ret, FAIL, "H5Dclose"); ret = H5Tclose(type_id); CHECK(ret, FAIL, "H5Tclose"); ret = H5Sclose(space_id); CHECK(ret, FAIL, "H5Sclose"); }
/*------------------------------------------------------------------------- * Function: trav_fileinfo_add * * Purpose: Add a file addr & fileno to info struct * * Return: void * *------------------------------------------------------------------------- */ void trav_fileinfo_add(trav_info_t *info, hid_t loc_id) { H5O_info_t oinfo; size_t idx = info->nused - 1; if ( info->paths[idx].path && HDstrcmp(info->paths[idx].path, ".")) H5Oget_info_by_name(loc_id, info->paths[idx].path, &oinfo, H5P_DEFAULT); else H5Oget_info(loc_id, &oinfo); info->paths[idx].objno = oinfo.addr; info->paths[idx].fileno = oinfo.fileno; } /* end trav_fileinfo_add() */
/* * test_fl_string * Tests that UTF-8 can be used for fixed-length string data. * Writes the string to a dataset and reads it back again. */ void test_fl_string(hid_t fid, const char *string) { hid_t dtype_id, space_id, dset_id; hsize_t dims = 1; char read_buf[MAX_STRING_LENGTH]; H5T_cset_t cset; herr_t ret; /* Create the datatype, ensure that the character set behaves * correctly (it should default to ASCII and can be set to UTF8) */ dtype_id = H5Tcopy(H5T_C_S1); CHECK(dtype_id, FAIL, "H5Tcopy"); ret = H5Tset_size(dtype_id, (size_t)MAX_STRING_LENGTH); CHECK(ret, FAIL, "H5Tset_size"); cset = H5Tget_cset(dtype_id); VERIFY(cset, H5T_CSET_ASCII, "H5Tget_cset"); ret = H5Tset_cset(dtype_id, H5T_CSET_UTF8); CHECK(ret, FAIL, "H5Tset_cset"); cset = H5Tget_cset(dtype_id); VERIFY(cset, H5T_CSET_UTF8, "H5Tget_cset"); /* Create dataspace for a dataset */ space_id = H5Screate_simple(RANK, &dims, NULL); CHECK(space_id, FAIL, "H5Screate_simple"); /* Create a dataset */ dset_id = H5Dcreate2(fid, DSET1_NAME, dtype_id, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(dset_id, FAIL, "H5Dcreate2"); /* Write UTF-8 string to dataset */ ret = H5Dwrite(dset_id, dtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, string); CHECK(ret, FAIL, "H5Dwrite"); /* Read string back and make sure it is unchanged */ ret = H5Dread(dset_id, dtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_buf); CHECK(ret, FAIL, "H5Dread"); VERIFY(HDstrcmp(string, read_buf), 0, "strcmp"); /* Close all */ ret = H5Dclose(dset_id); CHECK(ret, FAIL, "H5Dclose"); ret = H5Tclose(dtype_id); CHECK(ret, FAIL, "H5Tclose"); ret = H5Sclose(space_id); CHECK(ret, FAIL, "H5Sclose"); }
pack_info_t* options_get_object(const char *path, pack_opttbl_t *table) { unsigned int i; char tbl_path[MAX_NC_NAME + 1]; /* +1 for start with "/" case */ for (i = 0; i < table->nelems; i++) { /* make full path (start with "/") to compare correctly */ if (HDstrncmp(table->objs[i].path, "/", 1)) { HDstrcpy(tbl_path, "/"); HDstrcat(tbl_path, table->objs[i].path); } else HDstrcpy(tbl_path, table->objs[i].path); /* found it */ if (HDstrcmp(tbl_path, path) == 0) { return (&table->objs[i]); } } return NULL; }
/* Helper routine for test_vl_rewrite() */ static void read_scalar_dset(hid_t file, hid_t type, hid_t space, char *name, char *data) { hid_t dset; herr_t ret; char *data_read; dset = H5Dopen2(file, name, H5P_DEFAULT); CHECK(dset, FAIL, "H5Dopen2"); ret = H5Dread(dset, type, space, space, H5P_DEFAULT, &data_read); CHECK(ret, FAIL, "H5Dread"); ret = H5Dclose(dset); CHECK(ret, FAIL, "H5Dclose"); if(HDstrcmp(data, data_read)) TestErrPrintf("Expected %s for dataset %s but read %s\n", data, name, data_read); ret = H5Dvlen_reclaim(type, space, H5P_DEFAULT, &data_read); CHECK(ret, FAIL, "H5Dvlen_reclaim"); }
static int parse_flag(const char* s_flag, unsigned *flag) { unsigned fla=0; if (HDstrcmp(s_flag,"shallow")==0) { fla = H5O_COPY_SHALLOW_HIERARCHY_FLAG; } else if (HDstrcmp(s_flag,"soft")==0) { fla = H5O_COPY_EXPAND_SOFT_LINK_FLAG; } else if (HDstrcmp(s_flag,"ext")==0) { fla = H5O_COPY_EXPAND_EXT_LINK_FLAG; } else if (HDstrcmp(s_flag,"ref")==0) { fla = H5O_COPY_EXPAND_REFERENCE_FLAG; } else if (HDstrcmp(s_flag,"noattr")==0) { fla = H5O_COPY_WITHOUT_ATTR_FLAG; } else if (HDstrcmp(s_flag,"allflags")==0) { fla = H5O_COPY_ALL; } else if (HDstrcmp(s_flag,"nullmsg")==0) { fla = H5O_COPY_PRESERVE_NULL_FLAG; } else { error_msg("Error in input flag\n"); return -1; } *flag = (*flag) | fla; return 0; }
/**************************************************************** ** ** test_tst_iterate(): Test basic H5ST (ternary search tree) code. ** Tests iterating through key/value pairs in TST ** ****************************************************************/ static void test_tst_iterate(void) { H5ST_tree_t *tree; /* TST created */ H5ST_ptr_t found; /* Pointer to TST node found */ size_t u; /* Local index counter */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(5, ("Testing Iterating Over TSTs\n")); /* Create the TST */ tree=H5ST_create(); CHECK(tree, NULL, "H5ST_create"); /* Insert unique words into TST, in random order */ for(u=0; u<num_uniq_words; u++) { ret=H5ST_insert(tree,rand_uniq_words[u],rand_uniq_words[u]); CHECK(ret, FAIL, "H5ST_insert"); } /* end for */ /* Use findfirst/findnext calls to iterate through TST */ found=H5ST_findfirst(tree); CHECK(found, NULL, "H5ST_findfirst"); u=0; do { /* Check that the strings in the TST are in the correct order */ if(HDstrcmp((const char *)found->eqkid,sort_uniq_words[u])) TestErrPrintf("%d: TST node values don't match!, found->eqkid=%s, sort_uniq_words[%u]=%s\n",__LINE__,(char *)found->eqkid,(unsigned)u,sort_uniq_words[u]); /* Advance to next string in TST */ found=H5ST_findnext(found); u++; } while(found!=NULL); /* Close the TST */ ret=H5ST_close(tree); CHECK(ret, FAIL, "H5ST_close"); } /* end test_tst_iterate() */
/*------------------------------------------------------------------------- * Function: test_misc * * Purpose: Test miscellaneous group stuff. * * Return: Success: 0 * * Failure: number of errors * * Programmer: Robb Matzke * Tuesday, November 24, 1998 * *------------------------------------------------------------------------- */ static int test_misc(hid_t fapl, hbool_t new_format) { hid_t fid = (-1); /* File ID */ hid_t g1 = (-1), g2 = (-1), g3 = (-1); char filename[NAME_BUF_SIZE]; char comment[64]; if(new_format) TESTING("miscellaneous group tests (w/new group format)") else TESTING("miscellaneous group tests") /* Create file */ h5_fixname(FILENAME[0], fapl, filename, sizeof(filename)); if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR /* Create initial groups for testing, then close */ if((g1 = H5Gcreate2(fid, "test_1a", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR if((g2 = H5Gcreate2(g1, "sub_1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR if((g3 = H5Gcreate2(fid, "test_1b", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR if(H5Oset_comment(g3, "hello world") < 0) TEST_ERROR if(H5Gclose(g1) < 0) TEST_ERROR if(H5Gclose(g2) < 0) TEST_ERROR if(H5Gclose(g3) < 0) TEST_ERROR /* Open all groups with absolute names to check for exsistence */ if((g1 = H5Gopen2(fid, "/test_1a", H5P_DEFAULT)) < 0) TEST_ERROR if((g2 = H5Gopen2(fid, "/test_1a/sub_1", H5P_DEFAULT)) < 0) TEST_ERROR if((g3 = H5Gopen2(fid, "/test_1b", H5P_DEFAULT)) < 0) TEST_ERROR if(H5Oget_comment_by_name(g3, "././.", comment, sizeof comment, H5P_DEFAULT) < 0) TEST_ERROR if(HDstrcmp(comment, "hello world")) { H5_FAILED(); puts(" Read the wrong comment string from the group."); printf(" got: \"%s\"\n ans: \"hello world\"\n", comment); TEST_ERROR }
* equal to, or greater than the second. If two members compare * as equal, their order in the sorted array is undefined. * (i.e. same as strcmp()) * * Programmer: Quincey Koziol * [email protected] * Sep 5 2005 * *------------------------------------------------------------------------- */ static int H5G_link_cmp_name_inc(const void *lnk1, const void *lnk2) { FUNC_ENTER_NOAPI_NOINIT_NOERR FUNC_LEAVE_NOAPI(HDstrcmp(((const H5O_link_t *)lnk1)->name, ((const H5O_link_t *)lnk2)->name)) } /* end H5G_link_cmp_name_inc() */ /*------------------------------------------------------------------------- * Function: H5G_link_cmp_name_dec * * Purpose: Callback routine for comparing two link names, in * decreasing alphabetic order * * Return: An integer less than, equal to, or greater than zero if the * second argument is considered to be respectively less than, * equal to, or greater than the first. If two members compare * as equal, their order in the sorted array is undefined. * (i.e. opposite strcmp()) *
/*------------------------------------------------------------------------- * Function: options_add_filter * * Purpose: add a compression -f option to the option list * * Return: 0, ok, -1, fail * *------------------------------------------------------------------------- */ int options_add_filter(obj_list_t *obj_list, unsigned n_objs, filter_info_t filt, pack_opttbl_t *table) { unsigned int i, j, I; unsigned added = 0; hbool_t found = FALSE; /* increase the size of the collection by N_OBJS if necessary */ if (table->nelems + n_objs >= table->size) if (aux_inctable(table, n_objs) < 0) return -1; /* search if this object is already in the table; "path" is the key */ if (table->nelems > 0) { /* go tru the supplied list of names */ for (j = 0; j < n_objs; j++) { /* linear table search */ for (i = 0; i < table->nelems; i++) { /*already on the table */ if (HDstrcmp(obj_list[j].obj, table->objs[i].path) == 0) { /* insert */ aux_tblinsert_filter(table, i, filt); found = TRUE; break; } /* if */ } /* i */ if (!found) { /* keep the grow in a temp var */ I = table->nelems + added; added++; HDstrcpy(table->objs[I].path, obj_list[j].obj); aux_tblinsert_filter(table, I, filt); } /* cases where we have an already inserted name but there is a new name also example: -l dset1:CHUNK=20x20 -f dset1,dset2:GZIP=1 dset1 is already inserted, but dset2 must also be */ else if(found && HDstrcmp(obj_list[j].obj,table->objs[i].path) != 0) { /* keep the grow in a temp var */ I = table->nelems + added; added++; HDstrcpy(table->objs[I].path, obj_list[j].obj); aux_tblinsert_filter(table, I, filt); } } /* j */ } /* first time insertion */ else { /* go tru the supplied list of names */ for (j = 0; j < n_objs; j++) { I = table->nelems + added; added++; HDstrcpy(table->objs[I].path, obj_list[j].obj); aux_tblinsert_filter(table, I, filt); } } table->nelems += added; return 0; }
/*------------------------------------------------------------------------- * Function: options_add_layout * * Purpose: add a layout option to the option list * * Return: 0, ok, -1, fail * *------------------------------------------------------------------------- */ int options_add_layout(obj_list_t *obj_list, unsigned n_objs, pack_info_t *pack, pack_opttbl_t *table) { unsigned i, j, I; unsigned added = 0; hbool_t found = FALSE; /* increase the size of the collection by N_OBJS if necessary */ if (table->nelems + n_objs >= table->size) if (aux_inctable(table, n_objs) < 0) return -1; /* search if this object is already in the table; "path" is the key */ if (table->nelems > 0) { /* go tru the supplied list of names */ for (j = 0; j < n_objs; j++) { /* linear table search */ for (i = 0; i < table->nelems; i++) { /*already on the table */ if (HDstrcmp(obj_list[j].obj,table->objs[i].path) == 0) { /* already chunk info inserted for this one; exit */ if (table->objs[i].chunk.rank > 0) { error_msg("chunk information already inserted for <%s>\n", obj_list[j].obj); HDexit(EXIT_FAILURE); } /* insert the layout info */ else { aux_tblinsert_layout(table, i, pack); found = TRUE; break; } } /* if */ } /* i */ if (!found) { /* keep the grow in a temp var */ I = table->nelems + added; added++; HDstrcpy(table->objs[I].path, obj_list[j].obj); aux_tblinsert_layout(table, I, pack); } /* cases where we have an already inserted name but there is a new name also example: -f dset1:GZIP=1 -l dset1,dset2:CHUNK=20x20 dset1 is already inserted, but dset2 must also be */ else if(found && HDstrcmp(obj_list[j].obj,table->objs[i].path) != 0) { /* keep the grow in a temp var */ I = table->nelems + added; added++; HDstrcpy(table->objs[I].path, obj_list[j].obj); aux_tblinsert_layout(table, I, pack); } } /* j */ } /* first time insertion */ else { /* go tru the supplied list of names */ for (j = 0; j < n_objs; j++) { I = table->nelems + added; added++; HDstrcpy(table->objs[I].path, obj_list[j].obj); aux_tblinsert_layout(table, I, pack); } } table->nelems += added; return 0; }
/*------------------------------------------------------------------------- * 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: h5_fixname * * Purpose: Create a file name from a file base name like `test' and * return it through the FULLNAME (at most SIZE characters * counting the null terminator). The full name is created by * prepending the contents of HDF5_PREFIX (separated from the * base name by a slash) and appending a file extension based on * the driver supplied, resulting in something like * `ufs:/u/matzke/test.h5'. * * Return: Success: The FULLNAME pointer. * * Failure: NULL if BASENAME or FULLNAME is the null * pointer or if FULLNAME isn't large enough for * the result. * * Programmer: Robb Matzke * Thursday, November 19, 1998 * *------------------------------------------------------------------------- */ char * h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size) { const char *prefix = NULL; const char *suffix = ".h5"; /* suffix has default */ char *ptr, last = '\0'; size_t i, j; hid_t driver = -1; int isppdriver = 0; /* if the driver is MPI parallel */ if (!base_name || !fullname || size < 1) return NULL; HDmemset(fullname, 0, size); /* figure out the suffix */ if(H5P_DEFAULT != fapl) { if((driver = H5Pget_driver(fapl)) < 0) return NULL; if(H5FD_FAMILY == driver) suffix = "%05d.h5"; else if (H5FD_MULTI == driver) suffix = NULL; } /* Must first check fapl is not H5P_DEFAULT (-1) because H5FD_XXX * could be of value -1 if it is not defined. */ isppdriver = H5P_DEFAULT != fapl && (H5FD_MPIO==driver); /* Check HDF5_NOCLEANUP environment setting. * (The #ifdef is needed to prevent compile failure in case MPI is not * configured.) */ if(isppdriver) { #ifdef H5_HAVE_PARALLEL if(getenv_all(MPI_COMM_WORLD, 0, "HDF5_NOCLEANUP")) SetTestNoCleanup(); #endif /* H5_HAVE_PARALLEL */ } else { if(HDgetenv("HDF5_NOCLEANUP")) SetTestNoCleanup(); } /* Check what prefix to use for test files. Process HDF5_PARAPREFIX and * HDF5_PREFIX. * Use different ones depending on parallel or serial driver used. * (The #ifdef is needed to prevent compile failure in case MPI is not * configured.) */ if(isppdriver) { #ifdef H5_HAVE_PARALLEL /* * For parallel: * First use command line option, then the environment * variable, then try the constant */ static int explained = 0; prefix = (paraprefix ? paraprefix : getenv_all(MPI_COMM_WORLD, 0, "HDF5_PARAPREFIX")); if (!prefix && !explained) { /* print hint by process 0 once. */ int mpi_rank; MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); if (mpi_rank == 0) printf("*** Hint ***\n" "You can use environment variable HDF5_PARAPREFIX to " "run parallel test files in a\n" "different directory or to add file type prefix. E.g.,\n" " HDF5_PARAPREFIX=pfs:/PFS/user/me\n" " export HDF5_PARAPREFIX\n" "*** End of Hint ***\n"); explained = TRUE; #ifdef HDF5_PARAPREFIX prefix = HDF5_PARAPREFIX; #endif /* HDF5_PARAPREFIX */ } #endif /* H5_HAVE_PARALLEL */ } else { /* * For serial: * First use the environment variable, then try the constant */ prefix = HDgetenv("HDF5_PREFIX"); #ifdef HDF5_PREFIX if (!prefix) prefix = HDF5_PREFIX; #endif /* HDF5_PREFIX */ } /* Prepend the prefix value to the base name */ if (prefix && *prefix) { if (isppdriver) { /* This is a parallel system */ char *subdir; if (!HDstrcmp(prefix, HDF5_PARAPREFIX)) { /* * If the prefix specifies the HDF5_PARAPREFIX directory, then * default to using the "/tmp/$USER" or "/tmp/$LOGIN" * directory instead. */ char *user, *login; user = HDgetenv("USER"); login = HDgetenv("LOGIN"); subdir = (user ? user : login); if (subdir) { for (i = 0; i < size && prefix[i]; i++) fullname[i] = prefix[i]; fullname[i++] = '/'; for (j = 0; i < size && subdir[j]; ++i, ++j) fullname[i] = subdir[j]; } } if (!fullname[0]) { /* We didn't append the prefix yet */ HDstrncpy(fullname, prefix, size); fullname[size -1] = '\0'; } if (HDstrlen(fullname) + HDstrlen(base_name) + 1 < size) { /* * Append the base_name with a slash first. Multiple * slashes are handled below. */ h5_stat_t buf; if (HDstat(fullname, &buf) < 0) /* The directory doesn't exist just yet */ if (HDmkdir(fullname, (mode_t)0755) < 0 && errno != EEXIST) /* * We couldn't make the "/tmp/${USER,LOGIN}" * subdirectory. Default to PREFIX's original * prefix value. */ HDstrcpy(fullname, prefix); HDstrcat(fullname, "/"); HDstrcat(fullname, base_name); } else { /* Buffer is too small */ return NULL; } } else { if (HDsnprintf(fullname, size, "%s/%s", prefix, base_name) == (int)size) /* Buffer is too small */ return NULL; } } else if (HDstrlen(base_name) >= size) { /* Buffer is too small */ return NULL; } else { HDstrcpy(fullname, base_name); } /* Append a suffix */ if (suffix) { if (HDstrlen(fullname) + HDstrlen(suffix) >= size) return NULL; HDstrcat(fullname, suffix); } /* Remove any double slashes in the filename */ for (ptr = fullname, i = j = 0; ptr && i < size; i++, ptr++) { if (*ptr != '/' || last != '/') fullname[j++] = *ptr; last = *ptr; } return fullname; }
/*------------------------------------------------------------------------- * Function: ck_new_links * * Purpose: Open the file created in the first step and check that the * links look correct. * * Return: Success: 0 * * Failure: -1 * * Programmer: Raymond Lu * Thursday, April 25, 2002 * * Modifications: * *------------------------------------------------------------------------- */ static int ck_new_links(hid_t fapl) { hid_t file; H5G_stat_t sb_dset, sb_hard1, sb_hard2, sb_soft1, sb_soft2; char filename[NAME_BUF_SIZE]; char linkval[LINK_BUF_SIZE]; TESTING("new link queries"); /* Open the file */ h5_fixname(FILENAME[1], fapl, filename, sizeof filename); if ((file=H5Fopen(filename, H5F_ACC_RDONLY, fapl))<0) { goto error; } /* Get hard link info */ if(H5Gget_objinfo(file, "/grp1/dataset2", TRUE, &sb_dset)<0) goto error; if(H5Gget_objinfo(file, "/grp1/hard1", TRUE, &sb_hard1)<0) goto error; if(H5Gget_objinfo(file, "/grp2/hard2", TRUE, &sb_hard2)<0) goto error; /* Check hard links */ if(H5G_DATASET!=sb_hard1.type || H5G_DATASET!=sb_hard2.type) { H5_FAILED(); puts(" Unexpected object type, should have been a dataset"); goto error; } if( sb_dset.objno[0]!=sb_hard1.objno[0] || sb_dset.objno[1]!=sb_hard1.objno[1] || sb_dset.objno[0]!=sb_hard2.objno[0] || sb_dset.objno[1]!=sb_hard2.objno[1] ) { H5_FAILED(); puts(" Hard link test failed. Link seems not to point to the "); puts(" expected file location."); goto error; } /* Get soft link info */ if(H5Gget_objinfo(file, "/grp1/soft1", TRUE, &sb_soft1)<0) goto error; if(H5Gget_objinfo(file, "/grp2/soft2", TRUE, &sb_soft2)<0) goto error; /* Check soft links */ if(H5G_DATASET!=sb_soft1.type || H5G_DATASET!=sb_soft2.type) { H5_FAILED(); puts(" Unexpected object type, should have been a dataset"); goto error; } if( sb_dset.objno[0]!=sb_soft1.objno[0] || sb_dset.objno[1]!=sb_soft1.objno[1] || sb_dset.objno[0]!=sb_soft2.objno[0] || sb_dset.objno[1]!=sb_soft2.objno[1] ) { H5_FAILED(); puts(" Soft link test failed. Link seems not to point to the "); puts(" expected file location."); goto error; } if (H5Gget_linkval(file, "grp2/soft2", sizeof linkval, linkval)<0) { goto error; } if (HDstrcmp(linkval, "/grp1/dataset2")) { H5_FAILED(); puts(" Soft link test failed. Wrong link value"); goto error; } /* Cleanup */ if(H5Fclose(file)<0) goto error; PASSED(); return 0; error: return -1; }
/*------------------------------------------------------------------------- * Function: main * * Purpose: Part 1 of a two-part H5Fflush() test. * * Return: Success: 0 * * Failure: 1 * * Programmer: Robb Matzke * Friday, October 23, 1998 * * Modifications: * Leon Arber * Sept. 26, 2006, expand test to check for failure if H5Fflush is not called. * * *------------------------------------------------------------------------- */ int main(int argc, char* argv[]) { hid_t file1, file2, fapl; MPI_File *mpifh_p = NULL; char name[1024]; const char *envval = NULL; int mpi_size, mpi_rank; MPI_Comm comm = MPI_COMM_WORLD; MPI_Info info = MPI_INFO_NULL; MPI_Init(&argc, &argv); MPI_Comm_size(comm, &mpi_size); MPI_Comm_rank(comm, &mpi_rank); fapl = H5Pcreate(H5P_FILE_ACCESS); H5Pset_fapl_mpio(fapl, comm, info); if(mpi_rank == 0) TESTING("H5Fflush (part1)"); envval = HDgetenv("HDF5_DRIVER"); if(envval == NULL) envval = "nomatch"; if(HDstrcmp(envval, "split")) { /* Create the file */ h5_fixname(FILENAME[0], fapl, name, sizeof name); file1 = create_file(name, fapl); /* Flush and exit without closing the library */ if(H5Fflush(file1, H5F_SCOPE_GLOBAL) < 0) goto error; /* Create the other file which will not be flushed */ h5_fixname(FILENAME[1], fapl, name, sizeof name); file2 = create_file(name, fapl); if(mpi_rank == 0) PASSED(); fflush(stdout); fflush(stderr); } /* end if */ else { SKIPPED(); puts(" Test not compatible with current Virtual File Driver"); } /* end else */ /* * Some systems like AIX do not like files not closed when MPI_Finalize * is called. So, we need to get the MPI file handles, close them by hand. * Then the _exit is still needed to stop at_exit from happening in some systems. * Note that MPIO VFD returns the address of the file-handle in the VFD struct * because MPI_File_close wants to modify the file-handle variable. */ /* close file1 */ if(H5Fget_vfd_handle(file1, fapl, (void **)&mpifh_p) < 0) { printf("H5Fget_vfd_handle for file1 failed\n"); goto error; } /* end if */ if(MPI_File_close(mpifh_p) != MPI_SUCCESS) { printf("MPI_File_close for file1 failed\n"); goto error; } /* end if */ /* close file2 */ if(H5Fget_vfd_handle(file2, fapl, (void **)&mpifh_p) < 0) { printf("H5Fget_vfd_handle for file2 failed\n"); goto error; } /* end if */ if(MPI_File_close(mpifh_p) != MPI_SUCCESS) { printf("MPI_File_close for file2 failed\n"); goto error; } /* end if */ fflush(stdout); fflush(stderr); HD_exit(0); error: fflush(stdout); fflush(stderr); HD_exit(1); }
/*------------------------------------------------------------------------- * Function: cklinks * * Purpose: Open the file created in the first step and check that the * links look correct. * * Return: Success: 0 * * Failure: -1 * * Programmer: Robb Matzke * Friday, August 14, 1998 * * Modifications: * *------------------------------------------------------------------------- */ static int cklinks(hid_t fapl) { hid_t file; H5G_stat_t sb1, sb2; char linkval[LINK_BUF_SIZE]; char filename[NAME_BUF_SIZE]; herr_t status; TESTING("link queries"); /* Open the file */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if ((file=H5Fopen(filename, H5F_ACC_RDONLY, fapl))<0) { goto error; } /* Hard link */ if (H5Gget_objinfo(file, "d1", TRUE, &sb1)<0) goto error; if (H5Gget_objinfo(file, "grp1/hard", TRUE, &sb2)<0) goto error; if (H5G_DATASET!=sb2.type) { H5_FAILED(); puts(" Unexpected object type should have been a dataset"); goto error; } if (sb1.objno[0]!=sb2.objno[0] || sb1.objno[1]!=sb2.objno[1]) { H5_FAILED(); puts(" Hard link test failed. Link seems not to point to the "); puts(" expected file location."); goto error; } /* Symbolic link */ if (H5Gget_objinfo(file, "grp1/soft", TRUE, &sb2)<0) goto error; if (H5G_DATASET!=sb2.type) { H5_FAILED(); puts(" Unexpected object type should have been a dataset"); goto error; } if (sb1.objno[0]!=sb2.objno[0] || sb1.objno[1]!=sb2.objno[1]) { H5_FAILED(); puts(" Soft link test failed. Link seems not to point to the "); puts(" expected file location."); goto error; } if (H5Gget_linkval(file, "grp1/soft", sizeof linkval, linkval)<0) { goto error; } if (HDstrcmp(linkval, "/d1")) { H5_FAILED(); puts(" Soft link test failed. Wrong link value"); goto error; } /* Dangling link */ H5E_BEGIN_TRY { status = H5Gget_objinfo(file, "grp1/dangle", TRUE, &sb2); } H5E_END_TRY; if (status>=0) { H5_FAILED(); puts(" H5Gget_objinfo() should have failed for a dangling link."); goto error; } if (H5Gget_objinfo(file, "grp1/dangle", FALSE, &sb2)<0) goto error; if (H5G_LINK!=sb2.type) { H5_FAILED(); puts(" Unexpected object type should have been a symbolic link"); goto error; } if (H5Gget_linkval(file, "grp1/dangle", sizeof linkval, linkval)<0) { goto error; } if (HDstrcmp(linkval, "foobar")) { H5_FAILED(); puts(" Dangling link test failed. Wrong link value"); goto error; } /* Recursive link */ H5E_BEGIN_TRY { status = H5Gget_objinfo(file, "grp1/recursive", TRUE, &sb2); } H5E_END_TRY; if (status>=0) { H5_FAILED(); puts(" H5Gget_objinfo() should have failed for a recursive link."); goto error; } if (H5Gget_objinfo(file, "grp1/recursive", FALSE, &sb2)<0) goto error; if (H5G_LINK!=sb2.type) { H5_FAILED(); puts(" Unexpected object type should have been a symbolic link"); goto error; } if (H5Gget_linkval(file, "grp1/recursive", sizeof linkval, linkval)<0) { goto error; } if (HDstrcmp(linkval, "/grp1/recursive")) { H5_FAILED(); puts(" Recursive link test failed. Wrong link value"); goto error; } /* Cleanup */ if (H5Fclose(file)<0) goto error; PASSED(); return 0; error: return -1; }
/*------------------------------------------------------------------------- * Function: build_match_list_attrs * * Purpose: get list of matching attribute name from obj1 and obj2 * * Note: * Find common attribute; the algorithm for search is referred from * build_match_list() in h5diff.c . * * Parameter: * table_out [OUT] : return the list * * Programmer: Jonathan Kim * * Date: March 15, 2011 *------------------------------------------------------------------------*/ static herr_t build_match_list_attrs(hid_t loc1_id, hid_t loc2_id, table_attrs_t ** table_out, diff_opt_t *options) { H5O_info_t oinfo1, oinfo2; /* Object info */ hid_t attr1_id=-1; /* attr ID */ hid_t attr2_id=-1; /* attr ID */ size_t curr1 = 0; size_t curr2 = 0; unsigned infile[2]; char name1[ATTR_NAME_MAX]; char name2[ATTR_NAME_MAX]; int cmp; unsigned i; table_attrs_t *table_lp = NULL; if(H5Oget_info(loc1_id, &oinfo1) < 0) goto error; if(H5Oget_info(loc2_id, &oinfo2) < 0) goto error; table_attrs_init( &table_lp ); /*-------------------------------------------------- * build the list */ while(curr1 < oinfo1.num_attrs && curr2 < oinfo2.num_attrs) { /*------------------ * open attribute1 */ if((attr1_id = H5Aopen_by_idx(loc1_id, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)curr1, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error; /* get name */ if(H5Aget_name(attr1_id, (size_t)ATTR_NAME_MAX, name1) < 0) goto error; /*------------------ * open attribute2 */ if((attr2_id = H5Aopen_by_idx(loc2_id, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)curr2, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error; /* get name */ if(H5Aget_name(attr2_id, (size_t)ATTR_NAME_MAX, name2) < 0) goto error; /* criteria is string compare */ cmp = HDstrcmp(name1, name2); if(cmp == 0) { infile[0] = 1; infile[1] = 1; table_attr_mark_exist(infile, name1, table_lp); curr1++; curr2++; } else if(cmp < 0) { infile[0] = 1; infile[1] = 0; table_attr_mark_exist(infile, name1, table_lp); table_lp->nattrs_only1++; curr1++; } else { infile[0] = 0; infile[1] = 1; table_attr_mark_exist(infile, name2, table_lp); table_lp->nattrs_only2++; curr2++; } /* close for next turn */ H5Aclose(attr1_id); attr1_id = -1; H5Aclose(attr2_id); attr2_id = -1; } /* end while */ /* list1 did not end */ infile[0] = 1; infile[1] = 0; while(curr1 < oinfo1.num_attrs) { /*------------------ * open attribute1 */ if((attr1_id = H5Aopen_by_idx(loc1_id, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)curr1, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error; /* get name */ if(H5Aget_name(attr1_id, (size_t)ATTR_NAME_MAX, name1) < 0) goto error; table_attr_mark_exist(infile, name1, table_lp); table_lp->nattrs_only1++; curr1++; /* close for next turn */ H5Aclose(attr1_id); attr1_id = -1; } /* list2 did not end */ infile[0] = 0; infile[1] = 1; while(curr2 < oinfo2.num_attrs) { /*------------------ * open attribute2 */ if((attr2_id = H5Aopen_by_idx(loc2_id, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)curr2, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error; /* get name */ if(H5Aget_name(attr2_id, (size_t)ATTR_NAME_MAX, name2) < 0) goto error; table_attr_mark_exist(infile, name2, table_lp); table_lp->nattrs_only2++; curr2++; /* close for next turn */ H5Aclose(attr2_id); } /*------------------------------------------------------ * print the list */ if(options->m_verbose_level == 2) { /* if '-v2' is detected */ parallel_print(" obj1 obj2\n"); parallel_print(" --------------------------------------\n"); for(i = 0; i < (unsigned int) table_lp->nattrs; i++) { char c1, c2; c1 = (table_lp->attrs[i].exist[0]) ? 'x' : ' '; c2 = (table_lp->attrs[i].exist[1]) ? 'x' : ' '; parallel_print("%5c %6c %-15s\n", c1, c2, table_lp->attrs[i].name); } /* end for */ } if(options->m_verbose_level >= 1) { parallel_print("Attributes status: %d common, %d only in obj1, %d only in obj2\n", table_lp->nattrs - table_lp->nattrs_only1 - table_lp->nattrs_only2, table_lp->nattrs_only1, table_lp->nattrs_only2 ); } *table_out = table_lp; return 0; error: if (0 < attr1_id) H5Aclose(attr1_id); if (0 < attr2_id) H5Aclose(attr2_id); return -1; }
/*------------------------------------------------------------------------- * Function: toomany * * Purpose: Build a file with too many symbolic links * * Return: Success: 0 * * Failure: -1 * * Programmer: Quincey Koziol * Tuesday, August 9, 2005 * * Modifications: * *------------------------------------------------------------------------- */ static int toomany(hid_t fapl) { hid_t fid = (-1); /* File ID */ hid_t gid = (-1); /* Group ID */ hid_t gid2 = (-1); /* Datatype ID */ char objname[NAME_BUF_SIZE]; /* Object name */ ssize_t name_len; /* Length of object name */ char filename[NAME_BUF_SIZE]; TESTING("too many links"); /* Make certain test is valid */ /* XXX: should probably make a "generic" test that creates the proper * # of links based on this value - QAK */ HDassert(H5G_NLINKS == 16); /* Create files */ h5_fixname(FILENAME[1], fapl, filename, sizeof filename); if((fid=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) TEST_ERROR; /* Create group with short name in file (used as target for hard links) */ if((gid=H5Gcreate (fid, "final", (size_t)0))<0) TEST_ERROR; /* Create chain of hard links to existing object (no limit on #) */ if(H5Glink2(fid, "final", H5G_LINK_HARD, fid, "hard1") < 0) TEST_ERROR; if(H5Glink2(fid, "hard1", H5G_LINK_HARD, fid, "hard2") < 0) TEST_ERROR; if(H5Glink2(fid, "hard2", H5G_LINK_HARD, fid, "hard3") < 0) TEST_ERROR; if(H5Glink2(fid, "hard3", H5G_LINK_HARD, fid, "hard4") < 0) TEST_ERROR; if(H5Glink2(fid, "hard4", H5G_LINK_HARD, fid, "hard5") < 0) TEST_ERROR; if(H5Glink2(fid, "hard5", H5G_LINK_HARD, fid, "hard6") < 0) TEST_ERROR; if(H5Glink2(fid, "hard6", H5G_LINK_HARD, fid, "hard7") < 0) TEST_ERROR; if(H5Glink2(fid, "hard7", H5G_LINK_HARD, fid, "hard8") < 0) TEST_ERROR; if(H5Glink2(fid, "hard8", H5G_LINK_HARD, fid, "hard9") < 0) TEST_ERROR; if(H5Glink2(fid, "hard9", H5G_LINK_HARD, fid, "hard10") < 0) TEST_ERROR; if(H5Glink2(fid, "hard10", H5G_LINK_HARD, fid, "hard11") < 0) TEST_ERROR; if(H5Glink2(fid, "hard11", H5G_LINK_HARD, fid, "hard12") < 0) TEST_ERROR; if(H5Glink2(fid, "hard12", H5G_LINK_HARD, fid, "hard13") < 0) TEST_ERROR; if(H5Glink2(fid, "hard13", H5G_LINK_HARD, fid, "hard14") < 0) TEST_ERROR; if(H5Glink2(fid, "hard14", H5G_LINK_HARD, fid, "hard15") < 0) TEST_ERROR; if(H5Glink2(fid, "hard15", H5G_LINK_HARD, fid, "hard16") < 0) TEST_ERROR; if(H5Glink2(fid, "hard16", H5G_LINK_HARD, fid, "hard17") < 0) TEST_ERROR; if(H5Glink2(fid, "hard17", H5G_LINK_HARD, fid, "hard18") < 0) TEST_ERROR; if(H5Glink2(fid, "hard18", H5G_LINK_HARD, fid, "hard19") < 0) TEST_ERROR; if(H5Glink2(fid, "hard19", H5G_LINK_HARD, fid, "hard20") < 0) TEST_ERROR; if(H5Glink2(fid, "hard20", H5G_LINK_HARD, fid, "hard21") < 0) TEST_ERROR; /* Create chain of soft links to existing object (limited) */ if(H5Glink2(fid, "final", H5G_LINK_SOFT, fid, "soft1") < 0) TEST_ERROR; if(H5Glink2(fid, "soft1", H5G_LINK_SOFT, fid, "soft2") < 0) TEST_ERROR; if(H5Glink2(fid, "soft2", H5G_LINK_SOFT, fid, "soft3") < 0) TEST_ERROR; if(H5Glink2(fid, "soft3", H5G_LINK_SOFT, fid, "soft4") < 0) TEST_ERROR; if(H5Glink2(fid, "soft4", H5G_LINK_SOFT, fid, "soft5") < 0) TEST_ERROR; if(H5Glink2(fid, "soft5", H5G_LINK_SOFT, fid, "soft6") < 0) TEST_ERROR; if(H5Glink2(fid, "soft6", H5G_LINK_SOFT, fid, "soft7") < 0) TEST_ERROR; if(H5Glink2(fid, "soft7", H5G_LINK_SOFT, fid, "soft8") < 0) TEST_ERROR; if(H5Glink2(fid, "soft8", H5G_LINK_SOFT, fid, "soft9") < 0) TEST_ERROR; if(H5Glink2(fid, "soft9", H5G_LINK_SOFT, fid, "soft10") < 0) TEST_ERROR; if(H5Glink2(fid, "soft10", H5G_LINK_SOFT, fid, "soft11") < 0) TEST_ERROR; if(H5Glink2(fid, "soft11", H5G_LINK_SOFT, fid, "soft12") < 0) TEST_ERROR; if(H5Glink2(fid, "soft12", H5G_LINK_SOFT, fid, "soft13") < 0) TEST_ERROR; if(H5Glink2(fid, "soft13", H5G_LINK_SOFT, fid, "soft14") < 0) TEST_ERROR; if(H5Glink2(fid, "soft14", H5G_LINK_SOFT, fid, "soft15") < 0) TEST_ERROR; if(H5Glink2(fid, "soft15", H5G_LINK_SOFT, fid, "soft16") < 0) TEST_ERROR; if(H5Glink2(fid, "soft16", H5G_LINK_SOFT, fid, "soft17") < 0) TEST_ERROR; /* Close objects */ if(H5Gclose(gid)<0) TEST_ERROR; if(H5Fclose(fid)<0) TEST_ERROR; /* Open file */ if((fid=H5Fopen(filename, H5F_ACC_RDWR, fapl))<0) TEST_ERROR; /* Open object through last hard link */ if((gid = H5Gopen(fid, "hard21")) < 0) TEST_ERROR; /* Check name */ if((name_len = H5Iget_name( gid, objname, (size_t)NAME_BUF_SIZE )) < 0) TEST_ERROR if(HDstrcmp(objname, "/hard21")) TEST_ERROR /* Create object in hard-linked group */ if((gid2 = H5Gcreate(gid, "new_hard", (size_t)0)) < 0) TEST_ERROR /* Close group in hard-linked group */ if(H5Gclose(gid2) < 0) TEST_ERROR /* Close hard-linked object */ if(H5Gclose(gid) < 0) TEST_ERROR; /* Open object through too deep soft link */ H5E_BEGIN_TRY { gid = H5Gopen(fid, "soft17"); } H5E_END_TRY; if (gid >= 0) { H5_FAILED(); puts(" Should have failed for sequence of too many nested links."); goto error; } /* Open object through lesser soft link */ if((gid = H5Gopen(fid, "soft16")) < 0) TEST_ERROR; /* Check name */ if((name_len = H5Iget_name( gid, objname, (size_t)NAME_BUF_SIZE )) < 0) TEST_ERROR if(HDstrcmp(objname, "/soft16")) TEST_ERROR /* Create object in external file */ if((gid2 = H5Gcreate(gid, "new_soft", (size_t)0)) < 0) TEST_ERROR /* Close group in external file */ if(H5Gclose(gid2) < 0) TEST_ERROR /* Close external object */ if(H5Gclose(gid) < 0) TEST_ERROR; /* Close first file */ if(H5Fclose(fid)<0) TEST_ERROR; PASSED(); return 0; error: H5E_BEGIN_TRY { H5Gclose (gid2); H5Gclose (gid); H5Fclose (fid); } H5E_END_TRY; return -1; } /* end toomany() */
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; }