Yet Another eXchange Tool  DO_NOT_EDIT_HERE
test_idxlist_utils_f.f90
1 
12 
13 !
14 ! Keywords:
15 ! Maintainer: Jörg Behrens <behrens@dkrz.de>
16 ! Moritz Hanke <hanke@dkrz.de>
17 ! Thomas Jahns <jahns@dkrz.de>
18 ! URL: https://doc.redmine.dkrz.de/yaxt/html/
19 !
20 ! Redistribution and use in source and binary forms, with or without
21 ! modification, are permitted provided that the following conditions are
22 ! met:
23 !
24 ! Redistributions of source code must retain the above copyright notice,
25 ! this list of conditions and the following disclaimer.
26 !
27 ! Redistributions in binary form must reproduce the above copyright
28 ! notice, this list of conditions and the following disclaimer in the
29 ! documentation and/or other materials provided with the distribution.
30 !
31 ! Neither the name of the DKRZ GmbH nor the names of its contributors
32 ! may be used to endorse or promote products derived from this software
33 ! without specific prior written permission.
34 !
35 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
36 ! IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
37 ! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
38 ! PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
39 ! OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
40 ! EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
41 ! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
42 ! PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
43 ! LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
44 ! NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
45 ! SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 !
47 MODULE test_idxlist_utils
48  USE yaxt, ONLY: xt_int_kind, xt_idxlist, xt_idxlist_c2f, xt_idxlist_f2c, &
49  xt_stripe
50  USE ftest_common, ONLY: test_abort
51  USE iso_c_binding, ONLY: c_ptr, c_int, c_size_t
52  IMPLICIT NONE
53  PRIVATE
54  INTERFACE
55  FUNCTION test_err_count() bind(c, name='test_err_count') RESULT(code)
56  IMPORT :: c_int
57  INTEGER(c_int) :: code
58  END FUNCTION test_err_count
59  END INTERFACE
60  PUBLIC :: test_err_count
61  PUBLIC :: check_idxlist, check_stripes, check_offsets, &
62  idxlist_pack_unpack_copy, check_idxlist_copy
63 CONTAINS
64  SUBROUTINE check_idxlist(idxlist, ref_indices)
65  TYPE(xt_idxlist), INTENT(in) :: idxlist
66  INTEGER(xt_int_kind), INTENT(in) :: ref_indices(:)
67 
68  INTEGER :: num_ref_indices
69  INTEGER(xt_int_kind) :: dummy(1)
70  INTEGER(c_int) :: num_ref_indices_c
71 
72  INTERFACE
73  SUBROUTINE check_idxlist_c(idxlist, ref_indices, ref_num_indices) &
74  bind(c, name='check_idxlist')
75  IMPORT :: xt_int_kind, c_ptr, c_int
76  IMPLICIT NONE
77  TYPE(c_ptr), VALUE, INTENT(in) :: idxlist
78  INTEGER(xt_int_kind), INTENT(in) :: ref_indices(*)
79  INTEGER(c_int), VALUE, INTENT(in) :: ref_num_indices
80  END SUBROUTINE check_idxlist_c
81  END INTERFACE
82 
83  num_ref_indices = SIZE(ref_indices)
84  IF (num_ref_indices > 0) THEN
85  num_ref_indices_c = int(num_ref_indices, c_int)
86  CALL check_idxlist_c(xt_idxlist_f2c(idxlist), ref_indices, &
87  num_ref_indices_c)
88  ELSE
89  CALL check_idxlist_c(xt_idxlist_f2c(idxlist), dummy, &
90  0_c_int)
91  END IF
92  END SUBROUTINE check_idxlist
93 
94  SUBROUTINE check_stripes(stripes, ref_stripes)
95  TYPE(xt_stripe), INTENT(in) :: stripes(:), ref_stripes(:)
96  INTEGER(c_int) :: num_stripes_c, ref_num_stripes_c
97  INTERFACE
98  SUBROUTINE check_stripes_c(stripes, num_stripes, ref_stripes, &
99  ref_num_stripes) bind(c, name='check_stripes')
100  IMPORT :: xt_stripe, c_int
101  IMPLICIT NONE
102  TYPE(xt_stripe), INTENT(in) :: stripes(*), ref_stripes(*)
103  INTEGER(c_int), VALUE, INTENT(in) :: num_stripes, ref_num_stripes
104  END SUBROUTINE check_stripes_c
105  END INTERFACE
106 
107  num_stripes_c = int(SIZE(stripes), c_int)
108  ref_num_stripes_c = int(SIZE(ref_stripes), c_int)
109  CALL check_stripes_c(stripes, num_stripes_c, ref_stripes, ref_num_stripes_c)
110 
111  END SUBROUTINE check_stripes
112 
113  SUBROUTINE check_offsets(offsets_a, offsets_b)
114  INTEGER(c_int), INTENT(in) :: offsets_a(:), offsets_b(:)
115  INTEGER(c_size_t) :: num_offsets_c
116  INTERFACE
117  SUBROUTINE check_offsets_c(num_offsets, offsets_a, offsets_b) &
118  bind(c, name='check_offsets')
119  IMPORT :: c_size_t, c_int
120  IMPLICIT NONE
121  INTEGER(c_size_t), VALUE, INTENT(in) :: num_offsets
122  INTEGER(c_int), INTENT(IN) :: offsets_a(num_offsets), &
123  offsets_b(num_offsets)
124  END SUBROUTINE check_offsets_c
125  END INTERFACE
126 
127  IF (SIZE(offsets_a) /= size(offsets_b)) &
128  CALL test_abort("inequal number of array elements in eq test", &
129  __file__, &
130  __line__)
131 
132  num_offsets_c = int(SIZE(offsets_a), c_size_t)
133  CALL check_offsets_c(num_offsets_c, offsets_a, offsets_b)
134 
135  END SUBROUTINE check_offsets
136 
137  FUNCTION idxlist_pack_unpack_copy(idxlist) RESULT(idxlist_copy)
138  TYPE(xt_idxlist), INTENT(in) :: idxlist
139  TYPE(xt_idxlist) :: idxlist_copy
140 
141  INTERFACE
142  FUNCTION idxlist_pack_unpack_copy_c(idxlist) RESULT(idxlist_copy) &
143  bind(c, name='idxlist_pack_unpack_copy')
144  IMPORT :: c_ptr
145  TYPE(c_ptr), VALUE, INTENT(in) :: idxlist
146  TYPE(c_ptr) :: idxlist_copy
147  END FUNCTION idxlist_pack_unpack_copy_c
148  END INTERFACE
149 
150  idxlist_copy &
151  = xt_idxlist_c2f(idxlist_pack_unpack_copy_c(xt_idxlist_f2c(idxlist)))
152 
153  END FUNCTION idxlist_pack_unpack_copy
154 
155  SUBROUTINE check_idxlist_copy(idxlist, idxlist_copy, ref_indices, ref_stripes)
156  TYPE(xt_idxlist), INTENT(in) :: idxlist, idxlist_copy
157  INTEGER(xt_int_kind), INTENT(in) :: ref_indices(:)
158  TYPE(xt_stripe), INTENT(in) :: ref_stripes(:)
159  INTEGER(c_size_t) :: num_ref_indices_c, num_ref_stripes_c
160  INTERFACE
161  SUBROUTINE check_idxlist_copy_c(idxlist, idxlist_copy, &
162  num_ref_indices, ref_indices, &
163  num_ref_stripes, ref_stripes) bind(c, name='check_idxlist_copy')
164  IMPORT :: c_size_t, c_ptr, xt_int_kind, xt_stripe
165  TYPE(c_ptr), VALUE, INTENT(in) :: idxlist, idxlist_copy
166  INTEGER(c_size_t), VALUE, INTENT(in) :: num_ref_indices, num_ref_stripes
167  INTEGER(xt_int_kind), INTENT(in) :: ref_indices(*)
168  TYPE(xt_stripe), INTENT(in) :: ref_stripes(*)
169  END SUBROUTINE check_idxlist_copy_c
170  END INTERFACE
171  num_ref_indices_c = int(SIZE(ref_indices), c_size_t)
172  num_ref_stripes_c = int(SIZE(ref_stripes), c_size_t)
173  CALL check_idxlist_copy_c(xt_idxlist_f2c(idxlist), &
174  xt_idxlist_f2c(idxlist_copy), num_ref_indices_c, ref_indices, &
175  num_ref_stripes_c, ref_stripes)
176  END SUBROUTINE check_idxlist_copy
177 
178 END MODULE test_idxlist_utils
179 !
180 ! Local Variables:
181 ! f90-continuation-indent: 5
182 ! coding: utf-8
183 ! indent-tabs-mode: nil
184 ! show-trailing-whitespace: t
185 ! require-trailing-newline: t
186 ! End:
187 !