Skip to content
Snippets Groups Projects
Commit 5da4b6ce authored by Jacob Kegerreis's avatar Jacob Kegerreis Committed by Matthieu Schaller
Browse files

Tidy EoS file loading checks

parent f4e33282
No related branches found
No related tags found
No related merge requests found
...@@ -86,21 +86,19 @@ INLINE static void load_table_HM80(struct HM80_params *mat, char *table_file) { ...@@ -86,21 +86,19 @@ INLINE static void load_table_HM80(struct HM80_params *mat, char *table_file) {
// Load table contents from file // Load table contents from file
FILE *f = fopen(table_file, "r"); 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 // Ignore header lines
char buffer[100]; char buffer[100];
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (fgets(buffer, 100, f) == NULL) 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 // Table properties
int c = fscanf(f, "%f %f %d %f %f %d", &mat->log_rho_min, &mat->log_rho_max, 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); &mat->num_rho, &mat->log_u_min, &mat->log_u_max, &mat->num_u);
if (c != 6) { if (c != 6) error("Failed to read the HM80 EoS table %s", table_file);
error("Failed to read EOS table %s", table_file);
}
mat->log_rho_step = mat->log_rho_step =
(mat->log_rho_max - mat->log_rho_min) / (mat->num_rho - 1); (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); 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) { ...@@ -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_rho = 0; i_rho < mat->num_rho; i_rho++) {
for (int i_u = 0; i_u < mat->num_u; i_u++) { 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]); c = fscanf(f, "%f", &mat->table_log_P_rho_u[i_rho * mat->num_u + i_u]);
if (c != 1) { if (c != 1) error("Failed to read the HM80 EoS table %s", table_file);
error("Failed to read EOS table");
}
} }
} }
fclose(f); fclose(f);
......
...@@ -82,21 +82,19 @@ INLINE static void load_table_SESAME(struct SESAME_params *mat, ...@@ -82,21 +82,19 @@ INLINE static void load_table_SESAME(struct SESAME_params *mat,
// Load table contents from file // Load table contents from file
FILE *f = fopen(table_file, "r"); 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 // Ignore header lines
char buffer[100]; char buffer[100];
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
if (fgets(buffer, 100, f) == NULL) 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; float ignore;
// Table properties // Table properties
int c = fscanf(f, "%d %d", &mat->num_rho, &mat->num_T); int c = fscanf(f, "%d %d", &mat->num_rho, &mat->num_T);
if (c != 2) { if (c != 2) error("Failed to read the SESAME EoS table %s", table_file);
error("Failed to read EOS table %s", table_file);
}
// Ignore the first elements of rho = 0, T = 0 // Ignore the first elements of rho = 0, T = 0
mat->num_rho--; mat->num_rho--;
...@@ -118,23 +116,17 @@ INLINE static void load_table_SESAME(struct SESAME_params *mat, ...@@ -118,23 +116,17 @@ INLINE static void load_table_SESAME(struct SESAME_params *mat,
// Ignore the first elements of rho = 0, T = 0 // Ignore the first elements of rho = 0, T = 0
if (i_rho == -1) { if (i_rho == -1) {
c = fscanf(f, "%f", &ignore); c = fscanf(f, "%f", &ignore);
if (c != 1) { if (c != 1) error("Failed to read the SESAME EoS table %s", table_file);
error("Failed to read EOS table %s", table_file);
}
} else { } else {
c = fscanf(f, "%f", &mat->table_log_rho[i_rho]); c = fscanf(f, "%f", &mat->table_log_rho[i_rho]);
if (c != 1) { if (c != 1) error("Failed to read the SESAME EoS table %s", table_file);
error("Failed to read EOS table %s", table_file);
}
} }
} }
// Temperatures (ignored) // Temperatures (ignored)
for (int i_T = -1; i_T < mat->num_T; i_T++) { for (int i_T = -1; i_T < mat->num_T; i_T++) {
c = fscanf(f, "%f", &ignore); c = fscanf(f, "%f", &ignore);
if (c != 1) { if (c != 1) error("Failed to read the SESAME EoS table %s", table_file);
error("Failed to read EOS table %s", table_file);
}
} }
// Sp. int. energies (not log yet), pressures, sound speeds, and entropies // 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, ...@@ -143,18 +135,14 @@ INLINE static void load_table_SESAME(struct SESAME_params *mat,
// Ignore the first elements of rho = 0, T = 0 // Ignore the first elements of rho = 0, T = 0
if ((i_T == -1) || (i_rho == -1)) { if ((i_T == -1) || (i_rho == -1)) {
c = fscanf(f, "%f %f %f %f", &ignore, &ignore, &ignore, &ignore); c = fscanf(f, "%f %f %f %f", &ignore, &ignore, &ignore, &ignore);
if (c != 4) { if (c != 4) error("Failed to read the SESAME EoS table %s", table_file);
error("Failed to read EOS table %s", table_file);
}
} else { } else {
c = fscanf(f, "%f %f %f %f", c = fscanf(f, "%f %f %f %f",
&mat->table_log_u_rho_T[i_rho * mat->num_T + i_T], &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_P_rho_T[i_rho * mat->num_T + i_T],
&mat->table_c_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]); &mat->table_s_rho_T[i_rho * mat->num_T + i_T]);
if (c != 4) { if (c != 4) error("Failed to read the SESAME EoS table %s", table_file);
error("Failed to read EOS table %s", table_file);
}
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment