22 #include "../base/base_uses.f90"
28 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'cp_result_types'
35 PUBLIC :: cp_result_type, &
53 TYPE cp_result_value_type
54 INTEGER :: type_in_use = -1
55 LOGICAL,
DIMENSION(:),
POINTER :: logical_type => null()
56 INTEGER,
DIMENSION(:),
POINTER :: integer_type => null()
57 REAL(kind=
dp),
DIMENSION(:),
POINTER :: real_type => null()
58 END TYPE cp_result_value_type
61 TYPE cp_result_value_p_type
62 TYPE(cp_result_value_type),
POINTER ::
value => null()
63 END TYPE cp_result_value_p_type
74 INTEGER :: ref_count = -1
75 TYPE(cp_result_value_p_type),
POINTER,
DIMENSION(:) :: result_value => null()
76 CHARACTER(LEN=default_string_length),
DIMENSION(:), &
77 POINTER :: result_label => null()
78 END TYPE cp_result_type
82 TYPE(cp_result_type),
POINTER :: results => null()
83 END TYPE cp_result_p_type
96 TYPE(cp_result_type),
POINTER :: results
98 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_result_create'
102 CALL timeset(routinen, handle)
104 NULLIFY (results%result_value, results%result_label)
105 results%ref_count = 1
106 ALLOCATE (results%result_label(0))
107 ALLOCATE (results%result_value(0))
108 CALL timestop(handle)
120 TYPE(cp_result_type),
POINTER :: results
122 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_result_release'
126 CALL timeset(routinen, handle)
127 IF (
ASSOCIATED(results))
THEN
128 cpassert(results%ref_count > 0)
129 results%ref_count = results%ref_count - 1
130 IF (results%ref_count == 0)
THEN
132 IF (
ASSOCIATED(results%result_label))
THEN
133 DEALLOCATE (results%result_label)
136 IF (
ASSOCIATED(results%result_value))
THEN
137 DO i = 1,
SIZE(results%result_value)
138 CALL cp_result_value_release(results%result_value(i)%value)
140 DEALLOCATE (results%result_value)
145 CALL timestop(handle)
154 TYPE(cp_result_type),
INTENT(INOUT) :: results
156 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_result_clean'
160 CALL timeset(routinen, handle)
162 IF (
ASSOCIATED(results%result_label))
THEN
163 DEALLOCATE (results%result_label)
166 IF (
ASSOCIATED(results%result_value))
THEN
167 DO i = 1,
SIZE(results%result_value)
168 CALL cp_result_value_release(results%result_value(i)%value)
170 DEALLOCATE (results%result_value)
172 CALL timestop(handle)
183 TYPE(cp_result_type),
INTENT(INOUT) :: results
185 cpassert(results%ref_count > 0)
186 results%ref_count = results%ref_count + 1
195 TYPE(cp_result_value_type),
POINTER :: value
197 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_result_value_create'
201 CALL timeset(routinen, handle)
203 CALL timestop(handle)
214 TYPE(cp_result_value_type),
INTENT(INOUT) :: value
215 INTEGER,
INTENT(IN) :: type_in_use, size_value
217 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_result_value_init'
221 CALL timeset(routinen, handle)
222 value%type_in_use = type_in_use
223 SELECT CASE (
value%type_in_use)
225 ALLOCATE (
value%real_type(size_value))
227 ALLOCATE (
value%integer_type(size_value))
229 ALLOCATE (
value%logical_type(size_value))
234 CALL timestop(handle)
242 SUBROUTINE cp_result_value_release(value)
243 TYPE(cp_result_value_type),
POINTER :: value
245 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_result_value_release'
249 CALL timeset(routinen, handle)
250 IF (
ASSOCIATED(
value))
THEN
251 SELECT CASE (
value%type_in_use)
253 IF (
ASSOCIATED(
value%real_type))
THEN
254 DEALLOCATE (
value%real_type)
256 cpassert(.NOT.
ASSOCIATED(
value%integer_type))
257 cpassert(.NOT.
ASSOCIATED(
value%logical_type))
259 IF (
ASSOCIATED(
value%integer_type))
THEN
260 DEALLOCATE (
value%integer_type)
262 cpassert(.NOT.
ASSOCIATED(
value%real_type))
263 cpassert(.NOT.
ASSOCIATED(
value%logical_type))
265 IF (
ASSOCIATED(
value%logical_type))
THEN
266 DEALLOCATE (
value%logical_type)
268 cpassert(.NOT.
ASSOCIATED(
value%integer_type))
269 cpassert(.NOT.
ASSOCIATED(
value%real_type))
276 CALL timestop(handle)
277 END SUBROUTINE cp_result_value_release
286 TYPE(cp_result_type),
INTENT(INOUT) :: results_in, results_out
288 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_result_copy'
290 INTEGER :: handle, i, ndim
293 CALL timeset(routinen, handle)
296 check =
SIZE(results_in%result_label) ==
SIZE(results_in%result_value)
298 ndim =
SIZE(results_in%result_value)
299 ALLOCATE (results_out%result_label(ndim))
300 ALLOCATE (results_out%result_value(ndim))
302 results_out%result_label(i) = results_in%result_label(i)
305 results_in%result_value(i)%value)
307 CALL timestop(handle)
317 TYPE(cp_result_value_type),
INTENT(INOUT) :: value_out, value_in
319 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_result_value_copy'
321 INTEGER :: handle, isize
323 CALL timeset(routinen, handle)
324 value_out%type_in_use = value_in%type_in_use
325 SELECT CASE (value_out%type_in_use)
327 isize =
SIZE(value_in%real_type)
328 ALLOCATE (value_out%real_type(isize))
329 value_out%real_type = value_in%real_type
331 isize =
SIZE(value_in%integer_type)
332 ALLOCATE (value_out%integer_type(isize))
333 value_out%integer_type = value_in%integer_type
335 isize =
SIZE(value_in%logical_type)
336 ALLOCATE (value_out%logical_type(isize))
337 value_out%logical_type = value_in%logical_type
342 CALL timestop(handle)
353 TYPE(cp_result_value_p_type),
DIMENSION(:), &
354 POINTER :: result_value
355 INTEGER,
INTENT(in) :: istart, iend
357 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_result_value_p_reallocate'
359 INTEGER :: handle, i, lb_size, ub_size
360 TYPE(cp_result_value_p_type),
DIMENSION(:), &
363 CALL timeset(routinen, handle)
366 IF (
ASSOCIATED(result_value))
THEN
367 ub_size = ubound(result_value, 1)
368 lb_size = lbound(result_value, 1)
371 ALLOCATE (tmp_value(istart:iend))
373 NULLIFY (tmp_value(i)%value)
375 IF ((i <= ub_size) .AND. (i >= lb_size))
THEN
377 CALL cp_result_value_release(result_value(i)%value)
380 DEALLOCATE (result_value)
381 result_value => tmp_value
382 CALL timestop(handle)
set of type/routines to handle the storage of results in force_envs
integer, parameter, public result_type_real
subroutine, public cp_result_copy(results_in, results_out)
Copies the cp_result type.
integer, parameter, public result_type_logical
subroutine, public cp_result_retain(results)
Retains cp_result type.
subroutine, public cp_result_release(results)
Releases cp_result type.
subroutine, public cp_result_value_create(value)
Allocates and intitializes the cp_result_value type.
subroutine, public cp_result_clean(results)
Releases cp_result clean.
integer, parameter, public result_type_integer
subroutine, public cp_result_create(results)
Allocates and intitializes the cp_result.
subroutine, public cp_result_value_p_reallocate(result_value, istart, iend)
Reallocates the cp_result_value type.
subroutine, public cp_result_value_copy(value_out, value_in)
Copies the cp_result_value type.
subroutine, public cp_result_value_init(value, type_in_use, size_value)
Setup of the cp_result_value type.
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length