Files
src_old/examples/H5Part/read_strided.c
T
gsell 937d3f9c0e examples/H5Part/*
- cleanup and fixes
2015-09-11 14:04:12 +02:00

64 lines
1.9 KiB
C

/*
Copyright (c) 2006-2015, The Regents of the University of California,
through Lawrence Berkeley National Laboratory (subject to receipt of any
required approvals from the U.S. Dept. of Energy) and the Paul Scherrer
Institut (Switzerland). All rights reserved.
License: see file COPYING in top level of source distribution.
*/
#include "H5hut.h"
// name of input file
const char* fname = "example_strided.h5";
// H5hut verbosity level
//const h5_int64_t h5_verbosity = H5_VERBOSE_DEFAULT;
const h5_int64_t h5_verbosity = H5_DEBUG_ALL;
int
main (
int argc, char* argv[]
){
// initialize MPI & H5hut
MPI_Init (&argc, &argv);
MPI_Comm comm = MPI_COMM_WORLD;
int comm_size = 1;
MPI_Comm_size (comm, &comm_size);
int comm_rank = 0;
MPI_Comm_rank (comm, &comm_rank);
H5AbortOnError ();
H5SetVerbosityLevel (h5_verbosity);
// open file and go to first step
h5_file_t file = H5OpenFile (fname, H5_O_RDONLY, H5_PROP_DEFAULT);
H5SetStep (file, 0);
// Get number of particles in datasets
h5_int64_t num_particles = H5PartGetNumParticles (file);
// set number of particles and memory stride
H5PartSetNumParticlesStrided (file, 98, 6);
// read data
h5_float64_t* data = calloc (6*num_particles, sizeof (*data));
H5PartReadDataFloat64 (file, "x", data+0);
H5PartReadDataFloat64 (file, "y", data+1);
H5PartReadDataFloat64 (file, "z", data+2);
H5PartReadDataFloat64 (file, "px", data+3);
H5PartReadDataFloat64 (file, "py", data+4);
H5PartReadDataFloat64 (file, "pz", data+5);
// print dataset "x"
for (int i = 0; i < num_particles*6; i+=1) {
printf ("[proc %d]: local index = %d, value = %6.3f\n",
comm_rank, i, data[i]);
}
// cleanup
free (data);
H5CloseFile (file);
return MPI_Finalize ();
}