Set of routines to provide simple access to a R/O parameter file. More...
Go to the source code of this file.
Classes | |
struct | Par |
Holds a single name=valuecomment tuple as a linked list. More... | |
struct | Block |
Linked list of Pars that belong together. More... | |
Typedefs | |
typedef void(* | proc )(void) |
function pointer type | |
Functions | |
static void * | allocate (size_t size) |
Handy to call if you want to be certain to get the memory, else it will die here. | |
static char * | my_strdup (char *in) |
A simple wrapper for strdup which dies in case of failure. | |
static char * | skipwhite (char *cp) |
Skip whitespace, returning pointer to next location of non-whitespace, or NULL. | |
static void | str_term (char *cp) |
Terminate a string, removing any extra white space at the end of the string. | |
static char * | line_block_name (char *line) |
Extract a block name from a line containing <block> Note it returns pointer into a patched piece of the input 'line'. | |
static void | add_par (Block *bp, char *name, char *value, char *comment) |
Add a name = value # comment set to the Par list in the block *bp. | |
static void | add_par_line (Block *bp, char *line) |
Parse a line, assume it's "key = value # comment" and add it into a block. | |
static Block * | add_block (char *name) |
Find or add a new named Block. | |
static Block * | find_block (char *name) |
Check if a Block name already exists. | |
static Par * | find_par (Block *bp, char *name) |
Check if a Block contains a Par with certain name. | |
static void | free_all (void) |
Free all stuff associated with Block's and Par's. | |
static char * | par_getsl (char *block, char *name) |
Helper function to return a local string. | |
void | par_debug (int level) |
Set debug flag to level. | |
void | par_open (char *filename) |
Open a parameter file for R/O access. | |
void | par_cmdline (int argc, char *argv[]) |
Parse a commandline, very forgiving (no warnings) when not in the right block/name=value format. | |
int | par_exist (char *block, char *name) |
Return 0 or 1 if a block/name exists. | |
char * | par_gets (char *block, char *name) |
Return a string. | |
int | par_geti (char *block, char *name) |
Return an integer. | |
double | par_getd (char *block, char *name) |
Return a Real value. | |
char * | par_gets_def (char *block, char *name, char *def) |
Return string *name in *block if it exists, else use the string *def as a default value. | |
int | par_geti_def (char *block, char *name, int def) |
Return integer *name in *block if it exists, else use the integer def as a default value. | |
double | par_getd_def (char *block, char *name, double def) |
Return double *name in *block if it exists, else use the double def as a default value. | |
void | par_sets (char *block, char *name, char *sval, char *comment) |
Set or add a string. | |
void | par_seti (char *block, char *name, char *fmt, int ival, char *comment) |
Set or add an integer. | |
void | par_setd (char *block, char *name, char *fmt, double dval, char *comment) |
Set or add a double. | |
void | par_dump (int mode, FILE *fp) |
Debugging aid: print out the current status of all Blocks/Pars. | |
void | par_close (void) |
Close up shop, free memory. | |
void | par_dist_mpi (const int mytid, MPI_Comm comm) |
Distribute the doubly linked list of parsed information to the children. | |
int | main (int argc, char *argv[]) |
Variables | |
static int | now_open = 0 |
static char * | now_filename = NULL |
static Block * | base_block = NULL |
static int | debug = 0 |
Set of routines to provide simple access to a R/O parameter file.
PURPOSE: set of routines to provide simple access to a R/O parameter file slightly modeled after FORTRAN namelist. Parameters can also be read directly from the commandline in the same format.
EXAMPLE of input file in 'par' format:
LIMITATIONS:
HISTORY:
CONTAINS PUBLIC FUNCTIONS:
VARIABLE TYPE AND STRUCTURE DEFINITIONS:
PRIVATE FUNCTION PROTOTYPES:
Definition in file par.c.
static Block * add_block | ( | char * | name | ) | [static] |
Find or add a new named Block.
Definition at line 720 of file par.c.
References allocate(), debug, Block::max_name_len, Block::max_value_len, my_strdup(), Block::name, Block::next, and Block::p.
Referenced by par_dist_mpi(), par_open(), par_setd(), par_seti(), and par_sets().
static void add_par | ( | Block * | bp, | |
char * | name, | |||
char * | value, | |||
char * | comment | |||
) | [static] |
Add a name = value # comment set to the Par list in the block *bp.
If a parameter with the input name exists the value is replaced and if the input comment string is non-NULL it is also overwritten
Definition at line 619 of file par.c.
References allocate(), Par::comment, debug, Block::max_name_len, Block::max_value_len, my_strdup(), Par::name, Par::next, Block::p, and Par::value.
Referenced by add_par_line(), par_setd(), par_seti(), and par_sets().
static void add_par_line | ( | Block * | bp, | |
char * | line | |||
) | [static] |
Parse a line, assume it's "key = value # comment" and add it into a block.
Definition at line 669 of file par.c.
References add_par(), ath_error(), name, skipwhite(), and str_term().
Referenced by par_dist_mpi(), and par_open().
static void * allocate | ( | size_t | size | ) | [static] |
Handy to call if you want to be certain to get the memory, else it will die here.
Definition at line 539 of file par.c.
References ath_error().
Referenced by add_block(), and add_par().
static Block * find_block | ( | char * | name | ) | [static] |
Check if a Block name already exists.
Definition at line 745 of file par.c.
References debug, Block::name, and Block::next.
Referenced by par_cmdline(), par_exist(), and par_getsl().
Check if a Block contains a Par with certain name.
Definition at line 761 of file par.c.
References debug, Par::name, Par::next, and Block::p.
Referenced by par_cmdline(), par_exist(), and par_getsl().
static void free_all | ( | void | ) | [static] |
Free all stuff associated with Block's and Par's.
Definition at line 777 of file par.c.
References Par::comment, Block::name, Par::name, Par::next, Block::next, now_filename, Block::p, and Par::value.
Referenced by par_close().
static char * line_block_name | ( | char * | line | ) | [static] |
Extract a block name from a line containing <block> Note it returns pointer into a patched piece of the input 'line'.
Definition at line 595 of file par.c.
References ath_error(), skipwhite(), and str_term().
Referenced by par_dist_mpi(), and par_open().
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Definition at line 892 of file par.c.
References par_close(), par_cmdline(), par_debug(), par_dump(), par_getd(), par_geti(), par_gets(), and par_open().
static char * my_strdup | ( | char * | in | ) | [static] |
A simple wrapper for strdup which dies in case of failure.
Definition at line 551 of file par.c.
References ath_error(), and ath_strdup().
Referenced by add_block(), add_par(), par_cmdline(), par_dist_mpi(), par_gets(), par_gets_def(), and par_open().
void par_close | ( | void | ) |
Close up shop, free memory.
Definition at line 418 of file par.c.
References free_all(), and now_open.
Referenced by main().
void par_cmdline | ( | int | argc, | |
char * | argv[] | |||
) |
Parse a commandline, very forgiving (no warnings) when not in the right block/name=value format.
Definition at line 194 of file par.c.
References ath_error(), debug, find_block(), find_par(), Block::max_value_len, my_strdup(), name, and Par::value.
Referenced by main().
void par_debug | ( | int | level | ) |
void par_dist_mpi | ( | const int | mytid, | |
MPI_Comm | comm | |||
) |
Distribute the doubly linked list of parsed information to the children.
Definition at line 435 of file par.c.
References add_block(), add_par_line(), ath_error(), Par::comment, debug, line_block_name(), my_strdup(), Par::name, Block::name, Par::next, Block::next, now_filename, now_open, Block::p, and Par::value.
Referenced by main().
void par_dump | ( | int | mode, | |
FILE * | fp | |||
) |
Debugging aid: print out the current status of all Blocks/Pars.
Definition at line 377 of file par.c.
References Par::comment, Block::max_name_len, Block::max_value_len, Par::name, Block::name, Par::next, Block::next, Block::p, and Par::value.
Referenced by dump_restart(), and main().
int par_exist | ( | char * | block, | |
char * | name | |||
) |
Return 0 or 1 if a block/name exists.
Definition at line 239 of file par.c.
References ath_error(), find_block(), find_par(), and now_open.
Referenced by init_mesh(), init_output(), init_particle(), par_getd_def(), par_geti_def(), par_gets_def(), and parse_slice().
double par_getd | ( | char * | block, | |
char * | name | |||
) |
Return a Real value.
Definition at line 277 of file par.c.
References par_getsl().
Referenced by dump_particle_binary(), exchange_feedback_init(), init_mesh(), init_output(), initialize(), integrate_init(), main(), new_dt(), pbc_ix1(), pbc_ox1(), problem(), problem_read_restart(), set_bvals_particle_init(), and Userwork_after_loop().
double par_getd_def | ( | char * | block, | |
char * | name, | |||
double | def | |||
) |
Return double *name in *block if it exists, else use the double def as a default value.
Definition at line 320 of file par.c.
References par_exist(), par_getsl(), and par_setd().
Referenced by init_output(), problem(), problem_read_restart(), and Userwork_after_loop().
int par_geti | ( | char * | block, | |
char * | name | |||
) |
Return an integer.
Definition at line 267 of file par.c.
References par_getsl().
Referenced by exchange_feedback_init(), init_mesh(), init_output(), init_particle(), initialize(), main(), problem(), problem_read_restart(), selfg_multig_3d_init(), set_bvals_particle_init(), and Userwork_after_loop().
int par_geti_def | ( | char * | block, | |
char * | name, | |||
int | def | |||
) |
Return integer *name in *block if it exists, else use the integer def as a default value.
Definition at line 304 of file par.c.
References par_exist(), par_getsl(), and par_seti().
Referenced by bvals_mhd(), grid_limit(), init_mesh(), init_output(), init_particle(), main(), problem(), problem_read_restart(), resistivity_init(), and set_bvals_particle_init().
char * par_gets | ( | char * | block, | |
char * | name | |||
) |
Return a string.
Definition at line 257 of file par.c.
References my_strdup(), and par_getsl().
Referenced by init_mesh(), init_output(), main(), and parse_slice().
char * par_gets_def | ( | char * | block, | |
char * | name, | |||
char * | def | |||
) |
Return string *name in *block if it exists, else use the string *def as a default value.
Definition at line 288 of file par.c.
References my_strdup(), par_exist(), par_getsl(), and par_sets().
Referenced by init_output().
static char * par_getsl | ( | char * | block, | |
char * | name | |||
) | [static] |
Helper function to return a local string.
external clients should call par_gets, which returns a newline allocate string
Definition at line 806 of file par.c.
References ath_error(), find_block(), find_par(), now_open, and Par::value.
Referenced by par_getd(), par_getd_def(), par_geti(), par_geti_def(), par_gets(), and par_gets_def().
void par_open | ( | char * | filename | ) |
Open a parameter file for R/O access.
Lines read from the file are locally patched; all names, values and comments are allocated and put into a linked list of Block's and Par's.
Definition at line 156 of file par.c.
References add_block(), add_par_line(), ath_error(), debug, line_block_name(), my_strdup(), now_filename, now_open, and skipwhite().
Referenced by main().
void par_setd | ( | char * | block, | |
char * | name, | |||
char * | fmt, | |||
double | dval, | |||
char * | comment | |||
) |
Set or add a double.
Definition at line 363 of file par.c.
References add_block(), and add_par().
Referenced by data_output(), dump_restart(), and par_getd_def().
void par_seti | ( | char * | block, | |
char * | name, | |||
char * | fmt, | |||
int | ival, | |||
char * | comment | |||
) |
Set or add an integer.
Definition at line 348 of file par.c.
References add_block(), and add_par().
Referenced by data_output(), dump_restart(), init_mesh(), par_geti_def(), and show_config_par().
void par_sets | ( | char * | block, | |
char * | name, | |||
char * | sval, | |||
char * | comment | |||
) |
Set or add a string.
Definition at line 335 of file par.c.
References add_block(), and add_par().
Referenced by main(), par_gets_def(), and show_config_par().
static char * skipwhite | ( | char * | cp | ) | [static] |
Skip whitespace, returning pointer to next location of non-whitespace, or NULL.
Definition at line 564 of file par.c.
Referenced by add_par_line(), line_block_name(), and par_open().
static void str_term | ( | char * | cp | ) | [static] |
Terminate a string, removing any extra white space at the end of the string.
Input char pointer points to the terminating character, e.g. ''.
Definition at line 578 of file par.c.
Referenced by add_par_line(), and line_block_name().
Block* base_block = NULL [static] |
int debug = 0 [static] |
Definition at line 112 of file par.c.
Referenced by add_block(), add_par(), find_block(), find_par(), par_cmdline(), par_debug(), par_dist_mpi(), and par_open().
char* now_filename = NULL [static] |
Definition at line 87 of file par.c.
Referenced by free_all(), par_dist_mpi(), and par_open().
int now_open = 0 [static] |
Definition at line 86 of file par.c.
Referenced by par_close(), par_dist_mpi(), par_exist(), par_getsl(), and par_open().