Skip to content
Snippets Groups Projects
Commit 3462ec78 authored by Karl-Michael Schindler's avatar Karl-Michael Schindler
Browse files

Add Fortran YAML-test

parent c6cccd87
Branches
No related tags found
No related merge requests found
...@@ -26,3 +26,4 @@ tests/seteps/build-f90 ...@@ -26,3 +26,4 @@ tests/seteps/build-f90
tests/seteps/build-f90-new tests/seteps/build-f90-new
tests/seteps/build-WFW tests/seteps/build-WFW
tests/SetEpsTestCasesFromScratch/*/eels tests/SetEpsTestCasesFromScratch/*/eels
testprograms/YAML-Test/test
This is the new version of inputs and uses yaml input files. There are differences to the original eelsin/bosin input files.
*** YAML input ***
The input of yaml files uses the package fortran-yaml-c from:
https://github.com/Nicholaswogan/fortran-yaml-c
This is a fortran interface to the common C-library libyaml.
The package needs libyaml, gfortran and cmake and is build from sources with these commands:
mkdir build
cd build
cmake ..
cmake --build .
Among others, it creates these files:
fortran_yaml_c_interface.mod fortran_yaml_c_interface.f90.o fortran_yaml_c_types.mod fortran_yaml_c_types.f90.o fortran_yaml_c.mod fortran_yaml_c.f90.o libyaml_interface.c.o
Search for and copy them to your preferred location. If you like, you can also remove the .f90 and .c from the names.
Compile your source with a correspondingly adjusted command:
gfortran libyaml_interface.o fortran_yaml_c_interface.o fortran_yaml_c_types.o fortran_yaml_c.o -lyaml -L/opt/local/lib -o test test.f90
Or do it in a Makefile.
In the fortran file add
use fortran_yaml_c
For the details of usage, check out example.f90 and test_yaml.f90 in fortran-yaml-c/tests.
\ No newline at end of file
program test
use, intrinsic :: iso_fortran_env, only: output_unit
use fortran_yaml_c
implicit none
type(YamlFile), target :: file
character(:), allocatable :: err
class(type_node), pointer :: root
class(type_dictionary), pointer :: dict
class(type_list), pointer :: list
class(type_list_item), pointer :: item
type(type_error), allocatable :: io_err
character(:), allocatable :: string
real(dp) :: pi
logical :: happy, sadness
write (*,*) 'Program test'
call file%parse("test1.yaml", err)
if (allocated(err)) then
write (*,*) err
stop 1
else
write (*,*) 'File opened.'
endif
call file%dump(unit = output_unit, indent = 0)
write (*,*) '*** Details ***'
root => file%root
select type (root)
class is (type_dictionary)
print'(A,i3)','Number of key-value pairs in root dictionary: ', root%size()
pi = root%get_real('pi', error = io_err)
if (allocated(io_err)) then
print *, io_err%message
stop 1
endif
print *, 'pi: ', pi
happy = root%get_logical('happy-today', error = io_err)
if (allocated(io_err)) then
print *, io_err%message
stop 1
endif
print *, "happy: ",happy
sadness = root%get_logical('sadness', error = io_err)
if (allocated(io_err)) then
print *, io_err%message
stop 1
endif
print *, "sadness: ",sadness
dict => root%get_dictionary('reaction', required = .true., error = io_err)
if (allocated(io_err)) then
print *, io_err%message
stop 1
endif
string = dict%get_string("equation", error = io_err)
if (allocated(io_err)) then
print *, io_err%message
stop 1
endif
print *, "reaction equation: ", string
deallocate(string)
list => root%get_list('groceries', required = .true., error = io_err)
if (allocated(io_err)) then
print *, io_err%message
stop 1
endif
print '(1x,a,i3)', "Number of elements in Grocery list: ", list%size()
print *, "Grocery list:"
item => list%first
do while (associated(item))
select type (element => item%node)
class is (type_scalar)
print '(3x,A)', element%string
item => item%next
end select
enddo
end select
end program
\ No newline at end of file
pi: 3.14159
happy-today: true
sadness: off
groceries: [eggs, butter, oil, bread]
list-that-is-empty: []
"dictionary that-is-empty": {}
another-test:
- []
- {}
- {"what is happening": [1,2,9]}
to-do:
- run a mile
- go fishing
- study:
- for the test
- for the other test
reaction:
equation: H2CO + OH <=> HCO + H2O
rate-constant: {A: 5.7e-15, b: 1.18, Ea: -225.0}
note: this is a note
long-note: this is a really long note
that goes for a few lines
ya.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment