@@ -71,20 +71,37 @@ subroutine build_instance(tag, data_int, data_dp, error_v, instance_index, res_c
7171
7272 end subroutine build_instance
7373
74- subroutine finalise_instance (instance_index )
74+ function finalise_instance (instance_index ) result(state_index )
7575 ! ! Finalise an instance
7676
7777 integer , intent (in ) :: instance_index
7878 ! ! Index of the instance to finalise
7979
80- type (ResultGen) :: res_check_index_claimed
80+ type (ResultGen) :: res_check
81+ integer :: cause, state_index
82+
83+ res_check = check_index_claimed(instance_index)
8184
82- res_check_index_claimed = check_index_claimed(instance_index)
8385 ! MZ how do we handle unsuccefull finalisation?
84- ! if(res_check_index_claimed%is_error()) return
86+ if ((res_check% is_error()) .and. (&
87+ res_check% error_v% code /= 33 )) then
88+
89+ cause = error_v_manager_build_instance(code = res_check % error_v % code, &
90+ message = res_check % error_v % message)
91+
92+ call build_instance (tag = T_ERR,&
93+ error_v = ErrorV(code= 1 ,message= " Finalise Instance error : " ,cause= cause),&
94+ instance_index = state_index, &
95+ res_check= res_check &
96+ )
97+
98+ return
99+ end if
100+
101+ state_index = 0
85102 call instance_array(instance_index) % finalise()
86103
87- end subroutine finalise_instance
104+ end function finalise_instance
88105
89106 subroutine set_instance_index_to (instance_index , data_int , data_dp , error_v , res_check )
90107
@@ -102,12 +119,12 @@ subroutine set_instance_index_to(instance_index, data_int, data_dp, error_v, res
102119 if (input_check == 0 ) then
103120
104121 call res_check % build (tag = T_ERR,&
105- error_v = ErrorV(code= 1 ,message= " Setting instance ERROR: Empty Input" ))
122+ error_v = ErrorV(code= 1 ,message= " Setting instance ERROR: Empty Input" ))
106123
107124 else if (input_check > 1 ) then
108125
109126 call res_check % build (tag = T_ERR,&
110- error_v = ErrorV(code= 1 ,message= " Setting instance ERROR: Multiple Input" ))
127+ error_v = ErrorV(code= 1 ,message= " Setting instance ERROR: Multiple Input" ))
111128
112129 else
113130
@@ -150,7 +167,7 @@ function probe_instance(instance_index) result(res_instance_index)
150167
151168 end if
152169
153- res_instance_index = instance_index
170+ res_instance_index = 0
154171
155172 end function probe_instance
156173
@@ -241,9 +258,9 @@ function check_index_claimed(instance_index) result(res_check_index_claimed)
241258 if (instance_array(instance_index)% tag== T_NONE) then
242259
243260 msg = " Index " // trim (adjustl (idx_str)) // " has not been claimed"
244- call res_check_index_claimed % build(tag= T_ERR,error_v= ErrorV(code= 3 , message= msg))
245-
261+ call res_check_index_claimed % build(tag= T_ERR,error_v= ErrorV(code= 33 , message= msg))
246262 return
263+
247264 end if
248265
249266 call res_check_index_claimed % build(tag= T_CLAIM)
@@ -297,8 +314,6 @@ subroutine deallocate_instance_array()
297314
298315 if (allocated (instance_array))then
299316 deallocate (instance_array)
300- else
301- print * , " instance_array NOT allocated"
302317 end if
303318
304319 end subroutine deallocate_instance_array
0 commit comments