Exemplo n.º 1
0
int_f
nh5ltget_attribute_info_c(hid_t_f *loc_id,
                        int_f *namelen,
                        _fcd name,
                        int_f *attrnamelen,
                        _fcd attrname,
                        hsize_t_f *dims,
                        int_f *type_class,
                        size_t_f *type_size)
{
 int          ret_value = -1;
 herr_t       ret;
 hid_t        c_loc_id;
 char         *c_name;
 char         *c_attrname;
 int          c_namelen;
 int          c_attrnamelen;
 H5T_class_t  c_classtype;
 size_t       c_type_size;
 hsize_t      c_dims[32];
 int          i;
 int          c_rank;

/*
 * Convert FORTRAN name to C name
 */
 c_namelen = (int)*namelen;
 c_name = (char *)HD5f2cstring(name, c_namelen);
 if (c_name == NULL) return ret_value;

 c_attrnamelen = (int)*attrnamelen;
 c_attrname = (char *)HD5f2cstring(attrname, c_attrnamelen);
 if (c_attrname == NULL) return ret_value;

/*
 * Call H5LTget_attribute_info function.
 */
 c_loc_id = (hid_t)*loc_id;

 ret = H5LTget_attribute_info(c_loc_id,c_name,c_attrname,c_dims,&c_classtype,&c_type_size);
 if (ret < 0) return ret_value;

 *type_class = c_classtype;
 *type_size = (size_t_f)c_type_size;

/*
 * Transpose dimension arrays because of C-FORTRAN storage order
 */

 ret = H5LTget_attribute_ndims(c_loc_id,c_name,c_attrname,&c_rank);
 if (ret < 0) return ret_value;

 for (i = 0; i < c_rank ; i++) {
  dims[i] = (hsize_t_f) c_dims[c_rank - i - 1];
 }

 ret_value = 0;
 return ret_value;
}
Exemplo n.º 2
0
/* ------- 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;
}
Exemplo n.º 3
0
/* ------- 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;
}
Exemplo n.º 4
0
/* ------- 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;
}
Exemplo n.º 5
0
/* ------- 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;
}
Exemplo n.º 6
0
/* ------- begin --------------------------   init_hdf5_indata_old.c  --- */
void init_hdf5_indata_existing(void)
/* Opens an existing NetCDF input data file, loads structures and ids */
{
  const char routineName[] = "init_hdf5_indata_existing";
  int     ncid;
  size_t  attr_size;
  hid_t   plist;
  char   *atmosID;
  H5T_class_t type_class;

  /* 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(INPUTDATA_FILE, H5F_ACC_RDWR, plist) ) < 0)
    HERR(routineName);
  if (( H5Pclose(plist) ) < 0) HERR(routineName);
  io.in_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);
  /* Get group IDs */
  if (( io.in_input_ncid = H5Gopen(ncid, "input", H5P_DEFAULT) ) < 0)
      HERR(routineName);
  if (( io.in_atmos_ncid = H5Gopen(ncid, "atmos", H5P_DEFAULT) ) < 0)
      HERR(routineName);
  if (( io.in_mpi_ncid = H5Gopen(ncid, "mpi", H5P_DEFAULT) ) < 0)
      HERR(routineName);
  /* --- Open datasets collectively ---*/
  if (( io.in_atmos_T = H5Dopen(io.in_atmos_ncid, "temperature",
                                H5P_DEFAULT) ) < 0) HERR(routineName);
  if (( io.in_atmos_vz = H5Dopen(io.in_atmos_ncid, "velocity_z",
                                H5P_DEFAULT) ) < 0) HERR(routineName);
  if (( io.in_atmos_z = H5Dopen(io.in_atmos_ncid, "height",
                                H5P_DEFAULT) ) < 0) HERR(routineName);

  if (( io.in_mpi_tm = H5Dopen(io.in_mpi_ncid, TASK_MAP,
                               H5P_DEFAULT) ) < 0) HERR(routineName);
  if (( io.in_mpi_tn = H5Dopen(io.in_mpi_ncid, TASK_NUMBER,
                               H5P_DEFAULT) ) < 0) HERR(routineName);
  if (( io.in_mpi_it = H5Dopen(io.in_mpi_ncid, ITER_NAME,
                               H5P_DEFAULT) ) < 0) HERR(routineName);
  if (( io.in_mpi_conv = H5Dopen(io.in_mpi_ncid, CONV_NAME,
                               H5P_DEFAULT) ) < 0) HERR(routineName);
  if (( io.in_mpi_dm = H5Dopen(io.in_mpi_ncid, DM_NAME,
                               H5P_DEFAULT) ) < 0) HERR(routineName);
  if (( io.in_mpi_dmh = H5Dopen(io.in_mpi_ncid, DMH_NAME,
                               H5P_DEFAULT) ) < 0) HERR(routineName);
  if (( io.in_mpi_zc = H5Dopen(io.in_mpi_ncid, ZC_NAME,
                               H5P_DEFAULT) ) < 0) HERR(routineName);
  return;
}
Exemplo n.º 7
0
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;
}
Exemplo n.º 8
0
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);
  }
}
/***********************************************************************
 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;
}
/*----------------------------------------------------------------------
 NAME:                     read_epoch_time

 PURPOSE:  Reads the requested epoch time attribute from the ancillary
           data file

 RETURNS:  Integer status code of SUCCESS or ERROR

-------------------------------------------------------------------------*/
static int read_epoch_time
(
    hid_t hdf_file_id,       /* I:  Open ancillary data file handle */
    const char *epoch_name,  /* I:  Epoch time name  */
    double epoch_time[3]     /* O:  Array containing epoch time components */
)
{
    herr_t hdf_error_status = -1;    /* HDF5 error status code    */

    hsize_t epoch_dims = 0;          /* Epoch array dimension */

    H5T_class_t type_class;          /* Type class identifier */

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

    int rank = 0;                    /* Number of dimensions for the
                                        epoch time attribute   */


    /* Verify the epoch time array attribute has an array dimension of 1 */
    hdf_error_status = H5LTget_attribute_ndims(hdf_file_id, "/",
        epoch_name, &rank);
    if (hdf_error_status < 0)
    {
        IAS_LOG_ERROR("Retrieving epoch time attribute dimensions");
        return ERROR;
    }
    if (rank != 1)      /* Should only be 1D array */
    {
        IAS_LOG_ERROR("Invalid rank %d detected for epoch time array, "
            "should be 1", rank);
        return ERROR;
    }

    /* The epoch time attribute should be a 1D, 3-element array of datatype
       double */
    hdf_error_status = H5LTget_attribute_info(hdf_file_id, "/",
        epoch_name, &epoch_dims, &type_class, &type_size);
    if ((hdf_error_status < 0) || (epoch_dims != 3)
            || (type_class != H5T_FLOAT)
            || (type_size != sizeof(double)))
    {
        IAS_LOG_ERROR("Invalid epoch time array dimensions/datatype class/"
            "datatype size information");
        return ERROR;
    }

    /* Now get the epoch time components */
    hdf_error_status = H5LTget_attribute_double(hdf_file_id, "/",
        epoch_name, epoch_time);
    if (hdf_error_status < 0)
    {
        IAS_LOG_ERROR("Retrieving epoch time attribute values");
        return ERROR;
    }

   

    /* Done */
    return SUCCESS;
}