36 use gtdata_generic,
only: inquire, get_slice
39 use dc_trace,
only: beginsub, endsub, dbgmessage
42 logical,
intent(out),
optional:: err
43 integer:: ndim1, ndim2, ndimo
44 integer,
allocatable:: map1(:), map2(:)
47 character(*),
parameter:: subnam =
"GTVarXformBinary"
49 call beginsub(subnam,
'mapid=[%d, %d]', i=(/var1%mapid, var2%mapid/))
55 if (
present(err)) err = .false.
56 call inquire(var1, alldims=ndim1)
57 call inquire(var2, alldims=ndim2)
58 ndimo = max(ndim1, ndim2, 0)
59 allocate(map1(1:ndim1), map2(1:ndim2))
60 call getmatch(var1, var2, ndim1, ndim2, map1, map2)
61 call dbgmessage(
'map1=%*d map2=%*d', i=(/map1(1:ndim1), map2(1:ndim2)/), n=(/ndim1, ndim2/))
62 if (all(map2(1:ndim2) == 0))
then
69 ndimo = ndim2 + count(map1(1:ndim1) == 0)
74 newmap(1:ndim2)%dimno = map2(1:ndim2)
75 call inquire(var2, allcount=newmap(1:ndim2)%allcount)
76 call get_slice(var2, count=newmap(1:ndim2)%count)
78 if (map2(j) == 0)
then
81 call inquire(var2, j, url=newmap(j)%url)
85 & newmap(j)%start, newmap(j)%stride)
92 loop1:
do, i = ndim2 + 1, ndimo
95 if (j > ndim1)
exit loop1
96 if (map1(j) <= 0)
exit
99 call inquire(var1, dimord=j, allcount=newmap(i)%allcount)
100 call get_slice(var1, dimord=j, start=newmap(i)%start, &
101 & count=newmap(i)%count, stride=newmap(i)%stride)
109 call endsub(subnam,
'stat=%d', i=(/stat/))
110 deallocate(map1, map2)
119 use gtdata_generic,
only: get, open, close
121 integer,
intent(in):: idim1, idim2
122 integer,
intent(out):: offset, stepfact
125 real,
allocatable:: val1(:), val2(:)
127 call beginsub(
'adjust_slice')
128 call open(var_d, source_var=var1, dimord=idim1, count_compact=.true.)
129 call inquire(var_d, size=n)
131 call get(var_d, val1, n)
134 call open(var_d, source_var=var2, dimord=idim2, count_compact=.true.)
135 call inquire(var_d, size=n)
137 call get(var_d, val2, n)
140 buf(1:1) = minloc(abs(val1(:) - val2(1)))
142 if (
size(val2) < 2 .or.
size(val1) < 2)
then
145 buf(1:1) = minloc(abs(val1(:) - val2(2)))
146 stepfact = buf(1) - (offset + 1)
149 deallocate(val1, val2)
150 call endsub(
'adjust_slice')
157 subroutine getmatch(var1, var2, ndim1, ndim2, map1, map2)
160 use gtdata_generic,
only: get_attr, open, close
162 integer,
intent(in):: ndim1, ndim2
163 integer,
intent(out):: map1(:), map2(:)
165 integer,
allocatable:: map(:, :)
167 character(STRING):: su1, su2
168 type(
units),
allocatable:: u1(:), u2(:)
170 call beginsub(
'getmatch')
175 allocate(map(ndim1, ndim2))
180 allocate(u1(ndim1), u2(ndim2))
182 call open(var_d, var1, i, count_compact=.true.)
183 call get_attr(var_d,
'units', su1)
189 call open(var_d, var2, j, count_compact=.true.)
190 call get_attr(var_d,
'units', su2)
211 if (map_finished(map))
goto 1000
214 call endsub(
'getmatch',
'fail')
219 call dbgmessage(
'map(%d, :)=%*d', i=(/i, map(i,:)/), n=(/ndim2/))
222 if (all(map(i, :) <= 0))
then
225 map1(i:i) = maxloc(map(i, :))
229 if (all(map(:, j) <= 0))
then
232 map2(j:j) = maxloc(map(:, j), dim=1)
235 call endsub(
'getmatch',
'okay')
236 end subroutine getmatch
238 logical function map_finished(map)
result(result)
242 call beginsub(
'map_finished')
243 ni =
size(map, dim=1)
245 if (count(map(i, :) > 0) > 1)
then
251 if (count(map(j, :) > 0) > 1)
then
258 call endsub(
'map_finished')
259 end function map_finished