From fa4f6491a3613df06bacec88020e106a2ff4d44a Mon Sep 17 00:00:00 2001 From: Josh Borrow Date: Thu, 21 Sep 2017 11:19:21 +0100 Subject: [PATCH 1/4] 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. --- src/common_io.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/common_io.c b/src/common_io.c index 168fcf2c6..f96de8be1 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -299,10 +299,12 @@ void io_write_attribute_s(hid_t grp, const char* name, const char* str) { * If the 'Units' group does not exist in the ICs, cgs units will be assumed */ void io_read_unit_system(hid_t h_file, struct unit_system* us) { + // First check if it exists as this is *not* required. + // This check comes from the H5G documentation. + // https://support.hdfgroup.org/ftp/HDF5/examples/misc-examples/h5grpexist.c + int exists = H5Lexists(h_file, "/Units", H5P_DEFAULT); - hid_t h_grp = H5Gopen(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,7 +315,13 @@ 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 your ICs. H5Lexists gives %d", + exists); } + + message("Reading units from your 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, -- GitLab From 0e8d87efb4066350cbbc9e6cfc744eaa4d8995f2 Mon Sep 17 00:00:00 2001 From: Josh Borrow Date: Thu, 21 Sep 2017 12:37:19 +0100 Subject: [PATCH 2/4] Removed some incorrect comments --- src/common_io.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/common_io.c b/src/common_io.c index f96de8be1..22c8ebb6d 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -300,8 +300,6 @@ 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) { // First check if it exists as this is *not* required. - // This check comes from the H5G documentation. - // https://support.hdfgroup.org/ftp/HDF5/examples/misc-examples/h5grpexist.c int exists = H5Lexists(h_file, "/Units", H5P_DEFAULT); if (exists == 0) { -- GitLab From 1b4a75fdf792b0dbb68bece4f556e14d212a4acb Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Thu, 21 Sep 2017 14:31:44 +0200 Subject: [PATCH 3/4] Code formatting, comments style and correct type for the returned value of H5Lexists(). --- examples/main.c | 3 ++- src/common_io.c | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/examples/main.c b/examples/main.c index 6a7641dad..56f463940 100644 --- a/examples/main.c +++ b/examples/main.c @@ -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 diff --git a/src/common_io.c b/src/common_io.c index 22c8ebb6d..3bf0b91cb 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -299,8 +299,9 @@ void io_write_attribute_s(hid_t grp, const char* name, const char* str) { * If the 'Units' group does not exist in the ICs, cgs units will be assumed */ void io_read_unit_system(hid_t h_file, struct unit_system* us) { - // First check if it exists as this is *not* required. - int exists = H5Lexists(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 (exists == 0) { message("'Units' group not found in ICs. Assuming CGS unit system."); @@ -314,11 +315,11 @@ void io_read_unit_system(hid_t h_file, struct unit_system* us) { return; } else if (exists < 0) { - error("Serious problem with 'Units' group in your ICs. H5Lexists gives %d", + error("Serious problem with 'Units' group your ICs. H5Lexists gives %d", exists); } - - message("Reading units from your ICs."); + + message("Reading IC units from ICs."); hid_t h_grp = H5Gopen(h_file, "/Units", H5P_DEFAULT); /* Ok, Read the damn thing */ -- GitLab From 5e421b1dca37459269e3b78ed13fbef85b57a367 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Thu, 21 Sep 2017 16:13:24 +0200 Subject: [PATCH 4/4] Restore @jborrow's correct English grammar in comments. --- src/common_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common_io.c b/src/common_io.c index 3bf0b91cb..11ec6ef1c 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -315,7 +315,7 @@ void io_read_unit_system(hid_t h_file, struct unit_system* us) { return; } else if (exists < 0) { - error("Serious problem with 'Units' group your ICs. H5Lexists gives %d", + error("Serious problem with 'Units' group in ICs. H5Lexists gives %d", exists); } -- GitLab