4 integer,
parameter :: dp = kind(0.0d0)
8 real(dp),
allocatable :: my_reals(:)
12 integer :: variable_type
13 character(len=20) :: fmt_string
15 print *,
"Testing m_config.f90 (test 1)"
17 call cfg_add(my_cfg,
"filename",
"this/is/a/filename", &
18 "A string containing a filename")
21 call cfg_add(my_cfg,
"author%age", 25, &
22 "Age of the author of this code")
23 call cfg_add(my_cfg,
"author%fav_reals", (/1.337_dp, 13.37_dp, 133.7_dp/), &
24 "My favorite numbers", dynamic_size=.true.)
25 call cfg_add(my_cfg,
"author%lots_of_work", .true., &
26 "Whether I have a lot of work to do")
29 call cfg_add(my_cfg,
"author_name%first",
"jannis", &
30 "First name of the author of this code")
31 call cfg_add(my_cfg,
"author_name%full", &
32 [
"Jannis ",
"Teunissen"],
"Full name of the author")
34 call cfg_add(my_cfg,
"weather%temperature", 25.0_dp, &
35 "Temperature (Celsius)")
36 call cfg_add(my_cfg,
"weather%humidity", 90.0_dp, &
44 print *,
"----------------------------------------"
45 print *,
"Original values:"
46 print *,
"----------------------------------------"
51 print *,
"----------------------------------------"
52 print *,
"Reading in example_1_input.cfg"
54 print *,
"Udated values:"
55 print *,
"----------------------------------------"
58 call cfg_write(my_cfg,
"example_1_output.cfg")
61 print *,
"----------------------------------------"
62 print *,
"The code below demonstrates how to get values: "
63 print *,
"----------------------------------------"
66 call cfg_get(my_cfg,
"author%lots_of_work", my_logic)
67 write(*,
"(A25,L10)")
"Lots of work: ", my_logic
69 call cfg_get(my_cfg,
"author%age", my_int)
70 write(*,
"(A25,I10)")
"My age: ", my_int
73 write(*,
"(A25,I10)")
"Size favourite numbers: ", n_reals
76 write(fmt_string,
"(A,I0,A)")
"(A25,", n_reals,
"E10.2)"
78 allocate(my_reals(n_reals))
79 call cfg_get(my_cfg,
"author%fav_reals", my_reals)
80 write(*, fmt_string)
"Favourite numbers: ", my_reals
83 call cfg_get_type(my_cfg,
"author_name%full", variable_type)
84 write(*,
"(A25,A10)")
"Type of full name: ",
cfg_type_names(variable_type)
87 print *,
"----------------------------------------"
88 print *,
"Values that were used (through CFG_get):"
89 print *,
"----------------------------------------"
91 call cfg_write(my_cfg,
"stdout", hide_unused=.true.)
Interface to add variables to the configuration.
Interface to get variables from the configuration.
Module that allows working with a configuration file.
subroutine, public cfg_write(cfg_in, filename, hide_unused, custom_first)
This routine writes the current configuration to a file with descriptions.
character(len=10), dimension(0:cfg_num_types), parameter, public cfg_type_names
Names of the types.
subroutine, public cfg_get_size(cfg, var_name, res)
Get the size of a variable.
subroutine, public cfg_write_markdown(cfg_in, filename, hide_unused)
This routine writes the current configuration to a markdown file.
subroutine, public cfg_sort(cfg)
Sort the variables for faster lookup.
subroutine, public cfg_get_type(cfg, var_name, res)
Get the type of a given variable of a configuration type.
subroutine, public cfg_read_file(cfg, filename)
Update the variables in the configartion with the values found in 'filename'.
The configuration that contains all the variables.