Esempio n. 1
0
inline void group::open(group const& other, std::string const& name)
{
    if (hid_ >= 0) {
        throw error("h5xx::group object is already in use");
    }

    if (exists_group(other, name)) {
        hid_ = H5Gopen(other.hid(), name.c_str(), H5P_DEFAULT);
    }
    else {
        hid_t lcpl_id = H5Pcreate(H5P_LINK_CREATE);     // create group creation property list
        H5Pset_create_intermediate_group(lcpl_id, 1);   // set intermediate link creation
        hid_ = H5Gcreate(other.hid(), name.c_str(), lcpl_id, H5P_DEFAULT, H5P_DEFAULT);
    }
    if (hid_ < 0){
        throw error("creating or opening group \"" + name + "\"");
    }
}
Esempio n. 2
0
int convertimage(struct param par) {

  int err; 

  /* if image goes into h5 container, create container and group if needed
   * before starting conversion */

  if (par.conto[0]) {

      struct stat stat_buf;
      hid_t h5fid = -1; 

      std::string patho = std::string(par.patho);
      std::string conto = std::string(par.conto);
      std::string cpath = patho + "/" + conto;

      /* create containter if it doesn't exist */
      if (stat(cpath.c_str(), &stat_buf)){
          /* it doesn't exist, create empty container. TRUNC overwrites it if exists. */
          h5fid = H5Fcreate(cpath.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
          CHKRTN(h5fid < 0, FILEERR);
      }
      else {
          /* it exists, open an existing file. */
          h5fid = H5Fopen(cpath.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
          CHKRTN(h5fid < 0, FILEERR);
      } 

      err = H5Lexists(h5fid, par.grupo, H5P_DEFAULT ); CHKRTN(err < 0, ERR);
      if (!err){
          /* create empty group */
          hid_t gid;
          gid = H5Gcreate(h5fid, par.grupo, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
          CHKRTN(gid < 0, ERR);
      }
       
      H5Fclose(h5fid);

  }

  err = convertimageh5(par); CHKERR(err);

  return EXIT_SUCCESS;  
}
Esempio n. 3
0
extern hid_t make_group(hid_t parent, const char *name)
{
    hid_t gid = -1;

    if (parent < 0) {
        debug3("PROFILE: parent is not HDF5 object");
        return -1;
    }
    gid = get_group(parent, name);
    if (gid > 0)
        return gid;
    gid = H5Gcreate(parent, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    if (gid < 0) {
        debug3("PROFILE: failed to create HDF5 group=%s", name);
        return -1;
    }

    return gid;
}
bool H5G::create(hid_t filename, const char *groupname){
        //if currently valid, close and open a new
        if(valid){
                status = H5Gclose(classID);
                if(status>=0)valid = false;
        }
        classID = H5Gcreate(filename,groupname,0
#ifndef H5_USE_16_API
                          , H5P_DEFAULT, H5P_DEFAULT
#endif
                          );
//      printf("%d\n",classID);

        if((status>=0)&&(classID>=0)){
                valid = true;
                return true;
        }
        else return false;
}
Esempio n. 5
0
File: cxi.c Progetto: cxidb/libcxi
CXI_Process_Reference * cxi_create_process(hid_t loc, CXI_Process * process){
  if(loc < 0 || !process){
    return NULL;
  }
  int n = find_max_suffix(loc, "process");
  char buffer[1024];
  sprintf(buffer,"process_%d",n+1);
  hid_t handle = H5Gcreate(loc,buffer, H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
  if(handle < 0){
    return NULL;
  }
  CXI_Process_Reference * ref = calloc(sizeof(CXI_Process_Reference),1);
  process->handle = handle;
  ref->parent_handle = loc;
  ref->group_name = malloc(sizeof(char)*(strlen(buffer)+1));
  ref->process = process;
  strcpy(ref->group_name,buffer);
  return ref;
}
Esempio n. 6
0
File: cxi.c Progetto: cxidb/libcxi
CXI_Detector_Reference * cxi_create_detector(hid_t loc, CXI_Detector * detector){
  if(loc < 0 || !detector){
    return NULL;
  }
  int n = find_max_suffix(loc, "detector");
  char buffer[1024];
  sprintf(buffer,"detector_%d",n+1);
  hid_t handle = H5Gcreate(loc,buffer, H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
  if(handle < 0){
    return NULL;
  }
  CXI_Detector_Reference * ref = calloc(sizeof(CXI_Detector_Reference),1);
  detector->handle = handle;
  ref->parent_handle = loc;
  ref->group_name = malloc(sizeof(char)*(strlen(buffer)+1));
  ref->detector = detector;
  strcpy(ref->group_name,buffer);
  if(detector->basis_vectors_valid){
    try_write_float_2D_array(handle,"basis_vectors",(double *)detector->basis_vectors,2,3);
  }
  if(detector->corner_position_valid){
    try_write_float_1D_array(handle,"corner_position",(double *)detector->corner_position,3);
  }
  if(detector->counts_per_joule_valid){
    try_write_float(handle,"counts_per_joule",detector->counts_per_joule);
  }
  if(detector->data_sum_valid){
    try_write_float(handle,"data_sum",detector->data_sum);
  }
  if(detector->description){
    try_write_string(handle,"description",detector->description);
  }
  if(detector->distance_valid){
    try_write_float(handle,"distance",detector->distance);
  }
  if(detector->x_pixel_size_valid){
    try_write_float(handle,"x_pixel_size",detector->x_pixel_size);
  }
  if(detector->y_pixel_size_valid){
    try_write_float(handle,"y_pixel_size",detector->y_pixel_size);
  }
  return ref;
}
Esempio n. 7
0
File: cxi.c Progetto: cxidb/libcxi
CXI_Attenuator_Reference * cxi_create_attenuator(hid_t loc, CXI_Attenuator * attenuator){
  if(loc < 0 || !attenuator){
    return NULL;
  }
  int n = find_max_suffix(loc, "attenuator");
  char buffer[1024];
  sprintf(buffer,"attenuator_%d",n+1);
  hid_t handle = H5Gcreate(loc,buffer, H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
  if(handle < 0){
    return NULL;
  }
  CXI_Attenuator_Reference * ref = calloc(sizeof(CXI_Attenuator_Reference),1);
  attenuator->handle = handle;
  ref->parent_handle = loc;
  ref->group_name = malloc(sizeof(char)*(strlen(buffer)+1));
  ref->attenuator = attenuator;
  strcpy(ref->group_name,buffer);
  return ref;
}
Esempio n. 8
0
/*-----------------------------------------------------------------------------
 * Audience:    Public
 * Chapter:     Callbacks 
 * Purpose:     Impliment the open callback
 *-----------------------------------------------------------------------------
 */
void *OpenHDF5File(const char *fname, const char *nsname,
                   PMPIO_iomode_t ioMode, void *userData)
{
    hid_t *retval;
    hid_t h5File = H5Fopen(fname,
                       ioMode == PMPIO_WRITE ? H5F_ACC_RDWR : H5F_ACC_RDONLY,
                       H5P_DEFAULT);
    if (h5File >= 0)
    {
        if (ioMode == PMPIO_WRITE)
        {
            user_data_t *ud = (user_data_t *) userData;
            ud->groupId = H5Gcreate(h5File, nsname, 0);
        }
        retval = (hid_t *) malloc(sizeof(hid_t));
        *retval = h5File;
    }
    return (void *) retval;
}
Esempio n. 9
0
File: cxi.c Progetto: cxidb/libcxi
CXI_Geometry_Reference * cxi_create_geometry(hid_t loc, CXI_Geometry * geometry){
  if(loc < 0 || !geometry){
    return NULL;
  }
  int n = find_max_suffix(loc, "geometry");
  char buffer[1024];
  sprintf(buffer,"geometry_%d",n+1);
  hid_t handle = H5Gcreate(loc,buffer, H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
  if(handle < 0){
    return NULL;
  }
  CXI_Geometry_Reference * ref = calloc(sizeof(CXI_Geometry_Reference),1);
  geometry->handle = handle;
  ref->parent_handle = loc;
  ref->group_name = malloc(sizeof(char)*(strlen(buffer)+1));
  ref->geometry = geometry;
  strcpy(ref->group_name,buffer);
  return ref;
}
Esempio n. 10
0
int
main(void)
{
    hid_t       file, group, gcpl;      /* Handles */
    herr_t      status;

    /*
     * Create a new file using the default properties.
     */
    file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

    /*
     * Create group creation property list and set it to allow creation
     * of intermediate groups.
     */
    gcpl = H5Pcreate (H5P_LINK_CREATE);
    status = H5Pset_create_intermediate_group (gcpl, 1);

    /*
     * Create the group /G1/G2/G3.  Note that /G1 and /G1/G2 do not
     * exist yet.  This call would cause an error if we did not use the
     * previously created property list.
     */
    group = H5Gcreate (file, "/G1/G2/G3", gcpl, H5P_DEFAULT, H5P_DEFAULT);

    /*
     * Print all the objects in the files to show that intermediate
     * groups have been created.  See h5ex_g_visit for more information
     * on how to use H5Ovisit.
     */
    printf ("Objects in the file:\n");
    status = H5Ovisit (file, H5_INDEX_NAME, H5_ITER_NATIVE, op_func, NULL);

    /*
     * Close and release resources.
     */
    status = H5Pclose (gcpl);
    status = H5Gclose (group);
    status = H5Fclose (file);

    return 0;
}
Esempio n. 11
0
bool save_quad_bc(hid_t parent_group_id, JudyArray<Boundary *> &bcs) {
	herr_t status;

	// create main group
	hid_t group_id = H5Gcreate(parent_group_id, "quad", 0);

	// count
	hid_t dataspace_id = H5Screate(H5S_SCALAR);
	hid_t attr_count = H5Acreate(group_id, "count", H5T_NATIVE_UINT32, dataspace_id, H5P_DEFAULT);
	uint count = bcs.count();
	status = H5Awrite(attr_count, H5T_NATIVE_UINT32, &count);
	H5Aclose(attr_count);

    ///
	hsize_t dims = Quad::NUM_VERTICES;
	hid_t elem_dataspace_id = H5Screate_simple(1, &dims, NULL);

	hid_t merker_dataspace_id = H5Screate(H5S_SCALAR);

    // dump vertices
    for (int i = 0; i < count; i++) {
    	char name[256];
    	sprintf(name, "%d", i);

		// the dataset
		hid_t dataset_id = H5Dcreate(group_id, name, H5T_NATIVE_UINT32, elem_dataspace_id, H5P_DEFAULT);
		status = H5Dwrite(dataset_id, H5T_NATIVE_UINT32, H5S_ALL, H5S_ALL, H5P_DEFAULT, bcs[i]->get_vertices());

		// marker
		hid_t attr_marker = H5Acreate(dataset_id, "marker", H5T_NATIVE_UINT32, dataspace_id, H5P_DEFAULT);
		uint marker = bcs[i]->get_marker();
		status = H5Awrite(attr_marker, H5T_NATIVE_UINT32, &marker);
		H5Aclose(attr_marker);

		status = H5Dclose(dataset_id);
    }

    H5Sclose(elem_dataspace_id);
    H5Sclose(dataspace_id);

	status = H5Gclose(group_id);		// close the group
}
Esempio n. 12
0
void H5Group::createGroup(H5Object & parent, const int size, const char ** names)
{
    hid_t obj;
    hid_t loc = parent.getH5Id();

    for (unsigned int i = 0; i < (unsigned int)size; i++)
    {
        if (H5Lexists(loc, names[i], H5P_DEFAULT) > 0)
        {
            throw H5Exception(__LINE__, __FILE__, _("The group already exists: %s."), names[i]);
        }

        obj = H5Gcreate(loc, names[i], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
        if (obj < 0)
        {
            throw H5Exception(__LINE__, __FILE__, _("Cannot create the group: %s."), names[i]);
        }
        H5Gclose(obj);
    }
}
Esempio n. 13
0
File: cxi.c Progetto: cxidb/libcxi
CXI_Instrument_Reference * cxi_create_instrument(hid_t loc, CXI_Instrument * instrument){
  if(loc < 0 || !instrument){
    return NULL;
  }
  int n = find_max_suffix(loc, "instrument");
  char buffer[1024];
  sprintf(buffer,"instrument_%d",n+1);
  hid_t handle = H5Gcreate(loc,buffer, H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
  if(handle < 0){
    return NULL;
  }
  CXI_Instrument_Reference * ref = calloc(sizeof(CXI_Instrument_Reference),1);
  instrument->handle = handle;
  ref->parent_handle = loc;
  ref->group_name = malloc(sizeof(char)*(strlen(buffer)+1));
  ref->instrument = instrument;
  strcpy(ref->group_name,buffer);
  return ref;

}
Esempio n. 14
0
File: cxi.c Progetto: cxidb/libcxi
CXI_Data_Reference * cxi_create_data(hid_t loc, CXI_Data * data){
  if(loc < 0 || !data){
    return NULL;
  }
  int n = find_max_suffix(loc, "data");
  char buffer[1024];
  sprintf(buffer,"data_%d",n+1);
  hid_t handle = H5Gcreate(loc,buffer, H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
  if(handle < 0){
    return NULL;
  }
  CXI_Data_Reference * ref = calloc(sizeof(CXI_Data_Reference),1);
  data->handle = handle;
  ref->parent_handle = loc;
  ref->group_name = malloc(sizeof(char)*(strlen(buffer)+1));
  ref->data = data;
  strcpy(ref->group_name,buffer);
  return ref;

}
Esempio n. 15
0
static int
make_hdf_group( const char* path, hid_t file, size_t sz, mhdf_Status* status )
{
#if defined(H5Gcreate_vers) && H5Gcreate_vers > 1
  hid_t handle = H5Gcreate2( file, path, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT );
    /* empty statement to avoid compiler warning */
  if (sz) {}
#else
  hid_t handle = H5Gcreate( file, path, sz );
#endif
  if (handle < 0)
  {
    mhdf_setFail( status, "Failed to create \"%s\" group.", path );
    return 0;
  }
  else
  {
    H5Gclose( handle );
    return 1;
  }
}
Esempio n. 16
0
void Particle_source::write_to_file( hid_t group_id )
{
    std::cout << "Source name = " << name << ", "
	      << "number of particles = " << particles.size()
	      << std::endl;
    hid_t current_source_group_id;
    herr_t status;
    std::string table_of_particles_name = name;

    current_source_group_id = H5Gcreate( group_id,
					 ( "./" + table_of_particles_name ).c_str(),
					 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    hdf5_status_check( current_source_group_id );

    write_hdf5_particles( current_source_group_id );
    write_hdf5_source_parameters( current_source_group_id );

    status = H5Gclose( current_source_group_id );
    hdf5_status_check( status );
    
    return;
}
Esempio n. 17
0
File: e5.c Progetto: voidcycles/void
eid_t
e5_create_group(
    eid_t e5_group_id, const char* group_name)
{
    hid_t e5_sub_group_id;
    char* e5_group_name = (char*)e5_malloc(E5_MAX_GROUP_NAME_LENGTH+1);
    e5_group_name[E5_MAX_GROUP_NAME_LENGTH] = '\0';

    snprintf(e5_group_name, E5_MAX_GROUP_NAME_LENGTH, "%s", group_name);

    e5_group_name = e5_trim(e5_group_name, E5_FALSE, E5_TRUE, E5_MAX_GROUP_NAME_LENGTH);

    e5_info(e5_group_id, "Creating group '%s'\n", group_name);

    e5_sub_group_id = H5Gcreate(e5_group_id, e5_group_name, H5P_DEFAULT);

    e5_info(e5_group_id, "Created group '%p'\n", e5_sub_group_id);

    e5_free(e5_group_name);

    return e5_sub_group_id;
}
Esempio n. 18
0
herr_t ASDF_write_provenance_data(hid_t loc_id, const char *provenance_string) {
  hsize_t dims[1] = {strlen(provenance_string)};
  hsize_t maxdims[1] = {H5S_UNLIMITED};

  hid_t array_id, group_id, space_id, dcpl_id;

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

  CHK_H5(group_id = H5Gcreate(loc_id, "Provenance",
        H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT));
  CHK_H5(array_id = H5Dcreate(group_id, "373da5fe_d424_4f44_9bca_4334d77ed10b", H5T_STD_I8LE, space_id,
	H5P_DEFAULT, dcpl_id, H5P_DEFAULT));
  CHK_H5(H5Dwrite(array_id, H5T_STD_I8LE, H5S_ALL, H5S_ALL,
	H5P_DEFAULT, provenance_string));

  CHK_H5(H5Dclose(array_id));
  CHK_H5(H5Gclose(group_id));
  CHK_H5(H5Sclose(space_id));

  return 0; // Success
}
Esempio n. 19
0
File: vecio.c Progetto: lw4992/petsc
PetscErrorCode PetscViewerHDF5OpenGroup(PetscViewer viewer, hid_t *fileId, hid_t *groupId)
{
  hid_t          file_id, group;
  htri_t         found;
  const char     *groupName = NULL;
  PetscErrorCode ierr;

  PetscFunctionBegin;
  ierr = PetscViewerHDF5GetFileId(viewer, &file_id);CHKERRQ(ierr);
  ierr = PetscViewerHDF5GetGroup(viewer, &groupName);CHKERRQ(ierr);
  /* Open group */
  if (groupName) {
    PetscBool root;

    ierr = PetscStrcmp(groupName, "/", &root);CHKERRQ(ierr);
    found = H5Lexists(file_id, groupName, H5P_DEFAULT);
    if (!root && (found <= 0)) {
#if (H5_VERS_MAJOR * 10000 + H5_VERS_MINOR * 100 + H5_VERS_RELEASE >= 10800)
      group = H5Gcreate2(file_id, groupName, 0, H5P_DEFAULT, H5P_DEFAULT);
#else /* deprecated HDF5 1.6 API */
      group = H5Gcreate(file_id, groupName, 0);
#endif
      if (group < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_LIB, "Could not create group %s", groupName);
      ierr = H5Gclose(group);CHKERRQ(ierr);
    }
#if (H5_VERS_MAJOR * 10000 + H5_VERS_MINOR * 100 + H5_VERS_RELEASE >= 10800)
    group = H5Gopen2(file_id, groupName, H5P_DEFAULT);
#else
    group = H5Gopen(file_id, groupName);
#endif
    if (group < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_LIB, "Could not open group %s", groupName);
  } else group = file_id;

  *fileId  = file_id;
  *groupId = group;
  PetscFunctionReturn(0);
}
Esempio n. 20
0
int cow_dfield_write(cow_dfield *f, char *fname)
{
#if (COW_HDF5)
#if (COW_MPI)
  if (f->domain->cart_rank == 0) {
#endif
    // -------------------------------------------------------------------------
    // The write functions assume the file is already created. Have master
    // create the file if it's not there already.
    // -------------------------------------------------------------------------
    FILE *testf = fopen(fname, "r");
    hid_t fid;
    if (testf == NULL) {
      fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
    }
    else {
      fclose(testf);
      fid = H5Fopen(fname, H5F_ACC_RDWR, H5P_DEFAULT);
    }
    if (H5Lexists(fid, f->name, H5P_DEFAULT)) {
      H5Gunlink(fid, f->name);
    }
    hid_t memb = H5Gcreate(fid, f->name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    H5Gclose(memb);
    H5Fclose(fid);
#if (COW_MPI)
  }
#endif
  clock_t start = clock();
  _io_write(f, fname);
  double sec = (double)(clock() - start) / CLOCKS_PER_SEC;
  printf("[%s] write to %s/%s took %f minutes\n", MODULE, fname, f->name,
	 sec/60.0);
  fflush(stdout);
#endif
  return 0;
}
Esempio n. 21
0
escdf_errno_t utils_hdf5_create_group(hid_t loc_id, const char *path, hid_t *group_pt)
{
    char *token, *lpath;
    hid_t group_id;

    group_id = loc_id;
    lpath = strdup(path);
    for (token = strtok(lpath, "/"); token != NULL; token = strtok(NULL, "/")) {
        if (utils_hdf5_check_present(group_id, token)) {
            group_id = H5Gopen(group_id, path, H5P_DEFAULT);
        } else {
            group_id = H5Gcreate(group_id, token, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
        }
        DEFER_TEST_ERROR(group_id >= 0, ESCDF_ERROR);
    }
    free(lpath);

    RETURN_ON_DEFERRED_ERROR

    if (group_pt != NULL)
        *group_pt = group_id;

    return ESCDF_SUCCESS;
}
Esempio n. 22
0

void
ls2_hdf5_write_inverted(const char *filename,
			const float tag_x, const float tag_y,
			const vector2 *restrict anchors, const size_t no_anchors,
			const uint64_t *restrict result,
			const uint16_t width, const uint16_t height,
			const double center_x, const double center_y)
{
    hid_t file_id, grp, dataset, dataspace, plist_id;
    hsize_t dims[2];
    hsize_t chunk_dims[2] = { width, height };

    file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
    grp = H5Gcreate(file_id, "/Result", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    ls2_hdf_write_anchors(file_id, anchors, no_anchors);

    dims[0] = 2;
    dims[1] = 1;
    dataspace = H5Screate_simple(2, dims, NULL);
    dataset = H5Dcreate(file_id, "/Tag", H5T_NATIVE_FLOAT,
                        dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    float tag[2] = {tag_x, tag_y};
    H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, tag);
    H5Sclose(dataspace);
    H5Dclose(dataset);

    dims[0] = 2;
    dims[1] = 1;
Esempio n. 23
0
int main(int argc, char *argv[])
{
  hid_t fid           = -1;
  hid_t access_plist  = -1;
  hid_t create_plist  = -1;
  hid_t cparm         = -1;
  hid_t datatype      = -1;
  hid_t dataspace     = -1;
  hid_t dataset       = -1;
  hid_t memspace      = -1;
  hid_t groupDetector = -1;
  int rank = 1;
  hsize_t chunk[2] = {10,10};
  hsize_t dims[2] = {1,1};
  hsize_t elementSize[2] = {1,1};
  hsize_t maxdims[2] = {H5S_UNLIMITED,H5S_UNLIMITED};
  int ivalue[2];
  int fillValue = 0;
  
  /* Open the source file and dataset */
  /* All SWMR files need to use the latest file format */
  access_plist = H5Pcreate(H5P_FILE_ACCESS);
  H5Pset_fclose_degree(access_plist, H5F_CLOSE_STRONG);
#if H5_VERSION_GE(1,9,178)
  H5Pset_object_flush_cb(access_plist, cFlushCallback, NULL);
#endif
  H5Pset_libver_bounds(access_plist, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);
  create_plist = H5Pcreate(H5P_FILE_CREATE);
  fid = H5Fcreate("test_string_swmr.h5", H5F_ACC_TRUNC, create_plist, access_plist);

  /* Data */
  rank = 2;
  dims[0] = 10;
  dims[1] = 10;
  dataspace = H5Screate_simple(rank, dims, dims);
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_chunk(cparm, rank, chunk);
  datatype = H5Tcopy(H5T_NATIVE_INT8);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  groupDetector = H5Gcreate(fid, "detector", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

  access_plist = H5Pcreate(H5P_DATASET_ACCESS);
  H5Pset_chunk_cache(access_plist, 503, 100, 1.0);
  dataset = H5Dcreate2(groupDetector, "data1",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, access_plist);
  ivalue[0] = 1;
  ivalue[1] = 1;
  writeInt32Attribute(dataset, "NDArrayDimBinning", 2, ivalue);
  ivalue[0] = 0;
  ivalue[1] = 0;
  writeInt32Attribute(dataset, "NDArrayDimOffset", 2, ivalue);
  writeInt32Attribute(dataset, "NDArrayDimReverse", 2, ivalue);
  ivalue[0] = 2;
  writeInt32Attribute(dataset, "NDArrayNumDims", 1, ivalue);
  H5Gclose(groupDetector);

  dims[0] = 1;
  dims[1] = 1;
  chunk[0] = 1;
  rank = 1;

  /* Unique ID */
  datatype = H5T_NATIVE_INT32;
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "NDArrayUniqueId",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  memspace = H5Screate_simple(rank, elementSize, NULL);
  writeStringAttribute(dataset, "NDAttrName",        "NDArrayUniqueId");
  writeStringAttribute(dataset, "NDAttrDescription", "The unique ID of the NDArray");
  writeStringAttribute(dataset, "NDAttrSourceType",  "NDAttrSourceDriver");
  writeStringAttribute(dataset, "NDAttrSource",      "Driver");

  /* EPICS Timestemp */
  datatype = H5T_NATIVE_DOUBLE;
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "NDArrayTimeStamp",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  memspace = H5Screate_simple(rank, elementSize, NULL);
  writeStringAttribute(dataset, "NDAttrName",        "NDArrayTimeStamp");
  writeStringAttribute(dataset, "NDAttrDescription", "The timestamp of the NDArray as float64");
  writeStringAttribute(dataset, "NDAttrSourceType",  "NDAttrSourceDriver");
  writeStringAttribute(dataset, "NDAttrSource",      "Driver");

  /* EPICS TS sec */
  datatype = H5T_NATIVE_UINT32;
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "NDArrayEpicsTSSec",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  memspace = H5Screate_simple(rank, elementSize, NULL);
  writeStringAttribute(dataset, "NDAttrName",        "NDArrayEpicsTSSec");
  writeStringAttribute(dataset, "NDAttrDescription", "The NDArray EPICS timestamp seconds past epoch");
  writeStringAttribute(dataset, "NDAttrSourceType",  "NDAttrSourceDriver");
  writeStringAttribute(dataset, "NDAttrSource",      "Driver");

  /* EPICS TS nsec */
  datatype = H5T_NATIVE_UINT32;
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "NDArrayEpicsTSnSec",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  memspace = H5Screate_simple(rank, elementSize, NULL);
  writeStringAttribute(dataset, "NDAttrName",        "NDArrayEpicsTSnSec");
  writeStringAttribute(dataset, "NDAttrDescription", "The NDArray EPICS timestamp nanoseconds");
  writeStringAttribute(dataset, "NDAttrSourceType",  "NDAttrSourceDriver");
  writeStringAttribute(dataset, "NDAttrSource",      "Driver");
 
  /* Color mode */
  datatype = H5T_NATIVE_INT32;
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "ColorMode",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  memspace = H5Screate_simple(rank, elementSize, NULL);
  writeStringAttribute(dataset, "NDAttrName",        "ColorMode");
  writeStringAttribute(dataset, "NDAttrDescription", "Color mode");
  writeStringAttribute(dataset, "NDAttrSourceType",  "NDAttrSourceDriver");
  writeStringAttribute(dataset, "NDAttrSource",      "Driver");

  /* Camera manufacturer */
  datatype = H5Tcopy(H5T_C_S1);
  H5Tset_size(datatype, 256);
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "CameraManufacturer",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  memspace = H5Screate_simple(rank, elementSize, NULL);
  writeStringAttribute(dataset, "NDAttrName",        "CameraManufacturer");
  writeStringAttribute(dataset, "NDAttrDescription", "Camera manufacturer");
  writeStringAttribute(dataset, "NDAttrSourceType",  "NDAttrSourceParam");
  writeStringAttribute(dataset, "NDAttrSource",      "MANUFACTURER");

  /* Performance data */
  rank = 2;
  dims[0] = 1;
  dims[1] = 5;
  chunk[1] = 5;
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "timestamp",
                       H5T_NATIVE_DOUBLE, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  if (!H5Iis_valid(dataset)) {
    printf("Error writing performance dataset");
  }
  H5Sclose(dataspace);

#if H5_VERSION_GE(1,9,178)
  H5Fstart_swmr_write(fid);
#endif
  
  H5Fclose(fid);

  return 0;

} /* end main */
Esempio n. 24
0
/*-------------------------------------------------------------------------
 * Function:    toomany
 *
 * Purpose:     Build a file with too many symbolic links
 *
 * Return:      Success:        0
 *
 *              Failure:        -1
 *
 * Programmer:  Quincey Koziol
 *              Tuesday, August 9, 2005
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
toomany(hid_t fapl)
{
    hid_t		fid = (-1);     /* File ID */
    hid_t		gid = (-1);     /* Group ID */
    hid_t		gid2 = (-1);    /* Datatype ID */
    char                objname[NAME_BUF_SIZE];         /* Object name */
    ssize_t             name_len;       /* Length of object name */
    char		filename[NAME_BUF_SIZE]; 

    TESTING("too many links");

    /* Make certain test is valid */
    /* XXX: should probably make a "generic" test that creates the proper
     *          # of links based on this value - QAK
     */
    HDassert(H5G_NLINKS == 16);

    /* Create files */
    h5_fixname(FILENAME[1], fapl, filename, sizeof filename);
    if((fid=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) TEST_ERROR;

    /* Create group with short name in file (used as target for hard links) */
    if((gid=H5Gcreate (fid, "final", (size_t)0))<0) TEST_ERROR;

    /* Create chain of hard links to existing object (no limit on #) */
    if(H5Glink2(fid, "final", H5G_LINK_HARD, fid, "hard1") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard1", H5G_LINK_HARD, fid, "hard2") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard2", H5G_LINK_HARD, fid, "hard3") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard3", H5G_LINK_HARD, fid, "hard4") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard4", H5G_LINK_HARD, fid, "hard5") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard5", H5G_LINK_HARD, fid, "hard6") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard6", H5G_LINK_HARD, fid, "hard7") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard7", H5G_LINK_HARD, fid, "hard8") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard8", H5G_LINK_HARD, fid, "hard9") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard9", H5G_LINK_HARD, fid, "hard10") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard10", H5G_LINK_HARD, fid, "hard11") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard11", H5G_LINK_HARD, fid, "hard12") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard12", H5G_LINK_HARD, fid, "hard13") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard13", H5G_LINK_HARD, fid, "hard14") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard14", H5G_LINK_HARD, fid, "hard15") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard15", H5G_LINK_HARD, fid, "hard16") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard16", H5G_LINK_HARD, fid, "hard17") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard17", H5G_LINK_HARD, fid, "hard18") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard18", H5G_LINK_HARD, fid, "hard19") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard19", H5G_LINK_HARD, fid, "hard20") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard20", H5G_LINK_HARD, fid, "hard21") < 0) TEST_ERROR;

    /* Create chain of soft links to existing object (limited) */
    if(H5Glink2(fid, "final", H5G_LINK_SOFT, fid, "soft1") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft1", H5G_LINK_SOFT, fid, "soft2") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft2", H5G_LINK_SOFT, fid, "soft3") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft3", H5G_LINK_SOFT, fid, "soft4") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft4", H5G_LINK_SOFT, fid, "soft5") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft5", H5G_LINK_SOFT, fid, "soft6") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft6", H5G_LINK_SOFT, fid, "soft7") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft7", H5G_LINK_SOFT, fid, "soft8") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft8", H5G_LINK_SOFT, fid, "soft9") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft9", H5G_LINK_SOFT, fid, "soft10") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft10", H5G_LINK_SOFT, fid, "soft11") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft11", H5G_LINK_SOFT, fid, "soft12") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft12", H5G_LINK_SOFT, fid, "soft13") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft13", H5G_LINK_SOFT, fid, "soft14") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft14", H5G_LINK_SOFT, fid, "soft15") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft15", H5G_LINK_SOFT, fid, "soft16") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft16", H5G_LINK_SOFT, fid, "soft17") < 0) TEST_ERROR;

    /* Close objects */
    if(H5Gclose(gid)<0) TEST_ERROR;
    if(H5Fclose(fid)<0) TEST_ERROR;

    /* Open file */
    if((fid=H5Fopen(filename, H5F_ACC_RDWR, fapl))<0) TEST_ERROR;

    /* Open object through last hard link */
    if((gid = H5Gopen(fid, "hard21")) < 0) TEST_ERROR;

    /* Check name */
    if((name_len = H5Iget_name( gid, objname, (size_t)NAME_BUF_SIZE )) < 0) TEST_ERROR
    if(HDstrcmp(objname, "/hard21")) TEST_ERROR

    /* Create object in hard-linked group */
    if((gid2 = H5Gcreate(gid, "new_hard", (size_t)0)) < 0) TEST_ERROR

    /* Close group in hard-linked group */
    if(H5Gclose(gid2) < 0) TEST_ERROR

    /* Close hard-linked object */
    if(H5Gclose(gid) < 0) TEST_ERROR;

    /* Open object through too deep soft link */
    H5E_BEGIN_TRY {
        gid = H5Gopen(fid, "soft17");
    } H5E_END_TRY;
    if (gid >= 0) {
	H5_FAILED();
	puts("    Should have failed for sequence of too many nested links.");
	goto error;
    }

    /* Open object through lesser soft link */
    if((gid = H5Gopen(fid, "soft16")) < 0) TEST_ERROR;

    /* Check name */
    if((name_len = H5Iget_name( gid, objname, (size_t)NAME_BUF_SIZE )) < 0) TEST_ERROR
    if(HDstrcmp(objname, "/soft16")) TEST_ERROR

    /* Create object in external file */
    if((gid2 = H5Gcreate(gid, "new_soft", (size_t)0)) < 0) TEST_ERROR

    /* Close group in external file */
    if(H5Gclose(gid2) < 0) TEST_ERROR

    /* Close external object */
    if(H5Gclose(gid) < 0) TEST_ERROR;

    /* Close first file */
    if(H5Fclose(fid)<0) TEST_ERROR;

    PASSED();
    return 0;

 error:
    H5E_BEGIN_TRY {
    	H5Gclose (gid2);
    	H5Gclose (gid);
    	H5Fclose (fid);
    } H5E_END_TRY;
    return -1;
} /* end toomany() */
Esempio n. 25
0
/*-------------------------------------------------------------------------
 * Function:    new_links
 *
 * Purpose:     Build a file with assorted links for different locations.
 *
 * Return:      Success:        0
 *
 *              Failure:        -1
 *
 * Programmer:  Raymond Lu
 *              Friday, April 19, 2002
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
new_links(hid_t fapl)
{
    hid_t		file_a, file_b=(-1);
    hid_t		grp1_a=(-1), grp1_b=(-1), grp2_a=(-1), grp2_b=(-1);
    hid_t		scalar=(-1);
    hid_t		dset1=(-1), dset2=(-1);
    char		filename[NAME_BUF_SIZE];
    hsize_t             size[1] = {1};

    TESTING("H5Glink2 function");

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

    /* Create two groups in each file */
    if ((grp1_a=H5Gcreate (file_a, "grp1", (size_t)0))<0) goto error;
    if ((grp2_a=H5Gcreate (file_a, "grp2", (size_t)0))<0) goto error;
    if ((grp1_b=H5Gcreate (file_b, "grp1", (size_t)0))<0) goto error;
    if ((grp2_b=H5Gcreate (file_b, "grp2", (size_t)0))<0) goto error;

    /* Create datasets */
    if((dset1=H5Dcreate(file_a, "dataset1", H5T_NATIVE_INT, scalar,
	H5P_DEFAULT))<0) {
	goto error;
    }
    if((dset2=H5Dcreate(grp1_a, "dataset2", H5T_NATIVE_INT, scalar,
        H5P_DEFAULT))<0) {
        goto error;
    }

    /* Create links within a file.  Both of source and destination use
     * H5G_SAME_LOC.  Both hard and soft links should fail. */
    H5E_BEGIN_TRY {
        if(H5Glink2(H5G_SAME_LOC, "dataset1", H5G_LINK_HARD , H5G_SAME_LOC,
		"hard")!=FAIL) goto error;
    } H5E_END_TRY;
    H5E_BEGIN_TRY {
        if(H5Glink2(H5G_SAME_LOC, "dataset1", H5G_LINK_SOFT , H5G_SAME_LOC,
        	"soft")!=FAIL) goto error;
    } H5E_END_TRY;

    /* Create links across files.  Both hard and soft links should fail. */
    H5E_BEGIN_TRY {
        if(H5Glink2(file_a, "dataset1", H5G_LINK_HARD , file_b,
        	"hard")!=FAIL) goto error;
    } H5E_END_TRY;
    H5E_BEGIN_TRY {
        if(H5Glink2(file_a, "dataset1", H5G_LINK_SOFT, file_b, "soft")!=FAIL)
            goto error;
    } H5E_END_TRY;

    /* Create links to test H5G_SAME_LOC, H5G_LINK_HARD, H5G_LINK_SOFT. */
    if(H5Glink2(grp1_a, "dataset2", H5G_LINK_HARD , H5G_SAME_LOC,
        "hard1")<0) {
        goto error;
    }
    if(H5Glink2(H5G_SAME_LOC, "dataset2", H5G_LINK_SOFT , grp1_a,
	"soft1")<0) {
        goto error;
    }

    /* Create links to test H5G_LINK_HARD, H5G_LINK_SOFT across different
     * locations. */
    if(H5Glink2(grp1_a, "dataset2", H5G_LINK_HARD, grp2_a, "hard2")<0) {
        goto error;
    }
    if(H5Glink2(grp1_a, "/grp1/dataset2", H5G_LINK_SOFT , grp2_a, "soft2")<0) {
        goto error;
    }

    /* Close dataspace and files */
    if (H5Sclose (scalar)<0) goto error;
    if (H5Dclose(dset1)<0) goto error;
    if (H5Dclose(dset2)<0) goto error;
    if (H5Gclose (grp1_a)<0) goto error;
    if (H5Gclose (grp2_a)<0) goto error;
    if (H5Gclose (grp1_b)<0) goto error;
    if (H5Gclose (grp2_b)<0) goto error;
    if (H5Fclose (file_a)<0) goto error;
    if (H5Fclose (file_b)<0) goto error;

    PASSED();
    return 0;

 error:
    H5E_BEGIN_TRY {
    	H5Sclose (scalar);
    	H5Dclose (dset1);
    	H5Dclose (dset2);
    	H5Gclose (grp1_a);
    	H5Gclose (grp2_a);
    	H5Gclose (grp1_b);
    	H5Gclose (grp2_b);
    	H5Fclose (file_a);
    	H5Fclose (file_b);
    } H5E_END_TRY;
    return -1;
}
Esempio n. 26
0
int main (void)
{
  hid_t    file;
  hid_t    grp;
  hid_t    dataset, dataspace;
  hid_t    plist;
  
  herr_t   status;
  hsize_t  dims[2];
  hsize_t  cdims[2];
  
  int      idx_f, idx_g;
  
  /*
   * Create a file.
   */
  file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
  
  /*
   * Create a group in the file.
   */
  grp = H5Gcreate(file, "/Data", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
  
  /*
   * Create dataset "Compressed Data" in the group using absolute
   * name. Dataset creation property list is modified to use
   * GZIP compression with the compression effort set to 6.
   * Note that compression can be used only when dataset is chunked.
   */
  dims[0] = 1000;
  dims[1] = 20;
  cdims[0] = 20;
  cdims[1] = 20;
  dataspace = H5Screate_simple(RANK, dims, NULL);
  plist     = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_chunk(plist, 2, cdims);
  H5Pset_deflate( plist, 6);
  dataset = H5Dcreate(file, "/Data/Compressed_Data", H5T_NATIVE_INT,
		       dataspace, H5P_DEFAULT, plist, H5P_DEFAULT);
  /*
   * Close the first dataset .
   */
  H5Sclose(dataspace);
  H5Dclose(dataset);
  
  /*
   * Create the second dataset.
   */
  dims[0] = 500;
  dims[1] = 20;
  dataspace = H5Screate_simple(RANK, dims, NULL);
  dataset = H5Dcreate(file, "/Data/Float_Data", H5T_NATIVE_FLOAT,
		       dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
  
  /*
   *Close the second dataset and file.
   */
  H5Sclose(dataspace);
  H5Dclose(dataset);
  H5Pclose(plist);
  H5Gclose(grp);
  H5Fclose(file);
  
  /*
   * Now reopen the file and group in the file.
   */
  file = H5Fopen(H5FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT);
  grp  = H5Gopen(file, "Data", H5P_DEFAULT);
  
  /*
   * Access "Compressed_Data" dataset in the group.
   */
  dataset = H5Dopen(grp, "Compressed_Data", H5P_DEFAULT);
  if( dataset < 0) printf(" Dataset 'Compressed-Data' is not found. \n");
  printf("\"/Data/Compressed_Data\" dataset is open \n");
  
  /*
   * Close the dataset.
   */
  status = H5Dclose(dataset);
  
  /*
   * Create hard link to the Data group.
   */
  status = H5Lcreate_hard(file, "Data", H5L_SAME_LOC, "Data_new", H5P_DEFAULT, H5P_DEFAULT);
  
  /*
   * We can access "Compressed_Data" dataset using created
   * hard link "Data_new".
   */
  dataset = H5Dopen(file, "/Data_new/Compressed_Data", H5P_DEFAULT);
  if( dataset < 0) printf(" Dataset is not found. \n");
  printf("\"/Data_new/Compressed_Data\" dataset is open \n");
  
  /*
   * Close the dataset.
   */
  status = H5Dclose(dataset);
  
  
  /*
   * Use iterator to see the names of the objects in the root group.
   */
  idx_f = H5Literate(file, H5_INDEX_NAME, H5_ITER_INC, NULL, file_info, NULL);
  
  /*
   * Unlink  name "Data" and use iterator to see the names
   * of the objects in the file root direvtory.
   */
  if(H5Ldelete(file, "Data", H5P_DEFAULT) < 0)
    printf(" H5Ldelete failed \n");
  else
    printf("\"Data\" is unlinked \n");
  
  idx_f = H5Literate(file, H5_INDEX_NAME, H5_ITER_INC, NULL, file_info, NULL);
  
  /*
   * Use iterator to see the names of the objects in the group
   * /Data_new.
   */
  idx_g = H5Literate_by_name(grp, "/Data_new", H5_INDEX_NAME, H5_ITER_INC, NULL, group_info, NULL, H5P_DEFAULT);
  
  /*
   * Close the file.
   */
  
  H5Gclose(grp);
  H5Fclose(file);
  
  return 0;
}
Esempio n. 27
0
/*****************************************************************************
  This function generates attributes, groups, and datasets of many types. 

  Parameters:
            fname:	file_name.
            ngrps:	number of top level groups.
            ndsets:	number of datasets.
            attrs:	number of attributes.
            nrow:	number of rows in a dataset.
            chunk:	chunk size (single number).
            vlen:	max vlen size.
            comp:	use latest format.
            latest:	use gzip comnpression.
			
  Return:  Non-negative on success/Negative on failure
  
  Programmer:  Peter Cao <*****@*****.**>, Jan. 2013
 ****************************************************************************/
herr_t create_perf_test_file(const char *fname, int ngrps, int ndsets, 
       int nattrs, hsize_t nrows, hsize_t dim0, hsize_t chunk, int vlen, 
	   int compressed, int latest)
{
    int         i, j, k;
    hid_t       fid, sid_null, sid_scalar, sid_1d, sid_2d, did, aid, sid_2, sid_large, 
	            fapl=H5P_DEFAULT, dcpl=H5P_DEFAULT, gid1, gid2, cmp_tid, tid_str, 
				tid_enum, tid_array_f, tid_vlen_i, tid_vlen_s;
    char        name[32], tmp_name1[32], tmp_name2[32], tmp_name3[32];
    hsize_t     dims[1]={dim0}, dims2d[2]={dim0, (dim0/4+1)}, dims_array[1]={FIXED_LEN}, 
	            dim1[1]={2};
    char        *enum_names[4] = {"SOLID", "LIQUID", "GAS", "PLASMA"};
    test_comp_t *buf_comp=NULL, *buf_comp_large=NULL;
    int         *buf_int=NULL;
    float       (*buf_float_a)[FIXED_LEN]=NULL;
    double      **buf_double2d=NULL;
    hvl_t       *buf_vlen_i=NULL;
	char        (*buf_str)[FIXED_LEN];
	char        **buf_vlen_s=NULL;
	hobj_ref_t  buf_ref[2];
	hdset_reg_ref_t buf_reg_ref[2];
    size_t      offset, len;
    herr_t      status;
    char        *names[NTYPES] = { "int", "ulong", "float", "double", "fixed string", 
	            "enum", "fixed float array", "vlen int array", "vlen strings"};
    hid_t       types[NTYPES] = { H5T_NATIVE_INT, H5T_NATIVE_UINT64, H5T_NATIVE_FLOAT, 
                H5T_NATIVE_DOUBLE, tid_str, tid_enum, tid_array_f, tid_vlen_i, tid_vlen_s};
	hsize_t     coords[4][2] = { {0,  1}, {3, 5}, {1,  0}, {2,  4}}, start=0, stride=1, count=1;
	
	if (nrows < NROWS) nrows = NROWS; 
    if (ngrps<NGROUPS) ngrps=NGROUPS;
	if (ndsets<NDSETS) ndsets=NDSETS;
	if (nattrs<NATTRS) nattrs=NATTRS;
	if (dim0<DIM0) dim0=DIM0;
    if (chunk>dim0) chunk=dim0/4;
    if (chunk<1) chunk = 1;
	if (vlen<1) vlen = MAXVLEN;

    /* create fixed string datatype */                                   
    types[4] = tid_str =  H5Tcopy (H5T_C_S1);
    H5Tset_size (tid_str, FIXED_LEN);

    /* create enum datatype */
    types[5] = tid_enum = H5Tenum_create(H5T_NATIVE_INT);
    for (i = (int) SOLID; i <= (int) PLASMA; i++) {
        phase_t val = (phase_t) i;
        status = H5Tenum_insert (tid_enum, enum_names[i], &val);
    }

    /* create float array datatype */
    types[6] = tid_array_f = H5Tarray_create (H5T_NATIVE_FLOAT, 1, dims_array);
 
    /* create variable length integer datatypes */
    types[7] = tid_vlen_i = H5Tvlen_create (H5T_NATIVE_INT);
    	
    /* create variable length string datatype */
    types[8] = tid_vlen_s =  H5Tcopy (H5T_C_S1);
    H5Tset_size (tid_vlen_s, H5T_VARIABLE);
                   
    /* create compound datatypes */    
    cmp_tid = H5Tcreate (H5T_COMPOUND, sizeof (test_comp_t));
    offset = 0;
    for (i=0; i<NTYPES-2; i++) {
        H5Tinsert(cmp_tid, names[i], offset, types[i]);
        offset += H5Tget_size(types[i]);
    }

	H5Tinsert(cmp_tid, names[7], offset, types[7]);
	offset += sizeof (hvl_t);
	H5Tinsert(cmp_tid, names[8], offset, types[8]);

	/* create dataspace */
    sid_1d = H5Screate_simple (1, dims, NULL);
    sid_2d = H5Screate_simple (2, dims2d, NULL);
    sid_2 = H5Screate_simple  (1, dim1, NULL);
	sid_large = H5Screate_simple  (1, &nrows, NULL);
    sid_null = H5Screate (H5S_NULL);	
	sid_scalar = H5Screate (H5S_SCALAR);
	
	/* create fid access property */
	fapl = H5Pcreate (H5P_FILE_ACCESS);
    H5Pset_libver_bounds (fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);

	/* create dataset creation property */
    dcpl = H5Pcreate (H5P_DATASET_CREATE);

	/* set dataset chunk */
    if (chunk>0) {
        H5Pset_chunk (dcpl, 1, &chunk);
    }

	/* set dataset compression */
    if (compressed) {
        if (chunk<=0) {
            chunk = dim0/10+1;;
            H5Pset_chunk (dcpl, 1, &chunk);
        }
        H5Pset_shuffle (dcpl);
        H5Pset_deflate (dcpl, 6);
    }	

	/* allocate buffers */
    buf_comp   = (test_comp_t *)calloc(dim0, sizeof(test_comp_t));
    buf_comp_large   = (test_comp_t *)calloc(nrows, sizeof(test_comp_t));
    buf_int    = (int *)calloc(dim0, sizeof(int));
    buf_float_a  = malloc(dim0*sizeof(*buf_float_a));
	buf_vlen_i = (hvl_t *)calloc(dim0, sizeof (hvl_t));
    buf_vlen_s = (char **)calloc(dim0, sizeof(char *));
	buf_str    =  malloc(dim0*sizeof (*buf_str));

	/* allocate array of doulbe pointers */
	buf_double2d  = (double **)calloc(dims2d[0],sizeof(double *));
	/* allocate a contigous chunk of memory for the data */
	buf_double2d[0] = (double *)calloc( dims2d[0]*dims2d[1],sizeof(double) );
	/* assign memory city to pointer array */
	for (i=1; i <dims2d[0]; i++) buf_double2d[i] = buf_double2d[0]+i*dims2d[1];

	/* fill buffer values */
	len = 1;
    for (i=0; i<dims[0]; i++) {
        buf_comp[i].i = buf_int[i] = i-2147483648;
        buf_comp[i].l = 0xffffffffffffffff-i;
        buf_comp[i].f = 1.0/(i+1.0);
        buf_comp[i].d = 987654321.0*i+1.0/(i+1.0);
        buf_comp[i].e = (phase_t) (i % (int) (PLASMA + 1));
		
		for (j=0; j<FIXED_LEN; j++) {
		    buf_comp[i].f_array[j] = buf_float_a[i][j] = i*100+j;
			buf_str[i][j] = 'a' + (i%26);
		}
		buf_str[i][FIXED_LEN-1] = 0;
        strcpy(buf_comp[i].s, buf_str[i]);
		
		len = (1-cos(i/8.0))/2*vlen+1;
		if (!i) len = vlen;
		buf_vlen_i[i].len = len;
		buf_vlen_i[i].p = (int *)calloc(len, sizeof(int));
		for (j=0; j<len; j++) ((int*)(buf_vlen_i[i].p))[j] = i*100+j;
		buf_comp[i].i_vlen = buf_vlen_i[i];
		
		buf_vlen_s[i] = (char *)calloc(len, sizeof(char));
		for (j=0; j<len-1; j++)
		    buf_vlen_s[i][j] = j%26+'A';
		buf_comp[i].s_vlen = buf_vlen_s[i];
		
		for (j=0; j<dims2d[1]; j++)
		    buf_double2d[i][j] = i+j/10000.0;
    }

    for (i=0; i<nrows; i++) {
        buf_comp_large[i].i = i-2147483648;
        buf_comp_large[i].l = 0xffffffffffffffff-i;
        buf_comp_large[i].f = 1.0/(i+1.0);
        buf_comp_large[i].d = 987654321.0*i+1.0/(i+1.0);
        buf_comp_large[i].e = (phase_t) (i % (int) (PLASMA + 1));
        for (j=0; j<FIXED_LEN-1; j++) {
            buf_comp_large[i].f_array[j] = i*100+j;
            buf_comp_large[i].s[j] = 'a' + (i%26);
        }
		len = i%vlen+1;
        buf_comp_large[i].i_vlen.len = len;
        buf_comp_large[i].i_vlen.p = (int *)calloc(len, sizeof(int));
        for (j=0; j<len; j++) ((int*)(buf_comp_large[i].i_vlen.p))[j] = i*100+j;
        buf_comp_large[i].s_vlen = (char *)calloc(i+2, sizeof(char));
        for (j=0; j<i+1; j++) (buf_comp_large[i].s_vlen)[j] = j%26+'A';
    }
	
	/* create file */
    if (latest)
        fid = H5Fcreate (fname, H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
    else
        fid = H5Fcreate (fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
	add_attrs(fid, 0);

	sprintf(name, "a cmp ds of %d rows", nrows);
	did = H5Dcreate (fid, name, cmp_tid, sid_large, H5P_DEFAULT, dcpl, H5P_DEFAULT);
	H5Dwrite (did, cmp_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_comp_large);
	add_attrs(did, 0); 
	H5Dclose(did);

	// /* add attributes*/
    gid1 = H5Gcreate (fid, "attributes", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
	if (nattrs<1) nattrs = 1;
	i=0;
	while (i<nattrs) i += add_attrs(gid1, i);
	H5Gclose(gid1);
		
	/* add many sub groups to a group*/
    gid1 = H5Gcreate (fid, "groups", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
	add_attrs(gid1, 0);
    for (i=0; i<ngrps; i++) {
	    /* create sub groups */
        sprintf(name, "g%02d", i);
        gid2 = H5Gcreate (gid1, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
		if (i<10) add_attrs(gid2, 0);
		H5Gclose(gid2);
	}
	H5Gclose(gid1);

	/* add many datasets to a group */
	gid1 = H5Gcreate (fid, "datasets", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
	add_attrs(gid1, 0);
    for (j=0; j<ndsets; j+=12) {
		/* 1 add a null dataset */
		sprintf(name, "%05d null dataset", j);
        did = H5Dcreate (gid1, name, H5T_STD_I32LE, sid_null, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
		if (!j) add_attrs(did, j); 
        H5Dclose(did);	

		/* 2 add scalar int point */
	    sprintf(name, "%05d scalar int point", j);
        did = H5Dcreate (gid1, name, H5T_NATIVE_INT, sid_scalar, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
        H5Dwrite (did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &j);		
		if (!j) add_attrs(did, j); 
		H5Dclose(did);		
		
		/* 3 scalar vlen string */
	    sprintf(name, "%05d scalar vlen string", j);
        did = H5Dcreate (gid1, name, tid_vlen_s, sid_scalar, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
        H5Dwrite (did, tid_vlen_s, H5S_ALL, H5S_ALL, H5P_DEFAULT, &buf_vlen_s[0]);		
		if (!j) add_attrs(did, j); 
		H5Dclose(did);			
	
	    /* 4 add fixed-length float array */
		sprintf(name, "%05d fixed-length float array", j);
		did = H5Dcreate (gid1, name, tid_array_f, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT);
		H5Dwrite (did, tid_array_f, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_float_a);
		if (!j) add_attrs(did, j); 
		H5Dclose(did);
	
		/* 5 add fixed-length strings */
		sprintf(name, "%05d fixed-length strings", j);
		did = H5Dcreate (gid1, name, tid_str, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT);
		H5Dwrite (did, tid_str, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_str);
		if (!j) add_attrs(did, j); 
		H5Dclose(did);
		
		/* 6 add compound data */
	    sprintf(name, "%05d compund data", j);
	    did = H5Dcreate (gid1, name, cmp_tid, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT);
	    H5Dwrite (did, cmp_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_comp);
		if (!j) add_attrs(did, j); 
		H5Dclose(did);

		/* 7 add 2D double */
	    sprintf(name, "%05d 2D double", j);
		strcpy (tmp_name1, name);
	    did = H5Dcreate (gid1, name, H5T_NATIVE_DOUBLE, sid_2d, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
	    H5Dwrite (did, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_double2d[0]);
		if (!j) add_attrs(did, j); 
		H5Dclose(did);
		
		/* 8 add 1D int array */
	    sprintf(name, "%05d 1D int array", j);
        did = H5Dcreate (gid1, name, H5T_NATIVE_INT, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT);
        H5Dwrite (did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_int);		
		if (!j) add_attrs(did, j); 
		H5Dclose(did);
		
		/* 9 add vlen int array */
	    sprintf(name, "%05d vlen int array", j);
		strcpy (tmp_name2, name);
        did = H5Dcreate (gid1, name, tid_vlen_i, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT);
        H5Dwrite (did, tid_vlen_i, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_vlen_i);		
		if (!j) add_attrs(did, j); 
		H5Dclose(did);	

		/* 10 add vlen strings */
	    sprintf(name, "%05d vlen strings", j);
		strcpy (tmp_name3, name);
        did = H5Dcreate (gid1, name, tid_vlen_s, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT);
        H5Dwrite (did, tid_vlen_s, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_vlen_s);		
		if (!j) add_attrs(did, j); 
		H5Dclose(did);	
		
		/* 11 add object refs */
		H5Rcreate(&buf_ref[0],gid1, ".", H5R_OBJECT, -1); 
		H5Rcreate(&buf_ref[1],gid1, tmp_name3, H5R_OBJECT, -1); 
	    sprintf(name, "%05d obj refs", j);
        did = H5Dcreate (gid1, name, H5T_STD_REF_OBJ, sid_2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
        H5Dwrite (did, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_ref);		
		if (!j) add_attrs(did, j); 
		H5Dclose(did);

		/* 12 add region refs */
		H5Sselect_elements (sid_2d, H5S_SELECT_SET, 4, coords[0]);
		H5Rcreate(&buf_reg_ref[0],gid1, tmp_name1, H5R_DATASET_REGION, sid_2d); 
		H5Sselect_none(sid_2d);
		count = dims[0]/2+1;
		H5Sselect_hyperslab (sid_1d, H5S_SELECT_SET, &start, &stride, &count,NULL);
		H5Rcreate(&buf_reg_ref[1],gid1, tmp_name2, H5R_DATASET_REGION, sid_1d); 
		H5Sselect_none(sid_1d);
	    sprintf(name, "%05d region refs", j);
        did = H5Dcreate (gid1, name, H5T_STD_REF_DSETREG, sid_2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
        H5Dwrite (did, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_reg_ref);		
		if (!j) add_attrs(did, j); 
		H5Dclose(did);
	}
	H5Gclose(gid1);			
	
    H5Tclose (tid_array_f);
    H5Tclose (tid_vlen_i);
    H5Tclose (tid_vlen_s);
    H5Tclose (tid_enum);
    H5Tclose (tid_str);
    H5Tclose (cmp_tid);
    H5Pclose (dcpl);
    H5Pclose (fapl);
    H5Sclose (sid_1d);
    H5Sclose (sid_2d);
    H5Sclose (sid_2);
    H5Sclose (sid_large);
    H5Sclose (sid_null);
    H5Sclose (sid_scalar);
    H5Fclose (fid);

    for (i=0; i<dims[0]; i++) {
		if (buf_vlen_i[i].p) free(buf_vlen_i[i].p);
		if (buf_vlen_s[i]) free(buf_vlen_s[i]);
	}

    for (i=0; i<nrows; i++) {
	    if (buf_comp_large[i].i_vlen.p)  free(buf_comp_large[i].i_vlen.p);
		if (buf_comp_large[i].s_vlen) free(buf_comp_large[i].s_vlen);
	}
	
    free (buf_comp);
    free (buf_comp_large);
    free (buf_int);
    free (buf_float_a);
    free (buf_double2d[0]);
    free (buf_double2d);
	free (buf_str);
    free(buf_vlen_i);
    free(buf_vlen_s);

    return 0;
}
Esempio n. 28
0
/*-------------------------------------------------------------------------
 * Function:	test_tr2
 *
 * Purpose:	Tests conversions that use the O(log N) lookup function.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Tuesday, January  5, 1999
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_tr2(hid_t file)
{
    hid_t	cwg=-1, m_type=-1, f_type=-1, space=-1, dset=-1;
    hsize_t	ds_size[1]={10};
    size_t	i;
    c_e1	val1;
    int		val2;
    static c_e1	data1[10]={E1_RED,   E1_GREEN, E1_BLUE,  E1_GREEN, E1_WHITE,
			   E1_WHITE, E1_BLACK, E1_GREEN, E1_BLUE,  E1_RED};
    c_e1	data2[10];

    TESTING("O(log N) converions");
    if ((cwg=H5Gcreate(file, "test_tr2", 0))<0) goto error;

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

    if ((f_type = H5Tcreate(H5T_ENUM, sizeof(int)))<0) goto error;
    if (H5Tenum_insert(f_type, "RED",   CPTR(val2, 1050))<0) goto error;
    if (H5Tenum_insert(f_type, "GREEN", CPTR(val2, 1040))<0) goto error;
    if (H5Tenum_insert(f_type, "BLUE",  CPTR(val2, 1030))<0) goto error;
    if (H5Tenum_insert(f_type, "WHITE", CPTR(val2, 1020))<0) goto error;
    if (H5Tenum_insert(f_type, "BLACK", CPTR(val2, 1010))<0) goto error;

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

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

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

 error:
    H5E_BEGIN_TRY {
	H5Dclose(dset);
	H5Sclose(space);
	H5Tclose(m_type);
	H5Tclose(f_type);
	H5Gclose(cwg);
    } H5E_END_TRY;
    return 1;
}
int ias_rlut_write_linearization_params
(
    const IAS_RLUT_IO *rlut_file,    /* I: Open RLUT file */
    const IAS_RLUT_LINEARIZATION_PARAMS *linearization_params,
                                     /* I: Pointer to an array of data
                                        structures containing the
                                        linearization parameters for all
                                        detectors in the current band/SCA */
    int band_number,                 /* I: Current band number */
    int sca_number,                  /* I: Current SCA number*/
    int num_detectors                /* I: Number of detectors in the
                                        current band/SCA */
)
{
    char bandsca_parameter_name[IAS_RLUT_BANDSCA_GROUP_NAME_LENGTH + 1];
                                           /* Linearization parameter group
                                              name for the current band/SCA */
    const char *field_names[IAS_RLUT_PARAM_NFIELDS];
                                           /* Name of each linearization
                                              parameter */
    size_t offsets[IAS_RLUT_PARAM_NFIELDS];/* Data offsets in
                                              LINEARIZATION_PARAMS
                                              data structure for each
                                              field*/
    size_t field_sizes[IAS_RLUT_PARAM_NFIELDS];
                                           /* Size of each field */
    hid_t field_types[IAS_RLUT_PARAM_NFIELDS];
                                           /* Data type for each field */
    hid_t fields_to_close[IAS_RLUT_PARAM_NFIELDS];
                                           /* Flags indicating open
                                              fields needing to be closed */
    hid_t linearization_param_group_id;    /* Root LINEARIZATION_PARAMETERS
                                              group ID */
    hid_t bandsca_group_id;                /* SCA group ID */
    hsize_t type_size;                     /* Size of base
                                              LINEARIZATION_PARAMS
                                              data structure */
    herr_t hdf_status;                     /* HDF5 error status flag */
    int status;                            /* IAS status flags */
    int return_status = SUCCESS;


    /* Make sure the RLUT file is actually open */
    if ((rlut_file == NULL) || (rlut_file->file_id < 0))
    {
        IAS_LOG_ERROR("NULL pointer to IAS_RLUT_IO data block, or no RLUT "
            "file has been opened");
        return ERROR;
    }

    /* Construct the group name for the current band/SCA */
    status = snprintf(bandsca_parameter_name, sizeof(bandsca_parameter_name),
        "%s/Band%02d_SCA%02d", LINEARIZATION_PARAMS_GROUP_NAME, band_number,
        sca_number);
    if ((status < 0) || (status >= sizeof(bandsca_parameter_name)))
    {
        IAS_LOG_ERROR("Creating group name for band %d SCA %d "
            "linearization parameters", band_number, sca_number);
        return ERROR;
    }

    /* Open the root group */
    linearization_param_group_id = H5Gopen(rlut_file->file_id,
            LINEARIZATION_PARAMS_GROUP_NAME, H5P_DEFAULT);
    if (linearization_param_group_id < 0)
    {
        IAS_LOG_ERROR("Opening root linearization parameters group");
        return ERROR;
    }

    /* Create a new group for the current band/SCA within this group */
    bandsca_group_id = H5Gcreate(linearization_param_group_id,
       bandsca_parameter_name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    if (bandsca_group_id < 0)
    {
        IAS_LOG_ERROR("Creating group for band %d SCA %d linearization "
            "parameters", band_number, sca_number);
        H5Gclose(linearization_param_group_id);
        return ERROR;
    }

    /* Build the table definition */
    status = ias_rlut_build_linearization_params_table_description(offsets,
        field_names, field_types, fields_to_close, field_sizes);
    if (status != SUCCESS)
    {
        IAS_LOG_ERROR("Building linearization parameter table description");
        H5Gclose(bandsca_group_id);
        H5Gclose(linearization_param_group_id);
        return ERROR;
    }

    /* Get the size of the data structure */
    type_size = sizeof(*linearization_params);

    /* Write the parameter set for the current band/SCA */
    hdf_status = H5TBmake_table(LINEARIZATION_PARAMS_TABLE_NAME,
        bandsca_group_id, LINEARIZATION_PARAMS_DATASET_NAME,
        IAS_RLUT_PARAM_NFIELDS, num_detectors, type_size, field_names,
        offsets, field_types, sizeof(IAS_RLUT_LINEARIZATION_PARAMS), NULL, 0, 
        linearization_params);

    /* Cleanup the table description */
    ias_rlut_cleanup_table_description(fields_to_close,
        IAS_RLUT_PARAM_NFIELDS);

    /* Check the return status from the write */
    if (hdf_status < 0)
    {
        IAS_LOG_ERROR("Writing band %d SCA %d linearization parameter "
            "table to RLUT file %s", band_number, sca_number,
            rlut_file->filename);
        return_status = ERROR;
    }

    /* Close the local SCA group */
    hdf_status = H5Gclose(bandsca_group_id);
    if (hdf_status < 0)
    {
        IAS_LOG_ERROR("Closing band %d SCA %d linearization parameter "
            "group", band_number, sca_number);
        return_status = ERROR;
    }

    /* Close the main linearization parameter group */
    hdf_status = H5Gclose(linearization_param_group_id);
    if (hdf_status < 0)
    {
        IAS_LOG_ERROR("Closing root LINEARIZATION_PARAMETERS group");
        return_status = ERROR;
    }

    return return_status;
}   /* END ias_rlut_write_linearization_params */ 
Esempio n. 30
0
int
main (void)
{
    hid_t       file, space, dset, obj, attr;   /* Handles */
    herr_t      status;
    hsize_t     dims[1] = {DIM0};
    hobj_ref_t  wdata[DIM0],                    /* Write buffer */
                *rdata;                         /* Read buffer */
    H5G_obj_t   objtype;
    ssize_t     size;
    char        *name;
    int         ndims,
                i;

    /*
     * Create a new file using the default properties.
     */
    file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

    /*
     * Create a dataset with a scalar dataspace.
     */
    space = H5Screate (H5S_SCALAR);
    obj = H5Dcreate (file, "DS2", H5T_STD_I32LE, space, H5P_DEFAULT);
    status = H5Dclose (obj);
    status = H5Sclose (space);

    /*
     * Create a group.
     */
    obj = H5Gcreate (file, "G1", H5P_DEFAULT);
    status = H5Gclose (obj);

    /*
     * Create references to the previously created objects.  Passing -1
     * as space_id causes this parameter to be ignored.  Other values
     * besides valid dataspaces result in an error.
     */
    status = H5Rcreate (&wdata[0], file, "G1", H5R_OBJECT, -1);
    status = H5Rcreate (&wdata[1], file, "DS2", H5R_OBJECT, -1);

    /*
     * Create dataset with a scalar dataspace to serve as the parent
     * for the attribute.
     */
    space = H5Screate (H5S_SCALAR);
    dset = H5Dcreate (file, DATASET, H5T_STD_I32LE, space, H5P_DEFAULT);
    status = H5Sclose (space);

    /*
     * Create dataspace.  Setting maximum size to NULL sets the maximum
     * size to be the current size.
     */
    space = H5Screate_simple (1, dims, NULL);

    /*
     * Create the attribute and write the object references to it.
     */
    attr = H5Acreate (dset, ATTRIBUTE, H5T_STD_REF_OBJ, space, H5P_DEFAULT);
    status = H5Awrite (attr, H5T_STD_REF_OBJ, wdata);

    /*
     * Close and release resources.
     */
    status = H5Aclose (attr);
    status = H5Dclose (dset);
    status = H5Sclose (space);
    status = H5Fclose (file);


    /*
     * Now we begin the read section of this example.  Here we assume
     * the attribute has the same name and rank, but can have any size.
     * Therefore we must allocate a new array to read in data using
     * malloc().
     */

    /*
     * Open file, dataset, and attribute.
     */
    file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
    dset = H5Dopen (file, DATASET);
    attr = H5Aopen_name (dset, ATTRIBUTE);

    /*
     * Get dataspace and allocate memory for read buffer.
     */
    space = H5Aget_space (attr);
    ndims = H5Sget_simple_extent_dims (space, dims, NULL);
    rdata = (hobj_ref_t *) malloc (dims[0] * sizeof (hobj_ref_t));

    /*
     * Read the data.
     */
    status = H5Aread (attr, H5T_STD_REF_OBJ, rdata);

    /*
     * Output the data to the screen.
     */
    for (i=0; i<dims[0]; i++) {
        printf ("%s[%d]:\n  ->", ATTRIBUTE, i);

        /*
         * Open the referenced object, get its name and type.
         */
        obj = H5Rdereference (dset, H5R_OBJECT, &rdata[i]);
        objtype = H5Rget_obj_type (dset, H5R_OBJECT, &rdata[i]);

        /*
         * Get the length of the name, allocate space, then retrieve
         * the name.
         */
        size = 1 + H5Iget_name (obj, NULL, 0);
        if (size > 1) {
            name = (char *) malloc (size);
            size = 1 + H5Iget_name (obj, name, size);
        }

        /*
         * Print the object type and close the object.
         */
        switch (objtype) {
            case H5G_GROUP:
                printf ("Group");
                status = H5Gclose (obj);
                break;
            case H5G_DATASET:
                printf ("Dataset");
                status = H5Dclose (obj);
                break;
            case H5G_TYPE:
                printf ("Named Datatype");
                status = H5Tclose (obj);
        }

        /*
         * Print the name and deallocate space for the name.
         */
        if (size > 1) {
            printf (": %s", name);
            free (name);
        }
        printf ("\n");
    }

    /*
     * Close and release resources.
     */
    free (rdata);
    status = H5Aclose (attr);
    status = H5Dclose (dset);
    status = H5Sclose (space);
    status = H5Fclose (file);

    return 0;
}