void h5_value_doubles(hid_t file_id, char *group, char *name, double **values,
	int *numValues)
{
  int kk;
  hid_t group_id = H5Gopen(file_id, group, H5P_DEFAULT);
  hid_t data_id = H5Dopen(group_id, name, H5P_DEFAULT);
  hid_t data_space = H5Dget_space(data_id);
  int rank = H5Sget_simple_extent_ndims(data_space);
  hsize_t dims[H5S_MAX_RANK], maxdim[H5S_MAX_RANK];
  H5Sget_simple_extent_dims(data_space, dims, maxdim);
  hid_t data_type = H5Dget_type(data_id);
  H5T_class_t data_class = H5Tget_native_type(data_type, H5T_DIR_DEFAULT);
  size_t data_size = H5Tget_size(data_class);  
  hsize_t elements = 1;
  for (kk=0; kk<rank; kk++)
    elements *= dims[kk];
  void *buf = (void *) MALLOC((size_t)(elements*data_size));
  H5Dread(data_id, data_class, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
  *values = buf;
  *numValues = elements;
  H5Tclose(data_type);
  H5Tclose(data_class);
  H5Sclose(data_space);
  H5Dclose(data_id);
  H5Gclose(group_id); 
}
Beispiel #2
0
/****************************************************************
**
**  getHDF5ClassID(): Returns class ID for loc_id.name. -1 if error.
**
****************************************************************/
H5T_class_t getHDF5ClassID(hid_t loc_id,
                           const char *name,
                           H5D_layout_t *layout,
                           hid_t *type_id,
                           hid_t *dataset_id) {
   H5T_class_t  class_id;
   hid_t        plist;

   /* Open the dataset. */
   if ( (*dataset_id = H5Dopen( loc_id, name, H5P_DEFAULT )) < 0 )
     return -1;

   /* Get an identifier for the datatype. */
   *type_id = H5Dget_type( *dataset_id );

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

   /* Get the layout of the datatype */
   plist = H5Dget_create_plist(*dataset_id);
   *layout = H5Pget_layout(plist);
   H5Pclose(plist);

   return class_id;

}
Beispiel #3
0
int luaC_h5_read_string(lua_State *L)
{
  const char *dsetnm = luaL_checkstring(L, 1);
  if (PresentFile < 0) {
    luaL_error(L, "no open file");
  }
  hid_t dset = H5Dopen(PresentFile, dsetnm, H5P_DEFAULT);
  if (dset < 0) {
    luaL_error(L, "no data set named %s", dsetnm);
  }
  hid_t fspc = H5Dget_space(dset);
  hid_t strn = H5Dget_type(dset);
  hsize_t msize = H5Tget_size(strn);

  char *string = (char*) malloc((msize+1)*sizeof(char));

  H5Dread(dset, strn, fspc, fspc, H5P_DEFAULT, string);
  string[msize] = '\0'; // Make sure to null-terminate the string
  lua_pushstring(L, string);

  H5Tclose(strn);
  H5Sclose(fspc);
  H5Dclose(dset);
  free(string);

  return 1;
}
Beispiel #4
0
/** Return the byte size of the voxel datatytpe
 */
int miget_data_type_size ( mihandle_t volume, misize_t *voxel_size )
{
  hid_t grp_id;
  hid_t dset_id;
  hid_t type_id;
  hid_t file_id = volume->hdf_id;

  grp_id = midescend_path ( file_id, MI_FULLIMAGE_PATH );

  if ( grp_id < 0 ) {
    return ( MI_ERROR );
  }

  dset_id = H5Dopen1 ( grp_id, "image" );

  if ( dset_id < 0 ) {
    return ( MI_ERROR );
  }

  type_id = H5Dget_type ( dset_id );

  if ( type_id < 0 ) {
    return ( MI_ERROR );
  }

  *voxel_size = H5Tget_size ( type_id );

  H5Tclose ( type_id );
  H5Dclose ( dset_id );
  H5Gclose ( grp_id );

  return ( MI_NOERROR );
}
Beispiel #5
0
void  H5Dataset_readPalette(H5Dataset *d, hid_t did)
{
    hid_t pal_id=-1, tid=-1;
    hobj_ref_t *refs;

    if (!d || did<=0 ) return;

    refs = H5Dataset_get_paletteRef(did);
    if (refs) {
        // use the fist palette
        pal_id =  H5Rdereference(d->fid, H5R_OBJECT, refs);
        tid = H5Dget_type(pal_id);
        if (H5Dget_storage_size(pal_id) <= 768) 
        {
            H5Attribute *attr;
            d->nattributes = 1;
            d->attributes = (H5Attribute*)malloc(sizeof(H5Attribute));
            attr = &(d->attributes[0]);
            H5Attribute_ctor(attr);
            attr->value = (unsigned char *)malloc(3*256); 
            memset(attr->value, 0, 768);
            attr->nvalue = 768;
            attr->name = (char*)malloc(20);
            strcpy(attr->name, PALETTE_VALUE);
            H5Dread( pal_id, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, attr->value);
        }

        if (tid > 0) H5Tclose(tid);
        if (pal_id > 0) H5Dclose(pal_id);
        free(refs);
    }

}
Beispiel #6
0
H5T_class_t HdfDataset::type() const
{
  hid_t tid = H5Dget_type( d->id );
  H5T_class_t t_class = H5Tget_class( tid );
  H5Tclose( tid );
  return t_class;
}
/*+++++++++++++++++++++++++
.IDENTifer   PYTABLE_write_records
.PURPOSE     Write records to an HDF5 array
.INPUT/OUTPUT
  call as    stat = PYTABLE_write_records( locID, dset_name, start, step,
			                   count, buffer );
     input:
            hid_t locID      :  HDF5 identifier of file or group
	    char *dset_name  :  name of dataset
	    hsize_t *start   :  index of first row to overwrite
	    hsize_t *step    :  
	    hsize_t *count   :  number of rows to write
	    void *buffer     :  data to write
	    
.RETURNS     A negative value is returned on failure. 
.COMMENTS    none
-------------------------*/
herr_t PYTABLE_write_records( hid_t locID, const char *dset_name, 
			      hsize_t *start, hsize_t *step,
			      hsize_t *count, const void *buffer )
{
     int      rank;

     hid_t    dataID;
     hid_t    spaceID = -1;
     hid_t    mem_spaceID = -1;
     hid_t    typeID = -1;

/* open the dataset. */
     if ( (dataID = H5Dopen( locID, dset_name, H5P_DEFAULT )) < 0 )
	  return -1;

/* get the dataspace handle */
     if ( (spaceID = H5Dget_space( dataID )) < 0 )
	  goto done;

/* get rank */
     if ( (rank = H5Sget_simple_extent_ndims( spaceID )) <= 0 )
	  goto done;

/* create a simple memory data space */
     if ( (mem_spaceID = H5Screate_simple( rank, count, NULL )) < 0 )
	  goto done;

/* define a hyperslab in the dataset */
     if ( H5Sselect_hyperslab( spaceID, H5S_SELECT_SET, start,
			       step, count, NULL ) < 0 )
	  goto done;

/* get an identifier for the datatype. */
     if ( (typeID = H5Dget_type( dataID )) < 0 ) goto done;

/* write data to hyperslap */
     if ( H5Dwrite( dataID, typeID, mem_spaceID, spaceID, 
		    H5P_DEFAULT, buffer ) < 0 )
	  goto done;

/* terminate access to the datatype */
     if ( H5Tclose( typeID ) < 0 ) goto done;

/* end access to the dataset */
     if ( H5Dclose( dataID ) ) goto done;

/* terminate access to the dataspace */
     if ( H5Sclose( mem_spaceID ) < 0 ) goto done;
     if ( H5Sclose( spaceID ) < 0 ) goto done;

     return 0;
 done:
     if ( typeID > 0 ) (void) H5Tclose( typeID );
     if ( spaceID > 0 ) (void) H5Sclose( spaceID );
     if ( mem_spaceID > 0 ) (void) H5Sclose( mem_spaceID );
     if ( dataID > 0 ) (void) H5Dclose( dataID );
     return -1;
}
Beispiel #8
0
VsDataset::VsDataset(VsRegistry* r, VsObject* parentObject,
                     const std::string& datasetName, hid_t id):
    VsObject(r, parentObject, datasetName, id) {

    dataType = H5Tget_native_type(H5Dget_type(id), H5T_DIR_DEFAULT);
    loadDims();

    registry->add(this);
}
Beispiel #9
0
hdf5dataset::hdf5dataset(hdf5file& hfile, const std::string& pname) : _hfile(hfile), _name(pname)
{
	_dataset_id = H5Dopen(_hfile.handle(), _name.c_str(), H5P_DEFAULT);
	if(_dataset_id < 0)
		throw std::runtime_error("Failed to open dataset (" + _hfile.filename() + ") in file (" + _name + ")");

	_type_id = H5Dget_type(_dataset_id);
	_own_type_id = true;
}
Beispiel #10
0
//--------------------------------------------------------------------------
// Function:	IntType overloaded constructor
///\brief	Gets the integer datatype of the specified dataset.
///\param	dataset - IN: Dataset that this integer datatype associates with
///\exception	H5::DataTypeIException
// Programmer	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
IntType::IntType( const DataSet& dataset ) : AtomType()
{
   // Calls C function H5Dget_type to get the id of the datatype
   id = H5Dget_type( dataset.getId() );

   if( id < 0 )
   {
      throw DataSetIException("IntType constructor", "H5Dget_type failed");
   }
}
Beispiel #11
0
H5Type & H5Dataset::getDataType()
{
    hid_t type = H5Dget_type(dataset);
    if (type < 0)
    {
        throw H5Exception(__LINE__, __FILE__, _("Cannot get the dataspace associated with dataset named %s."), name.c_str());
    }

    return *new H5Type(*this, type);
}
Beispiel #12
0
/*--------------------------------------------------------------*/
static void validateDependsOn(pNXVcontext self, hid_t groupID,
	hid_t fieldID)
{
	char fname[512], dpData[1024];
	hid_t h5type, dpfieldID;
	H5T_class_t h5class;

	memset(fname,0,sizeof(fname));
	memset(dpData,0,sizeof(dpData));
	H5Iget_name(fieldID,fname,sizeof(fname));
	NXVsetLog(self,"dataPath",fname);
	NXVsetLog(self,"sev","debug");
	NXVprintLog(self,"message","Validating depends_on chain starting at %s",
						fname);
	NXVlog(self);

	/*
		test that the depends_on field is of the right type
	*/
	h5type = H5Dget_type(fieldID);
	h5class = H5Tget_class(h5type);
	H5Tclose(h5type);
	if(h5class != H5T_STRING){
			NXVsetLog(self,"sev","error");
			NXVsetLog(self,"message",
			"depends_on field is of wrong type, expect string");
			NXVlog(self);
			self->errCount++;
			return;
	}

	/*
		read the field
	*/
	H5LTread_dataset_string(groupID,"depends_on",dpData);

	/*
		find the field and start iterating through the chain
	*/

	dpfieldID = findDependentField(self,fieldID,dpData);
	if(dpfieldID < 0){
		NXVsetLog(self,"sev","error");
		NXVprintLog(self,"message",
		"Cannot even find the starting point of the depends_on chain, %s",
		dpData);
		NXVlog(self);
		self->errCount++;
		return;
	} else {
		validateDependsOnField(self,groupID,dpfieldID);
		H5Dclose(dpfieldID);
	}

}
Beispiel #13
0
//--------------------------------------------------------------------------
// Function:	CompType overloaded constructor
///\brief	Gets the compound datatype of the specified dataset.
///\param	dataset - IN: Dataset that this enum datatype associates with
///\return	CompType instance
///\exception	H5::DataTypeIException
// Programmer	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
CompType::CompType( const DataSet& dataset ) : DataType()
{
   // Calls C function H5Dget_type to get the id of the datatype
   id = H5Dget_type( dataset.getId() );

   // If the datatype id is invalid, throw exception
   if( id < 0 )
   {
      throw DataSetIException("CompType constructor", "H5Dget_type failed");
   }
}
Beispiel #14
0
asynStatus hdf5Driver::getFrameData (int frame, void *pData)
{
    const char *functionName = "getFrameData";
    asynStatus status = asynSuccess;

    struct dsetInfo *pDSet;
    hid_t dSpace, dType, mSpace;

    pDSet = getDatasetByFrame(frame);
    if(!pDSet)
        return asynError;

    hsize_t offset[3] = {(hsize_t)(frame - pDSet->imageNrLow), 0, 0};
    hsize_t count[3]  = {1, pDSet->height, pDSet->width};

    if((dSpace = H5Dget_space(pDSet->id)) < 0)
    {
        asynPrint(pasynUserSelf, ASYN_TRACE_ERROR,
                "%s:%s couldn't get dataspace\n",
                driverName, functionName);
        return asynError;
    }

    dType = H5Dget_type(pDSet->id);

    mSpace = H5Screate_simple(3, count, NULL);

    // Select the hyperslab
    if(H5Sselect_hyperslab(dSpace, H5S_SELECT_SET, offset, NULL, count,
            NULL) < 0)
    {
        asynPrint(pasynUserSelf, ASYN_TRACE_ERROR,
                "%s:%s couldn't select hyperslab\n",
                driverName, functionName);
        status = asynError;
        goto end;
    }

    // and finally read the image
    if(H5Dread(pDSet->id, dType, mSpace, dSpace, H5P_DEFAULT, pData) < 0)
    {
        asynPrint(pasynUserSelf, ASYN_TRACE_ERROR,
                "%s:%s couldn't read image\n",
                driverName, functionName);
        status = asynError;
    }

end:
    H5Tclose(dType);
    H5Sclose(mSpace);
    return status;
}
Beispiel #15
0
void Fast5Files::getFastq(hid_t dataset){
	hid_t dt;
	size_t size;
	char *data;

	dt   = H5Dget_type(dataset);
	size = H5Tget_size(dt);
	data = (char*)malloc(size);
	H5Dread(dataset, H5T_C_S1, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
	qDebug() << data;
	free(data);
	H5Dclose(dataset);
}
Beispiel #16
0
void PWParameterSet::checkVersion(hid_t h)
{
  if(is_manager())
  {
    hid_t dataset=H5Dopen(h,"version");
    hid_t datatype=H5Dget_type(dataset);
    H5T_class_t classtype = H5Tget_class(datatype);
    H5Tclose(datatype);
    H5Dclose(dataset);
    if(classtype == H5T_INTEGER)
    {
      HDFAttribIO<TinyVector<int,2> > hdfver(version);
      hdfver.read(h,"version");
    }
    else
      if(classtype == H5T_FLOAT)
      {
        TinyVector<double,2> vt;
        HDFAttribIO<TinyVector<double,2> > hdfver(vt);
        hdfver.read(h,"version");
        version[0]=int(vt[0]);
        version[1]=int(vt[1]);
      }
    //else
    //{
    //  APP_ABORT("PWParameterSet::checkVersion  The type of version is not integer or double.");
    //}
  }
  myComm->bcast(version);
  app_log() << "\tWavefunction HDF version: " << version[0] << "." << version[1] << endl;
  if(version[0] == 0)
  {
    if(version[1] == 11)
    {
      hasSpin=false;
      paramTag="parameters_0";
      basisTag="basis_1";
      pwTag="planewaves";
      pwMultTag="multipliers";
      eigTag="eigenstates_3";
      twistTag="twist_";
      bandTag="band_";
    }
    else
      if(version[1] == 10)
      {
        pwMultTag="planewaves";
        pwTag="0";
      }
  }
}
Beispiel #17
0
static int try_read_string(hid_t loc, char * name, char ** dest){
  if(H5Lexists(loc,name,H5P_DEFAULT)){
    hid_t ds = H5Dopen(loc,name,H5P_DEFAULT);
    hid_t t = H5Dget_type(ds);
    if(H5Tget_class(t) == H5T_STRING){
      *dest = malloc(sizeof(char)*H5Tget_size(t));
      H5Dread(ds,t,H5S_ALL,H5S_ALL,H5P_DEFAULT,*dest);
    }
    H5Tclose(t);
    H5Dclose(ds);
    return 1;
  }  
  return 0;
}
Beispiel #18
0
static int try_read_float_array(hid_t loc, char * name, double * dest, int size){
  if(H5Lexists(loc,name,H5P_DEFAULT)){
    hid_t ds = H5Dopen(loc,name,H5P_DEFAULT);
    hid_t t = H5Dget_type(ds);
    hid_t s = H5Dget_space(ds);
    if(H5Tget_class(t) == H5T_FLOAT &&  array_total_size(ds) == size){
      H5Dread(ds,H5T_NATIVE_DOUBLE,H5S_ALL,H5S_ALL,H5P_DEFAULT,dest);
    }
    H5Tclose(t);
    H5Sclose(s);
    H5Dclose(ds);
    return 1;
  }  
  return 0;
}
Beispiel #19
0
static int try_read_int(hid_t loc, char * name, int * dest){
  if(H5Lexists(loc,name,H5P_DEFAULT)){
    hid_t ds = H5Dopen(loc,name,H5P_DEFAULT);
    hid_t t = H5Dget_type(ds);
    hid_t s = H5Dget_space(ds);
    if(H5Tget_class(t) == H5T_INTEGER && is_scalar(ds)){
      H5Dread(ds,H5T_NATIVE_INT32,H5S_ALL,H5S_ALL,H5P_DEFAULT,dest);
    }
    H5Tclose(t);
    H5Sclose(s);
    H5Dclose(ds);
    return 1;
  }  
  return 0;
}
Beispiel #20
0
    bool DCDataSet::open(hid_t group)
    throw (DCException)
    {
        if (checkExistence && !H5Lexists(group, name.c_str(), H5P_LINK_ACCESS_DEFAULT))
            return false;

        dataset = H5Dopen(group, name.c_str(), H5P_DATASET_ACCESS_DEFAULT);

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

        datatype = H5Dget_type(dataset);
        if (datatype < 0)
        {
            H5Dclose(dataset);
            throw DCException(getExceptionString("open: Failed to get type of dataset"));
        }

        dataspace = H5Dget_space(dataset);
        if (dataspace < 0)
        {
            H5Dclose(dataset);
            throw DCException(getExceptionString("open: Failed to open dataspace"));
        }

        int dims_result = H5Sget_simple_extent_ndims(dataspace);
        if (dims_result < 0)
        {
            close();
            throw DCException(getExceptionString("open: Failed to get dimensions"));
        }

        ndims = dims_result;

        getLogicalSize().set(1, 1, 1);
        if (H5Sget_simple_extent_dims(dataspace, getLogicalSize().getPointer(), NULL) < 0)
        {
            close();
            throw DCException(getExceptionString("open: Failed to get sizes"));
        }

        getLogicalSize().swapDims(ndims);

        opened = true;

        return true;
    }
Beispiel #21
0
int_f
h5dget_type_c ( hid_t_f *dset_id , hid_t_f *type_id)
/******/
{
  int ret_value = -1;
  hid_t c_dset_id;
  hid_t c_type_id;

  c_dset_id = (hid_t)*dset_id;
  c_type_id = H5Dget_type(c_dset_id);

  if(c_type_id < 0 ) return ret_value;

  *type_id = (hid_t_f)c_type_id;
  ret_value = 0;
  return ret_value;
}
/*
 * - Name : _MEDdatasetRead
 * - Description : writes a HDF dataset
 * - Parameters :
 *     - id  (IN)     : dataset ID
 *     - val  (OUT)    : datset values
 * - Result : 
 *     - if success : 0
 *     - if failure : -1
 */ 
hdf_err HDFdatasetRead(hdf_idt id, void *val)
{
  hdf_idt datatype;
  hdf_err ret;

  if ((datatype = H5Dget_type(id)) < 0)
    return -1;

//#if defined (PCLINUX) || defined (PCLINUX64)
  if ((H5Tget_class(datatype) == H5T_INTEGER) && (H5Tget_size(datatype) == 4)) 
    datatype = H5T_NATIVE_INT;
//#endif 

  if ((ret = H5Dread(id,datatype,H5S_ALL,H5S_ALL,H5P_DEFAULT, val)) < 0)
    return -1;

  return 0;
}
Beispiel #23
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 */
hdf5_datatype::hdf5_datatype(hdf5_dataset const& dataset)
    :
      hdf5_object(H5Dget_type(dataset.get_id())),
      type_class_(H5Tget_class(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_datatype_access_error
            )
        );
    }
}
Beispiel #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;
}
Beispiel #26
0
/*+++++++++++++++++++++++++ Main Program or Function +++++++++++++++*/
int IDL_STDCALL _SDMF_RD_PT_CLUSDEF( int argc, void *argv[] )
{
     IDL_STRING         *dbName;
     struct clusdef_rec *ClusDef;

     hid_t  fid = -1;
     hid_t  data_id = -1;
     hid_t  type_id = -1;
/*
 * check number of parameters
 */
     if ( argc != 2 ) NADC_GOTO_ERROR( NADC_ERR_PARAM, err_msg );
     dbName   = (IDL_STRING *) argv[0];
     ClusDef  = (struct clusdef_rec *) argv[1];

     fid = H5Fopen( dbName->s, H5F_ACC_RDONLY, H5P_DEFAULT );
     if ( fid < 0 ) NADC_GOTO_ERROR( NADC_ERR_HDF_FILE, dbName->s );
     
     if ( (data_id = H5Dopen( fid, "ClusDef", H5P_DEFAULT )) < 0 )
	  NADC_GOTO_ERROR( NADC_ERR_HDF_DATA, "ClusDef" );

     if ( (type_id = H5Dget_type( data_id )) < 0 )
	  NADC_GOTO_ERROR( NADC_ERR_HDF_DTYPE, "ClusDef" );

     if ( H5LTread_dataset( fid, "ClusDef", type_id, ClusDef ) < 0 )
	  NADC_GOTO_ERROR( NADC_ERR_HDF_RD, "ClusDef" );

     (void) H5Tclose( type_id );
     (void) H5Dclose( data_id );
     (void) H5Fclose( fid );
     return 1;
 done:
     H5E_BEGIN_TRY {
	  (void) H5Tclose( type_id );
	  (void) H5Dclose( data_id );
	  (void) H5Fclose( fid );
     } H5E_END_TRY;
     return -1;
}
Beispiel #27
0
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;
}
Beispiel #28
0
void print_trial_info(hid_t trial,int num_trial) {

    char string_data[512];
    hid_t string_type = H5Tcopy(H5T_C_S1);
    size_t string_size = 512;
    H5Tset_size(string_type,string_size);

    printf("Trial #%d\n",num_trial);

    hid_t data = H5Dopen(trial,"Date",H5P_DEFAULT);
    H5Dread(data,string_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,string_data);
    H5Dclose(data);

    printf("\tDate: %s\n",string_data);

    data = H5Dopen(trial,"Synchronous Data/Channel Data",H5P_DEFAULT);
    hsize_t nchans = H5Tget_size(H5Dget_type(data))/sizeof(double);
    H5Dclose(data);

    data = H5PTopen(trial,"Synchronous Data/Channel Data");
    hsize_t nsamples;
    H5PTget_num_packets(data,&nsamples);

    printf("\t%llu Channels X %llu samples\n",nchans,nsamples);

    for(int i=1;i<=nchans;++i) {
        std::stringstream channel_name;
        channel_name << "Synchronous Data/Channel "  << i << " Name";
        data = H5Dopen(trial,channel_name.str().c_str(),H5P_DEFAULT);
        H5Dread(data,string_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,string_data);
        H5Dclose(data);

        printf("\t\t#%d: %s\n",i,string_data);
    }

    printf("\n");
}
Beispiel #29
0
int main(void)
{
    hid_t	file_id, prop_id, memspace_id, type_id;
    hid_t	group_id;
    hid_t	dataset_id, dataspace_id;
    herr_t	status;
    hsize_t	dims[1];
    hsize_t	maxdims[1];
    float	data[NPOINTS];
    float	floatval;
    unsigned	numdataobj	= 0;
    unsigned	i, j;
    char	name[80];
    hsize_t	start[1]			= {0};
    hsize_t	stride[1]			= {1};
    hsize_t	count[1]			= {1};

    /* Create a file */
    file_id = H5Fcreate(FILEN, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

    /* Create a dataset to hold the number of data objects */
    /* Create the data space */
    dataspace_id = H5Screate(H5S_SCALAR);

    /* Create dataset */
    dataset_id = H5Dcreate2(file_id, "/NumDataObj",
                                    H5T_NATIVE_UINT, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    /* Write value to NumDataObj dataset */
    status = H5Dwrite(dataset_id, H5T_NATIVE_UINT, H5S_ALL,
            H5S_ALL, H5P_DEFAULT, &numdataobj);

    /* Close the identifiers */
    status = H5Dclose(dataset_id);
    status = H5Sclose(dataspace_id);

    /* Create extendible arrays */
    /* Set up for extendible dataset */
    prop_id = H5Pcreate(H5P_DATASET_CREATE);
    dims[0] = CHUNK_SIZE;
    status = H5Pset_chunk(prop_id, 1, dims);

    /* Create dataspace */
    dims[0]=1;
    maxdims[0]=H5S_UNLIMITED;
    dataspace_id = H5Screate_simple(1, dims, maxdims);

    for(i=0; i<NEXTARRAYS; i++)
    {
        /* Create dataset */
        sprintf(name, "/ExtArray%06d", i);
        dataset_id = H5Dcreate2(file_id, name,
                H5T_NATIVE_FLOAT, dataspace_id, H5P_DEFAULT, prop_id, H5P_DEFAULT);

        /* Close the identifier */
        status = H5Dclose(dataset_id);
    }

    /* Close the identifiers */
    status = H5Sclose(dataspace_id);
    status = H5Pclose(prop_id);

    /* Create group to hold data object data arrays */
    group_id = H5Gcreate2(file_id, "/DataArray", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    H5Gclose(group_id);

    for(j=0; j<NDATAOBJECTS; j++)
    {
        printf("\rWriting Object #%d of %d", j+1, NDATAOBJECTS);
        fflush(stdout);

        floatval = (float)j;

        /* Create group to hold data arrays for this object */
        sprintf(name, "/DataArray/%06d", j);
        group_id = H5Gcreate2(file_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
        if(group_id < 0) {
            fprintf(stderr, "Failed to create DataArray group.\n");
            status = H5Fclose(file_id);
            return -1;
        }

        /* Loop over data arrays */
        for(i=0; i<NDATAARRAYS; i++)
        {
            /* Create dataspace */
            dims[0]=NPOINTS;
            maxdims[0]=NPOINTS;
            dataspace_id = H5Screate_simple(1 ,dims, maxdims);

            /* Create dataset */
            sprintf(name, "DataArray%06d", i);
            dataset_id = H5Dcreate2(group_id, name,
                    H5T_NATIVE_FLOAT, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
            if(dataset_id < 0) {
                fprintf(stderr, "Failed to create DataArray dataset.\n");
                status = H5Fclose(file_id);
                return -1;
            }

            /* Write the data array data */
            status = H5Dwrite(dataset_id, H5T_NATIVE_FLOAT, H5S_ALL,
                    H5S_ALL, H5P_DEFAULT, data);
            if(status < 0) {
                fprintf(stderr, "Failed to write DataArray dataset.\n");
                status = H5Fclose(file_id);
                return -1;
            }

            /* Close the identifiers */
            status = H5Dclose(dataset_id);
            status = H5Sclose(dataspace_id);
        }

        /* Open NumDataObj dataset */
        dataset_id = H5Dopen2(file_id, "/NumDataObj", H5P_DEFAULT);
        if(dataset_id < 0) {
            fprintf(stderr, "Failed to open NumDataObj dataset.\n");
            status = H5Fclose(file_id);
            return -1;
        }

        /* Write value to NumDataObj dataset */
        numdataobj = j + 1;
        status = H5Dwrite(dataset_id, H5T_NATIVE_UINT, H5S_ALL,
                H5S_ALL, H5P_DEFAULT, &numdataobj);
        if(status < 0) {
            fprintf(stderr, "Failed to write NumDataObj dataset.\n");
            status = H5Fclose(file_id);
            return -1;
        }

        /* Close identifiers */
        status = H5Dclose(dataset_id);
        status = H5Gclose(group_id);

        /* Extend attribute arrays */
        for(i = 0; i < NEXTARRAYS; i++) {
            /* Open extendable dataset */
            sprintf(name, "/ExtArray%06d", i);
            dataset_id = H5Dopen2(file_id, name, H5P_DEFAULT);
            if(dataset_id < 0) {
                fprintf(stderr, "Failed to open ExtArray dataset.\n");
                status = H5Fclose(file_id);
                return -1;
            } /* end if */

            /* Extend attribute dataset */
            dims[0] = (hsize_t)j + 1;
            status = H5Dset_extent(dataset_id, dims);
            if(status < 0) {
                fprintf(stderr, "Failed to extend DataArray dataset.\n");
                status = H5Fclose(file_id);
                return -1;
            } /* end if */

            /* Select element and write value to attribute dataset */
            dims[0] = 1;
            memspace_id = H5Screate_simple(1, dims, dims);
            dataspace_id = H5Dget_space(dataset_id);
            type_id = H5Dget_type(dataset_id);

            start[0] = 0;
            status = H5Sselect_hyperslab(memspace_id, H5S_SELECT_SET,
                    start, stride, count, NULL);
            start[0] = (hssize_t)j;
            status = H5Sselect_hyperslab(dataspace_id, H5S_SELECT_SET,
                    start, stride, count, NULL);
            status = H5Dwrite(dataset_id, type_id, memspace_id,
                    dataspace_id, H5P_DEFAULT, &floatval);
            if(status < 0)
            {
                fprintf(stderr, "Failed to write DataArray dataset.\n");
                status = H5Fclose(file_id);
                return -1;
            }

            /* Close identifiers */
            status = H5Tclose(type_id);
            status = H5Sclose(dataspace_id);
            status = H5Sclose(memspace_id);
            status = H5Dclose(dataset_id);
        }
    }


    /* Close the file */
    status = H5Fclose(file_id);

    printf("\n");

    return 0;
}
Beispiel #30
0
int do_copy_refobjs(hid_t fidin,
                    hid_t fidout,
                    trav_table_t *travt,
                    pack_opt_t *options) /* repack options */
{
    hid_t     grp_in=(-1);            /* read group ID */
    hid_t     grp_out=(-1);           /* write group ID */
    hid_t     dset_in=(-1);           /* read dataset ID */
    hid_t     dset_out=(-1);          /* write dataset ID */
    hid_t     type_in=(-1);           /* named type ID */
    hid_t     dcpl_id=(-1);           /* dataset creation property list ID */
    hid_t     space_id=(-1);          /* space ID */
    hid_t     ftype_id=(-1);          /* file data type ID */
    hid_t     mtype_id=(-1);          /* memory data type ID */
    size_t    msize;                  /* memory size of memory type */
    hsize_t   nelmts;                 /* number of elements in dataset */
    int       rank;                   /* rank of dataset */
    hsize_t   dims[H5S_MAX_RANK];     /* dimensions of dataset */
    unsigned int i, j;
    int       k;
    
    /*-------------------------------------------------------------------------
    * browse
    *-------------------------------------------------------------------------
    */
    
    for ( i = 0; i < travt->nobjs; i++)
    {
        switch ( travt->objs[i].type )
        {
        /*-------------------------------------------------------------------------
        * H5G_GROUP
        *-------------------------------------------------------------------------
        */
        case H5G_GROUP:
            
        /*-------------------------------------------------------------------------
        * copy referenced objects in attributes
        *-------------------------------------------------------------------------
        */
            
            if ((grp_out=H5Gopen(fidout,travt->objs[i].name))<0)
                goto error;
            if((grp_in = H5Gopen (fidin,travt->objs[i].name))<0)
                goto error;
            if (copy_refs_attr(grp_in,grp_out,options,travt,fidout)<0)
                goto error;
            if (H5Gclose(grp_out)<0)
                goto error;
            if (H5Gclose(grp_in)<0)
                goto error;
            
           /*-------------------------------------------------------------------------
            * check for hard links
            *-------------------------------------------------------------------------
            */
            
            if (travt->objs[i].nlinks)
            {
                for ( j=0; j<travt->objs[i].nlinks; j++)
                {
                    H5Glink(fidout,
                        H5G_LINK_HARD,
                        travt->objs[i].name,
                        travt->objs[i].links[j].new_name);
                }
            }
            
            break;
            
       /*-------------------------------------------------------------------------
       * H5G_DATASET
       *-------------------------------------------------------------------------
       */
        case H5G_DATASET:
            
            if ((dset_in=H5Dopen(fidin,travt->objs[i].name))<0)
                goto error;
            if ((space_id=H5Dget_space(dset_in))<0)
                goto error;
            if ((ftype_id=H5Dget_type (dset_in))<0)
                goto error;
            if ((dcpl_id=H5Dget_create_plist(dset_in))<0)
                goto error;
            if ( (rank=H5Sget_simple_extent_ndims(space_id))<0)
                goto error;
            if ( H5Sget_simple_extent_dims(space_id,dims,NULL)<0)
                goto error;
            nelmts=1;
            for (k=0; k<rank; k++)
                nelmts*=dims[k];
            
            if ((mtype_id=h5tools_get_native_type(ftype_id))<0)
                goto error;
            
            if ((msize=H5Tget_size(mtype_id))==0)
                goto error;
            
            
           /*-------------------------------------------------------------------------
           * check if the dataset creation property list has filters that
           * are not registered in the current configuration
           * 1) the external filters GZIP and SZIP might not be available
           * 2) the internal filters might be turned off
           *-------------------------------------------------------------------------
           */
            if (h5tools_canreadf((NULL),dcpl_id)==1)
            {
               /*-------------------------------------------------------------------------
                * test for a valid output dataset
                *-------------------------------------------------------------------------
                */
                dset_out = FAIL;
                
                /*-------------------------------------------------------------------------
                * object references are a special case
                * we cannot just copy the buffers, but instead we recreate the reference
                *-------------------------------------------------------------------------
                */
                if (H5Tequal(mtype_id, H5T_STD_REF_OBJ))
                {
                    H5G_obj_t1       obj_type;
                    hid_t            refobj_id;
                    hobj_ref_t       *refbuf=NULL; /* buffer for object references */
                    hobj_ref_t       *buf=NULL;
                    const char*      refname;
                    unsigned         u;
                    
                    /*-------------------------------------------------------------------------
                    * read to memory
                    *-------------------------------------------------------------------------
                    */
                    
                    if (nelmts)
                    {
                        buf=(void *) HDmalloc((unsigned)(nelmts*msize));
                        if ( buf==NULL){
                            printf( "cannot read into memory\n" );
                            goto error;
                        }
                        if (H5Dread(dset_in,mtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf)<0)
                            goto error;
                        
                        if ((obj_type = H5Rget_obj_type(dset_in,H5R_OBJECT,buf))<0)
                            goto error;
                        refbuf=HDcalloc((unsigned)nelmts,msize);
                        if ( refbuf==NULL){
                            printf( "cannot allocate memory\n" );
                            goto error;
                        }
                        for ( u=0; u<nelmts; u++)
                        {
                            H5E_BEGIN_TRY {
                                if ((refobj_id = H5Rdereference(dset_in,H5R_OBJECT,&buf[u]))<0)
                                    continue;
                            } H5E_END_TRY;
                            /* get the name. a valid name could only occur in the
                            second traversal of the file */
                            if ((refname=MapIdToName(refobj_id,travt))!=NULL)
                            {
                                /* create the reference, -1 parameter for objects */
                                if (H5Rcreate(&refbuf[u],fidout,refname,H5R_OBJECT,-1)<0)
                                    goto error;
                                if(options->verbose)
                                {
                                    
                                    
                                    printf(FORMAT_OBJ,"dset",travt->objs[i].name );
                                    printf("object <%s> object reference created to <%s>\n",
                                        travt->objs[i].name,
                                        refname);
                                }
                            }/*refname*/
                            close_obj(obj_type,refobj_id);
                        }/*  u */
                    }/*nelmts*/
                    
                     /*-------------------------------------------------------------------------
                     * create/write dataset/close
                     *-------------------------------------------------------------------------
                    */
                    if ((dset_out=H5Dcreate(fidout,travt->objs[i].name,mtype_id,space_id,dcpl_id))<0)
                        goto error;
                    if (nelmts) {
                        if (H5Dwrite(dset_out,mtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,refbuf)<0)
                            goto error;
                    }
                    
                    if (buf)
                        free(buf);
                    if (refbuf)
                        free(refbuf);
                    
                }/*H5T_STD_REF_OBJ*/
                
                 /*-------------------------------------------------------------------------
                 * dataset region references
                 *-------------------------------------------------------------------------
                */
                else if (H5Tequal(mtype_id, H5T_STD_REF_DSETREG))
                {
                    H5G_obj_t1       obj_type;
                    hid_t            refobj_id;
                    hdset_reg_ref_t  *refbuf=NULL; /* input buffer for region references */
                    hdset_reg_ref_t  *buf=NULL;    /* output buffer */
                    const char*      refname;
                    unsigned         u;
                    
                    /*-------------------------------------------------------------------------
                    * read input to memory
                    *-------------------------------------------------------------------------
                    */
                    if (nelmts)
                    {
                        buf=(void *) HDmalloc((unsigned)(nelmts*msize));
                        if ( buf==NULL){
                            printf( "cannot read into memory\n" );
                            goto error;
                        }
                        if (H5Dread(dset_in,mtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf)<0)
                            goto error;
                        if ((obj_type = H5Rget_obj_type(dset_in,H5R_DATASET_REGION,buf))<0)
                            goto error;
                        
                        /*-------------------------------------------------------------------------
                        * create output
                        *-------------------------------------------------------------------------
                        */
                        
                        refbuf=HDcalloc(sizeof(hdset_reg_ref_t),(size_t)nelmts); /*init to zero */
                        if ( refbuf==NULL){
                            printf( "cannot allocate memory\n" );
                            goto error;
                        }
                        for ( u=0; u<nelmts; u++)
                        {
                            H5E_BEGIN_TRY {
                                if ((refobj_id = H5Rdereference(dset_in,H5R_DATASET_REGION,&buf[u]))<0)
                                    continue;
                            } H5E_END_TRY;
                            
                            /* get the name. a valid name could only occur in the
                            second traversal of the file */
                            if ((refname=MapIdToName(refobj_id,travt))!=NULL)
                            {
                                hid_t region_id;    /* region id of the referenced dataset */
                                if ((region_id = H5Rget_region(dset_in,H5R_DATASET_REGION,&buf[u]))<0)
                                    goto error;
                                /* create the reference, we need the space_id */
                                if (H5Rcreate(&refbuf[u],fidout,refname,H5R_DATASET_REGION,region_id)<0)
                                    goto error;
                                if (H5Sclose(region_id)<0)
                                    goto error;
                                if(options->verbose)
                                {
                                    
                                    
                                    
                                    printf(FORMAT_OBJ,"dset",travt->objs[i].name );
                                    printf("object <%s> region reference created to <%s>\n",
                                        travt->objs[i].name,
                                        refname);
                                }
                            }/*refname*/
                            close_obj(obj_type,refobj_id);
                        }/*  u */
                    }/*nelmts*/
                    
                     /*-------------------------------------------------------------------------
                     * create/write dataset/close
                     *-------------------------------------------------------------------------
                    */
                    if ((dset_out=H5Dcreate(fidout,travt->objs[i].name,mtype_id,space_id,dcpl_id))<0)
                        goto error;
                    if (nelmts) {
                        if (H5Dwrite(dset_out,mtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,refbuf)<0)
                            goto error;
                    }
                    
                    if (buf)
                        free(buf);
                    if (refbuf)
                        free(refbuf);
                } /* H5T_STD_REF_DSETREG */
                
                
               /*-------------------------------------------------------------------------
                * not references, open previously created object in 1st traversal
                *-------------------------------------------------------------------------
                */
                else
                {
                    if ((dset_out=H5Dopen(fidout,travt->objs[i].name))<0)
                        goto error;
                }
                
                assert(dset_out!=FAIL);
                
                /*-------------------------------------------------------------------------
                * copy referenced objects in attributes
                *-------------------------------------------------------------------------
                */
                if (copy_refs_attr(dset_in,dset_out,options,travt,fidout)<0)
                    goto error;
                
                
                /*-------------------------------------------------------------------------
                * check for hard links
                *-------------------------------------------------------------------------
                */
                if (travt->objs[i].nlinks)
                {
                    for ( j=0; j<travt->objs[i].nlinks; j++){
                        H5Glink(fidout,
                            H5G_LINK_HARD,
                            travt->objs[i].name,
                            travt->objs[i].links[j].new_name);
                    }
                }
                
                if (H5Dclose(dset_out)<0)
                    goto error;
                
   }/*can_read*/