Afivo
0.3
|
Module that allows working with a configuration file. More...
Data Types | |
type | cfg_var_t |
The type of a configuration variable. More... | |
type | cfg_t |
The configuration that contains all the variables. More... | |
interface | cfg_add |
Interface to add variables to the configuration. More... | |
interface | cfg_get |
Interface to get variables from the configuration. More... | |
interface | cfg_add_get |
Interface to get variables from the configuration. More... | |
Functions/Subroutines | |
subroutine, public | cfg_update_from_arguments (cfg, ignore_unknown) |
Read command line arguments. Both files and variables can be specified, for example as: ./my_program config.cfg -n_runs=3. More... | |
subroutine, public | cfg_update_from_line (cfg, line) |
Update the configuration by parsing a line. More... | |
subroutine | handle_error (err_string) |
This routine will be called if an error occurs in one of the subroutines of this module. More... | |
subroutine | get_var_index (cfg, var_name, ix) |
Return the index of the variable with name 'var_name', or -1 if not found. More... | |
subroutine, public | cfg_read_file (cfg, filename) |
Update the variables in the configartion with the values found in 'filename'. More... | |
subroutine | parse_line (cfg, set_by, line_arg, valid_syntax, category_arg) |
Update the cfg by parsing one line. More... | |
subroutine | read_variable (var) |
subroutine | trim_comment (line, comment_chars) |
subroutine, public | cfg_check (cfg) |
subroutine, public | cfg_write (cfg_in, filename, hide_unused, custom_first) |
This routine writes the current configuration to a file with descriptions. More... | |
subroutine, public | cfg_write_markdown (cfg_in, filename, hide_unused) |
This routine writes the current configuration to a markdown file. More... | |
subroutine | split_category (variable, category, var_name) |
subroutine | resize_storage (variable) |
Resize the storage size of variable, which can be of type integer, logical, real or character. More... | |
subroutine | prepare_store_var (cfg, var_name, var_type, var_size, description, ix, dynamic_size) |
Helper routine to store variables. This is useful because a lot of the same code is executed for the different types of variables. More... | |
subroutine | prepare_get_var (cfg, var_name, var_type, var_size, ix) |
Helper routine to get variables. This is useful because a lot of the same code is executed for the different types of variables. More... | |
subroutine | add_real (cfg, var_name, real_data, comment) |
Add a configuration variable with a real value. More... | |
subroutine | add_real_array (cfg, var_name, real_data, comment, dynamic_size) |
Add a configuration variable with an array of type. More... | |
subroutine | add_int (cfg, var_name, int_data, comment) |
Add a configuration variable with an integer value. More... | |
subroutine | add_int_array (cfg, var_name, int_data, comment, dynamic_size) |
Add a configuration variable with an array of type integer. More... | |
subroutine | add_string (cfg, var_name, char_data, comment) |
Add a configuration variable with an character value. More... | |
subroutine | add_string_array (cfg, var_name, char_data, comment, dynamic_size) |
Add a configuration variable with an array of type character. More... | |
subroutine | add_logic (cfg, var_name, logic_data, comment) |
Add a configuration variable with an logical value. More... | |
subroutine | add_logic_array (cfg, var_name, logic_data, comment, dynamic_size) |
Add a configuration variable with an array of type logical. More... | |
subroutine | get_real_array (cfg, var_name, real_data) |
Get a real array of a given name. More... | |
subroutine | get_int_array (cfg, var_name, int_data) |
Get a integer array of a given name. More... | |
subroutine | get_string_array (cfg, var_name, char_data) |
Get a character array of a given name. More... | |
subroutine | get_logic_array (cfg, var_name, logic_data) |
Get a logical array of a given name. More... | |
subroutine | get_real (cfg, var_name, res) |
Get a real value of a given name. More... | |
subroutine | get_int (cfg, var_name, res) |
Get a integer value of a given name. More... | |
subroutine | get_logic (cfg, var_name, res) |
Get a logical value of a given name. More... | |
subroutine | get_string (cfg, var_name, res) |
Get a character value of a given name. More... | |
subroutine | add_get_real_array (cfg, var_name, real_data, comment, dynamic_size) |
Get or add a real array of a given name. More... | |
subroutine | add_get_int_array (cfg, var_name, int_data, comment, dynamic_size) |
Get or add a integer array of a given name. More... | |
subroutine | add_get_string_array (cfg, var_name, char_data, comment, dynamic_size) |
Get or add a character array of a given name. More... | |
subroutine | add_get_logic_array (cfg, var_name, logic_data, comment, dynamic_size) |
Get or add a logical array of a given name. More... | |
subroutine | add_get_real (cfg, var_name, real_data, comment) |
Get or add a real value of a given name. More... | |
subroutine | add_get_int (cfg, var_name, int_data, comment) |
Get or add a integer value of a given name. More... | |
subroutine | add_get_logic (cfg, var_name, logical_data, comment) |
Get or add a logical value of a given name. More... | |
subroutine | add_get_string (cfg, var_name, string_data, comment) |
Get a character value of a given name. More... | |
subroutine, public | cfg_get_size (cfg, var_name, res) |
Get the size of a variable. More... | |
subroutine, public | cfg_get_type (cfg, var_name, res) |
Get the type of a given variable of a configuration type. More... | |
subroutine | ensure_free_storage (cfg) |
Routine to ensure that enough storage is allocated for the configuration type. If not the new size will be twice as much as the current size. If no storage is allocated yet a minumum amount of starage is allocated. More... | |
subroutine | get_fields_string (line, delims, n_max, n_found, ixs_start, ixs_end) |
Routine to find the indices of entries in a string. More... | |
subroutine | binary_search_variable (cfg, var_name, ix) |
Performa a binary search for the variable 'var_name'. More... | |
subroutine, public | cfg_sort (cfg) |
Sort the variables for faster lookup. More... | |
recursive subroutine | qsort_config (list) |
Simple implementation of quicksort algorithm to sort the variable list alphabetically. More... | |
subroutine | parition_var_list (list, marker) |
Helper routine for quicksort, to perform partitioning. More... | |
subroutine, public | cfg_clear (cfg) |
Clear all data from a CFG_t object, so that it can be reused. Note that this also happens automatically when such an object goes out of scope. More... | |
Variables | |
integer, parameter | dp = kind(0.0d0) |
The double precision kind-parameter. More... | |
integer, parameter | cfg_num_types = 4 |
Number of variable types. More... | |
integer, parameter, public | cfg_integer_type = 1 |
Integer type. More... | |
integer, parameter, public | cfg_real_type = 2 |
Real number type. More... | |
integer, parameter, public | cfg_string_type = 3 |
String type. More... | |
integer, parameter, public | cfg_logic_type = 4 |
Boolean/logical type. More... | |
integer, parameter | cfg_unknown_type = 0 |
Used before a variable is created. More... | |
integer, parameter | cfg_set_by_default = 1 |
Indicates a variable has its default value. More... | |
integer, parameter | cfg_set_by_arg = 2 |
Indicates a variable was set by a command line argument. More... | |
integer, parameter | cfg_set_by_file = 3 |
Indicates a variable was set by reading a file. More... | |
character(len=10), dimension(0:cfg_num_types), parameter, public | cfg_type_names = [character(len=10) :: "storage", "integer", "real", "string ", "logical"] |
Names of the types. More... | |
integer, parameter, public | cfg_name_len = 80 |
Maximum length of variable names. More... | |
integer, parameter, public | cfg_string_len = 200 |
Fixed length of string type. More... | |
integer, parameter, public | cfg_max_array_size = 1000 |
Maximum number of entries in a variable (if it's an array) More... | |
character, parameter | tab_char = char(9) |
character(len= *), parameter | cfg_separators = " ,'"""//tab_char |
The separator(s) for array-like variables (space, comma, ', ", and tab) More... | |
character(len= *), parameter | cfg_category_separator = "%" |
The separator for categories (stored in var_name) More... | |
character(len= *), parameter | unstored_data_string = "__UNSTORED_DATA_STRING" |
The default string for data that is not yet stored. More... | |
Module that allows working with a configuration file.
Author: Jannis Teunissen and others Repository: https://github.com/jannisteunissen/config_fortran
subroutine, public m_config::cfg_update_from_arguments | ( | type(cfg_t), intent(inout) | cfg, |
logical, intent(in), optional | ignore_unknown | ||
) |
Read command line arguments. Both files and variables can be specified, for example as: ./my_program config.cfg -n_runs=3.
config files should have an extension .cfg or .txt command line arguments should be preceded by a single dash
[in] | ignore_unknown | Ignore unknown arguments (default: false) |
Definition at line 142 of file m_config.f90.
subroutine, public m_config::cfg_update_from_line | ( | type(cfg_t), intent(inout) | cfg, |
character(len=*), intent(in) | line | ||
) |
Update the configuration by parsing a line.
Definition at line 180 of file m_config.f90.
|
private |
This routine will be called if an error occurs in one of the subroutines of this module.
Definition at line 195 of file m_config.f90.
|
private |
Return the index of the variable with name 'var_name', or -1 if not found.
Definition at line 207 of file m_config.f90.
subroutine, public m_config::cfg_read_file | ( | type(cfg_t), intent(inout) | cfg, |
character(len=*), intent(in) | filename | ||
) |
Update the variables in the configartion with the values found in 'filename'.
Definition at line 229 of file m_config.f90.
|
private |
Update the cfg by parsing one line.
[in] | set_by | Where the line came from |
[in] | line_arg | Line to parse |
[in,out] | category_arg | The category |
Definition at line 273 of file m_config.f90.
|
private |
Definition at line 368 of file m_config.f90.
|
private |
Definition at line 419 of file m_config.f90.
subroutine, public m_config::cfg_check | ( | type(cfg_t), intent(in) | cfg | ) |
Definition at line 449 of file m_config.f90.
subroutine, public m_config::cfg_write | ( | type(cfg_t), intent(in) | cfg_in, |
character(len=*), intent(in) | filename, | ||
logical, intent(in), optional | hide_unused, | ||
logical, intent(in), optional | custom_first | ||
) |
This routine writes the current configuration to a file with descriptions.
[in] | hide_unused | Hide variables whose value was not requested |
[in] | custom_first | Show user-set variables first (default: false) |
Definition at line 464 of file m_config.f90.
subroutine, public m_config::cfg_write_markdown | ( | type(cfg_t), intent(in) | cfg_in, |
character(len=*), intent(in) | filename, | ||
logical, intent(in), optional | hide_unused | ||
) |
This routine writes the current configuration to a markdown file.
Definition at line 599 of file m_config.f90.
subroutine m_config::split_category | ( | type(cfg_var_t), intent(in) | variable, |
character(cfg_name_len), intent(out) | category, | ||
character(cfg_name_len), intent(out) | var_name | ||
) |
Definition at line 694 of file m_config.f90.
|
private |
Resize the storage size of variable, which can be of type integer, logical, real or character.
Definition at line 714 of file m_config.f90.
|
private |
Helper routine to store variables. This is useful because a lot of the same code is executed for the different types of variables.
[out] | ix | Index of variable |
Definition at line 735 of file m_config.f90.
|
private |
Helper routine to get variables. This is useful because a lot of the same code is executed for the different types of variables.
Definition at line 787 of file m_config.f90.
|
private |
Add a configuration variable with a real value.
Definition at line 815 of file m_config.f90.
|
private |
Add a configuration variable with an array of type.
Definition at line 832 of file m_config.f90.
|
private |
Add a configuration variable with an integer value.
Definition at line 850 of file m_config.f90.
|
private |
Add a configuration variable with an array of type integer.
Definition at line 866 of file m_config.f90.
|
private |
Add a configuration variable with an character value.
Definition at line 884 of file m_config.f90.
|
private |
Add a configuration variable with an array of type character.
Definition at line 898 of file m_config.f90.
|
private |
Add a configuration variable with an logical value.
Definition at line 916 of file m_config.f90.
|
private |
Add a configuration variable with an array of type logical.
Definition at line 932 of file m_config.f90.
|
private |
Get a real array of a given name.
Definition at line 951 of file m_config.f90.
|
private |
Get a integer array of a given name.
Definition at line 963 of file m_config.f90.
|
private |
Get a character array of a given name.
Definition at line 975 of file m_config.f90.
|
private |
Get a logical array of a given name.
Definition at line 987 of file m_config.f90.
|
private |
Get a real value of a given name.
Definition at line 999 of file m_config.f90.
|
private |
Get a integer value of a given name.
Definition at line 1010 of file m_config.f90.
|
private |
Get a logical value of a given name.
Definition at line 1021 of file m_config.f90.
|
private |
Get a character value of a given name.
Definition at line 1032 of file m_config.f90.
|
private |
Get or add a real array of a given name.
Definition at line 1043 of file m_config.f90.
|
private |
Get or add a integer array of a given name.
Definition at line 1055 of file m_config.f90.
|
private |
Get or add a character array of a given name.
Definition at line 1067 of file m_config.f90.
|
private |
Get or add a logical array of a given name.
Definition at line 1079 of file m_config.f90.
|
private |
Get or add a real value of a given name.
Definition at line 1091 of file m_config.f90.
|
private |
Get or add a integer value of a given name.
Definition at line 1101 of file m_config.f90.
|
private |
Get or add a logical value of a given name.
Definition at line 1111 of file m_config.f90.
|
private |
Get a character value of a given name.
Definition at line 1121 of file m_config.f90.
subroutine, public m_config::cfg_get_size | ( | type(cfg_t), intent(in) | cfg, |
character(len=*), intent(in) | var_name, | ||
integer, intent(out) | res | ||
) |
Get the size of a variable.
Definition at line 1131 of file m_config.f90.
subroutine, public m_config::cfg_get_type | ( | type(cfg_t), intent(in) | cfg, |
character(len=*), intent(in) | var_name, | ||
integer, intent(out) | res | ||
) |
Get the type of a given variable of a configuration type.
Definition at line 1147 of file m_config.f90.
|
private |
Routine to ensure that enough storage is allocated for the configuration type. If not the new size will be twice as much as the current size. If no storage is allocated yet a minumum amount of starage is allocated.
Definition at line 1166 of file m_config.f90.
|
private |
Routine to find the indices of entries in a string.
[in] | line | The line from which we want to read |
[in] | delims | A string with delimiters. For example delims = " ,'"""//tab_char |
[in] | n_max | Maximum number of entries to read in |
[in,out] | n_found | Number of entries found |
[in,out] | ixs_start | On return, ix_start(i) holds the starting point of entry i |
[in,out] | ixs_end | On return, ix_end(i) holds the end point of entry i |
Definition at line 1190 of file m_config.f90.
|
private |
Performa a binary search for the variable 'var_name'.
Definition at line 1233 of file m_config.f90.
subroutine, public m_config::cfg_sort | ( | type(cfg_t), intent(inout) | cfg | ) |
Sort the variables for faster lookup.
Definition at line 1261 of file m_config.f90.
|
private |
Simple implementation of quicksort algorithm to sort the variable list alphabetically.
Definition at line 1269 of file m_config.f90.
|
private |
Helper routine for quicksort, to perform partitioning.
Definition at line 1281 of file m_config.f90.
subroutine, public m_config::cfg_clear | ( | type(cfg_t) | cfg | ) |
Clear all data from a CFG_t object, so that it can be reused. Note that this also happens automatically when such an object goes out of scope.
Definition at line 1323 of file m_config.f90.
|
private |
The double precision kind-parameter.
Definition at line 11 of file m_config.f90.
|
private |
Number of variable types.
Definition at line 13 of file m_config.f90.
integer, parameter, public m_config::cfg_integer_type = 1 |
Integer type.
Definition at line 14 of file m_config.f90.
integer, parameter, public m_config::cfg_real_type = 2 |
Real number type.
Definition at line 15 of file m_config.f90.
integer, parameter, public m_config::cfg_string_type = 3 |
String type.
Definition at line 16 of file m_config.f90.
integer, parameter, public m_config::cfg_logic_type = 4 |
Boolean/logical type.
Definition at line 17 of file m_config.f90.
|
private |
Used before a variable is created.
Definition at line 18 of file m_config.f90.
|
private |
Indicates a variable has its default value.
Definition at line 21 of file m_config.f90.
|
private |
Indicates a variable was set by a command line argument.
Definition at line 23 of file m_config.f90.
|
private |
Indicates a variable was set by reading a file.
Definition at line 25 of file m_config.f90.
character(len=10), dimension(0:cfg_num_types), parameter, public m_config::cfg_type_names = [character(len=10) :: "storage", "integer", "real", "string ", "logical"] |
Names of the types.
Definition at line 28 of file m_config.f90.
integer, parameter, public m_config::cfg_name_len = 80 |
Maximum length of variable names.
Definition at line 31 of file m_config.f90.
integer, parameter, public m_config::cfg_string_len = 200 |
Fixed length of string type.
Definition at line 32 of file m_config.f90.
integer, parameter, public m_config::cfg_max_array_size = 1000 |
Maximum number of entries in a variable (if it's an array)
Definition at line 35 of file m_config.f90.
|
private |
Definition at line 37 of file m_config.f90.
|
private |
The separator(s) for array-like variables (space, comma, ', ", and tab)
Definition at line 40 of file m_config.f90.
|
private |
The separator for categories (stored in var_name)
Definition at line 43 of file m_config.f90.
|
private |
The default string for data that is not yet stored.
Definition at line 46 of file m_config.f90.