当前位置: 首页>>代码示例>>C++>>正文


C++ H5Dcreate函数代码示例

本文整理汇总了C++中H5Dcreate函数的典型用法代码示例。如果您正苦于以下问题:C++ H5Dcreate函数的具体用法?C++ H5Dcreate怎么用?C++ H5Dcreate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了H5Dcreate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: createfilerandom

/* 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;
}
开发者ID:JulianKunkel,项目名称:siox,代码行数:63,代码来源:h5slabwrite.c

示例2: SetupDataSet

/*
 * 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");
        }
}
开发者ID:roblatham00,项目名称:ior,代码行数:60,代码来源:aiori-HDF5.c

示例3: ASDF_write_auxiliary_data

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
}
开发者ID:QuLogic,项目名称:asdf-library,代码行数:44,代码来源:ASDF_write.c

示例4: H5Screate_simple

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);
}
开发者ID:erianthus,项目名称:lifev,代码行数:19,代码来源:HDF5IO.cpp

示例5: test_noconv

/*-------------------------------------------------------------------------
 * 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;
}
开发者ID:MattNapsAlot,项目名称:rHDF5,代码行数:71,代码来源:enum.c

示例6: try_write_float_array

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);
}
开发者ID:cxidb,项目名称:libcxi,代码行数:11,代码来源:cxi.c

示例7: filename

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);
}
开发者ID:adam-higuera,项目名称:adi-prototype,代码行数:54,代码来源:Simulation3D.cpp

示例8: _MEDdatasetStringEcrire

/*
 * - 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;
}
开发者ID:mndjinga,项目名称:CDMATH,代码行数:64,代码来源:MEDdatasetStringEcrire.c

示例9: try_write_float

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);
}
开发者ID:cxidb,项目名称:libcxi,代码行数:11,代码来源:cxi.c

示例10: extend1dDoubleExt

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);
        
    }
    
    
    
    
}
开发者ID:ernmeel,项目名称:sweeny,代码行数:53,代码来源:fileio_hdf5.c

示例11: throw

    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;
    }
开发者ID:c-schumann-zih,项目名称:libSplash,代码行数:53,代码来源:DCDataSet.cpp

示例12: F77_FUNC_

/** 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);
}
开发者ID:digideskio,项目名称:qmcpack,代码行数:90,代码来源:pw_hdf5.c

示例13: writeInt2d

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;    
}
开发者ID:ernmeel,项目名称:sweeny,代码行数:22,代码来源:fileio_hdf5.c

示例14: cxi_open_file

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;
  }    
}
开发者ID:cxidb,项目名称:libcxi,代码行数:51,代码来源:cxi.c

示例15: mklinks

/*-------------------------------------------------------------------------
 * 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;
}
开发者ID:MattNapsAlot,项目名称:rHDF5,代码行数:67,代码来源:links.c


注:本文中的H5Dcreate函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。