afivo-streamer 1.1
1D/2D/3D streamer simulations with AMR
Loading...
Searching...
No Matches
example_1.f90
Go to the documentation of this file.
2 use m_config
3
4 integer, parameter :: dp = kind(0.0d0)
5 type(cfg_t) :: my_cfg
6
7 ! Some dummy variables
8 real(dp), allocatable :: my_reals(:)
9 logical :: my_logic
10 integer :: my_int
11 integer :: n_reals
12 integer :: variable_type
13 character(len=20) :: fmt_string
14
15 print *, "Testing m_config.f90 (test 1)"
16
17 call cfg_add(my_cfg, "filename", "this/is/a/filename", &
18 "A string containing a filename")
19
20 ! Variables can be placed inside categories
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")
27
28 ! Categories cannot be nested
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")
33
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, &
37 "Humidity (percent)")
38
39 ! Sort the configuration (this can speed up looking for variables, but only if
40 ! you have a sufficiently large number of them)
41 call cfg_sort(my_cfg)
42
43 print *, ""
44 print *, "----------------------------------------"
45 print *, "Original values:"
46 print *, "----------------------------------------"
47 print *, ""
48
49 ! Write to stdout (only when given the filename "stdout")
50 call cfg_write(my_cfg, "stdout")
51 print *, "----------------------------------------"
52 print *, "Reading in example_1_input.cfg"
53 call cfg_read_file(my_cfg, "example_1_input.cfg") ! Update values with file
54 print *, "Udated values:"
55 print *, "----------------------------------------"
56 print *, ""
57 call cfg_write(my_cfg, "stdout") ! Write to stdout
58 call cfg_write(my_cfg, "example_1_output.cfg") ! Write to file
59 call cfg_write_markdown(my_cfg, "example_1_output.md") ! Write markdown file
60
61 print *, "----------------------------------------"
62 print *, "The code below demonstrates how to get values: "
63 print *, "----------------------------------------"
64 print *, ""
65
66 call cfg_get(my_cfg, "author%lots_of_work", my_logic)
67 write(*, "(A25,L10)") "Lots of work: ", my_logic
68
69 call cfg_get(my_cfg, "author%age", my_int)
70 write(*, "(A25,I10)") "My age: ", my_int
71
72 call cfg_get_size(my_cfg, "author%fav_reals", n_reals)
73 write(*, "(A25,I10)") "Size favourite numbers: ", n_reals
74
75 ! Generate format string
76 write(fmt_string, "(A,I0,A)") "(A25,", n_reals, "E10.2)"
77
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
81 deallocate(my_reals)
82
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)
85
86 print *, ""
87 print *, "----------------------------------------"
88 print *, "Values that were used (through CFG_get):"
89 print *, "----------------------------------------"
90 print *, ""
91 call cfg_write(my_cfg, "stdout", hide_unused=.true.) ! Write to stdout
92
93end program test_m_config
program test_m_config
Definition example_1.f90:1
Interface to add variables to the configuration.
Definition m_config.f90:86
Interface to get variables from the configuration.
Definition m_config.f90:94
Module that allows working with a configuration file.
Definition m_config.f90:5
subroutine, public cfg_write(cfg_in, filename, hide_unused, custom_first)
This routine writes the current configuration to a file with descriptions.
Definition m_config.f90:480
character(len=10), dimension(0:cfg_num_types), parameter, public cfg_type_names
Names of the types.
Definition m_config.f90:28
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.
Definition m_config.f90:615
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'.
Definition m_config.f90:239
The configuration that contains all the variables.
Definition m_config.f90:79