Commit c931e08e authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Merge branch 'fix-hdf5-errors' into 'master'

Use H5Lexists to check whether /Units exists in IC files before attempting to read them

Updated to use H5Lexists to check whether user has input units into 
their Initial Conditions files. This avoids error rasises from H5G* when
opening files without units and reverting back to the ones specified in
the parameterfile. We now also let users know when their units are being
read from their ICs explicitly.

See merge request !427
parents c41e0a84 5e421b1d
......@@ -325,7 +325,8 @@ int main(int argc, char *argv[]) {
/* Let's pin the main thread, now we know if affinity will be used. */
#if defined(HAVE_SETAFFINITY) && defined(HAVE_LIBNUMA) && defined(_GNU_SOURCE)
if (with_aff && ((ENGINE_POLICY)&engine_policy_setaffinity) == engine_policy_setaffinity)
if (with_aff &&
((ENGINE_POLICY)&engine_policy_setaffinity) == engine_policy_setaffinity)
engine_pin();
#endif
......
......@@ -300,9 +300,10 @@ void io_write_attribute_s(hid_t grp, const char* name, const char* str) {
*/
void io_read_unit_system(hid_t h_file, struct unit_system* us) {
hid_t h_grp = H5Gopen(h_file, "/Units", H5P_DEFAULT);
/* First check if it exists as this is *not* required. */
const htri_t exists = H5Lexists(h_file, "/Units", H5P_DEFAULT);
if (h_grp < 0) {
if (exists == 0) {
message("'Units' group not found in ICs. Assuming CGS unit system.");
/* Default to CGS */
......@@ -313,8 +314,14 @@ void io_read_unit_system(hid_t h_file, struct unit_system* us) {
us->UnitTemperature_in_cgs = 1.;
return;
} else if (exists < 0) {
error("Serious problem with 'Units' group in ICs. H5Lexists gives %d",
exists);
}
message("Reading IC units from ICs.");
hid_t h_grp = H5Gopen(h_file, "/Units", H5P_DEFAULT);
/* Ok, Read the damn thing */
io_read_attribute(h_grp, "Unit length in cgs (U_L)", DOUBLE,
&us->UnitLength_in_cgs);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment