/*--------------------------------------------------------------------------*/
int openHDF5File(const char *name, int _iAppendMode)
{
    hid_t           file;
    char *pathdest = getPathFilename(name);
    char *currentpath = NULL;
    char *filename = getFilenameWithExtension(name);
    int ierr = 0;
    void *oldclientdata = NULL;
    /* Used to avoid stack trace to be displayed */
    H5E_auto2_t oldfunc;

    /* TO DO : remove when HDF5 will be fixed ... */
    /* HDF5 does not manage no ANSI characters */
    /* UGLY workaround :( */
    /* We split path, move in this path, open file */
    /* and return in previous place */
    /* see BUG 6440 */
    currentpath = scigetcwd(&ierr);

    //prevent error msg to change directory to ""
    if (strcmp(pathdest, "") != 0)
    {
        scichdir(pathdest);
    }

    /* Save old error handler */
    H5Eget_auto2(H5E_DEFAULT, &oldfunc, &oldclientdata);

    /* Turn off error handling */
    H5Eset_auto2(H5E_DEFAULT, NULL, NULL);

    if (_iAppendMode == 0)
    {
        //read only
        file = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);
    }
    else
    {
        //read write to append
        file = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT);
    }

    /* The following test will display the backtrace in case of error */
    /* Deactivated because displayed each time we call 'load' to open a non-HDF5 file */
    /*if (file < 0)
    {
        H5Eprint(stderr);
        }*/
    /* Restore previous error handler */
    H5Eset_auto2(H5E_DEFAULT, oldfunc, oldclientdata);

    scichdir(currentpath);

    FREE(currentpath);
    FREE(filename);
    FREE(pathdest);

    return file;
}
示例#2
0
//--------------------------------------------------------------------------
// Function:	Exception::getAutoPrint
///\brief	Retrieves the current settings for the automatic error
///		stack traversal function and its data.
///\param	func        - OUT: Current setting for the function to be
///					called upon an error condition
///\param	client_data - OUT: Current setting for the data passed to
///					the error function
// Programmer	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void Exception::getAutoPrint( H5E_auto2_t& func, void** client_data )
{
   // calls the C API routine H5Eget_auto to get the current setting of
   // the automatic error printing
   herr_t ret_value = H5Eget_auto2( H5E_DEFAULT, &func, client_data );
   if( ret_value < 0 )
      throw Exception( "Exception::getAutoPrint", "H5Eget_auto failed" );
}
示例#3
0
static
void *tts_error_thread(void UNUSED *arg)
{
    hid_t dataspace, datatype, dataset;
    hsize_t dimsf[1]; /* dataset dimensions */
    H5E_auto2_t old_error_cb;
    void *old_error_client_data;
    int value;
    int ret;

    /* preserve previous error stack handler */
    H5Eget_auto2(H5E_DEFAULT, &old_error_cb, &old_error_client_data);

    /* set each thread's error stack handler */
    H5Eset_auto2(H5E_DEFAULT, error_callback, NULL);

    /* define dataspace for dataset */
    dimsf[0] = 1;
    dataspace = H5Screate_simple(1, dimsf, NULL);
    assert(dataspace >= 0);

    /* define datatype for the data using native little endian integers */
    datatype = H5Tcopy(H5T_NATIVE_INT);
    assert(datatype >= 0);
    H5Tset_order(datatype, H5T_ORDER_LE);

    /* create a new dataset within the file */
    dataset = H5Dcreate2(error_file, DATASETNAME, datatype, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    if(dataset >= 0) {   /* not an error */
        value = WRITE_NUMBER;
        H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &value);
        H5Dclose(dataset);
    } /* end if */

    ret = H5Tclose(datatype);
    assert(ret >= 0);
    ret = H5Sclose(dataspace);
    assert(ret >= 0);

    /* turn our error stack handler off */
    H5Eset_auto2(H5E_DEFAULT, old_error_cb, old_error_client_data);

    return NULL;
}
/*
 * Initialize testing framework
 *
 * ProgName: Name of test program.
 * private_usage: Optional routine provided by test program to print the
 *      private portion of usage page.  Default to NULL which means none is
 *      provided.
 * private_parser: Optional routine provided by test program to parse the
 *      private options.  Default to NULL which means none is provided.
 *
 * Modifications:
 *     	Albert Cheng 2004/08/17
 *     	Added the ProgName, private_usage and private_parser arguments.
 */
void TestInit(const char *ProgName, void (*private_usage)(void), int (*private_parser)(int ac, char *av[]))
{
    /* Save error printing settings */
    H5Eget_auto2(H5E_DEFAULT, PrintErrorStackFunc, PrintErrorStackData);
    /*
     * Turn off automatic error reporting since we do it ourselves.  Besides,
     * half the functions this test calls are private, so automatic error
     * reporting wouldn't do much good since it's triggered at the API layer.
     */
    PrintErrorStackOff();

    /*
     * Record the program name and private routines if provided.
     */
    TestProgName = ProgName;
    if (NULL != private_usage)
	TestPrivateUsage = private_usage;
    if (NULL != private_parser)
	TestPrivateParser = private_parser;
}
示例#5
0
文件: h5test.c 项目: zlongshen/hdf5
/*-------------------------------------------------------------------------
 * Function:  h5_reset
 *
 * Purpose:  Reset the library by closing it.
 *
 * Return:  void
 *
 * Programmer:  Robb Matzke
 *              Friday, November 20, 1998
 *
 *-------------------------------------------------------------------------
 */
void
h5_reset(void)
{
    HDfflush(stdout);
    HDfflush(stderr);
    H5close();

    /* Save current error stack reporting routine and redirect to our local one */
    HDassert(err_func == NULL);
    H5Eget_auto2(H5E_DEFAULT, &err_func, NULL);
    H5Eset_auto2(H5E_DEFAULT, h5_errors, NULL);

    /*
     * I commented this chunk of code out because it's not clear what diagnostics
     *      were being output and under what circumstances, and creating this file
     *      is throwing off debugging some of the tests.  I can't see any _direct_
     *      harm in keeping this section of code, but I can't see any _direct_
     *      benefit right now either.  If we figure out under which circumstances
     *      diagnostics are being output, we should enable this behavior based on
     *      appropriate configure flags/macros.  QAK - 2007/12/20
     */
#ifdef OLD_WAY
    {
        char  filename[1024];

        /*
         * Cause the library to emit some diagnostics early so they don't
         * interfere with other formatted output.
         */
        sprintf(filename, "/tmp/h5emit-%05d.h5", HDgetpid());
        H5E_BEGIN_TRY {
            hid_t file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT,
            H5P_DEFAULT);
            hid_t grp = H5Gcreate2(file, "emit", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
            H5Gclose(grp);
            H5Fclose(file);
            HDunlink(filename);
        } H5E_END_TRY;
    }
#endif /* OLD_WAY */
}
/*-------------------------------------------------------------------------
 * Function:    main
 *
 * Purpose:     HDF5 user block unjammer
 *
 * Return:      Success:    0
 *              Failure:    1
 *
 * Programmer:
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
int
main(int argc, const char *argv[])
{
    void               *edata;
    H5E_auto2_t         func;
    hid_t               ifile = -1;
    hid_t               plist = -1;
    off_t               fsize;
    hsize_t             usize;
    htri_t              testval;
    herr_t              status;
    int                 res;
    h5_stat_t           sbuf;

    h5tools_setprogname(PROGRAMNAME);
    h5tools_setstatus(EXIT_SUCCESS);

    /* Disable error reporting  */
    H5Eget_auto2(H5E_DEFAULT, &func, &edata);
    H5Eset_auto2(H5E_DEFAULT, NULL, NULL);

    /* Initialize h5tools lib  */
    h5tools_init();

    if(EXIT_FAILURE == parse_command_line(argc, argv))
        goto done;

    if (input_file == NULL) {
        /* no user block  */
        error_msg("missing arguemnt for HDF5 file input.\n");
        help_ref_msg(stderr);
        h5tools_setstatus(EXIT_FAILURE);
        goto done;
    }
  
    testval = H5Fis_hdf5(input_file);

    if (testval <= 0) {
        error_msg("Input HDF5 file \"%s\" is not HDF\n", input_file);
        help_ref_msg (stderr);
        h5tools_setstatus(EXIT_FAILURE);
        goto done;
    }

    ifile = H5Fopen(input_file, H5F_ACC_RDONLY , H5P_DEFAULT);

    if (ifile < 0) {
        error_msg("Can't open input HDF5 file \"%s\"\n", input_file);
        h5tools_setstatus(EXIT_FAILURE);
        goto done;
    }

    plist = H5Fget_create_plist(ifile);
    if (plist < 0) {
        error_msg("Can't get file creation plist for file \"%s\"\n", input_file);
        h5tools_setstatus(EXIT_FAILURE);
        goto done;
    }

    status = H5Pget_userblock(plist, & usize);
    if (status < 0) {
        error_msg("Can't get user block for file \"%s\"\n", input_file);
        h5tools_setstatus(EXIT_FAILURE);
        goto done;
    }

    status = H5Pclose(plist);
    HDassert(status >= 0);
    status = H5Fclose(ifile);
    HDassert(status >= 0);

    if (usize == 0) {
  /* no user block to remove: message? */
        error_msg("\"%s\" has no user block: no change to file\n", input_file);
        h5tools_setstatus(EXIT_SUCCESS);
        goto done;
    }

    res = HDfstat(HDfileno(rawinstream), &sbuf);
    if(res < 0) {
        error_msg("Can't stat file \"%s\"\n", input_file);
        h5tools_setstatus(EXIT_FAILURE);
        goto done;
    }

    fsize = sbuf.st_size;

    if (do_delete && (ub_file != NULL)) {
        error_msg("??\"%s\"\n", ub_file);
        h5tools_setstatus(EXIT_FAILURE);
        goto done;
    }

    if (output_file == NULL) {
            error_msg("unable to open output HDF5 file \"%s\"\n", input_file);
            h5tools_setstatus(EXIT_FAILURE);
            goto done;
    } 

    /* copy from 0 to 'usize - 1' into ufid  */
    if (!do_delete) {
        if(copy_to_file(rawinstream, rawoutstream, 0, (ssize_t) usize) < 0) {
            error_msg("unable to copy user block to output file \"%s\"\n", ub_file);
            h5tools_setstatus(EXIT_FAILURE);
            goto done;
        }
    }

    /* copy from usize to end of file into h5fid,
     * starting at end of user block if present */
   if(copy_to_file(rawinstream, rawdatastream, (ssize_t) usize, (ssize_t)(fsize - (ssize_t)usize)) < 0) {
        error_msg("unable to copy hdf5 data to output file \"%s\"\n", output_file);
        h5tools_setstatus(EXIT_FAILURE);
        goto done;
    }
 
done:
    if(input_file)
        HDfree(input_file);
		
    if(output_file)
        HDfree(output_file);
		
    if(ub_file) {
        HDfree(ub_file);
    }
	   
    h5tools_close();

    return h5tools_getstatus();
}
示例#7
0
文件: h5jam.c 项目: ElaraFX/hdf5
/*-------------------------------------------------------------------------
 * Function:    main
 *
 * Purpose:     HDF5 user block jammer
 *
 * Return:      Success:    0
 *              Failure:    1
 *
 * Programmer:
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
int
main (int argc, const char *argv[])
{
    int         ufid = -1;
    int         h5fid = -1;
    int         ofid = -1;
    void       *edata;
    H5E_auto2_t func;
    hid_t       ifile = -1;
    hid_t       plist = -1;
    herr_t      status;
    htri_t      testval;
    hsize_t     usize;
    hsize_t     h5fsize;
    hsize_t     startub;
    hsize_t     where;
    hsize_t     newubsize;
    off_t       fsize;
    h5_stat_t   sbuf;
    h5_stat_t   sbuf2;
    int         res;

    h5tools_setprogname(PROGRAMNAME);
    h5tools_setstatus(EXIT_SUCCESS);

    /* Disable error reporting */
    H5Eget_auto2(H5E_DEFAULT, &func, &edata);
    H5Eset_auto2(H5E_DEFAULT, NULL, NULL);

    /* Initialize h5tools lib */
    h5tools_init();

    parse_command_line (argc, argv);

    if (ub_file == NULL) {
        /* no user block */
        error_msg("missing arguemnt for -u <user_file>.\n");
        help_ref_msg(stderr);
        leave (EXIT_FAILURE);
    }

    testval = H5Fis_hdf5 (ub_file);

    if (testval > 0) {
        error_msg("-u <user_file> cannot be HDF5 file, but it appears to be an HDF5 file.\n");
        help_ref_msg(stderr);
        leave (EXIT_FAILURE);
    }

    if (input_file == NULL) {
        error_msg("missing arguemnt for -i <HDF5 file>.\n");
        help_ref_msg(stderr);
        leave (EXIT_FAILURE);
    }

    testval = H5Fis_hdf5 (input_file);

    if (testval <= 0) {
        error_msg("Input HDF5 file \"%s\" is not HDF5 format.\n", input_file);
        help_ref_msg(stderr);
        leave (EXIT_FAILURE);
    }

    ifile = H5Fopen (input_file, H5F_ACC_RDONLY, H5P_DEFAULT);

    if (ifile < 0) {
        error_msg("Can't open input HDF5 file \"%s\"\n", input_file);
        leave (EXIT_FAILURE);
    }

    plist = H5Fget_create_plist (ifile);
    if (plist < 0) {
        error_msg("Can't get file creation plist for file \"%s\"\n", input_file);
        H5Fclose(ifile);
        leave (EXIT_FAILURE);
    }

    status = H5Pget_userblock (plist, &usize);
    if (status < 0) {
        error_msg("Can't get user block for file \"%s\"\n", input_file);
        H5Pclose(plist);
        H5Fclose(ifile);
        leave (EXIT_FAILURE);
    }

    H5Pclose(plist);
    H5Fclose(ifile);

    ufid = HDopen(ub_file, O_RDONLY, 0);
    if(ufid < 0) {
        error_msg("unable to open user block file \"%s\"\n", ub_file);
        leave (EXIT_FAILURE);
    }

    res = HDfstat(ufid, &sbuf);
    if(res < 0) {
        error_msg("Can't stat file \"%s\"\n", ub_file);
        HDclose (ufid);
        leave (EXIT_FAILURE);
    }

    fsize = (off_t)sbuf.st_size;

    h5fid = HDopen(input_file, O_RDONLY, 0);
    if(h5fid < 0) {
        error_msg("unable to open HDF5 file for read \"%s\"\n", input_file);
        HDclose (ufid);
        leave (EXIT_FAILURE);
    }

    res = HDfstat(h5fid, &sbuf2);
    if(res < 0) {
        error_msg("Can't stat file \"%s\"\n", input_file);
        HDclose (h5fid);
        HDclose (ufid);
        leave (EXIT_FAILURE);
    }

    h5fsize = (hsize_t)sbuf2.st_size;

    if (output_file == NULL) {
        ofid = HDopen (input_file, O_WRONLY, 0);

        if (ofid < 0) {
            error_msg("unable to open output file \"%s\"\n", output_file);
            HDclose (h5fid);
            HDclose (ufid);
            leave (EXIT_FAILURE);
        }
    }
    else {
        ofid = HDopen (output_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);

        if (ofid < 0) {
            error_msg("unable to create output file \"%s\"\n", output_file);
            HDclose (h5fid);
            HDclose (ufid);
            leave (EXIT_FAILURE);
        }
    }

    newubsize = compute_user_block_size ((hsize_t) fsize);

    startub = usize;

    if (usize > 0) {
        if (do_clobber == TRUE) {
            /* where is max of the current size or the new UB */
            if (usize > newubsize) {
                newubsize = usize;
            }
            startub = 0;    /*blast the old */
        }
        else {
            /* add new ub to current ublock, pad to new offset */
            newubsize += usize;
            newubsize = compute_user_block_size ((hsize_t) newubsize);
        }
    }

    /* copy the HDF5 from starting at usize to starting at newubsize:
     *  makes room at 'from' for new ub */
    /* if no current ub, usize is 0 */
    copy_some_to_file (h5fid, ofid, usize, newubsize, (ssize_t) (h5fsize - usize));

    /* copy the old ub to the beginning of the new file */
    if (!do_clobber) {
        where = copy_some_to_file (h5fid, ofid, (hsize_t) 0, (hsize_t) 0, (ssize_t) usize);
    }

    /* copy the new ub to the end of the ub */
    where = copy_some_to_file (ufid, ofid, (hsize_t) 0, startub, (ssize_t) - 1);

    /* pad the ub */
    where = write_pad (ofid, where);

    if(ub_file)
        HDfree (ub_file);
    if(input_file)
        HDfree (input_file);
    if(output_file)
        HDfree (output_file);
    
    if(ufid >= 0)
        HDclose (ufid);
    if(h5fid >= 0)
        HDclose (h5fid);
    if(ofid >= 0)
        HDclose (ofid);

    return h5tools_getstatus();
}
示例#8
0
文件: h5watch.c 项目: FilipeMaia/hdf5
/*-------------------------------------------------------------------------
 * Function:    main
 *
 * Purpose:     h5watch
 *
 * Return:      Success:    0
 *              Failure:    1
 *
 * Programmer:  Vailin Choi; August 2010
 *
 *-------------------------------------------------------------------------
 */
int
main(int argc, const char *argv[])
{
    char        drivername[50];
    char 	*fname = NULL; 
    char	*dname = NULL; 
    void               *edata;
    H5E_auto2_t         func;
    char	*x;
    hid_t	fid = -1;
    hid_t	fapl = -1;

    /* Set up tool name and exit status */
    h5tools_setprogname(PROGRAMNAME);
    h5tools_setstatus(EXIT_SUCCESS);

    /* Disable error reporting */
    H5Eget_auto2(H5E_DEFAULT, &func, &edata);
    H5Eset_auto2(H5E_DEFAULT, NULL, NULL);

    /* Initialize h5tools lib */
    h5tools_init();

    /* parse command line options */
    parse_command_line(argc, argv);

    if(argc <= opt_ind) {
        error_msg("missing dataset name\n");
	usage(h5tools_getprogname());
        leave(EXIT_FAILURE);
    }

    /* Mostly copied from tools/h5ls coding & modified accordingly */
    /* 
     * [OBJECT] is specified as 
     *		[<filename>/<path_to_dataset>/<dsetname>]
     *
     * Example: ../dir1/foo/bar/dset
     *          \_________/\______/
     *             file       obj
     *
     * The dichotomy is determined by calling H5Fopen() repeatedly until it
     * succeeds. The first call uses the entire name and each subsequent call
     * chops off the last component. If we reach the beginning of the name
     * then there must have been something wrong with the file (perhaps it
     * doesn't exist). 
     */
    if((fname = HDstrdup(argv[opt_ind])) == NULL) {
	error_msg("memory allocation failed (file %s:line %d)\n",
                  __FILE__, __LINE__);
	h5tools_setstatus(EXIT_FAILURE);
    }

    /* Create a copy of file access property list */
    if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
        return -1;

    /* Set to use the latest library format */
    if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
        return -1;

    do {
	while(fname && *fname) {
	    fid = h5tools_fopen(fname, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl, NULL, drivername, sizeof drivername);

	    if(fid >= 0) {
		HDfprintf(stdout, "Opened \"%s\" with %s driver.\n", fname, drivername);
		break; /*success*/
	    } /* end if */

	    /* Shorten the file name; lengthen the object name */
	    x = dname;
	    dname = HDstrrchr(fname, '/');
	    if(x)
		*x = '/';
	    if(!dname)
		break;
	    *dname = '\0';
	} /* end while */
    /* Try opening the file again if somehow unstable */
    } while(g_retry-- > 0 && fid == FAIL);

    if(fid < 0) {
	error_msg("unable to open file \"%s\"\n", fname);
	if(fname) HDfree(fname);
	if(fapl >= 0) H5Pclose(fapl);
	leave(EXIT_FAILURE);
    } 

    if(!dname) {
	error_msg("no dataset specified\n");
	h5tools_setstatus(EXIT_FAILURE);
    } else {
	*dname = '/';
	x = dname;
	if((dname = HDstrdup(dname)) == NULL) {
	    error_msg("memory allocation failed (file %s:line %d)\n",
                      __FILE__, __LINE__);
	    h5tools_setstatus(EXIT_FAILURE);
	} else {
	    *x = '\0';
	    /* Validate dataset */
	    if(check_dataset(fid, dname) < 0)
		h5tools_setstatus(EXIT_FAILURE);
	    /* Validate input "fields" */
	    else if(g_list_of_fields && *g_list_of_fields)
		if(process_cmpd_fields(fid, dname) < 0)
		    h5tools_setstatus(EXIT_FAILURE);
	}
    } 

    /* If everything is fine, start monitoring the datset */
    if(h5tools_getstatus() != EXIT_FAILURE)
	if(monitor_dataset(fid, dname) < 0)
	    h5tools_setstatus(EXIT_FAILURE);
     	    
    /* Free spaces */
    if(fname) HDfree(fname);
    if(dname) HDfree(dname);
    if(g_list_of_fields) HDfree(g_list_of_fields);
    if(g_listv) {
	H5LD_clean_vector(g_listv);
	HDfree(g_listv);
    }
    if(g_dup_fields) HDfree(g_dup_fields);

    /* Close the file access property list */
    if(fapl >= 0 && H5Pclose(fapl) < 0) {
	error_msg("unable to close file access property list\n");
	h5tools_setstatus(EXIT_FAILURE);
    }

    /* Close the file */
    if(H5Fclose(fid) < 0) {
	error_msg("unable to close file\n");
	h5tools_setstatus(EXIT_FAILURE);
    }

    H5Eset_auto2(H5E_DEFAULT, func, edata);
    /* exit */
    leave(h5tools_getstatus());
} /* main() */
示例#9
0
文件: h5watch.c 项目: FilipeMaia/hdf5
/*-------------------------------------------------------------------------
 * Function:    check_dataset
 *
 * Purpose:     To check whether a dataset can be monitored:
 		  A chunked dataset with unlimited or max. dimension setting
 *
 * Return:      Non-negative on success: dataset can be monitored
 *		Negative on failure: dataset cannot be monitored
 *
 * Programmer:  Vailin Choi; August 2010
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static herr_t
check_dataset(hid_t fid, char *dsetname)
{
    hid_t did=-1;	/* Dataset id */
    hid_t dcp=-1;	/* Dataset creation property */
    hid_t sid=-1;	/* Dataset's dataspace id */
    int	  ndims;	/* # of dimensions in the dataspace */
    unsigned u;		/* Local index variable */
    hsize_t cur_dims[H5S_MAX_RANK];	/* size of dataspace dimensions */
    hsize_t max_dims[H5S_MAX_RANK];	/* maximum size of dataspace dimensions */
    hbool_t unlim_max_dims = FALSE;	/* whether dataset has unlimited or max. dimension setting */
    void               *edata;
    H5E_auto2_t         func;
    herr_t ret_value = SUCCEED;	/* Return value */

    /* Disable error reporting */
    H5Eget_auto2(H5E_DEFAULT, &func, &edata);
    H5Eset_auto2(H5E_DEFAULT, NULL, NULL);

    /* Open the dataset */
    if((did = H5Dopen2(fid, dsetname, H5P_DEFAULT)) < 0) {
	error_msg("unable to open dataset \"%s\"\n", dsetname);
	ret_value = FAIL;
	goto done;
    }

    /* Get dataset's creation property list */
    if((dcp = H5Dget_create_plist(did)) < 0) {
	error_msg("unable to get dataset's creation property list\"%s\"\n", dsetname);
	ret_value = FAIL;
	goto done;
    }

    /* Query dataset's layout; the layout should be chunked */
    if(H5Pget_layout(dcp) != H5D_CHUNKED) {
	error_msg("\"%s\" should be a chunked dataset\n", dsetname);
	ret_value = FAIL;
	goto done;
    }

    HDmemset(cur_dims, 0, sizeof cur_dims);
    HDmemset(max_dims, 0, sizeof max_dims);

    /* Get dataset's dataspace */
    if((sid = H5Dget_space(did)) < 0) {
	error_msg("can't get dataset's dataspace\"%s\"\n", dsetname);
	ret_value = FAIL;
	goto done;
    }

    /* Get dimension size of dataset's dataspace */
    if((ndims = H5Sget_simple_extent_dims(sid, cur_dims, max_dims)) < 0) {
	error_msg("can't get dataspace dimensions for dataset \"%s\"\n", dsetname);
	ret_value = FAIL;
	goto done;
    }

    /* Check whether dataset has unlimited dimension or max. dimension setting */
    for(u = 0; u < (unsigned)ndims; u++)
	if(max_dims[u] == H5S_UNLIMITED || cur_dims[u] != max_dims[u]) {
    	    unlim_max_dims = TRUE;
	    break;
	}

    if(!unlim_max_dims) {
	error_msg("\"%s\" should have unlimited or max. dimension setting\n", dsetname);
	ret_value = FAIL;
    }

done: 
    H5Eset_auto2(H5E_DEFAULT, func, edata);

    /* Closing */
    H5E_BEGIN_TRY
	H5Sclose(sid);
	H5Pclose(dcp);
	H5Dclose(did);
    H5E_END_TRY

    return(ret_value);
} /* check_dataset() */
示例#10
0
/*-------------------------------------------------------------------------
 * Function:    main
 *
 * Usage:       debug FILENAME [OFFSET]
 *
 * Return:      Success:        exit (0)
 *
 *              Failure:        exit (non-zero)
 *
 * Programmer:  Robb Matzke
 *              [email protected]
 *              Jul 18 1997
 *
 *-------------------------------------------------------------------------
 */
int
main(int argc, char *argv[])
{
    hid_t  fid, fapl, dxpl;
    H5F_t       *f;
    haddr_t     addr = 0, extra = 0, extra2 = 0, extra3 = 0, extra4 = 0;
    uint8_t     sig[H5F_SIGNATURE_LEN];
    size_t      u;
    H5E_auto2_t func;
    void 	*edata;
    herr_t      status = SUCCEED;

    if(argc == 1) {
  	HDfprintf(stderr, "Usage: %s filename [signature-addr [extra]]\n", argv[0]);
  	HDexit(1);
    } /* end if */

    /* Initialize the library */
    if(H5open() < 0) {
        HDfprintf(stderr, "cannot initialize the library\n");
        HDexit(1);
    } /* end if */

    /* Disable error reporting */
    H5Eget_auto2(H5E_DEFAULT, &func, &edata);
    H5Eset_auto2(H5E_DEFAULT, NULL, NULL);

    /*
     * Open the file and get the file descriptor.
     */
    dxpl = H5AC_ind_read_dxpl_id;
    if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) {
        HDfprintf(stderr, "cannot create file access property list\n");
        HDexit(1);
    } /* end if */
    if(HDstrchr(argv[1], '%'))
        if(H5Pset_fapl_family (fapl, (hsize_t)0, H5P_DEFAULT) < 0) {
            fprintf(stderr, "cannot set file access property list\n");
            HDexit(1);
        }
    if((fid = H5Fopen(argv[1], H5F_ACC_RDONLY, fapl)) < 0) {
        HDfprintf(stderr, "cannot open file\n");
        HDexit(1);
    } /* end if */
    if(NULL == (f = (H5F_t *)H5I_object(fid))) {
        HDfprintf(stderr, "cannot obtain H5F_t pointer\n");
        HDexit(2);
    } /* end if */

    /* Ignore metadata tags while using h5debug */
    if(H5AC_ignore_tags(f) < 0) {
        HDfprintf(stderr, "cannot ignore metadata tags\n");
        HDexit(1);
    }

    /*
     * Parse command arguments.
     */
    if(argc > 2)
        addr = (haddr_t)HDstrtoll(argv[2], NULL, 0);
    if(argc > 3)
        extra = (haddr_t)HDstrtoll(argv[3], NULL, 0);
    if(argc > 4)
        extra2 = (haddr_t)HDstrtoll(argv[4], NULL, 0);
    if(argc > 5)
        extra3 = (haddr_t)HDstrtoll(argv[5], NULL, 0);
    if(argc > 6)
        extra4 = (haddr_t)HDstrtoll(argv[6], NULL, 0);

    /*
     * Read the signature at the specified file position.
     */
    HDfprintf(stdout, "Reading signature at address %a (rel)\n", addr);
    if(H5F_block_read(f, H5FD_MEM_SUPER, addr, sizeof(sig), dxpl, sig) < 0) {
        HDfprintf(stderr, "cannot read signature\n");
        HDexit(3);
    }
    if(!HDmemcmp(sig, H5F_SIGNATURE, (size_t)H5F_SIGNATURE_LEN)) {
        /*
         * Debug the file's super block.
         */
        status = H5F_debug(f, stdout, 0, VCOL);

    } else if(!HDmemcmp(sig, H5HL_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
        /*
         * Debug a local heap.
         */
        status = H5HL_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL);

    } else if(!HDmemcmp (sig, H5HG_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
	/*
	 * Debug a global heap collection.
	 */
	status = H5HG_debug (f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL);

    } else if(!HDmemcmp(sig, H5G_NODE_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
        /*
         * Debug a symbol table node.
         */

        /* Check for extra parameters */
        if(extra == 0) {
            HDfprintf(stderr, "\nWarning: Providing the group's local heap address will give more information\n");
            HDfprintf(stderr, "Symbol table node usage:\n");
            HDfprintf(stderr, "\th5debug <filename> <Symbol table node address> <address of local heap>\n\n");
        } /* end if */

        status = H5G_node_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, extra);

    } else if(!HDmemcmp(sig, H5B_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
        /*
         * Debug a B-tree.  B-trees are debugged through the B-tree
         * subclass.  The subclass identifier is the byte immediately
         * after the B-tree signature.
         */
        H5B_subid_t subtype = (H5B_subid_t)sig[H5_SIZEOF_MAGIC];
        unsigned    ndims;
        uint32_t    dim[H5O_LAYOUT_NDIMS];

        switch(subtype) {
            case H5B_SNODE_ID:
                /* Check for extra parameters */
                if(extra == 0) {
                    HDfprintf(stderr, "\nWarning: Providing the group's local heap address will give more information\n");
                    HDfprintf(stderr, "B-tree symbol table node usage:\n");
                    HDfprintf(stderr, "\th5debug <filename> <B-tree node address> <address of local heap>\n\n");
                    HDexit(4);
                } /* end if */

                status = H5G_node_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, extra);
                break;

            case H5B_CHUNK_ID:
                /* Check for extra parameters */
                if(extra == 0) {
                    HDfprintf(stderr, "ERROR: Need number of dimensions of chunk in order to dump chunk B-tree node\n");
                    HDfprintf(stderr, "B-tree chunked storage node usage:\n");
                    HDfprintf(stderr, "\th5debug <filename> <B-tree node address> <# of dimensions> <slowest chunk dim>...<fastest chunk dim>\n");
                    HDexit(4);
                } /* end if */

                /* Build array of chunk dimensions */
                ndims = (unsigned)extra;
                dim[0] = (uint32_t)extra2;
                if(ndims > 1)
                    dim[1] = (uint32_t)extra3;
                if(ndims > 2)
                    dim[2] = (uint32_t)extra4;

                /* Check for dimension error */
                if(ndims > 3) {
                    HDfprintf(stderr, "ERROR: Only 3 dimensions support currently (fix h5debug)\n");
                    HDfprintf(stderr, "B-tree chunked storage node usage:\n");
                    HDfprintf(stderr, "\th5debug <filename> <B-tree node address> <# of dimensions> <slowest chunk dim>...<fastest chunk dim>\n");
                    HDexit(4);
                } /* end for */
                for(u = 0; u < ndims; u++)
                    if(0 == dim[u]) {
                        HDfprintf(stderr, "ERROR: Chunk dimensions should be >0\n");
                        HDfprintf(stderr, "B-tree chunked storage node usage:\n");
                        HDfprintf(stderr, "\th5debug <filename> <B-tree node address> <# of dimensions> <slowest chunk dim>...<fastest chunk dim>\n");
                        HDexit(4);
                    } /* end if */

                /* Set the last dimension (the element size) to zero */
                dim[ndims] = 0;

                status = H5D_btree_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, ndims, dim);
                break;

            case H5B_NUM_BTREE_ID:
            default:
                HDfprintf(stderr, "Unknown v1 B-tree subtype %u\n", (unsigned)(subtype));
                HDexit(4);
        }

    } else if(!HDmemcmp(sig, H5B2_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
        /*
         * Debug a v2 B-tree header.
         */
        const H5B2_class_t *cls = get_H5B2_class(sig);
        HDassert(cls);

	    if((cls == H5D_BT2 || cls == H5D_BT2_FILT) && extra == 0) {
            HDfprintf(stderr, "ERROR: Need v2 B-tree header address and object header address containing the layout message in order to dump header\n");
            HDfprintf(stderr, "v2 B-tree hdr usage:\n");
            HDfprintf(stderr, "\th5debug <filename> <v2 B-tree header address> <object header address>\n");
            HDexit(4);
	    } /* end if */

        status = H5B2__hdr_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, cls, (haddr_t)extra);

    } else if(!HDmemcmp(sig, H5B2_INT_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
        /*
         * Debug a v2 B-tree internal node.
         */
        const H5B2_class_t *cls = get_H5B2_class(sig);
        HDassert(cls);

        /* Check for enough valid parameters */
	if((cls == H5D_BT2 || cls == H5D_BT2_FILT) &&
	   (extra == 0 || extra2 == 0 || extra3 == 0 || extra4 == 0)) {

            fprintf(stderr, "ERROR: Need v2 B-tree header address, the node's number of records, depth, and object header address containing the layout message in order to dump internal node\n");
            fprintf(stderr, "NOTE: Leaf nodes are depth 0, the internal nodes above them are depth 1, etc.\n");
            fprintf(stderr, "v2 B-tree internal node usage:\n");
            fprintf(stderr, "\th5debug <filename> <internal node address> <v2 B-tree header address> <number of records> <depth> <object header address>\n");
            HDexit(4);

        } else if(extra == 0 || extra2 == 0 || extra3 == 0) {
            HDfprintf(stderr, "ERROR: Need v2 B-tree header address and the node's number of records and depth in order to dump internal node\n");
            HDfprintf(stderr, "NOTE: Leaf nodes are depth 0, the internal nodes above them are depth 1, etc.\n");
            HDfprintf(stderr, "v2 B-tree internal node usage:\n");
            HDfprintf(stderr, "\th5debug <filename> <internal node address> <v2 B-tree header address> <number of records> <depth>\n");
            HDexit(4);
        } /* end if */

        status = H5B2__int_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, cls, extra, (unsigned)extra2, (unsigned)extra3, (haddr_t)extra4);

    } else if(!HDmemcmp(sig, H5B2_LEAF_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
        /*
         * Debug a v2 B-tree leaf node.
         */
        const H5B2_class_t *cls = get_H5B2_class(sig);
        HDassert(cls);

        /* Check for enough valid parameters */
	if((cls == H5D_BT2 || cls == H5D_BT2_FILT) &&
	   (extra == 0 || extra2 == 0 || extra3 == 0 )) {

            fprintf(stderr, "ERROR: Need v2 B-tree header address, number of records, and object header address containing the layout message in order to dump leaf node\n");
            fprintf(stderr, "v2 B-tree leaf node usage:\n");
            fprintf(stderr, "\th5debug <filename> <leaf node address> <v2 B-tree header address> <number of records> <object header address>\n");
            HDexit(4);

        } else if(extra == 0 || extra2 == 0) {
            HDfprintf(stderr, "ERROR: Need v2 B-tree header address and number of records in order to dump leaf node\n");
            HDfprintf(stderr, "v2 B-tree leaf node usage:\n");
            HDfprintf(stderr, "\th5debug <filename> <leaf node address> <v2 B-tree header address> <number of records>\n");
            HDexit(4);
        } /* end if */

        status = H5B2__leaf_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, cls, extra, (unsigned)extra2, (haddr_t)extra3);

    } else if(!HDmemcmp(sig, H5HF_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
        /*
         * Debug a fractal heap header.
         */
        status = H5HF_hdr_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL);

    } else if(!HDmemcmp(sig, H5HF_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
        /*
         * Debug a fractal heap direct block.
         */

        /* Check for enough valid parameters */
        if(extra == 0 || extra2 == 0) {
            HDfprintf(stderr, "ERROR: Need fractal heap header address and size of direct block in order to dump direct block\n");
            HDfprintf(stderr, "Fractal heap direct block usage:\n");
            HDfprintf(stderr, "\th5debug <filename> <direct block address> <heap header address> <size of direct block>\n");
            HDexit(4);
        } /* end if */

        status = H5HF_dblock_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, extra, (size_t)extra2);

    } else if(!HDmemcmp(sig, H5HF_IBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
        /*
         * Debug a fractal heap indirect block.
         */

        /* Check for enough valid parameters */
        if(extra == 0 || extra2 == 0) {
            HDfprintf(stderr, "ERROR: Need fractal heap header address and number of rows in order to dump indirect block\n");
            HDfprintf(stderr, "Fractal heap indirect block usage:\n");
            HDfprintf(stderr, "\th5debug <filename> <indirect block address> <heap header address> <number of rows>\n");
            HDexit(4);
        } /* end if */

        status = H5HF_iblock_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, extra, (unsigned)extra2);

    } else if(!HDmemcmp(sig, H5FS_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
        /*
         * Debug a free space header.
         */

        status = H5FS_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL);

    } else if(!HDmemcmp(sig, H5FS_SINFO_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
        /*
         * Debug free space serialized sections.
         */

        /* Check for enough valid parameters */
        if(extra == 0 || extra2 == 0) {
            HDfprintf(stderr, "ERROR: Need free space header address and client address in order to dump serialized sections\n");
            HDfprintf(stderr, "Free space serialized sections usage:\n");
            HDfprintf(stderr, "\th5debug <filename> <serialized sections address> <free space header address> <client address>\n");
            HDexit(4);
        } /* end if */

        status = H5FS_sects_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, extra, extra2);

    } else if(!HDmemcmp(sig, H5SM_TABLE_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
        /*
         * Debug shared message master table.
         */

        status = H5SM_table_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, (unsigned) UFAIL, (unsigned) UFAIL);

    } else if(!HDmemcmp(sig, H5SM_LIST_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
        /*
         * Debug shared message list index.
         */

        /* Check for enough valid parameters */
        if(extra == 0) {
            HDfprintf(stderr, "ERROR: Need shared message header address in order to shared message list\n");
            HDfprintf(stderr, "Shared message list usage:\n");
            HDfprintf(stderr, "\th5debug <filename> <shared message list address> <shared message header address>\n");
            HDexit(4);
        } /* end if */

        status = H5SM_list_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, (haddr_t)extra);

    } else if(!HDmemcmp(sig, H5EA_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
        /*
         * Debug an extensible aray header.
         */
        const H5EA_class_t *cls = get_H5EA_class(sig);
        HDassert(cls);

        /* Check for enough valid parameters */
        if(extra == 0) {
            HDfprintf(stderr, "ERROR: Need object header address containing the layout message in order to dump header\n");
            HDfprintf(stderr, "Extensible array header block usage:\n");
            HDfprintf(stderr, "\th5debug <filename> <Extensible Array header address> <object header address>\n");
            HDexit(4);
        } /* end if */

        status = H5EA__hdr_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, cls, extra);

    } else if(!HDmemcmp(sig, H5EA_IBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
        /*
         * Debug an extensible aray index block.
         */
        const H5EA_class_t *cls = get_H5EA_class(sig);
        HDassert(cls);

        /* Check for enough valid parameters */
        if(extra == 0 || extra2 == 0) {
            HDfprintf(stderr, "ERROR: Need extensible array header address and object header address containing the layout message in order to dump index block\n");
            HDfprintf(stderr, "Extensible array index block usage:\n");
            HDfprintf(stderr, "\th5debug <filename> <index block address> <array header address> <object header address\n");
            HDexit(4);
        } /* end if */

        status = H5EA__iblock_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, cls, extra, extra2);

    } else if(!HDmemcmp(sig, H5EA_SBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
        /*
         * Debug an extensible aray super block.
         */
        const H5EA_class_t *cls = get_H5EA_class(sig);
        HDassert(cls);

        /* Check for enough valid parameters */
        if(extra == 0 || extra2 == 0 || extra3 == 0) {
            HDfprintf(stderr, "ERROR: Need extensible array header address, super block index and object header address containing the layout message in order to dump super block\n");
            HDfprintf(stderr, "Extensible array super block usage:\n");
            HDfprintf(stderr, "\th5debug <filename> <super block address> <array header address> <super block index> <object header address>\n");
            HDexit(4);
        } /* end if */

        status = H5EA__sblock_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, cls, extra, (unsigned)extra2, extra3);

    } else if(!HDmemcmp(sig, H5EA_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
        /*
         * Debug an extensible aray data block.
         */
        const H5EA_class_t *cls = get_H5EA_class(sig);
        HDassert(cls);

        /* Check for enough valid parameters */
        if(extra == 0 || extra2 == 0 || extra3 == 0) {
            HDfprintf(stderr, "ERROR: Need extensible array header address, # of elements in data block and object header address containing the layout message in order to dump data block\n");
            HDfprintf(stderr, "Extensible array data block usage:\n");
            HDfprintf(stderr, "\th5debug <filename> <data block address> <array header address> <# of elements in data block> <object header address\n");
            HDexit(4);
        } /* end if */

        status = H5EA__dblock_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, cls, extra, (size_t)extra2, extra3);

    } else if(!HDmemcmp(sig, H5FA_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
        /*
         * Debug a fixed array header.
         */
        const H5FA_class_t *cls = get_H5FA_class(sig);
        HDassert(cls);

        /* Check for enough valid parameters */
        if(extra == 0) {
            HDfprintf(stderr, "ERROR: Need object header address containing the layout message in order to dump header\n");
            HDfprintf(stderr, "Fixed array header block usage:\n");
            HDfprintf(stderr, "\th5debug <filename> <Fixed Array header address> <object header address>\n");
            HDexit(4);
        } /* end if */

        status = H5FA__hdr_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, cls, extra);

    } else if(!HDmemcmp(sig, H5FA_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
        /*
         * Debug a fixed array data block.
         */
        const H5FA_class_t *cls = get_H5FA_class(sig);
        HDassert(cls);

        /* Check for enough valid parameters */
        if(extra == 0 || extra2 == 0) {
            HDfprintf(stderr, "ERROR: Need fixed array header address and object header address containing the layout message in order to dump data block\n");
            HDfprintf(stderr, "fixed array data block usage:\n");
            HDfprintf(stderr, "\th5debug <filename> <data block address> <array header address> <object header address>\n");
            HDexit(4);
        } /* end if */

        status = H5FA__dblock_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL, cls, extra, extra2);

    } else if(!HDmemcmp(sig, H5O_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) {
        /*
         * Debug v2 object header (which have signatures).
         */

        status = H5O_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL);

    } else if(sig[0] == H5O_VERSION_1) {
        /*
         * This could be a v1 object header.  Since they don't have a signature
         * it's a somewhat "ify" detection.
         */
        status = H5O_debug(f, H5AC_ind_read_dxpl_id, addr, stdout, 0, VCOL);

    } else {
        /*
         * Got some other unrecognized signature.
         */
        printf("%-*s ", VCOL, "Signature:");
        for (u = 0; u < sizeof(sig); u++) {
            if (sig[u] > ' ' && sig[u] <= '~' && '\\' != sig[u])
                HDputchar(sig[u]);
            else if ('\\' == sig[u]) {
                HDputchar('\\');
                HDputchar('\\');
            } else
                printf("\\%03o", sig[u]);
        }
        HDputchar('\n');

        HDfprintf(stderr, "unknown signature\n");
        HDexit(4);
    } /* end else */

    /* Check for an error when dumping information */
    if(status < 0) {
        HDfprintf(stderr, "An error occurred!\n");
        H5Eprint2(H5E_DEFAULT, stderr);
        HDexit(5);
    } /* end if */

    H5Pclose(fapl);
    H5Fclose(fid);

    H5Eset_auto2(H5E_DEFAULT, func, edata);

    return 0;
} /* main() */
示例#11
0
文件: basic.c 项目: RhysU/ESIO
FCT_BGN()
{
    int preserve = 0;

    // MPI setup: MPI_Init and atexit(MPI_Finalize)
    int world_size, world_rank;
    MPI_Init(&argc, &argv);
    atexit((void (*) ()) MPI_Finalize);
    MPI_Comm_size(MPI_COMM_WORLD, &world_size);
    MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);

    // Install the command line options defined above.
    fctcl_install(my_cl_options);

    // Retrieve options
    preserve = fctcl_is("--preserve");

    // Obtain default HDF5 error handler
    H5E_auto2_t hdf5_handler;
    void *hdf5_client_data;
    H5Eget_auto2(H5E_DEFAULT, &hdf5_handler, &hdf5_client_data);

    // Obtain default ESIO error handler
    esio_error_handler_t * const esio_handler = esio_set_error_handler_off();
    esio_set_error_handler(esio_handler);

    // Fixture-related details
    const char * const input_dir  = getenv("ESIO_TEST_INPUT_DIR");
    const char * const output_dir = getenv("ESIO_TEST_OUTPUT_DIR");
    char * filetemplate = create_testfiletemplate(output_dir, __FILE__);
    char * filename = NULL;
    esio_handle handle = NULL;

    FCT_FIXTURE_SUITE_BGN(esio_file)
    {
        FCT_SETUP_BGN()
        {
            ESIO_MPICHKQ(MPI_Barrier(MPI_COMM_WORLD)); // Synchronize

            // Restore HDF5/ESIO default error handling
            H5Eset_auto2(H5E_DEFAULT, hdf5_handler, hdf5_client_data);
            esio_set_error_handler(esio_handler);

            // Rank 0 generates a unique filename and broadcasts it
            int filenamelen;
            if (world_rank == 0) {
                filename = create_testfilename(filetemplate);
                if (preserve) {
                    printf("\nfilename: %s\n", filename);
                }
                filenamelen = strlen(filename);
            }
            ESIO_MPICHKR(MPI_Bcast(&filenamelen, 1, MPI_INT,
                                   0, MPI_COMM_WORLD));
            if (world_rank > 0) {
                filename = calloc(filenamelen + 1, sizeof(char));
            }
            ESIO_MPICHKR(MPI_Bcast(filename, filenamelen, MPI_CHAR,
                                    0, MPI_COMM_WORLD));
            fct_req(filename);

            // Initialize ESIO handle
            handle = esio_handle_initialize(MPI_COMM_WORLD);
            fct_req(handle);

            // Check that the handle correctly reports world_size
            int size;
            fct_req(ESIO_SUCCESS == esio_handle_comm_size(handle, &size));
            fct_chk_eq_int(world_size, size);

            // Check that the handle correctly reports world_rank
            int rank;
            fct_req(ESIO_SUCCESS == esio_handle_comm_rank(handle, &rank));
            fct_chk_eq_int(world_rank, rank);
        }
        FCT_SETUP_END();

        FCT_TEARDOWN_BGN()
        {
            // Finalize ESIO handle
            esio_handle_finalize(handle);

            // Clean up the unique file and filename
            if (world_rank == 0) {
                if (!preserve) unlink(filename);
            }
            free(filename);
        }
        FCT_TEARDOWN_END();

        FCT_TEST_BGN(success_code)
        {
            fct_chk_eq_int(0, ESIO_SUCCESS); // Success is zero
            fct_chk(!ESIO_SUCCESS);          // Not success is true
        }
        FCT_TEST_END();

        FCT_TEST_BGN(file_create_and_open)
        {
            // No open file so esio_file_path is empty
            fct_req(NULL == esio_file_path(handle));

            // Create with overwrite should always work
            fct_req(0 == esio_file_create(handle, filename, 1 /* o/w */));

            // Flush flush flush should always work
            fct_req(0 == esio_file_flush(handle));
            fct_req(0 == esio_file_flush(handle));
            fct_req(0 == esio_file_flush(handle));

            // Check that esio_file_path points to a valid canonical location
            struct stat statbuf;
            char *file_path = esio_file_path(handle);
            fct_req(file_path != NULL);
            fct_chk_startswith_str(file_path, "/"); // Absolute?
            fct_req(0 == stat(file_path, &statbuf));
            free(file_path);

            // Close the file
            fct_req(0 == esio_file_close(handle));

            // Double closure should silently succeed
            fct_req(0 == esio_file_close(handle));

            // No open file so esio_file_path is empty
            fct_req(NULL == esio_file_path(handle));

            // Create without overwrite should fail
            H5Eset_auto2(H5E_DEFAULT, NULL, NULL);
            esio_set_error_handler_off();
            fct_req(0 != esio_file_create(handle, filename, 0 /* no o/w */));
            esio_set_error_handler(esio_handler);
            H5Eset_auto2(H5E_DEFAULT, hdf5_handler, hdf5_client_data);

            // Remove the file and create without overwrite should succeed
            ESIO_MPICHKQ(MPI_Barrier(MPI_COMM_WORLD)); // Synchronize
            if (world_rank == 0) {
                fct_req(0 == unlink(filename));
            }
            ESIO_MPICHKQ(MPI_Barrier(MPI_COMM_WORLD)); // Synchronize
            fct_req(0 == esio_file_create(handle, filename, 0 /* no o/w */));

            // Close the file
            fct_req(0 == esio_file_close(handle));

            // Ensure we can open in read-only mode
            fct_req(0 == esio_file_open(handle, filename, 0 /* read-only */));

            // Close the file
            fct_req(0 == esio_file_close(handle));

            // Ensure we can open in read-write mode
            fct_req(0 == esio_file_open(handle, filename, 1 /* read-write */));

            // Close the file
            fct_req(0 == esio_file_close(handle));
        }
        FCT_TEST_END();

        FCT_TEST_BGN(file_clone)
        {
            // Dynamically create the empty.h5 source filename per input_dir
            if (input_dir == NULL && world_rank == 0) {
                fprintf(stderr, "\nESIO_TEST_INPUT_DIR not in environment!\n");
            }
            fct_req(NULL != input_dir /* check ESIO_TEST_INPUT_DIR set */);
            int srcfilelen = strlen(input_dir);
            fct_req(srcfilelen > 0);
            srcfilelen += strlen("/empty.h5");
            srcfilelen += 1;
            char * srcfile = calloc(srcfilelen, 1);
            fct_req(NULL != srcfile);
            fct_req(NULL != strcat(srcfile, input_dir));
            fct_req(NULL != strcat(srcfile, "/empty.h5"));

            // Clone with overwrite should always work
            fct_req(0 == esio_file_clone(handle, srcfile, filename, 1));

            // Close the file
            fct_req(0 == esio_file_close(handle));

            // Create without overwrite should fail
            H5Eset_auto2(H5E_DEFAULT, NULL, NULL);
            esio_set_error_handler_off();
            fct_req(0 != esio_file_clone(handle, srcfile, filename, 0));
            esio_set_error_handler(esio_handler);
            H5Eset_auto2(H5E_DEFAULT, hdf5_handler, hdf5_client_data);

            // Remove the file and create without overwrite should succeed
            ESIO_MPICHKQ(MPI_Barrier(MPI_COMM_WORLD)); // Synchronize
            if (world_rank == 0) {
                fct_req(0 == unlink(filename));
            }
            ESIO_MPICHKQ(MPI_Barrier(MPI_COMM_WORLD)); // Synchronize
            fct_req(0 == esio_file_clone(handle, srcfile, filename, 0));

            // Close the file
            fct_req(0 == esio_file_close(handle));

            // Deallocate the srcfile name
            free(srcfile);
        }
        FCT_TEST_END();

        // Much of this functionality is covered in restart_helpers.c
        // and restart_rename.{sh,c}.  This covers only the public API's
        // most basic usage.
        FCT_TEST_BGN(file_close_restart)
        {
            struct stat statbuf;

            // Form template and expected file paths from temporary filename
            char *template = malloc(strlen(filename) + 2);
            fct_req(template);
示例#12
0
 inline SilenceHDF5()
     : _client_data(0)
 {
     H5Eget_auto2(H5E_DEFAULT, &_func, &_client_data);
     H5Eset_auto2(H5E_DEFAULT, 0, 0);
 }
示例#13
0
FCT_BGN()
{
    int preserve = 0;

    // MPI setup: MPI_Init and atexit(MPI_Finalize)
    int world_size, world_rank;
    MPI_Init(&argc, &argv);
    atexit((void (*) ()) MPI_Finalize);
    MPI_Comm_size(MPI_COMM_WORLD, &world_size);
    MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);

    // Install the command line options defined above.
    fctcl_install(my_cl_options);

    // Retrieve and sanity check problem size options
    preserve = fctcl_is("--preserve");
    const int ncomponents = (int) strtol(
        fctcl_val2("--ncomponents","2"), (char **) NULL, 10);
    if (ncomponents < 1) {
        fprintf(stderr, "\n--ncomponents=%d < 1\n", ncomponents);
        MPI_Abort(MPI_COMM_WORLD, 1);
    }

    // Obtain default HDF5 error handler
    H5E_auto2_t hdf5_handler;
    void *hdf5_client_data;
    H5Eget_auto2(H5E_DEFAULT, &hdf5_handler, &hdf5_client_data);

    // Obtain default ESIO error handler
    esio_error_handler_t * const esio_handler = esio_set_error_handler_off();
    esio_set_error_handler(esio_handler);

    // Fixture-related details
    const char * const input_dir  = getenv("ESIO_TEST_INPUT_DIR");
    const char * const output_dir = getenv("ESIO_TEST_OUTPUT_DIR");
    char * filetemplate = create_testfiletemplate(output_dir, __FILE__);
    (void) input_dir;  // Possibly unused
    char * filename = NULL;
    esio_handle state = NULL;

    FCT_FIXTURE_SUITE_BGN(attribute_suite)
    {
        FCT_SETUP_BGN()
        {
            ESIO_MPICHKQ(MPI_Barrier(MPI_COMM_WORLD)); // Synchronize

            // Restore HDF5/ESIO default error handling
            H5Eset_auto2(H5E_DEFAULT, hdf5_handler, hdf5_client_data);
            esio_set_error_handler(esio_handler);

            // Rank 0 generates a unique filename and broadcasts it
            int filenamelen;
            if (world_rank == 0) {
                filename = create_testfilename(filetemplate);
                if (preserve) {
                    printf("\nfilename: %s\n", filename);
                }
                filenamelen = strlen(filename);
            }
            ESIO_MPICHKR(MPI_Bcast(&filenamelen, 1, MPI_INT,
                                   0, MPI_COMM_WORLD));
            if (world_rank > 0) {
                filename = calloc(filenamelen + 1, sizeof(char));
            }
            ESIO_MPICHKR(MPI_Bcast(filename, filenamelen, MPI_CHAR,
                                    0, MPI_COMM_WORLD));
            fct_req(filename);

            // Initialize ESIO state
            state = esio_handle_initialize(MPI_COMM_WORLD);
            fct_req(state);
        }
        FCT_SETUP_END();

        FCT_TEARDOWN_BGN()
        {
            // Finalize ESIO state
            esio_handle_finalize(state);

            // Clean up the unique file and filename
            if (world_rank == 0) {
                if (!preserve) unlink(filename);
            }
            free(filename);
        }
        FCT_TEARDOWN_END();

        // Test scalar-valued attributes, including overwrite details
        FCT_TEST_BGN(attribute)
        {
            TYPE value;

            // Open file
            fct_req(0 == esio_file_create(state, filename, 1));

            // Write zero to disk and flush the buffers
            value = 0;
            fct_req(0 == AFFIX(esio_attribute_write)(
                        state, "/", "attribute", &value));
            fct_req(0 == esio_file_flush(state));

            // Populate value with non-zero data
            // TODO Vary this based on the rank?
            value = 5678;

            // Overwrite zeros on disk with test data
            fct_req(0 == AFFIX(esio_attribute_write)(
                        state, "/", "attribute", &value));

            // Clear storage in memory
            value = 0;

            { // Ensure we can retrieve the size correctly
                int count;
                fct_req(0 == esio_attribute_sizev(
                            state, "/", "attribute", &count));
                fct_chk_eq_int(count, 1);
            }

            // Close the file
            fct_req(0 == esio_file_close(state));

            // Reopen the file using normal HDF5 APIs on root processor
            // Ensure we can retrieve the data by other means
            if (world_rank == 0) {
                TYPE data;
                const hid_t file_id
                    = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);
                fct_req(0 <= AFFIX(H5LTget_attribute)(file_id, "/",
                                                      "attribute",
                                                      &data));

#ifdef __INTEL_COMPILER
#pragma warning(push,disable:1572)
#endif
                fct_chk(data == 5678);
#ifdef __INTEL_COMPILER
#pragma warning(pop)
#endif

                fct_req(0 <= H5Fclose(file_id));
            }

            // Re-read the file in a distributed manner and verify contents
            fct_req(0 == esio_file_open(state, filename, 0));
            fct_req(0 == AFFIX(esio_attribute_read)(
                        state, "/", "attribute", &value));
#ifdef __INTEL_COMPILER
#pragma warning(push,disable:1572)
#endif
            fct_chk(value == 5678);
#ifdef __INTEL_COMPILER
#pragma warning(pop)
#endif

            // Check that non-existent attribute yields quiet ESIO_NOTFOUND
            fct_chk(ESIO_NOTFOUND == esio_attribute_sizev(
                        state, "/", "nonexistent", NULL));

            fct_req(0 == esio_file_close(state));
        }
        FCT_TEST_END();

        // Test vector-like attributes
        FCT_TEST_BGN(attribute)
        {
            TYPE *value;

            // Allocate storage
            value = calloc(ncomponents, sizeof(TYPE));
            fct_req(value);

            // Open file
            fct_req(0 == esio_file_create(state, filename, 1));

            // Populate test data
            for (int i = 0; i < ncomponents; ++i) {
                value[i] = (TYPE) i + 5678;
            }

            // Write attribute to file
            fct_req(0 == AFFIX(esio_attribute_writev)(
                        state, "/", "attribute", value, ncomponents));

            { // Ensure we can retrieve the size correctly
                int count;
                fct_req(0 == esio_attribute_sizev(
                            state, "/", "attribute", &count));
                fct_chk_eq_int(count, ncomponents);
            }

            // Close the file
            fct_req(0 == esio_file_close(state));

            // Free the temporary
            free(value);

            // Reopen the file using normal HDF5 APIs on root processor
            // Examine the contents to ensure it matches
            if (world_rank == 0) {
                value = calloc(ncomponents, sizeof(TYPE));
                fct_req(value);
                const hid_t file_id
                    = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);
                fct_req(0 <= AFFIX(H5LTget_attribute)(file_id, "/",
                                                      "attribute", value));
                for (int i = 0; i < ncomponents; ++i) {
#ifdef __INTEL_COMPILER
#pragma warning(push,disable:1572)
#endif
                    fct_chk(i + 5678 == value[i]);
#ifdef __INTEL_COMPILER
#pragma warning(pop)
#endif
                }
                fct_req(0 <= H5Fclose(file_id));
                free(value);
            }

            // Re-read the file in a distributed manner and verify contents
            value = calloc(ncomponents, sizeof(TYPE));
            fct_req(value);
            fct_req(0 == esio_file_open(state, filename, 0));
            fct_req(0 == AFFIX(esio_attribute_readv)(
                        state, "/", "attribute", value, ncomponents));
            for (int i = 0; i < ncomponents; ++i) {
#ifdef __INTEL_COMPILER
#pragma warning(push,disable:1572)
#endif
                fct_chk(i + 5678 == value[i]);
#ifdef __INTEL_COMPILER
#pragma warning(pop)
#endif
            }
            free(value);
            fct_req(0 == esio_file_close(state));
        }
        FCT_TEST_END();

    }
    FCT_FIXTURE_SUITE_END();

    free(filetemplate);
}
示例#14
0
文件: tellub.c 项目: Starlink/hdf5
/*-------------------------------------------------------------------------
 * Function:    main
 *
 * Purpose:     HDF5 user block unjammer
 *
 * Return:      Success:    0
 *              Failure:    1
 *
 * Programmer:
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
int
main (int argc, const char *argv[])
{
  char *ifname;
  void *edata;
  H5E_auto2_t func;
  hid_t ifile;
  hsize_t usize;
  htri_t testval;
  herr_t status;
  hid_t plist;

  h5tools_setprogname(PROGRAMNAME);
  h5tools_setstatus(EXIT_SUCCESS);

  /* Initialize h5tools lib */
  h5tools_init();

  /* Disable error reporting */
  H5Eget_auto2(H5E_DEFAULT, &func, &edata);
  H5Eset_auto2(H5E_DEFAULT, NULL, NULL);

  parse_command_line (argc, argv);

  if (argc <= (opt_ind))
    {
      error_msg("missing file name\n");
      usage (h5tools_getprogname());
      return (EXIT_FAILURE);
    }

  ifname = HDstrdup (argv[opt_ind]);

  testval = H5Fis_hdf5 (ifname);

  if (testval <= 0)
    {
      error_msg("Input HDF5 file is not HDF \"%s\"\n", ifname);
      return (EXIT_FAILURE);
    }

  ifile = H5Fopen (ifname, H5F_ACC_RDONLY, H5P_DEFAULT);

  if (ifile < 0)
    {
      error_msg("Can't open input HDF5 file \"%s\"\n", ifname);
      return (EXIT_FAILURE);
    }

  plist = H5Fget_create_plist (ifile);
  if (plist < 0)
    {
      error_msg("Can't get file creation plist for file \"%s\"\n",
     ifname);
      return (EXIT_FAILURE);
    }

  status = H5Pget_userblock (plist, &usize);
  if (status < 0)
    {
      error_msg("Can't get user block for file \"%s\"\n", ifname);
      return (EXIT_FAILURE);
    }

  printf ("%ld\n", (long) usize);

  H5Pclose (plist);
  H5Fclose (ifile);

  return (EXIT_SUCCESS);
}
示例#15
0
/*-------------------------------------------------------------------------
 * Function:	test_error
 *
 * Purpose:	Test error API functions
 *
 * Return:	Success:	0
 *
 *		Failure:	-1
 *
 * Programmer:	Raymond Lu
 *		July 10, 2003
 *
 *-------------------------------------------------------------------------
 */
static herr_t
test_error(hid_t file)
{
    hid_t		dataset, space;
    hid_t               estack_id;
    hsize_t		dims[2];
    const char          *FUNC_test_error = "test_error";
    H5E_auto2_t         old_func;
    void                *old_data;

    HDfprintf(stderr, "\nTesting error API based on data I/O\n");

    /* Create the data space */
    dims[0] = DIM0;
    dims[1] = DIM1;
    if ((space = H5Screate_simple(2, dims, NULL))<0) TEST_ERROR;

    /* Test H5E_BEGIN_TRY */
    H5E_BEGIN_TRY {
        dataset = H5Dcreate2(FAKE_ID, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    } H5E_END_TRY;

    /* Create the dataset */
    if((dataset = H5Dcreate2(file, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
        H5Epush(H5E_DEFAULT, __FILE__, FUNC_test_error, __LINE__, ERR_CLS, ERR_MAJ_IO, ERR_MIN_CREATE,
                "H5Dcreate2 failed");
        goto error;
    } /* end if */

    /* Test enabling and disabling default printing */
    if(H5Eget_auto2(H5E_DEFAULT, &old_func, &old_data) < 0)
	TEST_ERROR;
    if(old_data != NULL)
	TEST_ERROR;
#ifdef H5_USE_16_API
    if (old_func != (H5E_auto_t)H5Eprint)
	TEST_ERROR;
#else /* H5_USE_16_API */
    if (old_func != (H5E_auto2_t)H5Eprint2)
	TEST_ERROR;
#endif /* H5_USE_16_API */

    if(H5Eset_auto2(H5E_DEFAULT, NULL, NULL) < 0)
        TEST_ERROR;

    /* Make H5Dwrite fail, verify default print is disabled */
    if(H5Dwrite(FAKE_ID, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2) >= 0) {
        H5Epush(H5E_DEFAULT, __FILE__, FUNC_test_error, __LINE__, ERR_CLS, ERR_MAJ_IO, ERR_MIN_WRITE,
                "H5Dwrite shouldn't succeed");
        goto error;
    } /* end if */

    if(H5Eset_auto2(H5E_DEFAULT, old_func, old_data) < 0)
        TEST_ERROR;

    /* Test saving and restoring the current error stack */
    if(H5Dwrite(FAKE_ID, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2) < 0) {
        H5Epush(H5E_DEFAULT, __FILE__, FUNC_test_error, __LINE__, ERR_CLS, ERR_MAJ_IO, ERR_MIN_WRITE,
                "H5Dwrite failed as supposed to");
        estack_id = H5Eget_current_stack();
        H5Dclose(dataset);
        H5Sclose(space);
        H5Eset_current_stack(estack_id);
        goto error;
    } /* end if */

    /* In case program comes to this point, close dataset */
    if(H5Dclose(dataset) < 0) TEST_ERROR;

    TEST_ERROR;

  error:
    return -1;
} /* end test_error() */