-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathicicles.f90
125 lines (102 loc) · 2.44 KB
/
icicles.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
!>
!! @file icicles.f90
!! @author Pawel Biernat <[email protected]>
!! @date Thu Mar 8 21:40:28 2012
!!
!! @brief example of icicles
!!
!! @todo try to do some caching of vectors and scalars positions in
!! order to use them with t%set_pointers, now they are looked up using
!! icicles%get.
!!
!! @todo replace [1,n] with sequence 1,n in t%set_pointers?
!!
program icicles_prog
use icicles_module
use tentacle_module
integer :: i,j
integer :: n = 40
character(len=10) :: str
type(named_vector), pointer :: v
type(named_scalar), pointer :: s
type(magical_tentacle) :: t
type(icicles), pointer :: ic
real, target :: x(5)
! create n registry entries, each with len=i and name=i
do i = 1, n
write(str,'(i4)') i
str=trim(adjustl(str))
call t%add(str,i)
end do
! create icicles from registry
call t%create_icicles(ic)
! initialize data inside icicles
ic%data = [(n*(n+1)/2-i+1,i=1,n*(n+1)/2)]
print *, ic%data
do i = 1, n
write(str,'(i4)') i
str=trim(adjustl(str))
! obtain vector 'i' from icicles and set it to i
if( ic%get(str,v) == 0 ) then
v%val = i
end if
end do
! set value of the only scalar to n
if( ic%get("1",s) == 0 ) then
s%val=1
else
print *, "scalar not found"
end if
do i = 1, n
do j = 1, i
print *, "testing data[",i,"]", ic%data(i*(i-1)/2+j) == i
end do
end do
! lets try to point some vectors from icicles to x
x = -1
call t%set_pointers(ic, [2,3], x)
! all of the following tests should print "T"
if( ic%get("2",v) == 0) then
print *, v%val == -1
else
stop
end if
if( ic%get("3",v) == 0 ) then
print *, v%val == -1
else
stop
end if
! now lets change the bounary values
x(1) = -2
x(5) = -2
! all of the following tests should print "T"
if( ic%get("2",v) == 0) then
print *, v%val(1) == -2
else
stop
end if
if( ic%get("3",v) == 0 ) then
print *, v%val(3) == -2
else
stop
end if
! meanwhile, data shouldn't be changed
do i = 1, n
do j = 1, i
print *, "testing data[",i,"]", ic%data(i*(i-1)/2+j) == i
end do
end do
! reset pointers
call t%set_pointers(ic,[1,n],ic%data)
! lets check if the pointers are pointing back to data now
if( ic%get("2",v) == 0) then
print *, v%val == 2
else
stop
end if
if( ic%get("3",v) == 0 ) then
print *, v%val == 3
else
stop
end if
end program icicles_prog