From 5da4b6ce2d2f2709544c9ece2ff521dbf718d661 Mon Sep 17 00:00:00 2001
From: Jacob Kegerreis <jacob.kegerreis@durham.ac.uk>
Date: Fri, 2 Nov 2018 10:44:19 +0000
Subject: [PATCH] Tidy EoS file loading checks

---
 src/equation_of_state/planetary/hm80.h   | 12 ++++------
 src/equation_of_state/planetary/sesame.h | 28 +++++++-----------------
 2 files changed, 12 insertions(+), 28 deletions(-)

diff --git a/src/equation_of_state/planetary/hm80.h b/src/equation_of_state/planetary/hm80.h
index 1af6ff0da7..38e2c9e402 100644
--- a/src/equation_of_state/planetary/hm80.h
+++ b/src/equation_of_state/planetary/hm80.h
@@ -86,21 +86,19 @@ INLINE static void load_table_HM80(struct HM80_params *mat, char *table_file) {
 
   // Load table contents from file
   FILE *f = fopen(table_file, "r");
-  if (f == NULL) error("Impossible to open HM80 EoS file '%s'", table_file);
+  if (f == NULL) error("Failed to open the HM80 EoS file '%s'", table_file);
 
   // Ignore header lines
   char buffer[100];
   for (int i = 0; i < 4; i++) {
     if (fgets(buffer, 100, f) == NULL)
-      error("Something incorrect happening with the file header.");
+      error("Failed to read the HM80 EoS file header %s", table_file);
   }
 
   // Table properties
   int c = fscanf(f, "%f %f %d %f %f %d", &mat->log_rho_min, &mat->log_rho_max,
                  &mat->num_rho, &mat->log_u_min, &mat->log_u_max, &mat->num_u);
-  if (c != 6) {
-    error("Failed to read EOS table %s", table_file);
-  }
+  if (c != 6) error("Failed to read the HM80 EoS table %s", table_file);
   mat->log_rho_step =
       (mat->log_rho_max - mat->log_rho_min) / (mat->num_rho - 1);
   mat->log_u_step = (mat->log_u_max - mat->log_u_min) / (mat->num_u - 1);
@@ -115,9 +113,7 @@ INLINE static void load_table_HM80(struct HM80_params *mat, char *table_file) {
   for (int i_rho = 0; i_rho < mat->num_rho; i_rho++) {
     for (int i_u = 0; i_u < mat->num_u; i_u++) {
       c = fscanf(f, "%f", &mat->table_log_P_rho_u[i_rho * mat->num_u + i_u]);
-      if (c != 1) {
-        error("Failed to read EOS table");
-      }
+      if (c != 1) error("Failed to read the HM80 EoS table %s", table_file);
     }
   }
   fclose(f);
diff --git a/src/equation_of_state/planetary/sesame.h b/src/equation_of_state/planetary/sesame.h
index 886a7d7263..11c1696460 100644
--- a/src/equation_of_state/planetary/sesame.h
+++ b/src/equation_of_state/planetary/sesame.h
@@ -82,21 +82,19 @@ INLINE static void load_table_SESAME(struct SESAME_params *mat,
 
   // Load table contents from file
   FILE *f = fopen(table_file, "r");
-  if (f == NULL) error("Impossible to open SESAME EoS file '%s'", table_file);
+  if (f == NULL) error("Failed to open the SESAME EoS file '%s'", table_file);
 
   // Ignore header lines
   char buffer[100];
   for (int i = 0; i < 5; i++) {
     if (fgets(buffer, 100, f) == NULL)
-      error("Something incorrect happening with the file header.");
+      error("Failed to read the SESAME EoS file header %s", table_file);
   }
   float ignore;
 
   // Table properties
   int c = fscanf(f, "%d %d", &mat->num_rho, &mat->num_T);
-  if (c != 2) {
-    error("Failed to read EOS table %s", table_file);
-  }
+  if (c != 2) error("Failed to read the SESAME EoS table %s", table_file);
 
   // Ignore the first elements of rho = 0, T = 0
   mat->num_rho--;
@@ -118,23 +116,17 @@ INLINE static void load_table_SESAME(struct SESAME_params *mat,
     // Ignore the first elements of rho = 0, T = 0
     if (i_rho == -1) {
       c = fscanf(f, "%f", &ignore);
-      if (c != 1) {
-        error("Failed to read EOS table %s", table_file);
-      }
+      if (c != 1) error("Failed to read the SESAME EoS table %s", table_file);
     } else {
       c = fscanf(f, "%f", &mat->table_log_rho[i_rho]);
-      if (c != 1) {
-        error("Failed to read EOS table %s", table_file);
-      }
+      if (c != 1) error("Failed to read the SESAME EoS table %s", table_file);
     }
   }
 
   // Temperatures (ignored)
   for (int i_T = -1; i_T < mat->num_T; i_T++) {
     c = fscanf(f, "%f", &ignore);
-    if (c != 1) {
-      error("Failed to read EOS table %s", table_file);
-    }
+    if (c != 1) error("Failed to read the SESAME EoS table %s", table_file);
   }
 
   // Sp. int. energies (not log yet), pressures, sound speeds, and entropies
@@ -143,18 +135,14 @@ INLINE static void load_table_SESAME(struct SESAME_params *mat,
       // Ignore the first elements of rho = 0, T = 0
       if ((i_T == -1) || (i_rho == -1)) {
         c = fscanf(f, "%f %f %f %f", &ignore, &ignore, &ignore, &ignore);
-        if (c != 4) {
-          error("Failed to read EOS table %s", table_file);
-        }
+        if (c != 4) error("Failed to read the SESAME EoS table %s", table_file);
       } else {
         c = fscanf(f, "%f %f %f %f",
                    &mat->table_log_u_rho_T[i_rho * mat->num_T + i_T],
                    &mat->table_P_rho_T[i_rho * mat->num_T + i_T],
                    &mat->table_c_rho_T[i_rho * mat->num_T + i_T],
                    &mat->table_s_rho_T[i_rho * mat->num_T + i_T]);
-        if (c != 4) {
-          error("Failed to read EOS table %s", table_file);
-        }
+        if (c != 4) error("Failed to read the SESAME EoS table %s", table_file);
       }
     }
   }
-- 
GitLab