Skip to content
Snippets Groups Projects
Commit 5ecfec5c authored by Izzard, Robert Dr (Maths & Physics)'s avatar Izzard, Robert Dr (Maths & Physics)
Browse files

add MINT_filename function in separate file

parent ad7cf9bb
No related branches found
No related tags found
No related merge requests found
......@@ -60,27 +60,29 @@
* Second is the "action" which is one of the
* MINT_ACTIONS_LIST
*/
#define MINT_MS_DATA_ITEMS_LIST \
X(RADIUS, LOG10) \
X(LUMINOSITY, LOG10) \
X(AGE, NOTHING) \
X(CONVECTIVE_CORE_MASS, NOTHING) \
X(CONVECTIVE_CORE_RADIUS, NOTHING) \
X(CONVECTIVE_CORE_MASS_OVERSHOOT, NOTHING) \
X(CONVECTIVE_CORE_RADIUS_OVERSHOOT, NOTHING) \
X(CONVECTIVE_ENVELOPE_MASS, NOTHING) \
X(CONVECTIVE_ENVELOPE_RADIUS, NOTHING) \
X(K2, NOTHING) \
X(TIMESCALE_KELVIN_HELMHOLTZ, NOTHING) \
X(TIMESCALE_DYNAMICAL, NOTHING) \
X(TIMESCALE_NUCLEAR, NOTHING) \
#define MINT_MS_DATA_ITEMS_LIST \
X(RADIUS, LOG10) \
X(LUMINOSITY, LOG10) \
X(AGE, NOTHING) \
X(CONVECTIVE_CORE_MASS, NOTHING) \
X(CONVECTIVE_CORE_RADIUS, NOTHING) \
X(CONVECTIVE_CORE_MASS_OVERSHOOT, NOTHING) \
X(CONVECTIVE_CORE_RADIUS_OVERSHOOT, NOTHING) \
X(CONVECTIVE_ENVELOPE_MASS, NOTHING) \
X(CONVECTIVE_ENVELOPE_RADIUS, NOTHING) \
X(CONVECTIVE_ENVELOPE_MASS_SIMPLIFIED, NOTHING) \
X(CONVECTIVE_ENVELOPE_RADIUS_SIMPLIFIED, NOTHING) \
X(K2, NOTHING) \
X(TIDAL_E2, NOTHING) \
X(TIDAL_E_FOR_LAMBDA, NOTHING) \
X(TIMESCALE_KELVIN_HELMHOLTZ, NOTHING) \
X(TIMESCALE_DYNAMICAL, NOTHING) \
X(TIMESCALE_NUCLEAR, NOTHING) \
X(FIRST_DERIVATIVE_CENTRAL_HYDROGEN, LOG10NEGATIVE) \
X(SECOND_DERIVATIVE_CENTRAL_HYDROGEN, NOTHING) \
X(E2, NOTHING) \
X(E_ZAHN, NOTHING) \
X(CHEBYSHEV_TEMPERATURE, NOTHING) \
X(CHEBYSHEV_DENSITY, NOTHING) \
X(CHEBYSHEV_TOTAL_PRESSURE, NOTHING) \
X(CHEBYSHEV_GAS_PRESSURE, NOTHING) \
X(SECOND_DERIVATIVE_CENTRAL_HYDROGEN, NOTHING) \
X(CHEBYSHEV_TEMPERATURE, NOTHING) \
X(CHEBYSHEV_DENSITY, NOTHING) \
X(CHEBYSHEV_TOTAL_PRESSURE, NOTHING) \
X(CHEBYSHEV_GAS_PRESSURE, NOTHING) \
X(CHEBYSHEV_RADIUS, NOTHING)
#endif // MINT_DATA_COLUMNS_MS_LIST_DEF
#pragma once
#ifndef MINT_DATA_TABLES_DEF
#define MINT_DATA_TABLES_DEF
/*
* Each table has a macro MINT_TABLE_* identifier
* which corresponds to a unqiue integer. The table
* X macros should be defined with the following
* data items:
*
* IDENTIFIER : the table ID, which as MINT_TABLE_ prepended
* FILENAME : the filename, looked for in the MINT directory
* (NULL if not defined)
*
* MINT_TABLE_NUMBER should be one greater than the
* final identifier.
*/
#define MINT_TABLES_LIST \
X(MS,"grid_Z0.02_chebyshev_withE_allM.dat") \
X(HG,NULL) \
X(GB,NULL) \
X(CHeB,NULL) \
X(EAGB,NULL) \
X(TPAGB,NULL) \
X(HeMS,NULL) \
X(HeHG,NULL) \
X(HeGB,NULL) \
X(HeWD,NULL) \
X(COWD,NULL) \
X(ONeWD,NULL) \
X(MS_TAMS,NULL) \
X(MS_ZAMS_L_MCONV,NULL) \
X(NUMBER,NULL)
#endif // MINT_DATA_TABLES_DEF
#include "../binary_c.h"
No_empty_translation_unit_warning;
#ifdef MINT
#include "MINT.h"
#include "MINT_load_MS_grid.h"
char * MINT_filename(struct stardata_t * const stardata MAYBE_UNUSED,
const unsigned int table_id)
{
#undef X
#define X(ID,FILENAME) FILENAME,
static char * const filenames[] = { MINT_TABLES_LIST };
#undef X
return table_id < MINT_TABLE_NUMBER ? filenames[table_id] : NULL;
}
#endif//MINT
......@@ -179,6 +179,7 @@ void MINT_load_MS_grid(struct stardata_t * const stardata,
* of the header
*/
const unsigned int nperline = nparam + ndata;
Boolean * set = Malloc(sizeof(Boolean) * nperline);
if(ncols < nperline)
{
......@@ -205,6 +206,7 @@ void MINT_load_MS_grid(struct stardata_t * const stardata,
double * const table = Malloc(nl *
(size_t)nperline *
sizeof(double));
Dprint("table %p\n",(void*)table);
if(table == NULL)
{
Exit_binary_c(BINARY_C_MALLOC_FAILED,
......@@ -212,6 +214,7 @@ void MINT_load_MS_grid(struct stardata_t * const stardata,
}
RCHash_new(ZAMS_age_hash);
Dprint("ZAMS_age_hash %p\n",(void*)ZAMS_age_hash);
/*
* Read in the table table
......@@ -220,13 +223,14 @@ void MINT_load_MS_grid(struct stardata_t * const stardata,
while(data_line_number < nl)
{
char ** strings;
double * doubles;
long int nstrings;
file_splitline(stream->fp,
0,
" ",
&strings,
&nstrings);
printf("strings = %p nstrings = %ld\n",(void*)strings,nstrings);
if(nstrings <= -1)
{
Exit_binary_c(BINARY_C_MINT_GRID_BAD_DATA_ON_LOAD,
......@@ -234,145 +238,150 @@ void MINT_load_MS_grid(struct stardata_t * const stardata,
MS_file,
data_line_number);
}
else
else if(strings[0][0] != MINT_HEADER_CHAR)
{
if(strings[0][0] != MINT_HEADER_CHAR)
/*
* Grid data line
*/
if(vb)printf("line %zu/%zu got nstrings = %ld : %s, %s, %s, %s...\n",
data_line_number+1,
nl,
nstrings,
nstrings >= 1 ? strings[0] : "",
nstrings >= 2 ? strings[1] : "",
nstrings >= 3 ? strings[2] : "",
nstrings >= 4 ? strings[3] : ""
);
if(nstrings >= 0)
{
double * doubles;
string_array_to_double_array(strings,
&doubles,
nstrings);
/*
Dprint("doubles : %g,%g,%g...\n",
doubles[0],
doubles[1],
doubles[2]);
*/
/*
* Grid data line
* Pointer to the start of this data line
*/
if(vb)printf("line %zu/%zu got nstrings = %ld : %s, %s, %s, %s...\n",
data_line_number+1,
nl,
nstrings,
nstrings >= 1 ? strings[0] : "",
nstrings >= 2 ? strings[1] : "",
nstrings >= 3 ? strings[2] : "",
nstrings >= 4 ? strings[3] : ""
);
if(nstrings >= 0)
double * const line_start = table + data_line_number * nperline;
/*
* Copy in parameter values
*/
for(size_t i=0; i<nperline; i++)
{
string_array_to_double_array(strings,
&doubles,
nstrings);
/*
Dprint("doubles : %g,%g,%g...\n",
doubles[0],
doubles[1],
doubles[2]);
*/
/*
* Pointer to the start of this data line
*/
double * const line_start = table + data_line_number * nperline;
/*
* Copy in parameter values
*/
Boolean * set = Malloc(sizeof(Boolean) * nperline);
for(size_t i=0; i<nperline; i++)
{
set[i] = FALSE;
}
set[i] = FALSE;
}
int offset = 0;
for(size_t i=0; i<nparam_array_size; i++)
int offset = 0;
for(size_t i=0; i<nparam_array_size; i++)
{
const int range[2] = MINT_Column_range_with_string(parameter_names[i]);
if(vb)printf("parameter %s : range %d to %d\n",
parameter_names[i],
range[0],
range[1]);
for(int j=range[0]; j<=range[1]; j++)
{
const int range[2] = MINT_Column_range_with_string(parameter_names[i]);
if(vb)printf("parameter %s : range %d to %d\n",
parameter_names[i],
range[0],
range[1]);
for(int j=range[0]; j<=range[1]; j++)
{
const int c = offset + j - range[0];
const double x = MINT_data_filter(doubles[j],
MINT_MS_parameter_actions[i]);
if(vb)printf("Read param at file column %d, interpolation table column %d (action %s on %g) : %g\n",
j,
c,
MINT_action_strings[MINT_MS_parameter_actions[i]],
doubles[j],
x);
set[c] = TRUE;
/*
* Set the data in the big interpolation table,
* using the MINT_data_filter to apply functions
* to the data, if required.
*/
*(line_start + i + j - range[0]) = x;
}
offset += range[1] - range[0] + 1;
const int c = offset + j - range[0];
const double x = MINT_data_filter(doubles[j],
MINT_MS_parameter_actions[i]);
if(vb)printf("Read param at file column %d, interpolation table column %d (action %s on %g) : %g\n",
j,
c,
MINT_action_strings[MINT_MS_parameter_actions[i]],
doubles[j],
x);
set[c] = TRUE;
/*
* Set the data in the big interpolation table,
* using the MINT_data_filter to apply functions
* to the data, if required.
*/
*(line_start + i + j - range[0]) = x;
}
offset += range[1] - range[0] + 1;
}
/*
* Copy in data values
*/
for(size_t i=0; i<ndata_array_size; i++)
/*
* Copy in data values
*/
for(size_t i=0; i<ndata_array_size; i++)
{
const int range[2] = MINT_Column_range_with_string(data_names[i]);
if(vb)printf("data item %s : range %d to %d\n",
data_names[i],
range[0],
range[1]);
fflush(NULL);
for(int j=range[0]; j<=range[1]; j++)
{
const int range[2] = MINT_Column_range_with_string(data_names[i]);
if(vb)printf("data item %s : range %d to %d\n",
data_names[i],
range[0],
range[1]);
fflush(NULL);
for(int j=range[0]; j<=range[1]; j++)
{
const int c = offset + j - range[0];
const double x = MINT_data_filter(doubles[j],
MINT_MS_data_actions[i]);
if(vb)printf("Read data from %s line %zu/%zu (% 5.1f%%), column %d, interpolation table column %d (action %s on %g) : %g\n",
MS_file,
data_line_number,
nl,
(100.0*data_line_number)/(1.0*nl),
j,
c,
MINT_action_strings[MINT_MS_data_actions[i]],
doubles[j],
x);
set[c] = TRUE;
/*
* Set the data in the big interpolation table,
* using the MINT_data_filter to apply functions
* to the data, if required.
*/
*(line_start + c) = x;
}
offset += range[1] - range[0] + 1;
const int c = offset + j - range[0];
const double x = MINT_data_filter(doubles[j],
MINT_MS_data_actions[i]);
if(vb)printf("Read data from %s line %zu/%zu (% 5.1f%%), column %d, interpolation table column %d (action %s on %g) : %g\n",
MS_file,
data_line_number,
nl,
(100.0*data_line_number)/(1.0*nl),
j,
c,
MINT_action_strings[MINT_MS_data_actions[i]],
doubles[j],
x);
set[c] = TRUE;
/*
* Set the data in the big interpolation table,
* using the MINT_data_filter to apply functions
* to the data, if required.
*/
*(line_start + c) = x;
}
offset += range[1] - range[0] + 1;
}
/*
* Check all data has been set
*/
for(size_t i=0; i<nperline; i++)
/*
* Check all data has been set
*/
for(size_t i=0; i<nperline; i++)
{
if(set[i] == FALSE)
{
if(set[i] == FALSE)
{
Exit_binary_c(BINARY_C_MINT_GRID_BAD_DATA_ON_LOAD,
"Data load fail : item %zu on line %zu is not set\n",
i,
data_line_number);
}
Exit_binary_c(BINARY_C_MINT_GRID_BAD_DATA_ON_LOAD,
"Data load fail : item %zu on line %zu is not set\n",
i,
data_line_number);
}
Safe_free(set);
/* free memory */
Safe_free(doubles);
}
data_line_number++;
}
/* strings are no longer needed: free them */
free_string_array(strings,nstrings);
/* free memory */
Dprint("free doubles %p\n",(void*)doubles);
Safe_free(doubles);
}
data_line_number++;
}
/* strings are no longer needed: free them */
Dprint("free strings %p\n",(void*)strings);
free_string_array(strings,
nstrings);
Dprint("done\n");
}
Dprint("free set %p\n",(void*)set);
Safe_free(set);
#ifdef __DEPRECATED
if(0)
{
/*
......@@ -398,8 +407,6 @@ void MINT_load_MS_grid(struct stardata_t * const stardata,
*agep = log10(exp10(*agep) - exp10(log_ZAMS_age));
}
}
if(0)
......@@ -440,9 +447,11 @@ void MINT_load_MS_grid(struct stardata_t * const stardata,
table[MINT_MS_FIRST_DERIVATIVE_CENTRAL_HYDROGEN + offset + nparam] =
log10(fabs(dXdt));
printf("time : dXdt was %g -> new dX / dt = %g / %g = %g\n",was,dX,dt,dXdt); }
printf("time : dXdt was %g -> new dX / dt = %g / %g = %g\n",was,dX,dt,dXdt);
}
}
}
#endif// __DEPRECATED
Dprint("data table has been set at %p is %g,%g,%g : nparam = %u, ndata = %u, nlines = %zu\n",
(void*)table,
......@@ -465,6 +474,7 @@ void MINT_load_MS_grid(struct stardata_t * const stardata,
nl
);
Dprint("free hash at %p\n",(void*)ZAMS_age_hash);
RCHash_free(ZAMS_age_hash);
}
......@@ -703,12 +713,22 @@ static char * MS_filename(struct stardata_t * const stardata,
else
{
/*
* Use hardcoded filename
* Construct filename
*/
char * const file = MINT_filename(stardata,MINT_TABLE_MS);
if(file == NULL)
{
Exit_binary_c(BINARY_C_MINT_FILENAME_ERROR,
"No MINT filename found for table %d\n",
MINT_TABLE_MS);
}
const int i = asprintf(&MS_file,
//"%s/grid_Z0.02_chebyshev_noE_allM.dat",
"%s/grid_Z0.02_chebyshev_withE_allM.dat",
stardata->preferences->MINT_dir);
"%s/%s",
stardata->preferences->MINT_dir,
MINT_filename(stardata,MINT_TABLE_MS));
if(i < 0)
{
MS_file = NULL;
......
......@@ -9,35 +9,13 @@
*/
#define MINT_HEADER_CHAR '#'
/*
* Each table has a macro MINT_TABLE_* identifier
* which corresponds to a unqiue integer.
*
* MINT_TABLE_NUMBER should be one greater than the
* final identifier.
*/
#define MINT_TABLES_LIST \
X(MS) \
X(HG) \
X(GB) \
X(CHeB) \
X(EAGB) \
X(TPAGB) \
X(HeMS) \
X(HeHG) \
X(HeGB) \
X(HeWD) \
X(COWD) \
X(ONeWD) \
X(MS_TAMS) \
X(MS_ZAMS_L_MCONV) \
X(NUMBER)
#include "MINT_data_tables.def"
#undef X
#define X(ID) MINT_TABLE_##ID,
#define X(ID,FILENAME) MINT_TABLE_##ID,
enum { MINT_TABLES_LIST };
#undef X
/*
* Actions to be taken upon loading of
* a data column. These are prefixed by
......
......@@ -23,6 +23,9 @@ void MINT_load_MS_grid(struct stardata_t * const stardata,
const Boolean vb);
void MINT_constructed_tables(struct stardata_t * stardata,
const Boolean vb);
char * MINT_filename(struct stardata_t * const stardata,
const unsigned int table_id);
/*
* Stellar structure
*/
......
......@@ -208,7 +208,7 @@
* Enable this to get real segfaults (for gdb etc.) or
* disable to catch segfaults and report a binary_c-style error
*/
//#define SEGFAULTS
#define SEGFAULTS
/* use AMD math library? */
#ifdef ACML
......
......@@ -36,7 +36,7 @@
*
* See below for further options.
*/
#define DEBUG 0
#define DEBUG 1
/*
* To remove debugging possibility from the code, globally, hence
......
......@@ -98,7 +98,8 @@
X(BINARY_C_FEATURE_NOT_YET_IMPLEMENTED , "Feature not yet implemented" ) \
X(BINARY_C_ASSERT_FAILED , "Assert failed" ) \
X(BINARY_C_ARGUMENT_OVERFLOW , "Argument overflow" ) \
X(BINARY_C_NUCSYN_SOLVER_FAILED,"nucsyn solver failed")
X(BINARY_C_NUCSYN_SOLVER_FAILED,"nucsyn solver failed") \
X(BINARY_C_MINT_FILENAME_ERROR,"MINT filename error")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment