Exemplo n.º 1
0
//-*****************************************************************************
AwImpl::AwImpl( const std::string &iFileName,
                const AbcA::MetaData &iMetaData )
  : m_fileName( iFileName )
  , m_metaData( iMetaData )
  , m_file( -1 )
{

    // add default time sampling
    AbcA::TimeSamplingPtr ts( new AbcA::TimeSampling() );
    m_timeSamples.push_back(ts);

    // OPEN THE FILE!
    hid_t faid = H5Pcreate( H5P_FILE_ACCESS );
    if ( faid < 0 )
    {
        ABCA_THROW( "Could not create property access for fopen" );
    }
    H5Pset_libver_bounds( faid, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST );

    m_file = H5Fcreate( m_fileName.c_str(),
                        H5F_ACC_TRUNC, H5P_DEFAULT,
                        faid );

    H5Pclose( faid );

    if ( m_file < 0 )
    {
        ABCA_THROW( "Could not open file: " << m_fileName );
    }

    // set the version using HDF5 native calls
    // This expresses the AbcCoreHDF5 version - how properties,
    // are stored within HDF5, etc.
    int version = ALEMBIC_HDF5_FILE_VERSION;
    H5LTset_attribute_int(m_file, ".", "abc_version", &version, 1);

    // This is the Alembic library version XXYYZZ
    // Where XX is the major version, YY is the minor version
    // and ZZ is the patch version
    int libraryVersion = ALEMBIC_LIBRARY_VERSION;
    H5LTset_attribute_int(m_file, ".", "abc_release_version", 
        &libraryVersion, 1);

    m_metaData.set("_ai_AlembicVersion", AbcA::GetLibraryVersion());

    // Create top explicitly.
    m_top = new TopOwImpl( *this, m_file, m_metaData );
}
Exemplo n.º 2
0
static void
psc_fields_single_write(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);
  ierr = H5LTset_attribute_int(group, ".", "p", &flds->p, 1); CE;
  ierr = H5LTset_attribute_int(group, ".", "ib", flds->ib, 3); CE;
  ierr = H5LTset_attribute_int(group, ".", "im", flds->im, 3); CE;
  ierr = H5LTset_attribute_int(group, ".", "nr_comp", &flds->nr_comp, 1); CE;
  // write components separately instead?
  hsize_t hdims[4] = { flds->nr_comp, flds->im[2], flds->im[1], flds->im[0] };
  ierr = H5LTmake_dataset_float(group, "fields_single", 4, hdims, flds->data); CE;
  ierr = H5Gclose(group); CE;
}
Exemplo n.º 3
0
int_f
nh5ltset_attribute_int_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 = (int)*attrnamelen;
    c_attrname = (char *)HD5f2cstring(attrname, c_attrnamelen);
    if (c_attrname == NULL)
        goto done;

    /*
    * call H5LTset_attribute_int function.
    */
    c_loc_id = (hid_t)*loc_id;
    c_size   = (size_t)*size;

    if (sizeof(int_f) == sizeof(int))
        ret = H5LTset_attribute_int(c_loc_id,c_name,c_attrname,buf,c_size);
    else if (sizeof(int_f) == sizeof(long))
        ret = H5LTset_attribute_long(c_loc_id,c_name,c_attrname,buf,c_size);
    else if (sizeof(int_f) == sizeof(long long))
        ret = H5LTset_attribute_long_long(c_loc_id,c_name,c_attrname,buf,c_size);
    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;
}
Exemplo n.º 4
0
// Write int attribute <attr_name> given by address <path>
char AH5_write_int_attr(hid_t loc_id, const char *path, char* attr_name, const int wdata)
{
    char success = AH5_FALSE;

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

    return success;
}
Exemplo n.º 5
0
 int GWriteHDFFile::WriteHeader(gadget_header& header)
 {
           herr_t herr;
           for(int i=0; i<N_TYPE; i++){
               header.npart[i]=npart[i];
           }
           hid_t handle = H5Fopen(filename.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
           if (handle < 0)
               return -1*handle;
           // Lite interface for making simple attributes
           // H5LTset_attribute_int (file_id, dset_name, attr_name, data, size);
           // herr_t H5LTset_attribute_int( hid_t loc_id, const char *obj_name, const char *attr_name, int *buffer, size_t size)
           hid_t hdgrp = H5Gcreate2(handle, "Header", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
           herr = H5LTset_attribute_uint(handle, "Header", "NumPart_ThisFile", header.npart, N_TYPE);
           if (herr < 0) {
               WARN("Could not write to header");
               return -1*herr;
           }
           herr = H5LTset_attribute_uint(handle, "Header", "NumPart_Total", header.npartTotal, N_TYPE);
           herr = H5LTset_attribute_uint(handle, "Header", "NumPart_Total_HighWord", header.NallHW, N_TYPE);
           herr = H5LTset_attribute_double(handle, "Header", "MassTable", header.mass, N_TYPE);
           if (herr < 0) {
               WARN("Could not write particle numbers");
               return -1*herr;
           }
           herr = H5LTset_attribute_double(handle, "Header", "Time", &header.time, 1);
           herr = H5LTset_attribute_double(handle, "Header", "Redshift", &header.redshift, 1);
           herr = H5LTset_attribute_double(handle, "Header", "BoxSize", &header.BoxSize, 1);
           herr = H5LTset_attribute_int(handle, "Header", "NumFilesPerSnapshot", &header.num_files, 1);
           herr = H5LTset_attribute_double(handle, "Header", "Omega0", &header.Omega0, 1);
           herr = H5LTset_attribute_double(handle, "Header", "OmegaLambda", &header.OmegaLambda, 1);
           herr = H5LTset_attribute_double(handle, "Header", "HubbleParam", &header.HubbleParam, 1);
           herr = H5LTset_attribute_int(handle, "Header", "Flag_Sfr", &header.flag_sfr, 1);
           herr = H5LTset_attribute_int(handle, "Header", "Flag_Cooling", &header.flag_cooling, 1);
           herr = H5LTset_attribute_int(handle, "Header", "Flag_StellarAge", &header.flag_stellarage, 1);
           herr = H5LTset_attribute_int(handle, "Header", "Flag_Metals", &header.flag_metals, 1);
           herr = H5LTset_attribute_int(handle, "Header", "Flag_Feedback", &header.flag_feedback, 1);
           herr = H5LTset_attribute_int(handle, "Header", "Flag_DoublePrecision", &header.flag_doubleprecision, 1);
           herr = H5LTset_attribute_int(handle, "Header", "Flag_IC_Info", &header.flag_ic_info, 1);
           herr = H5LTset_attribute_double(handle, "Header", "UnitLength_in_cm", &header.UnitLength_in_cm, 1);
           herr = H5LTset_attribute_double(handle, "Header", "UnitMass_in_g", &header.UnitMass_in_g, 1);
           herr = H5LTset_attribute_double(handle, "Header", "UnitVelocity_in_cm_per_s", &header.UnitVelocity_in_cm_per_s, 1);
           if (herr < 0) {
               WARN("Could not write final header flags");
               return -1*herr;
           }
           H5Gclose(hdgrp);
           H5Fclose(handle);
           return 0;
 }
Exemplo n.º 6
0
void Grid::initData(FileIO *fileIO) 
{

  hid_t gridGroup = fileIO->newGroup("/Grid");
  
  // set lengths
  check(H5LTset_attribute_double(gridGroup, ".", "Lx", &Lx, 1), DMESG("HDF-5 Error"));
  check(H5LTset_attribute_double(gridGroup, ".", "Ly", &Ly, 1), DMESG("HDF-5 Error"));
  check(H5LTset_attribute_double(gridGroup, ".", "Lz", &Lz, 1), DMESG("HDF-5 Error"));
  check(H5LTset_attribute_double(gridGroup, ".", "Lv", &Lv, 1), DMESG("HDF-5 Error"));
  check(H5LTset_attribute_double(gridGroup, ".", "Lm", &Lm, 1), DMESG("HDF-5 Error"));
         
  // set grid point number
  check(H5LTset_attribute_int(gridGroup, ".", "Nx", &Nx , 1), DMESG("HDF-5 Error"));
  check(H5LTset_attribute_int(gridGroup, ".", "Nky",&Nky, 1), DMESG("HDF-5 Error"));
  check(H5LTset_attribute_int(gridGroup, ".", "Nz", &Nz , 1), DMESG("HDF-5 Error"));
  check(H5LTset_attribute_int(gridGroup, ".", "Nv", &Nv , 1), DMESG("HDF-5 Error"));
  check(H5LTset_attribute_int(gridGroup, ".", "Nm", &Nm , 1), DMESG("HDF-5 Error"));
  check(H5LTset_attribute_int(gridGroup, ".", "Ns", &Ns , 1), DMESG("HDF-5 Error"));
         
  // set grids 
  check(H5LTset_attribute_double(gridGroup, ".", "X", &X[NxGlD], Nx), DMESG("HDF-5 Error"));
  check(H5LTset_attribute_double(gridGroup, ".", "Z", &Z[NzGlD], Nz), DMESG("HDF-5 Error"));
  check(H5LTset_attribute_double(gridGroup, ".", "V", &V[NvGlD], Nv), DMESG("HDF-5 Error"));
  check(H5LTset_attribute_double(gridGroup, ".", "M", &M[NmGlD], Nm), DMESG("HDF-5 Error"));
  
  check(H5LTset_attribute_string(gridGroup, ".", "MuIntegrationType", muIntegrationType.c_str()), DMESG("HDF-5 Error")); 
  
  H5Gclose(gridGroup);
}
Exemplo n.º 7
0
int pioAddAttributeInteger(PIOObject pioObject,
						   const char* attr_name, int 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_int(pioObject.identifier, ".", 
								 attr_name, &attr_value, 1);
}
Exemplo n.º 8
0
//-*****************************************************************************
HDF5HierarchyWriter::HDF5HierarchyWriter( hid_t iFile, HDF5Hierarchy& iH5H )
    : m_H5H( iH5H )
{
    m_H5H.build( iFile );

    writeHierarchy( iFile );

    // Hierarchy info is succcessfully saved.
    // Let's set a flag.
    //
    int enabled = 1;
    H5LTset_attribute_int( iFile, ".", "abc_ref_hierarchy", &enabled, 1 );
}
Exemplo n.º 9
0
int incrementTimesUsed(PIOTimeline pioTimeline)
{
	ERROR_SWITCH_INIT
	herr_t set_err;
	
	int times_used = getTimesUsed(pioTimeline);
	if (times_used < 0) return -1;
	
	times_used++;
	
	ERROR_SWITCH_OFF
	set_err = H5LTset_attribute_int(pioTimeline.identifier, ".", PIOAttribute_TimesUsed, &times_used, 1);
	ERROR_SWITCH_ON
	
	if (set_err < 0) return -1;
	return times_used;
}
Exemplo n.º 10
0
/*+++++++++++++++++++++++++
.IDENTifer   PYTABLE_make_array
.PURPOSE     create extensible HDF5 dataset
.INPUT/OUTPUT
  call as    stat = PYTABLE_make_array( locID, dset_name, title, rank, dims,
			                extdim, typeID, dims_chunk, fill_data,
			                compress, shuffle, fletcher32, buff );
     input:
            hid_t locID           :  HDF5 identifier of file or group
	    char *dset_name       :  name of dataset
	    char *title           :
	    int rank              :  number of dimensions
	    hsize_t *dims         :  size of each dimension
	    int extdim            :  index of expendable dimension
	    hid_t typeID          :  data type (HDF5 identifier)
	    hsize_t *dims_chunk   :  chunk sizes
	    void *fill_data       :  Fill value for data
	    unsigned int compress :  compression level (zero for no compression)
	    bool shuffle          :  shuffel data for better compression
	    bool fletcher32       :  
	    void *buffer          :  buffer with data to write (or NULL)
	    
.RETURNS     A negative value is returned on failure. 
.COMMENTS    none
-------------------------*/
herr_t PYTABLE_make_array( hid_t locID, const char *dset_name, 
			   const char *title, const int rank, 
			   const hsize_t *dims, int extdim, hid_t typeID,
			   const hsize_t *dims_chunk, void *fill_data,
			   unsigned int compress, bool shuffle, 
			   bool fletcher32, const void *buffer )
{
     register int ni;

     hid_t   dataID = -1, spaceID = -1;
     herr_t  stat;

/* check if the array has to be chunked or not */
     if ( dims_chunk != NULL ) {
	  hid_t   plistID;

	  hsize_t *maxdims = (hsize_t *) malloc( rank * sizeof(hsize_t) );
	  if ( maxdims == NULL )
	       NADC_GOTO_ERROR( NADC_ERR_ALLOC, "maxdims" );

	  for ( ni = 0; ni < rank; ni++ ) {
	       if ( ni == extdim )
		    maxdims[ni] = H5S_UNLIMITED;
	       else
		    maxdims[ni] = 
			 dims[ni] < dims_chunk[ni] ? dims_chunk[ni] : dims[ni];
	  }
	  spaceID = H5Screate_simple( rank, dims, maxdims );
	  free( maxdims );
	  if ( spaceID < 0 ) NADC_GOTO_ERROR( NADC_ERR_HDF_SPACE, "" );

	  /* Modify dataset creation properties, i.e. enable chunking  */
	  plistID = H5Pcreate( H5P_DATASET_CREATE );
	  if ( H5Pset_chunk( plistID, rank, dims_chunk ) < 0 ) goto done;

          /* set the fill value using a struct as the data type */
	  if ( fill_data != NULL 
	       && H5Pset_fill_value( plistID, typeID, fill_data ) < 0 )
	       goto done;

          /* dataset creation property list is modified to use */
          /* fletcher must be first */
	  if ( fletcher32 ) {
	       if ( H5Pset_fletcher32( plistID ) < 0 ) goto done;
	  }
          /* then shuffle */
	  if ( shuffle ) {
	       if ( H5Pset_shuffle( plistID ) < 0 ) goto done;
	  }
          /* finally compression */
	  if ( compress > 0 ) {
	       if ( H5Pset_deflate( plistID, compress ) < 0 ) goto done;
	  }
          /* create the (chunked) dataset */
	  dataID = H5Dcreate( locID, dset_name, typeID, spaceID, 
			      H5P_DEFAULT, plistID, H5P_DEFAULT );
	  if ( dataID < 0 ) 
	       NADC_GOTO_ERROR( NADC_ERR_HDF_DATA, dset_name );

          /* end access to the property list */
	  if ( H5Pclose( plistID ) < 0 ) goto done;
     } else {
	  spaceID = H5Screate_simple( rank, dims, NULL );
	  if ( spaceID < 0 ) return -1;

          /* create the dataset (not chunked) */
	  dataID = H5Dcreate( locID, dset_name, typeID, spaceID, 
			      H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT );
	  if ( dataID < 0 ) 
	       NADC_GOTO_ERROR( NADC_ERR_HDF_DATA, dset_name );
     }
/*
 * write the data
 */
     stat = H5Dwrite( dataID, typeID, H5S_ALL, H5S_ALL, H5P_DEFAULT, buffer );
     if ( stat < 0 ) NADC_GOTO_ERROR( NADC_ERR_HDF_WR, "" );

     (void) H5Dclose( dataID );
     (void) H5Sclose( spaceID );
/*
 * Set the conforming array attributes
 *
 * attach the CLASS attribute
 */
     (void) H5LTset_attribute_string( locID, dset_name, "CLASS", 
				      PY_ARRAY_CLASS );

/* attach the EXTDIM attribute in case of enlargeable arrays */
     (void) H5LTset_attribute_int( locID, dset_name, "EXTDIM", &extdim, 1 );

/* attach the FLAVOR attribute */
     (void) H5LTset_attribute_string( locID, dset_name, "FLAVOR", 
				      PY_ARRAY_FLAVOR );
/* attach the VERSION attribute */
     (void) H5LTset_attribute_string( locID, dset_name, "VERSION", 
				      PY_ARRAY_VERSION );

/* attach the TITLE attribute */
     (void) H5LTset_attribute_string( locID, dset_name, "TITLE", title );

     return 0;
 done:
     if ( dataID > 0 ) (void) H5Dclose( dataID );
     if ( spaceID > 0 ) (void) H5Sclose( spaceID );
     return -1;
}
Exemplo n.º 11
0
/* ------- begin --------------------------   init_hdf5_indata.c  --- */
void init_hdf5_indata_new(void)
/* Creates the netCDF file for the input data */
{
  const char routineName[] = "init_hdf5_indata_new";
  int     i, PRD_angle_dep;
  double  *eweight, *eabund, *x, *y;
  /* This value is harcoded for efficiency.
     Maximum number of iterations ever needed */
  int     NMaxIter = 1500;
  hid_t   plist, ncid, file_dspace, ncid_input, ncid_atmos, ncid_mpi;
  hsize_t dims[4];
  bool_t   XRD;
  char    startJ[MAX_LINE_SIZE], StokesMode[MAX_LINE_SIZE], angleSet[MAX_LINE_SIZE];

  /* 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(INPUTDATA_FILE, H5F_ACC_TRUNC, H5P_DEFAULT,
                         plist) ) < 0) HERR(routineName);
  if (( H5Pclose(plist) ) < 0) HERR(routineName);

  /* Create groups */
  if (( ncid_input = H5Gcreate(ncid, "/input", H5P_DEFAULT, H5P_DEFAULT,
                               H5P_DEFAULT) ) < 0) HERR(routineName);
  if (( ncid_atmos = H5Gcreate(ncid, "/atmos", H5P_DEFAULT, H5P_DEFAULT,
                               H5P_DEFAULT) ) < 0) HERR(routineName);
  if (( ncid_mpi = H5Gcreate(ncid, "/mpi", H5P_DEFAULT, H5P_DEFAULT,
                               H5P_DEFAULT) ) < 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);

  /* --- Definitions for the INPUT group --- */
  /* attributes */
  if ( atmos.NPRDactive > 0)
    PRD_angle_dep = input.PRD_angle_dep;
  else
    PRD_angle_dep=0;

  XRD = (input.XRD  &&  atmos.NPRDactive > 0);

  if (( H5LTset_attribute_uchar(ncid_input, ".", "Magneto_optical",
          (unsigned char *) &input.magneto_optical, 1)) < 0) HERR(routineName);
  if (( H5LTset_attribute_uchar(ncid_input, ".", "PRD_angle_dep",
          (unsigned char *) &PRD_angle_dep, 1)) < 0) HERR(routineName);
  if (( H5LTset_attribute_uchar(ncid_input, ".", "XRD",
          (unsigned char *) &XRD, 1)) < 0) HERR(routineName);
  if (( H5LTset_attribute_uchar(ncid_input, ".", "Background_polarization",
          (unsigned char *) &input.backgr_pol, 1)) < 0) HERR(routineName);

  switch (input.startJ) {
  case UNKNOWN:
    strcpy(startJ, "Unknown");
    break;
  case LTE_POPULATIONS:
    strcpy(startJ, "LTE_POPULATIONS");
    break;
  case ZERO_RADIATION:
    strcpy(startJ, "ZERO_RADIATION");
    break;
  case OLD_POPULATIONS:
    strcpy(startJ, "OLD_POPULATIONS");
    break;
  case ESCAPE_PROBABILITY:
    strcpy(startJ, "ESCAPE_PROBABILITY");
    break;
  case NEW_J:
    strcpy(startJ, "NEW_J");
    break;
  case OLD_J:
    strcpy(startJ, "OLD_J");
    break;
  }
  if (( H5LTset_attribute_string(ncid_input, ".", "Start_J", startJ)) < 0)
    HERR(routineName);

  switch (input.StokesMode) {
  case NO_STOKES:
    strcpy(StokesMode, "NO_STOKES");
    break;
  case FIELD_FREE:
    strcpy(StokesMode, "FIELD_FREE");
    break;
  case POLARIZATION_FREE:
    strcpy(StokesMode, "POLARIZATION_FREE");
    break;
  case FULL_STOKES:
    strcpy(StokesMode, "FULL_STOKES");
    break;
  }
  if (( H5LTset_attribute_string(ncid_input, ".", "Stokes_mode",
                                 StokesMode) ) < 0) HERR(routineName);

  switch (atmos.angleSet.set) {
  case SET_VERTICAL:
    strcpy(angleSet, "SET_VERTICAL");
    break;
  case SET_GL:
    strcpy(angleSet, "SET_GL");
    break;
  case SET_A2:
    strcpy(angleSet, "SET_A2");
    break;
  case SET_A4:
    strcpy(angleSet, "SET_A4");
    break;
  case SET_A6:
    strcpy(angleSet, "SET_A6");
    break;
  case SET_A8:
    strcpy(angleSet, "SET_A8");
    break;
  case SET_B4:
    strcpy(angleSet, "SET_B4");
    break;
  case SET_B6:
    strcpy(angleSet, "SET_B6");
    break;
  case SET_B8:
    strcpy(angleSet, "SET_B8");
    break;
  case NO_SET:
    strcpy(angleSet, "NO_SET");
    break;
  }
  if (( H5LTset_attribute_string(ncid_input, ".", "Angle_set",
                                 angleSet) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_string(ncid_input, ".", "Atmos_file",
                                 input.atmos_input) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_string(ncid_input, ".", "Abundances_file",
                                 input.abund_input) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_string(ncid_input, ".", "Kurucz_PF_data",
                                 input.pfData) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_double(ncid_input, ".", "Iteration_limit",
                                 &input.iterLimit, 1) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_double(ncid_input, ".", "PRD_Iteration_limit",
                              &input.PRDiterLimit, 1) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_int(ncid_input, ".", "N_max_iter",
                              &input.NmaxIter, 1) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_int(ncid_input, ".", "Ng_delay",
                              &input.Ngdelay, 1) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_int(ncid_input, ".", "Ng_order",
                              &input.Ngorder, 1) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_int(ncid_input, ".", "Ng_period",
                              &input.Ngperiod, 1) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_int(ncid_input, ".", "PRD_N_max_iter",
                              &input.PRD_NmaxIter, 1) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_int(ncid_input, ".", "PRD_Ng_delay",
                              &input.PRD_Ngdelay, 1) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_int(ncid_input, ".", "PRD_Ng_order",
                              &input.PRD_Ngorder, 1) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_int(ncid_input, ".", "PRD_Ng_period",
                              &input.PRD_Ngperiod, 1) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_double(ncid_input, ".", "Metallicity",
                               &input.metallicity, 1) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_double(ncid_input, ".", "Lambda_reference",
                                &atmos.lambda_ref, 1) ) < 0) HERR(routineName);

  /* --- Definitions for the ATMOS group --- */
  /* dimensions */
  if (( H5LTset_attribute_int(ncid_atmos, ".", "nhydr",
                              &atmos.H->Nlevel, 1) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_int(ncid_atmos, ".", "nelements",
                              &atmos.Nelem, 1) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_int(ncid_atmos, ".", "nrays",
                              &geometry.Nrays, 1) ) < 0) HERR(routineName);


  /* variables*/
  dims[0] = mpi.nx;
  dims[1] = mpi.ny;
  dims[2] = infile.nz;
  if (( file_dspace = H5Screate_simple(3, dims, NULL) ) < 0) HERR(routineName);
  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);

  if (( io.in_atmos_T = H5Dcreate(ncid_atmos, "temperature", H5T_NATIVE_FLOAT,
         file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName);
  if (( io.in_atmos_vz = H5Dcreate(ncid_atmos, "velocity_z", H5T_NATIVE_FLOAT,
         file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName);
  if (( io.in_atmos_z = H5Dcreate(ncid_atmos, "height", H5T_NATIVE_FLOAT,
         file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName);
  if (( H5Pclose(plist) ) < 0) HERR(routineName);
  if (( H5Sclose(file_dspace) ) < 0) HERR(routineName);
  /* --- Write some data that does not depend on xi, yi, ATMOS group --- */
  /* arrays of number of elements */
  eweight = (double *) malloc(atmos.Nelem * sizeof(double));
  eabund = (double *) malloc(atmos.Nelem * sizeof(double));
  for (i=0; i < atmos.Nelem; i++) {
    eweight[i] = atmos.elements[i].weight;
    eabund[i] = atmos.elements[i].abund;
  }
  dims[0] = atmos.Nelem;
  if (( H5LTmake_dataset(ncid_atmos, "element_weight", 1, dims,
                H5T_NATIVE_DOUBLE, eweight) ) < 0) HERR(routineName);
  if (( H5LTmake_dataset(ncid_atmos, "element_abundance", 1, dims,
                H5T_NATIVE_DOUBLE, eabund) ) < 0) HERR(routineName);
  /* Not writing element_id for now
  dims[1] = strlen;
  if (( H5LTmake_dataset(ncid_atmos, "element_id", 2, dims,
                H5T_C_S1, eID) ) < 0) HERR(routineName);
  */
  free(eweight);
  free(eabund);

  dims[0] = geometry.Nrays;
  if (( H5LTmake_dataset(ncid_atmos, "muz", 1, dims,
              H5T_NATIVE_DOUBLE, geometry.muz) ) < 0) HERR(routineName);
  if (( H5LTmake_dataset(ncid_atmos, "wmu", 1, dims,
              H5T_NATIVE_DOUBLE, geometry.wmu) ) < 0) HERR(routineName);

  x = (double *) malloc(mpi.nx * sizeof(double));
  y = (double *) malloc(mpi.ny * sizeof(double));
  for (i=0; i < mpi.nx; i++) x[i] = infile.x[mpi.xnum[i]];
  for (i=0; i < mpi.ny; i++) y[i] = infile.y[mpi.ynum[i]];
  dims[0] = mpi.nx;
  if (( H5LTmake_dataset(ncid_atmos, "x", 1, dims,
                         H5T_NATIVE_DOUBLE, x) ) < 0) HERR(routineName);
  dims[0] = mpi.ny;
  if (( H5LTmake_dataset(ncid_atmos, "y", 1, dims,
                         H5T_NATIVE_DOUBLE, y) ) < 0) HERR(routineName);
  free(x);
  free(y);

  /* attributes */
  if (( H5LTset_attribute_uchar(ncid_atmos, ".", "moving",
                   (unsigned char *) &atmos.moving, 1)) < 0) HERR(routineName);
  if (( H5LTset_attribute_uchar(ncid_atmos, ".", "stokes",
                   (unsigned char *) &atmos.Stokes, 1)) < 0) HERR(routineName);
  if (( H5LTset_attribute_string(ncid_atmos, "temperature", "units",
                                 "K") ) < 0) HERR(routineName);
  if (( H5LTset_attribute_string(ncid_atmos,  "velocity_z", "units",
                                 "m s^-1") ) < 0) HERR(routineName);
  if (( H5LTset_attribute_string(ncid_atmos,  "height", "units",
                                 "m") ) < 0) HERR(routineName);
  if (( H5LTset_attribute_string(ncid_atmos,  "element_weight", "units",
                                 "atomic_mass_units") ) < 0) HERR(routineName);
  if (( H5LTset_attribute_string(ncid_atmos,  "x", "units",
                                 "m") ) < 0) HERR(routineName);
  if (( H5LTset_attribute_string(ncid_atmos,  "y", "units",
                                 "m") ) < 0) HERR(routineName);

  /* --- Definitions for the MPI group --- */
  /* dimensions */
  if (( H5LTset_attribute_int(ncid_mpi, ".", "nprocesses",
                              &mpi.size, 1) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_int(ncid_mpi, ".", "niterations",
                              &NMaxIter, 1) ) < 0) HERR(routineName);
  /* variables*/
  dims[0] = mpi.nx;
  if (( H5LTmake_dataset(ncid_mpi, XNUM_NAME, 1, dims,
                H5T_NATIVE_INT, mpi.xnum) ) < 0) HERR(routineName);
  dims[0] = mpi.ny;
  if (( H5LTmake_dataset(ncid_mpi, YNUM_NAME, 1, dims,
                H5T_NATIVE_INT, mpi.ynum) ) < 0) HERR(routineName);
  dims[0] = mpi.nx;
  dims[1] = mpi.ny;
  if (( file_dspace = H5Screate_simple(2, dims, NULL) ) < 0) HERR(routineName);
  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);
  if (( io.in_mpi_tm = H5Dcreate(ncid_mpi, TASK_MAP, H5T_NATIVE_LONG,
         file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName);
  if (( io.in_mpi_tn = H5Dcreate(ncid_mpi, TASK_NUMBER, H5T_NATIVE_LONG,
         file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName);
  if (( io.in_mpi_it = H5Dcreate(ncid_mpi, ITER_NAME, H5T_NATIVE_LONG,
         file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName);
  if (( io.in_mpi_conv = H5Dcreate(ncid_mpi, CONV_NAME, H5T_NATIVE_LONG,
         file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName);
  if (( io.in_mpi_dm = H5Dcreate(ncid_mpi, DM_NAME, H5T_NATIVE_FLOAT,
         file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName);
  if (( io.in_mpi_zc = H5Dcreate(ncid_mpi, ZC_NAME, H5T_NATIVE_INT,
         file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName);
  if (( H5Pclose(plist) ) < 0) HERR(routineName);
  if (( H5Sclose(file_dspace) ) < 0) HERR(routineName);

  dims[0] = mpi.nx;
  dims[1] = mpi.ny;
  dims[2] = NMaxIter;
  if (( file_dspace = H5Screate_simple(3, dims, NULL) ) < 0) HERR(routineName);
  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);
  if (( io.in_mpi_dmh = H5Dcreate(ncid_mpi, DMH_NAME, H5T_NATIVE_FLOAT,
         file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName);
  if (( H5Pclose(plist) ) < 0) HERR(routineName);
  if (( H5Sclose(file_dspace) ) < 0) HERR(routineName);

  /* attributes */
  if (( H5LTset_attribute_int(ncid_mpi, ".", "x_start",
                              &input.p15d_x0, 1) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_int(ncid_mpi, ".", "x_end",
                              &input.p15d_x1, 1) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_int(ncid_mpi, ".", "x_step",
                              &input.p15d_xst, 1) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_int(ncid_mpi, ".", "y_start",
                              &input.p15d_y0, 1) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_int(ncid_mpi, ".", "y_end",
                              &input.p15d_y1, 1) ) < 0) HERR(routineName);
  if (( H5LTset_attribute_int(ncid_mpi, ".", "y_step",
                              &input.p15d_yst, 1) ) < 0) HERR(routineName);

  /* Tiago: most of the arrays involving Ntasks or rank as index are not
            currently being written. They should eventually be migrated into
            arrays of [ix, iy] and be written for each task. This is to
            avoid causing problems with pool mode, where these quantities are
            not known from the start.
  */

  /* Flush ensures file is created in case of crash */
  if (( H5Fflush(ncid, H5F_SCOPE_LOCAL) ) < 0) HERR(routineName);
  /* --- Copy stuff to the IO data struct --- */
  io.in_ncid       = ncid;
  io.in_input_ncid = ncid_input;
  io.in_atmos_ncid = ncid_atmos;
  io.in_mpi_ncid   = ncid_mpi;
  return;
}
Exemplo n.º 12
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.º 13
0
/*main mcmc loop, records sampled values, performs no tuning of the step size.*/
int /*always returns success*/
mcmc_foreach(int rank, /*MPI rank*/
	     int R, /*MPI Comm size*/
	     size_t SampleSize, /*number of iterations of MCMC*/
	     ode_model_parameters *omp, /*ODE problem cpecification and pre-allocated space*/
	     mcmc_kernel *kernel, /* MCMC kernel sturct, holds MCMC-algorithm's parameters*/
	     hdf5block_t *h5block, /*defines the hdf5 file to write into, holds ids and sizes*/
	     void *buffer, /* for MPI communication, similar to kernel*/
	     main_options *option)/*options from defaults, files and command line*/{
  clock_t ct=clock();
  gsl_matrix *log_para_chunk;
  gsl_vector *log_post_chunk;
  int D=get_number_of_MCMC_variables(omp);
  log_para_chunk=gsl_matrix_alloc(CHUNK,D);
  log_post_chunk=gsl_vector_alloc(CHUNK);
  gsl_vector_view current;
  gsl_vector_view x_state;
  int swaps = 0; // swap success counter
  int acc=no;    // acceptance flag
  int acc_c=0;   // acceptance counter
  double acc_rate=0.0;
  size_t it;
  int master=no;
  int DEST;
  double beta=mcmc_get_beta(kernel);
  herr_t status;
  int resume_EC;
  int last_chunk=no, not_written_yet=yes;
  for (it = 0; it < SampleSize; it++) {
    mcmc_sample(kernel, &acc);
    last_chunk=SampleSize-it<CHUNK;
    if (acc && last_chunk && not_written_yet){
      resume_EC=write_resume_state(option->resume_file, rank, R, kernel);
      if (resume_EC==EXIT_SUCCESS){
	not_written_yet=no;
      }
    }
    acc_c += acc;
    master=(it%2==rank%2);
    if (master){
      DEST=(rank+1)%R; // this process is the master process for swap decisions
    } else {
      DEST=(R+rank-1)%R; // this process has to accept swap decisions from DEST
    }
    //their_beta=BETA(DEST,R); // the other proc's
    if (R>1){
      mcmc_exchange_information(kernel,DEST,buffer);
      swaps+=mcmc_swap_chains(kernel,master,rank,DEST,buffer);
    }
    /* save sampled point for writing */
    current=gsl_matrix_row(log_para_chunk,it%CHUNK);
    x_state=gsl_vector_view_array(kernel->x,D);
    gsl_vector_memcpy(&(current.vector),&(x_state.vector));
    gsl_vector_set(log_post_chunk,it%CHUNK,kernel->fx[0]);
    /* print sample log and statistics every 100 samples */
    if ( ((it + 1) % CHUNK) == 0 ) {
      acc_rate = ((double) acc_c) / ((double) CHUNK);
      fprintf(stdout, "# [rank % 2i/% 2i; β=%5f; %3li%% done] (it %5li)\tacc. rate: %3.2f;\t%3i %% swap success\t",rank,R,beta,(100*it)/SampleSize,it,acc_rate,swaps);
      mcmc_print_stats(kernel, stdout);
      acc_c = 0;

      // print chunk to hdf5 file
      status=h5write_current_chunk(h5block,log_para_chunk,log_post_chunk);
      h5block->offset[0]=it+1;
      swaps=0;
    }
  }
  assert(status==0);
  // write remaining data to the output hdf5 file
  int Rest=SampleSize % CHUNK;
  printf("[main] last iteration done %i points remain to write.\n",Rest);
  if (Rest > 0){
    h5block->chunk_size[0]=Rest;
    h5block->chunk_size[1]=D;
    h5block->para_chunk_id=H5Screate_simple(2, h5block->chunk_size, NULL);    
    
    h5block->chunk_size[0]=Rest;
    h5block->chunk_size[1]=1;
    h5block->post_chunk_id=H5Screate_simple(2, h5block->chunk_size, NULL);
    
    printf("[main] writing the remaining %i sampled parametrisations to file.\n",Rest);
    h5block->block[0]=Rest;
    h5block->block[1]=D;
    display_chunk_properties(h5block);
    status = H5Sselect_hyperslab(h5block->para_dataspace_id, H5S_SELECT_SET, h5block->offset, h5block->stride, h5block->count, h5block->block);
    H5Dwrite(h5block->parameter_set_id, H5T_NATIVE_DOUBLE, h5block->para_chunk_id, h5block->para_dataspace_id, H5P_DEFAULT, log_para_chunk->data);
    
    h5block->block[1]=1;
    printf("[main] writing their %i log-posterior values to file.\n",Rest);
    display_chunk_properties(h5block);

    status &= H5Sselect_hyperslab(h5block->post_dataspace_id, H5S_SELECT_SET, h5block->offset, h5block->stride, h5block->count, h5block->block);
    H5Dwrite(h5block->posterior_set_id, H5T_NATIVE_DOUBLE, h5block->post_chunk_id, h5block->post_dataspace_id, H5P_DEFAULT, log_post_chunk->data);
    assert(status>=0);
  }

  // annotate written sample with all necessary information
  //printf("[main] writing some annotation about the sampled points as hdf5 attributes.\n");
  status&=H5LTset_attribute_int(h5block->file_id, "LogParameters", "MPI_RANK", &rank, 1);
  status&=H5LTset_attribute_ulong(h5block->file_id, "LogParameters", "SampleSize", &SampleSize, 1);
  status&=H5LTset_attribute_double(h5block->file_id, "LogParameters", "InverseTemperature_Beta", &beta, 1);
  
  ct=clock()-ct;
  double sampling_time=((double) ct)/((double) CLOCKS_PER_SEC);
  int ts=round(sampling_time);
  int hms[3]; // hours, minutes, seconds
  hms[0]=ts/3600;
  hms[1]=(ts%3600)/60;
  hms[2]=(ts%60);
  printf("# computation time spend sampling: %i:%i:%i\n",hms[0],hms[1],hms[2]);
  
  h5block->size[0]=1;
  status&=H5LTmake_dataset_double (h5block->file_id, "SamplingTime_s", 1, h5block->size, &sampling_time);
  h5block->size[0]=3;
  status&=H5LTmake_dataset_int(h5block->file_id, "SamplingTime_hms", 1, h5block->size, hms);
  
  if(status){
    printf("[rank %i] statistics written to file.\n",rank);
  }
  return EXIT_SUCCESS;
}
Exemplo n.º 14
0
/*+++++++++++++++++++++++++ Main Program or Function +++++++++++++++*/
void SCIA_WR_H5_MPH( struct param_record param, 
		     const struct mph_envi *mph )
{
     register unsigned short ni = 0;

     hid_t   mph_type[NFIELDS];

     const int compress = 0;
     const char *mph_names[NFIELDS] = {
	  "product_name", "proc_stage", "ref_doc", 
	  "acquisition_station", "proc_center", "proc_time", 
	  "software_version", 
	  "sensing_start", "sensing_stop", 
	  "phase", "cycle", "rel_orbit", "abs_orbit", "state_vector_time", 
	  "delta_ut1", 
	  "x_position", "y_position", "z_position", 
	  "x_velocity", "y_velocity", "z_velocity",
	  "vector_source", "utc_sbt_time", "sat_binary_time", "clock_step", 
	  "leap_utc", "leap_sign", "leap_err", 
	  "product_err", "tot_size", "sph_size", "num_dsd", "dsd_size", 
	  "num_data_sets"
     };
/*
 * define user-defined data types of the Table-fields
 */
     mph_type[0] = H5Tcopy( H5T_C_S1 );
     (void) H5Tset_size( mph_type[0], (size_t) ENVI_FILENAME_SIZE );
     mph_type[1] = H5Tcopy( H5T_C_S1 );
     (void) H5Tset_size( mph_type[1], (size_t) 2 );
     mph_type[2] = H5Tcopy( H5T_C_S1 );
     (void) H5Tset_size( mph_type[2], (size_t) 24 );

     mph_type[3] = H5Tcopy( H5T_C_S1 );
     (void) H5Tset_size( mph_type[3], (size_t) 21 );
     mph_type[4] = H5Tcopy( H5T_C_S1 );
     (void) H5Tset_size( mph_type[4], (size_t) 7 );
     mph_type[5] = H5Tcopy( H5T_C_S1 );
     (void) H5Tset_size( mph_type[5], (size_t) UTC_STRING_LENGTH );
     mph_type[6] = H5Tcopy( H5T_C_S1 );
     (void) H5Tset_size( mph_type[6], (size_t) 15 );

     mph_type[7] = H5Tcopy( H5T_C_S1 );
     (void) H5Tset_size( mph_type[7], (size_t) UTC_STRING_LENGTH );
     mph_type[8] = H5Tcopy( H5T_C_S1 );
     (void) H5Tset_size( mph_type[8], (size_t) UTC_STRING_LENGTH );

     mph_type[9] = H5Tcopy( H5T_C_S1 );
     (void) H5Tset_size( mph_type[9], (size_t) 2 );
     mph_type[10] = H5Tcopy( H5T_NATIVE_SHORT );
     mph_type[11] = H5Tcopy( H5T_NATIVE_INT );
     mph_type[12] = H5Tcopy( H5T_NATIVE_INT );
     mph_type[13] = H5Tcopy( H5T_C_S1 );
     (void) H5Tset_size( mph_type[13], (size_t) UTC_STRING_LENGTH );
     mph_type[14] = H5Tcopy( H5T_NATIVE_DOUBLE );
     mph_type[15] = H5Tcopy( H5T_NATIVE_DOUBLE );
     mph_type[16] = H5Tcopy( H5T_NATIVE_DOUBLE );
     mph_type[17] = H5Tcopy( H5T_NATIVE_DOUBLE );
     mph_type[18] = H5Tcopy( H5T_NATIVE_DOUBLE );
     mph_type[19] = H5Tcopy( H5T_NATIVE_DOUBLE );
     mph_type[20] = H5Tcopy( H5T_NATIVE_DOUBLE );

     mph_type[21] = H5Tcopy( H5T_C_S1 );
     (void) H5Tset_size( mph_type[21], (size_t) 3 );
     mph_type[22] = H5Tcopy( H5T_C_S1 );
     (void) H5Tset_size( mph_type[22], (size_t) UTC_STRING_LENGTH );
     mph_type[23] = H5Tcopy( H5T_NATIVE_UINT );
     mph_type[24] = H5Tcopy( H5T_NATIVE_UINT );

     mph_type[25] = H5Tcopy( H5T_C_S1 );
     (void) H5Tset_size( mph_type[25], (size_t) UTC_STRING_LENGTH );
     mph_type[26] = H5Tcopy( H5T_NATIVE_SHORT );
     mph_type[27] = H5Tcopy( H5T_C_S1 );
     (void) H5Tset_size( mph_type[27], (size_t) 2 );

     mph_type[28] = H5Tcopy( H5T_C_S1 );
     (void) H5Tset_size( mph_type[28], (size_t) 2 );
     mph_type[29] = H5Tcopy( H5T_NATIVE_UINT );
     mph_type[30] = H5Tcopy( H5T_NATIVE_UINT );
     mph_type[31] = H5Tcopy( H5T_NATIVE_UINT );
     mph_type[32] = H5Tcopy( H5T_NATIVE_UINT );
     mph_type[33] = H5Tcopy( H5T_NATIVE_UINT );
/*
 * create table
 */
     (void) H5TBmake_table( "Main Product Header", param.hdf_file_id, "MPH", 
			    NFIELDS, 1, mph_size, mph_names, mph_offs, 
			    mph_type, 1, NULL, compress, mph );
/*
 * create some attributes for quick access
 */
     (void) H5LTset_attribute_int( param.hdf_file_id, "/", "abs_orbit", 
				   &mph->abs_orbit, 1 );
/*
 * close interface
 */
     do {
	  (void) H5Tclose( mph_type[ni] );
     } while ( ++ni < NFIELDS );
}
Exemplo n.º 15
0
int SpIO_FwriteModel(SpFile *sfp, SpModel model)
{
	int status = 0;
	
	herr_t hstatus;

        /* Write the version of format */
        if(!status) {
                hstatus = H5LTset_attribute_string(sfp->h5f_id, "/", "format", "SPARX format v3");
                if(hstatus < 0)
                        status = 1;
        }

        /* Write the type of coordinat system */
        if(!status) {
                DatINode *geom = Dat_IList_IdxLookup(GEOM_TYPES, model.parms.geom);
                Deb_ASSERT(geom != NULL);
                hstatus = H5LTset_attribute_string(sfp->h5f_id, "/", "geom", geom->name);
                if(hstatus < 0)
                        status = 1;
        }

	/* Write T_cmb */
	if(!status) {
		hstatus = H5LTset_attribute_double(sfp->h5f_id, "/", "T_cmb", &model.parms.T_cmb, (size_t)1);
		if(hstatus < 0)
			status = 1;
	}

	/* Write T_in */
        if(!status) {
                hstatus = H5LTset_attribute_double(sfp->h5f_id, "/", "T_in", &model.parms.T_in, (size_t)1);
                if(hstatus < 0)
                        status = 1;
        }

        /* Write molecule name */
        if(!status) {
                Molec *mol = model.parms.mol;
                hstatus = H5LTset_attribute_string(sfp->h5f_id, "/", "molec", mol ? mol->name : "");
                if(hstatus < 0)
                        status = 1;
        }
	
	/* Write pops-switch */
        if(!status) {
                hstatus = H5LTset_attribute_int(sfp->h5f_id, "/", "pops", &model.parms.pops, (size_t)1);
                if(hstatus < 0)
                        status = 1;
        }

        /* Write dust-switch */
        if(!status) {
                hstatus = H5LTset_attribute_int(sfp->h5f_id, "/", "dust", &model.parms.dust, (size_t)1);
                if(hstatus < 0)
                        status = 1;
        }
        /* Write polariz-switch */
        if(!status) {
                hstatus = H5LTset_attribute_int(sfp->h5f_id, "/", "polariz", &model.parms.polariz, (size_t)1);
                if(hstatus < 0)
                        status = 1;
        }
        /* Write polariz-switch */
        if(!status) {
                hstatus = H5LTset_attribute_double(sfp->h5f_id, "/", "z", &model.parms.z, (size_t)1);
                if(hstatus < 0)
                        status = 1;
        }

	/* Write grid */
	if(!status)
		status = SpIO_H5WriteGrid(sfp->h5f_id, model.grid, &model.parms);        
        
	if(status)
		status = Err_SETSTRING("Error writing model to file `%s'", sfp->name);

	return status;
}
Exemplo n.º 16
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;
}
Exemplo n.º 17
0
//! Export data to HDF5 file. DO NOT include 'output/' in string 'file'.
void Surface::ExportHDF(const char* file, double xmin, double xmax, int Nx, double ymin, double ymax, int Ny, Interpolator* intpl)
{
    char fname[strlen(file)+11];
    strcpy(fname, "output/"); // Automatically export to directory 'output/'
    strcat(fname, file);
// Allocate memory for output data
    double *x;
    x = new double[Nx];
    double *y;
    y = new double[Ny];
    double *data;
    data = new double[Ny*Nx];
// Generate output data
    double stepx = (xmax-xmin)/Nx;
    double stepy = (ymax-ymin)/Ny;
    herr_t status;
    for( int i = 0; i < Nx; i++) {
        x[i] = xmin + stepx * i;
    }
    for( int j = 0; j < Ny; j++) {
        y[j] = ymin + stepy * j;
        for( int i = 0; i < Nx; i++) {
// The indexing is meant for consistency with python, VisIt, etc.
            data[i + j*Nx] = (*this)(x[i], y[j], intpl);
        }
    } 
// Create file and save data
    hid_t file_id;
    hsize_t dims[Dim2];
    dims[0] = Ny;
    dims[1] = Nx; 
    hsize_t dimx[Dim1];
    dimx[0] = Nx;
    hsize_t dimy[Dim1];
    dimy[0] = Ny;
    file_id = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
// Number of grids saved as attributes. Coodrinates saved as 1D arrays since the mesh is rectilinear. Data saved as 2D array. 
    status = H5LTmake_dataset_double(file_id,"/x",Dim1,dimx,x);
    status = H5LTmake_dataset_double(file_id,"/y",Dim1,dimy,y);
    status = H5LTmake_dataset_double(file_id,"/data",Dim2,dims,data);
    status = H5LTset_attribute_int(file_id,"/x","size of x",&Nx,1);
    status = H5LTset_attribute_int(file_id,"/y","size of y",&Ny,1); 
    status = H5Fclose(file_id);
// Clear up memory
    delete [] x;
    delete [] y;
    delete [] data;
// Create XMDF file that accompanies HDF5 file so as to enable VisIt reading.
    strcat(fname, ".xmf");
    FILE *xmf = 0;
    xmf = fopen(fname, "w");
    fprintf(xmf, "<?xml version=\"1.0\" ?>\n");
    fprintf(xmf, "<!DOCTYPE Xdmf SYSTEM \"Xdmf.dtd\" []>\n");
    fprintf(xmf, "<Xdmf Version=\"2.0\">\n");
    fprintf(xmf, " <Domain>\n");
    fprintf(xmf, "   <Grid Name=\"mesh\" GridType=\"Uniform\">\n");
    fprintf(xmf, "     <Topology TopologyType=\"2DRectMesh\" NumberOfElements=\"%d %d\"/>\n", Ny, Nx);
    fprintf(xmf, "     <Geometry GeometryType=\"VXVY\">\n");
    fprintf(xmf, "       <DataItem Dimensions=\"%d\" NumberType=\"Float\" Precision=\"4\" Format=\"HDF\">\n", Nx);
    fprintf(xmf, "        %s:/x\n", file);
    fprintf(xmf, "       </DataItem>\n");
    fprintf(xmf, "       <DataItem Dimensions=\"%d\" NumberType=\"Float\" Precision=\"4\" Format=\"HDF\">\n", Ny);
    fprintf(xmf, "        %s:/y\n", file);
    fprintf(xmf, "       </DataItem>\n");
    fprintf(xmf, "     </Geometry>\n");
    fprintf(xmf, "     <Attribute Name=\"data\" AttributeType=\"Scalar\" Center=\"Node\">\n");
    fprintf(xmf, "       <DataItem Dimensions=\"%d %d\" NumberType=\"Float\" Precision=\"4\" Format=\"HDF\">\n", Ny, Nx);
    fprintf(xmf, "        %s:/data\n", file);
    fprintf(xmf, "       </DataItem>\n");
    fprintf(xmf, "     </Attribute>\n");
    fprintf(xmf, "   </Grid>\n");
    fprintf(xmf, " </Domain>\n");
    fprintf(xmf, "</Xdmf>\n");
    fclose(xmf);
}