Example #1
0
/* Write the chunks in a random pattern.  This provides a read performance
 * worse than when the chunks are written and read in the same order, whether
 * it is by row or by column.
 *
 * Created by Albert Cheng and Christian Chilan 2010/7/13.
 */
int
createfilerandom( void )
{
	hid_t   file_id, dset_id, filespace, memspace, fapl, dxpl, dcpl;
	hsize_t dimsf[2], count[2], offset[2], chunk_dims[2] = {CX, CY};
	char   *  data, table[RC][CC];
	unsigned long i, j, cx, cy;
	fapl = H5Pcreate( H5P_FILE_ACCESS );
	dcpl = H5Pcreate( H5P_DATASET_CREATE );
	dxpl = H5Pcreate( H5P_DATASET_XFER );
	H5Pset_chunk( dcpl, 2, chunk_dims );
	fapl = dxpl = H5P_DEFAULT;
	file_id = H5Fcreate( "random_alloc.h5", H5F_ACC_TRUNC, H5P_DEFAULT, fapl );
	dimsf[0] = NX;
	dimsf[1] = NY;
	filespace = H5Screate_simple( 2, dimsf, NULL );
	dset_id = H5Dcreate( file_id, "dataset1", H5T_NATIVE_CHAR, filespace,
	                     H5P_DEFAULT, dcpl, H5P_DEFAULT );
	count[0] = CX;
	count[1] = CY;
	memspace = H5Screate_simple( 2, count, NULL );
	data = ( char * )malloc( count[0] * count[1] * sizeof( char ) );

	for( i = 0; i < RC; i++ )
		for( j = 0; j < CC; j++ )
			table[i][j] = 0;

	for( i = 0; i < RC * CC; i++ ) {
		do {
			cx = rand() % RC;
			cy = rand() % CC;
		} while( table[cx][cy] );

		for( j = 0; j < count[0]*count[1]; j++ ) {
			data[j] = cx + cy;
		}

		table[cx][cy] = 1;

		offset[0] = cx * CX;
		offset[1] = cy * CY;

		H5Sselect_hyperslab( filespace, H5S_SELECT_SET, offset, NULL, count, NULL );
		H5Dwrite( dset_id, H5T_NATIVE_CHAR, memspace, filespace, dxpl, data );

	}

	free( data );
	H5Dclose( dset_id );
	H5Sclose( filespace );
	H5Sclose( memspace );
	H5Pclose( dxpl );
	H5Pclose( dcpl );
	H5Pclose( fapl );
	H5Fclose( file_id );
	return 0;
}
Example #2
0
/*
 * Create HDF5 data set.
 */
static void SetupDataSet(void *fd, IOR_param_t * param)
{
        char dataSetName[MAX_STR];
        hid_t dataSetPropList;
        int dataSetID;
        static int dataSetSuffix = 0;

        /* may want to use an extendable dataset (H5S_UNLIMITED) someday */
        /* may want to use a chunked dataset (H5S_CHUNKED) someday */

        /* need to reset suffix counter if newly-opened file */
        if (newlyOpenedFile)
                dataSetSuffix = 0;

        /* may want to use individual access to each data set someday */
        if (param->individualDataSets) {
                dataSetID = (rank + rankOffset) % param->numTasks;
        } else {
                dataSetID = 0;
        }

        sprintf(dataSetName, "%s-%04d.%04d", "Dataset", dataSetID,
                dataSetSuffix++);

        if (param->open == WRITE) {     /* WRITE */
                /* create data set */
                dataSetPropList = H5Pcreate(H5P_DATASET_CREATE);
                /* check if hdf5 available */
#if defined (H5_VERS_MAJOR) && defined (H5_VERS_MINOR)
                /* no-fill option not available until hdf5-1.6.x */
#if (H5_VERS_MAJOR > 0 && H5_VERS_MINOR > 5)
                if (param->noFill == TRUE) {
                        if (rank == 0 && verbose >= VERBOSE_1) {
                                fprintf(stdout, "\nusing 'no fill' option\n");
                        }
                        HDF5_CHECK(H5Pset_fill_time(dataSetPropList,
                                                    H5D_FILL_TIME_NEVER),
                                   "cannot set fill time for property list");
                }
#else
                char errorString[MAX_STR];
                sprintf(errorString, "'no fill' option not available in %s",
                        test->apiVersion);
                ERR(errorString);
#endif
#else
                WARN("unable to determine HDF5 version for 'no fill' usage");
#endif
                dataSet =
                    H5Dcreate(*(hid_t *) fd, dataSetName, H5T_NATIVE_LLONG,
                              dataSpace, dataSetPropList);
                HDF5_CHECK(dataSet, "cannot create data set");
        } else {                /* READ or CHECK */
                dataSet = H5Dopen(*(hid_t *) fd, dataSetName);
                HDF5_CHECK(dataSet, "cannot create data set");
        }
}
Example #3
0
herr_t ASDF_write_auxiliary_data(hid_t loc_id, const char *sf_constants_file, const char *sf_Parfile) {
  hsize_t dims[1] = {strlen(sf_constants_file)};
  hsize_t dims2[1] = {strlen(sf_Parfile)};
  hsize_t maxdims[1] = {H5S_UNLIMITED};

  hid_t array_id, group_id, group_id2, space_id, dcpl_id;
  CHK_H5(group_id = H5Gcreate(loc_id, "AuxiliaryData",
        H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT));
  CHK_H5(group_id2 = H5Gcreate(loc_id, "/AuxiliaryData/File",
        H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT));

  /* Fill up with whatever AuxiliaryData contains. */
  
  /* Write specfem3d constants.h */

  CHK_H5(space_id = H5Screate_simple(1, dims, maxdims));
  CHK_H5(dcpl_id = H5Pcreate(H5P_DATASET_CREATE));
  CHK_H5(H5Pset_chunk(dcpl_id, 1, dims));

  CHK_H5(array_id = H5Dcreate(group_id2, "constants_h", H5T_STD_I8LE, space_id,
        H5P_DEFAULT, dcpl_id, H5P_DEFAULT));
  CHK_H5(H5Dwrite(array_id, H5T_STD_I8LE, H5S_ALL, H5S_ALL,
        H5P_DEFAULT, sf_constants_file));
  CHK_H5(H5Dclose(array_id));
  CHK_H5(H5Sclose(space_id));
 
  /* Write specfem3d Parfile */

  CHK_H5(space_id = H5Screate_simple(1, dims2, maxdims));
  CHK_H5(dcpl_id = H5Pcreate(H5P_DATASET_CREATE));
  CHK_H5(H5Pset_chunk(dcpl_id, 1, dims2));

  CHK_H5(array_id = H5Dcreate(group_id2, "Parfile", H5T_STD_I8LE, space_id,
        H5P_DEFAULT, dcpl_id, H5P_DEFAULT));
  CHK_H5(H5Dwrite(array_id, H5T_STD_I8LE, H5S_ALL, H5S_ALL,
        H5P_DEFAULT, sf_Parfile));
  CHK_H5(H5Dclose(array_id));
  CHK_H5(H5Sclose(space_id));

  CHK_H5(H5Gclose(group_id2));
  CHK_H5(H5Gclose(group_id));

  return 0; // Success
}
Example #4
0
void LifeV::HDF5IO::createTable (const std::string& tableName,
                                 hid_t& fileDataType,
                                 hsize_t tableDimensions[])
{
    tableHandle& currentTable = M_tableList[tableName];

    currentTable.filespace = H5Screate_simple (2, tableDimensions,
                                               tableDimensions);
#ifdef H5_USE_16_API
    currentTable.dataset = H5Dcreate (M_fileId, tableName.c_str(), fileDataType,
                                      currentTable.filespace, H5P_DEFAULT);
#else
    currentTable.dataset = H5Dcreate (M_fileId, tableName.c_str(), fileDataType,
                                      currentTable.filespace, H5P_DEFAULT,
                                      H5P_DEFAULT, H5P_DEFAULT);
#endif
    currentTable.plist = H5Pcreate (H5P_DATASET_XFER);
    H5Pset_dxpl_mpio (currentTable.plist, H5FD_MPIO_COLLECTIVE);
}
Example #5
0
/*-------------------------------------------------------------------------
 * Function:	test_noconv
 *
 * Purpose:	Tests creation of datasets when no conversion is present.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Monday, January  4, 1999
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_noconv(hid_t file)
{
    hid_t	cwg=-1, type=-1, space=-1, dset=-1;
    c_e1	val;
    static c_e1	data1[]={E1_RED,   E1_GREEN, E1_BLUE,  E1_GREEN, E1_WHITE,
			 E1_WHITE, E1_BLACK, E1_GREEN, E1_BLUE,  E1_RED,
			 E1_RED,   E1_BLUE,  E1_GREEN, E1_BLACK, E1_WHITE,
			 E1_RED,   E1_WHITE, E1_GREEN, E1_GREEN, E1_BLUE};
    c_e1	data2[NELMTS(data1)];
    hsize_t	ds_size[1]={NELMTS(data1)};
    size_t	i;

    TESTING("no-conversion datasets");
    if ((cwg=H5Gcreate(file, "test_noconv", 0))<0) goto error;

    if ((type = H5Tcreate(H5T_ENUM, sizeof(c_e1)))<0) goto error;
    if (H5Tenum_insert(type, "RED",   CPTR(val, E1_RED  ))<0) goto error;
    if (H5Tenum_insert(type, "GREEN", CPTR(val, E1_GREEN))<0) goto error;
    if (H5Tenum_insert(type, "BLUE",  CPTR(val, E1_BLUE ))<0) goto error;
    if (H5Tenum_insert(type, "WHITE", CPTR(val, E1_WHITE))<0) goto error;
    if (H5Tenum_insert(type, "BLACK", CPTR(val, E1_BLACK))<0) goto error;

    if ((space=H5Screate_simple(1, ds_size, NULL))<0) goto error;
    if ((dset=H5Dcreate(cwg, "color_table", type, space, H5P_DEFAULT))<0)
	goto error;
    if (H5Dwrite(dset, type, space, space, H5P_DEFAULT, data1)<0) goto error;
    if (H5Dread(dset, type, space, space, H5P_DEFAULT, data2)<0) goto error;

    for (i=0; i<ds_size[0]; i++) {
	if (data1[i]!=data2[i]) {
	    H5_FAILED();
	    printf("    data1[%lu]=%d, data2[%lu]=%d (should be same)\n",
		   (unsigned long)i, (int)(data1[i]),
		   (unsigned long)i, (int)(data2[i]));
	    goto error;
	}
    }

    if (H5Dclose(dset)<0) goto error;
    if (H5Sclose(space)<0) goto error;
    if (H5Tclose(type)<0) goto error;
    if (H5Gclose(cwg)<0) goto error;
    PASSED();
    return 0;

 error:
    H5E_BEGIN_TRY {
	H5Dclose(dset);
	H5Sclose(space);
	H5Tclose(type);
	H5Gclose(cwg);
    } H5E_END_TRY;
    return 1;
}
Example #6
0
File: cxi.c Project: cxidb/libcxi
static int try_write_float_array(hid_t loc, char * name, double * values, int ndims, hsize_t * dims){
  hid_t space = H5Screate_simple(ndims,dims,NULL);
  if(space < 0) return space;
  hid_t ds = H5Dcreate(loc,name,H5T_NATIVE_FLOAT,space,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
  if(ds < 0) return ds;
  herr_t status = H5Sclose(space);
  if(status < 0) return status;    
  status = H5Dwrite(ds,H5T_NATIVE_DOUBLE,H5S_ALL,H5S_ALL,H5P_DEFAULT,values);
  if(status < 0) return status;    
  return H5Dclose(ds);
}
void Simulation3D::dumpTimings(unsigned long* timings, hsize_t total_timings,
			       unsigned int steps_per_timing) {
  std::ostringstream filename(std::ios::out);
  filename << dumpDir << "/timing_s" << blockSize << "_p" << world.size() << ".h5";
  
  hid_t file_id=H5Fcreate(filename.str().c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

  hid_t timingspace=H5Screate_simple(1, & total_timings, NULL);
  hid_t dx_space = H5Screate(H5S_SCALAR);
  hid_t dt_space = H5Screate(H5S_SCALAR);
  hid_t bs_space = H5Screate(H5S_SCALAR);
  hid_t ns_space = H5Screate(H5S_SCALAR);
  hid_t alg_name_space = H5Screate(H5S_SCALAR);
  hid_t atype = H5Tcopy(H5T_C_S1);
#ifndef YEE
  H5Tset_size(atype, xUpdateRHSs->getAlgName().length());
#else
  H5Tset_size(atype, std::string("Yee").length());
#endif
  H5Tset_strpad(atype, H5T_STR_NULLTERM);

  hid_t timing_dset_id = H5Dcreate(file_id, "timings", H5T_NATIVE_LONG, timingspace,
				   H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
  hid_t dx_attr_id = H5Acreate(timing_dset_id, "dx", H5T_NATIVE_DOUBLE, dx_space,
			       H5P_DEFAULT, H5P_DEFAULT);
  hid_t dt_attr_id = H5Acreate(timing_dset_id, "dt", H5T_NATIVE_DOUBLE, dt_space,
			       H5P_DEFAULT, H5P_DEFAULT);
  hid_t bs_attr_id = H5Acreate(timing_dset_id, "blockSize", H5T_NATIVE_UINT, bs_space,
			       H5P_DEFAULT, H5P_DEFAULT);
  hid_t ns_attr_id = H5Acreate(timing_dset_id, "stepsPerTiming", H5T_NATIVE_UINT, ns_space,
			       H5P_DEFAULT, H5P_DEFAULT);
  hid_t alg_attr_id = H5Acreate(timing_dset_id,"communicationStrategy", atype, alg_name_space,
				H5P_DEFAULT, H5P_DEFAULT);

  herr_t status = H5Dwrite(timing_dset_id, H5T_NATIVE_LONG, H5S_ALL, H5S_ALL,
			   H5P_DEFAULT, timings);
  status = H5Awrite(dx_attr_id, H5T_NATIVE_DOUBLE, & dx);
  status = H5Awrite(dt_attr_id, H5T_NATIVE_DOUBLE, & dt);
  status = H5Awrite(bs_attr_id, H5T_NATIVE_UINT, & blockSize);
  status = H5Awrite(ns_attr_id, H5T_NATIVE_UINT, & steps_per_timing);
#ifndef YEE
  status = H5Awrite(alg_attr_id, atype, xUpdateRHSs->getAlgName().c_str());
#else
  status = H5Awrite(alg_attr_id, atype, "Yee");
#endif

  H5Sclose(timingspace); H5Sclose(dx_space); H5Sclose(dt_space);
  H5Sclose(alg_name_space); H5Sclose(bs_space); H5Sclose(ns_space);
  H5Tclose(atype);
  H5Aclose(dx_attr_id); H5Aclose(dt_attr_id); H5Aclose(bs_attr_id);
  H5Aclose(alg_attr_id); H5Aclose(ns_attr_id);
  H5Dclose(timing_dset_id);
  H5Fclose(file_id);
}
Example #8
0
/*
 * - Nom de la fonction : _MEDdatasetStringEcrire
 * - Description : ecriture d'un dataset tableau de caracteres
 * - Parametres :
 *     - pere (IN)     : l'ID de l'objet HDF pere ou placer l'attribut
 *     - nom  (IN)     : le nom de l'attribut 
 *     - dimd (IN)     : profil du tableau
 *     - val  (IN)     : valeurs du tableau
 * - Resultat : 0 en cas de succes, -1 sinon
 */ 
med_err _MEDdatasetStringEcrire(med_idt pere, char *nom, med_size *dimd, char *val)
{
  med_idt dataset;
  med_idt datatype = 0;
  med_idt dataspace = 0;
  med_err ret;
  med_mode_acces MED_MODE_ACCES;

  if ( (MED_MODE_ACCES = _MEDmodeAcces(pere) ) == MED_UNDEF_MODE_ACCES ) {
    MESSAGE("Impossible de déterminer le mode d'acces au fichier ");
    return -1;
  }

  if ((dataset = H5Dopen(pere,nom)) < 0)
    {
      if ((dataspace = H5Screate_simple(1,dimd,NULL)) < 0)
	return -1;
      if((datatype = H5Tcopy(H5T_C_S1)) < 0)
	return -1;
      if((ret = H5Tset_size(datatype,1)) < 0)
	return -1;
      if ((dataset = H5Dcreate(pere,nom,datatype,dataspace,
			     H5P_DEFAULT)) < 0)
	return -1;    
    }
  else
    if ( MED_MODE_ACCES == MED_LECTURE_AJOUT)
      {
	H5Dclose(dataset);
	return -1;
      }
    else
      {
      if ((dataspace = H5Screate_simple(1,dimd,NULL)) < 0)
	return -1;
      if((datatype = H5Tcopy(H5T_C_S1)) < 0)
	return -1;
      if((ret = H5Tset_size(datatype,1)) < 0)
	return -1;
      }
  if ((ret = H5Dwrite(dataset,datatype,H5S_ALL,H5S_ALL,
		      H5P_DEFAULT, val)) < 0)
    return -1;
  if (dataspace)
    if((ret = H5Sclose(dataspace)) < 0)
      return -1;
  if (datatype)
    if ((ret = H5Tclose(datatype)) < 0)
      return -1;
  if ((ret = H5Dclose(dataset)) < 0)
    return -1;

  return 0;
}
Example #9
0
File: cxi.c Project: cxidb/libcxi
static int try_write_float(hid_t loc, char * name, double value){
  hid_t space = H5Screate(H5S_SCALAR);
  if(space < 0) return space;
  hid_t ds = H5Dcreate(loc,name,H5T_NATIVE_FLOAT,space,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
  if(ds < 0) return ds;
  herr_t status = H5Sclose(space);
  if(status < 0) return status;    
  status = H5Dwrite(ds,H5T_NATIVE_DOUBLE,H5S_ALL,H5S_ALL,H5P_DEFAULT,&value);
  if(status < 0) return status;    
  return H5Dclose(ds);
}
Example #10
0
void extend1dDoubleExt(hdf5_ext_info *hi, void *array, hsize_t len) {
    if(!hi || !array || len <=0)
        return;
    if(hi->cur_dim == 0) {
        hi->cur_dim = len;
        /* Create the data space with unlimited dimensions. */
        hsize_t      maxdim = H5S_UNLIMITED;
        hi->dataspace = H5Screate_simple (1, &(hi->cur_dim),&maxdim); 


        /* Modify dataset creation properties, i.e. enable chunking  */
        hid_t prop = H5Pcreate (H5P_DATASET_CREATE);
        hi->status = H5Pset_chunk (prop, 1, &(hi->chunk_len));

        /* Create a new dataset within the file using chunk 
        creation properties.  */
        hi->dataset = H5Dcreate (hi->file_id, hi->dsetName,   H5T_NATIVE_DOUBLE, hi->dataspace,
                            H5P_DEFAULT, prop, H5P_DEFAULT);


        /* Write data to dataset */
        hi->status = H5Dwrite (hi->dataset,   H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL,
                        H5P_DEFAULT, array);
        hi->status = H5Pclose (prop);
        hi->status = H5Sclose (hi->dataspace);

    }
    else {
       /* Extend the dataset  */
        hi->cur_offset = hi->cur_dim ;
        hi->cur_dim += len;
        hi->status = H5Dextend (hi->dataset, &(hi->cur_dim));

        /* Select a hyperslab in extened portion of dataset  */
        hi->filespace = H5Dget_space (hi->dataset);
        hi->status = H5Sselect_hyperslab (hi->filespace, H5S_SELECT_SET, &(hi->cur_offset), NULL,
                                  &len, NULL);  

        /* Define memory space */
        hi->memspace = H5Screate_simple (1, &len, NULL); 

        /* Write the data to the extended portion of dataset  */
        hi->status = H5Dwrite (hi->dataset,   H5T_NATIVE_DOUBLE, hi->memspace, hi->filespace,
                       H5P_DEFAULT, array);    
        hi->status = H5Sclose (hi->memspace);
        hi->status = H5Sclose (hi->filespace);
        
    }
    
    
    
    
}
Example #11
0
    void DCDataSet::create(const CollectionType& colType,
            hid_t group, const Dimensions size, uint32_t ndims, bool compression)
    throw (DCException)
    {
        log_msg(2, "DCDataSet::create (%s, size %s)", name.c_str(), size.toString().c_str());

        if (opened)
            throw DCException(getExceptionString("create: dataset is already open"));

        // if the dataset already exists, remove/unlink it
        // note that this won't free the memory occupied by this
        // dataset, however, there currently is no function to delete
        // a dataset
        if (!checkExistence || (checkExistence && H5Lexists(group, name.c_str(), H5P_LINK_ACCESS_DEFAULT)))
            H5Ldelete(group, name.c_str(), H5P_LINK_ACCESS_DEFAULT);

        this->ndims = ndims;
        this->compression = compression;
        this->datatype = colType.getDataType();

        getLogicalSize().set(size);

        setChunking(colType.getSize());
        setCompression();

        if (getPhysicalSize().getScalarSize() != 0)
        {
            hsize_t *max_dims = new hsize_t[ndims];
            for (size_t i = 0; i < ndims; ++i)
                max_dims[i] = H5F_UNLIMITED;

            dataspace = H5Screate_simple(ndims, getPhysicalSize().getPointer(), max_dims);

            delete[] max_dims;
            max_dims = NULL;
        } else
            dataspace = H5Screate(H5S_NULL);



        if (dataspace < 0)
            throw DCException(getExceptionString("create: Failed to create dataspace"));

        // create the new dataset
        dataset = H5Dcreate(group, this->name.c_str(), this->datatype, dataspace,
                H5P_DEFAULT, dsetProperties, H5P_DEFAULT);

        if (dataset < 0)
            throw DCException(getExceptionString("create: Failed to create dataset"));

        isReference = false;
        opened = true;
    }
Example #12
0
/** write basisset: number of plane waves, plane wave coefficients
void F77_FUNC_(pwhdf_write_basis,PWHDF_WRITE_BASIS)(const double* g, const int* igtog, const int* ngtot)
{
  int ng=*ngtot;
  int *ig=(int*)malloc(3*ng*sizeof(int));
  for(int i=0,i3=0; i<ng; i++)
  {
    int cur=3*(igtog[i]-1);
    ig[i3++]=(int)g[cur++];
    ig[i3++]=(int)g[cur++];
    ig[i3++]=(int)g[cur++];
  }

  hid_t h_basis = H5Gcreate(h_file,"basis",0);
  hsize_t dim=1;
  hid_t dataspace= H5Screate_simple(1, &dim, NULL);
  hid_t dataset= H5Dcreate(h_basis, "num_planewaves", H5T_NATIVE_INT, dataspace, H5P_DEFAULT);
  hid_t ret = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,ngtot);
  H5Sclose(dataspace);
  H5Dclose(dataset);

  hsize_t dims[2];
  dims[0] = ng;
  dims[1] = 3;
  dataspace  = H5Screate_simple(2, dims, NULL);
  dataset =  H5Dcreate(h_basis, "planewaves", H5T_NATIVE_INT, dataspace, H5P_DEFAULT);
  ret = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,ig);
  H5Sclose(dataspace);
  H5Dclose(dataset);

  H5Gclose(h_basis);

  free(ig);
}
 */
void F77_FUNC_(pwhdf_write_parameters,PWHDF_WRITE_PARAMETERS)(
    const int* nelec, const int* nspin, const int* nband, const int* nk,
    const double* ecut, const double* alat, const double* at)
{

  hid_t h_param = H5Gcreate(h_file,"parameters",0);
  hsize_t dim=1;
  hid_t dataspace= H5Screate_simple(1, &dim, NULL);
  hid_t dataset= H5Dcreate(h_param, "num_spins", H5T_NATIVE_INT, dataspace, H5P_DEFAULT);
  hid_t ret = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,nspin);
  H5Sclose(dataspace);
  H5Dclose(dataset);

  dataspace= H5Screate_simple(1, &dim, NULL);
  dataset= H5Dcreate(h_param, "num_electrons", H5T_NATIVE_INT, dataspace, H5P_DEFAULT);
  ret = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,nelec);
  H5Sclose(dataspace);
  H5Dclose(dataset);

  dataspace= H5Screate_simple(1, &dim, NULL);
  dataset= H5Dcreate(h_param, "num_bands", H5T_NATIVE_INT, dataspace, H5P_DEFAULT);
  ret = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,nband);
  H5Sclose(dataspace);
  H5Dclose(dataset);

  dataspace= H5Screate_simple(1, &dim, NULL);
  dataset= H5Dcreate(h_param, "num_twists", H5T_NATIVE_INT, dataspace, H5P_DEFAULT);
  ret = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,nk);
  H5Sclose(dataspace);
  H5Dclose(dataset);

  int iscomplex=1;
  dataspace= H5Screate_simple(1, &dim, NULL);
  dataset= H5Dcreate(h_param, "complex_coefficients", H5T_NATIVE_INT, dataspace, H5P_DEFAULT);
  ret = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,&iscomplex);
  H5Sclose(dataspace);
  H5Dclose(dataset);

  dataspace= H5Screate_simple(1, &dim, NULL);
  dataset= H5Dcreate(h_param, "maximum_ecut", H5T_NATIVE_DOUBLE, dataspace, H5P_DEFAULT);
  ret = H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,ecut);
  H5Sclose(dataspace);
  H5Dclose(dataset);

  double lattice[9];
  for(int i=0; i<9; i++) lattice[i]=(*alat)*at[i];
  hsize_t dims[]={3,3};
  dataspace  = H5Screate_simple(2, dims, NULL);
  dataset =  H5Dcreate(h_param, "lattice", H5T_NATIVE_DOUBLE, dataspace, H5P_DEFAULT);
  ret = H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,lattice);
  H5Sclose(dataspace);
  H5Dclose(dataset);

  H5Gclose(h_param);
}
Example #13
0
/* write eigen value and eigen vector for (ibnd, ispin) */
void F77_FUNC_(pwhdf_write_rho,PWHDF_WRITE_RHO)(const double* rho, const double* rhog, int ngm)
{
  /* write eigenvector */
  hsize_t dims[3];
  dims[0] = h_ngrid[0];
  dims[1] = h_ngrid[1];
  dims[2] = h_ngrid[2];
  hid_t dataspace  = H5Screate_simple(3, dims, NULL);
  hid_t dataset =  H5Dcreate(h_file, "chargedensity_r", H5T_NATIVE_DOUBLE, dataspace, H5P_DEFAULT);
  hid_t ret = H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,rho);
  H5Sclose(dataspace);
  H5Dclose(dataset);

  /*
  hsize_t gdims[2];
  gdims[0]=ngm;
  gdims[1]=2;
  dataspace  = H5Screate_simple(2, gdims, NULL);
  dataset =  H5Dcreate(h_file, "chargedensity_g", H5T_NATIVE_DOUBLE, dataspace, H5P_DEFAULT);
  ret = H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,rhog);
  H5Sclose(dataspace);
  H5Dclose(dataset);
  */

  /* testing with paraview/vtk
  if(is_gamma)
  {
    char vtkname[32];
    sprintf(vtkname,"band%i.vtk",(*ibnd)-1);
    FILE *vtk=fopen(vtkname,"w");

    fprintf(vtk,"# vtk DataFile Version 3.0\n");
    fprintf(vtk,"vtk output\n");
    fprintf(vtk,"ASCII\n");
    fprintf(vtk,"DATASET STRUCTURED_POINTS\n");
    fprintf(vtk,"DIMENSIONS %i %i %i\n",h_ngrid[0],h_ngrid[1],h_ngrid[2]);
    fprintf(vtk,"ORIGIN 0 0 0\n");
    fprintf(vtk,"SPACING 1 1 1\n");
    fprintf(vtk,"\nPOINT_DATA %i\n",h_ngridtot);
    fprintf(vtk,"SCALARS scalars float\n");
    fprintf(vtk,"LOOKUP_TABLE default\n");

    for(int i=0,i2=0; i<h_ngridtot;i+=10)
    { 
      for(int j=0; j<10; j++,i2+=2) fprintf(vtk,"%12.6e ",eigr[i2]*eigr[i2]);
      fprintf(vtk,"\n");
    }
    fprintf(vtk,"\n");
    fclose(vtk);
  }
  */
}
Example #14
0
herr_t writeInt2d(hid_t file_id,const char *dsName, void * matrix, int DIM_X, int DIM_Y) {
    hid_t  dataset_id,dataspace_id;
    hsize_t     dims[] = {DIM_Y,DIM_X}; /*DIM_Y corresponds to number of rows, DIM_X to columns*/
    herr_t status;
    /* Create the data space for the dataset. */

    dataspace_id = H5Screate_simple(2, dims, NULL);
    /* Create the dataset. */
    if(sizeof(int) == 4)
        dataset_id = H5Dcreate(file_id, dsName, H5T_STD_I32LE, dataspace_id, 
                          H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    else
        dataset_id = H5Dcreate(file_id, dsName, H5T_STD_I64LE, dataspace_id, 
                          H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    status = H5Sclose(dataspace_id);
    /*Write the dataset*/
    status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, 
                     matrix);
    /* End access to the dataset and release resources used by it. */
    status = H5Dclose(dataset_id);
    return status;    
}
Example #15
0
File: cxi.c Project: cxidb/libcxi
CXI_File * cxi_open_file(const char * filename, const char * mode){
  cxi_debug("opening file");
  CXI_File * file = malloc(sizeof(CXI_File));
  if(!file){
    return NULL;
  }
  if(strcmp(mode,"r") == 0){
    file->handle = H5Fopen(filename, H5F_ACC_RDONLY,H5P_DEFAULT);
    if(file->handle < 0){
      free(file);
      return NULL;
    }
    file->filename = malloc(sizeof(char)*(strlen(filename)+1));
    strcpy(file->filename,filename);
    /* Read existing entries */
    int n = find_max_suffix(file->handle, "entry");
    file->entry_count = n;
    file->entries = calloc(sizeof(CXI_Entry_Reference *),n);
    char buffer[1024];
    for(int i = 0;i<n;i++){
      file->entries[i] = calloc(sizeof(CXI_Entry_Reference),1);
      sprintf(buffer,"entry_%d",i+1);
      file->entries[i]->parent_handle = file->handle;
      file->entries[i]->group_name = malloc(sizeof(char)*(strlen(buffer)+1));
      strcpy(file->entries[i]->group_name,buffer);      
    }
    /* Read the CXI verion */
    file->cxi_version = -1;
    try_read_int(file->handle, "cxi_version",&file->cxi_version);
    if(file->cxi_version < 0){
      /* Warning: Could not read CXI version */
    }else if(file->cxi_version >= CXI_VERSION){
      /* Warning: CXI version of the file is higher than from libcxi */
    }
    return file;    
  }else if(strcmp(mode,"w") == 0){
    file->handle = H5Fcreate(filename,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);
    file->filename = malloc(sizeof(char)*(strlen(filename)+1));
    strcpy(file->filename,filename);
    hsize_t dims[1] = {1};
    hid_t dataspace = H5Screate_simple(1, dims, dims);
    hid_t dataset = H5Dcreate(file->handle, "cxi_version", H5T_NATIVE_INT, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &CXI_VERSION);
    H5Dclose(dataset);
    H5Sclose(dataspace);
    return file;
  }else{
    free(file);
    return NULL;
  }    
}
Example #16
0
/*-------------------------------------------------------------------------
 * Function:	mklinks
 *
 * Purpose:	Build a file with assorted links.
 *
 * Return:	Success:	0
 *
 *		Failure:	-1
 *
 * Programmer:	Robb Matzke
 *              Friday, August 14, 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
mklinks(hid_t fapl)
{
    hid_t		file, scalar, grp, d1;
    hsize_t	        size[1] = {1};
    char		filename[NAME_BUF_SIZE];

    TESTING("link creation");

    /* Create a file */
    h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
    if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) {
	goto error;
    }
    if ((scalar=H5Screate_simple (1, size, size))<0) goto error;

    /* Create a group */
    if ((grp=H5Gcreate (file, "grp1", (size_t)0))<0) goto error;
    if (H5Gclose (grp)<0) goto error;

    /* Create a dataset */
    if ((d1=H5Dcreate (file, "d1", H5T_NATIVE_INT, scalar, H5P_DEFAULT))<0) {
	goto error;
    }
    if (H5Dclose (d1)<0) goto error;

    /* Create a hard link */
    if (H5Glink (file, H5G_LINK_HARD, "d1", "grp1/hard")<0) goto error;

    /* Create a symbolic link */
    if (H5Glink (file, H5G_LINK_SOFT, "/d1", "grp1/soft")<0) goto error;

    /* Create a symbolic link to something that doesn't exist */
    if (H5Glink (file, H5G_LINK_SOFT, "foobar", "grp1/dangle")<0) goto error;

    /* Create a recursive symbolic link */
    if (H5Glink (file, H5G_LINK_SOFT, "/grp1/recursive",
		 "/grp1/recursive")<0) {
	goto error;
    }

    /* Close */
    if (H5Sclose (scalar)<0) goto error;
    if (H5Fclose (file)<0) goto error;

    PASSED();
    return 0;

 error:
    return -1;
}
Example #17
0
//------------------------------------------------------------------------------
xdm::RefPtr< DatasetIdentifier > createDatasetIdentifier(
  const DatasetParameters& parameters ) {
  
  // check if the dataset already exists within the given parent
  htri_t exists = H5Lexists(
    parameters.parent,
    parameters.name.c_str(),
    H5P_DEFAULT );
  
  if ( exists ) {
    if ( parameters.mode == xdm::Dataset::kCreate ) {
      // the dataset exists and a create was requested, delete the existing one
      H5Ldelete( parameters.parent, parameters.name.c_str(), H5P_DEFAULT );
    } else {
      // read or modify access, open and return the existing dataset
      return openExistingDataset( parameters );
    }
  }

  // the dataset doesn't exist. Read only access is an error.
  if ( parameters.mode == xdm::Dataset::kRead ) {
    XDM_THROW( xdm::DatasetNotFound( parameters.name ) );
  }

  // Determine the dataset access properties based off chunking and compression
  // parameters.
  xdm::RefPtr< PListIdentifier > createPList( new PListIdentifier( H5P_DEFAULT ) );
  if ( parameters.chunked ) {
    createPList->reset( H5Pcreate( H5P_DATASET_CREATE ) );
    setupChunks( createPList->get(), parameters.chunkSize, parameters.dataspace );
    // Chunking is enabled, so check for compression and enable it if possible.
    if ( parameters.compress ) {
      setupCompression( createPList->get(), parameters.compressionLevel );
    }
  }

  // the mode is create or modify. In both cases we want to create it if it
  // doesn't yet exist. It is safe to create the dataset here because we deleted
  // the dataset earlier if it existed.
  hid_t datasetId = H5Dcreate(
    parameters.parent,
    parameters.name.c_str(),
    parameters.type,
    parameters.dataspace,
    H5P_DEFAULT,
    createPList->get(),
    H5P_DEFAULT );

  return xdm::RefPtr< DatasetIdentifier >( new DatasetIdentifier( datasetId ) );

}
Example #18
0
static void
ls2_hdf_write_anchors(hid_t file_id, const vector2 *anchors, size_t no_anchors)
{
    hid_t dataset, dataspace;
    hsize_t dims[2] = { no_anchors, 2 };
    
    dataspace = H5Screate_simple(2, dims, NULL);
    dataset = H5Dcreate(file_id, "/Anchors", H5T_NATIVE_FLOAT,
                        dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
             anchors);
    H5Sclose(dataspace);
    H5Dclose(dataset);
}
Example #19
0
int
main(int argc, char **argv)
{
    char file_name[256], dset_name[256];
    hid_t file_id, dataset_id, space_id, plist_id, type_id;
    hsize_t dims[1], dims_chunk[1];
    hsize_t maxdims[1] = { H5S_UNLIMITED };
    size_t disk_type_size, computed_type_size, packed_type_size;

    if (argc < 3) {
        printf("Pass the name of the file and dataset to check as arguments\n");
        return(0);
    }

    strcpy(file_name, argv[1]);
    strcpy(dset_name, argv[2]);
    
    dims[0] = 20;  // Create 20 records
    dims_chunk[0] = 10;

    // Create a new file
    file_id = H5Fcreate(file_name, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
    // Create a simple data space with unlimited size
    space_id = H5Screate_simple(1, dims, maxdims);
    // Modify dataset creation properties, i.e. enable chunking
    plist_id = H5Pcreate (H5P_DATASET_CREATE);
    H5Pset_chunk(plist_id, 1, dims_chunk);
    // Get the nested type
    type_id = createNestedType();
    // Create the dataset
    dataset_id = H5Dcreate(file_id, dset_name, type_id, space_id, plist_id);
    // Free resources
    H5Sclose(space_id);
    H5Pclose(plist_id);
    H5Dclose(dataset_id);
    H5Fclose(file_id);

    // Compute type sizes for native and packed
    disk_type_size = H5Tget_size(type_id);
    computed_type_size = getNestedSizeType(type_id);
    H5Tpack(type_id);  // pack type
    packed_type_size = H5Tget_size(type_id);
    printf("Disk type size: %d\n", disk_type_size);
    printf("Packed type size: %d (should be %d)\n",
           packed_type_size, computed_type_size);

    H5Tclose(type_id);

    return(1);
}
Example #20
0
void createExtensibleDataset(hid_t &file_id, int rank, hsize_t *maxdims, hsize_t *chunkdims, hid_t &type, char *datasetname) {
	// create feature dataspace with unlimited dimensions
	hid_t space = H5Screate_simple(rank, chunkdims, maxdims);
	// now create  the creation property list and set chunk size
	hid_t dcpl = H5Pcreate(H5P_DATASET_CREATE);
	herr_t status = H5Pset_chunk(dcpl, rank, chunkdims);
	// nowcreate the dataset
	hid_t dset = H5Dcreate(file_id, datasetname, type, space, H5P_DEFAULT, dcpl, H5P_DEFAULT);

	// clean up now.
	status = H5Pclose(dcpl);
	status = H5Dclose(dset);
	status = H5Sclose(space);
}
Example #21
0
    void DCDataSet::createReference(hid_t refGroup,
            hid_t srcGroup,
            DCDataSet &srcDataSet,
            Dimensions count,
            Dimensions offset,
            Dimensions stride)
    throw (DCException)
    {
        if (opened)
            throw DCException(getExceptionString("createReference: dataset is already open"));

        if (checkExistence && H5Lexists(refGroup, name.c_str(), H5P_LINK_ACCESS_DEFAULT))
            throw DCException(getExceptionString("createReference: this reference already exists"));

        getLogicalSize().set(count);
        this->ndims = srcDataSet.getNDims();

        count.swapDims(this->ndims);
        offset.swapDims(this->ndims);
        stride.swapDims(this->ndims);

        // select region hyperslab in source dataset
        if (H5Sselect_hyperslab(srcDataSet.getDataSpace(), H5S_SELECT_SET,
                offset.getPointer(), stride.getPointer(),
                count.getPointer(), NULL) < 0 ||
                H5Sselect_valid(srcDataSet.getDataSpace()) <= 0)
            throw DCException(getExceptionString("createReference: failed to select hyperslap for reference"));

        if (H5Rcreate(&regionRef, srcGroup, srcDataSet.getName().c_str(), H5R_DATASET_REGION,
                srcDataSet.getDataSpace()) < 0)
            throw DCException(getExceptionString("createReference: failed to create region reference"));

        hsize_t ndims = 1;
        dataspace = H5Screate_simple(1, &ndims, NULL);
        if (dataspace < 0)
            throw DCException(getExceptionString("createReference: failed to create dataspace for reference"));

        dataset = H5Dcreate(refGroup, name.c_str(), H5T_STD_REF_DSETREG,
                dataspace, H5P_DEFAULT, dsetProperties, H5P_DEFAULT);

        if (dataset < 0)
            throw DCException(getExceptionString("createReference: failed to create dataset for reference"));

        if (H5Dwrite(dataset, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL,
                dsetWriteProperties, &regionRef) < 0)
            throw DCException(getExceptionString("createReference: failed to write reference"));

        isReference = true;
        opened = true;
    }
Example #22
0
File: cxi.c Project: cxidb/libcxi
static int try_write_string(hid_t loc, char * name, char * values){
  hid_t space = H5Screate(H5S_SCALAR);
  if(space < 0) return space;
  hid_t datatype = H5Tcopy(H5T_C_S1);
  if(datatype < 0) return space;
  H5Tset_size(datatype, strlen(values));
  hid_t ds = H5Dcreate(loc,name,datatype,space,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
  if(ds < 0) return ds;
  herr_t status = H5Sclose(space);
  if(status < 0) return status;    
  status = H5Dwrite(ds,datatype,H5S_ALL,H5S_ALL,H5P_DEFAULT,values);
  if(status < 0) return status;    
  return H5Dclose(ds);
}
Example #23
0
/* Write the chunks in the row order.  This provides good and bad read
 * performance if the read pattern is by row and by column respectivly.
 *
 * Created by Albert Cheng and Christian Chilan 2010/7/13.
 */
int
createfilebyrow( void )
{
	hid_t   file_id, dset_id, filespace, memspace, fapl, dxpl, dcpl;
	hsize_t dimsf[2], count[2], offset[2], chunk_dims[2] = {CX, CY};
	char   *  data, dataval, table[RC];
	unsigned long i, j, l, cx;
	fapl = H5Pcreate( H5P_FILE_ACCESS );
	dcpl = H5Pcreate( H5P_DATASET_CREATE );
	dxpl = H5Pcreate( H5P_DATASET_XFER );
	H5Pset_chunk( dcpl, 2, chunk_dims );
	fapl = dxpl = H5P_DEFAULT;
	file_id = H5Fcreate( "row_alloc.h5", H5F_ACC_TRUNC, H5P_DEFAULT, fapl );
	dimsf[0] = NX;
	dimsf[1] = NY;
	filespace = H5Screate_simple( 2, dimsf, NULL );
	dset_id = H5Dcreate( file_id, "dataset1", H5T_NATIVE_CHAR, filespace,
	                     H5P_DEFAULT, dcpl, H5P_DEFAULT );
	count[0] = CX;
	count[1] = NY;
	memspace = H5Screate_simple( 2, count, NULL );

	data = ( char * )malloc( count[0] * count[1] * sizeof( char ) );

	/* writing the whole chunked rows each time. */
	for( l = 0; l < RC; l++ ) {

		offset[0] = l * CX;
		offset[1] = 0;

		/* fill with values according to row number */
		for( i = 0; i < count[0]; i++ )
			for( j = 0; j < count[1]; j++ )
				data[i * count[1] + j] = l;

		H5Sselect_hyperslab( filespace, H5S_SELECT_SET, offset, NULL, count, NULL );
		H5Dwrite( dset_id, H5T_NATIVE_CHAR, memspace, filespace, dxpl, data );
	}

	free( data );
	H5Dclose( dset_id );
	H5Sclose( filespace );
	H5Sclose( memspace );
	H5Pclose( dxpl );
	H5Pclose( dcpl );
	H5Pclose( fapl );
	H5Fclose( file_id );
	return 0;
}
Example #24
0
herr_t data_to_h5(
    const std::vector<T>& str_vec,
    hid_t group_id,
    const std::string& dataset_name,
    bool release_type,
    uint compression_level = 6
    ) {
  herr_t status;

  hsize_t dims[1] = {str_vec.size()};

  // create the propery which allows for compression
  hid_t prop_id = H5Pcreate(H5P_DATASET_CREATE);
  // chunk size is same size as vector
  status = H5Pset_chunk(prop_id, 1, dims);
  assert( status >= 0 );
  status = H5Pset_deflate(prop_id, compression_level);
  assert( status >= 0 );

  // create the data type
  hid_t datatype_id = get_datatype_id(str_vec);

  // create the dataspace
  hid_t dataspace_id = H5Screate_simple(1, dims, NULL);

  // create the dataset
  hid_t dataset_id = H5Dcreate(group_id, dataset_name.c_str(), datatype_id,
      dataspace_id, H5P_DEFAULT, prop_id, H5P_DEFAULT);

  // get the ptrs from the string and write out
  auto ptr = vec_to_ptr(str_vec);
  status = H5Dwrite(dataset_id, datatype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT,
      ptr);
  assert( status >= 0 );

  status = H5Pclose(prop_id);
  assert( status >= 0 );
  status = H5Dclose(dataset_id);
  assert( status >= 0 );
  status = H5Sclose(dataspace_id);
  assert( status >= 0 );
  if (release_type) {
    status = H5Tclose(datatype_id);
    assert( status >= 0 );
    delete [] ptr;
  }

  return status;
}
Example #25
0
void danu_h5_save_int_1d_array(struct DanuXDMFMeshHandle *h,
        const char *dataset_name, int* array1d, int n)
{
    hid_t space, dset;
    herr_t status;
    hsize_t dims[1] = {n};

    space = H5Screate_simple(1, dims, NULL);
    dset = H5Dcreate(h->group, dataset_name, H5T_STD_I32LE, space, H5P_DEFAULT,
                H5P_DEFAULT, H5P_DEFAULT);
    status = H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                array1d);
    status = H5Dclose(dset);
    status = H5Sclose(space);
}
Example #26
0
hid_t init2dCharTimeFrames(int nx, int ny, int ntimes, char *dsName, hid_t file_id) {
    hid_t  dataset_id,dataspace_id;
    hsize_t     dims[] = {ntimes,ny,nx}; 
    /* Create the data space for the dataset. */

    dataspace_id = H5Screate_simple(3, dims, NULL);
    /* Create the dataset. */

    dataset_id = H5Dcreate(file_id, dsName,  H5T_NATIVE_CHAR , dataspace_id, 
                          H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

     H5Sclose(dataspace_id);

    return dataset_id; 

}
Example #27
0
/**
 * Create the dataset. 
 * @throw ios::failure
 * 
 * @param [in]  DatasetName - Dataset name         
 * @param [in]  DimensionSizes - Dataset dimension sizes
 * @param [in]  ChunkSizes  - 3D Chunk size
 * @param [in]  CompressionLevel - Compression level
 * @return      Dataset_id
 */ 
hid_t THDF5_File::CreateFloatDataset(const char * DatasetName, const TDimensionSizes & DimensionSizes, const TDimensionSizes & ChunkSizes, const int CompressionLevel){
 
    const int RANK = 3;
    hsize_t    Dims [RANK] = {DimensionSizes.Z, DimensionSizes.Y, DimensionSizes.X};
    hsize_t    Chunk[RANK] = {ChunkSizes.Z, ChunkSizes.Y, ChunkSizes.X};
    hid_t      Property_list;
    herr_t     Status;
    
    hid_t dataspace_id = H5Screate_simple (RANK, Dims, NULL); 
    
    
    // set chunk size
    Property_list  = H5Pcreate (H5P_DATASET_CREATE);
    
    Status = H5Pset_chunk(Property_list, RANK, Chunk);    
    if (Status < 0 ){
        char ErrorMessage[256];
        sprintf(ErrorMessage,HDF5_ERR_FMT_DatasetNotOpened,FileName.c_str(), DatasetName);        
        throw ios::failure(ErrorMessage);    
       
    }
    
    // set compression level
    Status = H5Pset_deflate (Property_list, CompressionLevel); 
    if (Status < 0 ){
        char ErrorMessage[256];
        sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotSetCompression,FileName.c_str(), DatasetName, CompressionLevel);        
        throw ios::failure(ErrorMessage);    
       
    }
    
    // create dataset
    hid_t HDF5_dataset_id = H5Dcreate (HDF5_FileId, DatasetName, H5T_NATIVE_FLOAT, dataspace_id,
                            H5P_DEFAULT, Property_list, H5P_DEFAULT);
    
    if (HDF5_dataset_id == H5I_INVALID_HID ){
        char ErrorMessage[256];
        sprintf(ErrorMessage,HDF5_ERR_FMT_DatasetNotOpened,FileName.c_str(), DatasetName);        
        throw ios::failure(ErrorMessage);    
       
    }
    
    H5Pclose (Property_list);
    
    return HDF5_dataset_id; 
    
}// end of CreateDataset    
Example #28
0
hdf5dataset::hdf5dataset(hdf5file &hfile, const std::string &name, hid_t type_id, hid_t space_id, bool overwrite): _type_id(type_id), _hfile(hfile), _name(name)
{
	hfile.touch_group_recursive(name);

	bool exists = H5Lexists(_hfile.handle(), name.c_str(), H5P_DEFAULT);
	if(exists && overwrite)
		H5Ldelete(_hfile.handle(), name.c_str(), H5P_DEFAULT);
	else if(exists && !overwrite)
		throw std::runtime_error("Dataset already exists (" + _hfile.filename() + ") in file (" + name + ")");

	_dataset_id = H5Dcreate(hfile.handle(), name.c_str(), type_id, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
	_own_type_id = false;

	if(_dataset_id < 0)
		throw std::runtime_error("Error creating or opening dataset (" + _hfile.filename() + ") in file (" + name + ")");

}
Example #29
0
void write_test(hid_t file, int rank)
{
  if (rank < 0 || rank > 4)
  {
    printf("Error: unimplemented rank %d\n", rank);
    return;
  }

  hsize_t dims[] = {4, 8, 3, 2};
  hsize_t idx[] = {1, 1, 1, 1};

  int size = 1;
  for (int i = 0; i < rank; i++)
  {
    size *= dims[i];
  }
  double* data = (double*)malloc(size * sizeof(double));
  for (int i = 0; i < size; i++)
  {
    data[i] = 0;
    int powten = 1;
    for (int d = 0; d < rank; d++)
    {
      data[i] += powten*idx[d];
      powten *= 10;
    }
    for (int d = rank-1; d >= 0; d--)
    {
      idx[d]++;
      if (idx[d] <= dims[d]) break;
      else idx[d] = 1;
    }
  }

  char setname[32];
  sprintf(setname, "t%d", rank);

  hid_t dataspace = H5Screate_simple(rank, dims, NULL);
  hid_t dataset = H5Dcreate(file, setname, H5T_NATIVE_DOUBLE, dataspace,
      H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
  H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
  H5Dclose(dataset);
  H5Sclose(dataspace);

  free(data);
}
Example #30
0
static hid_t openDataset(QH5File *file, QH5Dataspace *dataspace, QString const &path, QH5Datatype::Type dtype)
{
  if (file->intent() == QH5File::ReadWrite) {
    return H5Dcreate (file->id(),
		      qPrintable(path),
		      QH5Datatype::toH5FileType(dtype),
		      dataspace->id(),
		      H5P_DEFAULT,
		      H5P_DEFAULT,
		      H5P_DEFAULT);
  }
  else {
    return H5Dopen2 (file->id(),
		     qPrintable(path),
		     H5P_DEFAULT);
  }
}