コード例 #1
0
ファイル: writeindata_p.c プロジェクト: kouui/rh
/* ------- begin -------------------------- readConvergence.c  --- */
void readConvergence(void) {
  /* This is a self-contained function to read the convergence matrix,
     written by RH. */
  const char routineName[] = "readConvergence";
  char *atmosID;
  int ncid, ncid_mpi, nx, ny;
  size_t attr_size;
  hid_t plist;
  H5T_class_t type_class;

  mpi.rh_converged = matrix_int(mpi.nx, mpi.ny);

  /* --- Open the inputdata file --- */
  if (( plist = H5Pcreate(H5P_FILE_ACCESS )) < 0) HERR(routineName);
  if (( H5Pset_fapl_mpio(plist, mpi.comm, mpi.info) ) < 0) HERR(routineName);
  if (( ncid = H5Fopen(INPUTDATA_FILE, H5F_ACC_RDWR, plist) ) < 0)
    HERR(routineName);
  if (( H5Pclose(plist) ) < 0) HERR(routineName);
  /* Get ncid of the MPI group */
  if (( ncid_mpi = H5Gopen(ncid, "mpi", H5P_DEFAULT) ) < 0) HERR(routineName);

  /* --- Consistency checks --- */
  /* Check that atmosID is the same */
  if (( H5LTget_attribute_info(ncid, "/", "atmosID", NULL, &type_class,
                               &attr_size) ) < 0) HERR(routineName);
  atmosID = (char *) malloc(attr_size + 1);
  if (( H5LTget_attribute_string(ncid, "/", "atmosID", atmosID) ) < 0)
    HERR(routineName);
  if (!strstr(atmosID, atmos.ID)) {
    sprintf(messageStr,
       "Indata file was calculated for different atmosphere (%s) than current",
	     atmosID);
    Error(WARNING, routineName, messageStr);
    }
  free(atmosID);
  /* Check that dimension sizes match */
  if (( H5LTget_attribute_int(ncid, "/", "nx", &nx) ) < 0) HERR(routineName);
  if (nx != mpi.nx) {
    sprintf(messageStr,
	    "Number of x points mismatch: expected %d, found %d.",
	    mpi.nx, (int)nx);
    Error(WARNING, routineName, messageStr);
  }
  if (( H5LTget_attribute_int(ncid, "/", "ny", &ny) ) < 0) HERR(routineName);
  if (ny != mpi.ny) {
    sprintf(messageStr,
	    "Number of y points mismatch: expected %d, found %d.",
	    mpi.ny, (int)ny);
    Error(WARNING, routineName, messageStr);
  }
  /* --- Read variable --- */
  if (( H5LTread_dataset_int(ncid_mpi, CONV_NAME,
                             mpi.rh_converged[0]) ) < 0) HERR(routineName);
  /* --- Close inputdata file --- */
  if (( H5Gclose(ncid_mpi) ) < 0) HERR(routineName);
  if (( H5Fclose(ncid) ) < 0) HERR(routineName);
  return;
}
コード例 #2
0
ファイル: H5LTfc.c プロジェクト: chaako/sceptic3D
int_f
nh5ltget_attribute_int_c(hid_t_f *loc_id,
                         int_f *namelen,
                         _fcd dsetname,
                         int_f *attrnamelen,
                         _fcd attrname,
                         void *buf)
{
    int     ret_value = -1;
    herr_t  ret;
    hid_t   c_loc_id;
    char    *c_name = NULL;
    char    *c_attrname = NULL;
    int     c_namelen;
    int     c_attrnamelen;

    /*
    * convert FORTRAN name to C name
    */
    c_namelen = (int)*namelen;
    c_name = (char *)HD5f2cstring(dsetname, c_namelen);
    if (c_name == NULL) 
        goto done;

    c_attrnamelen = (int)*attrnamelen;
    c_attrname = (char *)HD5f2cstring(attrname, c_attrnamelen);
    if (c_attrname == NULL) 
        goto done;

    /*
    * call H5LTget_attribute_int function.
    */
    c_loc_id = (hid_t)*loc_id;

    if(sizeof(int_f) == sizeof(int))
        ret = H5LTget_attribute_int(c_loc_id,c_name,c_attrname,buf);
    else if (sizeof(int_f) == sizeof(long))
        ret = H5LTget_attribute_long(c_loc_id,c_name,c_attrname,buf);
    else if (sizeof(int_f) == sizeof(long long))
        ret = H5LTget_attribute_long_long(c_loc_id,c_name,c_attrname,buf);
    else
        goto done;

    if (ret < 0) 
        goto done;

    ret_value = 0;

done:
    if(c_name!=NULL)
        free(c_name);
    if(c_attrname!=NULL)
        free(c_attrname);


    return ret_value;
}
コード例 #3
0
// Read integer attribute <attr_name> given by address <path>
char AH5_read_int_attr(hid_t loc_id, const char *path, char *attr, int *rdata)
{
    char success = AH5_FALSE;

    if (AH5_path_valid(loc_id, path))
        if (H5Aexists_by_name(loc_id, path, attr, H5P_DEFAULT) > 0)
            if (H5LTget_attribute_int(loc_id, path, attr, rdata) >= 0)
                success = AH5_TRUE;
    if(!success)
        *rdata = 0;
    return success;
}
コード例 #4
0
ファイル: psc_fields_single.c プロジェクト: ALaDyn/psc
static void
psc_fields_single_read(struct psc_fields *flds, struct mrc_io *io)
{
  int ierr;
  long h5_file;
  mrc_io_get_h5_file(io, &h5_file);
  hid_t group = H5Gopen(h5_file, mrc_io_obj_path(io, flds), H5P_DEFAULT); H5_CHK(group);
  int ib[3], im[3], nr_comp;
  ierr = H5LTget_attribute_int(group, ".", "p", &flds->p); CE;
  ierr = H5LTget_attribute_int(group, ".", "ib", ib); CE;
  ierr = H5LTget_attribute_int(group, ".", "im", im); CE;
  ierr = H5LTget_attribute_int(group, ".", "nr_comp", &nr_comp); CE;
  for (int d = 0; d < 3; d++) {
    assert(ib[d] == flds->ib[d]);
    assert(im[d] == flds->im[d]);
  }
  assert(nr_comp == flds->nr_comp);
  psc_fields_setup(flds);
  ierr = H5LTread_dataset_float(group, "fields_single", flds->data); CE;
  ierr = H5Gclose(group); CE;
}
コード例 #5
0
ファイル: structure_utils.c プロジェクト: hbredin/pinocchIO
int getTimesUsed(PIOTimeline pioTimeline)
{
	ERROR_SWITCH_INIT
	int times_used = -1;
	herr_t get_err;
	
	ERROR_SWITCH_OFF
	get_err = H5LTget_attribute_int(pioTimeline.identifier, ".", PIOAttribute_TimesUsed, &times_used);
	ERROR_SWITCH_ON
	
	if (get_err < 0) return -1;
	return times_used;
}
コード例 #6
0
ファイル: pIOAttributes.c プロジェクト: hbredin/pinocchIO
int pioReadAttributeInteger(PIOObject pioObject,
							const char* attr_name, int* attr_value)
{
	if (pioHasAttribute(pioObject, attr_name))
	{
		H5LTget_attribute_int(pioObject.identifier, ".",
							  attr_name, attr_value);	
		return 1;
	} 
	else {
		return -1;
	}
}
コード例 #7
0
ファイル: ArImpl.cpp プロジェクト: EgoIncarnate/appleseed
//-*****************************************************************************
ArImpl::ArImpl( const std::string &iFileName,
                AbcA::ReadArraySampleCachePtr iCache )
  : m_fileName( iFileName )
  , m_file( -1 )
  , m_readArraySampleCache( iCache )
{
    // OPEN THE FILE!
    htri_t exi = H5Fis_hdf5( m_fileName.c_str() );
    ABCA_ASSERT( exi == 1, "Nonexistent File: " << m_fileName );

    m_file = H5Fopen( m_fileName.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT );
    ABCA_ASSERT( m_file >= 0,
                 "Could not open file: " << m_fileName );

    // get the version using HDF5 native calls
    int version = -INT_MAX;
    if (H5Aexists(m_file, "abc_version"))
    {
        H5LTget_attribute_int(m_file, ".", "abc_version", &version);
    }
    ABCA_ASSERT(version == ALEMBIC_HDF5_FILE_VERSION,
        "Unsupported file version detected.");

    // if it isn't there, it's pre 1.0
    int fileVersion = 9999;
    if (H5Aexists( m_file, "abc_release_version" ))
    {
        H5LTget_attribute_int( m_file, ".", "abc_release_version",
                               &fileVersion);
    }
    m_archiveVersion = fileVersion;

    // Read the top object
    m_top = new TopOrImpl( *this, m_file );

    ReadTimeSamples( m_file, m_timeSamples );
}
コード例 #8
0
//-*****************************************************************************
HDF5HierarchyReader::HDF5HierarchyReader( hid_t iFile,
                                          HDF5Hierarchy& iH5H,
                                          const bool iCacheHierarchy )
    : m_H5H( iH5H )
{
    int enabled( 0 );
    if (iCacheHierarchy && H5Aexists( iFile, "abc_ref_hierarchy" ))
    {
        H5LTget_attribute_int( iFile, ".", "abc_ref_hierarchy", &enabled );
    }

    m_H5H.clear();
    m_H5H.setEnabled( enabled != 0 );

    if( enabled )
    {
        readHierarchy( iFile );
    }

}
コード例 #9
0
ファイル: writeAux_p.c プロジェクト: tiagopereira/rh
/* ------- begin -------------------------- readMolPops_p.c -- */
void readMolPops(Molecule *molecule) {

  /* --- Read populations from file.

   Note: readPopulations only reads the true populations and not
         the LTE populations.
         --                                            -------------- */

  const char routineName[] = "readMolPops";
  char    group_name[ARR_STRLEN], *atmosID;

  int nz, nlevel;
  H5T_class_t type_class;
  size_t attr_size;
  hsize_t offset[] = {0, 0, 0, 0};
  hsize_t count[] = {1, 1, 1, 1};
  hsize_t dims[4];
  hid_t ncid, file_dspace, mem_dspace, pop_var;

  /* --- Open molecule group --- */
  sprintf(group_name, "molecule_%s", molecule->ID);
  if (( ncid = H5Gopen(io.aux_ncid, group_name, H5P_DEFAULT) ) < 0)
    HERR(routineName);
  /* --- Consistency checks --- */
  /* Check that atmosID is the same */
  if (( H5LTget_attribute_info(io.aux_ncid, "/", "atmosID", NULL, &type_class,
                               &attr_size) ) < 0) HERR(routineName);
  atmosID = (char *) malloc(attr_size + 1);
  if (( H5LTget_attribute_string(io.aux_ncid, "/", "atmosID", atmosID) ) < 0)
    HERR(routineName);
  if (!strstr(atmosID, atmos.ID)) {
    sprintf(messageStr,
       "Indata file was calculated for different atmosphere (%s) than current",
       atmosID);
    Error(WARNING, routineName, messageStr);
  }
  free(atmosID);
  /* Check that dimension sizes match */
  if (( H5LTget_attribute_int(ncid, ".", "nlevel_vibr", &nlevel) ) < 0)
    HERR(routineName);
  if (nlevel != molecule->Nv) {
    sprintf(messageStr,
      "Number of levels mismatch: expected %d, found %d.",
      molecule->Nv, (int)nlevel);
    Error(ERROR_LEVEL_2, routineName, messageStr);
  }
  if (( H5LTget_attribute_int(io.aux_ncid, ".", "nz", &nz) ) < 0)
    HERR(routineName);
  if (nz < atmos.Nspace) {
    sprintf(messageStr,
      "Number of depth points mismatch: expected %ld, found %d.",
      atmos.Nspace, (int)nz);
    Error(ERROR_LEVEL_2, routineName, messageStr);
  }

  /* --- Read data --- */
  if (( pop_var = H5Dopen2(ncid, POP_NAME, H5P_DEFAULT)) < 0)
    HERR(routineName);
  dims[0] = molecule->Nv;
  dims[1] = atmos.Nspace;
  if (( mem_dspace = H5Screate_simple(2, dims, NULL) ) < 0) HERR(routineName);
  /* File dataspace */
  offset[0] = 0;
  offset[1] = mpi.ix;
  offset[2] = mpi.iy;
  offset[3] = mpi.zcut;
  count[0] = molecule->Nv;
  count[3] = atmos.Nspace;
  if (( file_dspace = H5Dget_space(pop_var) ) < 0) HERR(routineName);
  if (( H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, offset,
                            NULL, count, NULL) ) < 0) HERR(routineName);
  if (( H5Dread(pop_var, H5T_NATIVE_DOUBLE, mem_dspace,
            file_dspace, H5P_DEFAULT, molecule->nv[0]) ) < 0) HERR(routineName);
  if (( H5Sclose(mem_dspace) ) < 0) HERR(routineName);
  if (( H5Sclose(file_dspace) ) < 0) HERR(routineName);
  if (( H5Dclose(pop_var) ) < 0) HERR(routineName);

  return;
}
コード例 #10
0
ファイル: writeAux_p.c プロジェクト: tiagopereira/rh
/* ------- begin -------------------------- readPopulations_p.c -- */
void readPopulations(Atom *atom) {

  /* --- Read populations from file.

   Note: readPopulations only reads the true populations and not
         the LTE populations.
   Note2: This routine will not work yet in HFD5. Access to the aux file
          needs to be better regulated in OLD_POPULATIONS cases (ie, append
          and read/write acess). The code below assumes the file is already
          open, which may not be the case.
         --                                            -------------- */
  const char routineName[] = "readPopulations_p";
  char    group_name[ARR_STRLEN], *atmosID;
  int nz, nlevel;
  H5T_class_t type_class;
  size_t attr_size;
  hsize_t offset[] = {0, 0, 0, 0};
  hsize_t count[] = {1, 1, 1, 1};
  hsize_t dims[4];
  hid_t ncid, file_dspace, mem_dspace, pop_var;

  /* --- Open atom group --- */
  sprintf(group_name,(atom->ID[1] == ' ') ? "atom_%.1s" : "atom_%.2s", atom->ID);
  if (( ncid = H5Gopen(io.aux_ncid, group_name, H5P_DEFAULT) ) < 0)
    HERR(routineName);
  /* --- Consistency checks --- */
  /* Check that atmosID is the same */
  if (( H5LTget_attribute_info(io.aux_ncid, "/", "atmosID", NULL, &type_class,
                               &attr_size) ) < 0) HERR(routineName);
  atmosID = (char *) malloc(attr_size + 1);
  if (( H5LTget_attribute_string(io.aux_ncid, "/", "atmosID", atmosID) ) < 0)
    HERR(routineName);
  if (!strstr(atmosID, atmos.ID)) {
    sprintf(messageStr,
       "Indata file was calculated for different atmosphere (%s) than current",
       atmosID);
    Error(WARNING, routineName, messageStr);
  }
  free(atmosID);
  /* Check that dimension sizes match */
  if (( H5LTget_attribute_int(ncid, ".", "nlevel", &nlevel) ) < 0)
    HERR(routineName);
  if (nlevel != atom->Nlevel) {
      sprintf(messageStr,
          "Number of levels mismatch: expected %d, found %d.",
          atom->Nlevel, (int)nlevel);
      Error(ERROR_LEVEL_2, routineName, messageStr);
  }
  if (( H5LTget_attribute_int(io.aux_ncid, ".", "nz", &nz) ) < 0)
    HERR(routineName);
  if (nz < atmos.Nspace) {
    sprintf(messageStr,
      "Number of depth points mismatch: expected %ld, found %d.",
      atmos.Nspace, (int)nz);
    Error(ERROR_LEVEL_2, routineName, messageStr);
  }

  /* --- Read data --- */
  if (( pop_var = H5Dopen2(ncid, POP_NAME, H5P_DEFAULT)) < 0)
    HERR(routineName);
  dims[0] = atom->Nlevel;
  dims[1] = atmos.Nspace;
  if (( mem_dspace = H5Screate_simple(2, dims, NULL) ) < 0) HERR(routineName);
  /* File dataspace */
  offset[0] = 0;
  offset[1] = mpi.ix;
  offset[2] = mpi.iy;
  offset[3] = mpi.zcut;
  count[0] = atom->Nlevel;
  count[3] = atmos.Nspace;
  if (( file_dspace = H5Dget_space(pop_var) ) < 0) HERR(routineName);
  if (( H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, offset,
                            NULL, count, NULL) ) < 0) HERR(routineName);
  if (( H5Dread(pop_var, H5T_NATIVE_DOUBLE, mem_dspace,
                file_dspace, H5P_DEFAULT, atom->n[0]) ) < 0) HERR(routineName);
  if (( H5Sclose(mem_dspace) ) < 0) HERR(routineName);
  if (( H5Sclose(file_dspace) ) < 0) HERR(routineName);
  if (( H5Dclose(pop_var) ) < 0) HERR(routineName);

  return;
}
コード例 #11
0
ファイル: writeAux_p.c プロジェクト: tiagopereira/rh
/* ------- begin --------------------   init_aux_existing.c   --- */
void init_aux_existing(void) {
  const char routineName[] = "init_aux_existing";
  int     i, nlevel, nline, ncont;
  size_t  attr_size;
  hid_t   ncid, ncid_atom, ncid_mol, plist;
  H5T_class_t type_class;
  char    group_name[ARR_STRLEN], *atmosID;
  Atom   *atom;
  Molecule *molecule;

  /* Open the file with parallel MPI-IO access */
  if (( plist = H5Pcreate(H5P_FILE_ACCESS )) < 0) HERR(routineName);
  if (( H5Pset_fapl_mpio(plist, mpi.comm, mpi.info) ) < 0) HERR(routineName);
  if (( ncid = H5Fopen(AUX_FILE, H5F_ACC_RDWR, plist) ) < 0)
    HERR(routineName);
  if (( H5Pclose(plist) ) < 0) HERR(routineName);
  io.aux_ncid = ncid;
  /* --- Consistency checks --- */
  /* Check that atmosID is the same */
  if (( H5LTget_attribute_info(ncid, "/", "atmosID", NULL, &type_class,
                               &attr_size) ) < 0) HERR(routineName);
  atmosID = (char *) malloc(attr_size + 1);
  if (( H5LTget_attribute_string(ncid, "/", "atmosID", atmosID) ) < 0)
    HERR(routineName);
  if (!strstr(atmosID, atmos.ID)) {
    sprintf(messageStr,
       "Indata file was calculated for different atmosphere (%s) than current",
	     atmosID);
    Error(WARNING, routineName, messageStr);
    }
  free(atmosID);

  /* Create arrays for multiple-atom/molecule output */
  io.aux_atom_ncid   = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t));
  io.aux_mol_ncid    = (hid_t *) malloc(atmos.Nactivemol  * sizeof(hid_t));
  if (input.p15d_wpop) {
      io.aux_atom_pop    = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t));
      io.aux_atom_poplte = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t));
      io.aux_mol_pop     = (hid_t *) malloc(atmos.Nactivemol  * sizeof(hid_t));
      io.aux_mol_poplte  = (hid_t *) malloc(atmos.Nactivemol  * sizeof(hid_t));
  }
  if (input.p15d_wrates) {
      io.aux_atom_RijL   = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t));
      io.aux_atom_RjiL   = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t));
      io.aux_atom_RijC   = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t));
      io.aux_atom_RjiC   = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t));
  }

  /* --- Group loop over active ATOMS --- */
  for (i=0; i < atmos.Nactiveatom; i++) {
    atom = atmos.activeatoms[i];

    /* --- Get ncid of the atom group --- */
    sprintf(group_name,(atom->ID[1] == ' ') ? "atom_%.1s" : "atom_%.2s", atom->ID);
    if (( io.aux_atom_ncid[i] = H5Gopen(io.aux_ncid, group_name,
                                        H5P_DEFAULT) ) < 0)  HERR(routineName);
    ncid_atom = io.aux_atom_ncid[i];

    /* Check that dimension sizes match */
    if (( H5LTget_attribute_int(ncid_atom, ".", "nlevel", &nlevel) ) < 0)
      HERR(routineName);
    if (nlevel != atom->Nlevel) {
        sprintf(messageStr,
  	      "Number of levels mismatch: expected %d, found %d.",
  	      atom->Nlevel, (int)nlevel);
        Error(ERROR_LEVEL_2, routineName, messageStr);
    }
    if (( H5LTget_attribute_int(ncid_atom, ".", "nline", &nline) ) < 0)
      HERR(routineName);
    if (nline != atom->Nline) {
      sprintf(messageStr,
          "Number of lines mismatch: expected %d, found %d.",
          atom->Nline, (int)nline);
      Error(ERROR_LEVEL_2, routineName, messageStr);
    }
    if (( H5LTget_attribute_int(ncid_atom, ".", "ncontinuum", &ncont) ) < 0)
      HERR(routineName);
    if (ncont != atom->Ncont) {
      sprintf(messageStr,
          "Number of continua mismatch: expected %d, found %d.",
          atom->Ncont, (int)ncont);
      Error(ERROR_LEVEL_2, routineName, messageStr);
    }

    /* --- Open datasets collectively ---*/
    if (input.p15d_wpop) {
      if (( io.aux_atom_pop[i] = H5Dopen(ncid_atom, POP_NAME,
                                         H5P_DEFAULT) )  < 0) HERR(routineName);
      if (( io.aux_atom_poplte[i] = H5Dopen(ncid_atom, POPLTE_NAME,
                                          H5P_DEFAULT) ) < 0) HERR(routineName);
    }
    if (input.p15d_wrates) {
      if (( io.aux_atom_RijL[i] = H5Dopen(ncid_atom, RIJ_L_NAME,
                                         H5P_DEFAULT) )  < 0) HERR(routineName);
      if (( io.aux_atom_RjiL[i] = H5Dopen(ncid_atom, RJI_L_NAME,
                                         H5P_DEFAULT) )  < 0) HERR(routineName);
      if (atom->Ncont > 0) {
          if (( io.aux_atom_RijC[i] = H5Dopen(ncid_atom, RIJ_C_NAME,
                                         H5P_DEFAULT) )  < 0) HERR(routineName);
          if (( io.aux_atom_RjiC[i] = H5Dopen(ncid_atom, RJI_C_NAME,
                                         H5P_DEFAULT) )  < 0) HERR(routineName);
      }
    }
  } /* end active ATOMS loop */


  /* --- Group loop over active MOLECULES --- */
  for (i=0; i < atmos.Nactivemol; i++) {
    molecule = atmos.activemols[i];

    /* --- Get ncid of the molecule group --- */
    sprintf( group_name, "molecule_%s", molecule->ID);
    if (( io.aux_mol_ncid[i] = H5Gopen(io.aux_ncid, group_name,
                                        H5P_DEFAULT) ) < 0)  HERR(routineName);
    ncid_mol = io.aux_mol_ncid[i];

    /* Check that dimension sizes match */
    if (( H5LTget_attribute_int(ncid_mol, ".", "nlevel_vibr", &nlevel) ) < 0)
      HERR(routineName);
    if (nlevel != molecule->Nv) {
      sprintf(messageStr,
          "Number of levels mismatch: expected %d, found %d.",
          molecule->Nv, (int)nlevel);
      Error(ERROR_LEVEL_2, routineName, messageStr);
    }
    if (( H5LTget_attribute_int(ncid_mol, ".", "nline_molecule", &nline) ) < 0)
      HERR(routineName);
    if (nline != molecule->Nrt) {
      sprintf(messageStr,
          "Number of lines mismatch: expected %d, found %d.",
          molecule->Nrt, (int)nline);
      Error(ERROR_LEVEL_2, routineName, messageStr);
    }
    if (( H5LTget_attribute_int(ncid_mol, ".", "nJ", &ncont) ) < 0)
      HERR(routineName);
    if (ncont != molecule->NJ) {
      sprintf(messageStr,
          "Number of J mismatch: expected %d, found %d.",
          molecule->NJ, (int)ncont);
      Error(ERROR_LEVEL_2, routineName, messageStr);
    }

    /* --- Open datasets collectively ---*/
    if (input.p15d_wpop) {
      if (( io.aux_mol_pop[i] = H5Dopen(ncid_mol, POP_NAME,
                                         H5P_DEFAULT) )  < 0) HERR(routineName);
      if (( io.aux_mol_poplte[i] = H5Dopen(ncid_mol, POPLTE_NAME,
                                         H5P_DEFAULT) )  < 0) HERR(routineName);
    }
  } /* end active MOLECULES loop */

  return;
}
コード例 #12
0
ファイル: test_lite.c プロジェクト: chaako/sceptic3D
static herr_t make_attributes( hid_t loc_id, const char* obj_name )
{

    int         rank_out;
    hsize_t     *dims_out = 0;
    H5T_class_t type_class;
    size_t      type_size;
    int         i;

    char    attr_str_in[]     = {"My attribute"};
    char    attr_str_out[20];
    char    attr_char_in[5]   = {1,2,3,4,5};
    char    attr_char_out[5];
    short   attr_short_in[5]  = {1,2,3,4,5};
    short   attr_short_out[5];
    int     attr_int_in[5]    = {1,2,3,4,5};
    int     attr_int_out[5];
    long    attr_long_in[5]   = {1,2,3,4,5};
    long    attr_long_out[5];
    float   attr_float_in[5]  = {1,2,3,4,5};
    float   attr_float_out[5];
    double  attr_double_in[5] = {1,2,3,4,5};
    double  attr_double_out[5];
    unsigned char    attr_uchar_in[5]   = {1,2,3,4,5};
    unsigned char    attr_uchar_out[5];
    unsigned short   attr_ushort_in[5]  = {1,2,3,4,5};
    unsigned short   attr_ushort_out[5];
    unsigned int     attr_uint_in[5]    = {1,2,3,4,5};
    unsigned int     attr_uint_out[5];
    unsigned long    attr_ulong_in[5]   = {1,2,3,4,5};
    unsigned long    attr_ulong_out[5];

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_string test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_string");

    /* Set the attribute */
    if ( H5LTset_attribute_string( loc_id, obj_name, ATTR1_NAME, attr_str_in ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_string test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_string");


    /* Get the attribute */
    if ( H5LTget_attribute_string( loc_id, obj_name, ATTR1_NAME, attr_str_out ) < 0 )
        return -1;

    if ( strcmp( attr_str_in, attr_str_out ) != 0 )
    {
        return -1;
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTset_attribute_char test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_char");

    /* Set the attribute */
    if ( H5LTset_attribute_char( loc_id, obj_name, ATTR2_NAME, attr_char_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_char test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_char");

    /* Get the attribute */
    if ( H5LTget_attribute_char( loc_id, obj_name, ATTR2_NAME, attr_char_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_char_in[i] != attr_char_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR2_NAME, H5T_NATIVE_CHAR, attr_char_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_char_in[i] != attr_char_out[i] ) {
            return -1;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_short test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_short");

    /* Set the attribute */
    if ( H5LTset_attribute_short( loc_id, obj_name, ATTR3_NAME, attr_short_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTget_attribute_short test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_short");

    /* Get the attribute */
    if ( H5LTget_attribute_short( loc_id, obj_name, ATTR3_NAME, attr_short_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_short_in[i] != attr_short_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR3_NAME, H5T_NATIVE_SHORT, attr_short_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_short_in[i] != attr_short_out[i] ) {
            return -1;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTset_attribute_int test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_int");

    /* Set the attribute */
    if ( H5LTset_attribute_int( loc_id, obj_name, ATTR4_NAME, attr_int_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_int test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_int");

    /* Get the attribute */
    if ( H5LTget_attribute_int( loc_id, obj_name, ATTR4_NAME, attr_int_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_int_in[i] != attr_int_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR4_NAME, H5T_NATIVE_INT, attr_int_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_int_in[i] != attr_int_out[i] ) {
            return -1;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_long test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_long");

    /* Set the attribute */
    if ( H5LTset_attribute_long( loc_id, obj_name, ATTR5_NAME, attr_long_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_long test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_long");

    /* Get the attribute */
    if ( H5LTget_attribute_long( loc_id, obj_name, ATTR5_NAME, attr_long_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_long_in[i] != attr_long_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR5_NAME, H5T_NATIVE_LONG, attr_long_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_long_in[i] != attr_long_out[i] ) {
            return -1;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_uchar test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_uchar");

    /* Set the attribute */
    if ( H5LTset_attribute_uchar( loc_id, obj_name, ATTR6_NAME, attr_uchar_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_uchar test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_uchar");

    /* Get the attribute */
    if ( H5LTget_attribute_uchar( loc_id, obj_name, ATTR6_NAME, attr_uchar_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_uchar_in[i] != attr_uchar_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR6_NAME, H5T_NATIVE_UCHAR, attr_uchar_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_uchar_in[i] != attr_uchar_out[i] ) {
            return -1;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_ushort test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_ushort");

    /* Set the attribute */
    if ( H5LTset_attribute_ushort( loc_id, obj_name, ATTR7_NAME, attr_ushort_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTget_attribute_ushort test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_ushort");

    /* Get the attribute */
    if ( H5LTget_attribute_ushort( loc_id, obj_name, ATTR7_NAME, attr_ushort_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_ushort_in[i] != attr_ushort_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR7_NAME, H5T_NATIVE_USHORT, attr_ushort_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_ushort_in[i] != attr_ushort_out[i] ) {
            return -1;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTset_attribute_int test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_uint");

    /* Set the attribute */
    if ( H5LTset_attribute_uint( loc_id, obj_name, ATTR8_NAME, attr_uint_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_int test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_uint");

    /* Get the attribute */
    if ( H5LTget_attribute_uint( loc_id, obj_name, ATTR8_NAME, attr_uint_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_uint_in[i] != attr_uint_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR8_NAME, H5T_NATIVE_UINT, attr_uint_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_uint_in[i] != attr_uint_out[i] ) {
            return -1;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_ulong test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_ulong");

    /* Set the attribute */
    if ( H5LTset_attribute_ulong( loc_id, obj_name, ATTR9_NAME, attr_ulong_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_long test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_ulong");

    /* Get the attribute */
    if ( H5LTget_attribute_ulong( loc_id, obj_name, ATTR9_NAME, attr_ulong_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_ulong_in[i] != attr_ulong_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR9_NAME, H5T_NATIVE_ULONG, attr_ulong_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_ulong_in[i] != attr_ulong_out[i] ) {
            return -1;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTset_attribute_float test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_float");

    /* Set the attribute */
    if ( H5LTset_attribute_float( loc_id, obj_name, ATTR10_NAME, attr_float_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_float test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_float");


    /* Get the attribute */
    if ( H5LTget_attribute_float( loc_id, obj_name, ATTR10_NAME, attr_float_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_float_in[i] != attr_float_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR10_NAME, H5T_NATIVE_FLOAT, attr_float_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_float_in[i] != attr_float_out[i] ) {
            return -1;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_double test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_double");

    /* Set the attribute */
    if ( H5LTset_attribute_double( loc_id, obj_name, ATTR11_NAME, attr_double_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_double test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_double");

    /* Get the attribute */
    if ( H5LTget_attribute_double( loc_id, obj_name, ATTR11_NAME, attr_double_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_double_in[i] != attr_double_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR11_NAME, H5T_NATIVE_DOUBLE, attr_double_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_double_in[i] != attr_double_out[i] ) {
            return -1;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTget_attribute_ndims test
    *-------------------------------------------------------------------------
    */


    TESTING("H5LTget_attribute_ndims");

    if ( H5LTget_attribute_ndims( loc_id, obj_name, ATTR2_NAME, &rank_out ) < 0 )
        return -1;

    if ( rank_out != 1 ) {
        return -1;
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_info test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_info");

    dims_out = (hsize_t*) malloc( sizeof(hsize_t) * rank_out );

    if ( H5LTget_attribute_info( loc_id, obj_name, ATTR2_NAME, dims_out, &type_class,
        &type_size) < 0 )
        return -1;

    for (i = 0; i < rank_out; i++)
    {
        if ( dims_out[i] != 5 ) {
            return -1;
        }
    }

    if ( type_class != H5T_INTEGER ) {
        return -1;
    }

    if ( dims_out )
        free( dims_out );

    PASSED();

    return 0;
}
コード例 #13
0
ファイル: hdf5Driver.cpp プロジェクト: brunoseivam/ADHDF5
asynStatus hdf5Driver::openFile (const char *path)
{
    asynStatus status = asynSuccess;
    const char *functionName = "loadFile";

    hid_t fileId, groupId;
    H5G_info_t groupInfo;
    size_t totalFrames = 0;
    size_t maxWidth = 0, maxHeight = 0;

    // Reset some parameters
    setIntegerParam(HDF5DatasetsCount,  0);
    setIntegerParam(HDF5TotalFrames,    0);
    setIntegerParam(HDF5FirstFrame,     0);
    setIntegerParam(HDF5LastFrame,      0);
    setIntegerParam(HDF5CurrentFrame,   0);
    setIntegerParam(ADMaxSizeX,         0);
    setIntegerParam(ADMaxSizeY,         0);
    callParamCallbacks();

    // Get a file handle
    if((fileId = H5Fopen(path, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
    {
        asynPrint(pasynUserSelf, ASYN_TRACE_ERROR,
                "%s:%s couldn't open file '%s'\n",
                driverName, functionName, path);
        status = asynError;
        goto end;
    }

    // Get a handle to the '/entry' group
    if((groupId = H5Gopen2(fileId, "/entry", H5P_DEFAULT)) < 0)
    {
        asynPrint(pasynUserSelf, ASYN_TRACE_ERROR,
                "%s:%s couldn't open 'entry' group\n",
                driverName, functionName);
        status = asynError;
        goto closeFile;
    }

    // Need groupInfo to obtain number of links
    if(H5Gget_info(groupId, &groupInfo))
    {
        asynPrint(pasynUserSelf, ASYN_TRACE_ERROR,
                "%s:%s couldn't get group info\n",
                driverName, functionName);
        status = asynError;
        goto closeGroup;
    }

    // Deallocate information of previous file
    if(mpDatasets)
    {
        for(size_t i = 0; i < mDatasetsCount; ++i)
            H5Dclose(mpDatasets[i].id);
        free(mpDatasets);
    }

    // Allocate memory to store dataset information
    mpDatasets = (struct dsetInfo*) calloc(groupInfo.nlinks,
            sizeof(*mpDatasets));
    mDatasetsCount = 0;

    // Iterate over '/entry' objects
    for(size_t i = 0; i < groupInfo.nlinks; ++i)
    {
        // Get object name
        char dsetName[256];
        H5Lget_name_by_idx(groupId, ".", H5_INDEX_NAME, H5_ITER_INC, i,
                dsetName, sizeof(dsetName), H5P_DEFAULT);

        // If it doesn't start with 'data' it isn't a dataset. Ignore it.
        if(strncmp(dsetName, "data", 4))
            continue;

        // Get a handle to the dataset info structure
        struct dsetInfo *pDSet = &mpDatasets[mDatasetsCount++];
        pDSet->id = H5Dopen2(groupId, dsetName, H5P_DEFAULT);

        // Read dataset attributes
        H5LTget_attribute_int(pDSet->id, ".", "image_nr_low",
                &pDSet->imageNrLow);
        H5LTget_attribute_int(pDSet->id, ".", "image_nr_high",
                &pDSet->imageNrHigh);

        // Read dimensions (assume a 3D dataset)
        hsize_t dims[3] = {0,0,0};
        H5LTget_dataset_info(pDSet->id, ".", dims, NULL, NULL);
        totalFrames  += dims[0];
        pDSet->height = dims[1];
        pDSet->width  = dims[2];

        // Calculate maxHeight and maxWidth
        if(dims[1] > maxHeight)
            maxHeight = dims[1];

        if(dims[2] > maxWidth)
            maxWidth = dims[2];

        // Read type
        if(parseType(pDSet->id, &pDSet->type))
        {
            asynPrint(pasynUserSelf, ASYN_TRACE_ERROR,
                    "%s:%s couldn't parse dataset type\n",
                    driverName, functionName);
            status = asynError;
        }
    }

    // Update parameters
    setIntegerParam(HDF5DatasetsCount, (int) mDatasetsCount);
    setIntegerParam(HDF5TotalFrames,   (int) totalFrames);

    if(mDatasetsCount > 0)
    {
        int firstFrame = mpDatasets[0].imageNrLow;
        int lastFrame  = mpDatasets[mDatasetsCount-1].imageNrHigh;
        setIntegerParam(HDF5FirstFrame,   firstFrame);
        setIntegerParam(HDF5LastFrame,    lastFrame);
        setIntegerParam(HDF5CurrentFrame, firstFrame);
        setIntegerParam(ADMaxSizeX,       maxWidth);
        setIntegerParam(ADMaxSizeY,       maxHeight);

        int autoLoad;
        getIntegerParam(HDF5AutoLoadFrame, &autoLoad);
        if(autoLoad)
        {
            setIntegerParam(ADImageMode, ADImageSingle);
            setIntegerParam(ADNumImages, 1);
            setIntegerParam(ADAcquire,   1);
            epicsEventSignal(mStartEventId);
        }
    }

    callParamCallbacks();

closeGroup:
    H5Gclose(groupId);
closeFile:
    H5Fclose(fileId);
end:
    return status;
}
コード例 #14
0
ファイル: h5maxdiff.c プロジェクト: AStupidBear/Knet.jl
void rdiff(const char *name, hid_t f1, hid_t f2) {
  hid_t g1 = H5Gopen(f1, name, H5P_DEFAULT);
  hid_t g2 = H5Gopen(f2, name, H5P_DEFAULT);
  if (g1 >= 0 && g2 >= 0) {
    int n1 = H5Aget_num_attrs(g1);
    for (int i = 0; i < n1; i++) {
      char aname[MAXNAME];
      hid_t a1 = H5Aopen_idx(g1, i);
      assert(H5Aget_name(a1, MAXNAME, aname) < MAXNAME);
      H5Aclose(a1);
      if (!H5LTfind_attribute(g2, aname)) {
	printf("Only in %s[%s%s]\n", file1, name, aname);
	continue;
      }
      int d1, d2;
      H5LTget_attribute_ndims(f1, name, aname, &d1);
      H5LTget_attribute_ndims(f2, name, aname, &d2);
      assert(d1 <= 1 && d2 <= 1);
      hsize_t dims1, dims2;
      H5T_class_t t1, t2;
      size_t ts1, ts2;
      H5LTget_attribute_info(f1, name, aname, &dims1, &t1, &ts1);
      H5LTget_attribute_info(f2, name, aname, &dims2, &t2, &ts2);
      assert(t1 == t2);
      assert(t1 == H5T_INTEGER || t1 == H5T_FLOAT || t1 == H5T_STRING);
      if (t1 == H5T_INTEGER) {
	assert(d1==0 || (dims1 == 1 && dims2 == 1));
	assert(ts1 == 4 && ts2 == 4);
	int v1, v2;
	H5LTget_attribute_int(f1, name, aname, &v1);
	H5LTget_attribute_int(f2, name, aname, &v2);
	if (v1 != v2) {
	  printf("%s[%s%s]=%d %s[%s%s]=%d\n", file1, name, aname, v1, file2, name, aname, v2);
	}
      }
      if (t1 == H5T_FLOAT) {
	assert(d1==0 || (dims1 == 1 && dims2 == 1));
	assert(ts1 == 4 && ts2 == 4);
	float v1, v2;
	H5LTget_attribute_float(f1, name, aname, &v1);
	H5LTget_attribute_float(f2, name, aname, &v2);
	if (v1 != v2) {
	  printf("%s[%s%s]=%g %s[%s%s]=%g\n", file1, name, aname, v1, file2, name, aname, v2);
	}
      }
      if (t1 == H5T_STRING) {
	assert(ts1 < 256 && ts2 < 256);
	char buf1[256];
	char buf2[256];
	H5LTget_attribute_string(f1, name, aname, buf1);
	H5LTget_attribute_string(f2, name, aname, buf2);
	if (strcmp(buf1, buf2)) {
	  printf("%s[%s%s]=%s %s[%s%s]=%s\n", file1, name, aname, buf1, file2, name, aname, buf2);
	}
      }
    }
    int n2 = H5Aget_num_attrs(g2);
    for (int i = 0; i < n2; i++) {
      char aname[MAXNAME];
      hid_t a2 = H5Aopen_idx(g2, i);
      assert(H5Aget_name(a2, MAXNAME, aname) < MAXNAME);
      H5Aclose(a2);
      if (!H5LTfind_attribute(g1, aname)) {
	printf("Only in %s[%s%s]\n", file2, name, aname);
	continue;
      }
    }

    hsize_t nobj;
    H5Gget_num_objs(g1, &nobj);
    for (int i = 0; i < nobj; i++) {
      char oname[MAXNAME];
      assert(H5Gget_objname_by_idx(g1, i, oname, MAXNAME) < MAXNAME);
      int otype = H5Gget_objtype_by_idx(g1, i);
      assert(otype == H5G_DATASET);
      if (!H5LTfind_dataset(g2, oname)) {
	printf("Only in %s[%s%s]\n", file1, name, oname);
	continue;
      }
      hsize_t dims1[2], dims2[2];
      H5T_class_t t1, t2;
      size_t ts1, ts2;
      H5LTget_dataset_info(g1, oname, dims1, &t1, &ts1);
      H5LTget_dataset_info(g2, oname, dims2, &t2, &ts2);
      if (dims1[0] != dims2[0] || dims1[1] != dims2[1]) {
	printf("%s[%s%s](%d,%d) != %s[%s%s](%d,%d)\n", 
	       file1, name, oname, dims1[1], dims1[0],
	       file2, name, oname, dims2[1], dims2[0]);
	continue;
      }
      float *data1 = malloc(dims1[0]*dims1[1]*sizeof(float));
      float *data2 = malloc(dims1[0]*dims1[1]*sizeof(float));
      H5LTread_dataset_float(g1, oname, data1);
      H5LTread_dataset_float(g2, oname, data2);
      float maxdiff = 0;
      for (int i = dims1[0]*dims1[1]-1; i >= 0; i--) {
	float d = data1[i] - data2[i];
	if (d < 0) d = -d;
	if (d > maxdiff) maxdiff = d;
      }
      printf("max |%s[%s%s] - %s[%s%s]| = %g\n",
	     file1, name, oname, file2, name, oname, maxdiff);
      free(data1); free(data2);
    }
    H5Gget_num_objs(g2, &nobj);
    for (int i = 0; i < nobj; i++) {
      char oname[MAXNAME];
      assert(H5Gget_objname_by_idx(g2, i, oname, MAXNAME) < MAXNAME);
      int otype = H5Gget_objtype_by_idx(g2, i);
      assert(otype == H5G_DATASET);
      if (!H5LTfind_dataset(g1, oname)) {
	printf("Only in %s[%s%s]\n", file2, name, oname);
	continue;
      }
    }
    H5Gclose(g1);
    H5Gclose(g2);
  } else if (g1 >= 0) {
    printf("Only in %s:%s\n", file1, name);
    H5Gclose(g1);
  } else if (g2 >= 0) {
    printf("Only in %s:%s\n", file2, name);
    H5Gclose(g2);
  } else {
    printf("Group %s does not exist in either file.\n", name);
  }
}
コード例 #15
0
/***********************************************************************
 NAME:                     ias_ancillary_read

 PURPOSE:  Calls routines to read ancillary and ephemeris data

 RETURNS:  Integer status code of SUCCESS or ERROR

 NOTES:    Calling routine is responsible for ensuring a valid filename

************************************************************************/
int ias_ancillary_read
(
    const char *ancillary_filename,          /* I: Name of data file */
    IAS_ANC_ATTITUDE_DATA **attitude_data,   /* I/O: Pointer to attitude
                                                data */
    IAS_ANC_EPHEMERIS_DATA **ephemeris_data  /* I/O: Pointer to ephemeris
                                                data */
)
{
    hid_t hdf_file_id = -1;          /* HDF5 file handle */

    herr_t hdf_error_status = -1;    /* HDF5 error status code; negative
                                        values indicate an error */
    int file_format_version = 0;     /* File format version */
    int rank = 0;                    /* Number of dimensions for the
                                        format version attribute */

    H5T_class_t type_class;          /* Type class identifier */

    size_t type_size = 0;            /* Size of datatype in bytes */

    hsize_t version_dims = 0;        /* Format version array dimension */

    IAS_ANC_ATTITUDE_DATA *attitude_read = NULL;
    /* working attitude data buffer */

    IAS_ANC_EPHEMERIS_DATA *ephemeris_read = NULL;
    /* working ephemeris data buffer */


    /* Initialize the pointers so caller has something to check against */
    *attitude_data = NULL;
    *ephemeris_data = NULL;

    /* Make sure the ancillary file is "valid" */
    if (!ias_ancillary_is_ancillary_file(ancillary_filename))
    {
        IAS_LOG_ERROR("Ancillary file %s not valid", ancillary_filename);
        return ERROR;
    }

    /* Open the file for reading. */
    hdf_file_id = H5Fopen(ancillary_filename, H5F_ACC_RDONLY, H5P_DEFAULT);
    if (hdf_file_id < 0)
    {
        IAS_LOG_ERROR("Opening ancillary data file %s", ancillary_filename);
        return ERROR;
    }

    /* Verify the file format version attribute has a dimension of 1 */
    hdf_error_status = H5LTget_attribute_ndims(hdf_file_id, "/",
        FILE_FORMAT_VERSION_ATTRIBUTE_NAME, &rank);
    if (hdf_error_status < 0)
    {
        IAS_LOG_ERROR("Retrieving file format version attribute dimensions "
            "in ancillary file %s", ancillary_filename);
        return ERROR;
    }
    if (rank != 1)      /* Should only be 1D array */
    {
        IAS_LOG_ERROR("Invalid rank %d detected for file format version "
            "attribute in ancillary file %s, should be 1",
            rank, ancillary_filename);
        return ERROR;
    }

    /* The file format version attribute should be a scalar of integer
       data type*/
    hdf_error_status = H5LTget_attribute_info(hdf_file_id, "/",
        FILE_FORMAT_VERSION_ATTRIBUTE_NAME, &version_dims,
        &type_class, &type_size);
    if ((hdf_error_status < 0) || (version_dims != 1)
            || (type_class != H5T_INTEGER)
            || (type_size != sizeof(int)))
    {
        IAS_LOG_ERROR("Invalid file format version attribute information "
            "in ancillary file %s", ancillary_filename);
        return ERROR;
    }

    /* Read the file format version information */
    hdf_error_status = H5LTget_attribute_int(hdf_file_id, "/",
        FILE_FORMAT_VERSION_ATTRIBUTE_NAME, &file_format_version);
    if (hdf_error_status < 0) 
    {
        IAS_LOG_ERROR("Reading file format version attribute in ancillary "
            "file %s", ancillary_filename);
        H5Fclose(hdf_file_id);
        return ERROR;
    }

    /* Read the attitude data from the file.   */
    attitude_read = read_attitude_data(hdf_file_id, file_format_version);
    if (attitude_read == NULL)
    {
        IAS_LOG_ERROR("Reading attitude data from ancillary data file %s",
            ancillary_filename);
        H5Fclose(hdf_file_id);
        return ERROR;
    }

    /* Read the ephemeris data from the file.  */
    ephemeris_read = read_ephemeris_data(hdf_file_id, file_format_version);
    if (ephemeris_read == NULL)
    {
        IAS_LOG_ERROR("Reading ephemeris data from ancillary data file %s",
            ancillary_filename);
        ias_ancillary_free_attitude(attitude_read);
        H5Fclose(hdf_file_id);
        return ERROR;
    }

    /* Close the file now that the attitude and ephemeris data have been
       read from it. */
    hdf_error_status = H5Fclose(hdf_file_id);
    if (hdf_error_status < 0)
    {
        IAS_LOG_ERROR("Closing ancillary data file %s", ancillary_filename);
        ias_ancillary_free_attitude(attitude_read);
        ias_ancillary_free_ephemeris(ephemeris_read);
        return ERROR;
    }

    /* Point the input pointers to the working buffers. */
    *attitude_data = attitude_read;
    *ephemeris_data = ephemeris_read;

    /* Done */
    return SUCCESS;
}
コード例 #16
0
ファイル: sparx-io.c プロジェクト: itahsieh/sparx-alpha
int SpIO_FreadModel(const SpFile *sfp, const SpFile *popsfp, SpModel *model, int *read_pops)
{
	int status = 0;

	Deb_ASSERT(model->parms.mol == NULL);
	Deb_ASSERT(model->grid == NULL);
#if 1
        /* pre-check format version */
        if(!status){
                const char *default_format = "SPARX format v3";
                char *format = NULL;
                
                status = SpIO_H5GetAttribute_string(sfp->h5f_id, "/", "format", &format);
                if(strncmp(format, default_format, strlen("SPARX format v3"))){
                        printf("The format is not '%s' (%s)\n", default_format, format);
                        status = 1;
                }
                free(format);
        }
#endif 

        /* Read coordinate name */
        if(!status){
                char *coordinate = NULL;
                status = SpIO_H5GetAttribute_string(sfp->h5f_id, "/", "geom", &coordinate);
                /* Load molecule if present */
                if(strlen(coordinate) > 0) {
                        DatINode *geom = Dat_IList_NameLookup(GEOM_TYPES, coordinate);
                        model->parms.geom = geom->idx;
                }
                free(coordinate);
        }

        herr_t hstatus;

        /* Read T_cmb */
        if(!status) {
                hstatus = H5LTget_attribute_double(sfp->h5f_id, "/", "T_cmb", &model->parms.T_cmb);
                if(hstatus < 0)
                        status = 1;
        }
        /* Read T_in */
        if(!status) {
                hstatus = H5LTget_attribute_double(sfp->h5f_id, "/", "T_in", &model->parms.T_in);
                if(hstatus < 0)
                        status = 1;
        }
	/* Read molecule name */
	if(!status){
                char *mol_name = NULL;
		status = SpIO_H5GetAttribute_string(sfp->h5f_id, "/", "molec", &mol_name);

                /* Load molecule if present */
                if(strlen(mol_name) > 0) {
                        if(!(model->parms.mol = SpIO_FreadMolec(mol_name)))
                                status = 1;
                }
                free(mol_name);
        }

        /* Read pops-switch */
        if(!status) {
                hstatus = H5LTget_attribute_int(sfp->h5f_id, "/", "pops", &model->parms.pops);
                if(hstatus < 0)
                        status = 1;
        }
        /* Read dust-switch */
        if(!status) {
                hstatus = H5LTget_attribute_int(sfp->h5f_id, "/", "dust", &model->parms.dust);
                if(hstatus < 0)
                        status = 1;
        }
        /* Read polariz-switch */
        if(!status) {
                hstatus = H5LTget_attribute_int(sfp->h5f_id, "/", "polariz", &model->parms.polariz);
                if(hstatus < 0)
                        status = 1;
        }
        /* Read z (zeeman splitting) factor */
        if(!status) {
                hstatus = H5LTget_attribute_int(sfp->h5f_id, "/", "z", &model->parms.z);
                if(hstatus < 0)
                        status = 1;
        }

#if 0 
	/* Set velocity field: the "velfield" attribute is expected
	 * to contain a Python function named "Vgas((x1,x2,x3),(min1,min2,min3),(max1,max2,max3)" where
	 * (x1,x2,x3) are the three coordinates of the ray position, (min1,min2,min3) are the lower
	 * bounds of the bounding box, and (max1,max2,max3) are the upper baounds of the bounding
	 * box. An example Vgas function would be:
	 * def Vgas((x1, x2, x3), (min1, min2, min3), (max1, max2, max3)):"
	 *	return [0,0,0]"
	 */
	if(!status) {
                char *velfield = NULL;
		//if(!strncmp(velfield, "grid", strlen(velfield))) {
		if(!strncmp(velfield, "grid", strlen("grid"))) {
			model->parms.velfield = NULL;
		}
		else {
			status = PyRun_SimpleString(velfield);
			PyObject *__main__ = NULL, *ret = NULL;
			__main__ = PyImport_AddModule("__main__");
			model->parms.velfield = PyObject_GetAttrString(__main__, "Vgas");
			Py_INCREF(model->parms.velfield);
			/* Try calling the function and make sure it returns a sequence of length 3 */
                        char format[] = "(d,d,d),(d,d,d),(d,d,d)";
			ret = PyObject_CallFunction(model->parms.velfield, format, 0, 0, 0, 0, 0, 0, 0, 0, 0);
			if(!PySequence_Check(ret)) {
				PyWrErr_SetString(PyExc_Exception, "Vgas() does not return a vector!");
				status = 1;
			}
		}
		
		free(velfield);
	}
#endif


	/* Load grid */	
	if(!status)
		status = 
		SpIO_H5ReadGrid( 
                        sfp->h5f_id, 
                        (*read_pops) ? popsfp->h5f_id : NULL, 
                        &model->grid, 
                        &model->parms, 
                        read_pops
                );
	/* Cleanup */		

	if(status)
		PyWrErr_SetString(PyExc_Exception, "Error reading model from file `%s'", sfp->name);

	return status;
}