C and Fortran examples reviewed, new examples added
This commit is contained in:
+25
-11
@@ -6,6 +6,7 @@ LDADD =
|
||||
|
||||
if ENABLE_FORTRAN
|
||||
LDADD += -lH5hutF
|
||||
AM_LDFLAGS += -L${abs_top_builddir}/src/Fortran/.libs
|
||||
endif
|
||||
|
||||
LDADD += -lH5hut
|
||||
@@ -13,19 +14,32 @@ LDADD += -lH5hut
|
||||
noinst_PROGRAMS =
|
||||
|
||||
if ENABLE_C
|
||||
noinst_PROGRAMS += \
|
||||
openclose \
|
||||
file_attribs \
|
||||
attach_file
|
||||
noinst_PROGRAMS += \
|
||||
attach_file \
|
||||
openclose \
|
||||
query \
|
||||
read_file_attribs \
|
||||
read_step_attribs \
|
||||
write_file_attribs \
|
||||
write_step_attribs
|
||||
endif
|
||||
|
||||
if ENABLE_FORTRAN
|
||||
noinst_PROGRAMS +=
|
||||
noinst_PROGRAMS += \
|
||||
openclosef \
|
||||
queryf \
|
||||
read_file_attribsf \
|
||||
read_step_attribsf \
|
||||
write_file_attribsf \
|
||||
write_step_attribsf
|
||||
|
||||
openclosef_SOURCES = openclosef.f90
|
||||
queryf_SOURCES = queryf.f90
|
||||
read_file_attribsf_SOURCES = read_file_attribsf.f90
|
||||
read_step_attribsf_SOURCES = read_step_attribsf.f90
|
||||
write_file_attribsf_SOURCES = write_file_attribsf.f90
|
||||
write_step_attribsf_SOURCES = write_step_attribsf.f90
|
||||
endif
|
||||
|
||||
#EXTRA_PROGRAMS = openclose
|
||||
|
||||
#openclose_SOURCES = openclose.c
|
||||
|
||||
#%.o : %.f90
|
||||
# $(FC) $(FFLAGS) -c $<
|
||||
%.o : %.f90
|
||||
$(FC) $(FFLAGS) -c $<
|
||||
|
||||
@@ -19,20 +19,14 @@ main (
|
||||
int argc,
|
||||
char* argv[]
|
||||
) {
|
||||
MPI_Comm comm = MPI_COMM_WORLD;
|
||||
|
||||
int myproc;
|
||||
int nprocs;
|
||||
MPI_Init (&argc, &argv);
|
||||
MPI_Comm_size (comm, &nprocs);
|
||||
MPI_Comm_rank (comm, &myproc);
|
||||
|
||||
H5SetErrorHandler (H5AbortErrorhandler);
|
||||
H5SetVerbosityLevel (255);
|
||||
h5_file_t f = H5OpenFile (FNAME, H5_O_WRONLY, comm);
|
||||
h5_file_t f = H5OpenFile (FNAME, H5_O_WRONLY, H5_PROP_DEFAULT);
|
||||
H5AddAttachment (f, ATTACHMENT);
|
||||
H5CloseFile (f);
|
||||
f = H5OpenFile (FNAME, H5_O_RDONLY, 0);
|
||||
f = H5OpenFile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT);
|
||||
h5_ssize_t num_attachments = H5GetNumAttachments (f);
|
||||
printf ("Number of attachments: %lld\n", (long long int)num_attachments);
|
||||
int i;
|
||||
|
||||
@@ -21,12 +21,9 @@ main (
|
||||
MPI_Comm_size (comm, &nprocs);
|
||||
MPI_Comm_rank (comm, &myproc);
|
||||
|
||||
h5_file_t f = H5OpenFile ("testfile.h5", H5_O_WRONLY, comm);
|
||||
H5CloseFile (f);
|
||||
|
||||
h5_prop_t prop = H5CreateFileProp ();
|
||||
H5SetPropFileMPIO (prop, &comm);
|
||||
f = H5OpenFile2 ("testfile.h5", H5_O_WRONLY, prop);
|
||||
h5_file_t f = H5OpenFile ("testfile.h5", H5_O_WRONLY, prop);
|
||||
H5CloseProp (prop);
|
||||
H5CloseFile (f);
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
!
|
||||
! Copyright (c) 2006-2013, 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.f90'
|
||||
|
||||
program openclose
|
||||
|
||||
use H5hut
|
||||
|
||||
implicit none
|
||||
|
||||
include 'mpif.h'
|
||||
|
||||
integer :: comm, rank, ierr
|
||||
integer*8 :: file_id, status
|
||||
integer*8 :: props
|
||||
|
||||
comm = MPI_COMM_WORLD
|
||||
call mpi_init(ierr)
|
||||
call mpi_comm_rank(comm, rank, ierr)
|
||||
|
||||
props = h5_createprop_file ()
|
||||
status = h5_setprop_filempio (props, comm)
|
||||
file_id = h5_openfile ("testfile.h5", H5_O_WRONLY, props)
|
||||
status = h5_closeprop (props)
|
||||
status = h5_closefile (file_id);
|
||||
|
||||
call mpi_finalize(ierr)
|
||||
|
||||
end program openclose
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
Copyright (c) 2006-2013, 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"
|
||||
|
||||
#define FNAME1 "example_file_attribs.h5"
|
||||
#define FNAME2 "example_step_attribs.h5"
|
||||
|
||||
/*
|
||||
Due to the way types are defined in H5hut, we cannot use "switch() {}"
|
||||
*/
|
||||
const char*
|
||||
type2string (
|
||||
h5_int64_t type
|
||||
) {
|
||||
if (type == H5_FLOAT64_T)
|
||||
return "H5_FLOAT64_T";
|
||||
if (type == H5_FLOAT32_T)
|
||||
return "H5_FLOAT32_T";
|
||||
if (type == H5_INT64_T)
|
||||
return "H5_INT64_T";
|
||||
if (type == H5_INT32_T)
|
||||
return "H5_INT32_T";
|
||||
if (type == H5_STRING_T)
|
||||
return "H5_STRING_T";
|
||||
return "unknown type";
|
||||
}
|
||||
|
||||
static inline void
|
||||
print_header (
|
||||
h5_int64_t n
|
||||
) {
|
||||
if (n > 0) {
|
||||
printf ("\t%-6s %-30s %-15s %-10s\n", "idx", "name", "type", "dim");
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
print_query_result (
|
||||
h5_int64_t i,
|
||||
const char* const name,
|
||||
h5_int64_t type,
|
||||
h5_int64_t dim
|
||||
) {
|
||||
printf ("\t%-6lld %-30s %-15s %-10lld\n", i, name, type2string(type), dim);
|
||||
}
|
||||
|
||||
void
|
||||
query_file_attribs (
|
||||
h5_int64_t f
|
||||
) {
|
||||
char name[H5_MAX_NAME_LEN];
|
||||
h5_int64_t type;
|
||||
h5_size_t dim;
|
||||
|
||||
// query # of file attributes
|
||||
h5_int64_t n = H5GetNumFileAttribs (f);
|
||||
printf ("\tNumber of file attributes: %lld\n", n);
|
||||
|
||||
// output name and type of all file attribute
|
||||
print_header (n);
|
||||
for (h5_int64_t i = 0; i < n; i++) {
|
||||
H5GetFileAttribInfo (f, i, name, sizeof(name), &type, &dim);
|
||||
print_query_result (i, name, type, dim);
|
||||
}
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
void
|
||||
query_step_attribs (
|
||||
h5_int64_t f,
|
||||
h5_int64_t step
|
||||
) {
|
||||
char name[H5_MAX_NAME_LEN];
|
||||
h5_int64_t type;
|
||||
h5_size_t dim;
|
||||
|
||||
H5SetStep (f, step);
|
||||
|
||||
// query # of step attributes
|
||||
h5_int64_t n = H5GetNumStepAttribs (f);
|
||||
printf ("\tNumber of step attributes: %lld\n", n);
|
||||
|
||||
// output name and type of all step attribute
|
||||
print_header (n);
|
||||
for (h5_int64_t i = 0; i < n; i++) {
|
||||
H5GetStepAttribInfo (f, i, name, sizeof(name), &type, &dim);
|
||||
print_query_result (i, name, type, dim);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
query_file (
|
||||
const char* const fname
|
||||
) {
|
||||
printf ("\nFile: %s\n", fname);
|
||||
// if file properties is set to default, MPI_COMM_WORLD will be used
|
||||
h5_file_t f = H5OpenFile (fname, H5_O_RDONLY, H5_PROP_DEFAULT);
|
||||
|
||||
// query and output file attribs
|
||||
query_file_attribs (f);
|
||||
|
||||
// query # of steps, if > 0: go to first step, query and output step attribs
|
||||
h5_int64_t n = H5GetNumSteps (f);
|
||||
printf ("\tNumber of steps: %lld\n", n);
|
||||
|
||||
if (n > 0) {
|
||||
// go to first step
|
||||
h5_int64_t i = -1;
|
||||
while (!H5HasStep (f, ++i));
|
||||
|
||||
query_step_attribs (f, i);
|
||||
}
|
||||
H5CloseFile (f);
|
||||
}
|
||||
|
||||
int
|
||||
main (
|
||||
int argc,
|
||||
char** argv
|
||||
) {
|
||||
MPI_Init (&argc, &argv);
|
||||
H5AbortOnError ();
|
||||
|
||||
query_file (FNAME1);
|
||||
query_file (FNAME2);
|
||||
|
||||
MPI_Finalize ();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
!
|
||||
! Copyright (c) 2006-2013, 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.f90'
|
||||
|
||||
program query
|
||||
use H5hut
|
||||
implicit none
|
||||
include 'mpif.h'
|
||||
|
||||
! the file name we want to read
|
||||
character (len=*), parameter :: FNAME1 = "example_file_attribs.h5"
|
||||
character (len=*), parameter :: FNAME2 = "example_step_attribs.h5"
|
||||
|
||||
! verbosity level: set it to a power of 2 minus one or zero
|
||||
integer*8, parameter :: verbosity_level = 1
|
||||
|
||||
! used for mpi error return
|
||||
integer :: ierr
|
||||
|
||||
call mpi_init (ierr)
|
||||
|
||||
! abort program on any H5hut error
|
||||
call h5_abort_on_error ()
|
||||
|
||||
call h5_set_verbosity_level (verbosity_level)
|
||||
|
||||
call query_file (FNAME1);
|
||||
call query_file (FNAME2);
|
||||
|
||||
call mpi_finalize(ierr)
|
||||
|
||||
call exit (ierr)
|
||||
|
||||
contains
|
||||
|
||||
subroutine query_file (fname)
|
||||
character(len=*), intent(in):: fname
|
||||
|
||||
integer*8 file_id
|
||||
integer*8 i, n, status
|
||||
|
||||
write (*, '("File: ", a)') fname
|
||||
|
||||
! if file properties is set to default, MPI_COMM_WORLD will be used
|
||||
file_id = h5_openfile (fname, H5_O_RDONLY, H5_PROP_DEFAULT)
|
||||
|
||||
! query and output file attribs
|
||||
call query_file_attribs (file_id);
|
||||
|
||||
! query # of steps, if > 0: go to first step, query and output step attribs
|
||||
n = h5_getnsteps (file_id);
|
||||
write (*, '(T8, "Number of steps: ", I0)') n
|
||||
|
||||
if (n > 0) then
|
||||
! go to first step
|
||||
i = 0;
|
||||
do
|
||||
if (h5_hasstep (file_id, i)) exit
|
||||
i = i+1
|
||||
end do
|
||||
call query_step_attribs (file_id, i);
|
||||
end if
|
||||
status = h5_closefile (file_id)
|
||||
end subroutine query_file
|
||||
|
||||
! print header for attribute metadata table
|
||||
subroutine print_header (n)
|
||||
integer*8, intent(in):: n
|
||||
|
||||
character(len=6), parameter :: idx = "idx"
|
||||
character(len=30), parameter :: name = "name"
|
||||
character(len=15), parameter :: type = "type"
|
||||
character(len=10), parameter :: dim = "dim"
|
||||
|
||||
if (n > 0) then
|
||||
write (*, '(T8, A, 1X, A, 1X, A, 1X, A)') idx, name, type, dim
|
||||
end if
|
||||
|
||||
end subroutine print_header
|
||||
|
||||
! output attribute metadata
|
||||
subroutine print_query_result (i, name, type, dim)
|
||||
integer*8, intent(in):: i
|
||||
character(len=*), intent(in):: name
|
||||
integer*8, intent(in):: type
|
||||
integer*8, intent(in):: dim
|
||||
|
||||
character(len=30) name_
|
||||
character(len=15) type_, type_char
|
||||
character(len=6) i_
|
||||
character(len=10) dim_
|
||||
|
||||
if (type == H5_FLOAT64_T) then
|
||||
type_char = "H5_FLOAT64_T"
|
||||
else if (type == H5_FLOAT32_T) then
|
||||
type_char = "H5_FLOAT32_T"
|
||||
else if (type == H5_INT64_T) then
|
||||
type_char = "H5_INT64_T"
|
||||
else if (type == H5_INT32_T) then
|
||||
type_char = "H5_INT32_T"
|
||||
else if (type == H5_STRING_T) then
|
||||
type_char = "H5_STRING_T"
|
||||
else
|
||||
type_char = "unknown type"
|
||||
end if
|
||||
|
||||
write (i_, '(I6)') i
|
||||
write (name_, '(A30)') name
|
||||
write (type_, '(A15)') type_char
|
||||
write (dim_, '(I10)') dim
|
||||
|
||||
write (*, '(T8, A6, 1X, A30, 1X, A15, 1X, A10)') adjustl(i_), adjustl(name_), adjustl(type_), adjustl(dim_)
|
||||
end subroutine print_query_result
|
||||
|
||||
subroutine query_file_attribs (file_id)
|
||||
integer*8, intent(in):: file_id
|
||||
|
||||
integer*8 status
|
||||
integer*8 i, n
|
||||
character(len=H5_MAX_NAME_LEN) name
|
||||
integer*8 type, dim
|
||||
|
||||
! query # of file attributes
|
||||
n = h5_getnfileattribs (file_id);
|
||||
write (*, '(T8, "Number of file attributes: ", I0)') n
|
||||
|
||||
! output name and type of all file attribute
|
||||
call print_header (n);
|
||||
do i = 1, n
|
||||
status = h5_getfileattribinfo (file_id, i, name, type, dim);
|
||||
call print_query_result (i, name, type, dim);
|
||||
end do
|
||||
write (*,*)
|
||||
|
||||
end subroutine query_file_attribs
|
||||
|
||||
subroutine query_step_attribs (file_id, stepno)
|
||||
integer*8, intent(in):: file_id
|
||||
integer*8, intent(in):: stepno
|
||||
|
||||
integer*8 status
|
||||
integer*8 i, n
|
||||
character(len=H5_MAX_NAME_LEN) name
|
||||
integer*8 type, dim
|
||||
|
||||
! Go to step #1
|
||||
status = h5_setstep (file_id, stepno);
|
||||
|
||||
! query # of step attributes
|
||||
n = h5_getnstepattribs (file_id)
|
||||
write (*, '(T8, "Number of step attributes: ", i0)') n
|
||||
|
||||
! output name and type of all step attribute
|
||||
call print_header (n)
|
||||
do i = 1, n
|
||||
status = h5_getstepattribinfo (file_id, i, name, type, dim)
|
||||
call print_query_result (i, name, type, dim)
|
||||
end do
|
||||
|
||||
end subroutine query_step_attribs
|
||||
end program query
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
Copyright (c) 2006-2013, 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"
|
||||
|
||||
#define FNAME "example_file_attribs.h5"
|
||||
|
||||
#define ATTR_STRING "FileAttrString"
|
||||
#define ATTR_INT32 "FileAttrInt32"
|
||||
#define ATTR_INT64 "FileAttrInt64"
|
||||
#define ATTR_FLOAT32 "FileAttrFloat32"
|
||||
#define ATTR_FLOAT64 "FileAttrFloat64"
|
||||
|
||||
int
|
||||
main (
|
||||
int argc,
|
||||
char** argv
|
||||
) {
|
||||
MPI_Init (&argc, &argv);
|
||||
H5AbortOnError ();
|
||||
// if file properties is set to default, MPI_COMM_WORLD will be used
|
||||
h5_file_t f = H5OpenFile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT);
|
||||
h5_size_t len;
|
||||
|
||||
H5GetFileAttribInfoByName (f, ATTR_STRING, NULL, &len);
|
||||
char* attr_string = malloc (len+1);
|
||||
H5ReadFileAttribString (f, ATTR_STRING, attr_string);
|
||||
printf ("%s: %s\n", ATTR_STRING, attr_string);
|
||||
free (attr_string);
|
||||
|
||||
H5GetFileAttribInfoByName (f, ATTR_INT32, NULL, &len);
|
||||
int32_t* attr_int32 = malloc (sizeof(*attr_int32)*len);
|
||||
H5ReadFileAttribInt32 (f, ATTR_INT32, attr_int32);
|
||||
printf ("%s:", ATTR_INT32);
|
||||
for (int i = 0; i < len; i++) {
|
||||
printf (" %d", attr_int32[i]);
|
||||
}
|
||||
printf ("\n");
|
||||
free (attr_int32);
|
||||
|
||||
H5GetFileAttribInfoByName (f, ATTR_INT64, NULL, &len);
|
||||
int64_t* attr_int64 = malloc (sizeof(*attr_int64)*len);
|
||||
H5ReadFileAttribInt64 (f, ATTR_INT64, attr_int64);
|
||||
printf ("%s:", ATTR_INT64);
|
||||
for (int i = 0; i < len; i++) {
|
||||
printf (" %lld", (long long int)attr_int64[i]);
|
||||
}
|
||||
printf ("\n");
|
||||
free (attr_int64);
|
||||
|
||||
H5GetFileAttribInfoByName (f, ATTR_FLOAT32, NULL, &len);
|
||||
h5_float32_t* attr_float32 = malloc (sizeof(*attr_float32)*len);
|
||||
H5ReadFileAttribFloat32 (f, ATTR_FLOAT32, attr_float32);
|
||||
printf ("%s:", ATTR_FLOAT32);
|
||||
for (int i = 0; i < len; i++) {
|
||||
printf (" %f", attr_float32[i]);
|
||||
}
|
||||
printf ("\n");
|
||||
free (attr_float32);
|
||||
|
||||
H5GetFileAttribInfoByName (f, ATTR_FLOAT64, NULL, &len);
|
||||
h5_float64_t* attr_float64 = malloc (sizeof(*attr_float64)*len);
|
||||
H5ReadFileAttribFloat64 (f, ATTR_FLOAT64, attr_float64);
|
||||
printf ("%s:", ATTR_FLOAT64);
|
||||
for (int i = 0; i < len; i++) {
|
||||
printf (" %f", attr_float64[i]);
|
||||
}
|
||||
printf ("\n");
|
||||
free (attr_float64);
|
||||
|
||||
|
||||
H5CloseFile (f);
|
||||
MPI_Finalize ();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
!
|
||||
! Copyright (c) 2006-2013, 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.f90'
|
||||
|
||||
program read_file_attribs
|
||||
use H5hut
|
||||
implicit none
|
||||
include 'mpif.h'
|
||||
|
||||
! the file name we want to read
|
||||
character (len=*), parameter :: FNAME = "example_file_attribs.h5"
|
||||
|
||||
! verbosity level: set it to a power of 2 minus one or zero
|
||||
integer*8, parameter :: verbosity_level = 1
|
||||
|
||||
! we know the attribute names!
|
||||
character (len=*), parameter :: ATTR_STRING = "FileAttrString"
|
||||
character (len=*), parameter :: ATTR_I4 = "FileAttrInt32"
|
||||
character (len=*), parameter :: ATTR_I8 = "FileAttrInt64"
|
||||
character (len=*), parameter :: ATTR_R4 = "FileAttrFloat32"
|
||||
character (len=*), parameter :: ATTR_R8 = "FileAttrFloat64"
|
||||
|
||||
! for formated output
|
||||
character (len=128) :: fmt
|
||||
|
||||
! attribute values. Note: allocatable strings aren't supported in Fortran90
|
||||
character (len=256) :: string_value
|
||||
integer*4, allocatable :: i4_value (:)
|
||||
integer*8, allocatable :: i8_value (:)
|
||||
real*4, allocatable :: r4_value (:)
|
||||
real*8, allocatable :: r8_value (:)
|
||||
|
||||
! used for mpi error return
|
||||
integer :: ierr
|
||||
|
||||
! H5hut file id
|
||||
integer*8 :: file_id
|
||||
|
||||
! H5hut API status return
|
||||
integer*8 status
|
||||
|
||||
! type of attribute
|
||||
integer*8 type
|
||||
|
||||
! len of attribute
|
||||
integer*8 len
|
||||
|
||||
! loop index
|
||||
integer*8 i
|
||||
|
||||
call mpi_init (ierr)
|
||||
|
||||
! abort program on any H5hut error
|
||||
call h5_abort_on_error ()
|
||||
|
||||
call h5_set_verbosity_level (verbosity_level)
|
||||
|
||||
! MPI_COMM_WORLD is used, if file is opened with default properties
|
||||
file_id = h5_openfile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT)
|
||||
|
||||
! read and output string attribute
|
||||
status = h5_getfileattribinfo_by_name (file_id, ATTR_STRING, type, len)
|
||||
status = h5_readfileattrib_string (file_id, ATTR_STRING, string_value)
|
||||
write (fmt, "(a, i0, a)") '(a', len, ')'
|
||||
write (*, "(a, ' = ')", advance='no') ATTR_STRING
|
||||
write (*, fmt) string_value
|
||||
|
||||
! read and output 32bit integer attribute
|
||||
status = h5_getfileattribinfo_by_name (file_id, ATTR_I4, type, len)
|
||||
allocate (i4_value(len))
|
||||
status = h5_readfileattrib_i4 (file_id, ATTR_I4, i4_value)
|
||||
write (fmt, "(a, i0, a)") '(', len, 'i4)'
|
||||
write (*, "(a, ' =')", advance='no') ATTR_I4
|
||||
write (*, fmt) (i4_value(i), i = 1, len)
|
||||
|
||||
! read and output 64bit integer attribute
|
||||
status = h5_getfileattribinfo_by_name (file_id, ATTR_I8, type, len)
|
||||
allocate (i8_value(len))
|
||||
status = h5_readfileattrib_i8 (file_id, ATTR_I8, i8_value)
|
||||
write (fmt, "(a, i0, a)") '(', len, 'i4)'
|
||||
write (*, "(a, ' =')", advance='no') ATTR_I8
|
||||
write (*, fmt) (i8_value(i), i = 1, len)
|
||||
|
||||
! read and output 32bit floating point attribute
|
||||
status = h5_getfileattribinfo_by_name (file_id, ATTR_R4, type, len)
|
||||
allocate (r4_value(len))
|
||||
status = h5_readfileattrib_r4 (file_id, ATTR_R4, r4_value)
|
||||
write (fmt, "(a, i0, a)") '(', len, 'f10.5)'
|
||||
write (*, "(a, ' =')", advance='no') ATTR_R4
|
||||
write (*, fmt) (r4_value(i), i = 1, len)
|
||||
|
||||
! read and output 64bit floating point attribute
|
||||
status = h5_getfileattribinfo_by_name (file_id, ATTR_R8, type, len)
|
||||
allocate (r8_value(len))
|
||||
status = h5_readfileattrib_r8 (file_id, ATTR_R8, r8_value)
|
||||
write (fmt, "(a, i0, a)") '(', len, 'f10.5)'
|
||||
write (*, "(a, ' =')", advance='no') ATTR_R8
|
||||
write (*, fmt) (r8_value(i), i = 1, len)
|
||||
|
||||
! cleanup
|
||||
status = h5_closefile (file_id)
|
||||
call mpi_finalize(ierr)
|
||||
|
||||
end program read_file_attribs
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
Copyright (c) 2006-2013, 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"
|
||||
|
||||
#define FNAME "example_step_attribs.h5"
|
||||
|
||||
#define ATTR_STRING "StepAttrString"
|
||||
#define ATTR_INT32 "StepAttrInt32"
|
||||
#define ATTR_INT64 "StepAttrInt64"
|
||||
#define ATTR_FLOAT32 "StepAttrFloat32"
|
||||
#define ATTR_FLOAT64 "StepAttrFloat64"
|
||||
|
||||
int
|
||||
main (
|
||||
int argc,
|
||||
char** argv
|
||||
) {
|
||||
h5_size_t len;
|
||||
|
||||
MPI_Init (&argc, &argv);
|
||||
H5AbortOnError ();
|
||||
// if file properties is set to default, MPI_COMM_WORLD will be used
|
||||
h5_file_t f = H5OpenFile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT);
|
||||
|
||||
H5SetStep (f, 1);
|
||||
|
||||
H5GetStepAttribInfoByName (f, ATTR_STRING, NULL, &len);
|
||||
char* attr_string = malloc (len+1);
|
||||
H5ReadStepAttribString (f, ATTR_STRING, attr_string);
|
||||
printf ("%s: %s\n", ATTR_STRING, attr_string);
|
||||
free (attr_string);
|
||||
|
||||
H5GetStepAttribInfoByName (f, ATTR_INT32, NULL, &len);
|
||||
int32_t* attr_int32 = malloc (sizeof(*attr_int32)*len);
|
||||
H5ReadStepAttribInt32 (f, ATTR_INT32, attr_int32);
|
||||
printf ("%s:", ATTR_INT32);
|
||||
for (int i = 0; i < len; i++) {
|
||||
printf (" %d", attr_int32[i]);
|
||||
}
|
||||
printf ("\n");
|
||||
free (attr_int32);
|
||||
|
||||
H5GetStepAttribInfoByName (f, ATTR_INT64, NULL, &len);
|
||||
int64_t* attr_int64 = malloc (sizeof(*attr_int64)*len);
|
||||
H5ReadStepAttribInt64 (f, ATTR_INT64, attr_int64);
|
||||
printf ("%s:", ATTR_INT64);
|
||||
for (int i = 0; i < len; i++) {
|
||||
printf (" %lld", (long long int)attr_int64[i]);
|
||||
}
|
||||
printf ("\n");
|
||||
free (attr_int64);
|
||||
|
||||
H5GetStepAttribInfoByName (f, ATTR_FLOAT32, NULL, &len);
|
||||
h5_float32_t* attr_float32 = malloc (sizeof(*attr_float32)*len);
|
||||
H5ReadStepAttribFloat32 (f, ATTR_FLOAT32, attr_float32);
|
||||
printf ("%s:", ATTR_FLOAT32);
|
||||
for (int i = 0; i < len; i++) {
|
||||
printf (" %f", attr_float32[i]);
|
||||
}
|
||||
printf ("\n");
|
||||
free (attr_float32);
|
||||
|
||||
H5GetStepAttribInfoByName (f, ATTR_FLOAT64, NULL, &len);
|
||||
h5_float64_t* attr_float64 = malloc (sizeof(*attr_float64)*len);
|
||||
H5ReadStepAttribFloat64 (f, ATTR_FLOAT64, attr_float64);
|
||||
printf ("%s:", ATTR_FLOAT64);
|
||||
for (int i = 0; i < len; i++) {
|
||||
printf (" %f", attr_float64[i]);
|
||||
}
|
||||
printf ("\n");
|
||||
free (attr_float64);
|
||||
|
||||
|
||||
H5CloseFile (f);
|
||||
MPI_Finalize ();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
!
|
||||
! Copyright (c) 2006-2013, 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.f90'
|
||||
|
||||
program read_step_attribs
|
||||
use H5hut
|
||||
implicit none
|
||||
include 'mpif.h'
|
||||
|
||||
! the file name we want to read
|
||||
character (len=*), parameter :: FNAME = "example_file_attribs.h5"
|
||||
|
||||
! verbosity level: set it to a power of 2 minus one or zero
|
||||
integer*8, parameter :: verbosity_level = 1
|
||||
|
||||
! we know the attribute names!
|
||||
character (len=*), parameter :: ATTR_STRING = "StepAttrString"
|
||||
character (len=*), parameter :: ATTR_I4 = "StepAttrInt32"
|
||||
character (len=*), parameter :: ATTR_I8 = "StepAttrInt64"
|
||||
character (len=*), parameter :: ATTR_R4 = "StepAttrFloat32"
|
||||
character (len=*), parameter :: ATTR_R8 = "StepAttrFloat64"
|
||||
|
||||
! for formated output
|
||||
character (len=128) :: fmt
|
||||
|
||||
! attribute values. Note: allocatable strings aren't supported in Fortran90
|
||||
character (len=256) :: string_value
|
||||
integer*4, allocatable :: i4_value (:)
|
||||
integer*8, allocatable :: i8_value (:)
|
||||
real*4, allocatable :: r4_value (:)
|
||||
real*8, allocatable :: r8_value (:)
|
||||
|
||||
! used for mpi error return
|
||||
integer :: ierr
|
||||
|
||||
! H5hut file id
|
||||
integer*8 :: file_id
|
||||
|
||||
! H5hut API status return
|
||||
integer*8 status
|
||||
|
||||
! type of attribute
|
||||
integer*8 type
|
||||
|
||||
! len of attribute
|
||||
integer*8 len
|
||||
|
||||
! loop index
|
||||
integer*8 i
|
||||
|
||||
call mpi_init (ierr)
|
||||
|
||||
! abort program on any H5hut error
|
||||
call h5_abort_on_error ()
|
||||
|
||||
call h5_set_verbosity_level (verbosity_level)
|
||||
|
||||
! MPI_COMM_WORLD is used, if file is opened with default properties
|
||||
file_id = h5_openfile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT)
|
||||
|
||||
! open step 1
|
||||
status = h5_setstep (file_id, int8(1))
|
||||
|
||||
! read and output string attribute
|
||||
status = h5_getstepattribinfo_by_name (file_id, ATTR_STRING, type, len)
|
||||
status = h5_readstepattrib_string (file_id, ATTR_STRING, string_value)
|
||||
write (fmt, "(a, i0, a)") '(a', len, ')'
|
||||
write (*, "(a, ' = ')", advance='no') ATTR_STRING
|
||||
write (*, fmt) string_value
|
||||
|
||||
! read and output 32bit integer attribute
|
||||
status = h5_getstepattribinfo_by_name (file_id, ATTR_I4, type, len)
|
||||
allocate (i4_value(len))
|
||||
status = h5_readstepattrib_i4 (file_id, ATTR_I4, i4_value)
|
||||
write (fmt, "(a, i0, a)") '(', len, 'i4)'
|
||||
write (*, "(a, ' =')", advance='no') ATTR_I4
|
||||
write (*, fmt) (i4_value(i), i = 1, len)
|
||||
|
||||
! read and output 64bit integer attribute
|
||||
status = h5_getstepattribinfo_by_name (file_id, ATTR_I8, type, len)
|
||||
allocate (i8_value(len))
|
||||
status = h5_readstepattrib_i8 (file_id, ATTR_I8, i8_value)
|
||||
write (fmt, "(a, i0, a)") '(', len, 'i4)'
|
||||
write (*, "(a, ' =')", advance='no') ATTR_I8
|
||||
write (*, fmt) (i8_value(i), i = 1, len)
|
||||
|
||||
! read and output 32bit floating point attribute
|
||||
status = h5_getstepattribinfo_by_name (file_id, ATTR_R4, type, len)
|
||||
allocate (r4_value(len))
|
||||
status = h5_readstepattrib_r4 (file_id, ATTR_R4, r4_value)
|
||||
write (fmt, "(a, i0, a)") '(', len, 'f10.5)'
|
||||
write (*, "(a, ' =')", advance='no') ATTR_R4
|
||||
write (*, fmt) (r4_value(i), i = 1, len)
|
||||
|
||||
! read and output 64bit floating point attribute
|
||||
status = h5_getstepattribinfo_by_name (file_id, ATTR_R8, type, len)
|
||||
allocate (r8_value(len))
|
||||
status = h5_readstepattrib_r8 (file_id, ATTR_R8, r8_value)
|
||||
write (fmt, "(a, i0, a)") '(', len, 'f10.5)'
|
||||
write (*, "(a, ' =')", advance='no') ATTR_R8
|
||||
write (*, fmt) (r8_value(i), i = 1, len)
|
||||
|
||||
! cleanup
|
||||
status = h5_closefile (file_id)
|
||||
call mpi_finalize(ierr)
|
||||
|
||||
end program read_step_attribs
|
||||
@@ -1,31 +1,48 @@
|
||||
/*
|
||||
Copyright (c) 2006-2013, 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"
|
||||
|
||||
#define FNAME "example_file_attribs.h5"
|
||||
|
||||
#define ATTR_STRING "FileAttrString"
|
||||
#define ATTR_INT32 "FileAttrInt32"
|
||||
#define ATTR_INT64 "FileAttrInt64"
|
||||
#define ATTR_FLOAT32 "FileAttrFloat32"
|
||||
#define ATTR_FLOAT64 "FileAttrFloat64"
|
||||
|
||||
#define asize(array) (sizeof(array)/sizeof(array[0]))
|
||||
|
||||
int
|
||||
main (
|
||||
int argc,
|
||||
char** argv
|
||||
) {
|
||||
MPI_Comm comm = MPI_COMM_WORLD;
|
||||
char* string_value = "This is a string attribute bound to the file.";
|
||||
int32_t int32_value[] = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144};
|
||||
int64_t int64_value[] = {42, 43, 44, 45};
|
||||
h5_float32_t float32_value[] = {2.71828};
|
||||
h5_float64_t float64_value[] = {3.14159265358979323846264338327950288419716939937510};
|
||||
|
||||
int myproc;
|
||||
int nprocs;
|
||||
MPI_Init (&argc, &argv);
|
||||
MPI_Comm_size (comm, &nprocs);
|
||||
MPI_Comm_rank (comm, &myproc);
|
||||
|
||||
h5_file_t f = H5OpenFile ("testfile.h5", H5_O_WRONLY, comm);
|
||||
H5WriteFileAttribString (f, "FileAttrString", "This is a string attribute bound to the file.");
|
||||
H5AbortOnError ();
|
||||
|
||||
// if file properties is set to default, MPI_COMM_WORLD will be used
|
||||
h5_file_t f = H5OpenFile (FNAME, H5_O_WRONLY, H5_PROP_DEFAULT);
|
||||
H5WriteFileAttribString (f, ATTR_STRING, string_value);
|
||||
H5WriteFileAttribInt32 (f, ATTR_INT32, int32_value, asize(int32_value));
|
||||
H5WriteFileAttribInt64 (f, ATTR_INT64, int64_value, asize(int64_value));
|
||||
H5WriteFileAttribFloat32 (f, ATTR_FLOAT32, float32_value, asize(float32_value));
|
||||
H5WriteFileAttribFloat64 (f, ATTR_FLOAT64, float64_value, asize(float32_value));
|
||||
|
||||
H5CloseFile (f);
|
||||
|
||||
h5_prop_t prop = H5CreateFileProp ();
|
||||
H5SetPropFileMPIO (prop, &comm);
|
||||
f = H5OpenFile2 ("testfile.h5", H5_O_APPEND, prop);
|
||||
H5CloseProp (prop);
|
||||
int64_t id[] = {42, 43, 44, 45};
|
||||
H5WriteFileAttribInt64 (f, "FileAttrInt64", id, sizeof(id)/sizeof(id[0]));
|
||||
H5CloseFile (f);
|
||||
|
||||
MPI_Finalize ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
!
|
||||
! Copyright (c) 2006-2013, 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.f90'
|
||||
|
||||
program write_file_attribs
|
||||
use H5hut
|
||||
implicit none
|
||||
include 'mpif.h'
|
||||
|
||||
integer*8, parameter :: verbosity_level = 1
|
||||
|
||||
character (len=*), parameter :: FNAME = "example_file_attribs.h5"
|
||||
character (len=*), parameter :: ATTR_STRING = "FileAttrString"
|
||||
character (len=*), parameter :: ATTR_I4 = "FileAttrInt32"
|
||||
character (len=*), parameter :: ATTR_I8 = "FileAttrInt64"
|
||||
character (len=*), parameter :: ATTR_R4 = "FileAttrFloat32"
|
||||
character (len=*), parameter :: ATTR_R8 = "FileAttrFloat64"
|
||||
|
||||
character (len=*),parameter :: string_value = "This is a string attribute bound to the file."
|
||||
|
||||
integer*4, parameter, dimension(*) :: i4_value = (/0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144/)
|
||||
integer*8, parameter, dimension(*) :: i8_value = (/42, 43, 44, 45/)
|
||||
real*4, parameter, dimension(*) :: r4_value = (/2.71828/)
|
||||
real*8, parameter, dimension(*) :: r8_value = (/3.141592653589793238462643383279502884197169/)
|
||||
|
||||
integer :: ierr
|
||||
integer*8 :: file_id, status
|
||||
|
||||
call mpi_init(ierr)
|
||||
|
||||
! abort program on any H5hut error
|
||||
call h5_abort_on_error()
|
||||
|
||||
call h5_set_verbosity_level (verbosity_level)
|
||||
|
||||
! MPI_COMM_WORLD is used, if file is opened with default properties
|
||||
file_id = h5_openfile (FNAME, H5_O_WRONLY, H5_PROP_DEFAULT)
|
||||
|
||||
! write attributes
|
||||
status = h5_writefileattrib_string (file_id, ATTR_STRING, string_value)
|
||||
status = h5_writefileattrib_i4 (file_id, ATTR_I4, i4_value, int8(size(i4_value, 1)))
|
||||
status = h5_writefileattrib_i8 (file_id, ATTR_I8, i8_value, int8(size(i8_value, 1)))
|
||||
status = h5_writefileattrib_r4 (file_id, ATTR_R4, r4_value, int8(size(r4_value, 1)))
|
||||
status = h5_writefileattrib_r8 (file_id, ATTR_R8, r8_value, int8(size(r8_value, 1)))
|
||||
|
||||
! cleanup
|
||||
status = h5_closefile (file_id)
|
||||
call mpi_finalize(ierr)
|
||||
|
||||
end program write_file_attribs
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Copyright (c) 2006-2013, 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"
|
||||
|
||||
#define FNAME "example_step_attribs.h5"
|
||||
|
||||
#define ATTR_STRING "StepAttrString"
|
||||
#define ATTR_INT32 "StepAttrInt32"
|
||||
#define ATTR_INT64 "StepAttrInt64"
|
||||
#define ATTR_FLOAT32 "StepAttrFloat32"
|
||||
#define ATTR_FLOAT64 "StepAttrFloat64"
|
||||
|
||||
#define asize(array) (sizeof(array)/sizeof(array[0]))
|
||||
|
||||
int
|
||||
main (
|
||||
int argc,
|
||||
char** argv
|
||||
) {
|
||||
char* string_value = "This is a string attribute bound to this step.";
|
||||
int32_t int32_value[] = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144};
|
||||
int64_t int64_value[] = {42, 43, 44, 45};
|
||||
h5_float32_t float32_value[] = {2.71828};
|
||||
h5_float64_t float64_value[] = {3.14159265358979323846264338327950288419716939937510};
|
||||
|
||||
MPI_Init (&argc, &argv);
|
||||
|
||||
H5AbortOnError ();
|
||||
|
||||
// if file properties is set to default, MPI_COMM_WORLD will be used
|
||||
h5_file_t f = H5OpenFile (FNAME, H5_O_WRONLY, H5_PROP_DEFAULT);
|
||||
H5SetStep (f, 1);
|
||||
H5WriteStepAttribString (f, ATTR_STRING, string_value);
|
||||
H5WriteStepAttribInt32 (f, ATTR_INT32, int32_value, asize(int32_value));
|
||||
H5WriteStepAttribInt64 (f, ATTR_INT64, int64_value, asize(int64_value));
|
||||
H5WriteStepAttribFloat32 (f, ATTR_FLOAT32, float32_value, asize(float32_value));
|
||||
H5WriteStepAttribFloat64 (f, ATTR_FLOAT64, float64_value, asize(float32_value));
|
||||
|
||||
H5CloseFile (f);
|
||||
MPI_Finalize ();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
!
|
||||
! Copyright (c) 2006-2013, 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.f90'
|
||||
|
||||
program write_step_attribs
|
||||
use H5hut
|
||||
implicit none
|
||||
include 'mpif.h'
|
||||
|
||||
integer*8, parameter :: verbosity_level = 1
|
||||
character (len=*), parameter :: FNAME = "example_step_attribs.h5"
|
||||
|
||||
character (len=*), parameter :: ATTR_STRING = "StepAttrString"
|
||||
character (len=*), parameter :: ATTR_I4 = "StepAttrInt32"
|
||||
character (len=*), parameter :: ATTR_I8 = "StepAttrInt64"
|
||||
character (len=*), parameter :: ATTR_R4 = "StepAttrFloat32"
|
||||
character (len=*), parameter :: ATTR_R8 = "StepAttrFloat64"
|
||||
|
||||
character (len=*),parameter :: string_value = "This is a string attribute bound to the file."
|
||||
|
||||
integer*4, parameter, dimension(*) :: i4_value = (/0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144/)
|
||||
integer*8, parameter, dimension(*) :: i8_value = (/42, 43, 44, 45/)
|
||||
real*4, parameter, dimension(*) :: r4_value = (/2.71828/)
|
||||
real*8, parameter, dimension(*) :: r8_value = (/3.141592653589793238462643383279502884197169/)
|
||||
|
||||
integer :: ierr
|
||||
integer*8 :: file_id, status
|
||||
|
||||
call mpi_init(ierr)
|
||||
|
||||
! abort program on any H5hut error
|
||||
call h5_abort_on_error()
|
||||
|
||||
call h5_set_verbosity_level (verbosity_level)
|
||||
|
||||
! MPI_COMM_WORLD is used, if file is opened with default properties
|
||||
file_id = h5_openfile (FNAME, H5_O_WRONLY, H5_PROP_DEFAULT)
|
||||
|
||||
! open step 1
|
||||
status = h5_setstep (file_id, int8(1))
|
||||
|
||||
! write attributes
|
||||
status = h5_writestepattrib_string (file_id, ATTR_STRING, string_value)
|
||||
status = h5_writestepattrib_i4 (file_id, ATTR_I4, i4_value, int8(size(i4_value, 1)))
|
||||
status = h5_writestepattrib_i8 (file_id, ATTR_I8, i8_value, int8(size(i8_value, 1)))
|
||||
status = h5_writestepattrib_r4 (file_id, ATTR_R4, r4_value, int8(size(r4_value, 1)))
|
||||
status = h5_writestepattrib_r8 (file_id, ATTR_R8, r8_value, int8(size(r8_value, 1)))
|
||||
|
||||
! cleanup
|
||||
status = h5_closefile (file_id)
|
||||
call mpi_finalize(ierr)
|
||||
|
||||
end program write_step_attribs
|
||||
+97
-130
@@ -11,152 +11,119 @@
|
||||
#ifdef PARALLEL_IO
|
||||
|
||||
int main(int argc,char *argv[]){
|
||||
int sz=5;
|
||||
double *x,*y,*z;
|
||||
h5_int64_t *id;
|
||||
h5_file_t file;
|
||||
int i,t,nt,nds;
|
||||
int nprocs,myproc;
|
||||
MPI_Comm comm=MPI_COMM_WORLD;
|
||||
int sz=5;
|
||||
double *x,*y,*z;
|
||||
h5_int64_t *id;
|
||||
h5_file_t file;
|
||||
int i,t,nt,nds;
|
||||
|
||||
MPI_Init(&argc,&argv);
|
||||
MPI_Comm_size(comm,&nprocs);
|
||||
MPI_Comm_rank(comm,&myproc);
|
||||
int nprocs = 1;
|
||||
int myproc = 0;
|
||||
MPI_Comm comm = MPI_COMM_WORLD;
|
||||
|
||||
x=(double*)malloc(sz*nprocs*sizeof(double));
|
||||
y=(double*)malloc(sz*nprocs*sizeof(double));
|
||||
z=(double*)malloc(sz*nprocs*sizeof(double));
|
||||
id=(h5_int64_t*)malloc(sz*nprocs*sizeof(h5_int64_t));
|
||||
/* parallel file creation */
|
||||
file=H5OpenFile ("parttest.h5",H5_O_WRONLY,comm);
|
||||
if(!file) {
|
||||
perror("File open failed: exiting!");
|
||||
exit(0);
|
||||
}
|
||||
#if PARALLEL_IO
|
||||
MPI_Init (&argc,&argv);
|
||||
MPI_Comm_size (comm,&nprocs);
|
||||
MPI_Comm_rank (comm,&myproc);
|
||||
#endif
|
||||
x = (double*)malloc (sz*nprocs*sizeof(double));
|
||||
y = (double*)malloc (sz*nprocs*sizeof(double));
|
||||
z = (double*)malloc (sz*nprocs*sizeof(double));
|
||||
id=(h5_int64_t*)malloc (sz*nprocs*sizeof(h5_int64_t));
|
||||
|
||||
for(t=0;t<5;t++){
|
||||
MPI_Barrier(comm);
|
||||
for(i=0;i<sz;i++) {
|
||||
x[i]=(double)(i+t)+10.0*(double)myproc;
|
||||
y[i]=0.1 + (double)(i+t);
|
||||
z[i]=0.2 + (double)(i+t*10);
|
||||
id[i]=i+sz*myproc;
|
||||
}
|
||||
printf("Proc[%u] Writing timestep %u \n",myproc,t);
|
||||
H5SetStep(file,t); /* must set the current timestep in file */
|
||||
H5PartSetNumParticles(file,sz); /* then set number of particles to store */
|
||||
/* now write different tuples of data into this timestep of the file */
|
||||
H5PartWriteDataFloat64(file,"x",x);
|
||||
H5PartWriteDataFloat64(file,"y",y);
|
||||
H5PartWriteDataFloat64(file,"z",z);
|
||||
file=H5OpenFile ("parttest.h5",H5_O_WRONLY,comm);
|
||||
if(!file) {
|
||||
perror("File open failed: exiting!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
H5PartWriteDataFloat64(file,"px",x);
|
||||
H5PartWriteDataFloat64(file,"py",y);
|
||||
H5PartWriteDataFloat64(file,"pz",z);
|
||||
H5PartWriteFileAttribString (
|
||||
file,
|
||||
"File Description",
|
||||
"This file is created by H5PartTest.cc. "
|
||||
"Simple H5Part file for testing purpose...");
|
||||
char* FileAttrib = "Created by H5PartTest.cc";
|
||||
H5PartWriteFileAttrib (
|
||||
file,
|
||||
"Origin",
|
||||
H5T_NATIVE_CHAR,
|
||||
FileAttrib ,strlen(FileAttrib));
|
||||
|
||||
H5PartWriteDataInt64(file,"id",id);
|
||||
}
|
||||
for(t=0;t<5;t++){
|
||||
MPI_Barrier(comm);
|
||||
for(i=0;i<sz;i++) {
|
||||
x[i]=(double)(i+t)+10.0*(double)myproc;
|
||||
y[i]=0.1 + (double)(i+t);
|
||||
z[i]=0.2 + (double)(i+t*10);
|
||||
id[i]=i+sz*myproc;
|
||||
}
|
||||
printf("Proc[%u] Writing timestep %u \n",myproc,t);
|
||||
H5SetStep(file,t); /* must set the current timestep in file */
|
||||
H5PartSetNumParticles(file,sz); /* then set number of particles to store */
|
||||
/* now write different tuples of data into this timestep of the file */
|
||||
H5PartWriteDataFloat64(file,"x",x);
|
||||
H5PartWriteDataFloat64(file,"y",y);
|
||||
H5PartWriteDataFloat64(file,"z",z);
|
||||
|
||||
H5PartWriteDataFloat64(file,"px",x);
|
||||
H5PartWriteDataFloat64(file,"py",y);
|
||||
H5PartWriteDataFloat64(file,"pz",z);
|
||||
|
||||
unsigned int idStart = 0+sz*myproc;
|
||||
unsigned int idEnd = (sz-1)+sz*myproc;
|
||||
H5PartWriteDataInt64(file,"id",id);
|
||||
H5PartWriteStepAttribString (
|
||||
file,
|
||||
"Step Description",
|
||||
"STEP STEP STEP");
|
||||
char* StepAttrib = "STEP";
|
||||
H5PartWriteStepAttrib (
|
||||
file,
|
||||
"Step",
|
||||
H5T_NATIVE_CHAR,
|
||||
StepAttrib ,strlen(StepAttrib));
|
||||
|
||||
printf("AllDone p[%u]\n",myproc);
|
||||
H5CloseFile(file);
|
||||
fprintf(stderr,"Closed files p[%u]\n",myproc);
|
||||
MPI_Barrier(comm);
|
||||
}
|
||||
|
||||
printf("Done writing p[%u]\n",myproc);
|
||||
H5CloseFile(file);
|
||||
fprintf(stderr,"Closed files p[%u]\n",myproc);
|
||||
MPI_Barrier(comm);
|
||||
|
||||
fprintf(stderr,"p[%u:%u] : OK, close file and reopen for reading idStart %u idEnd %u \n",myproc,nprocs,idStart,idEnd);
|
||||
fprintf(stderr,
|
||||
"p[%u:%u] : OK, close file and reopen for reading idStart %u idEnd %u \n",
|
||||
myproc,nprocs,idStart,idEnd);
|
||||
|
||||
file=H5OpenFile("parttest.h5",H5_O_RDONLY,comm);
|
||||
H5SetStep(file,0);
|
||||
// unsigned int np = 0;
|
||||
unsigned int np = (int)H5PartGetNumParticles(file);
|
||||
nt=H5GetNumSteps(file); /* get number of steps in file */
|
||||
nds=H5PartGetNumDatasets(file); /* get number of datasets in timestep 0 */
|
||||
unsigned int idStart = 0+sz*myproc;
|
||||
unsigned int idEnd = (sz-1)+sz*myproc;
|
||||
|
||||
MPI_Barrier(comm);
|
||||
|
||||
file=H5OpenFile("parttest.h5",H5_O_RDONLY,comm);
|
||||
H5SetStep(file,0);
|
||||
// unsigned int np = 0;
|
||||
unsigned int np = (int)H5PartGetNumParticles(file);
|
||||
nt=H5GetNumSteps(file); /* get number of steps in file */
|
||||
nds=H5PartGetNumDatasets(file); /* get number of datasets in timestep 0 */
|
||||
|
||||
MPI_Barrier(comm);
|
||||
|
||||
H5PartSetView(file,idStart,idEnd);
|
||||
H5PartSetView(file,idStart,idEnd);
|
||||
|
||||
np = (int)H5PartGetNumParticles(file);
|
||||
printf("After SetView(%d,%d): steps= %u datasets= %u particles= %u\n",
|
||||
(int)idStart,(int)idEnd,
|
||||
nt,nds,np);
|
||||
np = (int)H5PartGetNumParticles(file);
|
||||
printf("After SetView(%d,%d): steps= %u datasets= %u particles= %u\n",
|
||||
(int)idStart,(int)idEnd,
|
||||
nt,nds,np);
|
||||
|
||||
free(x);
|
||||
free(y);
|
||||
free(z);
|
||||
free(id);
|
||||
|
||||
if(x)
|
||||
free(x);
|
||||
if(y)
|
||||
free(y);
|
||||
if(z)
|
||||
free(z);
|
||||
if(id)
|
||||
free(id);
|
||||
|
||||
H5CloseFile(file);
|
||||
MPI_Barrier(comm);
|
||||
fprintf(stderr,"proc[%u]: done\n",myproc);
|
||||
return MPI_Finalize();
|
||||
H5CloseFile(file);
|
||||
MPI_Barrier(comm);
|
||||
fprintf(stderr,"proc[%u]: done\n",myproc);
|
||||
return MPI_Finalize();
|
||||
}
|
||||
|
||||
#else
|
||||
int main(int argc,char *argv[]){
|
||||
int sz=10;
|
||||
double *x,*y,*z;
|
||||
h5_int64_t *id;
|
||||
h5_file_t *file;
|
||||
int i,t,nt,nds,np;
|
||||
h5_int64_t idStart = 0;
|
||||
h5_int64_t idEnd = 0;
|
||||
|
||||
|
||||
x=(double*)malloc(sz*sizeof(double));
|
||||
y=(double*)malloc(sz*sizeof(double));
|
||||
z=(double*)malloc(sz*sizeof(double));
|
||||
id=(h5_int64_t*)malloc(sz*sizeof(h5_int64_t));
|
||||
/* parallel file creation */
|
||||
file=H5PartOpenFile("parttest.h5",H5_O_WRONLY);
|
||||
if(!file) {
|
||||
perror("File open failed: exiting!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
H5PartWriteFileAttribString(file,"File Description", "This file is created by H5PartTest.cc. Simple H5Part file for testing purpose...");
|
||||
char* FileAttrib = "Created by H5PartTest.cc";
|
||||
H5PartWriteFileAttrib(file, "Origin", H5T_NATIVE_CHAR, FileAttrib ,strlen(FileAttrib));
|
||||
|
||||
for(t=0;t<5;t++){
|
||||
fprintf(stdout,"Writing timestep %u\n",t);
|
||||
for(i=0;i<sz;i++) {
|
||||
x[i]=(double)(i+t);
|
||||
y[i]=0.1 + (double)(i+t);
|
||||
z[i]=0.2 + (double)(i+t*10);
|
||||
id[i]=i;
|
||||
fprintf(stdout,"\tp[%u] x=%f y=%f z=%f id=%d\n",
|
||||
i,x[i],y[i],z[i],(int)id[i]);
|
||||
}
|
||||
H5PartSetStep(file,t); /* must set the current timestep in file */
|
||||
|
||||
H5PartSetNumParticles(file,sz); /* then set number of particles to store */
|
||||
/* now write different tuples of data into this timestep of the file */
|
||||
H5PartWriteDataFloat64(file,"x",x);
|
||||
H5PartWriteDataFloat64(file,"y",y);
|
||||
H5PartWriteDataFloat64(file,"z",z);
|
||||
|
||||
H5PartWriteDataFloat64(file,"px",x);
|
||||
H5PartWriteDataFloat64(file,"py",y);
|
||||
H5PartWriteDataFloat64(file,"pz",z);
|
||||
|
||||
H5PartWriteDataInt64(file,"id",id);
|
||||
|
||||
H5PartWriteStepAttribString(file,"Step Description", "STEP STEP STEP");
|
||||
char* StepAttrib = "STEP";
|
||||
H5PartWriteStepAttrib(file, "Step", H5T_NATIVE_CHAR, StepAttrib ,strlen(StepAttrib));
|
||||
}
|
||||
|
||||
|
||||
printf("AllDone writing\n");
|
||||
H5PartCloseFile(file);
|
||||
|
||||
|
||||
/*+++++++++++++ Reopen File for Reading +++H5PartSetStep(h5partFile,0)++++++++*/
|
||||
file=H5PartOpenFile("parttest.h5",H5_O_RDONLY);
|
||||
|
||||
Reference in New Issue
Block a user