Example #1
0
TEST_F(ObservableTest, AcceptanceRunAndSaveToFile) {
	// if files exists, delete them first
	boost::filesystem::path pathDiffDat("acceptance_diffusion_test.dat");
	boost::filesystem::path pathDiffH5("acceptance_diffusion_test.h5");
	boost::filesystem::path pathReactDat("acceptance_reactions_test.dat");
	boost::filesystem::path pathReactH5("acceptance_reactions_test.h5");
	boost::filesystem::remove(pathDiffH5);
	boost::filesystem::remove(pathDiffDat);
	boost::filesystem::remove(pathReactH5);
	boost::filesystem::remove(pathReactDat);
	// now actual test. with default impl, the acceptance is always = 1
	World w; Config c; Simulation s(&w, &c, ""); 
	s.new_Acceptance(1, "acceptance_reactions_test.dat", true);
	s.new_Acceptance(1, "acceptance_reactions_test.h5", true);
	s.new_Acceptance(1, "acceptance_diffusion_test.dat", false);
	s.new_Acceptance(1, "acceptance_diffusion_test.h5", false);
	// no particles added. just run for 4 timesteps -> there should be 5 entries in the observable
	s.run(4);
	s.writeAllObservablesToFile();
	// check h5 files
	hid_t reactFileId = H5Fopen("acceptance_reactions_test.h5", H5F_ACC_RDONLY, H5P_DEFAULT);
	hid_t diffFileId = H5Fopen("acceptance_diffusion_test.h5", H5F_ACC_RDONLY, H5P_DEFAULT);
	hsize_t reactDims[1], diffDims[1];
	H5LTget_dataset_info(reactFileId, "/acceptanceProbs", reactDims, NULL, NULL);
	H5LTget_dataset_info(diffFileId, "/acceptanceProbs", diffDims, NULL, NULL);
	EXPECT_EQ(reactDims[0], 5) << "expecting 5 entries in acceptance of reactions";
	EXPECT_EQ(diffDims[0], 5) << "expecting 5 entries in acceptance of diffusion";
	double data[5];
	H5LTread_dataset_double(reactFileId, "/acceptanceProbs", data);
	EXPECT_THAT(data, ::testing::ElementsAre(1,1,1,1,1));
	H5LTread_dataset_double(diffFileId, "/acceptanceProbs", data);
	EXPECT_THAT(data, ::testing::ElementsAre(1,1,1,1,1));
	H5Fclose(reactFileId);
	H5Fclose(diffFileId);
}
herr_t read_normal_seed_parameters(hid_t loc_id, struct normal_seed_parameters *p) {
    herr_t err = 0;
    err = H5LTread_dataset_int(loc_id, "/levy_seed_dimension", &p->dimension);
    p->mean       = malloc(p->dimension * sizeof(double));
    p->covariance = malloc(p->dimension * p->dimension * sizeof(double));
    err = H5LTread_dataset_double(loc_id, "/levy_seed_parameters/mean",       p->mean);
    err = H5LTread_dataset_double(loc_id, "/levy_seed_parameters/covariance", p->covariance);
    return err;
}
Example #3
0
File: fclib.c Project: xhub/fclib
/** read local vectors */
static void read_local_vectors (hid_t id, struct fclib_local *problem)
{
  MM (problem->q = malloc (sizeof (double [problem->W->m])));
  IO (H5LTread_dataset_double (id, "q", problem->q));

  ASSERT (problem->W->m % problem->spacedim == 0, "ERROR: number of W rows is not divisble by the spatial dimension");
  MM (problem->mu = malloc (sizeof (double [problem->W->m / problem->spacedim])));
  IO (H5LTread_dataset_double (id, "mu", problem->mu));

  if (problem->R)
  {
    MM (problem->s = malloc (sizeof (double [problem->R->m])));
    IO (H5LTread_dataset_double (id, "s", problem->s));
  }
}
Example #4
0
double hdf5_load_float<double>(hid_t loc_id, const string& dataset_name) {
  double val;
  herr_t status = H5LTread_dataset_double(loc_id, dataset_name.c_str(), &val);
  CHECK_GE(status, 0)
    << "Failed to load int dataset with name " << dataset_name;
  return val;
}
Example #5
0
File: hdf5.cpp Project: jofeu/caffe
void hdf5_load_nd_dataset<double>(hid_t file_id, const char* dataset_name_,
        int min_dim, int max_dim, Blob<double>* blob) {
  hdf5_load_nd_dataset_helper(file_id, dataset_name_, min_dim, max_dim, blob);
  herr_t status = H5LTread_dataset_double(
    file_id, dataset_name_, blob->mutable_cpu_data());
  CHECK_GE(status, 0) << "Failed to read double dataset " << dataset_name_;
}
Example #6
0
TEST_F(ObservableTest, MSDRunAndSaveToFile) {
	// if files exists, delete them first
	boost::filesystem::path pathH5("msd_test.h5");
	boost::filesystem::path pathDat("msd_test.dat");
	boost::filesystem::remove(pathH5);
	boost::filesystem::remove(pathDat);
	// now actual test. default implementation
	World w; Config c; Simulation s(&w, &c, "");
	c.new_Type("testparticle", 1., 1.);
	std::vector<double> pos = {0.,0.,0.};
	w.addParticle(pos, 0);
	s.new_MeanSquaredDisplacement(1, "msd_test.h5", 0);
	s.new_MeanSquaredDisplacement(1, "msd_test.dat", 0);
	s.run(4);
	s.writeAllObservablesToFile();
	// check h5 file
	hid_t fileId = H5Fopen("msd_test.h5", H5F_ACC_RDONLY, H5P_DEFAULT);
	hsize_t dims[1];
	H5LTget_dataset_info(fileId, "/meanSquaredDisplacements", dims, NULL, NULL);
	EXPECT_EQ(dims[0], 5) << "expecting 5 entries in MSD";
	double msd[5];
	H5LTread_dataset_double(fileId, "/meanSquaredDisplacements", msd);
	EXPECT_EQ(msd[0], 0.) << "initially the displacement must be zero";
	EXPECT_NE(msd[4], 0.) << "the final value is usually non-zero";
	unsigned int numbers[5];
	H5LTread_dataset(fileId, "/numberOfParticles", H5T_NATIVE_UINT, numbers);
	EXPECT_THAT(numbers, ::testing::ElementsAre(1,1,1,1,1)) << "number of particles should be 1 for all times";
	H5Fclose(fileId);
}
Example #7
0
TEST_F(ObservableTest, EnergyRunAndSaveToFile) {
	// if files exists, delete them first
	boost::filesystem::path pathH5("energy_test.h5");
	boost::filesystem::path pathDat("energy_test.dat");
	boost::filesystem::remove(pathH5);
	boost::filesystem::remove(pathDat);
	// now actual test
	World w; Config c; Simulation s(&w, &c, ""); // default impl
	c.new_Type("testparticle", 0.14, 1.);
	std::array<unsigned,2> affected = {0, 0};
	c.new_SoftRepulsion("testrepulsion", affected, 0.1);
	std::vector<double> pos = {0.,0.,0.};
	for (auto i=0; i<30; ++i) {
		pos[0] = 0.1*i; // particles are lined up from 0. to 3. with distance 0.1
		w.addParticle(pos, 0);
	}
	s.new_Energy(1, "energy_test.h5");
	s.new_Energy(1, "energy_test.dat");
	s.run(100);
	s.writeAllObservablesToFile();
	hid_t file_id = H5Fopen("energy_test.h5", H5F_ACC_RDONLY, H5P_DEFAULT);
	hsize_t dims[1];
	H5LTget_dataset_info(file_id, "/energies", dims, NULL, NULL);
	EXPECT_EQ(dims[0], 101) << "expecting the dataset to have 101 entries.";
	double data[101];
	H5LTread_dataset_double(file_id, "/energies", data);
	// initial energy value should be 0.11188
	EXPECT_NEAR(data[0], 0.11188, 1e-10) << "first energy value should be 0.11188";
	H5Fclose(file_id);
}
Example #8
0
File: fclib.c Project: xhub/fclib
/** read global vectors */
static void read_global_vectors (hid_t id, struct fclib_global *problem)
{
  MM (problem->f = malloc (sizeof (double [problem->M->m])));
  IO (H5LTread_dataset_double (id, "f", problem->f));

  ASSERT (problem->H->n % problem->spacedim == 0, "ERROR: number of H columns is not divisble by the spatial dimension");
  MM (problem->w = malloc (sizeof (double [problem->H->n])));
  MM (problem->mu = malloc (sizeof (double [problem->H->n / problem->spacedim])));
  IO (H5LTread_dataset_double (id, "w", problem->w));
  IO (H5LTread_dataset_double (id, "mu", problem->mu));

  if (problem->G)
  {
    MM (problem->b = malloc (sizeof (double [problem->G->n])));
    IO (H5LTread_dataset_double (id, "b", problem->b));
  }
}
Example #9
0
/**
 * Read the dataset
 * @param h5file file identifier
 * @param setName string name of dataset
 * @param buf storing dataset
 */
void LoadSassena::dataSetDouble(const hid_t &h5file, const std::string setName,
                                double *buf) {
  if (H5LTread_dataset_double(h5file, setName.c_str(), buf) < 0) {
    this->g_log.error("Cannot read " + setName + " dataset");
    throw Kernel::Exception::FileError(
        "Unable to read " + setName + " dataset:", m_filename);
  }
}
int read_input_config(char *input_file, struct input_config *cfg) {
    herr_t   err = 0;
    size_t   type_size;
    hid_t    input_file_id;
    void    *p = NULL;

    cfg->rng_family            = NULL;
    cfg->levy_seed_family      = NULL;
    cfg->levy_seed_parameters  = NULL;
    cfg->levy_basis_dimension  = NULL;
    cfg->levy_basis_resolution = NULL;
    
    input_file_id = H5Fopen(input_file, H5F_ACC_RDONLY, H5P_DEFAULT);
        
    err = H5LTget_dataset_info(input_file_id, "/rng_family", NULL, NULL, &type_size);
    cfg->rng_family = malloc(type_size * sizeof(char));
    err = H5LTread_dataset_string(input_file_id, "/rng_family", cfg->rng_family);
    
    err = H5LTread_dataset_int(input_file_id, "/rng_seed", &cfg->rng_seed);
    
    err = H5LTget_dataset_info(input_file_id, "/levy_seed_family", NULL, NULL, &type_size);
    cfg->levy_seed_family = malloc(type_size * sizeof(char));
    err = H5LTread_dataset_string(input_file_id, "/levy_seed_family", cfg->levy_seed_family);

    err = H5LTread_dataset_int(input_file_id, "/levy_seed_dimension", &cfg->levy_seed_dimension);
    
    if (strcmp(cfg->levy_seed_family, "normal") == 0) {
        p = (struct normal_seed_parameters *)malloc(sizeof(struct normal_seed_parameters));
        err = read_normal_seed_parameters(input_file_id, p);
        cfg->levy_seed_parameters = (void *)p;
    }
    else if (strcmp(cfg->levy_seed_family, "generalised hyperbolic") == 0) {
        printf("Error: GH not yet supported.\n");
        err = -1;
        goto cleanup;
    }
    else {
        printf("Error: Unsupported Levy seed.\n");
        err = -1;
        goto cleanup;
    }
    
    err = H5LTread_dataset_int(input_file_id, "/levy_basis_rank", &cfg->levy_basis_rank);
    cfg->levy_basis_dimension = malloc(cfg->levy_basis_rank * sizeof(int));
    cfg->levy_basis_resolution = malloc(cfg->levy_basis_rank * sizeof(double));
    err = H5LTread_dataset_int(input_file_id, "/levy_basis_dimension", cfg->levy_basis_dimension);
    err = H5LTread_dataset_double(input_file_id, "/levy_basis_resolution", cfg->levy_basis_resolution);
    
  cleanup:
    if (input_file_id >= 0) H5Fclose(input_file_id);
    return (int)err;
}
Example #11
0
File: fclib.c Project: xhub/fclib
/** read solution */
static void read_solution (hid_t id, hsize_t nv, hsize_t nr, hsize_t nl, struct fclib_solution *solution)
{
  if (nv)
  {
    MM (solution->v = malloc (sizeof (double [nv])));
    IO (H5LTread_dataset_double (id, "v", solution->v));
  }
  else solution->v = NULL;

  if (nl)
  {
    MM (solution->l = malloc (sizeof (double [nl])));
    IO (H5LTread_dataset_double (id, "l", solution->l));
  }
  else solution->l = NULL;

  ASSERT (nr, "ERROR: contact constraints must be present");
  MM (solution->u = malloc (sizeof (double [nr])));
  IO (H5LTread_dataset_double (id, "u", solution->u));
  MM (solution->r = malloc (sizeof (double [nr])));
  IO (H5LTread_dataset_double (id, "r", solution->r));
}
Example #12
0
void PHDF5fileClass::ReadPHDF5dataset_double(string datasetname, double ***data){

  herr_t  status;
  double *filedata;

  filedata = new double[dim[0]*dim[1]*dim[2]];

  status = H5LTread_dataset_double(file_id, datasetname.c_str(), filedata);

  for (int i=0; i<dim[0]; i++)
    for (int j=0; j<dim[1]; j++)
      for (int k=0; k<dim[2]; k++)
        data[i][j][k]=filedata[i+j*dim[2]+k*dim[1]*dim[0]];

}
Example #13
0
void PHDF5fileClass::ReadPHDF5param(){

  herr_t  status;
  string  dname;
  int     datadims[3];
  double  L[3];

  dname   = "/Parameters/ncell";
  status = H5LTread_dataset_int(file_id, dname.c_str(), datadims);

  dname   = "/Parameters/LxLyLz";
  status = H5LTread_dataset_double(file_id, dname.c_str(), L);

  ndim = 3;
  if (datadims[0]<=1 || datadims[1]<=1 || datadims[2]<=1) ndim = 2;

  for (int i=0; i<ndim; i++){
    dim[i]    = datadims[i];
    LxLyLz[i] = L[i];
  }

}
Example #14
0
File: fclib.c Project: xhub/fclib
/** read matrix */
struct fclib_matrix* read_matrix (hid_t id)
{
  struct fclib_matrix *mat;

  MM (mat = malloc (sizeof (struct fclib_matrix)));
 
  IO (H5LTread_dataset_int (id, "nzmax", &mat->nzmax));
  IO (H5LTread_dataset_int (id, "m", &mat->m));
  IO (H5LTread_dataset_int (id, "n", &mat->n));
  IO (H5LTread_dataset_int (id, "nz", &mat->nz));

  if (mat->nz >= 0) /* triplet */
  {
    MM (mat->p = malloc (sizeof (int [mat->nz])));
    MM (mat->i = malloc (sizeof (int [mat->nz])));
    IO (H5LTread_dataset_int (id, "p", mat->p));
    IO (H5LTread_dataset_int (id, "i", mat->i));
  }
  else if (mat->nz == -1) /* csc */
  {
    MM (mat->p = malloc (sizeof (int [mat->n+1])));
    MM (mat->i = malloc (sizeof (int [mat->nzmax])));
    IO (H5LTread_dataset_int (id, "p", mat->p));
    IO (H5LTread_dataset_int (id, "i", mat->i));
  }
  else if (mat->nz == -2) /* csr */
  {
    MM (mat->p = malloc (sizeof (int [mat->m+1])));
    MM (mat->i = malloc (sizeof (int [mat->nzmax])));
    IO (H5LTread_dataset_int (id, "p", mat->p));
    IO (H5LTread_dataset_int (id, "i", mat->i));
  }
  else ASSERT (0, "ERROR: unkown sparse matrix type => fclib_matrix->nz = %d\n", mat->nz);

  MM (mat->x = malloc (sizeof (double [mat->nzmax])));
  IO (H5LTread_dataset_double (id, "x", mat->x));

  if (H5LTfind_dataset (id, "conditioning"))
  {
    H5T_class_t class_id;
    hsize_t dim;
    size_t size;

    MM (mat->info = malloc (sizeof (struct fclib_matrix_info)));
    if (H5LTfind_dataset (id, "comment"))
    {
      IO (H5LTget_dataset_info  (id, "comment", &dim, &class_id, &size));
      MM (mat->info->comment = malloc (sizeof (char [size])));
      IO (H5LTread_dataset_string (id, "comment", mat->info->comment));
    }
    else mat->info->comment = NULL;
    IO (H5LTread_dataset_double (id, "conditioning", &mat->info->conditioning));
    IO (H5LTread_dataset_double (id, "determinant", &mat->info->determinant));
    IO (H5LTread_dataset_int (id, "rank", &mat->info->rank));
  }
  else
  {
    mat->info = NULL;
  }

  return mat;
}
Example #15
0
/*+++++++++++++++++++++++++ Main Program or Function +++++++++++++++*/
void SCIA_RD_IMAP_CH4( bool qflag, const char *flname, struct imap_hdr *hdr,
		       struct imap_rec **imap_out )
{
     register unsigned int ni, nr;

     char   *cpntr, ctemp[SHORT_STRING_LENGTH];
     float  *rbuff;
     double *dbuff;

     hid_t   fid = -1;
     hsize_t dims[2];

     struct imap_rec *rec = NULL;
/*
 * strip path of file-name
 */
     if ( (cpntr = strrchr( flname, '/' )) != NULL ) {
          (void) nadc_strlcpy( ctemp, ++cpntr, SHORT_STRING_LENGTH );
     } else {
          (void) nadc_strlcpy( ctemp, flname, SHORT_STRING_LENGTH );
     }
/*
 * initialize IMAP header structure
 */
     (void) nadc_strlcpy( hdr->product, ctemp, ENVI_FILENAME_SIZE );
     NADC_RECEIVEDATE( flname, hdr->receive_date );
     (void) strcpy( hdr->creation_date, hdr->receive_date );
     (void) strcpy( hdr->l1b_product, "" );
     (void) strcpy( hdr->validity_start, "" );
     (void) strcpy( hdr->validity_stop, "" );
     (void) nadc_strlcpy( hdr->software_version, ctemp+9, 4 );
     if ( (cpntr = strrchr( ctemp, '_' )) != NULL ) {
	  char str_magic[5], str_orbit[6];

	  (void) nadc_strlcpy( str_magic, cpntr+1, 5 );
	  while ( --cpntr > ctemp ) if ( *cpntr == '_' ) break;
	  (void) nadc_strlcpy( str_orbit, cpntr+1, 6 );
	  hdr->counter[0] = 
	       (unsigned short) strtoul( str_magic, (char **) NULL, 10 );
	  hdr->orbit[0]   = 
	       (unsigned int) strtoul( str_orbit, (char **) NULL, 10 );
     } else {
	  hdr->counter[0] = 0u;
	  hdr->orbit[0]   = 0u;
     }
     hdr->numProd   = 1u;
     hdr->numRec    = 0u;
     hdr->file_size = nadc_file_size( flname );
     imap_out[0] = NULL;
/*
 * open IMAP product in original HDF5 format
 */
     H5E_BEGIN_TRY {
	  fid = H5Fopen( flname, H5F_ACC_RDONLY, H5P_DEFAULT );
     } H5E_END_TRY;
     if ( fid < 0 ) NADC_RETURN_ERROR( NADC_ERR_HDF_FILE, flname );

     (void) H5LTget_dataset_info( fid, "/Data/Geolocation/time", 
				  dims, NULL, NULL );
     if ( dims[0] == 0 ) return;
     hdr->numRec = (unsigned int) dims[0];
/*
 * allocate enough space to store all records
 */
     rec = (struct imap_rec *) 
	  malloc( hdr->numRec * sizeof( struct imap_rec ));
     if ( rec == NULL ) NADC_RETURN_ERROR( NADC_ERR_ALLOC, "rec" );

     if ( (dbuff = (double *) malloc( hdr->numRec * sizeof(double) )) == NULL )
	  NADC_RETURN_ERROR( NADC_ERR_ALLOC, "rbuff" );
     (void) H5LTread_dataset_double( fid, "/Data/Geolocation/time", dbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) rec[ni].jday = dbuff[ni];
     free( dbuff );

     if ( (rbuff = (float *) malloc( hdr->numRec * sizeof(float) )) == NULL )
	  NADC_RETURN_ERROR( NADC_ERR_ALLOC, "rbuff" );
     (void) H5LTread_dataset_float( fid, "/Data/Geolocation/Longitude", rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ )
	  rec[ni].lon_center = LON_IN_RANGE( rbuff[ni] );
     (void) H5LTread_dataset_float( fid, "/Data/Geolocation/Latitude", rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) rec[ni].lat_center = rbuff[ni];

     (void) H5LTread_dataset_float( fid, "/Data/FitResults/VCD_CH4", rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) rec[ni].ch4_vcd = rbuff[ni];
     (void) H5LTread_dataset_float( fid, 
				    "/Data/FitResults/VCD_CH4_ERROR", rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) rec[ni].ch4_error = rbuff[ni];
     (void) H5LTread_dataset_float( fid, 
				    "/Data/FitResults/VCD_CH4_MODEL", rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) rec[ni].ch4_model = rbuff[ni];
     (void) H5LTread_dataset_float( fid, "/Data/FitResults/xVMR_CH4", rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) rec[ni].ch4_vmr = rbuff[ni];
     (void) H5LTread_dataset_float( fid, "/Data/FitResults/VCD_CO2", rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) rec[ni].co2_vcd = rbuff[ni];
     (void) H5LTread_dataset_float( fid, 
				    "/Data/FitResults/VCD_CO2_ERROR", rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) rec[ni].co2_error = rbuff[ni];
     (void) H5LTread_dataset_float( fid, 
				    "/Data/FitResults/VCD_CO2_MODEL", rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) rec[ni].co2_model = rbuff[ni];
/*
 * read auxiliary/geolocation data
 */
     (void) H5LTread_dataset_float( fid, "/Data/Geolocation/state_id", rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) 
	  rec[ni].meta.stateID = (unsigned char) rbuff[ni];
     (void) H5LTread_dataset_float( fid, "/Data/Geolocation/IntegrationTime", 
				    rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) {
	  if ( rbuff[ni] == 0.12f ) 
	       rec[ni].meta.intg_time = 0.125f;
	  else
	  rec[ni].meta.intg_time = rbuff[ni];
     }
     (void) H5LTread_dataset_float( fid, "/Data/Auxiliary/pixels_ch4", rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) 
	  rec[ni].meta.pixels_ch4 = (unsigned short) rbuff[ni];
     (void) H5LTread_dataset_float( fid, "/Data/Auxiliary/pixels_co2", rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) 
	  rec[ni].meta.pixels_co2 = (unsigned short) rbuff[ni];
     (void) H5LTread_dataset_float( fid, "/Data/Geolocation/AirMassFactor", 
				    rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) rec[ni].meta.amf = rbuff[ni];
     (void) H5LTread_dataset_float( fid, 
				    "/Data/Geolocation/LineOfSightZenithAngle", 
				    rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) rec[ni].meta.lza = rbuff[ni];
     (void) H5LTread_dataset_float( fid, "/Data/Geolocation/SolarZenithAngle", 
				    rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) rec[ni].meta.sza = rbuff[ni];
     (void) H5LTread_dataset_float( fid, "/Data/Geolocation/ScanRange", rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) rec[ni].meta.scanRange = rbuff[ni];
     SET_IMAP_BS_FLAG( rbuff, hdr->numRec, rec);
     (void) H5LTread_dataset_float( fid, "/Data/Geolocation/SurfaceElevation", 
				    rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) rec[ni].meta.elev = rbuff[ni];

     (void) H5LTread_dataset_float( fid, 
				    "/Data/Auxiliary/BU_ch4_window", rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) rec[ni].meta.bu_ch4 = rbuff[ni];
     (void) H5LTread_dataset_float( fid, 
				    "/Data/Auxiliary/residual_ch4", rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) rec[ni].meta.resi_ch4 = rbuff[ni];

     (void) H5LTread_dataset_float( fid, 
				    "/Data/Auxiliary/BU_co2_window", rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) rec[ni].meta.bu_co2 = rbuff[ni];
     (void) H5LTread_dataset_float( fid, 
				    "/Data/Auxiliary/residual_co2", rbuff );
     for ( ni = 0; ni < hdr->numRec; ni++ ) rec[ni].meta.resi_co2 = rbuff[ni];
/*
 * read corners of the tiles
 */
     rbuff = (float *) realloc( rbuff, 
				NUM_CORNERS * hdr->numRec * sizeof(float) );
     if ( rbuff == NULL ) NADC_RETURN_ERROR( NADC_ERR_ALLOC, "rbuff" );
     (void) H5LTread_dataset_float( fid, "/Data/Geolocation/CornerLongitudes", 
				    rbuff );
     for ( ni = nr = 0; ni < hdr->numRec; ni++ ) {
	  register unsigned short nc = 0;

	  rec[ni].lon_corner[1] = LON_IN_RANGE( rbuff[nr] ); nr++;
	  rec[ni].lon_corner[0] = LON_IN_RANGE( rbuff[nr] ); nr++;
	  rec[ni].lon_corner[2] = LON_IN_RANGE( rbuff[nr] ); nr++;
	  rec[ni].lon_corner[3] = LON_IN_RANGE( rbuff[nr] ); nr++;
	  do {
	       if ( fabsf(rec[ni].lon_center-rec[ni].lon_corner[nc]) > 180.f ) {
		    if ( rec[ni].lon_center > 0.f )
			 rec[ni].lon_corner[nc] += 360.f;
		    else
			 rec[ni].lon_corner[nc] -= 360.f;
	       }
	  } while ( ++nc < NUM_CORNERS );
     }
     (void) H5LTread_dataset_float( fid, "/Data/Geolocation/CornerLatitudes", 
				    rbuff );
     for ( ni = nr = 0; ni < hdr->numRec; ni++ ) {
	  rec[ni].lat_corner[1] = rbuff[nr++];
	  rec[ni].lat_corner[0] = rbuff[nr++];
	  rec[ni].lat_corner[2] = rbuff[nr++];
	  rec[ni].lat_corner[3] = rbuff[nr++];
     }
     free( rbuff );
/*
 * select IMAP records
 */
     if ( qflag ) hdr->numRec = SELECT_IMAP_RECORDS( hdr->numRec, rec );

     /* obtain validity period from data records */
     if ( hdr->numRec > 0 ) {
	  SciaJDAY2adaguc( rec->jday, hdr->validity_start );
	  SciaJDAY2adaguc( rec[hdr->numRec-1].jday, hdr->validity_stop );
	  imap_out[0] = rec;
     } else
	  free( rec );
}
int main(int argc, char *argv[]) {
    herr_t err = 0;
    
    int n_threads = omp_get_max_threads();

    hid_t kernel_file_id = 0;
    hid_t levy_basis_file_id = 0;
    hid_t levy_basis_dataset_id = 0;
    hid_t levy_basis_dataspace_id = 0;
    hid_t output_file_id      = 0;
    hid_t output_dataset_id   = 0;
    hid_t output_dataspace_id = 0;
    hid_t memspace = 0;

    hsize_t n_k = 0;
    double *tmp = NULL;
    double *k_abscissa = NULL;
    double *k_ordinate = NULL;
    double *x1 = NULL;
    double *x2 = NULL;
    double *x3 = NULL;
    
    DEBUGPRINT("### Parsing arguments");
    struct arguments args;
    initialise_arguments(&args);
    argp_parse (&argp, argc, argv, 0, 0, &args);
#ifdef DEBUG
    print_arguments(&args);
#endif
    
    DEBUGPRINT("### Reading kernel");
    kernel_file_id = H5Fopen(args.kernel_file, H5F_ACC_RDONLY, H5P_DEFAULT);
    if (kernel_file_id <= 0) {
        printf("Error: Could not open \"%s\".\n", args.kernel_file);
        err = -1;
        goto cleanup;
    }
    
    err = H5LTget_dataset_info(kernel_file_id, "/abscissa", &n_k, NULL, NULL);
    if (err < 0) {
        printf("Error: Could not read dataset info.\n");
        goto cleanup;
    }
    printf("n_k = %i\n", (int)n_k);
    k_abscissa = malloc(n_k * sizeof(double));
    k_ordinate = malloc(n_k * sizeof(double));
    err = H5LTread_dataset_double(kernel_file_id, "/abscissa", k_abscissa);
    err = H5LTread_dataset_double(kernel_file_id, "/ordinate", k_ordinate);
    
    DEBUGPRINT("### Reading Levy basis");
    hsize_t dims[4];
    hsize_t offset[4];
    hsize_t count[4];
    levy_basis_file_id      = H5Fopen(args.levy_basis_file, H5F_ACC_RDONLY, H5P_DEFAULT);
    levy_basis_dataset_id   = H5Dopen(levy_basis_file_id, "/levy_basis_realization", H5P_DEFAULT);
    levy_basis_dataspace_id = H5Dget_space(levy_basis_dataset_id);
    err = H5Sget_simple_extent_dims(levy_basis_dataspace_id, dims, NULL);
    
    if (dims[0] != dims[1] || dims[1] != dims[2]) {
        printf("Error: The three dimensions must be equal.\n");
        err = -1;
        goto cleanup;
    }

    hsize_t dims_pad[3];
    dims_pad[0] = dims[0];
    dims_pad[1] = dims[1];
    dims_pad[2] = 2 * (dims[2] / 2 + 1);

    hsize_t n_x = dims_pad[0] * dims_pad[1] * dims_pad[2];
    x1 = malloc(n_x * sizeof(double));
    x2 = malloc(n_x * sizeof(double));
    x3 = malloc(n_x * sizeof(double));

    double *x[] = {x1, x2, x3};
    if (!x1 || !x2 || !x3) {
        printf("Error: Could not allocate memory for the Levy basis.\n");
        err = -1;
        goto cleanup;
    }

#pragma omp parallel for 
    for (ptrdiff_t i = 0; i < n_x; i++) {
        x1[i] = 0.0;
        x2[i] = 0.0;
        x3[i] = 0.0;
    }    

    /* Define memory dataspace */
    memspace = H5Screate_simple(3, dims_pad, NULL);
    offset[0] = offset[1] = offset[2] = 0;
    count[0] = dims[0];
    count[1] = dims[1];
    count[2] = dims[2];
    /* Define hyperslab in the memory dataspace */
    err = H5Sselect_hyperslab(memspace, H5S_SELECT_SET, offset, NULL, count, NULL);
    
    for (int j = 0; j < 3; j++) {
        /* Define hyperslap in the file dataspace */
        offset[3] = j;
        count[3] = 1;
        err = H5Sselect_hyperslab(levy_basis_dataspace_id, H5S_SELECT_SET, offset, NULL, count, NULL);
        /* Read data from hyperslab */
        err = H5Dread(levy_basis_dataset_id, H5T_NATIVE_DOUBLE, 
                      memspace, levy_basis_dataspace_id,
                      H5P_DEFAULT, x[j]);
        if (err < 0) {
            printf("Error: Could not read hyperslab.\n");
            err = -1;
            goto cleanup;
        }
    }
    

    DEBUGPRINT("### Convolving");
    double delta = 2.0 * M_PI / dims[0];
    err = ambit_symmetric_odd_isotropic_circular_convolution_inplace(
        n_threads, n_k, k_abscissa, k_ordinate, dims[0], delta, x1, x2, x3);
    if (err) {
        printf("Error in ambit_symmetric_odd_isotropic_circular_convolution_inplace.\n");
        goto cleanup;
    }

    DEBUGPRINT("### Writing output");
    output_file_id = H5Fcreate(args.output_file, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
    if (output_file_id < 0) {
        printf("Error: Could not open \"%s\".\n", args.output_file);
        err = -1;
        goto cleanup;
    }
    
    output_dataspace_id = H5Screate_simple(4, dims, NULL);
    output_dataset_id   = H5Dcreate(output_file_id, "/simulation", H5T_NATIVE_DOUBLE, output_dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    for (int j = 0; j < 3; j++) {
        printf("j = %i\n", j);
        /* Define hyperslap in the file dataspace */
        offset[3] = j;
        count[3] = 1;
        err = H5Sselect_hyperslab(output_dataspace_id, H5S_SELECT_SET, offset, NULL, count, NULL);
        /* Write data to hyperslab */
        err = H5Dwrite(output_dataset_id, H5T_NATIVE_DOUBLE, 
                       memspace, output_dataspace_id,
                       H5P_DEFAULT, x[j]);
        if (err < 0) {
            printf("Error: Could not write hyperslab.\n");
            err = -1;
            goto cleanup;
        }
    }
    
  cleanup:
    if (memspace > 0) H5Sclose(memspace);
    if (output_dataspace_id > 0) H5Sclose(output_dataspace_id);
    if (output_dataset_id > 0) H5Dclose(output_dataset_id);
    if (output_file_id > 0) H5Fclose(output_file_id);
    if (levy_basis_dataspace_id > 0) H5Sclose(levy_basis_dataspace_id);
    if (levy_basis_dataset_id > 0) H5Dclose(levy_basis_dataset_id);
    if (levy_basis_file_id > 0) H5Fclose(levy_basis_file_id);
    if (kernel_file_id > 0) H5Fclose(kernel_file_id);
    free(tmp);
    free(k_abscissa);
    free(k_ordinate);
    free(x1);
    free(x2);
    free(x3);    
    return err;
}
Example #17
0
int main(int argc, char *argv[]) {
  progname = argv[0];
  int show_usage = 0;
  int outrate = 1, timesteps = 17;
  char *infile = NULL, *prefix = NULL;
  int optc;
  while ((optc = getopt_long(argc, argv, GETOPTS, long_opts, NULL)) != -1) {
    switch (optc) {
      case 'i':
        if (infile != NULL) {
          free(infile);
        }
        infile = strdup(optarg);
        break;
      case 'p':
        if (prefix != NULL) {
          free(prefix);
        }
        prefix = strdup(optarg);
        break;
      case 'r':
        outrate = atoi(optarg);
        break;
      case 't':
        timesteps = atoi(optarg);
        if (timesteps < 1) {
          fprintf(stderr, "Invalid value for timesteps: %s, must be a number greater than 1.\n", optarg);
          show_usage = 1;
        }
        break;
      default:
          show_usage = 1;
    }
  }
  if (show_usage == 1 || optind < argc || infile == NULL || prefix == NULL) {
    print_usage();
    return EXIT_FAILURE;
  }
  // READ FILE
  hsize_t dims[2];
  hid_t file_id;
  if ((file_id = H5Fopen(infile, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) {
    print_usage();
    return EXIT_FAILURE;
  }
  if (H5LTget_dataset_info(file_id, CCILK_DATASET, dims, NULL, NULL) < 0) {
    print_usage();
    return EXIT_FAILURE;
  }
  size_t rows = dims[0];
  size_t cols = dims[1];
  double *data = malloc(rows * cols * sizeof(double));
  double *next = malloc(rows * cols * sizeof(double));
  double width, depth, nu, sigma; 
  if (H5LTread_dataset_double(file_id, CCILK_DATASET, data) < 0
   || H5LTget_attribute_double(file_id, "/domain/", "width", &width) < 0 
   || H5LTget_attribute_double(file_id, "/domain/", "depth", &depth) < 0 
   || H5LTget_attribute_double(file_id, "/properties/", "nu", &nu) < 0 
   || H5LTget_attribute_double(file_id, "/properties/", "sigma", &sigma) < 0) {
    fprintf(stderr, "Encountered an issue reading the dataset\n");
    return EXIT_FAILURE;
  };

  printf("Width: %f dept %f\n", width, depth);

  simulate(data, next, rows, cols, width, depth, nu, sigma, outrate, timesteps, prefix);
  free(data);
  H5Fclose(file_id);
  return EXIT_SUCCESS;
}
Example #18
0
static int test_dsets( void )
{
    int     rank     = 2;
    hsize_t dims[2]  = {2,3};
    hid_t   file_id;
    hid_t   dataset_id;
    char    data_char_in[DIM]    = {1,2,3,4,5,6};
    char    data_char_out[DIM];
    short   data_short_in[DIM]   = {1,2,3,4,5,6};
    short   data_short_out[DIM];
    int     data_int_in[DIM]     = {1,2,3,4,5,6};
    int     data_int_out[DIM];
    long    data_long_in[DIM]    = {1,2,3,4,5,6};
    long    data_long_out[DIM];
    float   data_float_in[DIM]   = {1,2,3,4,5,6};
    float   data_float_out[DIM];
    double  data_double_in[DIM]  = {1,2,3,4,5,6};
    double  data_double_out[DIM];
    const char    *data_string_in = "This is a string";
    char    data_string_out[20];
    int     i;


    /* Create a new file using default properties. */
    file_id = H5Fcreate( FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT );

    /*-------------------------------------------------------------------------
    * H5LTmake_dataset test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTmake_dataset");

    /* Make dataset */
    if ( H5LTmake_dataset( file_id, DSET0_NAME, rank, dims, H5T_NATIVE_INT, data_int_in ) < 0 )
        goto out;

    /* Read dataset using the basic HDF5 API */

    if ( ( dataset_id = H5Dopen2(file_id, DSET0_NAME, H5P_DEFAULT) ) < 0 )
        goto out;

    if ( H5Dread ( dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data_int_out ) < 0 )
        goto out;

    if ( H5Dclose( dataset_id ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_int_in[i] != data_int_out[i] ) {
            goto out;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * read using the LT function H5LTread_dataset
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTread_dataset");

    if ( H5LTread_dataset( file_id, DSET0_NAME, H5T_NATIVE_INT, data_int_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_int_in[i] != data_int_out[i] ) {
            goto out;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * test the H5LTmake_dataset_ functions
    *-------------------------------------------------------------------------
    */


    /*-------------------------------------------------------------------------
    * H5LTmake_dataset_char
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTmake_dataset_char");

    /* Make dataset char */
    if ( H5LTmake_dataset_char( file_id, DSET1_NAME, rank, dims, data_char_in ) < 0 )
        goto out;

    /* Read dataset */
    if ( H5LTread_dataset( file_id, DSET1_NAME, H5T_NATIVE_CHAR, data_char_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_char_in[i] != data_char_out[i] ) {
            goto out;
        }
    }

    /* Read dataset */
    if ( H5LTread_dataset_char( file_id, DSET1_NAME, data_char_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_char_in[i] != data_char_out[i] ) {
            goto out;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTmake_dataset_short
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTmake_dataset_short");

    /* Make dataset short */
    if ( H5LTmake_dataset_short( file_id, DSET2_NAME, rank, dims, data_short_in ) < 0 )
        goto out;

    /* Read dataset */
    if ( H5LTread_dataset( file_id, DSET2_NAME, H5T_NATIVE_SHORT, data_short_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_short_in[i] != data_short_out[i] ) {
            goto out;
        }
    }

    /* Read dataset */
    if ( H5LTread_dataset_short( file_id, DSET2_NAME, data_short_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_short_in[i] != data_short_out[i] ) {
            goto out;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTmake_dataset_int
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTmake_dataset_int");

    /* Make dataset int */
    if ( H5LTmake_dataset_int( file_id, DSET3_NAME, rank, dims, data_int_in ) < 0 )
        goto out;

    /* Read dataset */
    if ( H5LTread_dataset( file_id, DSET3_NAME, H5T_NATIVE_INT, data_int_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_int_in[i] != data_int_out[i] ) {
            goto out;
        }
    }

    /* Read dataset */
    if ( H5LTread_dataset_int( file_id, DSET3_NAME, data_int_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_int_in[i] != data_int_out[i] ) {
            goto out;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTmake_dataset_long
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTmake_dataset_long");

    /* Make dataset long */
    if ( H5LTmake_dataset_long( file_id, DSET4_NAME, rank, dims, data_long_in ) < 0 )
        goto out;

    /* Read dataset */
    if ( H5LTread_dataset( file_id, DSET4_NAME, H5T_NATIVE_LONG, data_long_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_long_in[i] != data_long_out[i] ) {
            goto out;
        }
    }

    /* Read dataset */
    if ( H5LTread_dataset_long( file_id, DSET4_NAME, data_long_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_long_in[i] != data_long_out[i] ) {
            goto out;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTmake_dataset_float
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTmake_dataset_float");

    /* Make dataset float */
    if ( H5LTmake_dataset_float( file_id, DSET5_NAME, rank, dims, data_float_in ) < 0 )
        goto out;

    /* Read dataset */
    if ( H5LTread_dataset( file_id, DSET5_NAME, H5T_NATIVE_FLOAT, data_float_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_float_in[i] != data_float_out[i] ) {
            goto out;
        }
    }

    /* Read dataset */
    if ( H5LTread_dataset_float( file_id, DSET5_NAME, data_float_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_float_in[i] != data_float_out[i] ) {
            goto out;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTmake_dataset_double
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTmake_dataset_double");

    /* Make dataset double */
    if ( H5LTmake_dataset_double( file_id, DSET6_NAME, rank, dims, data_double_in ) < 0 )
        goto out;

    /* Read dataset */
    if ( H5LTread_dataset( file_id, DSET6_NAME, H5T_NATIVE_DOUBLE, data_double_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_double_in[i] != data_double_out[i] ) {
            goto out;
        }
    }

    /* Read dataset */
    if ( H5LTread_dataset_double( file_id, DSET6_NAME, data_double_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_double_in[i] != data_double_out[i] ) {
            goto out;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTmake_dataset_string
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTmake_dataset_string");

    /* Make dataset string */
    if ( H5LTmake_dataset_string(file_id,DSET7_NAME,data_string_in) < 0 )
        goto out;

    /* Read dataset */
    if ( H5LTread_dataset_string(file_id,DSET7_NAME,data_string_out) < 0 )
        goto out;

    if ( strcmp(data_string_in,data_string_out) != 0 )
        goto out;



    /*-------------------------------------------------------------------------
    * end tests
    *-------------------------------------------------------------------------
    */

    /* Close the file. */
    H5Fclose( file_id );

    PASSED();


    return 0;

out:
    /* Close the file. */
    H5_FAILED();
    return -1;
}