15#include "../include/var_struc.h"
28#define ACCESS(a,m) _access((a),(m))
31#define ACCESS(a,m) access((a),(m))
40 const int dim = (int)
config[0];
41 printf(
" dimension\t= %d\n", dim);
47 printf(
" total time\t= %g\n",
config[1]);
49 else if(!isfinite(
config[5]))
51 fprintf(stderr,
"The total time or the maximum number of time steps must be setted properly!\n");
60 printf(
" delta_t\t= %g\n",
config[16]);
63 printf(
" time step\t= %d\n", (
int)
config[5]);
68 if(eps < 0.0 || eps > 0.01)
70 fprintf(stderr,
"eps(%f) should in (0, 0.01)!\n", eps);
73 printf(
" eps\t\t= %g\n", eps);
77 else if(
config[6] < 1.0 + eps)
79 fprintf(stderr,
"The constant of the perfect gas(%f) should be larger than 1.0!\n",
config[6]);
82 printf(
" gamma\t\t= %g\n",
config[6]);
94 else if(
config[7] > 1.0 - eps)
96 fprintf(stderr,
"The CFL number(%f) should be smaller than 1.0.\n",
config[7]);
99 printf(
" CFL number\t= %g\n",
config[7]);
105 fprintf(stderr,
"The parameter in minmod limiter(%f) should in [0, 2)!\n",
config[41]);
111 else if(
config[110] < eps)
113 fprintf(stderr,
"The specific heat at constant volume(%f) should be larger than 0.0!\n",
config[110]);
152 while (fgets(one_line,
sizeof(one_line), fp) != NULL)
155 i =strtol(one_line, &endptr, 10);
156 for ( ; isspace(*endptr); endptr++) ;
162 tmp = strtod(endptr, NULL);
165 fprintf(stderr,
"Value range error of %d-th configuration in line %d of configuration file!\n", i, line_num);
169 printf(
"%3d-th configuration: %g\n", i,
config[i] = tmp);
171 printf(
"%3d-th configuration is repeatedly assigned with %g and %g(abandon)!\n", i,
config[i], tmp);
173 else if (i != 0 || (*endptr !=
'#' && *endptr !=
'\0'))
174 fprintf(stderr,
"Warning: unknown row occurrs in line %d of configuration file!\n", line_num);
179 fprintf(stderr,
"Read error occurrs in configuration file!\n");
194 char add[FILENAME_MAX+40];
196 strcat(add,
"config.txt");
199 if((fp_data = fopen(add,
"r")) == NULL)
202 strcat(add,
"config.dat");
204 if((fp_data = fopen(add,
"r")) == NULL)
206 printf(
"Cannot open configuration data file!\n");
218 printf(
"Configurated:\n");
224void config_write(
const char * add_out,
const double * cpu_time,
const char * name)
226 char file_data[FILENAME_MAX+40];
227 const int dim = (int)
config[0];
231 strcpy(file_data, add_out);
232 strcat(file_data,
"/log");
233 strcat(file_data,
".dat");
234 if((fp_write = fopen(file_data,
"w")) == NULL)
236 printf(
"Cannot open log output file!\n");
240 fprintf(fp_write,
"%s is initialized with %d grids.\n\n", name, (
int)
config[3]);
241 fprintf(fp_write,
"Configurated:\n");
242 fprintf(fp_write,
"dim\t\t= %d\n", dim);
244 fprintf(fp_write,
"t_all\t= %d\n", (
int)
config[1]);
245 else if(isfinite(
config[16]))
246 fprintf(fp_write,
"tau\t\t= %g\n",
config[16]);
247 fprintf(fp_write,
"eps\t\t= %g\n",
config[4]);
248 fprintf(fp_write,
"gamma\t= %g\n",
config[6]);
249 fprintf(fp_write,
"CFL\t\t= %g\n",
config[7]);
250 fprintf(fp_write,
"h\t\t= %g\n",
config[10]);
251 fprintf(fp_write,
"bond\t= %d\n", (
int)
config[17]);
254 fprintf(fp_write,
"h_y\t\t= %g\n",
config[11]);
255 fprintf(fp_write,
"bond_y\t= %d\n", (
int)
config[18]);
257 fprintf(fp_write,
"\nA total of %d time steps are computed.\n", (
int)
config[5]);
static int config_read(FILE *fp)
This function read the configuration data file, and store the configuration data in the array "config...
void configurate(const char *add_in)
This function controls configuration data reading and validation.
static void config_check(void)
This function check whether the configuration data is reasonable and set the default.
void config_write(const char *add_out, const double *cpu_time, const char *name)
#define EPS
If the system does not set, the default largest value can be seen as zero is EPS.
double config[]
Initial configuration data array.
#define N_CONF
Define the number of configuration parameters.