From 7a4e32f7d51974e03c7c40fd9c6ca794f3e5f809 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 23 Jun 2021 11:48:45 +0700 Subject: [PATCH] Add filetype and other metadata to properties.h5 --- include/openmc/constants.h | 1 + src/summary.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/openmc/constants.h b/include/openmc/constants.h index aac3a52a83..2083f33b42 100644 --- a/include/openmc/constants.h +++ b/include/openmc/constants.h @@ -31,6 +31,7 @@ constexpr array VERSION_SUMMARY {6, 0}; constexpr array VERSION_VOLUME {1, 0}; constexpr array VERSION_VOXEL {2, 0}; constexpr array VERSION_MGXS_LIBRARY {1, 0}; +constexpr array VERSION_PROPERTIES {1, 0}; // ============================================================================ // ADJUSTABLE PARAMETERS diff --git a/src/summary.cpp b/src/summary.cpp index df69448847..29d37009b1 100644 --- a/src/summary.cpp +++ b/src/summary.cpp @@ -148,6 +148,17 @@ extern "C" int openmc_properties_export(const char* filename) // Create a new file using default properties. hid_t file = file_open(name, 'w'); + // Write metadata + write_attribute(file, "filetype", "properties"); + write_attribute(file, "version", VERSION_STATEPOINT); + write_attribute(file, "openmc_version", VERSION); +#ifdef GIT_SHA1 + write_attribute(file, "git_sha1", GIT_SHA1); +#endif + write_attribute(file, "date_and_time", time_stamp()); + write_attribute(file, "path", settings::path_input); + + // Write cell properties auto geom_group = create_group(file, "geometry"); write_attribute(geom_group, "n_cells", model::cells.size()); @@ -184,6 +195,14 @@ extern "C" int openmc_properties_import(const char* filename) } hid_t file = file_open(filename, 'r'); + // Ensure the filetype is correct + std::string filetype; + read_attribute(file, "filetype", filetype); + if (filetype != "properties") { + set_errmsg(fmt::format("File '{}' is not a properties file.", filename)); + return OPENMC_E_INVALID_ARGUMENT; + } + // Read cell properties auto geom_group = open_group(file, "geometry"); auto cells_group = open_group(geom_group, "cells");