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


C++ DataSet::write方法代码示例

本文整理汇总了C++中h5::DataSet::write方法的典型用法代码示例。如果您正苦于以下问题:C++ DataSet::write方法的具体用法?C++ DataSet::write怎么用?C++ DataSet::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在h5::DataSet的用法示例。


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

示例1: dataspace

void HDF5IO::saveStdVector(const std::string& GroupName, const std::string& Name,
    const std::vector<std::complex<double> >& V)
{
  try{
    H5::CompType ComplexDataType = openCompType("complex");
    hsize_t Dim[1] = {hsize_t(V.size())};
    H5::DataSpace dataspace(1,Dim);
    H5::Group FG = getGroup( GroupName.c_str() );
    try{
      H5::Exception::dontPrint();
      H5::DataSet dataset = FG.openDataSet(Name.c_str());
      dataset.write(V.data(), ComplexDataType, dataspace);
    } catch( const H5::GroupIException not_found_error ){
      H5::DataSet dataset = FG.createDataSet(Name.c_str(), ComplexDataType,
        dataspace);
      dataset.write(V.data(), ComplexDataType);
    } catch( const H5::FileIException error){
      error.printError();
    } catch( const H5::DataSetIException error){
      error.printError();
    }
    FG.close();
  } catch( const H5::Exception err ){
    err.printError();
    RUNTIME_ERROR("HDF5IO::saveComplexStdVector. ");
  }
}
开发者ID:chengyanlai,项目名称:ExactDiagonalization,代码行数:27,代码来源:hdf5io.cpp

示例2: getGroup

void HDF5IO::saveNumber(const std::string& GroupName, const std::string& Name,
    unsigned long x)
{
    H5::Group FG = getGroup( GroupName );
    try{
      H5::Exception::dontPrint();
      H5::DataSet dataset = FG.openDataSet( Name.c_str() );
      dataset.write(&x, H5::PredType::NATIVE_ULONG);
    } catch ( const H5::GroupIException not_found_error ){
      H5::DataSet dataset = FG.createDataSet( Name.c_str(), H5::PredType::NATIVE_ULONG, H5::DataSpace());
      dataset.write(&x, H5::PredType::NATIVE_ULONG);
    }
    FG.close();
}
开发者ID:chengyanlai,项目名称:ExactDiagonalization,代码行数:14,代码来源:hdf5io.cpp

示例3: addrow

void addrow( H5::DataSet& ds, const std::vector<double>& rowtowrite )
{
  //Get the space (since it may have grown in length since last time of course )
  H5::DataSpace origspace = ds.getSpace();

  //get the rank, even though I know it is 2
  int rank = origspace.getSimpleExtentNdims();

  //Get the actual dimensions of the ranks.
  hsize_t dims[rank];
  int ndims = origspace.getSimpleExtentDims( dims, NULL);

  //Want to ADD a row, so need to offset at row = nrows, and col = 0;
  hsize_t offset[rank] = { dims[0], 0 }; 
  hsize_t dims_toadd[rank] = { 1, rowtowrite.size() }; //will write 1 row, ncols columns.

  //Compute "new" size (extended by 1 row).
  hsize_t size[rank] = { dims[0]+dims_toadd[0], rowtowrite.size() };

  //Do the extension.
  ds.extend( size );

  //Get the new (extended) space, and select the hyperslab to write the row to.
  origspace = ds.getSpace();
  origspace.selectHyperslab( H5S_SELECT_SET, dims_toadd, offset );

  //Make the "memory" data space?
  H5::DataSpace toaddspace(rank, dims_toadd);

  ds.write(  rowtowrite.data(), H5::PredType::NATIVE_DOUBLE, toaddspace, origspace );

  //Can close toaddspace/origspace with no effect.
  //Can also close/open data set at the beginning of each time with no effect.
}
开发者ID:flyingfalling,项目名称:psweep2,代码行数:34,代码来源:testhdf5ids.cpp

示例4: WriteString

void hdfutil::WriteString(const H5::CommonFG& group, const std::string & dsname, const std::string & str) {
    hsize_t dims[] = {1};
    H5::DataSpace dataspace(1, dims);       // 1 string
    H5::StrType   strtype  (0, str.size()); // string length
    H5::DataSet dset = group.createDataSet(dsname, strtype, dataspace, CreatePropList());
    dset.write(&str[0], strtype);
}
开发者ID:NaohiroHayashi,项目名称:bulletsim,代码行数:7,代码来源:hdfutil.cpp

示例5: writeArray

void writeArray(H5::Group &group, const std::string &name,
                const std::string &value) {
  StrType dataType(0, value.length() + 1);
  DataSpace dataSpace = getDataSpace(1);
  H5::DataSet data = group.createDataSet(name, dataType, dataSpace);
  data.write(value, dataType);
}
开发者ID:dezed,项目名称:mantid,代码行数:7,代码来源:SaveDiffCal.cpp

示例6: mutex

bool CompartmentReportHDF5::writeCompartments( const uint32_t gid,
                                               const uint16_ts& counts )
{
    lunchbox::ScopedWrite mutex( detail::_hdf5Lock );

    try
    {
        const size_t compCount = std::accumulate( counts.begin(),
                                                  counts.end(), 0 );
        LBASSERT( !counts.empty( ));
        LBASSERTINFO( compCount > 0, gid );
        H5::DataSet dataset = _createDataset( gid, compCount );

        const size_t sections = counts.size();
        LBASSERT( sections > 0 );
        dataset.openAttribute( 1 ).write( H5::PredType::NATIVE_INT, &sections );

//        dataset.openAttribute( 2 ).write( H5::PredType::NATIVE_INT, &somas );
//        dataset.openAttribute( 3 ).write( H5::PredType::NATIVE_INT, &axons );
//        dataset.openAttribute( 4 ).write( H5::PredType::NATIVE_INT, &basals );
//        dataset.openAttribute( 5 ).write( H5::PredType::NATIVE_INT, &apics );

        boost::scoped_array< float > mapping( new float[compCount] );
        size_t i = 0;
        for( size_t j = 0; j < counts.size(); ++j )
            for( size_t k = 0; k < counts[j]; ++k )
                mapping[i++] = j;

        dataset.write( mapping.get(), H5::PredType::NATIVE_FLOAT );
        return true;
    }
    CATCH_HDF5ERRORS
    return false;
}
开发者ID:adevress,项目名称:Brion,代码行数:34,代码来源:compartmentReportHDF5.cpp

示例7: dspace

/* only for Eigen3 matrix/vector */
void HDF5IO::saveVector(const std::string& GroupName,
  const std::string& Name, const RealVectorType& V)
{
    hsize_t Dim[1] = {hsize_t(V.size())};
    H5::DataSpace dspace(1,Dim);
    H5::Group FG = getGroup( GroupName );
    try{
      H5::Exception::dontPrint();
      H5::DataSet DataSet = FG.openDataSet(Name.c_str());
      DataSet.write(V.data(),H5::PredType::NATIVE_DOUBLE, dspace);
    } catch ( const H5::GroupIException not_found_error ){
      H5::DataSet DataSet = FG.createDataSet(Name.c_str(),
        H5::PredType::NATIVE_DOUBLE,dspace);
      DataSet.write(V.data(),H5::PredType::NATIVE_DOUBLE);
    }
    FG.close();
}
开发者ID:chengyanlai,项目名称:ExactDiagonalization,代码行数:18,代码来源:hdf5io.cpp

示例8: openCompType

void HDF5IO::saveNumber(const std::string& GroupName, const std::string& Name,
    ComplexType C)
{
    H5::CompType ComplexDataType = openCompType("complex");
    H5::Group FG = getGroup( GroupName );
    try{
      H5::Exception::dontPrint();
      H5::DataSet dataset = FG.openDataSet(Name.c_str());
      RealType RealImag[2] = {real(C),imag(C)};
      dataset.write(RealImag, ComplexDataType);
    } catch ( const H5::GroupIException not_found_error ){
      H5::DataSet dataset = FG.createDataSet(Name.c_str(), ComplexDataType, H5::DataSpace());
      RealType RealImag[2] = {real(C),imag(C)};
      dataset.write(RealImag, ComplexDataType);
    }
    FG.close();
}
开发者ID:chengyanlai,项目名称:ExactDiagonalization,代码行数:17,代码来源:hdf5io.cpp

示例9: write

void TImgWriteBuffer::write(const std::string& fname, const std::string& group, const std::string& img) {
	H5::H5File* h5file = H5Utils::openFile(fname);
	H5::Group* h5group = H5Utils::openGroup(h5file, group);
	
	// Dataset properties: optimized for reading/writing entire buffer at once
	int rank = 3;
	hsize_t dim[3] = {length_, rect_.N_bins[0], rect_.N_bins[1]};
	hsize_t chunk_dim[3] = {length_, rect_.N_bins[0], rect_.N_bins[1]};
	if(length_ > 1000) {
		float div = ceil((float)length_ / 1000.);
		chunk_dim[0] = (int)ceil(length_ / div);
		std::cerr << "! Changing chunk length to " << chunk_dim[0] << " stars." << std::endl;
	}
	H5::DataSpace dspace(rank, &(dim[0]));
	H5::DSetCreatPropList plist;
	plist.setDeflate(9);	// gzip compression level
	plist.setChunk(rank, &(chunk_dim[0]));
	float fillvalue = 0;
	plist.setFillValue(H5::PredType::NATIVE_FLOAT, &fillvalue);
	
	H5::DataSet* dataset = new H5::DataSet(h5group->createDataSet(img, H5::PredType::NATIVE_FLOAT, dspace, plist));
	dataset->write(buf, H5::PredType::NATIVE_FLOAT);
	
	/*
	 *  Attributes
	 */
	
	hsize_t att_dim = 2;
	H5::DataSpace att_dspace(1, &att_dim);
	
	H5::PredType att_dtype = H5::PredType::NATIVE_UINT32;
	H5::Attribute att_N = dataset->createAttribute("nPix", att_dtype, att_dspace);
	att_N.write(att_dtype, &(rect_.N_bins));
	
	att_dtype = H5::PredType::NATIVE_DOUBLE;
	H5::Attribute att_min = dataset->createAttribute("min", att_dtype, att_dspace);
	att_min.write(att_dtype, &(rect_.min));
	
	att_dtype = H5::PredType::NATIVE_DOUBLE;
	H5::Attribute att_max = dataset->createAttribute("max", att_dtype, att_dspace);
	att_max.write(att_dtype, &(rect_.max));
	
	delete dataset;
	delete h5group;
	delete h5file;
}
开发者ID:gregreen,项目名称:bayestar,代码行数:46,代码来源:chain.cpp

示例10: posesDS

void Bundle2::saveGeometry(const boost::filesystem::path& fileName) const {
	H5::H5File bundleFile;
	bundleFile.openFile(fileName.string(), H5F_ACC_RDWR);

	H5::Group rootGroup = bundleFile.openGroup("/");

	// If the group "Geometry" exists, delete it!
	if(checkGeometry_(bundleFile)) {
		rootGroup.unlink("Geometry");
	}

	// Creating group Geometry
	H5::Group geometryGroup = rootGroup.createGroup("Geometry");

	// Saving poses
	const hsize_t posesChunkDim[] = { 3, 12 };
	H5::DSetCreatPropList posesPropList;
	posesPropList.setLayout(H5D_CHUNKED);
	posesPropList.setChunk(2, posesChunkDim);
	posesPropList.setDeflate(9);

	const hsize_t posesMaxDim[] = { H5S_UNLIMITED, 12 };
	const hsize_t posesCurDim[] = { frames_.size(), 12 };
	H5::DataSpace posesDS(2, posesCurDim, posesMaxDim);

	H5::DataSet posesDataSet = geometryGroup.createDataSet("Poses", H5::PredType::IEEE_F64LE, posesDS, posesPropList);

	double* posesData = (double*)malloc(frames_.size()*12*sizeof(double));
	size_t i = 0;
	for(deque<Frame*>::const_iterator it = frames_.begin(); it != frames_.end(); it++) {
		posesData[i*12] = (*it)->pose()->t().x();
		posesData[i*12 + 1] = (*it)->pose()->t().y();
		posesData[i*12 + 2] = (*it)->pose()->t().z();

		core::Matrix<double> R = (*it)->pose()->R();
		posesData[i*12 + 3] = R[0][0];
		posesData[i*12 + 4] = R[1][0];
		posesData[i*12 + 5] = R[2][0];
		posesData[i*12 + 6] = R[0][1];
		posesData[i*12 + 7] = R[1][1];
		posesData[i*12 + 8] = R[2][1];
		posesData[i*12 + 9] = R[0][2];
		posesData[i*12 + 10] = R[1][2];
		posesData[i*12 + 11] = R[2][2];

		++i;
	}

	posesDataSet.write((const void*)posesData, H5::PredType::NATIVE_DOUBLE, H5::DataSpace::ALL, H5::DataSpace::ALL);
	free((void*)posesData);
	posesDataSet.close();
	posesDS.close();

	// Saving points
	const hsize_t pointsChunkDim[] = {10, 3};
	H5::DSetCreatPropList pointsPropList;
	pointsPropList.setLayout(H5D_CHUNKED);
	pointsPropList.setChunk(2, pointsChunkDim);
	pointsPropList.setDeflate(9);

	const hsize_t pointsMaxDim[] = { H5S_UNLIMITED, 3 };
	const hsize_t pointsCurDim[] = { tracks_.size(), 3 };
	H5::DataSpace pointsDS(2, pointsCurDim, pointsMaxDim);

	H5::DataSet pointsDataSet = geometryGroup.createDataSet("Points", H5::PredType::IEEE_F64LE, pointsDS, pointsPropList);

	double* pointsData = (double*)malloc(tracks_.size()*3*sizeof(double));

	i = 0;
	for(deque<Track*>::const_iterator it = tracks_.begin(); it != tracks_.end(); it++) {
		pointsData[i*3] = (*it)->point()->coords().x();
		pointsData[i*3 + 1] = (*it)->point()->coords().y();
		pointsData[i*3 + 2] = (*it)->point()->coords().z();

		++i;
	}

	pointsDataSet.write((const void*)pointsData, H5::PredType::NATIVE_DOUBLE, H5::DataSpace::ALL, H5::DataSpace::ALL);
	free((void*)pointsData);
	pointsDataSet.close();
	pointsDS.close();

	// Saving inlier information
	const hsize_t inliersChunkDim[] = { 3 };
	H5::DSetCreatPropList inliersPropList;
	inliersPropList.setLayout(H5D_CHUNKED);
	inliersPropList.setChunk(1, inliersChunkDim);
	inliersPropList.setDeflate(9);

	const hsize_t inliersMaxDim[] = { H5S_UNLIMITED };
	const hsize_t inliersCurDim[] = { frames_.size() };
	H5::DataSpace inliersDS(1, inliersCurDim, inliersMaxDim);

	H5::VarLenType inliersType(&H5::PredType::STD_U8LE);

	H5::DataSet inliersDataSet = geometryGroup.createDataSet("Inliers", inliersType, inliersDS, inliersPropList);

	i = 0;
	for(deque<Frame*>::const_iterator it = frames_.begin(); it != frames_.end(); it++) {
		hvl_t inliersLine;
//.........这里部分代码省略.........
开发者ID:ttnguyenUBP,项目名称:T3DV_backup,代码行数:101,代码来源:bundle2.cpp

示例11: main

int main( int argCount, char *argVec[] )
{

    //declare *default* input file, output file, and length of radial profiles
    std::string inFile;
    std::string outFile;
    const int radialProfileLength = 101;

    //options for command line input are defined here
    po::options_description optDesc("Allowed options");
    optDesc.add_options()
        ("help","produce help message")
        ("in",po::value<std::string>(&inFile)->default_value("analytic.yaml"), "input file name")
        ("out",po::value<std::string>(&outFile)->default_value("gtcInputEq.h5"), "output file name")
    ;
    po::variables_map varMap;
    po::store(po::parse_command_line(argCount, argVec, optDesc), varMap);
    po::notify(varMap);
    
    if (varMap.count("help")) {
        std::cout << optDesc << "\n";
        return 1;
    }



   //declare YAML nodes to work with input file
    YAML::Node magEq;
    YAML::Node oneDim;
    YAML::Node twoDim;

    //declare variables to hold and manipulate intermediate data
    int i; //loop index
    double psi[radialProfileLength] = {0.0};
    double dat[radialProfileLength] = {0.0};

    //declare vars to manipulate HDF5 output file
    H5::H5File outfile( outFile, H5F_ACC_TRUNC );
    hsize_t dim[1] = { (unsigned int)radialProfileLength };
    H5::DataSpace datspace1D( 1, dim );
    H5::IntType dattype( H5::PredType::NATIVE_DOUBLE );
    H5::DataSet datset; 

    //read in the YAML eq file
    magEq = YAML::LoadFile( inFile );

    //generate radial coords
    for ( i=0; i<radialProfileLength; i++ )
        psi[i] = i/(radialProfileLength - 1.0);

    //do some parsing
    //first check for 1D and 2D data in the eq file
    //if the exist, generate profiles from polynomial coefficients
    if(magEq["1D profiles"]){
        oneDim = magEq["1D profiles"];
        for(YAML::const_iterator iter=oneDim.begin(); iter!=oneDim.end(); ++iter){
            for( i=0; i<radialProfileLength; i++)
                dat[i] = iter->second[0].as<double>() 
                        + iter->second[1].as<double>()*psi[i] 
                        + iter->second[2].as<double>()*psi[i]*psi[i];
            datset = outfile.createDataSet( iter->first.as<std::string>(), dattype, datspace1D );
            datset.write( dat, H5::PredType::NATIVE_DOUBLE );
        }
    }
    if(magEq["2d profiles"]){
        twoDim = magEq["2D profiles"];
        // do some more parsing if we need this part...
    }

    return 0;
}
开发者ID:uci-physics-231,项目名称:gtc-equilibrium-mapper,代码行数:71,代码来源:main.cpp

示例12: saveStackHDF5

bool saveStackHDF5( const char* fileName, const My4DImage& img, Codec_Mapping* mapping )
{
    try
    {
#ifdef USE_HDF5
        H5::Exception::dontPrint();
        H5::H5File file( fileName, H5F_ACC_TRUNC );
        H5::Group* group = new H5::Group( file.createGroup( "/Channels" ) );

        Image4DProxy<My4DImage> proxy( const_cast<My4DImage*>( &img ) );

        long scaledHeight = nearestPowerOfEight( proxy.sy );
        long scaledWidth = nearestPowerOfEight( proxy.sx );

        // Initialize the upper and lower bounds
        long pad_right = ( scaledWidth - proxy.sx ) ;
        long pad_bottom = ( scaledHeight - proxy.sy );

        hsize_t dims[1] = { 1 };
        H5::DataSpace attr_ds = H5::DataSpace( 1, dims );
        H5::Attribute attr = group->createAttribute( "width", H5::PredType::STD_I64LE, attr_ds );
        attr.write( H5::PredType::NATIVE_INT, &( proxy.sx ) );
        attr = group->createAttribute( "height", H5::PredType::STD_I64LE, attr_ds );
        attr.write( H5::PredType::NATIVE_INT, &( proxy.sy ) );
        attr = group->createAttribute( "frames", H5::PredType::STD_I64LE, attr_ds );
        attr.write( H5::PredType::NATIVE_INT, &( proxy.sz ) );
        attr = group->createAttribute( "pad_right", H5::PredType::STD_I64LE, attr_ds );
        attr.write( H5::PredType::NATIVE_INT, &( pad_right ) );
        attr = group->createAttribute( "pad_bottom", H5::PredType::STD_I64LE, attr_ds );
        attr.write( H5::PredType::NATIVE_INT, &( pad_bottom ) );

        Codec_Mapping* imap = mapping;
        if ( !mapping )
        {
            imap = new Codec_Mapping();
            generate_codec_mapping( *imap, proxy.sc );
        }

        for ( int c = 0; c < proxy.sc; ++c )
        {
            double default_irange = 1.0; // assumes data range is 0-255.0
            if ( proxy.su > 1 )
            {
                default_irange = 1.0 / 16.0; // 0-4096, like our microscope images
            }
            std::vector<double> imin( proxy.sc, 0.0 );
            std::vector<double> irange2( proxy.sc, default_irange );
            // rescale if converting from 16 bit to 8 bit
            if ( proxy.su > 1 )
            {
                if ( img.p_vmin && img.p_vmax )
                    proxy.set_minmax( img.p_vmin, img.p_vmax );
                if ( proxy.has_minmax() )
                {
                    imin[c] = proxy.vmin[c];
                    irange2[c] = 255.0 / ( proxy.vmax[c] - proxy.vmin[c] );
                }
            }

            FFMpegEncoder encoder( NULL, scaledWidth, scaledHeight,
                                   ( *imap )[c].first, ( *imap )[c].second );
            // If the image needs padding, fill the expanded border regions with black
            for ( int z = 0; z < proxy.sz; ++z )
            {
                for ( int y = 0; y < scaledHeight; ++y )
                {
                    for ( int x = 0; x < scaledWidth; ++x )
                    {
                        // If inside the area with valid data
                        if ( x < proxy.sx && y < proxy.sy )
                        {
                            int ic = c;
                            double val = proxy.value_at( x, y, z, ic );
                            val = ( val - imin[ic] ) * irange2[ic]; // rescale to range 0-255
                            for ( int cc = 0; cc < 3; ++cc )
                                encoder.setPixelIntensity( x, y, cc, ( int )val );
                        }
                        else
                            for ( int cc = 0; cc < 3; ++cc )
                                encoder.setPixelIntensity( x, y, cc, 0 );
                    }
                }
                encoder.write_frame();
            }

            for ( int rem = encoder.encoded_frames(); rem < proxy.sz; rem++ )
                encoder.encode();

            encoder.close();

            hsize_t  dims[1];
            dims[0] = encoder.buffer_size();
            H5::DataSpace dataspace( 1, dims );
std: stringstream name;
            name << "Channel_" << c;
            H5::DataSet dataset = group->createDataSet( name.str(), H5::PredType::NATIVE_UINT8, dataspace );
            dataset.write( encoder.buffer(), H5::PredType::NATIVE_UINT8 );
            dataset.close();

            std::cout << "Encoded channel is " << encoder.buffer_size() << " bytes." << std::endl;
//.........这里部分代码省略.........
开发者ID:Vaa3D,项目名称:v3d_external,代码行数:101,代码来源:loadV3dFFMpeg.cpp

示例13: save

bool TStellarData::save(const std::string& fname, const std::string& group, const std::string &dset, int compression) {
	if((compression < 0) || (compression > 9)) {
		std::cerr << "! Invalid gzip compression level: " << compression << std::endl;
		return false;
	}
	
	hsize_t nstars = star.size();
	if(nstars == 0) {
		std::cerr << "! No stars to write." << std::endl;
		return false;
	}
	
	H5::Exception::dontPrint();
	
	H5::H5File *file = H5Utils::openFile(fname);
	if(file == NULL) { return false; }
	
	H5::Group *gp = H5Utils::openGroup(file, group);
	if(gp == NULL) {
		delete file;
		return false;
	}
	
	/*
	 *  Photometry
	 */
	
	// Datatype
	hsize_t nbands = NBANDS;
	H5::ArrayType f4arr(H5::PredType::NATIVE_FLOAT, 1, &nbands);
	H5::ArrayType u4arr(H5::PredType::NATIVE_FLOAT, 1, &nbands);
	H5::CompType dtype(sizeof(TFileData));
	dtype.insertMember("obj_id", HOFFSET(TFileData, obj_id), H5::PredType::NATIVE_UINT64);
	dtype.insertMember("l", HOFFSET(TFileData, l), H5::PredType::NATIVE_DOUBLE);
	dtype.insertMember("b", HOFFSET(TFileData, b), H5::PredType::NATIVE_DOUBLE);
	dtype.insertMember("mag", HOFFSET(TFileData, mag), f4arr);
	dtype.insertMember("err", HOFFSET(TFileData, err), f4arr);
	dtype.insertMember("maglimit", HOFFSET(TFileData, maglimit), f4arr);
	dtype.insertMember("nDet", HOFFSET(TFileData, N_det), u4arr);
	dtype.insertMember("EBV", HOFFSET(TFileData, EBV), H5::PredType::NATIVE_FLOAT);
	
	// Dataspace
	hsize_t dim = nstars;
	H5::DataSpace dspace(1, &dim);
	
	// Property List
	H5::DSetCreatPropList plist;
	plist.setChunk(1, &nstars);
	plist.setDeflate(compression);
	
	// Dataset
	H5::DataSet dataset = gp->createDataSet(dset, dtype, dspace, plist);
	
	// Write dataset
	TFileData* data = new TFileData[nstars];
	for(size_t i=0; i<nstars; i++) {
		data[i].obj_id = star[i].obj_id;
		data[i].l = star[i].l;
		data[i].b = star[i].b;
		for(size_t k=0; k<NBANDS; k++) {
			data[i].mag[k] = star[i].m[k];
			data[i].err[k] = star[i].err[k];
			data[i].maglimit[k] = star[i].maglimit[k];
		}
		data[i].EBV = star[i].EBV;
	}
	dataset.write(data, dtype);
	
	/*
	 *  Attributes
	 */
	
	dim = 1;
	H5::DataSpace att_dspace(1, &dim);
	
	H5::PredType att_dtype = H5::PredType::NATIVE_UINT64;
	H5::Attribute att_healpix_index = dataset.createAttribute("healpix_index", att_dtype, att_dspace);
	att_healpix_index.write(att_dtype, &healpix_index);
	
	att_dtype = H5::PredType::NATIVE_UINT32;
	H5::Attribute att_nside = dataset.createAttribute("nside", att_dtype, att_dspace);
	att_nside.write(att_dtype, &nside);
	
	att_dtype = H5::PredType::NATIVE_UCHAR;
	H5::Attribute att_nested = dataset.createAttribute("nested", att_dtype, att_dspace);
	att_nested.write(att_dtype, &nested);
	
	att_dtype = H5::PredType::NATIVE_DOUBLE;
	H5::Attribute att_l = dataset.createAttribute("l", att_dtype, att_dspace);
	att_l.write(att_dtype, &l);
	
	att_dtype = H5::PredType::NATIVE_DOUBLE;
	H5::Attribute att_b = dataset.createAttribute("b", att_dtype, att_dspace);
	att_b.write(att_dtype, &b);
	
	att_dtype = H5::PredType::NATIVE_DOUBLE;
	H5::Attribute att_EBV = dataset.createAttribute("EBV", att_dtype, att_dspace);
	att_EBV.write(att_dtype, &EBV);
	
	file->close();
//.........这里部分代码省略.........
开发者ID:gregreen,项目名称:bayestar,代码行数:101,代码来源:data.cpp

示例14: save_mat_image

bool save_mat_image(cv::Mat& img, TRect& rect, std::string fname, std::string group_name,
                    std::string dset_name, std::string dim1, std::string dim2, int compression) {
	assert((img.dims == 2) && (img.rows == rect.N_bins[0]) && (img.cols == rect.N_bins[1]));
	
	if((compression<0) || (compression > 9)) {
		std::cerr << "! Invalid gzip compression level: " << compression << std::endl;
		return false;
	}
	
	H5::Exception::dontPrint();
	
	H5::H5File *file = H5Utils::openFile(fname);
	if(file == NULL) { return false; }
	
	H5::Group *group = H5Utils::openGroup(file, group_name);
	if(group == NULL) {
		delete file;
		return false;
	}
	
	/*
	 *  Image Data
	 */
	
	// Creation property list
	H5::DSetCreatPropList plist;
	int rank = 2;
	hsize_t dim[2] = {rect.N_bins[0], rect.N_bins[1]};
	plist.setDeflate(compression);	// gzip compression level
	float fillvalue = 0;
	plist.setFillValue(H5::PredType::NATIVE_FLOAT, &fillvalue);
	plist.setChunk(rank, &(dim[0]));
	H5::DataSpace dspace(rank, &(dim[0]));
	
	H5::DataSet* dataset;
	try {
		dataset = new H5::DataSet(group->createDataSet(dset_name, H5::PredType::NATIVE_FLOAT, dspace, plist));
	} catch(H5::FileIException create_dset_err) {
		std::cerr << "Unable to create dataset '" << dset_name << "'." << std::endl;
		delete group;
		delete file;
		return false;
	}
	
	float *buf = new float[rect.N_bins[0]*rect.N_bins[1]];
	for(size_t j=0; j<rect.N_bins[0]; j++) {
		for(size_t k=0; k<rect.N_bins[1]; k++) {
			buf[rect.N_bins[1]*j + k] = img.at<double>(j,k);
			/*float tmp = img.at<double>(j,k);
			if(tmp > 0.) {
				std::cerr << j << ", " << k << " --> " << j + rect.N_bins[0]*k << " --> " << tmp << std::endl;
			}*/
		}
	}
	dataset->write(buf, H5::PredType::NATIVE_FLOAT);
	
	/*
	 *  Attributes
	 */
	
	hsize_t att_dim = 2;
	H5::DataSpace att_dspace(1, &att_dim);
	
	H5::PredType att_dtype = H5::PredType::NATIVE_UINT32;
	H5::Attribute att_N = dataset->createAttribute("N_pix", att_dtype, att_dspace);
	att_N.write(att_dtype, &(rect.N_bins));
	
	att_dtype = H5::PredType::NATIVE_DOUBLE;
	H5::Attribute att_min = dataset->createAttribute("min", att_dtype, att_dspace);
	att_min.write(att_dtype, &(rect.min));
	
	att_dtype = H5::PredType::NATIVE_DOUBLE;
	H5::Attribute att_max = dataset->createAttribute("max", att_dtype, att_dspace);
	att_max.write(att_dtype, &(rect.max));
	
	att_dim = 1;
	H5::StrType vls_type(0, H5T_VARIABLE);
	H5::DataSpace att_space_str(H5S_SCALAR);
	H5::Attribute att_name_1 = dataset->createAttribute("dim_name_1", vls_type, att_space_str);
	att_name_1.write(vls_type, dim1);
	H5::Attribute att_name_2 = dataset->createAttribute("dim_name_2",  vls_type, att_space_str);
	att_name_2.write(vls_type, dim2);
	
	file->close();
	
	delete[] buf;
	delete dataset;
	delete group;
	delete file;
	
	return true;
	
}
开发者ID:gregreen,项目名称:bayestar,代码行数:93,代码来源:chain.cpp

示例15: WriteTable

 void WriteTable(void* data){
    //write data and close data set
    dSet_.write(data, dType_, dSpace_);
    dSet_.close();
 }
开发者ID:rseal,项目名称:HDF5R,代码行数:5,代码来源:HDF5.hpp


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