From 3137063d22af526e6ab036779b788f9a241b18ba Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Fri, 8 Apr 2016 19:06:42 +0200 Subject: [PATCH] example/H5Block: - has_field.c added --- examples/H5Block/Makefile.am | 6 ++- examples/H5Block/has_field.c | 82 ++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 examples/H5Block/has_field.c diff --git a/examples/H5Block/Makefile.am b/examples/H5Block/Makefile.am index b739d7d..4291150 100644 --- a/examples/H5Block/Makefile.am +++ b/examples/H5Block/Makefile.am @@ -24,8 +24,9 @@ LDADD += -lH5hut noinst_PROGRAMS = if ENABLE_C -noinst_PROGRAMS += \ - fields \ +noinst_PROGRAMS += \ + fields \ + has_field \ read_write_scalar_field \ write_field endif @@ -37,6 +38,7 @@ endif endif fields_SOURCES = fields.c +has_field_SOURCES = has_field.c read_write_scalar_field_SOURCES = read_write_scalar_field.c read_write_scalar_fieldf_SOURCES = read_write_scalar_fieldf.f90 write_field_SOURCES = write_field.c diff --git a/examples/H5Block/has_field.c b/examples/H5Block/has_field.c new file mode 100644 index 0000000..90f5179 --- /dev/null +++ b/examples/H5Block/has_field.c @@ -0,0 +1,82 @@ +/* + 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 output file +const char* fname = "example_write_field.h5"; + +// H5hut verbosity level +const h5_int64_t h5_verbosity = H5_VERBOSE_DEFAULT; + +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); + //H5SetDebugMask (-1); + + // open file and create first step + h5_file_t file = H5OpenFile (fname, H5_O_RDONLY, H5_PROP_DEFAULT); + H5SetStep (file, 0); + + if (!H5BlockHasFieldData (file)) { + goto done; + } + printf ("Has field data in step#0\n"); + + if (!H5BlockHasField (file, "data")) { + goto done; + } + printf ("Has field data with name 'data' in step#0\n"); + + h5_size_t field_rank; + h5_size_t field_dims[3]; + h5_size_t elem_rank; + h5_int64_t type; + H5BlockGetFieldInfoByName ( + file, + "data", + &field_rank, + field_dims, + &elem_rank, + &type); + char* stype = "unknown"; + if (type == H5_INT64_T) { + stype = "H5_INT64_T"; + } else if (type == H5_INT32_T) { + stype = "H5_INT32_T"; + } else if (type == H5_FLOAT64_T) { + stype = "H5_FLOAT64_T"; + } else if (type == H5_FLOAT32_T) { + stype = "H5_FLOAT32_T"; + } else if (type == H5_STRING_T) { + stype = "H5_STRING_T"; + } + printf ("rank of field: %lld\n", field_rank); + printf ("dims of field: [%lld, %lld, %lld]\n", + field_dims[0], field_dims[1], field_dims[2]); + printf ("rank of field data: %lld\n", elem_rank); + printf ("type of field data: '%s'\n", stype); +done: + // done + H5CloseFile(file); + MPI_Finalize (); + return 0; +}