Exemple #1
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);
}
 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;
 }
Exemple #3
0
/*writes properties of the current run related to implementation and command line choices*/
herr_t /*hdf5 error*/
append_meta_properties(hdf5block_t *h5block,/*hdf5 file ids*/
		       double *seed,/*random number seed*/
		       size_t *BurnInSampleSize, /*tuning iterations*/
		       char *h5file, /*name of hdf5 file containing the experimental data and prior set-up*/
		       char *lib_base)/*basename of the library file @code .so@ file*/{
  herr_t status;
  int omp_n,omp_np,i;
  status&=H5LTset_attribute_double(h5block->file_id, "LogParameters", "seed", seed, 1);
  status&=H5LTset_attribute_ulong(h5block->file_id, "LogParameters", "BurnIn", BurnInSampleSize, 1);
  status&=H5LTset_attribute_string(h5block->file_id, "LogParameters", "DataFrom", h5file);
  status&=H5LTmake_dataset_string(h5block->file_id,"Model",lib_base);
  // here we make a short test to see what the automatic choice of the
  // number of threads turns out to be.
#pragma omp parallel private(omp_n,omp_np) reduction(+:i)
  {
    i=1;
    omp_n=omp_get_num_threads();
    omp_np=omp_get_num_procs();
  }
  if (i!=omp_n){
    fprintf(stderr,"[append_meta_properties] warning: finding out number of threads possibly failed reduction of (n×1: %i) != get_num_threads():%i.\n",i,omp_n);
  } else {
    h5block->size[0]=1;
    h5block->size[1]=1;
    status&=H5LTmake_dataset_int(h5block->file_id,"OMP_NUM_THREADS",1,h5block->size,&omp_n);
    status&=H5LTmake_dataset_int(h5block->file_id,"OMP_NUM_PROCS",1,h5block->size,&omp_np);
  }
  return status;
}
Exemple #4
0
int_f
nh5ltset_attribute_double_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_double function.
    */
    c_loc_id = (hid_t)*loc_id;
    c_size   = (size_t)*size;

    ret = H5LTset_attribute_double(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;
}
Exemple #5
0
void Particle_source_box::write_hdf5_source_parameters( hid_t current_source_group_id )
{
    Particle_source::write_hdf5_source_parameters( current_source_group_id );
    
    herr_t status;
    int single_element = 1;
    std::string current_group = "./";    

    status = H5LTset_attribute_double( current_source_group_id,
				       current_group.c_str(),
    				       "box_x_left", &xleft, single_element );
    hdf5_status_check( status );
    status = H5LTset_attribute_double( current_source_group_id,
				       current_group.c_str(),
    				       "box_x_right", &xright, single_element );
    hdf5_status_check( status );
    status = H5LTset_attribute_double( current_source_group_id,
				       current_group.c_str(),
    				       "box_y_top", &ytop, single_element );
    hdf5_status_check( status );
    status = H5LTset_attribute_double( current_source_group_id,
				       current_group.c_str(),
    				       "box_y_bottom", &ybottom, single_element );
    hdf5_status_check( status );
    status = H5LTset_attribute_double( current_source_group_id,
				       current_group.c_str(),
    				       "box_z_far", &zfar, single_element );
    hdf5_status_check( status );
    status = H5LTset_attribute_double( current_source_group_id,
				       current_group.c_str(),
    				       "box_z_near", &znear, single_element );
    hdf5_status_check( status );
}
Exemple #6
0
void Particle_source::write_hdf5_source_parameters( hid_t current_source_group_id )
{
    herr_t status;
    int single_element = 1;
    std::string current_group = "./";
    double mean_mom_x = vec3d_x( mean_momentum );
    double mean_mom_y = vec3d_y( mean_momentum );
    double mean_mom_z = vec3d_z( mean_momentum );
    
    status = H5LTset_attribute_double( current_source_group_id,
				       current_group.c_str(),
    				       "temperature", &temperature, single_element );
    hdf5_status_check( status );
    status = H5LTset_attribute_double( current_source_group_id,
				       current_group.c_str(),
    				       "mean_momentum_x", &mean_mom_x, single_element );
    hdf5_status_check( status );
    status = H5LTset_attribute_double( current_source_group_id,
				       current_group.c_str(),
    				       "mean_momentum_y", &mean_mom_y, single_element );
    hdf5_status_check( status );
    status = H5LTset_attribute_double( current_source_group_id,
				       current_group.c_str(),
    				       "mean_momentum_z", &mean_mom_z, single_element );
    hdf5_status_check( status );
    status = H5LTset_attribute_double( current_source_group_id,
				       current_group.c_str(),
    				       "charge", &charge, single_element );
    hdf5_status_check( status );
    status = H5LTset_attribute_double( current_source_group_id,
				       current_group.c_str(),
    				       "mass", &mass, single_element );
    hdf5_status_check( status );
}
Exemple #7
0
int pioAddAttributeDouble(PIOObject pioObject,
						  const char* attr_name, double 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_double(pioObject.identifier, ".",
									attr_name, &attr_value, 1);
}
Exemple #8
0
//-*****************************************************************************
void WriteTimeSampling( hid_t iGroup,
                    const std::string &iName,
                    const AbcA::TimeSampling &iTsmp )
{

    AbcA::TimeSamplingType tst = iTsmp.getTimeSamplingType();
    WriteTimeSamplingType( iGroup, iName, tst );

    //-*************************************************************************
    // WRITE TIMES.
    //-*************************************************************************
    std::string timeSampsName = iName + ".time";

    const std::vector < chrono_t > & samps = iTsmp.getStoredTimes();
    ABCA_ASSERT( samps.size() > 0, "No TimeSamples to write!");
    H5LTset_attribute_double ( iGroup, ".", timeSampsName.c_str(),
        &samps.front(), samps.size() );
}
Exemple #9
0
void Particle_source_cylinder::write_hdf5_source_parameters( hid_t current_source_group_id )
{
    Particle_source::write_hdf5_source_parameters( current_source_group_id );
    
    herr_t status;
    int single_element = 1;
    std::string current_group = "./";    

    status = H5LTset_attribute_double( current_source_group_id,
				       current_group.c_str(),
    				       "cylinder_axis_start_x", &axis_start_x, single_element );
    hdf5_status_check( status );
    status = H5LTset_attribute_double( current_source_group_id,
				       current_group.c_str(),
    				       "cylinder_axis_start_y", &axis_start_y, single_element );
    hdf5_status_check( status );
    status = H5LTset_attribute_double( current_source_group_id,
				       current_group.c_str(),
    				       "cylinder_axis_start_z", &axis_start_z, single_element );
    hdf5_status_check( status );
    status = H5LTset_attribute_double( current_source_group_id,
				       current_group.c_str(),
    				       "cylinder_axis_end_x", &axis_end_x, single_element );
    hdf5_status_check( status );
    status = H5LTset_attribute_double( current_source_group_id,
				       current_group.c_str(),
    				       "cylinder_axis_end_y", &axis_end_y, single_element );
    hdf5_status_check( status );
    status = H5LTset_attribute_double( current_source_group_id,
				       current_group.c_str(),
    				       "cylinder_axis_end_z", &axis_end_z, single_element );
    hdf5_status_check( status );
    status = H5LTset_attribute_double( current_source_group_id,
				       current_group.c_str(),
    				       "cylinder_radius", &radius, single_element );
    hdf5_status_check( status );

}
Exemple #10
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;
}
Exemple #11
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;
}
Exemple #12
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;
}
Exemple #13
0
    int FileIO::create(Setup *setup) {
     
        hid_t file_plist = H5Pcreate(H5P_FILE_ACCESS);
#ifdef GKC_PARALLEL_MPI
   //       pass some information onto the underlying MPI_File_open call 
          MPI_Info file_info;
          check(MPI_Info_create(&file_info), DMESG("File info"));
          /* 
          H5Pset_sieve_buf_size(file_plist, 262144); 
          H5Pset_alignment(file_plist, 524288, 262144);
                
          MPI_Info_set(file_info, (char *) "access_style"        , (char *) "write_once");
          MPI_Info_set(file_info, (char *) "collective_buffering", (char *) "true");
          MPI_Info_set(file_info, (char *) "cb_block_size"       , (char *) "1048576");
          MPI_Info_set(file_info, (char *) "cb_buffer_size"      , (char *) "4194304");
           * */

          check( H5Pset_fapl_mpio(file_plist, parallel->Comm[DIR_ALL], file_info), DMESG("Set MPI Property"));
#endif
        file = check(H5Fcreate(outputFileName.c_str(), (overwriteFile ? H5F_ACC_TRUNC : H5F_ACC_EXCL),
                        H5P_DEFAULT, file_plist ), DMESG("H5FCreate : HDF5 File (File already exists ? use -f to overwrite) : " + outputFileName));
        check( H5Pclose(file_plist),   DMESG("H5Pclose"));

#ifdef GKC_PARALLEL_MPI
        MPI_Info_free(&file_info);
#endif
        
         //////////////////////////////////////////////////////////////// Info Group ////////////////////////////////////////////////////////

          hid_t infoGroup = check(H5Gcreate(file, "/Info",H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT), DMESG("Error creating group file for Phasespace : H5Gcreate"));

         check(H5LTset_attribute_string(infoGroup, ".", "Output", outputFileName.c_str()), DMESG("H5LTset_attribute"));
         check(H5LTset_attribute_string(infoGroup, ".", "Input",  inputFileName.c_str()), DMESG("H5LTset_attribute"));
         
         
         check(H5LTset_attribute_string(infoGroup, ".", "Version", PACKAGE_VERSION), DMESG("H5LTset_attribute"));
         // Some Simulation specific stuff
         //check(H5LTset_attribute_string(infoGroup, ".", "Solver", ((setup->Solver & VL_LIN) ? "Linear" : "Non-Linear")), DMESG("H5LTset_attribute"));
         //heck(H5LTset_attribute_string(infoGroup, ".", "Type",   ((setup->VlasovType   & VLASOV_LOCAL ) ? "Local"  : "Global"    )), DMESG("H5LTset_attribute"));
         //heck(H5LTset_attribute_string(infoGroup, ".", "FFTSolverS",   ((setup->VlasovType   & VLASOV_LOCAL ) ? "Local"  : "Global"    )), DMESG("H5LTset_attribute"));
         //check(H5LTset_attribute_string(infoGroup, ".", "Initial Condition", setup->PerturbationMethod.c_str()), DMESG("H5LTset_attribute"));
         check(H5LTset_attribute_string(infoGroup, ".", "Info", info.c_str()), DMESG("H5LTset_attribute"));
         
         check(H5LTset_attribute_string(infoGroup, ".", "Config", setup->configFileString.c_str()), DMESG("H5LTset_attribute"));

         H5Gclose(infoGroup);
         
         
         /// Wrote setup constants, ugly here ////
         hid_t constantsGroup = check(H5Gcreate(file, "/Constants",H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT), DMESG("Error creating group file for Phasespace : H5Gcreate"));
         //
         if (!setup->parser_constants.empty()) { 
            
           std::vector<std::string> const_vec = Setup::split(setup->parser_constants, ",");

            for(int s = 0; s < const_vec.size(); s++) { 
                std::vector<std::string> key_value = Setup::split(const_vec[s],"=");
                double value = Setup::string_to_double(key_value[1]);
                int dim[] = { 1 };
   //           check(H5LTmake_dataset_double(constantsGroup, Setup::trimLower(key_value[0], false).c_str(), 1, dim, &value ), DMESG("Write Constants Attributes"));
                check(H5LTset_attribute_double(constantsGroup, ".", Setup::trimLower(key_value[0], false).c_str(), &value, 1), DMESG("H5LTset_attribute"));
                //check(H5LTset_attribute_double(constantsGroup, ".", Setup::trimLower(key_value[0], false).c_str(), &(Setup::string_to_double(key_value[1])), 1), DMESG("H5LTset_attribute"));
            };
         
         }
         
          H5Gclose(constantsGroup);

         
         // ********************* setup Table for CFL   *****************88
         cfl_table = new CFLTable();
         
         cfl_offset[0] =  HOFFSET( CFLTable, timeStep );
         cfl_offset[1] =  HOFFSET( CFLTable, time );
         cfl_offset[2] =  HOFFSET( CFLTable, Fx );
         cfl_offset[3] =  HOFFSET( CFLTable, Fy );
         cfl_offset[4] =  HOFFSET( CFLTable, Fz  );
         cfl_offset[5] =  HOFFSET( CFLTable, Fv );
         cfl_offset[6] =  HOFFSET( CFLTable, total );
          

         for(int i = 1; i < 7; i++)  cfl_sizes[i] = sizeof(double); cfl_sizes[0] = sizeof(int);
         hid_t   cfl_type[7]; for(int i = 1; i < 7; i++)  cfl_type [i] = H5T_NATIVE_DOUBLE; cfl_type[0] = H5T_NATIVE_INT;

         const char *cfl_names[7];
         cfl_names[0] = "timeStep";
         cfl_names[1] = "time";
         cfl_names[2] = "Fx"; cfl_names[3] = "Fy"; cfl_names[4] = "Fz"; cfl_names[5] = "Fv"; cfl_names[6] = "Total";

          check(H5TBmake_table("cflTable", file, "cfl", (hsize_t) 7, (hsize_t) 0, sizeof(CFLTable), (const char**) cfl_names,
                               cfl_offset, cfl_type, 32, NULL, 0, cfl_table ), DMESG("H5Tmake_table : cfl"));
         

         return HELIOS_SUCCESS;
    }
Exemple #14
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;
}