1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
program testunitnormmap
implicit none
include 'AST_PAR'
include 'SAE_PAR'
integer status, map, cmpmap, smap, invmap, nin, i
logical good, differ
double precision norm, frompos(3), centre(3), topos(4)
data centre /-1.0D0, 1.0D0, 2.0D0 /,
: frompos /-22.0D0, 3.0D0, 0.5D0/
status = sai__ok
call err_mark( status )
call ast_begin( status )
do nin = 1, 3
map = ast_unitnormmap( nin, centre, ' ', status )
if( .not. ast_isaunitnormmap( map, status ) )
: call stopit( status, 'Error 1' )
if( .not. ast_isamapping( map, status ) )
: call stopit( status, 'Error 2' )
if( ast_geti( map, 'Nin', status ) .ne. nin )
: call stopit( status, 'Error 3' )
if( ast_geti( map, 'Nout', status ) .ne. nin+1 )
: call stopit( status, 'Error 4' )
if( ast_getl( map, 'IsLinear', status ) )
: call stopit( status, 'Error 5' )
call checkdump( map, status )
call checkroundtrip( map, frompos, good, status )
if( .not. good ) call stopit( status, 'Error 6' )
call checkroundtrip( map, centre, good, status )
if( .not. good ) call stopit( status, 'Error 6' )
invmap = ast_copy( map, status )
call ast_invert( invmap, status )
cmpmap = ast_cmpmap( map, invmap, .true., ' ', status )
smap = ast_simplify( cmpmap, status )
if( .not. ast_isaunitmap( smap, status ) )
: call stopit( status, 'Error 7' )
if( ast_geti( smap, 'Nin', status ) .ne. nin )
: call stopit( status, 'Error 8' )
cmpmap = ast_cmpmap( invmap, map, .true., ' ', status )
smap = ast_simplify( cmpmap, status )
if( .not. ast_isaunitmap( smap, status ) )
: call stopit( status, 'Error 9' )
if( ast_geti( smap, 'Nin', status ) .ne. nin+1 )
: call stopit( status, 'Error 10' )
call ast_trann( map, 1, nin, 1, frompos, .true., nin+1,
: 1, topos, status );
norm = 0.0D0
do i = 1, nin
norm = norm + (frompos(i)-centre(i))**2
end do
norm = sqrt( norm )
if( differ( norm, topos(nin+1) ) )
: call stopit( status, 'Error 11' )
do i = 1, nin
if( differ( norm*topos(i), frompos(i)-centre(i) ) )
: call stopit( status, 'Error 12' )
end do
end do
call testsimplify( status )
call ast_end( status )
call err_rlse( status )
c call ast_activememory( 'testunitnormmap' )
call ast_flushmemory( 1 )
if( status .eq. sai__ok ) then
write(*,*) 'All UnitNormMap tests passed'
else
write(*,*) 'UnitNormMap tests failed'
end if
end
subroutine stopit( status, text )
implicit none
include 'SAE_PAR'
integer status
character text*(*)
if( status .ne. sai__ok ) return
status = sai__error
write(*,*) text
end
subroutine checkdump( obj, status )
implicit none
include 'SAE_PAR'
include 'AST_PAR'
integer obj, status, stat, ch, result, nin, i
logical differ
double precision in(3), out1(3), out2(3)
data in /10.0D0, 5.0D0, -12.0D0 /
if( status .ne. sai__ok ) return
ch = ast_channel( AST_NULL, AST_NULL, 'SinkFile=testdmp', status )
if( ast_write( ch, obj, status ) .ne.1 ) then
call stopit( status, 'Cannot write supplied object to '//
: 'channel' )
end if
call ast_clear( ch, 'SinkFile', status )
call ast_setc( ch, 'SourceFile', 'testdmp', status )
result = ast_read( ch, status )
if( result .eq. ast__null ) then
call stopit( status, 'Cannot read object from channel' )
end if
if( .not. ast_isaunitnormmap( result, status ) ) then
call stopit( status, 'Object read from channel is not a '//
: 'UnitNormMap')
else if( ast_geti( result, 'Nin', status ) .ne.
: ast_geti( obj, 'Nin', status ) ) then
call stopit( status, 'UnitNormMap have different Nin values' )
else
nin = ast_geti( result, 'Nin', status )
call ast_trann( result, 1, nin, 1, in, .TRUE., nin+1, 1, out1,
: status );
call ast_trann( obj, 1, nin, 1, in, .TRUE., nin+1, 1, out2,
: status );
do i = 1, nin
if( differ( out2(i), out1(i) ) )
: call stopit( status, 'Error - Recovered UnitNormMap '//
: 'differs from suppled UnitNormMap' )
end do
end if
call ast_annul( result, status )
open( unit=1234, iostat=stat, file='testdmp', status='old')
if (stat == 0) close(1234, status='delete')
end
subroutine checkroundtrip( map, pos, good, status )
implicit none
include 'SAE_PAR'
include 'AST_PAR'
logical good, differ
integer status, map, mapinv, cmp, i, nin, nout
double precision pos(*), rtol, atol, out(7), in(7)
good = .true.
if( status .ne. sai__ok ) return
nin = ast_geti( map, 'Nin', status )
nout = ast_geti( map, 'Nout', status )
call ast_trann( map, 1, nin, 1, pos, .TRUE., nout, 1, out,
: status );
call ast_trann( map, 1, nout, 1, out, .FALSE., nin, 1, in,
: status );
do i = 1, nin
if( differ( in(i), pos(i) ) ) good = .false.
end do
mapinv = ast_copy( map, status )
call ast_invert( mapinv, status )
cmp = ast_cmpmap( map, mapinv, .TRUE., ' ', status )
call ast_trann( cmp, 1, nin, 1, pos, .true., nin, 1, in,
: status );
do i = 1, nin
if( differ( in(i), pos(i) ) ) good = .false.
end do
end
subroutine testsimplify( status )
implicit none
include 'SAE_PAR'
include 'AST_PAR'
integer status, unm1, unm1inv, unm2, unm2inv, shiftmap,
: winmap1, winmap2, i, j, k, nin, nout, cmpmap,
: cmpmap_simp
double precision centre1(3)
double precision centre2(3)
double precision shift(3)
double precision zeros(3)
double precision ones(3)
double precision a(3)
double precision testpoints(3,4)
double precision outpoints(3,4)
double precision outpoints_simp(3,4)
integer map1(7), map2(7)
character class(7)*30
logical differ
data centre1 /2.0D0, -1.0D0, 0.0D0/,
: centre2 /-1.0D0, 6.0D0, 4.0D0/,
: shift /3.0D0, 7.0D0, -9.0D0/,
: zeros /0.0D0, 0.0D0, 0.0D0/,
: ones /1.0D0, 1.0D0, 1.0D0/,
: testpoints / 1.0D0, 3.0D0, -5.0D0, 2.0D0, 3.0D0, 99.0D0,
: -6.0D0, -5.0D0, -7.0D0, 30.0D0, 21.0D0, 37.0D0 /
if( status .ne. sai__ok ) return
unm1 = ast_unitnormmap( 3, centre1, ' ', status )
unm1inv = ast_copy( unm1, status )
call ast_setl( unm1inv, 'Invert', .TRUE., status )
unm2 = ast_unitnormmap( 3, centre2, ' ', status )
unm2inv = ast_copy( unm2, status )
call ast_setl( unm2inv, 'Invert', .TRUE., status )
shiftmap = ast_shiftmap(3, shift, ' ', status )
do i = 1, 3
a(i) = ones(i) + shift(i)
end do
winmap1 = ast_winmap( 3, zeros, shift, ones, a, ' ', status )
do i = 1, 3
a(i) = 2*ones(i) + shift(i)
end do
winmap2 = ast_winmap( 3, zeros, shift, ones, a, ' ', status )
map1(1) = unm1
map2(1) = unm2inv
class(1) = 'WinMap'
map1(2) = shiftmap
map2(2) = unm2
class(2) = 'UnitNormMap'
map1(3) = winmap1
map2(3) = unm1
class(3) = 'UnitNormMap'
map1(4) = winmap2
map2(4) = unm1
class(4) = 'CmpMap'
map1(5) = unm1inv
map2(5) = shiftmap
class(5) = 'UnitNormMap'
map1(6) = unm1inv
map2(6) = winmap1
class(6) = 'UnitNormMap'
map1(7) = unm1inv
map2(7) = winmap2
class(7) = 'CmpMap'
do i = 1, 7
cmpmap = ast_cmpmap( map1(i), map2(i), .true., ' ', status )
cmpmap_simp = ast_simplify( cmpmap, status )
if( ast_getc( cmpmap_simp, 'Class', status ) .ne. class(i) )
: call stopit( status, 'Simplify error 1' )
nin = ast_geti( cmpmap, 'Nin', status )
if( nin .ne. ast_geti( cmpmap_simp, 'Nin', status ) )
: call stopit( status, 'Simplify error 2' )
nout = ast_geti( cmpmap, 'Nout', status )
if( nout .ne. ast_geti( cmpmap_simp, 'Nout', status ) )
: call stopit( status, 'Simplify error 3' )
call ast_trann( cmpmap, 3, nin, 3, testpoints, .true., nout,
: 3, outpoints, status )
call ast_trann( cmpmap_simp, 3, nin, 3, testpoints, .true.,
: nout, 3, outpoints_simp, status )
do j = 1, nout
do k = 1, 3
if( differ( outpoints(k,j), outpoints_simp(k,j) ) )
: call stopit( status, 'Simplify error 4' )
end do
end do
end do
end
logical function differ( aa, bb )
implicit none
double precision aa, bb, diff
differ = abs( (aa) - (bb) ) .gt.
: abs( 0.5D0*( (aa) + (bb) ) )*1.0D-14
end
|