@@ -24,8 +24,10 @@ module m_result_w
2424 private
2525
2626 public :: build_instance_int, build_instance_dp, build_instance_err,&
27- get_instance_tag, get_data_int, get_data_dp, &
28- finalise_instance, finalise_instances
27+ finalise_instance, finalise_instances, &
28+ get_instance_tag, get_data_int, get_data_dp, get_error
29+
30+ integer , parameter , public :: s_claimed= T_CLAIM, s_none= T_NONE, s_int= T_INT, s_dp= T_DP, s_err= T_ERR
2931
3032contains
3133
@@ -94,6 +96,9 @@ function build_instance_err(error_v_instance_index) result(instance_index)
9496
9597 type (ErrorV) :: error_v
9698 type (ResultGen) :: res_check
99+ ! integer :: code
100+ ! character(len=10) :: int2char
101+ ! character(len=:), allocatable :: message
97102
98103 if (error_v_instance_index > 0 ) then
99104
@@ -109,8 +114,13 @@ function build_instance_err(error_v_instance_index) result(instance_index)
109114
110115 else
111116
112- ! maybe generate an error
113- print * , " Provided code does NOT match any ERROR type"
117+ call error_v % build(code = 1 , message = " Provided code does NOT match any ERROR type" )
118+ call result_manager_build_instance(&
119+ tag = T_ERR, &
120+ error_v = error_v, &
121+ instance_index= instance_index,&
122+ res_check = res_check &
123+ )
114124
115125 end if
116126
@@ -150,12 +160,6 @@ function get_data_int(instance_index) result(data_int)
150160
151161 res_stored = result_manager_get_instance(instance_index)
152162
153- if (res_stored % tag /= T_INT) then
154- ! ERROR in a smarter way
155- print * , " TAG type does not match the expected type"
156- return
157- end if
158-
159163 data_int = res_stored % data_int
160164
161165 end function get_data_int
@@ -170,14 +174,7 @@ function get_data_dp(instance_index) result(data_dp)
170174
171175 res_stored = result_manager_get_instance(instance_index)
172176
173- ! Think if it is worth checking
174- if (res_stored % tag /= T_DP) then
175- ! ERROR in a smarter way
176- print * , " TAG type does not match the expected type"
177- return
178- end if
179-
180- data_dp = res_stored% data_dp
177+ data_dp = res_stored % data_dp
181178
182179 end function get_data_dp
183180
@@ -186,15 +183,21 @@ subroutine get_error(instance_index,code,message)
186183
187184 integer , intent (in ) :: instance_index
188185 integer , intent (out ) :: code
189- character (len=* ), intent (out ) :: message
186+ ! MZ: How to avoid long fixed length??
187+ character (len= 1000 ), intent (out ) :: message
188+ character (len= 10 ) :: int2char
190189 type (ResultGen) :: res_stored
191190
192191 res_stored = result_manager_get_instance(instance_index)
193192
194- ! Think if it is worth checking
193+ ! Think if it is worth checking as the Python side should already deal with it. Should be built an error?
195194 if (res_stored % tag /= T_ERR) then
196- ! ERROR in a smarter way
197- print * , " TAG type does not match the expected type"
195+ ! ERROR in a smarter way?
196+ code = 1
197+ write (int2char," (I0)" ) instance_index
198+ message = " TAG mismatch! Expected -> ERROR but index: " // adjustl (trim (int2char))
199+ write (int2char," (I0)" ) res_stored % tag
200+ message = adjustl (trim (message)) // " has TAG = " // adjustl (trim (int2char))
198201 return
199202 end if
200203
0 commit comments