Esempio n. 1
0
herr_t H5VLARRAYmodify_records( hid_t dataset_id,
                                hid_t type_id,
                                hsize_t nrow,
                                int nobjects,
                                const void *data )
{

    hid_t    space_id;
    hid_t    mem_space_id;
    hsize_t  start[1];
    hsize_t  dims_new[1] = {1};    /* Only a record on each update */
    hvl_t    wdata;   /* Information to write */

    /* Initialize VL data to write */
    wdata.p=(void *)data;
    wdata.len=nobjects;

    /* Create a simple memory data space */
    if ( (mem_space_id = H5Screate_simple( 1, dims_new, NULL )) < 0 )
        return -1;

    /* Get the file data space */
    if ( (space_id = H5Dget_space( dataset_id )) < 0 )
        return -1;

    /* Define a hyperslab in the dataset */
    start[0] = nrow;
    if ( H5Sselect_hyperslab( space_id, H5S_SELECT_SET, start, NULL, dims_new, NULL) < 0 )
        goto out;

    if ( H5Dwrite( dataset_id, type_id, mem_space_id, space_id, H5P_DEFAULT, &wdata ) < 0 )
        goto out;

    /* Terminate access to the dataspace */
    if ( H5Sclose( space_id ) < 0 )
        goto out;

    if ( H5Sclose( mem_space_id ) < 0 )
        goto out;

    return 1;

out:
    return -1;

}
Esempio n. 2
0
int H5mdfile::H5_Dextend(int argc, char **argv, Tcl_Interp *interp)
{
    /* Extend dataset to higher dimensions */
    H5Sclose(dataspace_id);
    for(int i=0;i<dataset_rank;i++)
    {

     if(atoi(argv[3+i])>(int)dims[i])
     {
         dims[i]=atoi(argv[3+i])-dimstotal[i];
     }
     dimstotal[i] = atoi(argv[3+i]);
    }
    status = H5Dset_extent(dataset_id, dimstotal);
    dataspace_id = H5Dget_space(dataset_id);
    return TCL_OK;
}
Esempio n. 3
0
int main (int argc, char ** argv) 
{
    char        filename [256];
    int         rank, size, i, j;
    uint64_t start[2], count[2], bytes_read = 0;
    int ndims, nsf;
    hid_t file;
    hid_t dataset;
    hid_t filespace;
    hid_t memspace;

    int data_out[size];

    struct timeval t1;
    gettimeofday (&t1, NULL);

        file = H5Fopen("write_test.h5", H5F_ACC_RDONLY, H5P_DEFAULT);
        dataset = H5Dopen(file, "index");
        filespace = H5Dget_space(dataset);    /* Get filespace handle first. */
        ndims     = H5Sget_simple_extent_ndims(filespace);

        hsize_t dims[ndims];
        herr_t status_n  = H5Sget_simple_extent_dims(filespace, dims, NULL);
/*
    printf("dataset(temperature) rank %d, dimensions %lux%lu\n",
               ndims, (unsigned long)(dims[0]), (unsigned long)(dims[1]));
*/
    /*
     * Define the memory space to read dataset.
     */
        memspace = H5Screate_simple(ndims,dims,NULL);

        double data[dims[0]];
    /*
     * Read dataset back and display.
     */
        herr_t status = H5Dread(dataset, H5T_NATIVE_DOUBLE, memspace, filespace,
                         H5P_DEFAULT, data);

    struct timeval t2;
    gettimeofday (&t2, NULL);

    printf ("read time = %f\n", t2.tv_sec + t2.tv_usec/1000000.0 - t1.tv_sec - t1.tv_usec/1000000.0); 
    return 0;
}
Esempio n. 4
0
int freeStringMatrix(int _iDatasetId, char** _pstData)
{
    herr_t status;
    hid_t typeId;
    hid_t space;

    if (_iDatasetId == -1)
    {
        return 0;
    }

    typeId = H5Tcopy(H5T_C_S1);
    status = H5Tset_size(typeId, H5T_VARIABLE);
    if (status < 0)
    {
        return -1;
    }

    space = H5Dget_space (_iDatasetId);
    status = H5Dvlen_reclaim (typeId, space, H5P_DEFAULT, _pstData);
    if (status < 0)
    {
        return -1;
    }

    status = H5Sclose(space);
    if (status < 0)
    {
        return -1;
    }

    status = H5Tclose(typeId);
    if (status < 0)
    {
        return -1;
    }

    status = H5Dclose(_iDatasetId);
    if (status < 0)
    {
        return -1;
    }

    return 0;
}
Esempio n. 5
0
void FWSingle::readInLong(int step, string IDstring, vector<long>& data_out)
{
  int RANK=1;
  hid_t       dataset;
  hid_t       filespace;
  hid_t       memspace;
  hid_t       cparms;
  hsize_t     dims[1];                     /* dataset and chunk dimensions*/
  hsize_t     chunk_dims[1];
  herr_t      status, status_n;
  int         rank, rank_chunk;
  hsize_t hi, hj;
  c_file = H5Fopen(fname.str().c_str(),H5F_ACC_RDONLY,H5P_DEFAULT);
  stringstream gname("");
  gname<<"Block_"<< step;
  hid_t d_file = H5Gopen(c_file,gname.str().c_str());
  dataset = H5Dopen(d_file, IDstring.c_str());
  filespace = H5Dget_space(dataset);
  rank = H5Sget_simple_extent_ndims(filespace);
  status_n  = H5Sget_simple_extent_dims(filespace, dims, NULL);
  //     if (verbose>1) printf("dataset ",IDstring.c_str(),"rank %d, dimensions %lu x %lu\n", rank, (unsigned long)(dims[0]), (unsigned long)(dims[1]));
  data_out.resize(dims[0]);
  cparms = H5Dget_create_plist(dataset);
  if (H5D_CHUNKED == H5Pget_layout(cparms))
  {
    rank_chunk = H5Pget_chunk(cparms, 2, chunk_dims);
    //       if (verbose>1) printf("chunk rank %d, dimensions %lu \n", rank_chunk, (unsigned long)(chunk_dims[0]) );
  }
  memspace = H5Screate_simple(RANK,dims,NULL);
  status = H5Dread(dataset, H5T_NATIVE_LONG, memspace, filespace, H5P_DEFAULT, &(data_out[0]));
  //     if(verbose>2)
  //     {
  //       printf("\n");
  //       app_log()<<IDstring.c_str()<<" Dataset: \n"<<endl;
  //       for (int j = 0; j < dims[0]; j++) app_log()<<data_out[j]<<" ";
  //       app_log()<<endl;
  //     }
  H5Pclose(cparms);
  H5Dclose(dataset);
  H5Sclose(filespace);
  H5Sclose(memspace);
  H5Gclose(d_file);
  H5Fclose(c_file);
}
Esempio n. 6
0
extern void
gridReaderHDF5_readIntoPatchForVar(gridReader_t reader,
                                   gridPatch_t  patch,
                                   int          idxOfVar)
{
	assert(reader != NULL);
	assert(reader->type = GRIDIO_TYPE_HDF5);
	assert(patch != NULL);
	assert(idxOfVar >= 0 && idxOfVar < gridPatch_getNumVars(patch));

	hid_t             dataSet;
	hid_t             dataSpaceFile, dataTypeFile;
	hid_t             dataSpacePatch, dataTypePatch;
	gridPointUint32_t idxLoPatch, dimsPatch;
	dataVar_t         var   = gridPatch_getVarHandle(patch, idxOfVar);
	void              *data = gridPatch_getVarDataHandle(patch, idxOfVar);

	gridPatch_getIdxLo(patch, idxLoPatch);
	gridPatch_getDims(patch, dimsPatch);

	dataSet        = H5Dopen(((gridReaderHDF5_t)reader)->file,
	                         dataVar_getName(var), H5P_DEFAULT);
	dataTypeFile   = H5Dget_type(dataSet);
	dataSpaceFile  = H5Dget_space(dataSet);

	dataTypePatch  = dataVar_getHDF5Datatype(var);
	dataSpacePatch = gridUtilHDF5_getDataSpaceFromDims(dimsPatch);

	gridUtilHDF5_selectHyperslab(dataSpaceFile, idxLoPatch, dimsPatch);

	if (H5Tequal(dataTypeFile, dataTypePatch)) {
		H5Dread(dataSet, dataTypeFile, dataSpacePatch,
		        dataSpaceFile, H5P_DEFAULT, data);
	} else {
		fprintf(stderr, "ERROR: Datatype in memory differs from file.\n");
		diediedie(EXIT_FAILURE);
	}

	H5Sclose(dataSpacePatch);
	H5Tclose(dataTypePatch);
	H5Sclose(dataSpaceFile);
	H5Tclose(dataTypeFile);
	H5Dclose(dataSet);
} /* gridReaderHDF5_readIntoPatchForVar */
Esempio n. 7
0
herr_t H5TBOread_records( hid_t dataset_id,
                          hid_t mem_type_id,
                          hsize_t start,
                          hsize_t nrecords,
                          void *data )
{

 hid_t    space_id;
 hid_t    mem_space_id;
 hsize_t  count[1];
 hsize_t  offset[1];

 /* Get the dataspace handle */
 if ( (space_id = H5Dget_space( dataset_id )) < 0 )
  goto out;

 /* Define a hyperslab in the dataset of the size of the records */
 offset[0] = start;
 count[0]  = nrecords;
 if ( H5Sselect_hyperslab(space_id, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
  goto out;

 /* Create a memory dataspace handle */
 if ( (mem_space_id = H5Screate_simple( 1, count, NULL )) < 0 )
  goto out;

 if ( H5Dread(dataset_id, mem_type_id, mem_space_id, space_id, H5P_DEFAULT, data ) < 0 )
  goto out;

 /* Terminate access to the memory dataspace */
 if ( H5Sclose( mem_space_id ) < 0 )
  goto out;

 /* Terminate access to the dataspace */
 if ( H5Sclose( space_id ) < 0 )
  goto out;

return 0;

out:
 return -1;

}
Esempio n. 8
0
void fh5d_open_(char *dname, int *hdferr)
{

extern hid_t fileid;
herr_t herr;

dsetid = H5Dopen(fileid, dname);
//printf("fh5d_open: %d\n",dsetid);

if (dsetid < 0) { *hdferr = dsetid; return;}


dspcid = H5Dget_space(dsetid);
//printf("fh5d_get_space: %d\n",dspcid);

*hdferr = dspcid;

return;
}
Esempio n. 9
0
	// Extract information from HDF5 file
	void get_data(std::string data_path, std::string dataset_name, std::vector<double> &data_out){

		//  Declare variables 
		const char *fname = data_path.c_str();
		hid_t  file_id , dataset_id , dataspace_id , file_dataspace_id;
		hsize_t* dims;
		hssize_t  num_elem;
		int rank;
		int ndims;

		// Open  existing  HDF5  file 
		file_id = H5Fopen(fname , H5F_ACC_RDONLY , H5P_DEFAULT);

		// Open  existing  dataset
		dataset_id = H5Dopen(file_id , dataset_name.c_str(), H5P_DEFAULT);

		//  Determine  dataset  parameters
		file_dataspace_id = H5Dget_space(dataset_id);
		rank = H5Sget_simple_extent_ndims(file_dataspace_id);
		dims = (hsize_t*)  malloc(rank *sizeof(hsize_t));
		ndims = H5Sget_simple_extent_dims(file_dataspace_id, dims, NULL);
		//std::cout << "rank: " << std::to_string(rank) << std::endl;

		// Allocate  matrix
		num_elem = H5Sget_simple_extent_npoints(file_dataspace_id);
		std::vector<double> data_out_tmp(num_elem);
		// = (double*)malloc(num_elem *sizeof(double));
		//std::cout << "num_elem: " << std::to_string(num_elem) << std::endl;

		// Create  dataspace
		dataspace_id = H5Screate_simple(rank , dims , NULL);

		// Read  matrix  data  from  file 
		H5Dread(dataset_id, H5T_NATIVE_DOUBLE, dataspace_id, file_dataspace_id , H5P_DEFAULT , &data_out_tmp[0]);
		data_out = data_out_tmp;
		
		//  Release  resources  and  close  file 
		H5Dclose(dataset_id);
		H5Sclose(dataspace_id);
		H5Sclose(file_dataspace_id);
		H5Fclose(file_id);
		free(dims);
	}
/*
 *  utility function to get dimensionality of a dataset
 */
int get_rank_by_name(hid_t group_id, char *name)
{

  if (!checkfordataset(group_id,name)) { return 0; }

  herr_t HDF5_error = -1;
#if H5_VERSION_GE(1,8,0)
  hid_t dataset_id   = H5Dopen2(group_id,name,H5P_DEFAULT);
#else
  hid_t dataset_id   = H5Dopen(group_id,name);
#endif
  if (dataset_id == HDF5_error) 
     { printf("ERROR opening %s data set \n",name); return 0; }

  hid_t dataspace_id = H5Dget_space(dataset_id);
  int rank           = get_rank(dataspace_id);
  H5Dclose(dataset_id);
  return rank;
}
Esempio n. 11
0
hdf5_dataspace::hdf5_dataspace(hdf5_dataset const& dataset)
    :
      hdf5_object(H5Dget_space(dataset.get_id()))
{
    if(dataset.get_id() < 0) {
        boost::serialization::throw_exception(
            hdf5_archive_exception(
                hdf5_archive_exception::hdf5_archive_dataset_access_error
            )
        );
    }
    if(get_id() < 0) {
        boost::serialization::throw_exception(
            hdf5_archive_exception(
                hdf5_archive_exception::hdf5_archive_dataspace_access_error
            )
        );
    }
}
Esempio n. 12
0
herr_t H5ARRAYget_info( hid_t dataset_id,
			hid_t type_id,
			hsize_t *dims,
			hsize_t *maxdims,
			H5T_class_t *class_id,
			char *byteorder)
{
  hid_t       space_id;

  /* Get the class. */
  *class_id = H5Tget_class( type_id );

  /* Get the dataspace handle */
  if ( (space_id = H5Dget_space( dataset_id )) < 0 )
    goto out;

  /* Get dimensions */
  if ( H5Sget_simple_extent_dims( space_id, dims, maxdims) < 0 )
    goto out;

  /* Terminate access to the dataspace */
  if ( H5Sclose( space_id ) < 0 )
    goto out;

  /* Get the byteorder */
  /* Only integer, float, time, enumerate and array classes can be
     byteordered */
  if ((*class_id == H5T_INTEGER) || (*class_id == H5T_FLOAT)
      || (*class_id == H5T_BITFIELD) || (*class_id == H5T_COMPOUND)
      || (*class_id == H5T_TIME) || (*class_id == H5T_ENUM)
      || (*class_id == H5T_ARRAY)) {
    get_order(type_id, byteorder);
  }
  else {
    strcpy(byteorder, "irrelevant");
  }

  return 0;

out:
 return -1;

}
Esempio n. 13
0
herr_t ASDF_write_partial_waveform(hid_t data_id, const float *waveform,
                                   int offset, int nsamples) {
  hid_t space_id, slab_id;

  CHK_H5(space_id = H5Dget_space(data_id));

  hsize_t start[1] = {offset};
  hsize_t count[1] = {1};
  hsize_t block[1] = {nsamples};
  CHK_H5(H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start,
                             NULL, count, block));
  CHK_H5(slab_id = H5Screate_simple(1, block, NULL));
  CHK_H5(H5Dwrite(data_id, H5T_IEEE_F32LE, slab_id, space_id,
                  H5P_DEFAULT, waveform));
  CHK_H5(H5Sclose(slab_id));
  CHK_H5(H5Sclose(space_id));

  return 0; // Success
}
Esempio n. 14
0
File: io.c Progetto: darien0/cow
void cow_domain_readsize(cow_domain *d, char *fname, char *dname)
{
#if (COW_HDF5)
  if (_io_check_file_exists(fname)) return;
  hid_t file = H5Fopen(fname, H5F_ACC_RDONLY, d->fapl);
  hid_t dset = H5Dopen(file, dname, H5P_DEFAULT);
  hid_t fspc = H5Dget_space(dset);
  hsize_t dims[3] = { 1, 1, 1 };
  int ndims = H5Sget_simple_extent_dims(fspc, dims, NULL);
  H5Dclose(dset);
  H5Fclose(file);
  cow_domain_setndim(d, ndims);
  for (int n=0; n<ndims; ++n) {
    cow_domain_setsize(d, n, dims[n]);
  }
  printf("[%s] inferred global domain size of (%lld %lld %lld) from %s/%s\n",
	 MODULE, dims[0], dims[1], dims[2], fname, dname);
#endif
}
Esempio n. 15
0
 void h5_read(group g, std::string const& name, std::string& value) {
  dataset ds = g.open_dataset(name);
  h5::dataspace d_space = H5Dget_space(ds);
  int rank = H5Sget_simple_extent_ndims(d_space);
  if (rank != 0) TRIQS_RUNTIME_ERROR << "Reading a string and got rank !=0";
  size_t size = H5Dget_storage_size(ds);

  datatype strdatatype = H5Tcopy(H5T_C_S1);
  H5Tset_size(strdatatype, size);
  //auto status = H5Tset_size(strdatatype, size);
  // auto status = H5Tset_size (strdatatype, H5T_VARIABLE);

  std::vector<char> buf(size + 1, 0x00);
  auto err = H5Dread(ds, strdatatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, &buf[0]);
  if (err < 0) TRIQS_RUNTIME_ERROR << "Error reading the string named" << name << " in the group" << g.name();

  value = "";
  value.append(&(buf.front()));
 }
Esempio n. 16
0
herr_t H5TBOwrite_elements( hid_t dataset_id,
                            hid_t mem_type_id,
                            hsize_t nrecords,
                            const void *coords,
                            const void *data )
{

 hsize_t  count[1];
 hid_t    space_id;
 hid_t    mem_space_id;

 /* Get the dataspace handle */
 if ( (space_id = H5Dget_space( dataset_id )) < 0 )
  goto out;

 /* Define a selection of points in the dataset */

 if ( H5Sselect_elements(space_id, H5S_SELECT_SET, (size_t)nrecords, (const hsize_t *)coords) < 0 )
  goto out;

 /* Create a memory dataspace handle */
 count[0] = nrecords;
 if ( (mem_space_id = H5Screate_simple( 1, count, NULL )) < 0 )
  goto out;

 if ( H5Dwrite( dataset_id, mem_type_id, mem_space_id, space_id, H5P_DEFAULT, data ) < 0 )
  goto out;

 /* Terminate access to the memory dataspace */
 if ( H5Sclose( mem_space_id ) < 0 )
  goto out;

 /* Terminate access to the dataspace */
 if ( H5Sclose( space_id ) < 0 )
  goto out;

return 0;

out:
 return -1;

}
Esempio n. 17
0
/**
 * Write hyperslab.
 * 
 * @param [in] HDF5_Dataset_id - Dataset id
 * @param [in] Position - Position in the dataset
 * @param [in] Size - Size of the hyperslab
 * @param [in] Data
 * @throw ios::failure
 */
void THDF5_File::WriteHyperSlab(const hid_t HDF5_Dataset_id, const TDimensionSizes & Position , const TDimensionSizes & Size, const long * Data){
    
    
    
     // Select hyperslab
    const int MatrixRank = 3;    
    hsize_t ElementCount[MatrixRank] = {Size.Z, Size.Y, Size.X};    
    hsize_t Offset[MatrixRank] = {Position.Z,Position.Y,Position.X};
    
    herr_t status;
    hid_t  HDF5_Filespace,HDF5_Memspace;
    
    // Select hyperslab in the file.     
    HDF5_Filespace = H5Dget_space(HDF5_Dataset_id);  
    
    
    status = H5Sselect_hyperslab(HDF5_Filespace, H5S_SELECT_SET, Offset, 0, ElementCount, NULL);
    if (status < 0) {
        char ErrorMessage[256];
        sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,"");        
        throw ios::failure(ErrorMessage);
     } 
    
    
    // assign memspace
    HDF5_Memspace = H5Screate_simple(MatrixRank, ElementCount, NULL);

    
     status = H5Dwrite(HDF5_Dataset_id, H5T_STD_U64LE, HDF5_Memspace, HDF5_Filespace,  H5P_DEFAULT, Data);
     if (status < 0) {
        char ErrorMessage[256];
        sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,"");
        
        throw ios::failure(ErrorMessage);
     } 
    
    H5Sclose(HDF5_Memspace);
    H5Sclose(HDF5_Filespace);  
    
    
    
}// end of WriteHyperSlab
Esempio n. 18
0
bool PWParameterSet::getEigVectorType(hid_t h)
{
  int rank=0;
  if(is_manager())
  {
    ostringstream oss;
    oss << "/"<<eigTag << "/"<<twistTag<<twistIndex << "/"<< bandTag << 0;
    //if(version[1]==10)
    if(hasSpin)
      oss << "/" << spinTag << 0;
    oss << "/eigenvector";
    hsize_t dimTot[4];
    hid_t dataset = H5Dopen(h,oss.str().c_str());
    hid_t dataspace = H5Dget_space(dataset);
    rank = H5Sget_simple_extent_ndims(dataspace);
    int status_n = H5Sget_simple_extent_dims(dataspace, dimTot, NULL);
  }
  myComm->bcast(rank);
  return rank==4;
}
Esempio n. 19
0
/* ------- begin --------------------------   writeAtmos_p.c --- */
void writeAtmos_p(void)
{
  /* Write atmos arrays. This has now been modified and writes the interpolated
     arrays, from depth_refine. With that, now this is the only viable option
     to write the atmos data, as there is no option to save in memory and
     writeAtmos_all used to write from the input file, not the interpolated
     quantities

     IMPORTANT: at the moment this is a trimmed version, only writing z to save
                space and computational time.

     */
  const char routineName[] = "writeAtmos_p";
  hsize_t  offset[] = {0, 0, 0, 0};
  hsize_t  count[] = {1, 1, 1, 1};
  hsize_t  dims[4];
  hid_t    file_dspace, mem_dspace;

  /* Memory dataspace */
  dims[0] = atmos.Nspace;
  if (( mem_dspace = H5Screate_simple(1, dims, NULL) ) < 0)
    HERR(routineName);
  /* File dataspace */
  offset[0] = mpi.ix;
  offset[1] = mpi.iy;
  offset[2] = mpi.zcut;
  count[2] = atmos.Nspace;
  if (( file_dspace = H5Dget_space(io.in_atmos_T) ) < 0) HERR(routineName);
  if (( H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, offset,
                            NULL, count, NULL) ) < 0) HERR(routineName);
  if (( H5Dwrite(io.in_atmos_T, H5T_NATIVE_DOUBLE, mem_dspace,
                file_dspace, H5P_DEFAULT, atmos.T) ) < 0) HERR(routineName);
  if (( H5Dwrite(io.in_atmos_vz, H5T_NATIVE_DOUBLE, mem_dspace,
           file_dspace, H5P_DEFAULT, geometry.vel) ) < 0) HERR(routineName);
  if (( H5Dwrite(io.in_atmos_z, H5T_NATIVE_DOUBLE, mem_dspace,
        file_dspace, H5P_DEFAULT, geometry.height) ) < 0) HERR(routineName);
  /* release dataspace resources */
  if (( H5Sclose(mem_dspace) ) < 0) HERR(routineName);
  if (( H5Sclose(file_dspace) ) < 0) HERR(routineName);
  return;
}
Esempio n. 20
0
/*-------------------------------------------------------------------------
 * Function:  check_dset
 *
 * Purpose:  Part 2 of a two-part H5Fflush() test, checks if the data in a dataset
 *     is what it is supposed to be.
 *
 * Return:  Success:  0
 *
 *    Failure:  1
 *
 * Programmer:  Leon Arber
 *              Oct. 4, 2006.
 *
 *-------------------------------------------------------------------------
 */
static int
check_dset(hid_t file, const char* name)
{
    hid_t  space, dset;
    hsize_t  ds_size[2] = {100, 100};
    double  error;
    size_t  i, j;

    /* Open the dataset */
    if((dset = H5Dopen2(file, name, H5P_DEFAULT)) < 0) goto error;
    if((space = H5Dget_space(dset)) < 0) goto error;
    if(H5Sget_simple_extent_dims(space, ds_size, NULL) < 0) goto error;
    assert(100 == ds_size[0] && 100 == ds_size[1]);

    /* Read some data */
    if(H5Dread(dset, H5T_NATIVE_DOUBLE, space, space, H5P_DEFAULT, the_data) < 0)
        goto error;
    for(i = 0; i < (size_t)ds_size[0]; i++)
        for(j = 0; j < (size_t)ds_size[1]; j++) {
            /*
             * The extra cast in the following statement is a bug workaround
             * for the Win32 version 5.0 compiler.
             * 1998-11-06 ptl
             */
            error = fabs(the_data[i][j] - (double)(hssize_t)i / ((hssize_t)j + 1));
            if(error > 0.0001F) {
                H5_FAILED();
                printf("    dset[%lu][%lu] = %g\n",
                    (unsigned long)i, (unsigned long)j, the_data[i][j]);
                printf("    should be %g\n",
                    (double)(hssize_t)i/(hssize_t)(j+1));
                goto error;
            } /* end if */
        } /* end for */
    if(H5Dclose(dset) < 0)
        goto error;
    return 0;

error:
    return 1;
}
Esempio n. 21
0
/* Load and read file with initial positions and velocites */
int loadHdf5Init(char *filename, std::vector<array6> &init){
    hid_t   hdf_file,hdf_group,hdf_data,hdf_dspace;
    herr_t  status;
    //state_type x(6);
    array6 x;

    fprintf(stdout,"Reading file %s ...\n",filename);
    hdf_file = H5Fopen(filename,H5F_ACC_RDONLY,H5P_DEFAULT);
    if (hdf_file < 0){
        return -1;
    }

    if ( (hdf_group=H5Gopen2(hdf_file,"/",H5P_DEFAULT)) < 0){
        H5Fclose(hdf_file);
        return -1;
    }

    if ( (hdf_data=H5Dopen2(hdf_file,"/x",H5P_DEFAULT)) < 0){
        H5Dclose(hdf_data);
        return -1;
    }
    hdf_dspace = H5Dget_space(hdf_data);
    hsize_t dims[2];
    H5Sget_simple_extent_dims(hdf_dspace,dims,NULL);
    std::cout << "No. of test particles read = " << dims[0] << "\n";
    double *temp = new double[dims[0]*dims[1]];
    status=H5Dread(hdf_data, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, temp);
    for (int i=0; i<dims[0]; i++){
        for (int j=0; j<dims[1]; j++){
            x[j]=temp[i*dims[1]+j];
        }
        init.push_back(x);
    }

    delete [] temp;
    H5Gclose(hdf_group);
    H5Fclose(hdf_file);
    H5Dclose(hdf_data);
    fprintf(stdout," file read successfully!\n");
    return 0;
}
Esempio n. 22
0
void saveParticleComp_Int(int *data,char *fileName,char *dataName,int totalCnt,int cnt,int offSet)
{
  int i,j,k;
  int myrank, nTasks;
  MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
  MPI_Comm_size(MPI_COMM_WORLD, &nTasks);

  hid_t file_id,dset_id,plist_id,tic_id;
  herr_t status;
  hid_t total_file_space,subfilespace,filespace,memspace,ticspace;
  hsize_t dimsf[1],count[1],offset[1];

  plist_id=H5Pcreate(H5P_FILE_ACCESS);
  H5Pset_fapl_mpio(plist_id,MPI_COMM_WORLD,MPI_INFO_NULL);
//    H5Pset_fclose_degree(plist_id,H5F_CLOSE_SEMI);
//    MPI_Barrier(MPI_COMM_WORLD);

  file_id=H5Fopen(fileName,H5F_ACC_RDWR,plist_id);
  H5Pclose(plist_id);

  dimsf[0]=totalCnt;
  filespace=H5Screate_simple(1,dimsf,NULL);

  count[0]=cnt;
  offset[0]=offSet;
  memspace=H5Screate_simple(1,count,NULL);

  dset_id=H5Dcreate2(file_id,dataName,H5T_NATIVE_INT,filespace,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
  subfilespace=H5Dget_space(dset_id);
  H5Sselect_hyperslab(subfilespace,H5S_SELECT_SET,offset,NULL,count,NULL);
  plist_id=H5Pcreate(H5P_DATASET_XFER);
  H5Pset_dxpl_mpio(plist_id,H5FD_MPIO_INDEPENDENT);
  status = H5Dwrite(dset_id, H5T_NATIVE_INT,memspace,subfilespace,plist_id,data);
  H5Pclose(plist_id);
  H5Sclose(subfilespace);
  H5Dclose(dset_id);

  H5Sclose(memspace);
  H5Sclose(filespace);
  H5Fclose(file_id);
}
Esempio n. 23
0
asynStatus NDFileHDF5AttributeDataset::writeAttributeDataset(hdf5::When_t whenToSave, hsize_t *offsets, NDAttribute *ndAttr, int flush, int indexed)
{
  asynStatus status = asynSuccess;
  char * stackbuf[MAX_ATTRIBUTE_STRING_SIZE];
  void* pDatavalue = stackbuf;
  int ret;
  //check if the attribute is meant to be saved at this time
  if (whenToSave_ == whenToSave) {
    // Extend the dataset as required to store the data
    if (indexed == -1){
      extendDataSet(offsets);
    } else {
      extendIndexDataSet(offsets[indexed]);
    }
    // find the data based on datatype
    ret = ndAttr->getValue(ndAttr->getDataType(), pDatavalue, MAX_ATTRIBUTE_STRING_SIZE);
    if (ret == ND_ERROR) {
      memset(pDatavalue, 0, MAX_ATTRIBUTE_STRING_SIZE);
    }
    // Work with HDF5 library to select a suitable hyperslab (one element) and write the new data to it
    H5Dset_extent(dataset_, dims_);
    filespace_ = H5Dget_space(dataset_);

    // Select the hyperslab
    H5Sselect_hyperslab(filespace_, H5S_SELECT_SET, offset_, NULL, elementSize_, NULL);

    // Write the data to the hyperslab.
    H5Dwrite(dataset_, datatype_, memspace_, filespace_, H5P_DEFAULT, pDatavalue);


    // Check if we are being asked to flush
    if (flush == 1){
      status = this->flushDataset();
    }

    H5Sclose(filespace_);
    nextRecord_++;
  }

  return status;
}
Esempio n. 24
0
ls2_hdf5_read_locbased(const char *filename, ls2_output_variant variant,
                       vector2 **anchors, size_t *no_anchors,
                       float **results, uint16_t *width, uint16_t *height)
{
    hid_t file, dataset, dataspace, memspace;
    hsize_t dims[2];
    int rank, ret;

    file = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);

    // Read the anchors.
    if (anchors != NULL && no_anchors != NULL) {
        ret = ls2_hdf5_read_anchors(file, anchors, no_anchors);
        if (ret < 0)
            return ret;
    }

    // Read the errors.
    char name[256];
    snprintf(name, 256, "/Result/%s", ls2_hdf5_variant_name(variant));
    dataset = H5Dopen2(file, name, H5P_DEFAULT);
    dataspace = H5Dget_space(dataset);
    rank = H5Sget_simple_extent_ndims(dataspace);
    if (rank != 2) {
        fprintf(stderr, "%s wrong rank %d\n", name, (int) rank);
        return -1;
    }
    H5Sget_simple_extent_dims(dataspace, dims, NULL);
    *width = (uint16_t) dims[1];
    *height = (uint16_t) dims[0];
    *results = (float *) calloc((size_t) (*height * *width), sizeof(float));
    memspace = H5Screate_simple(2, dims, NULL);
    H5Dread(dataset, H5T_NATIVE_FLOAT, memspace, dataspace, H5P_DEFAULT,
            *results);
    H5Dclose(dataset);
    H5Sclose(dataspace);
    H5Sclose(memspace);

    H5Fclose(file);
    return 0;
}
Esempio n. 25
0
int H5mdfile::H5_Dopen2(int argc, char **argv, Tcl_Interp *interp)
{
    /* Open an existing dataset */
    dataset_id = H5Dopen2(file_id, argv[2], H5P_DEFAULT);
    // Dataset properties
    dataspace_id = H5Dget_space(dataset_id);
    dataset_type_id = H5Dget_type(dataset_id);
    datatype_size = H5Tget_size(dataset_type_id);
    dataset_rank = H5Sget_simple_extent_dims(dataspace_id,dims,maxdims);
    dataset_rank = H5Sget_simple_extent_dims(dataspace_id,dimstotal,maxdims);
    prop_id = H5Dget_create_plist(dataset_id);
    if (H5D_CHUNKED == H5Pget_layout(prop_id))
        chunk_rank = H5Pget_chunk(prop_id, dataset_rank, chunk_dims);
    // Dataset size
    dset_data_size=1;
    for(int i=0;i<dataset_rank;i++)
    {
        dset_data_size*=dims[i];
    }
    return TCL_OK;
}
Esempio n. 26
0
//hyperslab write
void pHdf5IoDataModel::writeHyperslab(const QString& dataset_name, DataType type, quint64 *offset, quint64 *stride, quint64 *count, quint64 *block, quint64 *values_shape, void *values)
{
    d->status=0;
    hid_t dataset_id = d->datasetId(dataset_name);

    //the selection within the file dataset's dataspace
    hid_t file_dataspace = H5Dget_space(dataset_id);

    if(H5Sselect_hyperslab(file_dataspace, H5S_SELECT_SET, offset, stride, count, block)<0) {
        dtkError() << "ERROR selecting hyperslab" << dataset_name;
    }

    //set the dimensions of values. memory dataspace and the selection within it
    hid_t values_dataspace = H5Screate_simple(H5Sget_simple_extent_ndims(file_dataspace),
                                              values_shape, NULL);

    switch(type) {
    case dtkIoDataModel::Int:
        d->status = H5Dwrite(dataset_id, H5T_NATIVE_INT, values_dataspace,
                             file_dataspace, d->prop_list_id, values);
        break;
    case dtkIoDataModel::LongLongInt:
        d->status = H5Dwrite(dataset_id, H5T_NATIVE_LLONG, values_dataspace,
                             file_dataspace, d->prop_list_id, values);
        break;
    case dtkIoDataModel::Double:
        d->status = H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, values_dataspace,
                             file_dataspace, d->prop_list_id, values);
        break;
    default:
        dtkError() << "write method: Datatype not supported";
    };
    if(d->status<0) {
        dtkError() << "error writing hyperslab" << dataset_name;
    }

    H5Sclose(file_dataspace);
    H5Sclose(values_dataspace);
}
static unsigned hdf5_subarray(ndio_t file,nd_t dst,size_t *pos,size_t *step)
{ ndio_hdf5_t self=(ndio_hdf5_t)ndioContext(file);
  hsize_t *pos_,*shape_,*step_;
  hid_t m=-1,f=-1;
  STACK_ALLOC(hsize_t,pos_,ndndim(dst));
  STACK_ALLOC(hsize_t,shape_,ndndim(dst));
  STACK_ALLOC(hsize_t,step_,ndndim(dst));
  reverse_hsz_sz(ndndim(dst),shape_,ndshape(dst));
  reverse_hsz_sz(ndndim(dst),pos_,pos);
  reverse_hsz_sz(ndndim(dst),step_,step);

  HTRY(f=H5Dget_space(dataset(self)));
  HTRY(H5Sselect_hyperslab(f,H5S_SELECT_SET,pos_,step_,shape_,NULL/*block*/));
  HTRY(m=H5Screate_simple(ndndim(dst),shape_,NULL));
  HTRY(H5Dread(dataset(self),dtype(self),m,f,H5P_DEFAULT,nddata(dst)));
  H5Sclose(f);
  return 1;
Error:
  if(f>-1) H5Sclose(f);
  if(m>-1) H5Sclose(m);
  return 0;
}
Esempio n. 28
0
File: cxi.c Progetto: cxidb/libcxi
CXI_Dataset * cxi_open_dataset(CXI_Dataset_Reference * ref){
  cxi_debug("opening dataset");
  if(!ref){
    return NULL;
  }


  cxi_debug("opening dataset");
  CXI_Dataset * dataset = calloc(sizeof(CXI_Dataset),1);
  if(!dataset){
    return NULL;
  }
  dataset->handle = H5Dopen(ref->parent_handle,ref->group_name,H5P_DEFAULT);

  hid_t s = H5Dget_space(dataset->handle);
  dataset->dimension_count = H5Sget_simple_extent_ndims(s);
  dataset->dimensions = calloc(sizeof(hsize_t),dataset->dimension_count);
  H5Sget_simple_extent_dims(s,dataset->dimensions,NULL);     
  dataset->data_type = H5Dget_type(dataset->handle);
  ref->dataset = dataset;
  return dataset;
}
Esempio n. 29
0
File: cxi.c Progetto: cxidb/libcxi
int cxi_write_dataset_slice(CXI_Dataset * dataset,unsigned int slice, void * data, hid_t datatype){
  if(!dataset){
    return -1;
  }
  if(!data){
    return -1;
  }
  if(slice >= dataset->dimensions[0]){
    return -1;
  }
  if(dataset->handle < 0){
    return -1;
  }

  hid_t s = H5Dget_space(dataset->handle);
  if(s < 0){
    return -1;
  }
  hsize_t *start;
  start = malloc(sizeof(hsize_t)*dataset->dimension_count);
  hsize_t *count;
  count = malloc(sizeof(hsize_t)*dataset->dimension_count);
  for(int i =0;i<dataset->dimension_count;i++){
    start[i] = 0;
    count[i] = dataset->dimensions[i];
  }

  start[0] = slice;
  count[0] = 1;
  hid_t memspace = H5Screate_simple (dataset->dimension_count, count, NULL);
  
  H5Sselect_hyperslab(s, H5S_SELECT_SET, start, NULL, count, NULL);
  H5Dwrite(dataset->handle,datatype,memspace,s,H5P_DEFAULT,data);      
  H5Sclose(s);
  free(start);
  free(count);

  return 0;
}
Esempio n. 30
0
void restoreData(float *data,char *fileName,char *dataName,int totalCnt,int cnt,int *cntOffSet)
{
  hid_t file_id,dset_id,plist_id,group_id;
  herr_t status;
  hid_t subfilespace,filespace,memspace;
  hsize_t dimsf[1],count[1],offset[1];

  int myrank, nTasks;    
  MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
  MPI_Comm_size(MPI_COMM_WORLD, &nTasks);

  plist_id=H5Pcreate(H5P_FILE_ACCESS);
  H5Pset_fapl_mpio(plist_id,MPI_COMM_WORLD,MPI_INFO_NULL);
//  H5Pset_fclose_degree(plist_id,H5F_CLOSE_SEMI);
//  MPI_Barrier(MPI_COMM_WORLD);

  file_id=H5Fopen(fileName,H5F_ACC_RDWR,plist_id);
  H5Pclose(plist_id);
  dimsf[0]=totalCnt;     
  filespace=H5Screate_simple(1,dimsf,NULL);

  count[0]=cnt;
  offset[0]=cntOffSet[myrank];
  memspace=H5Screate_simple(1,count,NULL);

  dset_id=H5Dopen2(file_id,dataName,H5P_DEFAULT);
  subfilespace=H5Dget_space(dset_id);
  H5Sselect_hyperslab(subfilespace,H5S_SELECT_SET,offset,NULL,count,NULL);
  plist_id=H5Pcreate(H5P_DATASET_XFER);
  H5Pset_dxpl_mpio(plist_id,H5FD_MPIO_COLLECTIVE);
  status = H5Dread(dset_id, H5T_NATIVE_FLOAT,memspace,subfilespace,plist_id,data);
  H5Pclose(plist_id);
  H5Sclose(subfilespace);
  H5Dclose(dset_id);

  H5Sclose(memspace);
  H5Sclose(filespace);
  H5Fclose(file_id);
}