66 logical,
intent(out),
optional:: err
67 integer:: ndim1, ndim2, ndimo
68 integer,
allocatable:: map1(:), map2(:)
71 character(*),
parameter:: subnam =
"GTVarXformBinary"
73 call beginsub(subnam,
'mapid=[%d, %d]', i=(/var1%mapid, var2%mapid/))
79 if (
present(err)) err = .false.
80 call inquire(var1, alldims=ndim1)
81 call inquire(var2, alldims=ndim2)
82 ndimo = max(ndim1, ndim2, 0)
83 allocate(map1(1:ndim1), map2(1:ndim2))
84 call getmatch(var1, var2, ndim1, ndim2, map1, map2)
85 call dbgmessage(
'map1=%*d map2=%*d', i=(/map1(1:ndim1), map2(1:ndim2)/), n=(/ndim1, ndim2/))
86 if (all(map2(1:ndim2) == 0))
then
93 ndimo = ndim2 + count(map1(1:ndim1) == 0)
98 newmap(1:ndim2)%dimno = map2(1:ndim2)
99 call inquire(var2, allcount=newmap(1:ndim2)%allcount)
100 call get_slice(var2, count=newmap(1:ndim2)%count)
102 if (map2(j) == 0)
then
105 call inquire(var2, j, url=newmap(j)%url)
109 & newmap(j)%start, newmap(j)%stride)
116 loop1:
do, i = ndim2 + 1, ndimo
119 if (j > ndim1)
exit loop1
120 if (map1(j) <= 0)
exit
123 call inquire(var1, dimord=j, allcount=newmap(i)%allcount)
124 call get_slice(var1, dimord=j, start=newmap(i)%start, &
125 & count=newmap(i)%count, stride=newmap(i)%stride)
133 call endsub(subnam,
'stat=%d', i=(/stat/))
134 deallocate(map1, map2)
145 integer,
intent(in):: idim1, idim2
146 integer,
intent(out):: offset, stepfact
149 real,
allocatable:: val1(:), val2(:)
152 call open(var_d, source_var=var1, dimord=idim1, count_compact=.true.)
155 call get(var_d, val1, n)
158 call open(var_d, source_var=var2, dimord=idim2, count_compact=.true.)
161 call get(var_d, val2, n)
164 buf(1:1) = minloc(abs(val1(:) - val2(1)))
166 if (
size(val2) < 2 .or.
size(val1) < 2)
then
169 buf(1:1) = minloc(abs(val1(:) - val2(2)))
170 stepfact = buf(1) - (offset + 1)
173 deallocate(val1, val2)
174 call endsub(
'adjust_slice')
181 subroutine getmatch(var1, var2, ndim1, ndim2, map1, map2)
186 integer,
intent(in):: ndim1, ndim2
187 integer,
intent(out):: map1(:), map2(:)
189 integer,
allocatable:: map(:, :)
191 character(STRING):: su1, su2
192 type(
units),
allocatable:: u1(:), u2(:)
199 allocate(map(ndim1, ndim2))
204 allocate(u1(ndim1), u2(ndim2))
206 call open(var_d, var1, i, count_compact=.true.)
213 call open(var_d, var2, j, count_compact=.true.)
235 if (map_finished(map))
goto 1000
238 call endsub(
'getmatch',
'fail')
243 call dbgmessage(
'map(%d, :)=%*d', i=(/i, map(i,:)/), n=(/ndim2/))
246 if (all(map(i, :) <= 0))
then
249 map1(i:i) = maxloc(map(i, :))
253 if (all(map(:, j) <= 0))
then
256 map2(j:j) = maxloc(map(:, j), dim=1)
259 call endsub(
'getmatch',
'okay')
260 end subroutine getmatch
262 logical function map_finished(map)
result(result)
267 ni =
size(map, dim=1)
269 if (count(map(i, :) > 0) > 1)
then
275 if (count(map(j, :) > 0) > 1)
then
282 call endsub(
'map_finished')
283 end function map_finished
subroutine, public dbgmessage(fmt, i, r, d, l, n, c1, c2, c3, ca)
subroutine, public beginsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca, version)
subroutine, public endsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca)