forked from jacobwilliams/daglib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint-to-json.f90
48 lines (43 loc) · 2.02 KB
/
print-to-json.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
program print_to_json
!! Demonstrate writing a dag_t object in JSON format
!!
!! Compile and run run this program by executing the following
!! command from the top-level directory of the dag source tree:
!!
!! fpm run --example print-to-json
!!
use dag_m, only: dag_t
use vertex_m, only: vertex_t
use iso_varying_string, only : varying_string, var_str
implicit none
character(len=*), parameter :: longest_name = "iso_varying_string"
character(len=len(longest_name)), parameter :: names(*) = &
[character(len=len(longest_name)) :: "iso_varying_string", "assert_m", "vertex_s", "vertex_m", "dag_m", "dag_s", "main"]
type(varying_string) name_string(size(names))
name_string = var_str(names)
associate( &
iso_varying_string => findloc(names, "iso_varying_string", dim=1) &
,assert_m => findloc(names, "assert_m", dim=1) &
,vertex_s => findloc(names, "vertex_s", dim=1) &
,vertex_m => findloc(names, "vertex_m", dim=1) &
,dag_m => findloc(names, "dag_m", dim=1) &
,dag_s => findloc(names, "dag_s", dim=1) &
,main => findloc(names, "main", dim=1) &
)
block
type(dag_t) program_units
program_units = dag_t([ &
vertex_t( [integer::], name_string(iso_varying_string) ) &
,vertex_t( [integer::], name_string(assert_m) ) &
,vertex_t( [vertex_m, assert_m], name_string(vertex_s) ) &
,vertex_t( [integer::], name_string(vertex_m) ) &
,vertex_t( [vertex_m], name_string(dag_m) ) &
,vertex_t( [dag_m, assert_m], name_string(dag_s) ) &
,vertex_t( [dag_m, vertex_m], name_string(main) ) &
])
associate(json_object => program_units%to_json())
print *, json_object%to_expanded_string()
end associate
end block
end associate
end program