Yet Another eXchange Tool 0.11.3
Loading...
Searching...
No Matches
test_idxlist_utils_f.f90
1!>
2!! @file test_idxlist_utils_f.f90
3!!
4!! @copyright Copyright (C) 2016 Jörg Behrens <behrens@dkrz.de>
5!! Moritz Hanke <hanke@dkrz.de>
6!! Thomas Jahns <jahns@dkrz.de>
7!!
8!! @author Jörg Behrens <behrens@dkrz.de>
9!! Moritz Hanke <hanke@dkrz.de>
10!! Thomas Jahns <jahns@dkrz.de>
11!!
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://dkrz-sw.gitlab-pages.dkrz.de/yaxt/
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#include "fc_feature_defs.inc"
48MODULE test_idxlist_utils
49 USE yaxt, ONLY: xt_int_kind, xt_idxlist, xt_idxlist_c2f, xt_idxlist_f2c, &
51 USE ftest_common, ONLY: test_abort
52 USE iso_c_binding, ONLY: c_ptr, c_int, c_size_t
53 IMPLICIT NONE
54 PRIVATE
55 INTERFACE
56 FUNCTION test_err_count() bind(c, name='test_err_count') RESULT(code)
57 IMPORT :: c_int
58 INTEGER(c_int) :: code
59 END FUNCTION test_err_count
60 END INTERFACE
61 PUBLIC :: test_err_count
62 PUBLIC :: check_idxlist, check_stripes, check_offsets, &
63 idxlist_pack_unpack_copy, check_idxlist_copy
64
65 CHARACTER(len=*), PARAMETER :: filename = 'test_idxlist_utils_f.f90'
66CONTAINS
67 SUBROUTINE check_idxlist(idxlist, ref_indices)
68 TYPE(xt_idxlist), INTENT(in) :: idxlist
69 INTEGER(xt_int_kind), INTENT(in) :: ref_indices(:)
70
71 INTEGER :: num_ref_indices
72 INTEGER(xt_int_kind) :: dummy(1)
73 INTEGER(c_int) :: num_ref_indices_c
74
75 INTERFACE
76 SUBROUTINE check_idxlist_c(idxlist, ref_indices, ref_num_indices) &
77 bind(c, name='check_idxlist')
78 IMPORT :: xt_int_kind, c_ptr, c_int
79 IMPLICIT NONE
80 TYPE(c_ptr), VALUE, INTENT(in) :: idxlist
81 INTEGER(xt_int_kind), INTENT(in) :: ref_indices(*)
82 INTEGER(c_int), VALUE, INTENT(in) :: ref_num_indices
83 END SUBROUTINE check_idxlist_c
84 END INTERFACE
85
86 num_ref_indices = SIZE(ref_indices)
87 IF (num_ref_indices > 0) THEN
88 num_ref_indices_c = int(num_ref_indices, c_int)
89 CALL check_idxlist_c(xt_idxlist_f2c(idxlist), ref_indices, &
90 num_ref_indices_c)
91 ELSE
92 dummy(1) = 0_xt_int_kind
93 CALL check_idxlist_c(xt_idxlist_f2c(idxlist), dummy, &
94 0_c_int)
95 END IF
96 END SUBROUTINE check_idxlist
97
98 SUBROUTINE check_stripes(stripes, ref_stripes)
99 TYPE(xt_stripe), INTENT(in) :: stripes(:), ref_stripes(:)
100 INTEGER(c_int) :: num_stripes_c, ref_num_stripes_c
101 INTERFACE
102 SUBROUTINE check_stripes_c(stripes, num_stripes, ref_stripes, &
103 ref_num_stripes) bind(c, name='check_stripes')
104 IMPORT :: xt_stripe, c_int
105 IMPLICIT NONE
106 TYPE(xt_stripe), INTENT(in) :: stripes(*), ref_stripes(*)
107 INTEGER(c_int), VALUE, INTENT(in) :: num_stripes, ref_num_stripes
108 END SUBROUTINE check_stripes_c
109 END INTERFACE
110
111 num_stripes_c = int(SIZE(stripes), c_int)
112 ref_num_stripes_c = int(SIZE(ref_stripes), c_int)
113 CALL check_stripes_c(stripes, num_stripes_c, ref_stripes, ref_num_stripes_c)
114
115 END SUBROUTINE check_stripes
116
117 SUBROUTINE check_offsets(offsets_a, offsets_b)
118 INTEGER(c_int), INTENT(in) :: offsets_a(:), offsets_b(:)
119 INTEGER(c_size_t) :: num_offsets_c
120 INTERFACE
121 SUBROUTINE check_offsets_c(num_offsets, offsets_a, offsets_b) &
122 bind(c, name='check_offsets')
123 IMPORT :: c_size_t, c_int
124 IMPLICIT NONE
125 INTEGER(c_size_t), VALUE, INTENT(in) :: num_offsets
126 INTEGER(c_int), INTENT(IN) :: offsets_a(num_offsets), &
127 offsets_b(num_offsets)
128 END SUBROUTINE check_offsets_c
129 END INTERFACE
130
131 IF (SIZE(offsets_a) /= SIZE(offsets_b)) &
132 CALL test_abort("inequal number of array elements in eq test", &
133 filename, __line__)
134
135 num_offsets_c = int(SIZE(offsets_a), c_size_t)
136 CALL check_offsets_c(num_offsets_c, offsets_a, offsets_b)
137
138 END SUBROUTINE check_offsets
139
140 FUNCTION idxlist_pack_unpack_copy(idxlist) RESULT(idxlist_copy)
141 TYPE(xt_idxlist), INTENT(in) :: idxlist
142 TYPE(xt_idxlist) :: idxlist_copy
143
144 INTERFACE
145 FUNCTION idxlist_pack_unpack_copy_c(idxlist) RESULT(idxlist_copy) &
146 bind(c, name='idxlist_pack_unpack_copy')
147 IMPORT :: c_ptr
148 TYPE(c_ptr), VALUE, INTENT(in) :: idxlist
149 TYPE(c_ptr) :: idxlist_copy
150 END FUNCTION idxlist_pack_unpack_copy_c
151 END INTERFACE
152
153 idxlist_copy &
154 = xt_idxlist_c2f(idxlist_pack_unpack_copy_c(xt_idxlist_f2c(idxlist)))
155
156 END FUNCTION idxlist_pack_unpack_copy
157
158 SUBROUTINE check_idxlist_copy(idxlist, idxlist_copy, ref_indices, ref_stripes)
159 TYPE(xt_idxlist), INTENT(in) :: idxlist, idxlist_copy
160 INTEGER(xt_int_kind), INTENT(in) :: ref_indices(:)
161 TYPE(xt_stripe), INTENT(in) :: ref_stripes(:)
162 INTEGER(c_size_t) :: num_ref_indices_c, num_ref_stripes_c
163 INTERFACE
164 SUBROUTINE check_idxlist_copy_c(idxlist, idxlist_copy, &
165 num_ref_indices, ref_indices, &
166 num_ref_stripes, ref_stripes) bind(c, name='check_idxlist_copy')
167 IMPORT :: c_size_t, c_ptr, xt_int_kind, xt_stripe
168 TYPE(c_ptr), VALUE, INTENT(in) :: idxlist, idxlist_copy
169 INTEGER(c_size_t), VALUE, INTENT(in) :: num_ref_indices, num_ref_stripes
170 INTEGER(xt_int_kind), INTENT(in) :: ref_indices(*)
171 TYPE(xt_stripe), INTENT(in) :: ref_stripes(*)
172 END SUBROUTINE check_idxlist_copy_c
173 END INTERFACE
174 num_ref_indices_c = int(SIZE(ref_indices), c_size_t)
175 num_ref_stripes_c = int(SIZE(ref_stripes), c_size_t)
176 CALL check_idxlist_copy_c(xt_idxlist_f2c(idxlist), &
177 xt_idxlist_f2c(idxlist_copy), num_ref_indices_c, ref_indices, &
178 num_ref_stripes_c, ref_stripes)
179 END SUBROUTINE check_idxlist_copy
180
181END MODULE test_idxlist_utils
182!
183! Local Variables:
184! f90-continuation-indent: 5
185! coding: utf-8
186! indent-tabs-mode: nil
187! show-trailing-whitespace: t
188! require-trailing-newline: t
189! End:
190!
Xt_idxlist xt_idxlist_f2c(struct xt_idxlist_f *p)
Definition yaxt_f2c.c:180