PLUTO
4.4-patch2
|
File parser utilities. More...
#include "pluto.h"
Functions | |
static int | ParamFileGetWords (char *line, char **) |
int | ParamFileRead (char *fname) |
char * | ParamFileGet (const char *label, int pos) |
int | ParamFileHasBoth (const char *label1, const char *label2) |
int | ParamExist (const char *label) |
Variables | |
static int | nlines |
static char ** | fline |
This file provides a set of useful functions to open / read and parse the content of a parameter file (typically pluto.ini). The parameter file can contain a number of lines with the general structure
label value1 value2 ...
where the number of values following the label can be different for each line.
ParamFileRead() reads the file and store its content into an array of lines (**fline
). ParamFileGet() can be used to retrieve the n-th parameter value following a given label, while ParQuery() check whether a parameter actually exists.
As an example consider the following file "myparam.txt":
---- File myparam.txt ----- nx 100 xdomain 15.0 30.0 ---------------------------
The parameter can be read with the following code snippet:
int ParamExist | ( | const char * | label | ) |
Check whether *label exists in any of the lines (**fline).
[in] | label |
char* ParamFileGet | ( | const char * | label, |
int | pos | ||
) |
Search for *label
in all the lines pointed to by **fline
. If label exists, return a pointer to the string located pos words after label. Issue an error if this string cannot be located.
[in] | label | the first word of a line to be searched |
[in] | pos | an integer giving the position of the word |
|
static |
Return the words and their number contained in a single line.
int ParamFileHasBoth | ( | const char * | label1, |
const char * | label2 | ||
) |
Locate the line beginning with label1 and return 1 if label2 can be found on the same line. Return 0 otherwise.
[in] | label1 | The first word of the line to be searched |
[in] | label2 | A word containined in the same line beginning with label1 |
int ParamFileRead | ( | char * | fname | ) |
Parse file *fname and store its content line by line in *fline. Blank lines are excluded.
[in] | fname | the name of the file to be read |
|
static |
All of the lines (including empty ones) in the file
|
static |
The total number of lines (including empty ones) contained in the file