Esempio n. 1
0
hid_t seissol::checkpoint::h5::Fault::initFile(int odd, const char* filename)
{
	hid_t h5file;

	if (loaded()) {
		// Open the file
		h5file = open(filename, false);
		checkH5Err(h5file);

		// Fault writer
		m_h5timestepFault[odd] = H5Aopen(h5file, "timestep_fault", H5P_DEFAULT);
		checkH5Err(m_h5timestepFault[odd]);

		// Data
		for (unsigned int i = 0; i < NUM_VARIABLES; i++) {
			m_h5data[odd][i] = H5Dopen(h5file, VAR_NAMES[i], H5P_DEFAULT);
			checkH5Err(m_h5data[odd][i]);
		}
	} else {
		// Create the file
		hid_t h5plist = H5Pcreate(H5P_FILE_ACCESS);
		checkH5Err(h5plist);
		checkH5Err(H5Pset_libver_bounds(h5plist, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST));
#ifdef USE_MPI
		checkH5Err(H5Pset_fapl_mpio(h5plist, comm(), MPI_INFO_NULL));
#endif // USE_MPI

		h5file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, h5plist);
		checkH5Err(h5file);
		checkH5Err(H5Pclose(h5plist));

		// Create scalar dataspace for attributes
		hid_t h5spaceScalar = H5Screate(H5S_SCALAR);
		checkH5Err(h5spaceScalar);

		// Fault writer
		m_h5timestepFault[odd] = H5Acreate(h5file, "timestep_fault",
				H5T_STD_I32LE, h5spaceScalar, H5P_DEFAULT, H5P_DEFAULT);
		checkH5Err(m_h5timestepFault[odd]);
		int t = 0;
		checkH5Err(H5Awrite(m_h5timestepFault[odd], H5T_NATIVE_INT, &t));

		checkH5Err(H5Sclose(h5spaceScalar));

		// Variables
		for (unsigned int i = 0; i < NUM_VARIABLES; i++) {
			h5plist = H5Pcreate(H5P_DATASET_CREATE);
			checkH5Err(h5plist);
			checkH5Err(H5Pset_layout(h5plist, H5D_CONTIGUOUS));
			checkH5Err(H5Pset_alloc_time(h5plist, H5D_ALLOC_TIME_EARLY));
			m_h5data[odd][i] = H5Dcreate(h5file, VAR_NAMES[i], H5T_IEEE_F64LE, m_h5fSpaceData,
				H5P_DEFAULT, h5plist, H5P_DEFAULT);
			checkH5Err(m_h5data[odd][i]);
			checkH5Err(H5Pclose(h5plist));
		}
	}

	return h5file;
}
Esempio n. 2
0
//--------------------------------------------------------------------------
// Function:	FileAccPropList::setLibverBounds
///\brief	Sets bounds on versions of library format to be used when creating
///		or writing objects.
///\param	libver_low  - IN: Earliest version of the library that will be
///				  used for creating or writing objects
///\param	libver_high - IN: Latest version of the library that will be
///\exception	H5::PropListIException
///\par Description
///		Valid values of \a libver_low are as follows:
///		\li \c H5F_LIBVER_EARLIEST   (Default)
///		\li \c H5F_LIBVER_18
///		\li \c H5F_LIBVER_LATEST
///
///		Valid values of \a libver_high are as follows:
///		\li \c H5F_LIBVER_18
///		\li \c H5F_LIBVER_LATEST   (Default)
///
///		For more details, please refer to
/// http://www.hdfgroup.org/HDF5/doc/RM/RM_H5P.html#Property-SetLibverBounds
// Programmer:  Binh-Minh Ribler - March, 2015
//--------------------------------------------------------------------------
void FileAccPropList::setLibverBounds(H5F_libver_t libver_low, H5F_libver_t libver_high) const
{
    herr_t ret_value = H5Pset_libver_bounds(id, libver_low, libver_high);
    if (ret_value < 0)
    {
	throw PropListIException("FileAccPropList::setLibverBounds", "H5Pset_libver_bounds failed");
    }
}
Esempio n. 3
0
/** 
 * Create an HDF5 file. 
 */
static hid_t _hdf_create(const char *path, int cmode)
{
  hid_t grp_id;
  hid_t fd;
  hid_t tmp_id;
  hid_t hdf_gpid;
  hid_t fpid;
  
  fpid = H5Pcreate (H5P_FILE_ACCESS);
  
  /*VF use all the features of new HDF5 1.8*/
  H5Pset_libver_bounds (fpid, H5F_LIBVER_18, H5F_LIBVER_18);
  
  H5E_BEGIN_TRY {
    fd = H5Fcreate(path, cmode, H5P_DEFAULT, fpid);
  } H5E_END_TRY;
  
  if (fd < 0) {
    /*TODO: report error properly*/
    return MI_LOG_ERROR(MI2_MSG_CREATEFILE,path);
  }
  
  /* Create the default groups.
   * Should we use a non-zero value for size_hint (parameter 3)???
   */

  hdf_gpid = H5Pcreate (H5P_GROUP_CREATE);
  H5Pset_attr_phase_change (hdf_gpid, 0, 0);
  
  MI_CHECK_HDF_CALL_RET(grp_id = H5Gcreate2(fd, MI_ROOT_PATH , H5P_DEFAULT, hdf_gpid, H5P_DEFAULT),"H5Gcreate2")

  MI_CHECK_HDF_CALL_RET(tmp_id = H5Gcreate2(grp_id, "dimensions", H5P_DEFAULT, hdf_gpid, H5P_DEFAULT),"H5Gcreate2")
  H5Gclose(tmp_id);
  
  MI_CHECK_HDF_CALL_RET(tmp_id = H5Gcreate2(grp_id, "info", H5P_DEFAULT, hdf_gpid, H5P_DEFAULT),"H5Gcreate2")
  H5Gclose(tmp_id);
  
  MI_CHECK_HDF_CALL_RET(tmp_id = H5Gcreate2(grp_id, "image", H5P_DEFAULT, hdf_gpid, H5P_DEFAULT),"H5Gcreate2")
  
  H5Gclose(tmp_id);
  MI_CHECK_HDF_CALL_RET(tmp_id = H5Gcreate2(grp_id, "image/0", H5P_DEFAULT, hdf_gpid, H5P_DEFAULT),"H5Gcreate2")
  
  H5Pclose ( hdf_gpid );
  H5Gclose(tmp_id);
  H5Gclose(grp_id);
  
  return fd;
}
Esempio n. 4
0
//-*****************************************************************************
AwImpl::AwImpl( const std::string &iFileName,
                const AbcA::MetaData &iMetaData )
  : m_fileName( iFileName )
  , m_metaData( iMetaData )
  , m_file( -1 )
{

    // add default time sampling
    AbcA::TimeSamplingPtr ts( new AbcA::TimeSampling() );
    m_timeSamples.push_back(ts);

    // OPEN THE FILE!
    hid_t faid = H5Pcreate( H5P_FILE_ACCESS );
    if ( faid < 0 )
    {
        ABCA_THROW( "Could not create property access for fopen" );
    }
    H5Pset_libver_bounds( faid, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST );

    m_file = H5Fcreate( m_fileName.c_str(),
                        H5F_ACC_TRUNC, H5P_DEFAULT,
                        faid );

    H5Pclose( faid );

    if ( m_file < 0 )
    {
        ABCA_THROW( "Could not open file: " << m_fileName );
    }

    // set the version using HDF5 native calls
    // This expresses the AbcCoreHDF5 version - how properties,
    // are stored within HDF5, etc.
    int version = ALEMBIC_HDF5_FILE_VERSION;
    H5LTset_attribute_int(m_file, ".", "abc_version", &version, 1);

    // This is the Alembic library version XXYYZZ
    // Where XX is the major version, YY is the minor version
    // and ZZ is the patch version
    int libraryVersion = ALEMBIC_LIBRARY_VERSION;
    H5LTset_attribute_int(m_file, ".", "abc_release_version", 
        &libraryVersion, 1);

    m_metaData.set("_ai_AlembicVersion", AbcA::GetLibraryVersion());

    // Create top explicitly.
    m_top = new TopOwImpl( *this, m_file, m_metaData );
}
/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:	Test external link with environment variable HDF5_EXT_PREFIX
 *
 * Return:	Success:	exit(0)
 *		Failure:	exit(non-zero)
 *
 * Programmer:	Vailin Choi; Nov 2010
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    hid_t fapl; 	/* File access property lists */
    int	nerrors = 0;	/* Error from tests */
    const char  *env_h5_drvr;      /* File Driver value from environment */

    env_h5_drvr = HDgetenv("HDF5_DRIVER");
    if(env_h5_drvr == NULL)
        env_h5_drvr = "nomatch";

    h5_reset();
    fapl = h5_fileaccess();

    nerrors += external_link_env(fapl, FALSE) < 0 ? 1 : 0;

    /* Set the "use the latest version of the format" bounds for creating objects in the file */
    if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) TEST_ERROR

    nerrors += external_link_env(fapl, TRUE) < 0 ? 1 : 0;

    /* Verify symbol table messages are cached */
    nerrors += (h5_verify_cached_stabs(FILENAME, fapl) < 0 ? 1 : 0);

    h5_cleanup(FILENAME, fapl);

    /* Results */
    if(nerrors) {
        printf("***** %d External Link (HDF5_EXT_PREFIX) test%s FAILED! *****\n",
                nerrors, 1 == nerrors ? "" : "s");
        exit(1);
    }
    printf("All external Link (HDF5_EXT_PREFIX) tests passed.\n");

    /* clean up tmp directory created by external link tests */
    HDrmdir(TMPDIR);

    return 0;

error:
    puts("*** TESTS FAILED ***");
    return 1;
}
Esempio n. 6
0
/****************************************************************
**
**  test_iterate(): Main iteration testing routine.
**
****************************************************************/
void
test_iterate(void)
{
    hid_t fapl, fapl2;          /* File access property lists */
    unsigned new_format;        /* Whether to use the new format or not */
    herr_t ret;		        /* Generic return value */

    /* Output message about test being performed */
    MESSAGE(5, ("Testing Iteration Operations\n"));

    /* Get the default FAPL */
    fapl = H5Pcreate(H5P_FILE_ACCESS);
    CHECK(fapl, FAIL, "H5Pcreate");

    /* Copy the file access property list */
    fapl2 = H5Pcopy(fapl);
    CHECK(fapl2, FAIL, "H5Pcopy");

    /* Set the "use the latest version of the format" bounds for creating objects in the file */
    ret = H5Pset_libver_bounds(fapl2, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);
    CHECK(ret, FAIL, "H5Pset_libver_bounds");

    /* These next tests use the same file */
    for(new_format = FALSE; new_format <= TRUE; new_format++) {
        test_iter_group(new_format ? fapl2 : fapl, new_format); /* Test group iteration */
        test_iter_group_large(new_format ? fapl2 : fapl);   /* Test group iteration for large # of objects */
        test_iter_attr(new_format ? fapl2 : fapl, new_format);  /* Test attribute iteration */
        test_grp_memb_funcs(new_format ? fapl2 : fapl);     /* Test group member information functions */
        test_links(new_format ? fapl2 : fapl);              /* Test soft and hard link iteration */
    } /* end for */

    /* Close FAPLs */
    ret = H5Pclose(fapl);
    CHECK(ret, FAIL, "H5Pclose");
    ret = H5Pclose(fapl2);
    CHECK(ret, FAIL, "H5Pclose");
}   /* test_iterate() */
Esempio n. 7
0
/*
 *  To exercise the coding for the re-read of the object header for SWMR access.
 *  When the object header is read in H5O_load() of H5Ocache.c, the library initially reads
 *  H5O_SPEC_READ_SIZE (512, currently)  bytes for decoding, then reads the
 *  remaining bytes later if the object header is greater than H5O_SPEC_READ_SIZE
 *  bytes.  For SWMR access, the read should be done all at one time.
 */
static herr_t
test_ohdr_swmr(hbool_t new_format)
{
    hid_t fid = -1;                /* File ID */
    hid_t fapl = -1;            /* File access property list */
    hid_t did = -1;                /* Dataset ID */
    hid_t sid = -1;             /* Dataspace ID */
    hid_t plist = -1;            /* Dataset creation property list */
    size_t compact_size = 1024;    /* The size of compact dataset */
    int *wbuf = NULL;            /* Buffer for writing */
    hsize_t dims[1];            /* Dimension sizes */
    size_t u;                    /* Iterator */
    int n;                      /* Data variable */
    H5O_info_t obj_info;        /* Information for the object */

    if(new_format) {
        TESTING("exercise the coding for the re-read of the object header for SWMR access: latest-format");
    } else {
        TESTING("exercise the coding for the re-read of the object header for SWMR access: non-latest-format");
    } /* end if */

    /* File access property list */
    if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
        FAIL_STACK_ERROR

    /* Create the file with/without latest format: ensure version 2 object header for SWMR */
    if(new_format)  {
        /* Set to use latest library format */
        if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
            FAIL_STACK_ERROR

        if((fid = H5Fcreate(FILE_OHDR_SWMR, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
            TEST_ERROR
    } /* end if */
    else {
        if((fid = H5Fcreate(FILE_OHDR_SWMR, H5F_ACC_TRUNC|H5F_ACC_SWMR_WRITE, H5P_DEFAULT, fapl)) < 0)
Esempio n. 8
0
/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:	Tests the plugin module (H5PL)
 *
 * Return:	Success:	exit(0)
 *
 *		Failure:	exit(1)
 *
 * Programmer:	Raymond Lu
 *		14 March 2013
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    char		filename[FILENAME_BUF_SIZE];
    hid_t		file, fapl, fapl2;
    hbool_t new_format;
    int mdc_nelmts;
    size_t rdcc_nelmts;
    size_t rdcc_nbytes;
    double rdcc_w0;
    int	nerrors = 0;

    /* Testing setup */
    h5_reset();
    fapl = h5_fileaccess();

    /* Turn off the chunk cache, so all the chunks are immediately written to disk */
    if(H5Pget_cache(fapl, &mdc_nelmts, &rdcc_nelmts, &rdcc_nbytes, &rdcc_w0) < 0)
        TEST_ERROR 
    rdcc_nbytes = 0;
    if(H5Pset_cache(fapl, mdc_nelmts, rdcc_nelmts, rdcc_nbytes, rdcc_w0) < 0)
        TEST_ERROR 

    /* Copy the file access property list */
    if((fapl2 = H5Pcopy(fapl)) < 0) TEST_ERROR

    /* Set the "use the latest version of the format" bounds for creating objects in the file */
    if(H5Pset_libver_bounds(fapl2, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) TEST_ERROR

    h5_fixname(FILENAME[0], fapl, filename, sizeof filename);

    /* Test with old & new format groups */
    for(new_format = FALSE; new_format <= TRUE; new_format++) {
        hid_t my_fapl;

        /* Set the FAPL for the type of format */
        if(new_format) {
            puts("\nTesting with new file format:");
            my_fapl = fapl2;
        } /* end if */
        else {
            puts("Testing with old file format:");
            my_fapl = fapl;
        } /* end else */

        /* Create the file for this test */
        if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl)) < 0)
            TEST_ERROR 

        /* Test dynamically loaded filters for chunked dataset */
        nerrors += (test_filters_for_datasets(file) < 0	? 1 : 0);

        /* Test dynamically loaded filters for groups */
        nerrors += (test_filters_for_groups(file) < 0 ? 1 : 0);

        if(H5Fclose(file) < 0)
            TEST_ERROR 
    } /* end for */

    /* Close FAPL */
    if(H5Pclose(fapl2) < 0) TEST_ERROR
    if(H5Pclose(fapl) < 0) TEST_ERROR
   
    puts("\nTesting reading data with with dynamic plugin filters:");

    /* Close the library so that all loaded plugin libraries are unloaded */
    h5_reset();
    fapl = h5_fileaccess();

    /* Reopen the file for testing data reading */
    if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
        TEST_ERROR 

    /* Read the data with filters */
    nerrors += (test_read_with_filters(file) < 0		? 1 : 0);

    /* Open the groups with filters */
    nerrors += (test_groups_with_filters(file) < 0	? 1 : 0);

    if(H5Fclose(file) < 0)
        TEST_ERROR 

    if(nerrors)
        TEST_ERROR 
    printf("All plugin tests passed.\n");
    h5_cleanup(FILENAME, fapl);

    return 0;

error:
    nerrors = MAX(1, nerrors);
    printf("***** %d PLUGIN TEST%s FAILED! *****\n",
            nerrors, 1 == nerrors ? "" : "S");
    return 1;
}
Esempio n. 9
0
/*-------------------------------------------------------------------------
 * Function:    open_skeleton
 *
 * Purpose:     Opens the SWMR HDF5 file and datasets.
 *
 * Parameters:  const char *filename
 *              The filename of the SWMR HDF5 file to open
 *
 *              unsigned verbose
 *              Whether or not to emit verbose console messages
 *
 * Return:      Success:    The file ID of the opened SWMR file
 *                          The dataset IDs are stored in a global array
 *
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
static hid_t
open_skeleton(const char *filename, unsigned verbose)
{
    hid_t fid;          /* File ID for new HDF5 file */
    hid_t fapl;         /* File access property list */
    hid_t sid;          /* Dataspace ID */
    hsize_t dim[2];     /* Dataspace dimension */
    unsigned u, v;      /* Local index variable */

    assert(filename);

    /* Create 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;

#ifdef QAK
    /* Increase the initial size of the metadata cache */
    {
        H5AC_cache_config_t mdc_config;

        mdc_config.version = H5AC__CURR_CACHE_CONFIG_VERSION;
        H5Pget_mdc_config(fapl, &mdc_config);
        fprintf(stderr, "mdc_config.initial_size = %lu\n", (unsigned long)mdc_config.initial_size);
        fprintf(stderr, "mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length);
        mdc_config.set_initial_size = 1;
        mdc_config.initial_size = 16 * 1024 * 1024;
        /* mdc_config.epoch_length = 5000; */
        H5Pset_mdc_config(fapl, &mdc_config);
    }
#endif /* QAK */

#ifdef QAK
    H5Pset_fapl_log(fapl, "append.log", H5FD_LOG_ALL, (size_t)(512 * 1024 * 1024));
#endif /* QAK */

    /* Open the file */
    if((fid = H5Fopen(filename, H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE, fapl)) < 0)
        return -1;

    /* Close file access property list */
    if(H5Pclose(fapl) < 0)
        return -1;

    /* Emit informational message */
    if(verbose)
        fprintf(stderr, "Opening datasets\n");

    /* Open the datasets */
    for(u = 0; u < NLEVELS; u++)
        for(v = 0; v < symbol_count[u]; v++) {
            if((symbol_info[u][v].dsid = H5Dopen2(fid, symbol_info[u][v].name, H5P_DEFAULT)) < 0)
                return -1;
            if((sid = H5Dget_space(symbol_info[u][v].dsid)) < 0)
                return -1;
            if(2 != H5Sget_simple_extent_ndims(sid))
                return -1;
            if(H5Sget_simple_extent_dims(sid, dim, NULL) < 0)
                return -1;
            symbol_info[u][v].nrecords = dim[1];
        } /* end for */

    return fid;
}
Esempio n. 10
0
int main(int argc, char *argv[])
{
  hid_t fid           = -1;
  hid_t access_plist  = -1;
  hid_t create_plist  = -1;
  hid_t cparm         = -1;
  hid_t datatype      = -1;
  hid_t dataspace     = -1;
  hid_t dataset       = -1;
  hid_t memspace      = -1;
  hid_t groupDetector = -1;
  int rank = 1;
  hsize_t chunk[2] = {10,10};
  hsize_t dims[2] = {1,1};
  hsize_t elementSize[2] = {1,1};
  hsize_t maxdims[2] = {H5S_UNLIMITED,H5S_UNLIMITED};
  int ivalue[2];
  int fillValue = 0;
  
  /* Open the source file and dataset */
  /* All SWMR files need to use the latest file format */
  access_plist = H5Pcreate(H5P_FILE_ACCESS);
  H5Pset_fclose_degree(access_plist, H5F_CLOSE_STRONG);
#if H5_VERSION_GE(1,9,178)
  H5Pset_object_flush_cb(access_plist, cFlushCallback, NULL);
#endif
  H5Pset_libver_bounds(access_plist, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);
  create_plist = H5Pcreate(H5P_FILE_CREATE);
  fid = H5Fcreate("test_string_swmr.h5", H5F_ACC_TRUNC, create_plist, access_plist);

  /* Data */
  rank = 2;
  dims[0] = 10;
  dims[1] = 10;
  dataspace = H5Screate_simple(rank, dims, dims);
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_chunk(cparm, rank, chunk);
  datatype = H5Tcopy(H5T_NATIVE_INT8);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  groupDetector = H5Gcreate(fid, "detector", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

  access_plist = H5Pcreate(H5P_DATASET_ACCESS);
  H5Pset_chunk_cache(access_plist, 503, 100, 1.0);
  dataset = H5Dcreate2(groupDetector, "data1",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, access_plist);
  ivalue[0] = 1;
  ivalue[1] = 1;
  writeInt32Attribute(dataset, "NDArrayDimBinning", 2, ivalue);
  ivalue[0] = 0;
  ivalue[1] = 0;
  writeInt32Attribute(dataset, "NDArrayDimOffset", 2, ivalue);
  writeInt32Attribute(dataset, "NDArrayDimReverse", 2, ivalue);
  ivalue[0] = 2;
  writeInt32Attribute(dataset, "NDArrayNumDims", 1, ivalue);
  H5Gclose(groupDetector);

  dims[0] = 1;
  dims[1] = 1;
  chunk[0] = 1;
  rank = 1;

  /* Unique ID */
  datatype = H5T_NATIVE_INT32;
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "NDArrayUniqueId",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  memspace = H5Screate_simple(rank, elementSize, NULL);
  writeStringAttribute(dataset, "NDAttrName",        "NDArrayUniqueId");
  writeStringAttribute(dataset, "NDAttrDescription", "The unique ID of the NDArray");
  writeStringAttribute(dataset, "NDAttrSourceType",  "NDAttrSourceDriver");
  writeStringAttribute(dataset, "NDAttrSource",      "Driver");

  /* EPICS Timestemp */
  datatype = H5T_NATIVE_DOUBLE;
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "NDArrayTimeStamp",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  memspace = H5Screate_simple(rank, elementSize, NULL);
  writeStringAttribute(dataset, "NDAttrName",        "NDArrayTimeStamp");
  writeStringAttribute(dataset, "NDAttrDescription", "The timestamp of the NDArray as float64");
  writeStringAttribute(dataset, "NDAttrSourceType",  "NDAttrSourceDriver");
  writeStringAttribute(dataset, "NDAttrSource",      "Driver");

  /* EPICS TS sec */
  datatype = H5T_NATIVE_UINT32;
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "NDArrayEpicsTSSec",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  memspace = H5Screate_simple(rank, elementSize, NULL);
  writeStringAttribute(dataset, "NDAttrName",        "NDArrayEpicsTSSec");
  writeStringAttribute(dataset, "NDAttrDescription", "The NDArray EPICS timestamp seconds past epoch");
  writeStringAttribute(dataset, "NDAttrSourceType",  "NDAttrSourceDriver");
  writeStringAttribute(dataset, "NDAttrSource",      "Driver");

  /* EPICS TS nsec */
  datatype = H5T_NATIVE_UINT32;
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "NDArrayEpicsTSnSec",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  memspace = H5Screate_simple(rank, elementSize, NULL);
  writeStringAttribute(dataset, "NDAttrName",        "NDArrayEpicsTSnSec");
  writeStringAttribute(dataset, "NDAttrDescription", "The NDArray EPICS timestamp nanoseconds");
  writeStringAttribute(dataset, "NDAttrSourceType",  "NDAttrSourceDriver");
  writeStringAttribute(dataset, "NDAttrSource",      "Driver");
 
  /* Color mode */
  datatype = H5T_NATIVE_INT32;
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "ColorMode",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  memspace = H5Screate_simple(rank, elementSize, NULL);
  writeStringAttribute(dataset, "NDAttrName",        "ColorMode");
  writeStringAttribute(dataset, "NDAttrDescription", "Color mode");
  writeStringAttribute(dataset, "NDAttrSourceType",  "NDAttrSourceDriver");
  writeStringAttribute(dataset, "NDAttrSource",      "Driver");

  /* Camera manufacturer */
  datatype = H5Tcopy(H5T_C_S1);
  H5Tset_size(datatype, 256);
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "CameraManufacturer",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  memspace = H5Screate_simple(rank, elementSize, NULL);
  writeStringAttribute(dataset, "NDAttrName",        "CameraManufacturer");
  writeStringAttribute(dataset, "NDAttrDescription", "Camera manufacturer");
  writeStringAttribute(dataset, "NDAttrSourceType",  "NDAttrSourceParam");
  writeStringAttribute(dataset, "NDAttrSource",      "MANUFACTURER");

  /* Performance data */
  rank = 2;
  dims[0] = 1;
  dims[1] = 5;
  chunk[1] = 5;
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "timestamp",
                       H5T_NATIVE_DOUBLE, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  if (!H5Iis_valid(dataset)) {
    printf("Error writing performance dataset");
  }
  H5Sclose(dataspace);

#if H5_VERSION_GE(1,9,178)
  H5Fstart_swmr_write(fid);
#endif
  
  H5Fclose(fid);

  return 0;

} /* end main */
Esempio n. 11
0
/*-------------------------------------------------------------------------
 * Function: main
 *
 * Purpose: Create group(s) in an HDF5 file
 *
 * Programmer: Quincey Koziol, 2/13/2007
 *
 *-------------------------------------------------------------------------
 */
int
main(int argc, const char *argv[])
{
    hid_t fid;                  /* HDF5 file ID */
    hid_t fapl_id;              /* File access property list ID */
    hid_t lcpl_id;              /* Link creation property list ID */
    size_t curr_group;          /* Current group to create */

    h5tools_setprogname(PROGRAMNAME);
    h5tools_setstatus(EXIT_SUCCESS);

    /* Disable the HDF5 library's error reporting */
    H5Eset_auto2(H5E_DEFAULT, NULL, NULL);

    /* Initialize h5tools lib */
    h5tools_init();

    /* Parse command line */
    HDmemset(&params, 0, sizeof(params));
    if(parse_command_line(argc, argv, &params) < 0) {
        error_msg("unable to parse command line arguments\n");
        leave(EXIT_FAILURE);
    } /* end if */

    /* Create file access property list */
    if((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) {
        error_msg("Could not create file access property list\n");
        leave(EXIT_FAILURE);
    } /* end if */

    /* Check for creating groups with new format version */
    if(params.latest) {
        /* Set the "use the latest version of the format" bounds */
        if(H5Pset_libver_bounds(fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) {
            error_msg("Could not set property for using latest version of the format\n");
            leave(EXIT_FAILURE);
        } /* end if */

        /* Display some output if requested */
        if(params.verbose)
            printf("%s: Creating groups with latest version of the format\n", h5tools_getprogname());
    } /* end if */

    /* Attempt to open an existing HDF5 file first */
    fid = h5tools_fopen(params.fname, H5F_ACC_RDWR, fapl_id, NULL, NULL, 0);

    /* If we couldn't open an existing file, try creating file */
    /* (use "EXCL" instead of "TRUNC", so we don't blow away existing non-HDF5 file) */
    if(fid < 0)
        fid = H5Fcreate(params.fname, H5F_ACC_EXCL, H5P_DEFAULT, fapl_id);

    /* Test for error in opening file */
    if(fid < 0) {
        error_msg("Could not open output file '%s'\n", params.fname);
        leave(EXIT_FAILURE);
    } /* end if */

    /* Create link creation property list */
    if((lcpl_id = H5Pcreate(H5P_LINK_CREATE)) < 0) {
        error_msg("Could not create link creation property list\n");
        leave(EXIT_FAILURE);
    } /* end if */

    /* Check for creating intermediate groups */
    if(params.parents) {
        /* Set the intermediate group creation property */
        if(H5Pset_create_intermediate_group(lcpl_id, TRUE) < 0) {
            error_msg("Could not set property for creating parent groups\n");
            leave(EXIT_FAILURE);
        } /* end if */

        /* Display some output if requested */
        if(params.verbose)
            printf("%s: Creating parent groups\n", h5tools_getprogname());
    } /* end if */

    /* Loop over creating requested groups */
    for(curr_group = 0; curr_group < params.ngroups; curr_group++) {
        hid_t gid;              /* Group ID */

        /* Attempt to create a group */
        if((gid = H5Gcreate2(fid, params.groups[curr_group], lcpl_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
            error_msg("Could not create group '%s'\n", params.groups[curr_group]);
            leave(EXIT_FAILURE);
        } /* end if */

        /* Close the group */
        if(H5Gclose(gid) < 0) {
            error_msg("Could not close group '%s'??\n", params.groups[curr_group]);
            leave(EXIT_FAILURE);
        } /* end if */

        /* Display some output if requested */
        if(params.verbose)
            printf("%s: created group '%s'\n", h5tools_getprogname(), params.groups[curr_group]);
    } /* end for */

    /* Close link creation property list */
    if(H5Pclose(lcpl_id) < 0) {
        error_msg("Could not close link creation property list\n");
        leave(EXIT_FAILURE);
    } /* end if */

    /* Close file */
    if(H5Fclose(fid) < 0) {
        error_msg("Could not close output file '%s'??\n", params.fname);
        leave(EXIT_FAILURE);
    } /* end if */

    /* Close file access property list */
    if(H5Pclose(fapl_id) < 0) {
        error_msg("Could not close file access property list\n");
        leave(EXIT_FAILURE);
    } /* end if */

    /* Shut down h5tools lib */
    h5tools_close();

    leave(EXIT_SUCCESS);
} /* end main() */
Esempio n. 12
0
/*-------------------------------------------------------------------------
 * Function:    test_logging_api
 *
 * Purpose:     Tests the API calls that affect mdc logging
 *
 * Return:      Success:        0
 *              Failure:        -1
 *-------------------------------------------------------------------------
 */
static herr_t
test_logging_api(void)
{
    hid_t       fapl = -1;
    hbool_t     is_enabled;
    hbool_t     is_enabled_out;
    hbool_t     start_on_access;
    hbool_t     start_on_access_out;
    char        *location = NULL;
    size_t      size;

    hid_t       fid;
    hid_t       gid;
    hbool_t     is_currently_logging;
    char        group_name[8];
    char        filename[1024];
    int         i;

    TESTING("metadata cache log api calls");

    fapl = h5_fileaccess();
    h5_fixname(FILE_NAME, fapl, filename, sizeof filename);

    /* Set up metadata cache logging */
    is_enabled = TRUE;
    start_on_access = FALSE;
    if(H5Pset_mdc_log_options(fapl, is_enabled, LOG_LOCATION, start_on_access) < 0)
        TEST_ERROR;

    /* Check to make sure that the property list getter returns the correct
     * location string buffer size;
     */
    is_enabled_out = FALSE;
    start_on_access_out = TRUE;
    location = NULL;
    size = 999;
    if(H5Pget_mdc_log_options(fapl, &is_enabled_out, location, &size, 
                              &start_on_access_out) < 0)
        TEST_ERROR;
    if(size != strlen(LOG_LOCATION) + 1)
        TEST_ERROR;

    /* Check to make sure that the property list getter works */
    if(NULL == (location = (char *)HDcalloc(size, sizeof(char))))
        TEST_ERROR;
    if(H5Pget_mdc_log_options(fapl, &is_enabled_out, location, &size, 
                              &start_on_access_out) < 0)
        TEST_ERROR;
    if((is_enabled != is_enabled_out)
        || (start_on_access != start_on_access_out)
        || HDstrcmp(LOG_LOCATION, location))
        TEST_ERROR;

    /* Create a file */
    if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
        TEST_ERROR;
    if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR;
    if(H5Pclose(fapl) < 0)
        TEST_ERROR;


    /* Check to see if the logging flags were set correctly */
    is_enabled = FALSE;
    is_currently_logging = TRUE;
    if((H5Fget_mdc_logging_status(fid, &is_enabled, &is_currently_logging) < 0)
       || (is_enabled != TRUE)
       || (is_currently_logging != FALSE))
        TEST_ERROR;

    /* Turn on logging and check flags */
    if(H5Fstart_mdc_logging(fid) < 0)
        TEST_ERROR;
    is_enabled = FALSE;
    is_currently_logging = FALSE;
    if((H5Fget_mdc_logging_status(fid, &is_enabled, &is_currently_logging) < 0)
       || (is_enabled != TRUE)
       || (is_currently_logging != TRUE))
        TEST_ERROR;

    /* Perform some manipulations */
    for(i = 0; i < N_GROUPS; i++) {
        HDmemset(group_name, 0, 8);
        HDsnprintf(group_name, 8, "%d", i);
        if((gid = H5Gcreate2(fid, group_name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
            TEST_ERROR;
        if(H5Gclose(gid) < 0)
            TEST_ERROR;
    }

    /* Turn off logging and check flags */
    if(H5Fstop_mdc_logging(fid) < 0)
        TEST_ERROR;
    is_enabled = FALSE;
    is_currently_logging = TRUE;
    if((H5Fget_mdc_logging_status(fid, &is_enabled, &is_currently_logging) < 0)
       || (is_enabled != TRUE)
       || (is_currently_logging != FALSE))
        TEST_ERROR;

    /* Clean up */
    HDfree(location);
    if(H5Fclose(fid) < 0)
        TEST_ERROR;

    PASSED();
    return 0;

error:
    return 1;
 } /* test_logging_api() */
Esempio n. 13
0
/*****************************************************************************
  This function generates attributes, groups, and datasets of many types. 

  Parameters:
            fname:	file_name.
            ngrps:	number of top level groups.
            ndsets:	number of datasets.
            attrs:	number of attributes.
            nrow:	number of rows in a dataset.
            chunk:	chunk size (single number).
            vlen:	max vlen size.
            comp:	use latest format.
            latest:	use gzip comnpression.
			
  Return:  Non-negative on success/Negative on failure
  
  Programmer:  Peter Cao <*****@*****.**>, Jan. 2013
 ****************************************************************************/
herr_t create_perf_test_file(const char *fname, int ngrps, int ndsets, 
       int nattrs, hsize_t nrows, hsize_t dim0, hsize_t chunk, int vlen, 
	   int compressed, int latest)
{
    int         i, j, k;
    hid_t       fid, sid_null, sid_scalar, sid_1d, sid_2d, did, aid, sid_2, sid_large, 
	            fapl=H5P_DEFAULT, dcpl=H5P_DEFAULT, gid1, gid2, cmp_tid, tid_str, 
				tid_enum, tid_array_f, tid_vlen_i, tid_vlen_s;
    char        name[32], tmp_name1[32], tmp_name2[32], tmp_name3[32];
    hsize_t     dims[1]={dim0}, dims2d[2]={dim0, (dim0/4+1)}, dims_array[1]={FIXED_LEN}, 
	            dim1[1]={2};
    char        *enum_names[4] = {"SOLID", "LIQUID", "GAS", "PLASMA"};
    test_comp_t *buf_comp=NULL, *buf_comp_large=NULL;
    int         *buf_int=NULL;
    float       (*buf_float_a)[FIXED_LEN]=NULL;
    double      **buf_double2d=NULL;
    hvl_t       *buf_vlen_i=NULL;
	char        (*buf_str)[FIXED_LEN];
	char        **buf_vlen_s=NULL;
	hobj_ref_t  buf_ref[2];
	hdset_reg_ref_t buf_reg_ref[2];
    size_t      offset, len;
    herr_t      status;
    char        *names[NTYPES] = { "int", "ulong", "float", "double", "fixed string", 
	            "enum", "fixed float array", "vlen int array", "vlen strings"};
    hid_t       types[NTYPES] = { H5T_NATIVE_INT, H5T_NATIVE_UINT64, H5T_NATIVE_FLOAT, 
                H5T_NATIVE_DOUBLE, tid_str, tid_enum, tid_array_f, tid_vlen_i, tid_vlen_s};
	hsize_t     coords[4][2] = { {0,  1}, {3, 5}, {1,  0}, {2,  4}}, start=0, stride=1, count=1;
	
	if (nrows < NROWS) nrows = NROWS; 
    if (ngrps<NGROUPS) ngrps=NGROUPS;
	if (ndsets<NDSETS) ndsets=NDSETS;
	if (nattrs<NATTRS) nattrs=NATTRS;
	if (dim0<DIM0) dim0=DIM0;
    if (chunk>dim0) chunk=dim0/4;
    if (chunk<1) chunk = 1;
	if (vlen<1) vlen = MAXVLEN;

    /* create fixed string datatype */                                   
    types[4] = tid_str =  H5Tcopy (H5T_C_S1);
    H5Tset_size (tid_str, FIXED_LEN);

    /* create enum datatype */
    types[5] = tid_enum = H5Tenum_create(H5T_NATIVE_INT);
    for (i = (int) SOLID; i <= (int) PLASMA; i++) {
        phase_t val = (phase_t) i;
        status = H5Tenum_insert (tid_enum, enum_names[i], &val);
    }

    /* create float array datatype */
    types[6] = tid_array_f = H5Tarray_create (H5T_NATIVE_FLOAT, 1, dims_array);
 
    /* create variable length integer datatypes */
    types[7] = tid_vlen_i = H5Tvlen_create (H5T_NATIVE_INT);
    	
    /* create variable length string datatype */
    types[8] = tid_vlen_s =  H5Tcopy (H5T_C_S1);
    H5Tset_size (tid_vlen_s, H5T_VARIABLE);
                   
    /* create compound datatypes */    
    cmp_tid = H5Tcreate (H5T_COMPOUND, sizeof (test_comp_t));
    offset = 0;
    for (i=0; i<NTYPES-2; i++) {
        H5Tinsert(cmp_tid, names[i], offset, types[i]);
        offset += H5Tget_size(types[i]);
    }

	H5Tinsert(cmp_tid, names[7], offset, types[7]);
	offset += sizeof (hvl_t);
	H5Tinsert(cmp_tid, names[8], offset, types[8]);

	/* create dataspace */
    sid_1d = H5Screate_simple (1, dims, NULL);
    sid_2d = H5Screate_simple (2, dims2d, NULL);
    sid_2 = H5Screate_simple  (1, dim1, NULL);
	sid_large = H5Screate_simple  (1, &nrows, NULL);
    sid_null = H5Screate (H5S_NULL);	
	sid_scalar = H5Screate (H5S_SCALAR);
	
	/* create fid access property */
	fapl = H5Pcreate (H5P_FILE_ACCESS);
    H5Pset_libver_bounds (fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);

	/* create dataset creation property */
    dcpl = H5Pcreate (H5P_DATASET_CREATE);

	/* set dataset chunk */
    if (chunk>0) {
        H5Pset_chunk (dcpl, 1, &chunk);
    }

	/* set dataset compression */
    if (compressed) {
        if (chunk<=0) {
            chunk = dim0/10+1;;
            H5Pset_chunk (dcpl, 1, &chunk);
        }
        H5Pset_shuffle (dcpl);
        H5Pset_deflate (dcpl, 6);
    }	

	/* allocate buffers */
    buf_comp   = (test_comp_t *)calloc(dim0, sizeof(test_comp_t));
    buf_comp_large   = (test_comp_t *)calloc(nrows, sizeof(test_comp_t));
    buf_int    = (int *)calloc(dim0, sizeof(int));
    buf_float_a  = malloc(dim0*sizeof(*buf_float_a));
	buf_vlen_i = (hvl_t *)calloc(dim0, sizeof (hvl_t));
    buf_vlen_s = (char **)calloc(dim0, sizeof(char *));
	buf_str    =  malloc(dim0*sizeof (*buf_str));

	/* allocate array of doulbe pointers */
	buf_double2d  = (double **)calloc(dims2d[0],sizeof(double *));
	/* allocate a contigous chunk of memory for the data */
	buf_double2d[0] = (double *)calloc( dims2d[0]*dims2d[1],sizeof(double) );
	/* assign memory city to pointer array */
	for (i=1; i <dims2d[0]; i++) buf_double2d[i] = buf_double2d[0]+i*dims2d[1];

	/* fill buffer values */
	len = 1;
    for (i=0; i<dims[0]; i++) {
        buf_comp[i].i = buf_int[i] = i-2147483648;
        buf_comp[i].l = 0xffffffffffffffff-i;
        buf_comp[i].f = 1.0/(i+1.0);
        buf_comp[i].d = 987654321.0*i+1.0/(i+1.0);
        buf_comp[i].e = (phase_t) (i % (int) (PLASMA + 1));
		
		for (j=0; j<FIXED_LEN; j++) {
		    buf_comp[i].f_array[j] = buf_float_a[i][j] = i*100+j;
			buf_str[i][j] = 'a' + (i%26);
		}
		buf_str[i][FIXED_LEN-1] = 0;
        strcpy(buf_comp[i].s, buf_str[i]);
		
		len = (1-cos(i/8.0))/2*vlen+1;
		if (!i) len = vlen;
		buf_vlen_i[i].len = len;
		buf_vlen_i[i].p = (int *)calloc(len, sizeof(int));
		for (j=0; j<len; j++) ((int*)(buf_vlen_i[i].p))[j] = i*100+j;
		buf_comp[i].i_vlen = buf_vlen_i[i];
		
		buf_vlen_s[i] = (char *)calloc(len, sizeof(char));
		for (j=0; j<len-1; j++)
		    buf_vlen_s[i][j] = j%26+'A';
		buf_comp[i].s_vlen = buf_vlen_s[i];
		
		for (j=0; j<dims2d[1]; j++)
		    buf_double2d[i][j] = i+j/10000.0;
    }

    for (i=0; i<nrows; i++) {
        buf_comp_large[i].i = i-2147483648;
        buf_comp_large[i].l = 0xffffffffffffffff-i;
        buf_comp_large[i].f = 1.0/(i+1.0);
        buf_comp_large[i].d = 987654321.0*i+1.0/(i+1.0);
        buf_comp_large[i].e = (phase_t) (i % (int) (PLASMA + 1));
        for (j=0; j<FIXED_LEN-1; j++) {
            buf_comp_large[i].f_array[j] = i*100+j;
            buf_comp_large[i].s[j] = 'a' + (i%26);
        }
		len = i%vlen+1;
        buf_comp_large[i].i_vlen.len = len;
        buf_comp_large[i].i_vlen.p = (int *)calloc(len, sizeof(int));
        for (j=0; j<len; j++) ((int*)(buf_comp_large[i].i_vlen.p))[j] = i*100+j;
        buf_comp_large[i].s_vlen = (char *)calloc(i+2, sizeof(char));
        for (j=0; j<i+1; j++) (buf_comp_large[i].s_vlen)[j] = j%26+'A';
    }
	
	/* create file */
    if (latest)
        fid = H5Fcreate (fname, H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
    else
        fid = H5Fcreate (fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
	add_attrs(fid, 0);

	sprintf(name, "a cmp ds of %d rows", nrows);
	did = H5Dcreate (fid, name, cmp_tid, sid_large, H5P_DEFAULT, dcpl, H5P_DEFAULT);
	H5Dwrite (did, cmp_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_comp_large);
	add_attrs(did, 0); 
	H5Dclose(did);

	// /* add attributes*/
    gid1 = H5Gcreate (fid, "attributes", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
	if (nattrs<1) nattrs = 1;
	i=0;
	while (i<nattrs) i += add_attrs(gid1, i);
	H5Gclose(gid1);
		
	/* add many sub groups to a group*/
    gid1 = H5Gcreate (fid, "groups", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
	add_attrs(gid1, 0);
    for (i=0; i<ngrps; i++) {
	    /* create sub groups */
        sprintf(name, "g%02d", i);
        gid2 = H5Gcreate (gid1, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
		if (i<10) add_attrs(gid2, 0);
		H5Gclose(gid2);
	}
	H5Gclose(gid1);

	/* add many datasets to a group */
	gid1 = H5Gcreate (fid, "datasets", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
	add_attrs(gid1, 0);
    for (j=0; j<ndsets; j+=12) {
		/* 1 add a null dataset */
		sprintf(name, "%05d null dataset", j);
        did = H5Dcreate (gid1, name, H5T_STD_I32LE, sid_null, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
		if (!j) add_attrs(did, j); 
        H5Dclose(did);	

		/* 2 add scalar int point */
	    sprintf(name, "%05d scalar int point", j);
        did = H5Dcreate (gid1, name, H5T_NATIVE_INT, sid_scalar, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
        H5Dwrite (did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &j);		
		if (!j) add_attrs(did, j); 
		H5Dclose(did);		
		
		/* 3 scalar vlen string */
	    sprintf(name, "%05d scalar vlen string", j);
        did = H5Dcreate (gid1, name, tid_vlen_s, sid_scalar, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
        H5Dwrite (did, tid_vlen_s, H5S_ALL, H5S_ALL, H5P_DEFAULT, &buf_vlen_s[0]);		
		if (!j) add_attrs(did, j); 
		H5Dclose(did);			
	
	    /* 4 add fixed-length float array */
		sprintf(name, "%05d fixed-length float array", j);
		did = H5Dcreate (gid1, name, tid_array_f, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT);
		H5Dwrite (did, tid_array_f, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_float_a);
		if (!j) add_attrs(did, j); 
		H5Dclose(did);
	
		/* 5 add fixed-length strings */
		sprintf(name, "%05d fixed-length strings", j);
		did = H5Dcreate (gid1, name, tid_str, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT);
		H5Dwrite (did, tid_str, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_str);
		if (!j) add_attrs(did, j); 
		H5Dclose(did);
		
		/* 6 add compound data */
	    sprintf(name, "%05d compund data", j);
	    did = H5Dcreate (gid1, name, cmp_tid, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT);
	    H5Dwrite (did, cmp_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_comp);
		if (!j) add_attrs(did, j); 
		H5Dclose(did);

		/* 7 add 2D double */
	    sprintf(name, "%05d 2D double", j);
		strcpy (tmp_name1, name);
	    did = H5Dcreate (gid1, name, H5T_NATIVE_DOUBLE, sid_2d, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
	    H5Dwrite (did, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_double2d[0]);
		if (!j) add_attrs(did, j); 
		H5Dclose(did);
		
		/* 8 add 1D int array */
	    sprintf(name, "%05d 1D int array", j);
        did = H5Dcreate (gid1, name, H5T_NATIVE_INT, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT);
        H5Dwrite (did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_int);		
		if (!j) add_attrs(did, j); 
		H5Dclose(did);
		
		/* 9 add vlen int array */
	    sprintf(name, "%05d vlen int array", j);
		strcpy (tmp_name2, name);
        did = H5Dcreate (gid1, name, tid_vlen_i, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT);
        H5Dwrite (did, tid_vlen_i, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_vlen_i);		
		if (!j) add_attrs(did, j); 
		H5Dclose(did);	

		/* 10 add vlen strings */
	    sprintf(name, "%05d vlen strings", j);
		strcpy (tmp_name3, name);
        did = H5Dcreate (gid1, name, tid_vlen_s, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT);
        H5Dwrite (did, tid_vlen_s, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_vlen_s);		
		if (!j) add_attrs(did, j); 
		H5Dclose(did);	
		
		/* 11 add object refs */
		H5Rcreate(&buf_ref[0],gid1, ".", H5R_OBJECT, -1); 
		H5Rcreate(&buf_ref[1],gid1, tmp_name3, H5R_OBJECT, -1); 
	    sprintf(name, "%05d obj refs", j);
        did = H5Dcreate (gid1, name, H5T_STD_REF_OBJ, sid_2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
        H5Dwrite (did, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_ref);		
		if (!j) add_attrs(did, j); 
		H5Dclose(did);

		/* 12 add region refs */
		H5Sselect_elements (sid_2d, H5S_SELECT_SET, 4, coords[0]);
		H5Rcreate(&buf_reg_ref[0],gid1, tmp_name1, H5R_DATASET_REGION, sid_2d); 
		H5Sselect_none(sid_2d);
		count = dims[0]/2+1;
		H5Sselect_hyperslab (sid_1d, H5S_SELECT_SET, &start, &stride, &count,NULL);
		H5Rcreate(&buf_reg_ref[1],gid1, tmp_name2, H5R_DATASET_REGION, sid_1d); 
		H5Sselect_none(sid_1d);
	    sprintf(name, "%05d region refs", j);
        did = H5Dcreate (gid1, name, H5T_STD_REF_DSETREG, sid_2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
        H5Dwrite (did, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_reg_ref);		
		if (!j) add_attrs(did, j); 
		H5Dclose(did);
	}
	H5Gclose(gid1);			
	
    H5Tclose (tid_array_f);
    H5Tclose (tid_vlen_i);
    H5Tclose (tid_vlen_s);
    H5Tclose (tid_enum);
    H5Tclose (tid_str);
    H5Tclose (cmp_tid);
    H5Pclose (dcpl);
    H5Pclose (fapl);
    H5Sclose (sid_1d);
    H5Sclose (sid_2d);
    H5Sclose (sid_2);
    H5Sclose (sid_large);
    H5Sclose (sid_null);
    H5Sclose (sid_scalar);
    H5Fclose (fid);

    for (i=0; i<dims[0]; i++) {
		if (buf_vlen_i[i].p) free(buf_vlen_i[i].p);
		if (buf_vlen_s[i]) free(buf_vlen_s[i]);
	}

    for (i=0; i<nrows; i++) {
	    if (buf_comp_large[i].i_vlen.p)  free(buf_comp_large[i].i_vlen.p);
		if (buf_comp_large[i].s_vlen) free(buf_comp_large[i].s_vlen);
	}
	
    free (buf_comp);
    free (buf_comp_large);
    free (buf_int);
    free (buf_float_a);
    free (buf_double2d[0]);
    free (buf_double2d);
	free (buf_str);
    free(buf_vlen_i);
    free(buf_vlen_s);

    return 0;
}
Esempio n. 14
0
/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:	To create HDF5 files with non-zero status_flags in the superblock
 *		via flushing and exiting without closing the library.
 *
 *		Due to file locking, status_flag in the superblock will be 
 *		nonzero after H5Fcreate.  The library will clear status_flags
 *		on file closing.  This program, after "H5Fcreate" the files,
 *		exits without going through library closing. Thus, status_flags
 *		for these files are not cleared and users cannot open them.
 *
 *		These files are used by "h5clear" to see if the tool clears
 *		status_flags properly so users can open the files afterwards.
 *
 * Return:	Success:	0
 *		Failure:	1
 *
 * Programmer:	Vailin Choi; July 2013
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    hid_t fid;			/* File ID */
    hid_t fapl, new_fapl;	/* File access property lists */
    char fname[512];		/* File name */
    hbool_t new_format;		/* To use latest library format or not */
    int fd;			/* File descriptor */
    uint8_t super_vers;		/* Superblock version */
    ssize_t bytes_written;	/* The # of bytes written to the file */

    /* Create a copy of the file access property list */
    if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
	goto error;

    /* Copy the file access property list */
    if((new_fapl = H5Pcopy(fapl)) < 0)
	goto error;
    /* Set to latest library format */
    if(H5Pset_libver_bounds(new_fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
	goto error;

    /* Create file with/without latest library format */
    for(new_format = FALSE; new_format <= TRUE; new_format++) {
	hid_t fapl2, my_fapl;	/* File access property lists */

	/* Set to use the appropriate file access property list */
	if(new_format)
	    fapl2 = new_fapl;
	else
	    fapl2 = fapl;
	/*
	 * Create a sec2 file
	 */
	if((my_fapl = H5Pcopy(fapl2)) < 0)
	    goto error;
	/* Create the file */
	sprintf(fname, "%s%s", new_format? "latest_":"", FILENAME[0]);
	if((fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl)) < 0) 
	    goto error;

	/* Flush the file */
	if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0)
	    goto error;
    
	/* Close the property list */
	if(H5Pclose(my_fapl) < 0)
	    goto error;

	/*
	 * Create a core file
	 */
	/* Create a copy of file access property list */
	if((my_fapl = H5Pcopy(fapl2)) < 0)
	    goto error;

	/* Setup the fapl for the family file driver */
	if(H5Pset_fapl_core(my_fapl, (size_t)CORE_INCREMENT, TRUE) < 0)
	    goto error;

	/* Create the file */
	sprintf(fname, "%s%s", new_format? "latest_":"", FILENAME[1]);
	if((fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl)) < 0) 
	    goto error;

	/* Flush the file */
	if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0)
	    goto error;

	/* Close the property list */
	if(H5Pclose(my_fapl) < 0)
	    goto error;

	/*
	 * Create a family file
	 */
	/* Create a copy of file access property list */
	if((my_fapl = H5Pcopy(fapl2)) < 0)
	    goto error;

	/* Setup the fapl for the family file driver */
	if(H5Pset_fapl_family(my_fapl, (hsize_t)FAMILY_SIZE, H5P_DEFAULT) < 0)
	    goto error;

	/* Create the file */
	sprintf(fname, "%s%s", new_format? "latest_":"", FILENAME[2]);
	if((fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl)) < 0) 
	    goto error;

	/* Flush the file */
	if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0)
	    goto error;

	/* Close the property list */
	if(H5Pclose(my_fapl) < 0)
	    goto error;

	/*
	 * Create a split file
	 */
	 /* Create a copy of file access property list */
	my_fapl = H5Pcopy(fapl2);

	/* Setup the fapl for the split file driver */
	H5Pset_fapl_split(my_fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT);

	/* Create the file */
	sprintf(fname, "%s%s", new_format? "latest_":"", FILENAME[3]);
	if((fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl)) < 0)
	    goto error;

	/* Flush the file */
	if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0)
	    goto error;

	/* Close the property list */
	if(H5Pclose(my_fapl) < 0)
	    goto error;

	/* 
	 * Create a sec2 file but change its superblock version # 
	 */
	/* Create a copy of file access property list */
	if((my_fapl = H5Pcopy(fapl2)) < 0)
	    goto error;
	/* Create the file */
	sprintf(fname, "%s%s", new_format? "latest_":"", FILENAME[4]);
	if((fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl)) < 0) 
	    goto error;

	/* Flush the file */
	if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0)
	    goto error;
    
	/* Close the property list */
	if(H5Pclose(my_fapl) < 0)
	    goto error;

	/* Open the test file via system call "open" */
	if((fd = HDopen(fname, O_RDWR, 0666)) < 0) {
	    HDfprintf(stdout, "cannot open the file\n");
	    goto error;
	}

	/* Position the file to superblock version via system call "lseek" */
	if(HDlseek(fd, (off_t)SUPER_VERS_OFF, SEEK_SET) < 0) {
	    HDfprintf(stdout, "cannot lseek the file superblock version\n");
	    goto error;
	}

	/* Change to an incorrect superblock version */
	super_vers = SUPER_VERS_LATEST + 1;
	/* Write to the file via system call "write" */
	if((bytes_written = HDwrite(fd, &super_vers, (size_t)SUPER_VERS_SIZE)) < 0) {
	    HDfprintf(stdout, "cannot write to the file with incorrect superblock version\n");
	    goto error;
	}

	/* Close the file via system call "close" */
	if(HDclose(fd) < 0) {
	    HDfprintf(stdout, "cannot close the file\n");
	    goto error;
	}

    } /* end for */

    /* Close the property lists */
    if(H5Pclose(fapl) < 0)
	goto error;
    if(H5Pclose(new_fapl) < 0)
	goto error;

    fflush(stdout);
    fflush(stderr);

    /* Not going through library closing by calling _exit(0) with success */
    HD_exit(0);

error:

    /* Exit with failure */
    HD_exit(1);
}
Esempio n. 15
0
/*-------------------------------------------------------------------------
 * Function:    test_flush
 *
 * Purpose:     This function tests flushing individual objects' metadata
 *              from the metadata cache.
 *
 * Return:      0 on Success, 1 on Failure
 *
 * Programmer:  Mike McGreevy
 *              July 1, 2010
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
herr_t test_flush(void) 
{
    /**************************************************************************
     *
     * Test Description:
     *
     * This test will build an HDF5 file with several objects in a varying 
     * hierarchical layout. It will then attempt to flush the objects
     * in the file one by one, individually, using the four H5*flush
     * routines (D,G,T, and O). After each call to either create or flush an 
     * object, a series of verifications will occur on each object in the file.
     *
     * Each verification consists of spawning off a new process and determining
     * if the object can be opened and its information retreived in said 
     * alternate process. It reports the results, which are compared to an 
     * expected value (either that the object can be found on disk, or that it
     * cannot).
     *
     * Note that to spawn a verification, this program sends a signal (by creating
     * a file on disk) to the test script controlling it, indicating how to 
     * run the verification.
     * 
     * Implementation is funky, but basically, an example: 
     *
     * Step 1. Dataset is created.
     * Step 2. Verify that dataset can't be opened by separate process, as
     *         it should not have been flushed to disk yet.
     * Step 3. Group is created.
     * Step 4. Verify that group can't be opened by separate process.
     * Step 5. H5Gflush is called on the group.
     * Step 6. Verify that group CAN be opened, but dataset still has
     *         yet to hit disk, and CANNOT be opened. Success! Only the group 
     *         was flushed.
     *
     **************************************************************************/

    /**************************************************************************
      * Generated Test File will look like this:
      * 
      * GROUP "/"
      *   DATASET "Dataset1"
      *   GROUP "Group1" {
      *     DATASET "Dataset2"
      *     GROUP "Group2" {
      *       DATATYPE "CommittedDatatype3"
      *     }
      *   }
      *   GROUP "Group3" {
      *     DATASET "Dataset3"
      *     DATATYPE "CommittedDatatype2"
      *   }
      *   DATATYPE "CommittedDatatype1"
     **************************************************************************/

    /* Variables */
    hid_t fid,gid,gid2,gid3,sid,tid1,tid2,tid3,did,did2,did3,rid,fapl,status = 0;
    hsize_t dims[2] = {3,5};

    /* Testing Message */
    HDfprintf(stdout, "Testing individual object flush behavior:\n");

    /* Cleanup any old error or signal files */
    CLEANUP_FILES;
    
    /* ================ */
    /* CREATE TEST FILE */
    /* ================ */

    /* Create file, open root group - have to use latest file format for SWMR */
    if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) TEST_ERROR;
    if (H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) TEST_ERROR; 
    if ((fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC|H5F_ACC_SWMR_WRITE, H5P_DEFAULT, fapl)) < 0) TEST_ERROR;
    if ((rid = H5Gopen2(fid, "/", H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Create data space and types */
    if ((sid = H5Screate_simple(2, dims, dims)) < 0) TEST_ERROR;
    if ((tid1 = H5Tcopy(H5T_NATIVE_INT)) < 0) TEST_ERROR;
    if ((tid2 = H5Tcopy(H5T_NATIVE_CHAR)) < 0) TEST_ERROR;
    if ((tid3 = H5Tcopy(H5T_NATIVE_LONG)) < 0) TEST_ERROR;

    /* Create Group1 */
    if ((gid = H5Gcreate2(fid, "Group1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Create Group2 */
    if ((gid2 = H5Gcreate2(gid, "Group2", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Create Group3 */
    if ((gid3 = H5Gcreate2(fid, "Group3", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Create Dataset1 */
    if ((did = H5Dcreate2(fid, "Dataset1", tid1, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Create Dataset2 */
    if ((did2 = H5Dcreate2(gid, "Dataset2", tid3, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Create Dataset3 */
    if ((did3 = H5Dcreate2(gid3, "Dataset3", tid2, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Create CommittedDatatype1 */
    if ((status = H5Tcommit2(fid, "CommittedDatatype1", tid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Create CommittedDatatype2 */
    if ((status = H5Tcommit2(gid2, "CommittedDatatype2", tid2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Create CommittedDatatype3 */
    if ((status = H5Tcommit2(gid3, "CommittedDatatype3", tid3, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* ============ */
    /* FLUSH GROUPS */
    /* ============ */

    /* Test */
    TESTING("to ensure H5Gflush correctly flushes single groups");

    /* First, let's verify that nothing is currently flushed. */
    if (run_flush_verification_process(RG, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G1, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G2, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G3, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D1, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D2, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D3, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T1, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T2, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T3, NOT_FLUSHED) != 0) TEST_ERROR;

    /* Then, flush the root group and verify it's the only thing on disk */
    if ((status = H5Gflush(rid)) < 0) TEST_ERROR;
    if (run_flush_verification_process(RG, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G1, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G2, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G3, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D1, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D2, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D3, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T1, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T2, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T3, NOT_FLUSHED) != 0) TEST_ERROR;

    /* Flush Group1 and Verify it is recently flushed, and nothing 
     * else has changed. */
    if ((status = H5Gflush(gid)) < 0) TEST_ERROR;
    if (run_flush_verification_process(RG, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G2, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G3, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D1, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D2, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D3, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T1, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T2, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T3, NOT_FLUSHED) != 0) TEST_ERROR;

    /* Flush Group2 and Verify it is recently flushed, and nothing 
     * else has changed. */
    if ((status = H5Gflush(gid2)) < 0) TEST_ERROR;
    if (run_flush_verification_process(RG, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G2, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G3, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D1, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D2, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D3, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T1, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T2, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T3, NOT_FLUSHED) != 0) TEST_ERROR;

    PASSED();

    /* ============== */
    /* FLUSH DATASETS */
    /* ============== */

    /* Test */
    TESTING("to ensure H5Dflush correctly flushes single datasets");

    /* Flush Dataset1 and verify it's the only thing that hits disk. */
    if ((status = H5Dflush(did)) < 0) TEST_ERROR;
    if (run_flush_verification_process(RG, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G2, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G3, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D2, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D3, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T1, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T2, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T3, NOT_FLUSHED) != 0) TEST_ERROR;

    /* Flush Dataset2 and verify it's the only thing that hits disk. */
    if ((status = H5Dflush(did2)) < 0) TEST_ERROR;
    if (run_flush_verification_process(RG, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G2, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G3, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D2, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D3, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T1, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T2, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T3, NOT_FLUSHED) != 0) TEST_ERROR;

    PASSED();

    /* =============== */
    /* FLUSH DATATYPES */
    /* =============== */

    /* Test */
    TESTING("to ensure H5Tflush correctly flushes single datatypes");

    /* Flush Datatype 1 and verify it's the only thing that hits disk. */
    if ((status = H5Tflush(tid1)) < 0) TEST_ERROR;
    if (run_flush_verification_process(RG, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G2, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G3, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D2, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D3, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T2, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T3, NOT_FLUSHED) != 0) TEST_ERROR;

    /* Flush Datatype 2 and verify it's the only thing that hits disk. */
    if ((status = H5Tflush(tid2)) < 0) TEST_ERROR;
    if (run_flush_verification_process(RG, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G2, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G3, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D2, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D3, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T2, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T3, NOT_FLUSHED) != 0) TEST_ERROR;

    PASSED();
    
    /* ============= */
    /* FLUSH OBJECTS */
    /* ============= */

    /* Test */
    TESTING("to ensure H5Oflush correctly flushes single objects");

    /* Flush Group3 and verify it's the only thing that hits disk. */
    if ((status = H5Oflush(gid3)) < 0) TEST_ERROR;
    if (run_flush_verification_process(RG, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G2, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G3, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D2, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D3, NOT_FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T2, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T3, NOT_FLUSHED) != 0) TEST_ERROR;

    /* Flush Dataset3 and verify it's the only thing that hits disk. */
    if ((status = H5Oflush(did3)) < 0) TEST_ERROR;
    if (run_flush_verification_process(RG, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G2, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G3, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D2, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D3, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T2, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T3, NOT_FLUSHED) != 0) TEST_ERROR;

    /* Flush CommittedDatatype3 and verify it's the only thing that hits disk. */
    if ((status = H5Oflush(tid3)) < 0) TEST_ERROR;
    if (run_flush_verification_process(RG, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G2, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(G3, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D2, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(D3, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T1, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T2, FLUSHED) != 0) TEST_ERROR;
    if (run_flush_verification_process(T3, FLUSHED) != 0) TEST_ERROR;

    PASSED();

    /* ================== */
    /* Cleanup and Return */  
    /* ================== */
    if (H5Pclose(fapl) < 0) TEST_ERROR;
    if (H5Gclose(gid) < 0) TEST_ERROR;
    if (H5Gclose(gid2) < 0) TEST_ERROR;
    if (H5Dclose(did) < 0) TEST_ERROR;
    if (H5Dclose(did2) < 0) TEST_ERROR;
    if (H5Gclose(rid) < 0) TEST_ERROR;
    if (H5Fclose(fid) < 0) TEST_ERROR;

    /* Delete test file */
    HDremove(FILENAME);

    if (end_verification() < 0) TEST_ERROR;

    return SUCCEED;

error:
    return FAIL;

} /* end test_flush */
Esempio n. 16
0
int
main()
{
   printf("\n*** Checking HDF5 dimscales detach.\n");
   printf("*** Creating a file with two vars with one dimension scale...");
   {
#if 0
      hid_t cparmsid;
#endif
      hid_t fileid, grpid, spaceid, var1_id, var2_id, dimscaleid;
      hid_t fcpl_id, fapl_id, create_propid, access_propid;
      hsize_t dims[NDIMS] = {DIM_LEN};
      char dimscale_wo_var[STR_LEN];
      float data = 42;

      /* Create file. */
      if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR;
      if (H5Pset_fclose_degree(fapl_id, H5F_CLOSE_STRONG)) ERR;
      if (H5Pset_cache(fapl_id, 0, CHUNK_CACHE_NELEMS, CHUNK_CACHE_SIZE,
		       CHUNK_CACHE_PREEMPTION) < 0) ERR;
      if (H5Pset_libver_bounds(fapl_id, H5F_LIBVER_18, H5F_LIBVER_18) < 0) ERR;
      if ((fcpl_id = H5Pcreate(H5P_FILE_CREATE)) < 0) ERR;
      if (H5Pset_link_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED |
					       H5P_CRT_ORDER_INDEXED)) < 0) ERR;
      if (H5Pset_attr_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED |
					       H5P_CRT_ORDER_INDEXED)) < 0) ERR;
      if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, fcpl_id, fapl_id)) < 0) ERR;
      if (H5Pclose(fapl_id) < 0) ERR;
      if (H5Pclose(fcpl_id) < 0) ERR;
      if ((grpid = H5Gopen2(fileid, "/", H5P_DEFAULT)) < 0) ERR;

      /* Create dimension scale. */
      if ((create_propid = H5Pcreate(H5P_DATASET_CREATE)) < 0) ERR;
      if (H5Pset_attr_creation_order(create_propid, H5P_CRT_ORDER_TRACKED|
				     H5P_CRT_ORDER_INDEXED) < 0) ERR;
      if ((spaceid = H5Screate_simple(1, dims, dims)) < 0) ERR;
      if ((dimscaleid = H5Dcreate1(grpid, DIMSCALE_NAME, H5T_IEEE_F32BE,
				   spaceid, create_propid)) < 0) ERR;
      if (H5Sclose(spaceid) < 0) ERR;
      if (H5Pclose(create_propid) < 0) ERR;
      sprintf(dimscale_wo_var, "%s%10d", DIM_WITHOUT_VARIABLE, DIM_LEN);
      if (H5DSset_scale(dimscaleid, dimscale_wo_var) < 0) ERR;

      /* Create a variable that uses this dimension scale. */
      if ((access_propid = H5Pcreate(H5P_DATASET_ACCESS)) < 0) ERR;
      if (H5Pset_chunk_cache(access_propid, CHUNK_CACHE_NELEMS,
   			     CHUNK_CACHE_SIZE, CHUNK_CACHE_PREEMPTION) < 0) ERR;
      if ((create_propid = H5Pcreate(H5P_DATASET_CREATE)) < 0) ERR;
      if (H5Pset_fill_value(create_propid, H5T_NATIVE_FLOAT, &data) < 0) ERR;
      if (H5Pset_layout(create_propid, H5D_CONTIGUOUS) < 0) ERR;
      if (H5Pset_attr_creation_order(create_propid, H5P_CRT_ORDER_TRACKED|
				     H5P_CRT_ORDER_INDEXED) < 0) ERR;
      if ((spaceid = H5Screate_simple(NDIMS, dims, dims)) < 0) ERR;
      if ((var1_id = H5Dcreate2(grpid, VAR1_NAME, H5T_NATIVE_FLOAT, spaceid, 
				H5P_DEFAULT, create_propid, access_propid)) < 0) ERR;
      if (H5Pclose(create_propid) < 0) ERR;
      if (H5Pclose(access_propid) < 0) ERR;
      if (H5Sclose(spaceid) < 0) ERR;
      if (H5DSattach_scale(var1_id, dimscaleid, 0) < 0) ERR;

      /* Create another variable that uses this dimension scale. */
      if ((access_propid = H5Pcreate(H5P_DATASET_ACCESS)) < 0) ERR;
      if (H5Pset_chunk_cache(access_propid, CHUNK_CACHE_NELEMS,
   			     CHUNK_CACHE_SIZE, CHUNK_CACHE_PREEMPTION) < 0) ERR;
      if ((create_propid = H5Pcreate(H5P_DATASET_CREATE)) < 0) ERR;
      if (H5Pset_fill_value(create_propid, H5T_NATIVE_FLOAT, &data) < 0) ERR;
      if (H5Pset_layout(create_propid, H5D_CONTIGUOUS) < 0) ERR;
      if (H5Pset_attr_creation_order(create_propid, H5P_CRT_ORDER_TRACKED|
				     H5P_CRT_ORDER_INDEXED) < 0) ERR;
      if ((spaceid = H5Screate_simple(NDIMS, dims, dims)) < 0) ERR;
      if ((var2_id = H5Dcreate2(grpid, VAR2_NAME, H5T_NATIVE_FLOAT, spaceid, 
				H5P_DEFAULT, create_propid, access_propid)) < 0) ERR;
      if (H5Pclose(create_propid) < 0) ERR;
      if (H5Pclose(access_propid) < 0) ERR;
      if (H5Sclose(spaceid) < 0) ERR;
      if (H5DSattach_scale(var2_id, dimscaleid, 0) < 0) ERR;

      /* Now detach the scales and remove the dimscale. This doesn't
       * work if I reverse the order of the statements. */
      if (H5DSdetach_scale(var2_id, dimscaleid, 0) < 0) ERR;     
      if (H5DSdetach_scale(var1_id, dimscaleid, 0) < 0) ERR;      

      /* Fold up our tents. */
      if (H5Dclose(var1_id) < 0) ERR;
      if (H5Dclose(dimscaleid) < 0) ERR;
      if (H5Gclose(grpid) < 0) ERR;
      if (H5Fclose(fileid) < 0) ERR;

      /* /\* Now read the file and check it. *\/ */
      /* { */
      /* 	 hid_t fileid, spaceid = 0, datasetid = 0; */
      /* 	 hsize_t num_obj, i; */
      /* 	 int obj_class; */
      /* 	 char obj_name[STR_LEN + 1]; */
      /* 	 char dimscale_name[STR_LEN+1]; */
      /* 	 htri_t is_scale; */
      /* 	 char label[STR_LEN+1]; */
      /* 	 int num_scales; */
      /* 	 hsize_t dims[1], maxdims[1]; */
      /* 	 H5G_stat_t statbuf; */
      /* 	 HDF5_OBJID_T dimscale_obj, vars_dimscale_obj; */
      /* 	 struct nc_hdf5_link_info link_info; */
      /* 	 hsize_t idx = 0; */

      /* 	 /\* Open the file. *\/ */
      /* 	 if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) ERR; */
      /* 	 if ((grpid = H5Gopen2(fileid, "/", H5P_DEFAULT)) < 0) ERR; */
      
      /* 	 /\* Loop through objects in the root group. *\/ */
      /* 	 if (H5Gget_num_objs(fileid, &num_obj) < 0) ERR; */
      /* 	 for (i = 0; i < num_obj; i++) */
      /* 	 { */

      /* 	    if (H5Literate(grpid, H5_INDEX_CRT_ORDER, H5_ITER_INC,  */
      /* 			   &idx, visit_link, (void *)&link_info) < 0) ERR; */

      /* 	    printf("Encountered: HDF5 object link_info.name %s\n", link_info.name); */

      /* 	    /\* Deal with object based on its obj_class. *\/ */
      /* 	    switch(link_info.obj_type) */
      /* 	    { */
      /* 	       case H5I_GROUP: */
      /* 		  break; */
      /* 	       case H5I_DATASET: */
      /* 		  /\* Open the dataset. *\/ */
      /* 		  if ((datasetid = H5Dopen1(fileid, link_info.name)) < 0) ERR; */

      /* 		  if ((spaceid = H5Dget_space(datasetid)) < 0) ERR; */
      /* 		  if (H5Sget_simple_extent_dims(spaceid, dims, maxdims) < 0) ERR; */
      /* 		  if (maxdims[0] != DIM_LEN) ERR; */
      /* 		  if (H5Sclose(spaceid) < 0) ERR; */

      /* 		  /\* Is this a dimscale? *\/ */
      /* 		  if ((is_scale = H5DSis_scale(datasetid)) < 0) ERR; */
      /* 		  if (is_scale && strcmp(link_info.name, DIMSCALE_NAME)) ERR; */
      /* 		  if (is_scale) */
      /* 		  { */
      /* 		     /\* A dimscale comes with a NAME attribute, in */
      /* 		      * addition to its real name. *\/ */
      /* 		     if (H5DSget_scale_name(datasetid, dimscale_name, STR_LEN) < 0) ERR; */
      /* 		     if (strcmp(dimscale_name, dimscale_wo_var)) ERR; */

      /* 		     /\* fileno and objno uniquely identify an object and a */
      /* 		      * HDF5 file. *\/ */
      /* 		     if (H5Gget_objinfo(datasetid, ".", 1, &statbuf) < 0) ERR;  */
      /* 		     dimscale_obj.fileno[0] = statbuf.fileno[0]; */
      /* 		     dimscale_obj.objno[0] = statbuf.objno[0]; */
      /* 		     dimscale_obj.fileno[1] = statbuf.fileno[1]; */
      /* 		     dimscale_obj.objno[1] = statbuf.objno[1]; */
      /* 		     /\*printf("scale statbuf.fileno = %d statbuf.objno = %d\n", */
      /* 		       statbuf.fileno, statbuf.objno);*\/ */

      /* 		  } */
      /* 		  else */
      /* 		  { */
      /* 		     /\* Here's how to get the number of scales attached */
      /* 		      * to the dataset's dimension 0. *\/ */
      /* 		     if ((num_scales = H5DSget_num_scales(datasetid, 0)) < 0) ERR; */
      /* 		     if (num_scales != 1) ERR; */

      /* 		     /\* Go through all dimscales for this var and learn about them. *\/ */
      /* 		     if (H5DSiterate_scales(datasetid, 0, NULL, alien_visitor, */
      /* 					    &vars_dimscale_obj) < 0) ERR; */
      /* 		     /\*printf("vars_dimscale_obj.fileno = %d vars_dimscale_obj.objno = %d\n", */
      /* 		       vars_dimscale_obj.fileno, vars_dimscale_obj.objno);*\/ */
      /* 		     /\* if (vars_dimscale_obj.fileno[0] != dimscale_obj.fileno[0] || *\/ */
      /* 		     /\* 	 vars_dimscale_obj.objno[0] != dimscale_obj.objno[0] || *\/ */
      /* 		     /\* 	 vars_dimscale_obj.fileno[1] != dimscale_obj.fileno[1] || *\/ */
      /* 		     /\* 	 vars_dimscale_obj.objno[1] != dimscale_obj.objno[1]) ERR; *\/ */
		  
      /* 		     /\* There's also a label for dimension 0. *\/ */
      /* 		     if (H5DSget_label(datasetid, 0, label, STR_LEN) < 0) ERR; */

      /* 		     /\*printf("found non-scale dataset %s, label %s\n", link_info.name, label);*\/ */
      /* 		  } */
      /* 		  if (H5Dclose(datasetid) < 0) ERR; */
      /* 		  break; */
      /* 	       case H5I_DATATYPE: */
      /* 		  break; */
      /* 	       default: */
      /* 		  printf("Unknown object!"); */
      /* 		  ERR; */
      /* 	    } */
      /* 	 } */

      /* 	 /\* Close up the shop. *\/ */
      /* 	 if (H5Fclose(fileid) < 0) ERR; */
      /*   }*/
   }
   SUMMARIZE_ERR;
   FINAL_RESULTS;
}
Esempio n. 17
0
int
main(void)
{
    hid_t faplid        = -1;   /* file access property list ID (all files) */

    hid_t src_sid       = -1;   /* source dataset's dataspace ID            */
    hid_t src_dcplid    = -1;   /* source dataset property list ID          */

    hid_t vds_sid       = -1;   /* VDS dataspace ID                         */
    hid_t vds_dcplid    = -1;   /* VDS dataset property list ID             */

    hid_t fid           = -1;   /* HDF5 file ID                             */
    hid_t did           = -1;   /* dataset ID                               */

    hsize_t start[RANK];        /* starting point for hyperslab             */
    int map_start       = -1;   /* starting point in the VDS map            */

    int i;                      /* iterator                         */


    /* Start by creating the virtual dataset (VDS) dataspace and creation
     * property list. The individual source datasets are then created
     * and the VDS map (stored in the VDS property list) is updated.
     */

    /* Create VDS dcpl */
    if((vds_dcplid = H5Pcreate(H5P_DATASET_CREATE)) < 0)
        TEST_ERROR
    if(H5Pset_fill_value(vds_dcplid, VDS_DATATYPE,
                &VDS_FILL_VALUE) < 0)
        TEST_ERROR

    /* Create VDS dataspace */
    if((vds_sid = H5Screate_simple(RANK, VDS_DIMS,
                    VDS_MAX_DIMS)) < 0)
        TEST_ERROR

    /************************************
     * Create source files and datasets *
     ************************************/

    start[0] = 0;
    start[1] = 0;
    start[2] = 0;
    map_start = 0;

    /* All SWMR files need to use the latest file format */
    if((faplid = H5Pcreate(H5P_FILE_ACCESS)) < 0)
        TEST_ERROR
    if(H5Pset_libver_bounds(faplid, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
        TEST_ERROR

    for(i = 0; i < N_SOURCES; i++) {

        /* source dataset dcpl */
        if((src_dcplid = H5Pcreate(H5P_DATASET_CREATE)) < 0)
            TEST_ERROR
        if(H5Pset_chunk(src_dcplid, RANK, PLANES[i]) < 0)
            TEST_ERROR
        if(H5Pset_fill_value(src_dcplid, SOURCE_DATATYPE,
                    &FILL_VALUES[i]) < 0)
            TEST_ERROR

        /* Use a mix of compressed and uncompressed datasets */
        if(0 != i % 2)
            if(H5Pset_deflate(src_dcplid, COMPRESSION_LEVEL) < 0)
                TEST_ERROR

        /* Create source file, dataspace, and dataset */
        if((fid = H5Fcreate(FILE_NAMES[i], H5F_ACC_TRUNC,
                        H5P_DEFAULT, faplid)) < 0)
            TEST_ERROR
        if((src_sid = H5Screate_simple(RANK, DIMS[i],
                        MAX_DIMS[i])) < 0)
            TEST_ERROR
        if((did = H5Dcreate2(fid, SOURCE_DSET_NAME,
                        SOURCE_DATATYPE, src_sid,
                        H5P_DEFAULT, src_dcplid, H5P_DEFAULT)) < 0)
            TEST_ERROR

        /* set up hyperslabs for source and destination datasets */
        start[1] = 0;
        if(H5Sselect_hyperslab(src_sid, H5S_SELECT_SET, start, NULL,
                    MAX_DIMS[i], NULL) < 0)
            TEST_ERROR
        start[1] = map_start;
        if(H5Sselect_hyperslab(vds_sid, H5S_SELECT_SET, start, NULL,
                    MAX_DIMS[i], NULL) < 0)
            TEST_ERROR
        map_start += PLANES[i][1];

        /* Add VDS mapping */
        if(H5Pset_virtual(vds_dcplid, vds_sid, FILE_NAMES[i],
                    SOURCE_DSET_PATH, src_sid) < 0)
            TEST_ERROR

        /* close */
        if(H5Sclose(src_sid) < 0)
            TEST_ERROR
        if(H5Pclose(src_dcplid) < 0)
            TEST_ERROR
        if(H5Dclose(did) < 0)
            TEST_ERROR
        if(H5Fclose(fid) < 0)
            TEST_ERROR

    } /* end for */


    /*******************
     * Create VDS file *
     *******************/

    /* file */
    if((fid = H5Fcreate(VDS_FILE_NAME, H5F_ACC_TRUNC,
                    H5P_DEFAULT, faplid)) < 0)
        TEST_ERROR

    /* dataset */
    if((did = H5Dcreate2(fid, VDS_DSET_NAME, VDS_DATATYPE, vds_sid,
                    H5P_DEFAULT, vds_dcplid, H5P_DEFAULT)) < 0)
        TEST_ERROR

    /* close */
    if(H5Pclose(faplid) < 0)
        TEST_ERROR
    if(H5Pclose(vds_dcplid) < 0)
        TEST_ERROR
    if(H5Sclose(vds_sid) < 0)
        TEST_ERROR
    if(H5Dclose(did) < 0)
        TEST_ERROR
    if(H5Fclose(fid) < 0)
        TEST_ERROR

    return EXIT_SUCCESS;

error:

    H5E_BEGIN_TRY {
        if(faplid >= 0)
            (void)H5Pclose(faplid);
        if(src_sid >= 0)
            (void)H5Sclose(src_sid);
        if(src_dcplid >= 0)
            (void)H5Pclose(src_dcplid);
        if(vds_sid >= 0)
            (void)H5Sclose(vds_sid);
        if(vds_dcplid >= 0)
            (void)H5Pclose(vds_dcplid);
        if(fid >= 0)
            (void)H5Fclose(fid);
        if(did >= 0)
            (void)H5Dclose(did);
    } H5E_END_TRY

    return EXIT_FAILURE;

} /* end main */
Esempio n. 18
0
/*-------------------------------------------------------------------------
 * 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() */
Esempio n. 19
0
/*-------------------------------------------------------------------------
 * Function:    main
 *
 * Purpose:     Tests the plugin module (H5PL)
 *
 * Return:      EXIT_SUCCESS/EXIT_FAILURE
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    char        filename[FILENAME_BUF_SIZE];
    hid_t       fid = -1;
    hid_t       old_ff_fapl_id = -1;
    hid_t       new_ff_fapl_id = -1;
    unsigned    new_format;
    int         nerrors = 0;

    /*******************************************************************/
    /* ENSURE THAT WRITING TO DATASETS AND CREATING GROUPS WORKS       */
    /*******************************************************************/
    /* Test with old & new format groups */
    for (new_format = FALSE; new_format <= TRUE; new_format++) {
        hid_t my_fapl_id;

        /* Testing setup */
        h5_reset();

        /* Get a VFD-dependent filename */
        if ((old_ff_fapl_id = h5_fileaccess()) < 0)
            TEST_ERROR;

        /* Turn off the chunk cache, so all the chunks are immediately written to disk */
        if (disable_chunk_cache(old_ff_fapl_id) < 0)
            TEST_ERROR;

        /* Fix up the filename for the VFD */
        h5_fixname(FILENAME[0], old_ff_fapl_id, filename, sizeof(filename));

        /* Set the FAPL for the type of format */
        if (new_format) {
            HDputs("\nTesting with new file format:");
            /* Copy the file access property list and set the latest file format on it */
            if ((new_ff_fapl_id = H5Pcopy(old_ff_fapl_id)) < 0)
                TEST_ERROR;
            if (H5Pset_libver_bounds(new_ff_fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
                TEST_ERROR;

            my_fapl_id = new_ff_fapl_id;
        }
        else {
            HDputs("Testing with old file format:");
            my_fapl_id = old_ff_fapl_id;
        }

        /* Create the file for this test */
        if ((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl_id)) < 0)
            TEST_ERROR;

        /* Test creating datasets and writing to them using plugin filters */
        nerrors += (test_dataset_write_with_filters(fid) < 0 ? 1 : 0);

        /* Test creating groups using dynamically-loaded plugin filters */
        nerrors += (test_creating_groups_using_plugins(fid) < 0 ? 1 : 0);

        if (H5Fclose(fid) < 0)
            TEST_ERROR;

        /* Close FAPLs */
        if (H5Pclose(old_ff_fapl_id) < 0)
            TEST_ERROR;
        if (new_format) {
            if (H5Pclose(new_ff_fapl_id) < 0)
                TEST_ERROR;
        }

        /* Restore the default error handler (set in h5_reset()) */
        h5_restore_err();

        /*******************************************************************/
        /* ENSURE THAT READING FROM DATASETS AND OPENING GROUPS WORKS      */
        /*******************************************************************/

        HDputs("\nTesting reading data with with dynamic plugin filters:");

        /* Close the library so that all loaded plugin libraries are unloaded */
        h5_reset();
        if ((old_ff_fapl_id = h5_fileaccess()) < 0)
            TEST_ERROR;

        /* Set the FAPL for the type of format */
        if (new_format) {
            /* Copy the file access property list and set the latest file format on it */
            if ((new_ff_fapl_id = H5Pcopy(old_ff_fapl_id)) < 0)
                TEST_ERROR;
            if (H5Pset_libver_bounds(new_ff_fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
                TEST_ERROR;

            my_fapl_id = new_ff_fapl_id;
        }
        else
            my_fapl_id = old_ff_fapl_id;

        /* Reopen the file for testing data reading */
        if ((fid = H5Fopen(filename, H5F_ACC_RDONLY, my_fapl_id)) < 0)
            TEST_ERROR;

        /* Read the data with filters */
        nerrors += (test_dataset_read_with_filters(fid) < 0 ? 1 : 0);

        /* Test creating groups using dynamically-loaded plugin filters */
        nerrors += (test_opening_groups_using_plugins(fid) < 0  ? 1 : 0);

        /* Close FAPLs */
        if (H5Pclose(old_ff_fapl_id) < 0)
            TEST_ERROR;
        if (new_format) {
            if (H5Pclose(new_ff_fapl_id) < 0)
                TEST_ERROR;
        }

        /* Restore the default error handler (set in h5_reset()) */
        h5_restore_err();

        /*******************************************************************/
        /* ENSURE THAT DISABLING FILTER PLUGINS VIA THE FILTER FLAGS WORKS */
        /*******************************************************************/

        /* Close the library so that all loaded plugin libraries are unloaded */
        h5_reset();
        if ((old_ff_fapl_id = h5_fileaccess()) < 0)
            TEST_ERROR;

        /* Set the FAPL for the type of format */
        if (new_format) {
            /* Copy the file access property list and set the latest file format on it */
            if ((new_ff_fapl_id = H5Pcopy(old_ff_fapl_id)) < 0)
                TEST_ERROR;
            if (H5Pset_libver_bounds(new_ff_fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
                TEST_ERROR;

            my_fapl_id = new_ff_fapl_id;
        }
        else
            my_fapl_id = old_ff_fapl_id;

        /* Reopen the file for testing data reading */
        if ((fid = H5Fopen(filename, H5F_ACC_RDONLY, my_fapl_id)) < 0)
            TEST_ERROR;

        /* When filters are disabled, make sure we can't read data from a
        * dataset that requires a filter plugin.
        */
        nerrors += (test_no_read_when_plugins_disabled(fid) < 0  ? 1 : 0);

        if (H5Fclose(fid) < 0)
            TEST_ERROR;

        /*********************/
        /* CLEAN UP          */
        /*********************/
        /* Close FAPLs */
        if (new_format) {
            if (H5Pclose(new_ff_fapl_id) < 0)
                TEST_ERROR;
        }
        else {
            /* Restore the default error handler (set in h5_reset()) */
            h5_restore_err();

            if (H5Pclose(old_ff_fapl_id) < 0)
                TEST_ERROR;
        }

        /* Free up saved arrays */
        free_2D_array(&orig_deflate_g);
        free_2D_array(&orig_dynlib1_g);
        free_2D_array(&orig_dynlib2_g);
        free_2D_array(&orig_dynlib4_g);
    } /* end for */

    h5_cleanup(FILENAME, old_ff_fapl_id);

    /************************************/
    /* TEST THE FILTER PLUGIN API CALLS */
    /************************************/

    /* Test the APIs for access to the filter plugin path table */
    nerrors += (test_path_api_calls() < 0  ? 1 : 0);

    if (nerrors)
        TEST_ERROR;

    HDprintf("All plugin tests passed.\n");

    HDexit(EXIT_SUCCESS);

error:
    H5E_BEGIN_TRY {
        H5Fclose(fid);
        H5Pclose(old_ff_fapl_id);
        H5Pclose(new_ff_fapl_id);
    } H5E_END_TRY

    /* Free up saved arrays (NULLs okay) */
    free_2D_array(&orig_deflate_g);
    free_2D_array(&orig_dynlib1_g);
    free_2D_array(&orig_dynlib2_g);
    free_2D_array(&orig_dynlib4_g);

    nerrors = MAX(1, nerrors);
    HDprintf("***** %d PLUGIN TEST%s FAILED! *****\n", nerrors, 1 == nerrors ? "" : "S");
    HDexit(EXIT_FAILURE);
} /* end main() */
Esempio n. 20
0
int
main()
{
   printf("\n*** Checking HDF5 group functions.\n");
   printf("*** Checking out root group...");
   {
      hid_t fileid, grpid, access_plistid;

      /* Open the root group of a new file. */
      if ((access_plistid = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR;
      if (H5Pset_fclose_degree(access_plistid, H5F_CLOSE_SEMI)) ERR;
      if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT,
			      access_plistid)) < 0) ERR;
      if ((grpid = H5Gopen(fileid, "/")) < 0) ERR;
      if (H5Gclose(grpid) < 0 ||
	  H5Fclose(fileid) < 0) ERR;

      /* Reopen file and root group. */
      if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDWR,
			    access_plistid)) < 0) ERR;
      if ((grpid = H5Gopen(fileid, "/")) < 0) ERR;
      if (H5Gclose(grpid) < 0 ||
	  H5Fclose(fileid) < 0)
	 ERR;
   }

   SUMMARIZE_ERR;
   printf("*** Checking out H5Gmove...");
   {

      hid_t fileid, grpid;
      hid_t datasetid, spaceid;

      /* Create file with one dataset. */
      if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT,
			      H5P_DEFAULT)) < 0) ERR;
      if ((grpid = H5Gopen(fileid, "/")) < 0) ERR;
      if ((spaceid = H5Screate(H5S_SCALAR)) < 0) ERR;
      if ((datasetid = H5Dcreate(grpid, DATASET_NAME, H5T_NATIVE_INT,
				 spaceid, H5P_DEFAULT)) < 0) ERR;
      if (H5Dclose(datasetid) < 0 ||
	  H5Sclose(spaceid) < 0 ||
	  H5Gclose(grpid) < 0 ||
	  H5Fclose(fileid) < 0) ERR;

      /* Reopen file and check, then rename dataset. */
      if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDWR,
			    H5P_DEFAULT)) < 0) ERR;
      if ((grpid = H5Gopen(fileid, "/")) < 0) ERR;
      if ((datasetid = H5Dopen1(grpid, DATASET_NAME)) < 0) ERR;
      if (H5Dclose(datasetid) < 0) ERR;
      if (H5Gmove(grpid, DATASET_NAME, NEW_NAME) < 0) ERR;
      if ((datasetid = H5Dopen1(grpid, NEW_NAME)) < 0) ERR;
      if (H5Dclose(datasetid) < 0 ||
	  H5Gclose(grpid) < 0 ||
	  H5Fclose(fileid) < 0)
	 ERR;
   }

   SUMMARIZE_ERR;
   printf("*** Checking out sub-groups...");

   {
      hid_t fileid, grpid, subgrpid;

      /* Create file with some nested groups. */
      if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT,
			      H5P_DEFAULT)) < 0) ERR;
      if ((grpid = H5Gcreate(fileid, GRP_NAME, 0)) < 0) ERR;
      if ((subgrpid = H5Gcreate(grpid, SUB_GRP_NAME, 0)) < 0) ERR;
      if (H5Gclose(subgrpid) < 0 ||
	  H5Gclose(grpid) < 0 ||
	  H5Fclose(fileid) < 0) ERR;

      /* Reopen file and discover groups. */
      if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) ERR;
      if ((grpid = H5Gopen(fileid, GRP_NAME)) < 0) ERR;
      if ((subgrpid = H5Gopen(grpid, SUB_GRP_NAME)) < 0) ERR;
      if (H5Gclose(subgrpid) < 0 ||
	  H5Gclose(grpid) < 0 ||
	  H5Fclose(fileid) < 0) ERR;
   }

   SUMMARIZE_ERR;
   printf("*** Checking out UTF8 named sub-group...");

   {
      hid_t fileid, grpid, subgrpid;

      /* Create file with nested group. */
      if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT,
			      H5P_DEFAULT)) < 0) ERR;
      if ((grpid = H5Gcreate(fileid, (char *)norm_utf8, 0)) < 0) ERR;
      if ((subgrpid = H5Gcreate(grpid, SUB_GRP_NAME, 0)) < 0) ERR;
      if (H5Gclose(subgrpid) < 0 ||
	  H5Gclose(grpid) < 0 ||
	  H5Fclose(fileid) < 0) ERR;

      /* Reopen file and discover groups. */
      if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) ERR;
      if ((grpid = H5Gopen(fileid, (char *)norm_utf8)) < 0) ERR;
      if ((subgrpid = H5Gopen(grpid, SUB_GRP_NAME)) < 0) ERR;
      if (H5Gclose(subgrpid) < 0 ||
	  H5Gclose(grpid) < 0 ||
	  H5Fclose(fileid) < 0) ERR;
   }

   SUMMARIZE_ERR;
   printf("*** Checking out UTF8 named sub-group with group creation ordering...");

   {
      hid_t fileid, grpid, subgrpid;
      hid_t fapl_id, fcpl_id, gcpl_id;

      /* Create file with nested group. */
      if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR;
      if (H5Pset_libver_bounds(fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) ERR;
      if ((fcpl_id = H5Pcreate(H5P_FILE_CREATE)) < 0) ERR;
      if (H5Pset_link_creation_order(fcpl_id, H5P_CRT_ORDER_TRACKED|H5P_CRT_ORDER_INDEXED) < 0) ERR;
      if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, fcpl_id, fapl_id)) < 0) ERR;

      if ((gcpl_id = H5Pcreate(H5P_GROUP_CREATE)) < 0) ERR;
      if (H5Pset_link_creation_order(gcpl_id, H5P_CRT_ORDER_TRACKED|H5P_CRT_ORDER_INDEXED) < 0) ERR;
      if ((grpid = H5Gcreate_anon(fileid, gcpl_id, H5P_DEFAULT)) < 0) ERR;
      if ((H5Olink(grpid, fileid, (char *)norm_utf8, H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR;

      if ((subgrpid = H5Gcreate(grpid, SUB_GRP_NAME, 0)) < 0) ERR;
      if (H5Gclose(subgrpid) < 0 ||
	  H5Gclose(grpid) < 0 ||
	  H5Fclose(fileid) < 0) ERR;

      /* Reopen file and discover groups. */
      if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) ERR;
      if ((grpid = H5Gopen(fileid, (char *)norm_utf8)) < 0) ERR;
      if ((subgrpid = H5Gopen(grpid, SUB_GRP_NAME)) < 0) ERR;
      if (H5Gclose(subgrpid) < 0 ||
	  H5Gclose(grpid) < 0 ||
	  H5Fclose(fileid) < 0) ERR;
   }

   SUMMARIZE_ERR;

   FINAL_RESULTS;
}
Esempio n. 21
0
/*-------------------------------------------------------------------------
 * Function:    test_refresh
 *
 * Purpose:     This function tests refresh (evict/reload) of individual 
 *              objects' metadata from the metadata cache.
 *
 * Return:      0 on Success, 1 on Failure
 *
 * Programmer:  Mike McGreevy
 *              August 17, 2010
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
herr_t test_refresh(void) 
{
    /**************************************************************************
     *
     * Test Description:
     *
     * This test will build an HDF5 file with several objects in a varying 
     * hierarchical layout. It will then flush the entire file to disk. Then,
     * an attribute will be added to each object in the file.
     * 
     * One by one, this process will flush each object to disk, individually.
     * It will also be coordinating with another process, which will open
     * the object before it is flushed by this process, and then refresh the
     * object after it's been flushed, comparing the before and after object
     * information to ensure that they are as expected. (i.e., most notably,
     * that an attribute has been added, and is only visible after a 
     * successful call to a H5*refresh function).
     * 
     * As with the flush case, the implemention is a bit tricky as it's 
     * dealing with signals going back and forth between the two processes
     * to ensure the timing is correct, but basically, an example: 
     *
     * Step 1. Dataset is created.
     * Step 2. Dataset is flushed.
     * Step 3. Attribute on Dataset is created.
     * Step 4. Another process opens the dataset and verifies that it does
     *         not see an attribute (as the attribute hasn't been flushed yet).
     * Step 5. This process flushes the dataset again (with Attribute attached).
     * Step 6. The other process calls H5Drefresh, which should evict/reload
     *         the object's metadata, and thus pick up the attribute that's
     *         attached to it. Most other before/after object information is 
     *         compared for sanity as well.
     * Step 7. Rinse and Repeat for each object in the file.
     *
     **************************************************************************/

    /**************************************************************************
      * Generated Test File will look like this:
      * 
      * GROUP "/"
      *   DATASET "Dataset1"
      *   GROUP "Group1" {
      *     DATASET "Dataset2"
      *     GROUP "Group2" {
      *       DATATYPE "CommittedDatatype3"
      *     }
      *   }
      *   GROUP "Group3" {
      *     DATASET "Dataset3"
      *     DATATYPE "CommittedDatatype2"
      *   }
      *   DATATYPE "CommittedDatatype1"
     **************************************************************************/

    /* Variables */
    hid_t aid,fid,sid,tid1,did,dcpl,fapl = 0;
    hid_t gid,gid2,gid3,tid2,tid3,did2,did3,status = 0;
    hsize_t dims[2] = {50,50};
    hsize_t cdims[2] = {1,1};
    int fillval = 2;

    /* Testing Message */
    HDfprintf(stdout, "Testing individual object refresh behavior:\n");

    /* Cleanup any old error or signal files */
    CLEANUP_FILES;

    /* ================ */
    /* CREATE TEST FILE */
    /* ================ */

    /* Create File */
    if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) TEST_ERROR;
    if (H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) TEST_ERROR;
    if ((fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC|H5F_ACC_SWMR_WRITE, H5P_DEFAULT, fapl)) < 0) TEST_ERROR;

    /* Create data space and types */
    if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) TEST_ERROR;
    if ( H5Pset_chunk(dcpl, 2, cdims) < 0 ) TEST_ERROR;
    if ( H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fillval) < 0 ) TEST_ERROR;
    if ((sid = H5Screate_simple(2, dims, dims)) < 0) TEST_ERROR;
    if ((tid1 = H5Tcopy(H5T_NATIVE_INT)) < 0) TEST_ERROR;
    if ((tid2 = H5Tcopy(H5T_NATIVE_CHAR)) < 0) TEST_ERROR;
    if ((tid3 = H5Tcopy(H5T_NATIVE_LONG)) < 0) TEST_ERROR;

    /* Create Group1 */
    if ((gid = H5Gcreate2(fid, "Group1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Create Group2 */
    if ((gid2 = H5Gcreate2(gid, "Group2", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Create Group3 */
    if ((gid3 = H5Gcreate2(fid, "Group3", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Create Dataset1 */
    if ((did = H5Dcreate2(fid, "Dataset1", tid1, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Create Dataset2 */
    if ((did2 = H5Dcreate2(gid, "Dataset2", tid3, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Create Dataset3 */
    if ((did3 = H5Dcreate2(gid3, "Dataset3", tid2, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Create CommittedDatatype1 */
    if ((status = H5Tcommit2(fid, "CommittedDatatype1", tid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Create CommittedDatatype2 */
    if ((status = H5Tcommit2(gid2, "CommittedDatatype2", tid2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Create CommittedDatatype3 */
    if ((status = H5Tcommit2(gid3, "CommittedDatatype3", tid3, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Flush File to Disk */
    if (H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0) TEST_ERROR;

    /* Create an attribute on each object. These will not immediately hit disk, 
        and thus be unavailable to another process until this process flushes
        the object and the other process refreshes from disk. */
    if ((aid = H5Acreate2(did, "Attribute", tid1, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
    if (H5Aclose(aid) < 0) TEST_ERROR;
    if ((aid = H5Acreate2(did2, "Attribute", tid1, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
    if (H5Aclose(aid) < 0) TEST_ERROR;
    if ((aid = H5Acreate2(did3, "Attribute", tid1, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
    if (H5Aclose(aid) < 0) TEST_ERROR;
    if ((aid = H5Acreate2(gid, "Attribute", tid1, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
    if (H5Aclose(aid) < 0) TEST_ERROR;
    if ((aid = H5Acreate2(gid2, "Attribute", tid1, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
    if (H5Aclose(aid) < 0) TEST_ERROR;
    if ((aid = H5Acreate2(gid3, "Attribute", tid1, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
    if (H5Aclose(aid) < 0) TEST_ERROR;
    if ((aid = H5Acreate2(tid1, "Attribute", tid1, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
    if (H5Aclose(aid) < 0) TEST_ERROR;
    if ((aid = H5Acreate2(tid2, "Attribute", tid1, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
    if (H5Aclose(aid) < 0) TEST_ERROR;
    if ((aid = H5Acreate2(tid3, "Attribute", tid1, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
    if (H5Aclose(aid) < 0) TEST_ERROR;

    /* ================ */
    /* Refresh Datasets */
    /* ================ */

    TESTING("to ensure that H5Drefresh correctly refreshes single datasets");

    /* Verify First Dataset can be refreshed with H5Drefresh */
    if (start_refresh_verification_process(D1) != 0) TEST_ERROR;
    if (H5Oflush(did) < 0) TEST_ERROR;
    if (end_refresh_verification_process() != 0) TEST_ERROR;

    /* Verify Second Dataset can be refreshed with H5Drefresh */
    if (start_refresh_verification_process(D2) != 0) TEST_ERROR;
    if (H5Oflush(did2) < 0) TEST_ERROR;
    if (end_refresh_verification_process() != 0) TEST_ERROR;

    PASSED();

    /* ============== */
    /* Refresh Groups */
    /* ============== */

    TESTING("to ensure that H5Grefresh correctly refreshes single groups");

    /* Verify First Group can be refreshed with H5Grefresh */
    if (start_refresh_verification_process(G1) != 0) TEST_ERROR;
    if (H5Oflush(gid) < 0) TEST_ERROR;
    if (end_refresh_verification_process() != 0) TEST_ERROR;

    /* Verify Second Group can be refreshed with H5Grefresh */
    if (start_refresh_verification_process(G2) != 0) TEST_ERROR;
    if (H5Oflush(gid2) < 0) TEST_ERROR;
    if (end_refresh_verification_process() != 0) TEST_ERROR;

    PASSED();

    /* ================= */
    /* Refresh Datatypes */
    /* ================= */

    TESTING("to ensure that H5Trefresh correctly refreshes single datatypes");

    /* Verify First Committed Datatype can be refreshed with H5Trefresh */
    if (start_refresh_verification_process(T1) != 0) TEST_ERROR;
    if (H5Oflush(tid1) < 0) TEST_ERROR;
    if (end_refresh_verification_process() != 0) TEST_ERROR;

    /* Verify Second Committed Datatype can be refreshed with H5Trefresh */
    if (start_refresh_verification_process(T2) != 0) TEST_ERROR;
    if (H5Oflush(tid2) < 0) TEST_ERROR;
    if (end_refresh_verification_process() != 0) TEST_ERROR;

    PASSED();

    /* =============== */
    /* Refresh Objects */
    /* =============== */

    TESTING("to ensure that H5Orefresh correctly refreshes single objects");

    /* Verify Third Dataset can be refreshed with H5Orefresh */
    if (start_refresh_verification_process(D3) != 0) TEST_ERROR;
    if (H5Oflush(did3) < 0) TEST_ERROR;
    if (end_refresh_verification_process() != 0) TEST_ERROR;

    /* Verify Third Group can be refreshed with H5Orefresh */
    if (start_refresh_verification_process(G3) != 0) TEST_ERROR;
    if (H5Oflush(gid3) < 0) TEST_ERROR;
    if (end_refresh_verification_process() != 0) TEST_ERROR;

    /* Verify Third Committed Datatype can be refreshed with H5Orefresh */
    if (start_refresh_verification_process(T3) != 0) TEST_ERROR;
    if (H5Oflush(tid3) < 0) TEST_ERROR;
    if (end_refresh_verification_process() != 0) TEST_ERROR;

    PASSED();

    /* ================== */
    /* Cleanup and Return */  
    /* ================== */

    /* Close Stuff */
    if (H5Pclose(fapl) < 0) TEST_ERROR;
    if (H5Tclose(tid1) < 0) TEST_ERROR;
    if (H5Tclose(tid2) < 0) TEST_ERROR;
    if (H5Tclose(tid3) < 0) TEST_ERROR;
    if (H5Dclose(did) < 0) TEST_ERROR;
    if (H5Dclose(did2) < 0) TEST_ERROR;
    if (H5Dclose(did3) < 0) TEST_ERROR;
    if (H5Gclose(gid) < 0) TEST_ERROR;
    if (H5Gclose(gid2) < 0) TEST_ERROR;
    if (H5Gclose(gid3) < 0) TEST_ERROR;
    if (H5Sclose(sid) < 0) TEST_ERROR;
    if (H5Fclose(fid) < 0) TEST_ERROR;

    /* Delete Test File */
    HDremove(FILENAME);

    if (end_verification() < 0) TEST_ERROR;

    return SUCCEED;

error:
    /* Return */
    return FAIL;

} /* test_refresh() */
Esempio n. 22
0
int
main (int argc, char **argv)
{
  extern char* optarg;
  extern int optind, optopt;
  int c, errflg, backflg, incrflg, nopagflg, pagflg, rank, nranks;
  hid_t fapl, file, group, group1, dset;
  size_t incr, page;
  unsigned iter, level, igroup, idset, maxiter;
  char name[MAX_LEN];
  char g1name[MAX_LEN];
  char g2name[MAX_LEN];
  hsize_t dims[3] = { X, Y, Z };
  float *buf;
  double start, stop;
  double t1, t2;
  char cdum[MAX_LEN];
  int i, memtotal, memfree, buffers, cached, swapcached, active, inactive;
  float fdum;

  assert (MPI_Init (&argc, &argv) >= 0);
  assert (MPI_Comm_rank (MPI_COMM_WORLD, &rank) >= 0);
  assert (MPI_Comm_size (MPI_COMM_WORLD, &nranks) >= 0);

  /* parse arguments */

  backflg = errflg = incrflg = nopagflg = pagflg = 0;
  incr = INCREMENT;
  page = PAGE_SIZE;
  maxiter = MAX_ITER;

  while ((c = getopt(argc, argv, ":bni:t:p:")) != -1)
    {
      switch (c)
      {
      case 'b':
        backflg++;
        break;
      case 'i':
        incrflg++;
        incr = (size_t)atol(optarg);
        if (incr == 0)
          {
            fprintf(stderr,
                    "Option -%c requires a positive integer argument\n", optopt);
            errflg++;
          }
        break;
      case 'n':
        nopagflg++;
        break;
      case 'p':
        pagflg++;
        page = (size_t)atol(optarg);
        if (page == 0)
          {
            fprintf(stderr,
                    "Option -%c requires a positive integer argument\n", optopt);
            errflg++;
          }
        break;
      case 't':
        maxiter = (unsigned)atol(optarg);
        if (maxiter == 0)
          {
            fprintf(stderr,
                    "Option -%c requires a positive integer argument\n", optopt);
            errflg++;
          }
        break;
      case ':':       /* -i or -p without operand */
        fprintf(stderr,
                "Option -%c requires an operand\n", optopt);
        errflg++;
        break;
      case '?':
        fprintf(stderr, "Unrecognized option: -%c\n", optopt);
        errflg++;
        break;
      default:
        errflg++;
        break;
      }
    }
  if (errflg)
    {
      if (rank == 0)
        {
          fprintf(stderr, "usage: . . . ");

          fprintf(stderr, "usage: h5core [OPTIONS]\n");
          fprintf(stderr, "  OPTIONS\n");
          fprintf(stderr, "     -b      Write file to disk on exit\n");
          fprintf(stderr, "     -i I    Memory buffer increment size in bytes [default: 512 MB]\n");
          fprintf(stderr, "     -n      Disable write (to disk) paging\n");
          fprintf(stderr, "     -p P    Page size in bytes [default: 64 MB]\n");
          fprintf(stderr, "     -t T    Number of iterations [default: 5]\n");
          fprintf(stderr, "\n");
          fflush(stderr);
        }

      exit(2);
    }

  if ((backflg == 0) && (pagflg > 0))
    {
      if (rank == 0)
        {
          fprintf(stderr, "The -p has no effect without the -b option");
          fflush(stderr);
        }
    }

  if (pagflg && nopagflg)
    {
      if (rank == 0)
        {
          fprintf(stderr, "The -n and -p options are mutually exclusive.");
          fflush(stderr);
        }
      exit(3);
    }

  /* Let's go! */

  fapl = H5Pcreate (H5P_FILE_ACCESS);
  assert (fapl >= 0);
  assert (H5Pset_libver_bounds (fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) >= 0);
  assert (H5Pset_fapl_core (fapl, incr, (hbool_t) backflg) >= 0);
  if (nopagflg == 0)  /* the user didn't disable paging */
    {
      assert (H5Pset_core_write_tracking (fapl, 1, page) >= 0);
    }

  if (rank == 0)
    {
      printf("\n");
      printf("Write to disk: %s\n", (backflg > 0) ? "YES" : "NO");
      printf("Increment size: %ld [bytes]\n", incr);

      if (nopagflg == 0)
        {
          printf("Page size: %ld [bytes]\n", page);
        }
      else
        {
          printf("Page size: PAGING DISABLED!\n");
        }

      printf("Iterations: %d\n", maxiter);
      printf("\n");
      fflush(stdout);
    }

  buf = (float *) malloc (X * Y * Z * sizeof (float));

  // Get basic memory info on each node, see how memory usage changes
  // after flushing to disk; do we end up back where we started?

  getmemory (&memtotal, &memfree, &buffers, &cached, &swapcached, &active,
             &inactive);

  if (rank == 0)
    {
      fprintf (stdout, "BEFORE RUNNING:\n");
      fflush (stdout);
    }
  for (i = 0; i < nranks; i++)
    {
      if (rank == i)
        {
          printmemory (rank, memtotal, memfree, buffers, cached, swapcached,
                       active, inactive);
        }
      MPI_Barrier (MPI_COMM_WORLD);
    }

  start = MPI_Wtime ();

  /* outer loop - simulated time */
  for (iter = 0; iter < maxiter; ++iter)
    {
      if (rank == 0)
        {
          printf ("Iteration: %u\n", iter);
          assert (fflush (stdout) == 0);
        }

      assert (sprintf (name, "rank%05dtime%04u.h5", rank, iter) > 0);
      file = H5Fcreate (name, H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
      assert (file >= 0);

      t1 = MPI_Wtime ();

      /* time level */
      for (level = 0; level < MAX_TIME_LEVEL; ++level)
        {
          assert (sprintf (g1name, "level%03d", level) > 0);
          group = H5Gcreate2 (file, g1name, H5P_DEFAULT, H5P_DEFAULT,
                              H5P_DEFAULT);
          assert (group >= 0);

          /* group level */
          for (igroup = 0; igroup < MAX_GROUPS; ++igroup)
            {
              assert (sprintf (g2name, "group%02d", igroup) > 0);
              group1 = H5Gcreate2 (group, g2name, H5P_DEFAULT, H5P_DEFAULT,
                                   H5P_DEFAULT);
              assert (group1 >= 0);

              /* dataset level */
              for (idset = 0; idset < MAX_DATASETS; ++idset)
                {
                  assert (sprintf (name, "dataset%02d", idset) > 0);
                  assert (H5LTmake_dataset_float (group1, name, RANK, dims, buf) >= 0);

#ifdef DEBUG
                  assert (fprintf (stderr,
                                   "rank %i time %i Wrote dataset %s/%s/%s\n",
                                   rank, level, g1name, g2name, name));
                  assert (fflush (stderr) == 0);
#endif
                }

              assert (H5Gclose (group1) >= 0);
            }

          assert (H5Gclose (group) >= 0);
        }

      t2 = MPI_Wtime ();

      assert (fprintf (stdout,
                       "rank %04i Total time for buffering chunks to memory:\t %f seconds\n",
                       rank, t2 - t1));
      assert (fflush (stdout) == 0);

      MPI_Barrier (MPI_COMM_WORLD);    // To keep output less jumbled

      getmemory (&memtotal, &memfree, &buffers, &cached, &swapcached, &active,
                 &inactive);

      if (rank == 0)
        {
          fprintf (stdout, "BEFORE FLUSHING:\n");
          fflush (stdout);
        }

      for (i = 0; i < nranks; i++)
        {
          if (rank == i)
            {
              printmemory (rank, memtotal, memfree, buffers, cached, swapcached,
                           active, inactive);
            }
          MPI_Barrier (MPI_COMM_WORLD);
        }

      /* close the file */
      t1 = MPI_Wtime ();
      assert (H5Fclose (file) >= 0);
      t2 = MPI_Wtime ();

      getmemory (&memtotal, &memfree, &buffers, &cached, &swapcached, &active,
                 &inactive);

      if (rank == 0)
        {
          fprintf (stdout, "AFTER FLUSHING:\n");
          fflush (stdout);
        }

      for (i = 0; i < nranks; i++)
        {
          if (rank == i)
            {
              printmemory (rank, memtotal, memfree, buffers, cached, swapcached,
                           active, inactive);
              assert (fprintf (stdout, "rank %04i Total time for flushing to disk:\t\t %10.2f seconds\n", rank, t2 - t1));
              assert (fflush (stderr) == 0);
            }
          MPI_Barrier (MPI_COMM_WORLD);
        }
    }

  stop = MPI_Wtime ();
  MPI_Barrier (MPI_COMM_WORLD);

  if (rank == 0)
    {
      printf ("Total time: %f s\n", stop - start);
      printf ("Aggregate bandwidth per process: %f GB/s\n",
              ((float) X * Y * Z * sizeof (float)) *
              ((float) MAX_DATASETS * MAX_GROUPS * MAX_TIME_LEVEL * MAX_ITER) /
              (1024.0 * 1024.0 * 1024.0 * (stop - start)));
    }

  free ((void *) buf);

  assert (H5Pclose (fapl) >= 0);

  assert (MPI_Finalize () >= 0);

  return 0;

}
Esempio n. 23
0
hid_t seissol::checkpoint::h5::Wavefield::initFile(int odd, const char* filename)
{
	hid_t h5file;

	if (loaded()) {
		// Open the old file
		h5file = open(filename, false);
		checkH5Err(h5file);

		// Time
		m_h5time[odd] = H5Aopen(h5file, "time", H5P_DEFAULT);
		checkH5Err(m_h5time[odd]);

		// Wavefield writer
		m_h5timestepWavefield[odd] = H5Aopen(h5file, "timestep_wavefield", H5P_DEFAULT);
		checkH5Err(m_h5timestepWavefield[odd]);

		// Data
		m_h5data[odd] = H5Dopen(h5file, "values", H5P_DEFAULT);
		checkH5Err(m_h5data[odd]);
	} else {
		// Create the file
		hid_t h5plist = H5Pcreate(H5P_FILE_ACCESS);
		checkH5Err(h5plist);
		checkH5Err(H5Pset_libver_bounds(h5plist, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST));
		hsize_t align = utils::Env::get<hsize_t>("SEISSOL_CHECKPOINT_ALIGNMENT", 0);
		if (align > 0)
			checkH5Err(H5Pset_alignment(h5plist, 1, align));
#ifdef USE_MPI
		MPIInfo info;
		checkH5Err(H5Pset_fapl_mpio(h5plist, seissol::MPI::mpi.comm(), info.get()));
#endif // USE_MPI

		h5file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, h5plist);
		checkH5Err(h5file);
		checkH5Err(H5Pclose(h5plist));

		// Create scalar dataspace for attributes
		hid_t h5spaceScalar = H5Screate(H5S_SCALAR);
		checkH5Err(h5spaceScalar);

		// Time
		m_h5time[odd] = H5Acreate(h5file, "time", H5T_IEEE_F64LE, h5spaceScalar,
				H5P_DEFAULT, H5P_DEFAULT);
		checkH5Err(m_h5time[odd]);

		// Partitions
		hid_t h5partitions = H5Acreate(h5file, "partitions", H5T_STD_I32LE, h5spaceScalar,
				H5P_DEFAULT, H5P_DEFAULT);
		checkH5Err(h5partitions);
		int p = partitions();
		checkH5Err(H5Awrite(h5partitions, H5T_NATIVE_INT, &p));
		checkH5Err(H5Aclose(h5partitions));

		// Wavefield writer
		m_h5timestepWavefield[odd] = H5Acreate(h5file, "timestep_wavefield",
				H5T_STD_I32LE, h5spaceScalar, H5P_DEFAULT, H5P_DEFAULT);
		checkH5Err(m_h5timestepWavefield[odd]);
		int t = 0;
		checkH5Err(H5Awrite(m_h5timestepWavefield[odd], H5T_NATIVE_INT, &t));

		checkH5Err(H5Sclose(h5spaceScalar));

		// Variable
		h5plist = H5Pcreate(H5P_DATASET_CREATE);
		checkH5Err(h5plist);
		checkH5Err(H5Pset_layout(h5plist, H5D_CONTIGUOUS));
		checkH5Err(H5Pset_alloc_time(h5plist, H5D_ALLOC_TIME_EARLY));
		m_h5data[odd] = H5Dcreate(h5file, "values", H5T_IEEE_F64LE, m_h5fSpaceData,
				H5P_DEFAULT, h5plist, H5P_DEFAULT);
		checkH5Err(m_h5data[odd]);
		checkH5Err(H5Pclose(h5plist));
	}

	return h5file;
}
Esempio n. 24
0
/*
 *  To exercise the coding for the re-read of the object header for SWMR access.
 *  When the object header is read in H5O_load() of H5Ocache.c, the library initially reads
 *  512 bytes for decoding, then reads the remaining bytes later if the object header is
 *  greater than 512 bytes.  For SWMR access, the read should be done all at one time.
 */
static herr_t
test_ohdr_swmr(void)
{
    hid_t fid = -1;			/* File ID */
    hid_t fapl = -1;			/* File access property list */
    hid_t did = -1;			/* Dataset ID */
    hid_t sid = -1;                   	/* Dataspace ID */
    hid_t plist = -1;			/* Dataset creation property list */
    size_t compact_size = 1024;		/* The size of compact dataset */
    int wbuf[1024];			/* Buffer for writing */
    hsize_t dims[1];			/* Dimension sizes */
    unsigned int n = 0, u;		/* Locatl index variable */
    H5O_info_t obj_info;		/* Information for the object */

    TESTING("exercise the coding for the re-read of the object header for SWMR access");

    /* File access property list */
    if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
	FAIL_STACK_ERROR

    /* Set to use latest library format */
    if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
	FAIL_STACK_ERROR

    /* Initialize data */
    for(u = 0; u < compact_size; u++)
	wbuf[u] = n++;

    /* Create the file with the latest format (ensure version 2 object header for SWMR) */
    if((fid = H5Fcreate(FILE_OHDR_SWMR, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
	TEST_ERROR

    /* Create a small data space for compact dataset */
    dims[0] = (hsize_t)compact_size;
    if((sid = H5Screate_simple(1, dims, NULL)) < 0)
	FAIL_STACK_ERROR
    
    /* Create property list for compact dataset creation */
    if((plist = H5Pcreate(H5P_DATASET_CREATE)) < 0)
	FAIL_STACK_ERROR

    /* Set the layout for the compact dataset */
    if(H5Pset_layout(plist, H5D_COMPACT) < 0)
	FAIL_STACK_ERROR

    /* Create a compact dataset */
    if((did = H5Dcreate2(fid, DSET_NAME, H5T_NATIVE_INT, sid, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0)
	FAIL_STACK_ERROR
	
    /* Write to the compact dataset */
    if(H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf) < 0)
	FAIL_STACK_ERROR

    /* Close the dataset */
    if(H5Dclose(did) < 0)
	FAIL_STACK_ERROR

    /* Close the file */
    if(H5Fclose(fid) < 0)
	FAIL_STACK_ERROR

    /* Open the file for SWMR write and latest format */
    if((fid = H5Fopen(FILE_OHDR_SWMR, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl)) < 0)
	FAIL_STACK_ERROR

    /* Open the compact dataset */
    if((did = H5Dopen2(fid, DSET_NAME, H5P_DEFAULT)) < 0)
	FAIL_STACK_ERROR

    /* Get the object information */
    if(H5Oget_info(did, &obj_info) < 0)
	FAIL_STACK_ERROR

    /* The size of object header should be greater than the speculative read size of 512 */
    /* This will exercise the coding for the re-read of the object header for SWMR access */
    if(obj_info.hdr.space.total < 512)
	TEST_ERROR;

    /* Close the dataset */
    if(H5Dclose(did) < 0)
	FAIL_STACK_ERROR

    /* Close the file */
    if(H5Fclose(fid) < 0)
	FAIL_STACK_ERROR
	
    /* Close the dataspace */
    if(H5Sclose(sid) < 0)
	FAIL_STACK_ERROR

    /* Close the dataset creation property list */
    if(H5Pclose(plist) < 0)
	FAIL_STACK_ERROR

    /* Close the file access property list */
    if(H5Pclose(fapl) < 0)
	FAIL_STACK_ERROR

    /* Remove the test file */
    if(HDremove(FILE_OHDR_SWMR) < 0)
	FAIL_STACK_ERROR

    PASSED();

    return 0;

error:
    H5E_BEGIN_TRY {
        H5Fclose(fid);
	H5Dclose(did);
	H5Sclose(sid);
	H5Pclose(plist);
	H5Pclose(fapl);
	HDremove(FILE_OHDR_SWMR);
    } H5E_END_TRY;

    return -1;
} /* test_ohdr_swmr() */
Esempio n. 25
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;
}
Esempio n. 26
0
int
main()
{
   printf("\n*** Checking HDF5 attribute functions some more.\n");
   printf("*** Creating tst_xplatform2_3.nc with HDF only...");
   {
      hid_t fapl_id, fcpl_id;
      size_t chunk_cache_size = MY_CHUNK_CACHE_SIZE;
      size_t chunk_cache_nelems = CHUNK_CACHE_NELEMS;
      float chunk_cache_preemption = CHUNK_CACHE_PREEMPTION;
      hid_t fileid, grpid, attid, spaceid;
      hid_t s1_typeid, vlen_typeid, s3_typeid;
      hid_t file_typeid1[NUM_OBJ], native_typeid1[NUM_OBJ];
      hid_t file_typeid2, native_typeid2;
      hsize_t num_obj;
      H5O_info_t obj_info;
      char obj_name[STR_LEN + 1];
      hsize_t dims[1] = {ATT_LEN}; /* netcdf attributes always 1-D. */
      struct s1
      {
	 float x;
	 double y;
      };
      struct s3
      {
	 hvl_t data[NUM_VL];
      };
      /* cvc stands for "Compound with Vlen of Compound." */
      struct s3 cvc_out[ATT_LEN];
      int i, j, k;

      /* Create some output data: a struct s3 array (length ATT_LEN)
       * which holds an array of vlen (length NUM_VL) of struct s1. */
      for (i = 0; i < ATT_LEN; i++)
	 for (j = 0; j < NUM_VL; j++)
	 {
	    cvc_out[i].data[j].len = i + 1; 
	    if (!(cvc_out[i].data[j].p = calloc(sizeof(struct s1), cvc_out[i].data[j].len))) ERR;
	    for (k = 0; k < cvc_out[i].data[j].len; k++)
	    {
	       ((struct s1 *)cvc_out[i].data[j].p)[k].x = 42.42;
	       ((struct s1 *)cvc_out[i].data[j].p)[k].y = 2.0;
	    }
	 }

      /* Create the HDF5 file, with cache control, creation order, and
       * all the timmings. */
      if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR;
      if (H5Pset_fclose_degree(fapl_id, H5F_CLOSE_STRONG)) ERR;
      if (H5Pset_cache(fapl_id, 0, chunk_cache_nelems, chunk_cache_size, 
		       chunk_cache_preemption) < 0) ERR;
      if (H5Pset_libver_bounds(fapl_id, H5F_LIBVER_LATEST, 
			       H5F_LIBVER_LATEST) < 0) ERR;
      if ((fcpl_id = H5Pcreate(H5P_FILE_CREATE)) < 0) ERR;
      if (H5Pset_link_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED | 
					       H5P_CRT_ORDER_INDEXED)) < 0) ERR;
      if (H5Pset_attr_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED | 
					       H5P_CRT_ORDER_INDEXED)) < 0) ERR;
      if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, fcpl_id, fapl_id)) < 0) ERR;
      if (H5Pclose(fapl_id) < 0) ERR;
      if (H5Pclose(fcpl_id) < 0) ERR;

      /* Open the root group. */
      if ((grpid = H5Gopen2(fileid, "/", H5P_DEFAULT)) < 0) ERR;

      /* Create the compound type for struct s1. */
      if ((s1_typeid = H5Tcreate(H5T_COMPOUND, sizeof(struct s1))) < 0) ERR;
      if (H5Tinsert(s1_typeid, X_NAME, offsetof(struct s1, x), 
		    H5T_NATIVE_FLOAT) < 0) ERR;
      if (H5Tinsert(s1_typeid, Y_NAME, offsetof(struct s1, y), 
		    H5T_NATIVE_DOUBLE) < 0) ERR;
      if (H5Tcommit(grpid, S1_TYPE_NAME, s1_typeid) < 0) ERR;

      /* Create a vlen type. Its a vlen of struct s1. */
      if ((vlen_typeid = H5Tvlen_create(s1_typeid)) < 0) ERR;
      if (H5Tcommit(grpid, VLEN_TYPE_NAME, vlen_typeid) < 0) ERR;

      /* Create the struct s3 type, which contains the vlen. */
      if ((s3_typeid = H5Tcreate(H5T_COMPOUND, sizeof(struct s3))) < 0) ERR;
      if (H5Tinsert(s3_typeid, VL_NAME, offsetof(struct s3, data), 
		    vlen_typeid) < 0) ERR;
      if (H5Tcommit(grpid, S3_TYPE_NAME, s3_typeid) < 0) ERR;

      /* Create an attribute of this new type. */
      if ((spaceid = H5Screate_simple(1, dims, NULL)) < 0) ERR;
      if ((attid = H5Acreate(grpid, S3_ATT_NAME, s3_typeid, spaceid, 
			     H5P_DEFAULT)) < 0) ERR;
      if (H5Awrite(attid, s3_typeid, cvc_out) < 0) ERR;

      /* Close the types. */
      if (H5Tclose(s1_typeid) < 0 ||
	  H5Tclose(vlen_typeid) < 0 ||
	  H5Tclose(s3_typeid) < 0) ERR;

      /* Close the att. */
      if (H5Aclose(attid) < 0) ERR;
      
      /* Close the space. */
      if (H5Sclose(spaceid) < 0) ERR;

      /* Close the group and file. */
      if (H5Gclose(grpid) < 0 ||
	  H5Fclose(fileid) < 0) ERR;

      /* Reopen the file. */
      if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) ERR;
      if ((grpid = H5Gopen(fileid, "/")) < 0) ERR;

      /* How many objects in this group? (There should be 3, the
       * types. Atts don't count as objects to HDF5.) */
      if (H5Gget_num_objs(grpid, &num_obj) < 0) ERR;
      if (num_obj != NUM_OBJ) ERR;

      /* For each object in the group... */
      for (i = 0; i < num_obj; i++)
      {
	 /* Get the name, and make sure this is a type. */
	 if (H5Oget_info_by_idx(grpid, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC,
				i, &obj_info, H5P_DEFAULT) < 0) ERR;
	 if (H5Lget_name_by_idx(grpid, ".", H5_INDEX_NAME, H5_ITER_INC, i,
				obj_name, STR_LEN + 1, H5P_DEFAULT) < 0) ERR;
	 if (obj_info.type != H5O_TYPE_NAMED_DATATYPE) ERR;

	 /* Get the typeid and native typeid. */
	 if ((file_typeid1[i] = H5Topen2(grpid, obj_name, H5P_DEFAULT)) < 0) ERR;
	 if ((native_typeid1[i] = H5Tget_native_type(file_typeid1[i], 
						     H5T_DIR_DEFAULT)) < 0) ERR;
      }

      /* There is one att: open it by index. */
      if ((attid = H5Aopen_idx(grpid, 0)) < 0) ERR;

      /* Get file and native typeids of the att. */
      if ((file_typeid2 = H5Aget_type(attid)) < 0) ERR;
      if ((native_typeid2 = H5Tget_native_type(file_typeid2, H5T_DIR_DEFAULT)) < 0) ERR;

      /* Close the attribute. */
      if (H5Aclose(attid) < 0) ERR;

      /* Close the typeids. */
      for (i = 0; i < NUM_OBJ; i++)
      {
	 if (H5Tclose(file_typeid1[i]) < 0) ERR;
	 if (H5Tclose(native_typeid1[i]) < 0) ERR;
      }
      if (H5Tclose(file_typeid2) < 0) ERR;
      if (H5Tclose(native_typeid2) < 0) ERR;

      /* Close the group and file. */
      if (H5Gclose(grpid) < 0 ||
	  H5Fclose(fileid) < 0) ERR;

      /* Deallocate our vlens. */
      for (i = 0; i < ATT_LEN; i++)
	 for (j = 0; j < NUM_VL; j++)
	    free(cvc_out[i].data[j].p);
   }
   SUMMARIZE_ERR;
   printf("*** Checking vlen of compound file...");
   {
#define NUM_OBJ_1 1
#define ATT_NAME "Poseidon"
      hid_t fapl_id, fcpl_id;
      hid_t fileid, grpid, attid, spaceid;
      hid_t vlen_typeid;
      hid_t file_typeid1[NUM_OBJ_1], native_typeid1[NUM_OBJ_1];
      hid_t file_typeid2, native_typeid2;
      hsize_t num_obj;
      H5O_info_t obj_info;
      char obj_name[STR_LEN + 1];
      hsize_t dims[1] = {ATT_LEN}; /* netcdf attributes always 1-D. */

      /* vc stands for "Vlen of Compound." */
      hvl_t vc_out[ATT_LEN];
      int i, k;

      /* Create some output data: an array of vlen (length ATT_LEN) of
       * int. */
      for (i = 0; i < ATT_LEN; i++)
      {
	 vc_out[i].len = i + 1; 
	 if (!(vc_out[i].p = calloc(sizeof(int), vc_out[i].len))) ERR;
	 for (k = 0; k < vc_out[i].len; k++)
	    ((int *)vc_out[i].p)[k] = 42;
      }
      
      /* Create the HDF5 file with creation order. */
      if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR;
      if ((fcpl_id = H5Pcreate(H5P_FILE_CREATE)) < 0) ERR;
      if (H5Pset_link_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED | 
					       H5P_CRT_ORDER_INDEXED)) < 0) ERR;
      if (H5Pset_attr_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED | 
					       H5P_CRT_ORDER_INDEXED)) < 0) ERR;
      if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, fcpl_id, fapl_id)) < 0) ERR;
      if (H5Pclose(fapl_id) < 0) ERR;
      if (H5Pclose(fcpl_id) < 0) ERR;
      
      /* Open the root group. */
      if ((grpid = H5Gopen2(fileid, "/", H5P_DEFAULT)) < 0) ERR;
      
      /* Create a vlen type. Its a vlen of int. */
      if ((vlen_typeid = H5Tvlen_create(H5T_NATIVE_INT)) < 0) ERR;
      if (H5Tcommit(grpid, VLEN_TYPE_NAME, vlen_typeid) < 0) ERR;
      
      /* Create an attribute of this new type. */
      if ((spaceid = H5Screate_simple(1, dims, NULL)) < 0) ERR;
      if ((attid = H5Acreate(grpid, ATT_NAME, vlen_typeid, spaceid, 
			     H5P_DEFAULT)) < 0) ERR;
      if (H5Awrite(attid, vlen_typeid, vc_out) < 0) ERR;
      
      /* Close the type. */
      if (H5Tclose(vlen_typeid) < 0) ERR;
	  
      /* Close the att. */
      if (H5Aclose(attid) < 0) ERR;
      
      /* Close the space. */
      if (H5Sclose(spaceid) < 0) ERR;

      /* Close the group and file. */
      if (H5Gclose(grpid) < 0 ||
	  H5Fclose(fileid) < 0) ERR;

      /* Reopen the file. */
      if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) ERR;
      if ((grpid = H5Gopen(fileid, "/")) < 0) ERR;

      /* How many objects in this group? (There should be 2, the
       * types. Atts don't count as objects to HDF5.) */
      if (H5Gget_num_objs(grpid, &num_obj) < 0) ERR;
      if (num_obj != NUM_OBJ_1) ERR;

      /* For each object in the group... */
      for (i = 0; i < num_obj; i++)
      {
	 /* Get the name, and make sure this is a type. */
	 if (H5Oget_info_by_idx(grpid, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC,
				i, &obj_info, H5P_DEFAULT) < 0) ERR;
	 if (H5Lget_name_by_idx(grpid, ".", H5_INDEX_NAME, H5_ITER_INC, i,
				obj_name, STR_LEN + 1, H5P_DEFAULT) < 0) ERR;
	 if (obj_info.type != H5O_TYPE_NAMED_DATATYPE) ERR;

	 /* Get the typeid and native typeid. */
	 if ((file_typeid1[i] = H5Topen2(grpid, obj_name, H5P_DEFAULT)) < 0) ERR;
	 if ((native_typeid1[i] = H5Tget_native_type(file_typeid1[i],
						     H5T_DIR_DEFAULT)) < 0) ERR;
      }

      /* There is one att: open it by index. */
      if ((attid = H5Aopen_idx(grpid, 0)) < 0) ERR;

      /* Get file and native typeids of the att. */
      if ((file_typeid2 = H5Aget_type(attid)) < 0) ERR;
      if ((native_typeid2 = H5Tget_native_type(file_typeid2, H5T_DIR_DEFAULT)) < 0) ERR;

      /* Close the attribute. */
      if (H5Aclose(attid) < 0) ERR;

      /* Close the typeids. */
      for (i = 0; i < NUM_OBJ_1; i++)
      {
	 if (H5Tclose(file_typeid1[i]) < 0) ERR;
	 if (H5Tclose(native_typeid1[i]) < 0) ERR;
      }
      if (H5Tclose(file_typeid2) < 0) ERR;
      if (H5Tclose(native_typeid2) < 0) ERR;

      /* Close the group and file. */
      if (H5Gclose(grpid) < 0 ||
	  H5Fclose(fileid) < 0) ERR;

      /* Deallocate our vlens. */
      for (i = 0; i < ATT_LEN; i++)
	 free(vc_out[i].p);
   }
   SUMMARIZE_ERR;
   FINAL_RESULTS;
}
/*
 * Generate HDF5 file with latest format with
 * NUM_GRPS groups and NUM_ATTRS attributes for the dataset
 *
 */
static void 
gen_newgrat_file(const char *fname)
{
    hid_t fapl; 	/* File access property */
    hid_t fid;		/* File id */
    hid_t gid;		/* Group id */
    hid_t tid;		/* Datatype id */
    hid_t sid; 		/* Dataspace id */
    hid_t attr_id; 	/* Attribute id */
    hid_t did;		/* Dataset id */
    char name[30];	/* Group name */
    char attrname[30];	/* Attribute name */
    int  i;		/* Local index variable */

    /* Get a copy file access property list */
    if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
	goto error;

    /* Set to use latest library format */
    if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
	goto error;

     /* Create dataset */
    if((fid = H5Fcreate(NEWGRAT_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
	goto error;

    /* Create NUM_GRPS groups in the root group */
    for(i = 1; i <= NUM_GRPS; i++) {
        sprintf(name, "%s%d", GROUP_NAME,i);
        if((gid = H5Gcreate2(fid, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
	    goto error;
        if(H5Gclose(gid) < 0)
	    goto error;
    } /* end for */

    /* Create a datatype to commit and use */
    if((tid = H5Tcopy(H5T_NATIVE_INT)) < 0)
	goto error;

    /* Create dataspace for dataset */
    if((sid = H5Screate(H5S_SCALAR)) < 0)
	goto error;

    /* Create dataset */
    if((did = H5Dcreate2(fid, DATASET_NAME, tid, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
	goto error;

    /* Create NUM_ATTRS for the dataset */
    for(i = 1; i <= NUM_ATTRS; i++) {
        sprintf(attrname, "%s%d", ATTR_NAME,i);
        if((attr_id = H5Acreate2(did, attrname, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
	    goto error;
        if(H5Aclose(attr_id) < 0)
	    goto error;
    } /* end for */

    /* Close dataset, dataspace, datatype, file */
    if(H5Dclose(did) < 0)
	goto error;
    if(H5Sclose(sid) < 0)
	goto error;
    if(H5Tclose(tid) < 0)
	goto error;
    if(H5Fclose(fid) < 0)
	goto error;

error:
    H5E_BEGIN_TRY {
	H5Aclose(attr_id);
        H5Dclose(did);
        H5Tclose(tid);
        H5Sclose(sid);
        H5Gclose(gid);
        H5Fclose(fid);
    } H5E_END_TRY;

} /* gen_newgrat_file() */
Esempio n. 28
0
int
main(int argc, char **argv)
{
   int p, my_rank;

#ifdef USE_MPE
   int s_init, e_init, s_define, e_define, s_write, e_write, s_close, e_close;
#endif /* USE_MPE */

   MPI_Init(&argc, &argv);
   MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
   MPI_Comm_size(MPI_COMM_WORLD, &p);

#ifdef USE_MPE
   MPE_Init_log();
   s_init = MPE_Log_get_event_number(); 
   e_init = MPE_Log_get_event_number(); 
   s_define = MPE_Log_get_event_number(); 
   e_define = MPE_Log_get_event_number(); 
   s_write = MPE_Log_get_event_number(); 
   e_write = MPE_Log_get_event_number(); 
   s_close = MPE_Log_get_event_number(); 
   e_close = MPE_Log_get_event_number(); 
   MPE_Describe_state(s_init, e_init, "Init", "red");
   MPE_Describe_state(s_define, e_define, "Define", "yellow");
   MPE_Describe_state(s_write, e_write, "Write", "green");
   MPE_Describe_state(s_close, e_close, "Close", "purple");
   MPE_Start_log();
   MPE_Log_event(s_init, 0, "start init");
#endif /* USE_MPE */

   if (!my_rank)
      printf("*** Creating file for parallel I/O read, and rereading it...");
   {
      hid_t fapl_id, fileid, whole_spaceid, dsid, slice_spaceid, whole_spaceid1, xferid;
      hsize_t start[NDIMS], count[NDIMS];
      hsize_t dims[1];
      int data[SC1], data_in[SC1];
      int num_steps;
      double ftime;
      int write_us, read_us;
      int max_write_us, max_read_us;
      float write_rate, read_rate;
      int i, s;

      /* We will write the same slice of random data over and over to
       * fill the file. */
      for (i = 0; i < SC1; i++)
	 data[i] = rand();
      
#ifdef USE_MPE
      MPE_Log_event(e_init, 0, "end init");
      MPE_Log_event(s_define, 0, "start define file");
#endif /* USE_MPE */

      /* Create file. */
      if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR;
      if (H5Pset_fapl_mpio(fapl_id, MPI_COMM_WORLD, MPI_INFO_NULL) < 0) ERR;
      if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, 
			      fapl_id)) < 0) ERR;

      /* Create a space to deal with one slice in memory. */
      dims[0] = SC1;
      if ((slice_spaceid = H5Screate_simple(NDIMS, dims, NULL)) < 0) ERR;

      /* Create a space to write all slices. */
      dims[0] = DIM2_LEN;
      if ((whole_spaceid = H5Screate_simple(NDIMS, dims, NULL)) < 0) ERR;

      /* Create dataset. */
      if ((dsid = H5Dcreate1(fileid, VAR_NAME, H5T_NATIVE_INT, 
      whole_spaceid, H5P_DEFAULT)) < 0) ERR;

      /* Use collective write operations. */
      if ((xferid = H5Pcreate(H5P_DATASET_XFER)) < 0) ERR;
      if (H5Pset_dxpl_mpio(xferid, H5FD_MPIO_COLLECTIVE) < 0) ERR;

#ifdef USE_MPE
      MPE_Log_event(e_define, 0, "end define file");
      if (my_rank)
	 sleep(my_rank);
#endif /* USE_MPE */

      /* Write the data in num_step steps. */
      ftime = MPI_Wtime();      
      num_steps = (DIM2_LEN/SC1) / p;
      for (s = 0; s < num_steps; s++)
      {
#ifdef USE_MPE
	 MPE_Log_event(s_write, 0, "start write slab");
#endif /* USE_MPE */

	 /* Select hyperslab for write of one slice. */
	 start[0] = s * SC1 * p + my_rank * SC1;
	 count[0] = SC1;
	 if (H5Sselect_hyperslab(whole_spaceid, H5S_SELECT_SET, 
	 start, NULL, count, NULL) < 0) ERR;
	 
	 if (H5Dwrite(dsid, H5T_NATIVE_INT, slice_spaceid, whole_spaceid, 
	 xferid, data) < 0) ERR;

#ifdef USE_MPE
	 MPE_Log_event(e_write, 0, "end write file");
#endif /* USE_MPE */
      }
      write_us = (MPI_Wtime() - ftime) * MILLION;
      MPI_Reduce(&write_us, &max_write_us, 1, MPI_INT, MPI_MAX, 0, MPI_COMM_WORLD);
      if (!my_rank)
      {
	 write_rate = (float)(DIM2_LEN * sizeof(int))/(float)max_write_us;      
	 printf("\np=%d, write_rate=%g", p, write_rate);
      }
      
#ifdef USE_MPE
      MPE_Log_event(s_close, 0, "start close file");
#endif /* USE_MPE */

      /* Close. These collective operations will allow every process
       * to catch up. */
      if (H5Dclose(dsid) < 0 ||
      H5Sclose(whole_spaceid) < 0 ||
      H5Sclose(slice_spaceid) < 0 ||
      H5Pclose(fapl_id) < 0 ||
      H5Fclose(fileid) < 0)
	 ERR;

#ifdef USE_MPE
      MPE_Log_event(e_close, 0, "end close file");
#endif /* USE_MPE */

      /* Open the file. */
      if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR;
      if (H5Pset_fapl_mpio(fapl_id, MPI_COMM_WORLD, MPI_INFO_NULL) < 0) ERR;


      if (H5Pset_libver_bounds(fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) ERR;
      if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, fapl_id)) < 0) ERR;

      /* Create a space to deal with one slice in memory. */
      dims[0] = SC1;
      if ((slice_spaceid = H5Screate_simple(NDIMS, dims, NULL)) < 0) ERR;

      /* Open the dataset. */
      if ((dsid = H5Dopen(fileid, VAR_NAME)) < 0) ERR;
      if ((whole_spaceid1 = H5Dget_space(dsid)) < 0) ERR;

      ftime = MPI_Wtime();      
      
      /* Read the data, a slice at a time. */
      for (s = 0; s < num_steps; s++)
      {
	 /* Select hyperslab for read of one slice. */
	 start[0] = s * SC1 * p + my_rank * SC1;
	 count[0] = SC1;
	 if (H5Sselect_hyperslab(whole_spaceid1, H5S_SELECT_SET, 
	 start, NULL, count, NULL) < 0) 
	 {
	    ERR;
	    return 2;
	 }

	 if (H5Dread(dsid, H5T_NATIVE_INT, slice_spaceid, whole_spaceid1, 
	 H5P_DEFAULT, data_in) < 0) 
	 {
	    ERR;
	    return 2;
	 }

/* 	 /\* Check the slice of data. *\/ */
/* 	 for (i = 0; i < SC1; i++) */
/* 	    if (data[i] != data_in[i])  */
/* 	    { */
/* 	       ERR; */
/* 	       return 2; */
/* 	    } */
      }
      read_us = (MPI_Wtime() - ftime) * MILLION;
      MPI_Reduce(&read_us, &max_read_us, 1, MPI_INT, MPI_MAX, 0, MPI_COMM_WORLD);
      if (!my_rank)
      {
	 read_rate = (float)(DIM2_LEN * sizeof(int))/(float)max_read_us;      
	 printf(", read_rate=%g\n", read_rate);
      }
      
      /* Close down. */
      if (H5Dclose(dsid) < 0 ||
      H5Sclose(slice_spaceid) < 0 ||
      H5Sclose(whole_spaceid1) < 0 ||
      H5Pclose(fapl_id) < 0 ||
      H5Fclose(fileid) < 0)
	 ERR;
   }
   if (!my_rank)
      SUMMARIZE_ERR;

   MPI_Finalize();

   if (!my_rank)
      FINAL_RESULTS;
   return 0;
}
Esempio n. 29
0
/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:     Exercise private object header behavior and routines
 *
 * Return:	Success:        0
 *		Failure:        1
 *
 * Programmer:	Robb Matzke
 *              Tuesday, November 24, 1998
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    hid_t	fapl = -1, file = -1;
    hid_t	dset = -1;
    H5F_t	*f = NULL;
    char	filename[1024];
    H5O_hdr_info_t hdr_info;            /* Object info */
    H5O_loc_t	oh_loc, oh_loc2;        /* Object header locations */
    time_t	time_new, ro;
    int         chunkno;                /* Chunk index for message */
    int		i;                      /* Local index variable */
    hbool_t     b;                      /* Index for "new format" loop */
    herr_t      ret;                    /* Generic return value */

    /* Reset library */
    h5_reset();
    fapl = h5_fileaccess();
    h5_fixname(FILENAME[0], fapl, filename, sizeof filename);

    /* Loop over old & new formats */
    for(b = FALSE; b <= TRUE; b++) {
        /* Display info about testing */
        if(b)
            HDputs("Using new file format:");
        else
            HDputs("Using default file format:");

        /* Set the format to use for the file */
        if(H5Pset_libver_bounds(fapl, (b ? H5F_LIBVER_LATEST : H5F_LIBVER_EARLIEST), H5F_LIBVER_LATEST) < 0)
            FAIL_STACK_ERROR

	/* test on object continuation block */
	if(test_cont(filename, fapl) < 0)
            FAIL_STACK_ERROR

        /* Create the file to operate on */
        if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
            TEST_ERROR
        if(NULL == (f = (H5F_t *)H5I_object(file)))
            FAIL_STACK_ERROR
        if (H5AC_ignore_tags(f) < 0) {
	    H5_FAILED();
	    H5Eprint2(H5E_DEFAULT, stdout);
	    goto error;
        }


        /*
         * Test object header creation
         * (using default group creation property list only because it's convenient)
         */
        TESTING("object header creation");
        HDmemset(&oh_loc, 0, sizeof(oh_loc));
        if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc/*out*/) < 0)
            FAIL_STACK_ERROR
        PASSED();


        /* create a new message */
        TESTING("message creation");
        time_new = 11111111;
        if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(1 != H5O_link(&oh_loc, 1, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR
        if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0)
            FAIL_STACK_ERROR
        if(NULL == H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR
        if(ro != time_new)
            TEST_ERROR
        PASSED();


        /*
         * Test modification of an existing message.
         */
        TESTING("message modification");
        time_new = 33333333;
        if(H5O_msg_write(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0)
            FAIL_STACK_ERROR
        if(NULL == H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR
        if(ro != time_new)
            TEST_ERROR

        /* Make certain that chunk #0 in the object header can be encoded with a 1-byte size */
        if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0)
            FAIL_STACK_ERROR
        if(hdr_info.space.total >=256)
            TEST_ERROR

        PASSED();

        /*
         * Test creation of a bunch of messages one after another to see
         * what happens when the object header overflows in core.
         * (Use 'old' MTIME message here, because it is large enough to be
         *  replaced with a continuation message (the new one is too small)
         *  and the library doesn't understand how to migrate more than one
         *  message from an object header currently - QAK - 10/8/03)
         */
        TESTING("object header overflow in memory");
        for(i = 0; i < 40; i++) {
            time_new = (i + 1) * 1000 + 1000000;
            if(H5O_msg_create(&oh_loc, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
                FAIL_STACK_ERROR
        } /* end for */
        if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0)
            FAIL_STACK_ERROR

        /* Make certain that chunk #0 in the object header will be encoded with a 2-byte size */
        if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0)
            FAIL_STACK_ERROR
        if(hdr_info.space.total < 256)
            TEST_ERROR

        PASSED();

        /* Close & re-open file & object header */
        /* (makes certain that an object header in the new format that transitions
         *  between 1-byte chunk #0 size encoding and 2-byte chunk #0 size encoding
         *  works correctly - QAK)
         */
        TESTING("close & re-open object header");
        if(H5O_close(&oh_loc) < 0)
            FAIL_STACK_ERROR
        if(H5Fclose(file) < 0)
            FAIL_STACK_ERROR
        if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
            FAIL_STACK_ERROR
        if(NULL == (f = (H5F_t *)H5I_object(file)))
            FAIL_STACK_ERROR
        if (H5AC_ignore_tags(f) < 0)
            FAIL_STACK_ERROR
        oh_loc.file = f;
        if(H5O_open(&oh_loc) < 0)
            FAIL_STACK_ERROR
        PASSED();

        /*
         * Test creation of a bunch of messages one after another to see
         * what happens when the object header overflows on disk.
         */
        TESTING("object header overflow on disk");
        for(i = 0; i < 10; i++) {
            time_new = (i + 1) * 1000 + 10;
            if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
                FAIL_STACK_ERROR
            if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0)
                FAIL_STACK_ERROR
            if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0)
                FAIL_STACK_ERROR
        } /* end for */
        PASSED();

        /*
         * Delete all time messages.
         */
        TESTING("message deletion");
        if(H5O_msg_remove(&oh_loc, H5O_MTIME_NEW_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5O_msg_remove(&oh_loc, H5O_MTIME_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR
        if(H5O_msg_read(&oh_loc, H5O_MTIME_ID, &ro, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR
        PASSED();


        /*
         * Constant message handling.
         * (can't write to them, but should be able to remove them)
         */
        TESTING("constant message handling");
        time_new = 22222222;
        if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, H5O_MSG_FLAG_CONSTANT, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0)
            FAIL_STACK_ERROR
        if(NULL == H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR
        if(ro != time_new)
            TEST_ERROR
        time_new = 33333333;
        H5E_BEGIN_TRY {
            ret = H5O_msg_write(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT);
        } H5E_END_TRY;
        if(ret >= 0)
            TEST_ERROR
        if(H5O_msg_remove(&oh_loc, H5O_MTIME_NEW_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        PASSED();


        /* release resources */
        TESTING("object header closing");
        if(H5O_close(&oh_loc) < 0)
            FAIL_STACK_ERROR
        PASSED();

        /*
         * Test moving message to first chunk
         */
        TESTING("locking messages");
        HDmemset(&oh_loc, 0, sizeof(oh_loc));
        if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc/*out*/) < 0)
            FAIL_STACK_ERROR
        if(1 != H5O_link(&oh_loc, 1, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR

        /* Create second object header, to guarantee that first object header uses multiple chunks */
        HDmemset(&oh_loc2, 0, sizeof(oh_loc2));
        if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc2/*out*/) < 0)
            FAIL_STACK_ERROR
        if(1 != H5O_link(&oh_loc2, 1, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR

        /* Fill object header with messages, creating multiple chunks */
        for(i = 0; i < 10; i++) {
            time_new = (i + 1) * 1000 + 10;
            if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
                FAIL_STACK_ERROR
        } /* end for */

        /* Get # of object header chunks */
        if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0)
            FAIL_STACK_ERROR
        if(hdr_info.nchunks != 2)
            TEST_ERROR

        /* Add message to lock to object header */
        time_new = 11111111;
        if(H5O_msg_create(&oh_loc, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Verify chunk index for message */
        if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0)
            FAIL_STACK_ERROR
        if(chunkno != 1)
            TEST_ERROR

        /* Lock the message into the chunk */
        if(H5O_msg_lock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Attempt to lock the message twice */
        H5E_BEGIN_TRY {
            ret = H5O_msg_lock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT);
        } H5E_END_TRY;
        if(ret >= 0)
            TEST_ERROR

        /* Delete all the other messages, which would move the message into
         * chunk #0, if it wasn't locked
         */
        if(H5O_msg_remove(&oh_loc, H5O_MTIME_NEW_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Verify chunk index for message */
        if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0)
            FAIL_STACK_ERROR
        if(chunkno != 1)
            TEST_ERROR

        /* Unlock the message */
        if(H5O_msg_unlock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Attempt to unlock the message twice */
        H5E_BEGIN_TRY {
            ret = H5O_msg_unlock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT);
        } H5E_END_TRY;
        if(ret >= 0)
            TEST_ERROR

        /* Close object headers */
        if(H5O_close(&oh_loc2) < 0)
            FAIL_STACK_ERROR
        if(H5O_close(&oh_loc) < 0)
            FAIL_STACK_ERROR

        /* Open first object header */
        HDmemset(&oh_loc, 0, sizeof(oh_loc));
        if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc/*out*/) < 0)
            FAIL_STACK_ERROR
        if(1 != H5O_link(&oh_loc, 1, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR

        /* Create second object header, to guarantee that first object header uses multiple chunks */
        HDmemset(&oh_loc2, 0, sizeof(oh_loc2));
        if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc2/*out*/) < 0)
            FAIL_STACK_ERROR
        if(1 != H5O_link(&oh_loc2, 1, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR

        /* Add message to move to object header */
        time_new = 11111111;
        if(H5O_msg_create(&oh_loc, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Verify chunk index for message */
        if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0)
            FAIL_STACK_ERROR
        if(chunkno != 0)
            TEST_ERROR

        /* Lock the message into the chunk */
        if(H5O_msg_lock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Fill object header with messages, creating multiple chunks */
        /* (would normally move locked message to new chunk) */
        for(i = 0; i < 10; i++) {
            time_new = (i + 1) * 1000 + 10;
            if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
                FAIL_STACK_ERROR
        } /* end for */

        /* Get # of object header chunks */
        if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0)
            FAIL_STACK_ERROR
        if(hdr_info.nchunks != 2)
            TEST_ERROR

        /* Verify chunk index for message */
        if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0)
            FAIL_STACK_ERROR
        if(chunkno != 0)
            TEST_ERROR

        /* Unlock the message */
        if(H5O_msg_unlock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Close object headers */
        if(H5O_close(&oh_loc2) < 0)
            FAIL_STACK_ERROR
        if(H5O_close(&oh_loc) < 0)
            FAIL_STACK_ERROR

        PASSED();


        /* Test reading datasets with undefined object header messages
         * and the various "fail/mark if unknown" object header message flags
         */
        HDputs("Accessing objects with unknown header messages:");
        {
            hid_t file2;                    /* File ID for 'bogus' object file */
            hid_t sid;                      /* Dataspace ID */
            hid_t aid;                      /* Attribute ID */
            const char *testfile = H5_get_srcdir_filename(FILE_BOGUS);

            TESTING("object with unknown header message and no flags set");

            /* Open the file with objects that have unknown header messages (generated with gen_bogus.c) */
            if((file2 = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
                TEST_ERROR

            /* Open the dataset with the unknown header message, but no extra flags */
            if((dset = H5Dopen2(file2, "/Dataset1", H5P_DEFAULT)) < 0)
                TEST_ERROR
            if(H5Dclose(dset) < 0)
                TEST_ERROR

            PASSED();

            TESTING("object in r/o file with unknown header message & 'fail if unknown and open for write' flag set");

            /* Open the dataset with the unknown header message, and "fail if unknown and open for write" flag */
            if((dset = H5Dopen2(file2, "/Dataset2", H5P_DEFAULT)) < 0)
                TEST_ERROR
            if(H5Dclose(dset) < 0)
                TEST_ERROR

            PASSED();

            TESTING("object in r/o file with unknown header message & 'fail if unknown always' flag set");

            /* Attempt to open the dataset with the unknown header message, and "fail if unknown always" flag */
            H5E_BEGIN_TRY {
                dset = H5Dopen2(file2, "/Dataset3", H5P_DEFAULT);
            } H5E_END_TRY;
            if(dset >= 0) {
                H5Dclose(dset);
                TEST_ERROR
            } /* end if */

            PASSED();

            TESTING("object with unknown header message & 'mark if unknown' flag set");

            /* Copy object with "mark if unknown" flag on message into file that can be modified */
            if(H5Ocopy(file2, "/Dataset4", file, "/Dataset4", H5P_DEFAULT, H5P_DEFAULT) < 0)
                TEST_ERROR

            /* Close the file we created (to flush changes to file) */
            if(H5Fclose(file) < 0)
                TEST_ERROR

            /* Re-open the file created, with read-only permissions */
            if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
                TEST_ERROR

            /* Open the dataset with the "mark if unknown" message */
            if((dset = H5Dopen2(file, "/Dataset4", H5P_DEFAULT)) < 0)
                TEST_ERROR

            /* Check that the "unknown" message was _NOT_ marked */
            if(H5O_check_msg_marked_test(dset, FALSE) < 0)
                FAIL_STACK_ERROR

            /* Close the dataset */
            if(H5Dclose(dset) < 0)
                TEST_ERROR

            /* Close the file we created (to flush change to object header) */
            if(H5Fclose(file) < 0)
                TEST_ERROR

            /* Re-open the file created */
            if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
                TEST_ERROR

            /* Open the dataset with the "mark if unknown" message */
            if((dset = H5Dopen2(file, "/Dataset4", H5P_DEFAULT)) < 0)
                TEST_ERROR

            /* Create data space */
            if((sid = H5Screate(H5S_SCALAR)) < 0)
                FAIL_STACK_ERROR

            /* Create an attribute, to get the object header into write access */
            if((aid = H5Acreate2(dset, "Attr", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
                FAIL_STACK_ERROR

            /* Close dataspace */
            if(H5Sclose(sid) < 0)
                FAIL_STACK_ERROR

            /* Close attribute */
            if(H5Aclose(aid) < 0)
                FAIL_STACK_ERROR

            /* Close the dataset */
            if(H5Dclose(dset) < 0)
                TEST_ERROR

            /* Close the file we created (to flush change to object header) */
            if(H5Fclose(file) < 0)
                TEST_ERROR

            /* Re-open the file created */
            if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
                TEST_ERROR

            /* Re-open the dataset with the "mark if unknown" message */
            if((dset = H5Dopen2(file, "/Dataset4", H5P_DEFAULT)) < 0)
                TEST_ERROR

            /* Check that the "unknown" message was marked */
            if(H5O_check_msg_marked_test(dset, TRUE) < 0)
                FAIL_STACK_ERROR

            /* Close the dataset */
            if(H5Dclose(dset) < 0)
                TEST_ERROR

            /* Close the file with the bogus objects */
            if(H5Fclose(file2) < 0)
                TEST_ERROR

            PASSED();

            /* Open the file with objects that have unknown header messages (generated with gen_bogus.c) with RW intent this time */
            if((file2 = H5Fopen(testfile, H5F_ACC_RDWR, H5P_DEFAULT)) < 0)
                TEST_ERROR

            TESTING("object in r/w file with unknown header message & 'fail if unknown and open for write' flag set");

            /* Attempt to open the dataset with the unknown header message, and "fail if unknown and open for write" flag */
            H5E_BEGIN_TRY {
                dset = H5Dopen2(file2, "/Dataset2", H5P_DEFAULT);
            } H5E_END_TRY;
            if(dset >= 0) {
                H5Dclose(dset);
                TEST_ERROR
            } /* end if */

            PASSED();

            TESTING("object in r/w file with unknown header message & 'fail if unknown always' flag set");

            /* Attempt to open the dataset with the unknown header message, and "fail if unknown always" flag */
            H5E_BEGIN_TRY {
                dset = H5Dopen2(file2, "/Dataset3", H5P_DEFAULT);
            } H5E_END_TRY;
            if(dset >= 0) {
                H5Dclose(dset);
                TEST_ERROR
            } /* end if */
Esempio n. 30
0
/* 
 * Append planes, each of (1,2*chunksize,2*chunksize) to the dataset.
 * In other words, 4 chunks are appended to the dataset at a time.
 * Fill each plane with the plane number and then write it at the nth plane.
 * Increase the plane number and repeat till the end of dataset, when it
 * reaches chunksize long. End product is a (2*chunksize)^3 cube.
 *
 * Return: 0 succeed; -1 fail.
 */
static int 
write_file(void)
{
    hid_t	fid;          	/* File ID for new HDF5 file */
    hid_t	dsid;         	/* dataset ID */
    hid_t       fapl;         	/* File access property list */
    hid_t	dcpl;      	/* Dataset creation property list */
    char	*name;
    UC_CTYPE	*buffer, *bufptr;	/* data buffer */
    hsize_t	cz=chunksize_g;		/* Chunk size */
    hid_t	f_sid;	    	/* dataset file space id */
    hid_t	m_sid;	    	/* memory space id */
    int		rank;	    	/* rank */
    hsize_t 	chunk_dims[3];	/* Chunk dimensions */
    hsize_t	dims[3];    	/* Dataspace dimensions */
    hsize_t	memdims[3]; 	/* Memory space dimensions */
    hsize_t	start[3] = {0,0,0}, count[3];    /* Hyperslab selection values */
    hbool_t 	disabled;   	/* Object's disabled status */	
    hsize_t     i, j, k;

    name = filename_g;

    /* Open the file */
    if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
        return -1;
    if(use_swmr_g)
        if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
            return -1;
    if((fid = H5Fopen(name, H5F_ACC_RDWR | (use_swmr_g ? H5F_ACC_SWMR_WRITE : 0), fapl)) < 0){
	fprintf(stderr, "H5Fopen failed\n");
        return -1;
    }

    /* Open the dataset of the program name */
    if((dsid = H5Dopen2(fid, progname_g, H5P_DEFAULT)) < 0){
	fprintf(stderr, "H5Dopen2 failed\n");
	return -1;
    }

    /* Disabled mdc flushed for the dataset */
    if(H5Odisable_mdc_flushes(dsid) < 0) {
	fprintf(stderr, "H5Odisable_mdc_flushes failed\n");
	return -1;
    }

    /* Get mdc disabled status of the dataset */
    if(H5Oare_mdc_flushes_disabled(dsid, &disabled) < 0) {
	fprintf(stderr, "H5Oare_mdc_flushes_disabled failed\n");
	return -1;
    } else if(disabled)
	printf("Dataset has disabled mdc flushes.\n");
    else
	printf("Dataset should have disabled its mdc flushes.\n");

    /* Find chunksize used */
    if ((dcpl = H5Dget_create_plist(dsid)) < 0){
	fprintf(stderr, "H5Dget_create_plist failed\n");
	return -1;
    }
    if (H5D_CHUNKED != H5Pget_layout(dcpl)){
	fprintf(stderr, "storage layout is not chunked\n");
	return -1;
    }
    if ((rank = H5Pget_chunk(dcpl, 3, chunk_dims)) != 3){
	fprintf(stderr, "storage rank is not 3\n");
	return -1;
    }

    /* verify chunk_dims against set paramenters */
    if (chunk_dims[0]!= chunkdims_g[0] || chunk_dims[1] != cz || chunk_dims[2] != cz){
	fprintf(stderr, "chunk size is not as expected. Got dims=(%llu,%llu,%llu)\n",
	    (unsigned long long)chunk_dims[0], (unsigned long long)chunk_dims[1], 
            (unsigned long long)chunk_dims[2]);
	return -1;
    }

    /* allocate space for data buffer 1 X dims[1] X dims[2] of UC_CTYPE */
    memdims[0]=1;
    memdims[1] = dims_g[1];
    memdims[2] = dims_g[2];
    if ((buffer=(UC_CTYPE*)HDmalloc((size_t)memdims[1]*(size_t)memdims[2]*sizeof(UC_CTYPE)))==NULL) {
	fprintf(stderr, "malloc: failed\n");
	return -1;
    };

    /*
     * Get dataset rank and dimension.
     */
    f_sid = H5Dget_space(dsid);    /* Get filespace handle first. */
    rank  = H5Sget_simple_extent_ndims(f_sid);
    if (rank != UC_RANK){
	fprintf(stderr, "rank(%d) of dataset does not match\n", rank);
	return -1;
    }
    if (H5Sget_simple_extent_dims(f_sid, dims, NULL) < 0){
	fprintf(stderr, "H5Sget_simple_extent_dims got error\n");
	return -1;
    }
    printf("dataset rank %d, dimensions %llu x %llu x %llu\n",
	   rank, (unsigned long long)(dims[0]), (unsigned long long)(dims[1]), 
           (unsigned long long)(dims[2]));
    /* verify that file space dims are as expected and are consistent with memory space dims */
    if (dims[0] != 0 || dims[1] != memdims[1] || dims[2] != memdims[2]){
	fprintf(stderr, "dataset is not empty. Got dims=(%llu,%llu,%llu)\n",
	    (unsigned long long)dims[0], (unsigned long long)dims[1], 
            (unsigned long long)dims[2]);
	return -1;
    }
    
    /* setup mem-space for buffer */
    if ((m_sid=H5Screate_simple(rank, memdims, NULL))<0){
	fprintf(stderr, "H5Screate_simple for memory failed\n");
	return -1;
    };

    /* write planes */
    count[0]=1;
    count[1]=dims[1];
    count[2]=dims[2];
    for (i=0; i<nplanes_g; i++){
	/* fill buffer with value i+1 */
	bufptr = buffer;
	for (j=0; j<dims[1]; j++)
	    for (k=0; k<dims[2]; k++)
		*bufptr++ = i;

	/* extend the dataset by one for new plane */
	dims[0]=i+1;
        if(H5Dset_extent(dsid, dims) < 0){
	    fprintf(stderr, "H5Dset_extent failed\n");
            return -1;
	}

        /* Get the dataset's dataspace */
        if((f_sid = H5Dget_space(dsid)) < 0){
	    fprintf(stderr, "H5Dset_extent failed\n");
            return -1;
	}

	start[0]=i;
        /* Choose the next plane to write */
        if(H5Sselect_hyperslab(f_sid, H5S_SELECT_SET, start, NULL, count, NULL) < 0){
	    fprintf(stderr, "Failed H5Sselect_hyperslab\n");
            return -1;
	}

        /* Write plane to the dataset */
        if(H5Dwrite(dsid, UC_DATATYPE, m_sid, f_sid, H5P_DEFAULT, buffer) < 0){
	    fprintf(stderr, "Failed H5Dwrite\n");
            return -1;
	}

	/* Flush the dataset for every "chunkplanes_g" planes */
	if(!((i + 1) % (hsize_t)chunkplanes_g)) {
	    if(H5Dflush(dsid) < 0) {
		fprintf(stderr, "Failed to H5Dflush dataset\n");
		return -1;
	    }
	}
    }

    if(H5Dflush(dsid) < 0) {
	fprintf(stderr, "Failed to H5Dflush dataset\n");
	return -1;
    }

    /* Enable mdc flushes for the dataset */
    /* Closing the dataset later will enable mdc flushes automatically if this is not done */
    if(disabled)
	if(H5Oenable_mdc_flushes(dsid) < 0) {
	    fprintf(stderr, "Failed to H5Oenable_mdc_flushes\n");
	    return -1;
	}

    /* Done writing. Free/Close all resources including data file */
    HDfree(buffer);

    if(H5Dclose(dsid) < 0){
	fprintf(stderr, "Failed to close datasete\n");
	return -1;
    }
    if(H5Sclose(m_sid) < 0){
	fprintf(stderr, "Failed to close memory space\n");
	return -1;
    }
    if(H5Sclose(f_sid) < 0){
	fprintf(stderr, "Failed to close file space\n");
	return -1;
    }
    if(H5Pclose(fapl) < 0){
	fprintf(stderr, "Failed to property list\n");
	return -1;
    }
    if(H5Fclose(fid) < 0){
	fprintf(stderr, "Failed to close file id\n");
	return -1;
    }

    return 0;
} /* write_file() */