Пример #1
0
// Write float attribute <attr_name> given by address <path>
char AH5_write_flt_attr(hid_t loc_id, const char *path, char* attr_name, const float wdata)
{
    char success = AH5_FALSE;

    if (AH5_path_valid(loc_id, path))
        if (H5LTset_attribute_float(loc_id, path, attr_name, &wdata, 1) >= 0)
            success = AH5_TRUE;

    return success;
}
Пример #2
0
void dump_particles_hdf(char *outfile, struct PList * p)
{
    hid_t    file_id,group_id;
    herr_t      status;
    size_t     i, j,nread=0;
    hsize_t dims[2];

    //if(try_readfile(outfile))
    file_id = H5Fcreate (outfile, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); //always create a new file or overwite existing file
//     group_id = HDFcreate_group(file_id, "/PartType0");
//     status = H5Gclose(group_id);

    float (* pos)[3],(* vel)[3];
    pos=malloc(sizeof(float)*3*p->np);
    vel=malloc(sizeof(float)*3*p->np);
    for(i=0;i<p->np;i++)
    {
      for(j=0;j<3;j++)
      {
	pos[i][j]=(Particles.Pos[p->PIndex[i]][j]-CoM[j])*LUNIT;
	vel[i][j]=Particles.Vel[p->PIndex[i]][j]-VCoM[j];
      }
    }
    dims[0]=p->np;
    dims[1]=3;
    status = H5LTmake_dataset(file_id,"/x",2,dims,H5T_NATIVE_FLOAT,pos);
    status = H5LTmake_dataset(file_id,"/v",2,dims,H5T_NATIVE_FLOAT,vel);
	H5LTset_attribute_float(file_id, "/x", "x0", CoM, 3);
	H5LTset_attribute_float(file_id, "/v", "v0", VCoM, 3);
	
	dims[0]=p->np;
    dims[1]=1;
    status = H5LTmake_dataset(file_id,"/Pid",2,dims,H5T_NATIVE_INT,p->PIndex);
		
    /* close file */
    status = H5Fclose (file_id);
    printf("Pos[1]: (%g,%g,%g)\n",pos[1][0],pos[1][1],pos[1][2]);
    free(pos);
    free(vel);
}
Пример #3
0
int_f
nh5ltset_attribute_float_c(hid_t_f *loc_id,
                           int_f *namelen,
                           _fcd dsetname,
                           int_f *attrnamelen,
                           _fcd attrname,
                           size_t_f *size,
                           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;
    size_t  c_size;

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

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

    /*
    * Call H5LTset_attribute_float function.
    */
    c_loc_id = (hid_t)*loc_id;
    c_size   = (size_t)*size;

    ret = H5LTset_attribute_float(c_loc_id,c_name,c_attrname,buf,c_size);

    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;
}
Пример #4
0
int pioAddAttributeFloat(PIOObject pioObject,
						 const char* attr_name, float attr_value)
{
	if (pioAttributeIsProtected(attr_name)) 
	{
		fprintf(stdout, 
				"WARNING: Attribute name %s is a reserved for pinocchIO internal use.\n",
				attr_name);		
		return -1;
	}
	return H5LTset_attribute_float(pioObject.identifier, ".",
								   attr_name, &attr_value, 1);
}
Пример #5
0
/* ------- begin --------------------------   init_aux_new.c --   --- */
void init_aux_new(void) {
  /* Creates the HDF5 file for the auxiliary data */
  const char routineName[] = "init_aux_new";
  unsigned int *tmp;
  double   *tmp_double;
  int       i;
  hid_t     plist, ncid, file_dspace, ncid_atom, ncid_mol;
  hid_t     id_x, id_y, id_z, id_n, id_tmp;
  hsize_t   dims[4];
  char      group_name[ARR_STRLEN];
  Atom     *atom;
  Molecule *molecule;

  /* Create the file  */
  if (( plist = H5Pcreate(H5P_FILE_ACCESS) ) < 0) HERR(routineName);
  if (( H5Pset_fapl_mpio(plist, mpi.comm, mpi.info) ) < 0) HERR(routineName);
  if (( ncid = H5Fcreate(AUX_FILE, H5F_ACC_TRUNC, H5P_DEFAULT,
                         plist) ) < 0) HERR(routineName);
  if (( H5Pclose(plist) ) < 0) HERR(routineName);


  /* --- Definitions for the root group --- */
  /* dimensions as attributes */
  if (( H5LTset_attribute_int(ncid, "/", "nx", &mpi.nx, 1) ) < 0)
      HERR(routineName);
  if (( H5LTset_attribute_int(ncid, "/", "ny", &mpi.ny, 1) ) < 0)
      HERR(routineName);
  if (( H5LTset_attribute_int(ncid, "/", "nz", (int *) &infile.nz, 1 )) < 0)
      HERR(routineName);
  /* attributes */
  if (( H5LTset_attribute_string(ncid, "/", "atmosID", atmos.ID)) < 0)
    HERR(routineName);
  if (( H5LTset_attribute_string(ncid, "/", "rev_id", mpi.rev_id) ) < 0)
    HERR(routineName);

  /* 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));
  }


  /* Fill value */
  if (( plist = H5Pcreate(H5P_DATASET_CREATE) ) < 0) HERR(routineName);
  if (( H5Pset_fill_value(plist, H5T_NATIVE_FLOAT, &FILLVALUE) ) < 0)
      HERR(routineName);
  if (( H5Pset_alloc_time(plist, H5D_ALLOC_TIME_EARLY) ) < 0) HERR(routineName);
  if (( H5Pset_fill_time(plist, H5D_FILL_TIME_ALLOC) ) < 0) HERR(routineName);

  /* --- Group loop over active ATOMS --- */
  for (i=0; i < atmos.Nactiveatom; i++) {
    atom = atmos.activeatoms[i];
    /* Get group name */
    sprintf(group_name, (atom->ID[1] == ' ') ? "atom_%.1s" : "atom_%.2s",
            atom->ID);
    if (( ncid_atom = H5Gcreate(ncid, group_name, H5P_DEFAULT, H5P_DEFAULT,
                                H5P_DEFAULT) ) < 0) HERR(routineName);
    io.aux_atom_ncid[i] = ncid_atom;
    /* --- dimensions as attributes --- */
    if (( H5LTset_attribute_int(ncid_atom, ".", "nlevel",
                                &atom->Nlevel, 1)) < 0) HERR(routineName);
    if (( H5LTset_attribute_int(ncid_atom, ".", "nline",
                                &atom->Nline, 1)) < 0) HERR(routineName);
    if (( H5LTset_attribute_int(ncid_atom, ".", "ncontinuum",
                                &atom->Ncont, 1)) < 0) HERR(routineName);
    /* --- dimension datasets --- */
    dims[0] = mpi.nx;
    if (( H5LTmake_dataset(ncid_atom, X_NAME, 1, dims, H5T_NATIVE_DOUBLE,
                           geometry.xscale) ) < 0)  HERR(routineName);
    if (( id_x = H5Dopen2(ncid_atom, X_NAME, H5P_DEFAULT)) < 0) HERR(routineName);
    dims[0] = mpi.ny;
    if (( H5LTmake_dataset(ncid_atom, Y_NAME, 1, dims, H5T_NATIVE_DOUBLE,
                           geometry.yscale) ) < 0)  HERR(routineName);
    if (( id_y = H5Dopen2(ncid_atom, Y_NAME, H5P_DEFAULT)) < 0) HERR(routineName);
    dims[0] = infile.nz;
    tmp_double = (double *) calloc(infile.nz , sizeof(double));
    if (( H5LTmake_dataset(ncid_atom, ZOUT_NAME, 1, dims, H5T_NATIVE_DOUBLE,
                           tmp_double) ) < 0)  HERR(routineName);
    free(tmp_double);
    if (( id_z = H5Dopen2(ncid_atom, ZOUT_NAME, H5P_DEFAULT)) < 0) HERR(routineName);
    dims[0] = atom->Nlevel;
    tmp = (unsigned int *) calloc(atom->Nlevel , sizeof(unsigned int));
    if (( H5LTmake_dataset(ncid_atom, LEVEL_NAME, 1, dims, H5T_NATIVE_UINT,
                           tmp) ) < 0)  HERR(routineName);
    free(tmp);
    dims[0] = atom->Nline;
    tmp = (unsigned int *) calloc(atom->Nline , sizeof(unsigned int));
    if (( H5LTmake_dataset(ncid_atom, LINE_NAME, 1, dims, H5T_NATIVE_UINT,
                           tmp) ) < 0)  HERR(routineName);
    free(tmp);
    if (atom->Ncont > 0) {
        dims[0] = atom->Ncont;
        tmp = (unsigned int *) calloc(atom->Ncont , sizeof(unsigned int));
        if (( H5LTmake_dataset(ncid_atom, CONT_NAME, 1, dims, H5T_NATIVE_UINT,
                               tmp) ) < 0)  HERR(routineName);
        free(tmp);
    }
    /* For compatibility with netCDF readers, only use dataset as dimension */
    if (( H5LTset_attribute_string(ncid_atom, ZOUT_NAME, "NAME",
                                   NETCDF_COMPAT) ) < 0) HERR(routineName);
    if (( H5LTset_attribute_string(ncid_atom, LEVEL_NAME, "NAME",
                                   NETCDF_COMPAT) ) < 0) HERR(routineName);
    if (( H5LTset_attribute_string(ncid_atom, LINE_NAME, "NAME",
                                   NETCDF_COMPAT) ) < 0) HERR(routineName);
    if (atom->Ncont > 0) {
        if (( H5LTset_attribute_string(ncid_atom, CONT_NAME, "NAME",
                                       NETCDF_COMPAT) ) < 0) HERR(routineName);
    }
    /* --- variables --- */
    dims[0] = atom->Nlevel;
    dims[1] = mpi.nx;
    dims[2] = mpi.ny;
    dims[3] = infile.nz;
    /* Populations */
    if (input.p15d_wpop) {
      if (( file_dspace = H5Screate_simple(4, dims, NULL) ) < 0)
        HERR(routineName);
      if (( id_n = H5Dopen2(ncid_atom, LEVEL_NAME,
                            H5P_DEFAULT)) < 0) HERR(routineName);
      if (atom->n != NULL) {
        if (( id_tmp = H5Dcreate(ncid_atom, POP_NAME, H5T_NATIVE_FLOAT,
                                 file_dspace, H5P_DEFAULT,
                                 plist, H5P_DEFAULT)) < 0) HERR(routineName);
        if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName);
        if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName);
        if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName);
        if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName);
        if (( H5LTset_attribute_float(ncid_atom, POP_NAME, "_FillValue",
                                      &FILLVALUE, 1) ) < 0) HERR(routineName);
        io.aux_atom_pop[i] = id_tmp;
      }
      if (atom->nstar != NULL) {
        if (( id_tmp = H5Dcreate(ncid_atom, POPLTE_NAME, H5T_NATIVE_FLOAT,
                                 file_dspace, H5P_DEFAULT,
                                 plist, H5P_DEFAULT)) < 0) HERR(routineName);
        if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName);
        if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName);
        if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName);
        if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName);
        if (( H5LTset_attribute_float(ncid_atom, POPLTE_NAME, "_FillValue",
                                      &FILLVALUE, 1) ) < 0) HERR(routineName);
        io.aux_atom_poplte[i] = id_tmp;
      }
      if (( H5Dclose(id_n) ) < 0) HERR(routineName);
      if (( H5Sclose(file_dspace) ) < 0) HERR(routineName);
    }
    if (input.p15d_wrates) {
      /* Radiative rates */
      dims[0] = atom->Nline;
      dims[1] = mpi.nx;
      dims[2] = mpi.ny;
      dims[3] = infile.nz;
      if (( file_dspace = H5Screate_simple(4, dims, NULL) ) < 0) HERR(routineName);
      if (( id_n = H5Dopen2(ncid_atom, LINE_NAME,
                            H5P_DEFAULT)) < 0) HERR(routineName);
      if (( id_tmp = H5Dcreate(ncid_atom, RIJ_L_NAME, H5T_NATIVE_FLOAT,
                               file_dspace, H5P_DEFAULT, plist,
                               H5P_DEFAULT)) < 0) HERR(routineName);
      if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName);
      if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName);
      if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName);
      if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName);
      if (( H5LTset_attribute_float(ncid_atom, RIJ_L_NAME, "_FillValue",
                                    &FILLVALUE, 1) ) < 0) HERR(routineName);
      io.aux_atom_RijL[i] = id_tmp;
      if (( id_tmp = H5Dcreate(ncid_atom, RJI_L_NAME, H5T_NATIVE_FLOAT,
                               file_dspace, H5P_DEFAULT, plist,
                               H5P_DEFAULT)) < 0) HERR(routineName);
      if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName);
      if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName);
      if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName);
      if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName);
      if (( H5LTset_attribute_float(ncid_atom, RJI_L_NAME, "_FillValue",
                                    &FILLVALUE, 1) ) < 0) HERR(routineName);
      io.aux_atom_RjiL[i] = id_tmp;
      if (( H5Dclose(id_n) ) < 0) HERR(routineName);
      if (( H5Sclose(file_dspace) ) < 0) HERR(routineName);
      if (atom->Ncont > 0) {
          dims[0] = atom->Ncont;
          if (( file_dspace = H5Screate_simple(4, dims, NULL) ) < 0)
            HERR(routineName);
          if (( id_n = H5Dopen2(ncid_atom, CONT_NAME,
                                H5P_DEFAULT)) < 0) HERR(routineName);
          if (( id_tmp = H5Dcreate(ncid_atom, RIJ_C_NAME, H5T_NATIVE_FLOAT,
                                   file_dspace, H5P_DEFAULT,  plist,
                                   H5P_DEFAULT)) < 0) HERR(routineName);
          if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName);
          if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName);
          if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName);
          if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName);
          if (( H5LTset_attribute_float(ncid_atom, RIJ_C_NAME, "_FillValue",
                                        &FILLVALUE, 1) ) < 0) HERR(routineName);
          io.aux_atom_RijC[i] = id_tmp;
          if (( id_tmp = H5Dcreate(ncid_atom, RJI_C_NAME, H5T_NATIVE_FLOAT,
                                   file_dspace, H5P_DEFAULT, plist,
                                   H5P_DEFAULT)) < 0) HERR(routineName);
          if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName);
          if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName);
          if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName);
          if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName);
          if (( H5LTset_attribute_float(ncid_atom, RJI_C_NAME, "_FillValue",
                                        &FILLVALUE, 1) ) < 0) HERR(routineName);
          io.aux_atom_RjiC[i] = id_tmp;
          if (( H5Dclose(id_n) ) < 0) HERR(routineName);
          if (( H5Sclose(file_dspace) ) < 0) HERR(routineName);
      }
    }
  if (( H5Dclose(id_x) ) < 0) HERR(routineName);
  if (( H5Dclose(id_y) ) < 0) HERR(routineName);
  if (( H5Dclose(id_z) ) < 0) HERR(routineName);
  }   /* end active ATOMS loop */

  /* --- Group loop over active MOLECULES --- */
  for (i=0; i < atmos.Nactivemol; i++) {
    molecule = atmos.activemols[i];
    /* Get group name */
    sprintf( group_name, "molecule_%s", molecule->ID);
    if (( ncid_mol = H5Gcreate(ncid, group_name, H5P_DEFAULT, H5P_DEFAULT,
                                H5P_DEFAULT) ) < 0) HERR(routineName);
    io.aux_mol_ncid[i] = ncid_mol;
    /* --- dimensions as attributes --- */
    if (( H5LTset_attribute_int(ncid_mol, ".", "nlevel_vibr",
                                &molecule->Nv, 1)) < 0) HERR(routineName);
    if (( H5LTset_attribute_int(ncid_mol, ".", "nline_molecule",
                                &molecule->Nrt, 1)) < 0) HERR(routineName);
    if (( H5LTset_attribute_int(ncid_mol, ".", "nJ",
                                &molecule->NJ, 1)) < 0) HERR(routineName);
    /* --- dimension datasets --- */
    dims[0] = mpi.nx;
    if (( H5LTmake_dataset(ncid_mol, X_NAME, 1, dims, H5T_NATIVE_DOUBLE,
                           geometry.xscale) ) < 0)  HERR(routineName);
    if (( id_x = H5Dopen2(ncid_mol, X_NAME, H5P_DEFAULT)) < 0) HERR(routineName);
    dims[0] = mpi.ny;
    if (( H5LTmake_dataset(ncid_mol, Y_NAME, 1, dims, H5T_NATIVE_DOUBLE,
                           geometry.yscale) ) < 0)  HERR(routineName);
    if (( id_y = H5Dopen2(ncid_mol, Y_NAME, H5P_DEFAULT)) < 0) HERR(routineName);
    dims[0] = infile.nz;
    tmp_double = (double *) calloc(infile.nz , sizeof(double));
    if (( H5LTmake_dataset(ncid_mol, ZOUT_NAME, 1, dims, H5T_NATIVE_DOUBLE,
                           tmp_double) ) < 0)  HERR(routineName);
    free(tmp_double);
    if (( id_z = H5Dopen2(ncid_mol, ZOUT_NAME, H5P_DEFAULT)) < 0) HERR(routineName);
    dims[0] = molecule->Nv;
    tmp = (unsigned int *) calloc(molecule->Nv, sizeof(unsigned int));
    if (( H5LTmake_dataset(ncid_mol, VLEVEL_NAME, 1, dims, H5T_NATIVE_UINT,
                           tmp) ) < 0)  HERR(routineName);
    free(tmp);
    dims[0] = molecule->Nrt;
    tmp = (unsigned int *) calloc(molecule->Nrt, sizeof(unsigned int));
    if (( H5LTmake_dataset(ncid_mol, VLINE_NAME, 1, dims, H5T_NATIVE_UINT,
                           tmp) ) < 0)  HERR(routineName);
    free(tmp);
    dims[0] = molecule->NJ;
    tmp = (unsigned int *) calloc(molecule->NJ, sizeof(unsigned int));
    if (( H5LTmake_dataset(ncid_mol, NJ_NAME, 1, dims, H5T_NATIVE_UINT,
                           tmp) ) < 0)  HERR(routineName);
    free(tmp);
    /* For compatibility with netCDF readers, only use dataset as dimension */
    if (( H5LTset_attribute_string(ncid_mol, ZOUT_NAME, "NAME",
                                   NETCDF_COMPAT) ) < 0) HERR(routineName);
    if (( H5LTset_attribute_string(ncid_mol, VLEVEL_NAME, "NAME",
                                   NETCDF_COMPAT) ) < 0) HERR(routineName);
    if (( H5LTset_attribute_string(ncid_mol, VLINE_NAME, "NAME",
                                   NETCDF_COMPAT) ) < 0) HERR(routineName);
    if (( H5LTset_attribute_string(ncid_mol, NJ_NAME, "NAME",
                                   NETCDF_COMPAT) ) < 0) HERR(routineName);
    /* --- variables --- */
    dims[0] = molecule->Nv;
    dims[1] = mpi.nx;
    dims[2] = mpi.ny;
    dims[3] = infile.nz;
    /* Populations */
    if (input.p15d_wpop) {
      if (( file_dspace = H5Screate_simple(4, dims, NULL) ) < 0)
        HERR(routineName);
      if (( id_n = H5Dopen2(ncid_mol, VLEVEL_NAME,
                            H5P_DEFAULT)) < 0) HERR(routineName);
      if (molecule->nv != NULL) {
        if (( id_tmp = H5Dcreate(ncid_mol, POP_NAME, H5T_NATIVE_FLOAT,
                                 file_dspace, H5P_DEFAULT, plist,
                                 H5P_DEFAULT)) < 0) HERR(routineName);
        if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName);
        if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName);
        if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName);
        if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName);
        io.aux_mol_pop[i] = id_tmp;
      }
      if (molecule->nvstar != NULL) {
        if (( id_tmp = H5Dcreate(ncid_mol, POPLTE_NAME, H5T_NATIVE_FLOAT,
                                 file_dspace, H5P_DEFAULT, plist,
                                 H5P_DEFAULT)) < 0) HERR(routineName);
        if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName);
        if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName);
        if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName);
        if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName);
        io.aux_mol_poplte[i] = id_tmp;
      }
      if (( H5Dclose(id_n) ) < 0) HERR(routineName);
      if (( H5Sclose(file_dspace) ) < 0) HERR(routineName);
      // TODO:  molecule->Ediss, molecule->Tmin, molecule->Tmax
    }
  if (( H5Dclose(id_x) ) < 0) HERR(routineName);
  if (( H5Dclose(id_y) ) < 0) HERR(routineName);
  if (( H5Dclose(id_z) ) < 0) HERR(routineName);
  } /* end active MOLECULES loop */
  io.aux_ncid = ncid;   /* Copy stuff to the IO data struct */
  if (( H5Pclose(plist) ) < 0) HERR(routineName);  /* Free hdf5 resources */
  /* Flush ensures file is created in case of crash */
  if (( H5Fflush(ncid, H5F_SCOPE_LOCAL) ) < 0) HERR(routineName);
  return;
}
Пример #6
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;
}