-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtst_exp_flook.lua
86 lines (73 loc) · 1.58 KB
/
tst_exp_flook.lua
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
-- @example exp_flook.lua
--[[
LUA function called by fortran
--]]
print("LUA called from FORTRAN")
-- Define the handle for retaining data
struct = {}
function pre_init()
-- Communicate data from fortran
fortran_get()
struct:print("pre_init")
struct.control = 2.
-- Communicate data to fortran
fortran_set()
end
function post_init()
fortran_get()
struct:print("post_init")
struct.control = 1.
fortran_set()
end
function pre_calc()
fortran_get()
struct:print("pre_calc")
struct.control = 2.
struct.vector[2] = 0.
fortran_set()
end
function post_calc()
fortran_get()
struct:print("post_calc")
fortran_set()
end
function pre_finalize()
fortran_get()
struct:print("pre_finalize")
struct.control = 3.
fortran_set()
end
function post_finalize()
fortran_get()
struct:print("post_finalize")
fortran_set()
print("Fully ran everything in the LUA file")
end
--[[
To ease the printing of the data structures
we add a few helper functions to print matrices in a stringent
way
--]]
function mat_print(name,mat)
print("Printing matrix: "..name)
a = ""
is_matrix = false
for ia,xyz in pairs(mat) do
if type(xyz) == "table" then
is_matrix = true
a = ""
for _,x in pairs(xyz) do a = a .. " " .. x end
print(a)
else
a = a .. " " .. xyz
end
end
if not is_matrix then print(a) end
end
struct.print = function(self,msg)
if msg then print(msg) end
print("Control: "..self.control)
mat_print("matrix",self.matrix)
mat_print("vector",self.vector)
print("") -- new line
end