DOLFIN
DOLFIN C++ interface
HDF5Interface.h
1// Copyright (C) 2012 Chris N. Richardson and Garth N. Wells
2//
3// This file is part of DOLFIN.
4//
5// DOLFIN is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// DOLFIN is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU Lesser General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17//
18// First added: 2012-09-21
19
20#ifndef __DOLFIN_HDF5_INTERFACE_H
21#define __DOLFIN_HDF5_INTERFACE_H
22
23#ifdef HAS_HDF5
24
25#include <cstdint>
26#include <vector>
27#include <string>
28
29// Note: dolfin/common/MPI.h is included before hdf5.h to avoid the
30// MPICH_IGNORE_CXX_SEEK issue
31#include <dolfin/common/MPI.h>
32#include <hdf5.h>
33#include <dolfin/log/log.h>
34
35namespace dolfin
36{
37
38 class HDF5File;
39
43
45 {
46 #define HDF5_FAIL -1
47 public:
48
50 static hid_t open_file(MPI_Comm mpi_comm, const std::string filename,
51 const std::string mode, const bool use_mpi_io);
52
54 static void close_file(const hid_t hdf5_file_handle);
55
58 static void flush_file(const hid_t hdf5_file_handle);
59
60 static std::string get_filename(hid_t hdf5_file_handle);
61
69 template <typename T>
70 static void write_dataset(const hid_t file_handle,
71 const std::string dataset_path,
72 const std::vector<T>& data,
73 const std::pair<std::int64_t, std::int64_t> range,
74 const std::vector<std::int64_t> global_size,
75 bool use_mpio, bool use_chunking);
76
81 template <typename T>
82 static void read_dataset(const hid_t file_handle,
83 const std::string dataset_path,
84 const std::pair<std::int64_t, std::int64_t> range,
85 std::vector<T>& data);
86
88 static bool has_group(const hid_t hdf5_file_handle,
89 const std::string group_name);
90
92 static bool has_dataset(const hid_t hdf5_file_handle,
93 const std::string dataset_path);
94
96 static void add_group(const hid_t hdf5_file_handle,
97 const std::string dataset_path);
98
100 static int dataset_rank(const hid_t hdf5_file_handle,
101 const std::string dataset_path);
102
104 static int num_datasets_in_group(const hid_t hdf5_file_handle,
105 const std::string group_name);
106
108 static std::vector<std::int64_t>
109 get_dataset_shape(const hid_t hdf5_file_handle,
110 const std::string dataset_path);
111
113 static std::vector<std::string> dataset_list(const hid_t hdf5_file_handle,
114 const std::string group_name);
115
117 static const std::string
118 get_attribute_type(const hid_t hdf5_file_handle,
119 const std::string dataset_path,
120 const std::string attribute_name);
121
123 template <typename T>
124 static void get_attribute(const hid_t hdf5_file_handle,
125 const std::string dataset_path,
126 const std::string attribute_name,
127 T& attribute_value);
128
130 template <typename T>
131 static void add_attribute(const hid_t hdf5_file_handle,
132 const std::string dataset_path,
133 const std::string attribute_name,
134 const T& attribute_value);
135
137 static void delete_attribute(const hid_t hdf5_file_handle,
138 const std::string dataset_path,
139 const std::string attribute_name);
140
142 static bool has_attribute(const hid_t hdf5_file_handle,
143 const std::string dataset_path,
144 const std::string attribute_name);
145
146 // List attributes of dataset or group
147 static const std::vector<std::string>
148 list_attributes(const hid_t hdf5_file_handle,
149 const std::string dataset_path);
150
157 static void set_mpi_atomicity(const hid_t hdf5_file_handle,
158 const bool atomic);
159
164 static bool get_mpi_atomicity(const hid_t hdf5_file_handle);
165
166 private:
167
168 static herr_t attribute_iteration_function(hid_t loc_id,
169 const char* name,
170 const H5A_info_t* info,
171 void* str);
172
173 template <typename T>
174 static void add_attribute_value(const hid_t dset_id,
175 const std::string attribute_name,
176 const T& attribute_value);
177
178 template <typename T>
179 static void add_attribute_value(const hid_t dset_id,
180 const std::string attribute_name,
181 const std::vector<T>& attribute_value);
182
183 template <typename T>
184 static void get_attribute_value(const hid_t attr_type,
185 const hid_t attr_id,
186 T& attribute_value);
187
188 template <typename T>
189 static void get_attribute_value(const hid_t attr_type,
190 const hid_t attr_id,
191 std::vector<T>& attribute_value);
192
193 // Return HDF5 data type
194 template <typename T>
195 static hid_t hdf5_type()
196 {
197 dolfin_error("HDF5Interface.cpp",
198 "get HDF5 primitive data type",
199 "No specialised function for this data type");
200 return 0;
201 }
202
203 };
204
205 //---------------------------------------------------------------------------
206 template <> inline hid_t HDF5Interface::hdf5_type<float>()
207 { return H5T_NATIVE_FLOAT; }
208 //---------------------------------------------------------------------------
209 template <> inline hid_t HDF5Interface::hdf5_type<double>()
210 { return H5T_NATIVE_DOUBLE; }
211 //---------------------------------------------------------------------------
212 template <> inline hid_t HDF5Interface::hdf5_type<int>()
213 { return H5T_NATIVE_INT; }
214 //---------------------------------------------------------------------------
215 template <> inline hid_t HDF5Interface::hdf5_type<std::int64_t>()
216 { return H5T_NATIVE_INT64; }
217 //---------------------------------------------------------------------------
218 template <> inline hid_t HDF5Interface::hdf5_type<std::size_t>()
219 {
220 if (sizeof(std::size_t) == sizeof(unsigned long))
221 return H5T_NATIVE_ULONG;
222 else if (sizeof(std::size_t) == sizeof(unsigned int))
223 return H5T_NATIVE_UINT;
224 else
225 dolfin_error("HDF5Interface.h",
226 "determine size of std::size_t",
227 "std::size_t is not the same size as long or int");
228 return 0;
229 }
230 //---------------------------------------------------------------------------
231 template <typename T>
232 inline void
233 HDF5Interface::write_dataset(const hid_t file_handle,
234 const std::string dataset_path,
235 const std::vector<T>& data,
236 const std::pair<std::int64_t, std::int64_t> range,
237 const std::vector<int64_t> global_size,
238 bool use_mpi_io, bool use_chunking)
239 {
240 // Data rank
241 const std::size_t rank = global_size.size();
242 dolfin_assert(rank != 0);
243
244 if (rank > 2)
245 {
246 dolfin_error("HDF5Interface.cpp",
247 "write dataset to HDF5 file",
248 "Only rank 1 and rank 2 dataset are supported");
249 }
250
251 // Get HDF5 data type
252 const hid_t h5type = hdf5_type<T>();
253
254 // Hyperslab selection parameters
255 std::vector<hsize_t> count(global_size.begin(), global_size.end());
256 count[0] = range.second - range.first;
257
258 // Data offsets
259 std::vector<hsize_t> offset(rank, 0);
260 offset[0] = range.first;
261
262 // Dataset dimensions
263 const std::vector<hsize_t> dimsf(global_size.begin(), global_size.end());
264
265 // Generic status report
266 herr_t status;
267
268 // Create a global data space
269 const hid_t filespace0 = H5Screate_simple(rank, dimsf.data(), NULL);
270 dolfin_assert(filespace0 != HDF5_FAIL);
271
272 // Set chunking parameters
273 hid_t chunking_properties;
274 if (use_chunking)
275 {
276 // Set chunk size and limit to 1kB min/1MB max
277 hsize_t chunk_size = dimsf[0]/2;
278 if (chunk_size > 1048576)
279 chunk_size = 1048576;
280 if (chunk_size < 1024)
281 chunk_size = 1024;
282
283 hsize_t chunk_dims[2] = {chunk_size, dimsf[1]};
284 chunking_properties = H5Pcreate(H5P_DATASET_CREATE);
285 H5Pset_chunk(chunking_properties, rank, chunk_dims);
286 }
287 else
288 chunking_properties = H5P_DEFAULT;
289
290 // Check that group exists and recursively create if required
291 const std::string group_name(dataset_path, 0, dataset_path.rfind('/'));
292 add_group(file_handle, group_name);
293
294 // Create global dataset (using dataset_path)
295 const hid_t dset_id = H5Dcreate2(file_handle, dataset_path.c_str(), h5type,
296 filespace0, H5P_DEFAULT,
297 chunking_properties, H5P_DEFAULT);
298 dolfin_assert(dset_id != HDF5_FAIL);
299
300 // Close global data space
301 status = H5Sclose(filespace0);
302 dolfin_assert(status != HDF5_FAIL);
303
304 // Create a local data space
305 const hid_t memspace = H5Screate_simple(rank, count.data(), NULL);
306 dolfin_assert(memspace != HDF5_FAIL);
307
308 // Create a file dataspace within the global space - a hyperslab
309 const hid_t filespace1 = H5Dget_space(dset_id);
310 status = H5Sselect_hyperslab(filespace1, H5S_SELECT_SET, offset.data(),
311 NULL, count.data(), NULL);
312 dolfin_assert(status != HDF5_FAIL);
313
314 // Set parallel access
315 const hid_t plist_id = H5Pcreate(H5P_DATASET_XFER);
316 if (use_mpi_io)
317 {
318 #ifdef H5_HAVE_PARALLEL
319 status = H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);
320 dolfin_assert(status != HDF5_FAIL);
321 #else
322 dolfin_error("HDF5Interface.h",
323 "use MPI",
324 "HDF5 library has not been configured with MPI");
325 #endif
326 }
327
328 // Write local dataset into selected hyperslab
329 status = H5Dwrite(dset_id, h5type, memspace, filespace1, plist_id,
330 data.data());
331 dolfin_assert(status != HDF5_FAIL);
332
333 if (use_chunking)
334 {
335 // Close chunking properties
336 status = H5Pclose(chunking_properties);
337 dolfin_assert(status != HDF5_FAIL);
338 }
339
340 // Close dataset collectively
341 status = H5Dclose(dset_id);
342 dolfin_assert(status != HDF5_FAIL);
343
344 // Close hyperslab
345 status = H5Sclose(filespace1);
346 dolfin_assert(status != HDF5_FAIL);
347
348 // Close local dataset
349 status = H5Sclose(memspace);
350 dolfin_assert(status != HDF5_FAIL);
351
352 // Release file-access template
353 status = H5Pclose(plist_id);
354 dolfin_assert(status != HDF5_FAIL);
355 }
356 //---------------------------------------------------------------------------
357 template <typename T>
358 inline void
359 HDF5Interface::read_dataset(const hid_t file_handle,
360 const std::string dataset_path,
361 const std::pair<std::int64_t, std::int64_t> range,
362 std::vector<T>& data)
363 {
364 // Open the dataset
365 const hid_t dset_id = H5Dopen2(file_handle, dataset_path.c_str(),
366 H5P_DEFAULT);
367 dolfin_assert(dset_id != HDF5_FAIL);
368
369 // Open dataspace
370 const hid_t dataspace = H5Dget_space(dset_id);
371 dolfin_assert(dataspace != HDF5_FAIL);
372
373 // Get rank of data set
374 const int rank = H5Sget_simple_extent_ndims(dataspace);
375 dolfin_assert(rank >= 0);
376
377 if (rank > 2)
378 warning("HDF5Interface::read_dataset untested for rank > 2.");
379
380 // Allocate data for shape
381 std::vector<hsize_t> shape(rank);
382
383 // Get size in each dimension
384 const int ndims = H5Sget_simple_extent_dims(dataspace, shape.data(), NULL);
385 dolfin_assert(ndims == rank);
386
387 // Hyperslab selection
388 std::vector<hsize_t> offset(rank, 0);
389 std::vector<hsize_t> count = shape;
390 if (range.first != -1 and range.second != -1)
391 {
392 offset[0]= range.first;
393 count[0] = range.second - range.first;
394 }
395 else
396 offset[0]= 0;
397
398 // Select a block in the dataset beginning at offset[], with
399 // size=count[]
400 herr_t status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET,
401 offset.data(), NULL, count.data(),
402 NULL);
403 dolfin_assert(status != HDF5_FAIL);
404
405 // Create a memory dataspace
406 const hid_t memspace = H5Screate_simple(rank, count.data(), NULL);
407 dolfin_assert (memspace != HDF5_FAIL);
408
409 // Resize local data to read into
410 std::size_t data_size = 1;
411 for (std::size_t i = 0; i < count.size(); ++i)
412 data_size *= count[i];
413 data.resize(data_size);
414
415 // Read data on each process
416 const hid_t h5type = hdf5_type<T>();
417 status = H5Dread(dset_id, h5type, memspace, dataspace, H5P_DEFAULT,
418 data.data());
419 dolfin_assert(status != HDF5_FAIL);
420
421 // Close dataspace
422 status = H5Sclose(dataspace);
423 dolfin_assert(status != HDF5_FAIL);
424
425 // Close memspace
426 status = H5Sclose(memspace);
427 dolfin_assert(status != HDF5_FAIL);
428
429 // Close dataset
430 status = H5Dclose(dset_id);
431 dolfin_assert(status != HDF5_FAIL);
432 }
433 //---------------------------------------------------------------------------
434 template <typename T>
435 inline void HDF5Interface::get_attribute(hid_t hdf5_file_handle,
436 const std::string dataset_path,
437 const std::string attribute_name,
438 T& attribute_value)
439 {
440 herr_t status;
441
442 // Open dataset or group by name
443 const hid_t dset_id = H5Oopen(hdf5_file_handle, dataset_path.c_str(),
444 H5P_DEFAULT);
445 dolfin_assert(dset_id != HDF5_FAIL);
446
447 // Open attribute by name and get its type
448 const hid_t attr_id = H5Aopen(dset_id, attribute_name.c_str(), H5P_DEFAULT);
449 dolfin_assert(attr_id != HDF5_FAIL);
450 const hid_t attr_type = H5Aget_type(attr_id);
451 dolfin_assert(attr_type != HDF5_FAIL);
452
453 // Specific code for each type of data template
454 get_attribute_value(attr_type, attr_id, attribute_value);
455
456 // Close attribute type
457 status = H5Tclose(attr_type);
458 dolfin_assert(status != HDF5_FAIL);
459
460 // Close attribute
461 status = H5Aclose(attr_id);
462 dolfin_assert(status != HDF5_FAIL);
463
464 // Close dataset or group
465 status = H5Oclose(dset_id);
466 dolfin_assert(status != HDF5_FAIL);
467 }
468 //--------------------------------------------------------------------------
469 template <typename T>
470 inline void HDF5Interface::add_attribute(const hid_t hdf5_file_handle,
471 const std::string dataset_path,
472 const std::string attribute_name,
473 const T& attribute_value)
474 {
475
476 // Open named dataset or group
477 hid_t dset_id = H5Oopen(hdf5_file_handle, dataset_path.c_str(),
478 H5P_DEFAULT);
479 dolfin_assert(dset_id != HDF5_FAIL);
480
481 // Check if attribute already exists and delete if so
482 htri_t has_attr = H5Aexists(dset_id, attribute_name.c_str());
483 dolfin_assert(has_attr != HDF5_FAIL);
484 if (has_attr > 0)
485 {
486 herr_t status = H5Adelete(dset_id, attribute_name.c_str());
487 dolfin_assert(status != HDF5_FAIL);
488 }
489
490 // Add attribute of appropriate type
491 add_attribute_value(dset_id, attribute_name, attribute_value);
492
493 // Close dataset or group
494 herr_t status = H5Oclose(dset_id);
495 dolfin_assert(status != HDF5_FAIL);
496 }
497 //---------------------------------------------------------------------------
498 // Specialised member functions (must be inlined to avoid link errors)
499 //---------------------------------------------------------------------------
500
501 // Template for simple types (e.g. size_t, double, int etc.) and
502 // vectors of these
503 // Specialization below for string
504 template<typename T>
505 inline void
506 HDF5Interface::add_attribute_value(const hid_t dset_id,
507 const std::string attribute_name,
508 const T& attribute_value)
509 {
510 // Create a scalar dataspace
511 hid_t dataspace_id = H5Screate(H5S_SCALAR);
512 dolfin_assert(dataspace_id != HDF5_FAIL);
513
514 const hid_t h5type = hdf5_type<T>();
515
516 // Create attribute of type std::size_t
517 hid_t attribute_id = H5Acreate2(dset_id, attribute_name.c_str(),
518 h5type, dataspace_id,
519 H5P_DEFAULT, H5P_DEFAULT);
520 dolfin_assert(attribute_id != HDF5_FAIL);
521
522 // Write attribute to dataset
523 herr_t status = H5Awrite(attribute_id, h5type, &attribute_value);
524 dolfin_assert(status != HDF5_FAIL);
525
526 // Close dataspace
527 status = H5Sclose(dataspace_id);
528 dolfin_assert(status != HDF5_FAIL);
529
530 // Close attribute
531 status = H5Aclose(attribute_id);
532 dolfin_assert(status != HDF5_FAIL);
533 }
534 //---------------------------------------------------------------------------
535 template<typename T>
536 inline void HDF5Interface::add_attribute_value(const hid_t dset_id,
537 const std::string attribute_name,
538 const std::vector<T>& attribute_value)
539 {
540
541 const hid_t h5type = hdf5_type<T>();
542
543 // Create a vector dataspace
544 const hsize_t dimsf = attribute_value.size();
545 const hid_t dataspace_id = H5Screate_simple(1, &dimsf, NULL);
546 dolfin_assert(dataspace_id != HDF5_FAIL);
547
548 // Create an attribute of type size_t in the dataspace
549 const hid_t attribute_id = H5Acreate2(dset_id, attribute_name.c_str(),
550 h5type, dataspace_id,
551 H5P_DEFAULT, H5P_DEFAULT);
552 dolfin_assert(attribute_id != HDF5_FAIL);
553
554 // Write attribute to dataset
555 herr_t status = H5Awrite(attribute_id, h5type, attribute_value.data());
556 dolfin_assert(status != HDF5_FAIL);
557
558 // Close dataspace
559 status = H5Sclose(dataspace_id);
560 dolfin_assert(status != HDF5_FAIL);
561
562 // Close attribute
563 status = H5Aclose(attribute_id);
564 dolfin_assert(status != HDF5_FAIL);
565 }
566 //---------------------------------------------------------------------------
567 template<>
568 inline void HDF5Interface::add_attribute_value(const hid_t dset_id,
569 const std::string attribute_name,
570 const std::string& attribute_value)
571 {
572 // Create a scalar dataspace
573 const hid_t dataspace_id = H5Screate(H5S_SCALAR);
574 dolfin_assert(dataspace_id != HDF5_FAIL);
575
576 // Copy basic string type from HDF5 types and set string length
577 const hid_t datatype_id = H5Tcopy(H5T_C_S1);
578 herr_t status = H5Tset_size(datatype_id, attribute_value.size());
579 dolfin_assert(status != HDF5_FAIL);
580
581 // Create attribute in the dataspace with the given string
582 const hid_t attribute_id = H5Acreate2(dset_id, attribute_name.c_str(),
583 datatype_id, dataspace_id,
584 H5P_DEFAULT, H5P_DEFAULT);
585 dolfin_assert(attribute_id != HDF5_FAIL);
586
587 // Write attribute to dataset
588 status = H5Awrite(attribute_id, datatype_id, attribute_value.c_str());
589 dolfin_assert(status != HDF5_FAIL);
590
591 // Close dataspace
592 status = H5Sclose(dataspace_id);
593 dolfin_assert(status != HDF5_FAIL);
594
595 // Close string type
596 status = H5Tclose(datatype_id);
597 dolfin_assert(status != HDF5_FAIL);
598
599 // Close attribute
600 status = H5Aclose(attribute_id);
601 dolfin_assert(status != HDF5_FAIL);
602 }
603 //--------------------------------------------------------------------------
604 template<typename T>
605 inline void HDF5Interface::get_attribute_value(const hid_t attr_type,
606 const hid_t attr_id,
607 T& attribute_value)
608 {
609 const hid_t h5type = hdf5_type<T>();
610
611 // FIXME: more complete check of type
612 dolfin_assert(H5Tget_class(attr_type) == H5Tget_class(h5type));
613
614 // Read value
615 herr_t status = H5Aread(attr_id, h5type, &attribute_value);
616 dolfin_assert(status != HDF5_FAIL);
617 }
618 //---------------------------------------------------------------------------
619 template<typename T>
620 inline void
621 HDF5Interface::get_attribute_value(const hid_t attr_type,
622 const hid_t attr_id,
623 std::vector<T>& attribute_value)
624 {
625 const hid_t h5type = hdf5_type<T>();
626
627 // FIXME: more complete check of type
628 dolfin_assert(H5Tget_class(attr_type) == H5Tget_class(h5type));
629
630 // get dimensions of attribute array, check it is one-dimensional
631 const hid_t dataspace = H5Aget_space(attr_id);
632 dolfin_assert(dataspace != HDF5_FAIL);
633
634 hsize_t cur_size[10];
635 hsize_t max_size[10];
636 const int ndims = H5Sget_simple_extent_dims(dataspace, cur_size, max_size);
637 dolfin_assert(ndims == 1);
638
639 attribute_value.resize(cur_size[0]);
640
641 // Read value to vector
642 herr_t status = H5Aread(attr_id, h5type, attribute_value.data());
643 dolfin_assert(status != HDF5_FAIL);
644
645 // Close dataspace
646 status = H5Sclose(dataspace);
647 dolfin_assert(status != HDF5_FAIL);
648 }
649 //---------------------------------------------------------------------------
650 template<>
651 inline void HDF5Interface::get_attribute_value(const hid_t attr_type,
652 const hid_t attr_id,
653 std::string& attribute_value)
654 {
655 // Check this attribute is a string
656 dolfin_assert(H5Tget_class(attr_type) == H5T_STRING);
657
658 // Copy string type from HDF5 types and set length accordingly
659 const hid_t memtype = H5Tcopy(H5T_C_S1);
660 const int string_length = H5Tget_size(attr_type) + 1;
661 herr_t status = H5Tset_size(memtype, string_length);
662 dolfin_assert(status != HDF5_FAIL);
663
664 // FIXME: messy
665 // Copy string value into temporary vector std::vector::data can
666 // be copied into (std::string::data cannot)
667 std::vector<char> attribute_data(string_length);
668 status = H5Aread(attr_id, memtype, attribute_data.data());
669 dolfin_assert(status != HDF5_FAIL);
670
671 attribute_value.assign(attribute_data.data());
672
673 // Close memory type
674 status = H5Tclose(memtype);
675 dolfin_assert(status != HDF5_FAIL);
676 }
677 //---------------------------------------------------------------------------
678
679}
680
681#endif
682
683#endif
Definition: HDF5Interface.h:45
static bool has_dataset(const hid_t hdf5_file_handle, const std::string dataset_path)
Check for existence of dataset in HDF5 file.
Definition: HDF5Interface.cpp:300
static bool get_mpi_atomicity(const hid_t hdf5_file_handle)
Definition: HDF5Interface.cpp:460
static void flush_file(const hid_t hdf5_file_handle)
Definition: HDF5Interface.cpp:108
static void write_dataset(const hid_t file_handle, const std::string dataset_path, const std::vector< T > &data, const std::pair< std::int64_t, std::int64_t > range, const std::vector< std::int64_t > global_size, bool use_mpio, bool use_chunking)
static bool has_group(const hid_t hdf5_file_handle, const std::string group_name)
Check for existence of group in HDF5 file.
Definition: HDF5Interface.cpp:269
static void delete_attribute(const hid_t hdf5_file_handle, const std::string dataset_path, const std::string attribute_name)
Delete an attribute from a dataset or group.
Definition: HDF5Interface.cpp:192
static void add_group(const hid_t hdf5_file_handle, const std::string dataset_path)
Add group to HDF5 file.
Definition: HDF5Interface.cpp:314
static int dataset_rank(const hid_t hdf5_file_handle, const std::string dataset_path)
Get dataset rank.
Definition: HDF5Interface.cpp:347
static std::vector< std::int64_t > get_dataset_shape(const hid_t hdf5_file_handle, const std::string dataset_path)
Get dataset shape (size of each dimension)
Definition: HDF5Interface.cpp:373
static std::vector< std::string > dataset_list(const hid_t hdf5_file_handle, const std::string group_name)
Return list all datasets in named group of file.
Definition: HDF5Interface.cpp:417
static const std::string get_attribute_type(const hid_t hdf5_file_handle, const std::string dataset_path, const std::string attribute_name)
Get type of attribute.
Definition: HDF5Interface.cpp:130
static void set_mpi_atomicity(const hid_t hdf5_file_handle, const bool atomic)
Definition: HDF5Interface.cpp:449
static void add_attribute(const hid_t hdf5_file_handle, const std::string dataset_path, const std::string attribute_name, const T &attribute_value)
Add attribute to dataset or group.
Definition: HDF5Interface.h:470
static bool has_attribute(const hid_t hdf5_file_handle, const std::string dataset_path, const std::string attribute_name)
Check if an attribute exists on a dataset or group.
Definition: HDF5Interface.cpp:246
static void read_dataset(const hid_t file_handle, const std::string dataset_path, const std::pair< std::int64_t, std::int64_t > range, std::vector< T > &data)
Definition: HDF5Interface.h:359
static hid_t open_file(MPI_Comm mpi_comm, const std::string filename, const std::string mode, const bool use_mpi_io)
Open HDF5 and return file descriptor.
Definition: HDF5Interface.cpp:37
static void close_file(const hid_t hdf5_file_handle)
Close HDF5 file.
Definition: HDF5Interface.cpp:102
static void get_attribute(const hid_t hdf5_file_handle, const std::string dataset_path, const std::string attribute_name, T &attribute_value)
Get a named attribute of a dataset of known type.
Definition: HDF5Interface.h:435
static int num_datasets_in_group(const hid_t hdf5_file_handle, const std::string group_name)
Return number of data sets in a group.
Definition: HDF5Interface.cpp:404
Definition: adapt.h:30
void warning(std::string msg,...)
Print warning.
Definition: log.cpp:115
void dolfin_error(std::string location, std::string task, std::string reason,...)
Definition: log.cpp:129
void info(std::string msg,...)
Print message.
Definition: log.cpp:72