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 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <mach.h>
include <math.h>
include <mwset.h>
include "imwcs.h"
task simple = t_simple,
wcs = t_wcs,
float = t_float,
imtest = t_imtest,
inv = t_inv,
save = t_save,
load = t_load
define SAVELEN 10240
# SIMPLE -- Simple test of the most common interface routines.
procedure t_simple()
pointer mw, ct, bp
int buflen, nchars
real ltm[2,2], ltv[2], x1,y1, x2,y2
pointer mw_open(), mw_sctran()
int mw_save()
begin
call memchk()
mw = mw_open (NULL, 2)
ltm[1,1] = 1.0; ltm[1,2] = 0.0
ltm[2,1] = 0.0; ltm[2,2] = 1.0
ltv[1] = 0.0; ltv[2] = 0.0
call mw_sltermr (mw, ltm, ltv, 2)
ct = mw_sctran (mw, "logical", "physical", 0)
x1 = 0.5; y1 = 0.5
call mw_c2tranr (ct, x1, y1, x2, y2)
call eprintf ("[%g,%g] -> [%g,%g]\n")
call pargr (x1); call pargr (y1)
call pargr (x2); call pargr (y2)
bp = NULL
nchars = mw_save (mw, bp, buflen)
call mw_load (mw, bp)
call eprintf ("save/load, save buflen = %d chars, nchars=%d\n")
call pargi (buflen)
call pargi (nchars)
ct = mw_sctran (mw, "logical", "physical", 0)
x1 = 0.5; y1 = 0.5
call mw_c2tranr (ct, x1, y1, x2, y2)
call eprintf ("[%g,%g] -> [%g,%g]\n")
call pargr (x1); call pargr (y1)
call pargr (x2); call pargr (y2)
call mw_close (mw)
end
# WCS -- Test the creation and use of a world coordinate system.
procedure t_wcs()
pointer mw, ct1, ct2, ct3
real pv[100], wv[100]
real theta, center[2], scale[2], shift[2]
real ltm[3,3], ltv[3], x1,y1, x2,y2
double r[3], w[3], cd[3,3]
double l2m[2,2], l2v_1[2], l2v_2[2], d_theta
int ndim, axes[3], naxes, npts, i
pointer mw_open(), mw_sctran()
real mw_c1tranr()
begin
call memchk()
ndim = 3
# Create a unitary, 3 dim WCS.
mw = mw_open (NULL, ndim)
# Examine the Lterm.
call plterm (mw, ltm, ltv, ndim)
# Apply a transform to the first 2 axes.
d_theta = DEGTORAD(30.0D0)
l2m[1,1] = cos(d_theta); l2m[2,1] = sin(d_theta)
l2m[1,2] = -sin(d_theta); l2m[2,2] = cos(d_theta)
l2v_1[1] = 0.0; l2v_1[2] = 0.0
l2v_2[1] = 10.0; l2v_2[2] = 20.0
#l2v_2[1] = 0.0; l2v_2[2] = 0.0
#call mw_translated (mw, l2v_1, l2m, l2v_2, 2)
theta = d_theta; call aclrr (center, 2)
call mw_rotate (mw, theta, center, 3B)
shift[1] = 10.0; shift[2] = 20.0
call mw_shift (mw, shift, 3B)
scale[1] = 4.0; scale[2] = 0.2
call mw_scale (mw, scale, 3B)
# Examine the Lterm.
call plterm (mw, ltm, ltv, ndim)
# Apply the inverse transform.
d_theta = -d_theta
l2m[1,1] = cos(d_theta); l2m[2,1] = sin(d_theta)
l2m[1,2] = -sin(d_theta); l2m[2,2] = cos(d_theta)
call amovd (l2v_2, l2v_1, 2); call aclrd (l2v_2, 2)
#call mw_translated (mw, l2v_1, l2m, l2v_2, 2)
scale[1] = 1.0/scale[1]; scale[2] = 1.0/scale[2]
call mw_scale (mw, scale, 3B)
shift[1] = -shift[1]; shift[2] = -shift[2]
call mw_shift (mw, shift, 3B)
call mw_rotate (mw, -theta, center, 3B)
# Examine the Lterm.
call plterm (mw, ltm, ltv, ndim)
# Add a WCS.
call mw_newsystem (mw, "sky", 3)
cd[1,1] = .01D0; cd[2,1] = 0; cd[3,1] = 0
cd[1,2] = 0; cd[2,2] = .01D0; cd[3,2] = 0
cd[1,3] = 0; cd[2,3] = 0; cd[3,3] = 1
r[1] = 0; r[2] = 0; r[3] = 0
w[1] = 100; w[2] = 20; w[3] = 0
# Put a tangent projection on axis 1&2.
call mw_swtermd (mw, r, w, cd, ndim)
axes[1] = 1; axes[2] = 2; naxes = 2
call mw_swtype (mw, axes, naxes, "tan",
"axis 1: axtype=ra axis 2: axtype=dec")
# Put a simple sampled curve on axis 3.
call mw_swtype (mw, 3, 1, "sampled", "")
npts = 10
do i = 1, npts {
pv[i] = i
wv[i] = i * 2
}
call mw_swsampr (mw, 3, pv, wv, npts)
# Try a transform on the axis 1-2 plane.
ct1 = mw_sctran (mw, "logical", "sky", 3B)
x1 = 50.0; y1 = -20.0
call mw_c2tranr (ct1, x1,y1, x2,y2)
call eprintf ("[%g,%g]logical -> [%g,%g]sky\n")
call pargr (x1); call pargr (y1)
call pargr (x2); call pargr (y2)
# Check out the reverse transform.
ct2 = mw_sctran (mw, "sky", "logical", 3B)
call mw_c2tranr (ct2, x2,y2, x1,y1)
call eprintf ("[%g,%g]sky -> [%g,%g]logical\n")
call pargr (x2); call pargr (y2)
call pargr (x1); call pargr (y1)
# Try evaluating the sampled axis.
ct3 = mw_sctran (mw, "physical", "sky", 4B)
x1 = 4.5; x2 = mw_c1tranr (ct3, x1)
call eprintf ("axis 3: %gL -> %gS\n")
call pargr (x1)
call pargr (x2)
call mw_close (mw)
end
# PLTERM -- Print the Lterm.
procedure plterm (mw, ltm, ltv, ndim)
pointer mw
real ltm[ndim,ndim]
real ltv[ndim]
int ndim
int i, j
begin
# Examine the Lterm.
call mw_gltermr (mw, ltm, ltv, ndim)
call eprintf ("----- lterm -----\n")
do j = 1, ndim {
do i = 1, ndim {
call eprintf (" %8.3f")
call pargr (ltm[i,j])
}
call eprintf (" : %8.3f\n")
call pargr (ltv[j])
}
end
# IMTEST -- Test the image header WCS save and load facilities.
procedure t_imtest()
double cd[3,3], r[3], w[3]
int ndim, naxes, axes[2], npts, i
pointer mw, ct1, ct2, ct3, im, iw, cp
real theta, center[3], shift[3], scale[3], x1,y1, x2,y2, pv[10], wv[10]
pointer mw_open(), mw_sctran(), immap(), iw_rfits()
real mw_c1tranr()
begin
call memchk()
ndim = 3
# Create a unitary, 3 dim WCS.
mw = mw_open (NULL, ndim)
# Apply a transform to the first 2 axes.
call aclrr (center, 2)
theta = DEGTORAD(30.0D0)
shift[1] = 10.0; shift[2] = 20.0
scale[1] = 4.0; scale[2] = 0.2
call mw_rotate (mw, theta, center, 3B)
call mw_shift (mw, shift, 3B)
call mw_scale (mw, scale, 3B)
# Add a WCS.
call mw_newsystem (mw, "sky", 3)
cd[1,1] = .01D0; cd[2,1] = 0; cd[3,1] = 0
cd[1,2] = 0; cd[2,2] = .01D0; cd[3,2] = 0
cd[1,3] = 0; cd[2,3] = 0; cd[3,3] = 1
r[1] = 0; r[2] = 0; r[3] = 0
w[1] = 100; w[2] = 20; w[3] = 0
# Put a tangent projection on axis 1&2.
call mw_swtermd (mw, r, w, cd, ndim)
axes[1] = 1; axes[2] = 2; naxes = 2
call mw_swtype (mw, axes, naxes, "tan",
"axis 1: axtype=ra axis 2: axtype=dec")
# Put a simple sampled curve on axis 3.
call mw_swtype (mw, 3, 1, "sampled", "")
npts = 10
do i = 1, npts {
pv[i] = i
wv[i] = i * 2
}
call mw_swsampr (mw, 3, pv, wv, npts)
# Evaluate tests 1.
# -----------------
# Try a transform on the axis 1-2 plane.
ct1 = mw_sctran (mw, "logical", "sky", 3B)
x1 = 50.0; y1 = -20.0
call mw_c2tranr (ct1, x1,y1, x2,y2)
call eprintf ("[%g,%g]logical -> [%g,%g]sky\n")
call pargr (x1); call pargr (y1)
call pargr (x2); call pargr (y2)
# Check out the reverse transform.
ct2 = mw_sctran (mw, "sky", "logical", 3B)
call mw_c2tranr (ct2, x2,y2, x1,y1)
call eprintf ("[%g,%g]sky -> [%g,%g]logical\n")
call pargr (x2); call pargr (y2)
call pargr (x1); call pargr (y1)
# Try evaluating the sampled axis.
ct3 = mw_sctran (mw, "physical", "sky", 4B)
x1 = 4.5; x2 = mw_c1tranr (ct3, x1)
call eprintf ("axis 3: %gL -> %gS\n")
call pargr (x1)
call pargr (x2)
# Test image header save/load.
call eprintf ("save WCS in image header...\n")
#iferr (call imdelete ("pix"))
# ;
im = immap ("pix", READ_WRITE, 0)
call mw_saveim (mw, im)
# See what we saved.
call printf ("-------- IMAGE HEADER --------\n")
iw = iw_rfits (mw, im, RF_REFERENCE)
do i = 1, IW_NCARDS(iw) {
cp = IW_CARD(iw,i)
call write (STDOUT, Memc[C_RP(cp)], 80)
call putci (STDOUT, '\n')
}
call iw_cfits (iw)
call printf ("------------------------------\n")
call flush (STDOUT)
# Reload saved header.
call mw_loadim (mw, im)
# Evaluate tests 2.
# -----------------
# Try a transform on the axis 1-2 plane.
ct1 = mw_sctran (mw, "logical", "sky", 3B)
x1 = 50.0; y1 = -20.0
call mw_c2tranr (ct1, x1,y1, x2,y2)
call eprintf ("[%g,%g]logical -> [%g,%g]sky\n")
call pargr (x1); call pargr (y1)
call pargr (x2); call pargr (y2)
# Check out the reverse transform.
ct2 = mw_sctran (mw, "sky", "logical", 3B)
call mw_c2tranr (ct2, x2,y2, x1,y1)
call eprintf ("[%g,%g]sky -> [%g,%g]logical\n")
call pargr (x2); call pargr (y2)
call pargr (x1); call pargr (y1)
# Try evaluating the sampled axis.
ct3 = mw_sctran (mw, "physical", "sky", 4B)
x1 = 4.5; x2 = mw_c1tranr (ct3, x1)
call eprintf ("axis 3: %gL -> %gS\n")
call pargr (x1)
call pargr (x2)
call mw_close (mw)
end
# INV -- Test matrix inversion.
procedure t_inv()
int i, j
double a[3,3], b[3,3], c[3,3]
long seed, clktime()
real urand()
begin
# Construct the identity matrix.
do i = 1, 3 {
do j = 1, 3
a[i,j] = 0.0
a[i,i] = 1.0
}
# Invert the matrix.
call mw_invertd (a, b, 3)
# Print the inverse.
call printf ("inverse of identity matrix:\n")
do i = 1, 3 {
do j = 1, 3 {
call printf (" %20.*f")
call pargi (NDIGITS_DP)
call pargd (b[i,j])
}
call printf ("\n")
}
# Compute a random matrix.
seed = clktime(0)
do i = 1, 3
do j = 1, 3
a[i,j] = urand (seed)
# Invert the matrix.
call mw_invertd (a, b, 3)
call mw_invertd (b, c, 3)
# Print the difference of the original and the inverted inverse.
call printf ("difference of inverse of random matrix:\n")
do i = 1, 3 {
do j = 1, 3 {
call printf (" %20.*f")
call pargi (NDIGITS_DP)
call pargd (a[i,j] - c[i,j])
}
call printf ("\n")
}
end
# SAVE -- Save a test WCS to a file.
procedure t_save()
pointer mw, bp
double cd[3,3], r[3], w[3]
int ndim, naxes, axes[2], npts, buflen, nchars, fd, i
real theta, center[3], shift[3], scale[3], pv[10], wv[10]
int open(), mw_save
pointer mw_open()
begin
ndim = 3
# Create a unitary, 3 dim WCS.
mw = mw_open (NULL, ndim)
# Apply a transform to the first 2 axes.
call aclrr (center, 2)
theta = DEGTORAD(30.0D0)
shift[1] = 10.0; shift[2] = 20.0
scale[1] = 4.0; scale[2] = 0.2
call mw_rotate (mw, theta, center, 3B)
call mw_shift (mw, shift, 3B)
call mw_scale (mw, scale, 3B)
# Add a WCS.
call mw_newsystem (mw, "sky", 3)
cd[1,1] = .01D0; cd[2,1] = 0; cd[3,1] = 0
cd[1,2] = 0; cd[2,2] = .01D0; cd[3,2] = 0
cd[1,3] = 0; cd[2,3] = 0; cd[3,3] = 1
r[1] = 0; r[2] = 0; r[3] = 0
w[1] = 100; w[2] = 20; w[3] = 0
# Put a tangent projection on axis 1&2.
call mw_swtermd (mw, r, w, cd, ndim)
axes[1] = 1; axes[2] = 2; naxes = 2
call mw_swtype (mw, axes, naxes, "tan",
"axis 1: axtype=ra axis 2: axtype=dec")
# Put a simple sampled curve on axis 3.
call mw_swtype (mw, 3, 1, "sampled", "")
npts = 10
do i = 1, npts {
pv[i] = i
wv[i] = i * 2
}
call mw_swsampr (mw, 3, pv, wv, npts)
# Display the new WCS.
call mw_show (mw, STDOUT, 0)
# Save to a file.
bp = NULL; buflen = 0
nchars = mw_save (mw, bp, buflen)
fd = open ("mwcs.sav", NEW_FILE, BINARY_FILE)
call write (fd, Memc[bp], nchars)
call close (fd)
call mfree (bp, TY_CHAR)
call mw_close (mw)
end
# LOAD -- Load a test WCS from a file.
procedure t_load()
pointer mw, bp
int fd, nchars
char fname[SZ_FNAME]
int open(), read()
pointer mw_open()
begin
call clgstr ("savefile", fname, SZ_FNAME)
call malloc (bp, SAVELEN, TY_CHAR)
# Open and read save file.
fd = open (fname, READ_ONLY, BINARY_FILE)
nchars = read (fd, Memc[bp], SAVELEN)
call printf ("read %d chars from %s\n")
call pargi (nchars)
call pargstr (fname)
mw = mw_open (NULL, 3)
call mw_load (mw, bp)
# Display the new WCS.
call mw_show (mw, STDOUT, 0)
call mw_close (mw)
call mfree (bp, TY_CHAR)
end
# FLOAT -- Test single to double conversions.
procedure t_float()
real r
double x
begin
x = sin(0.34567D0)
r = 1.0
call achtrd (r, x, 1)
call printf ("x = %g\n")
call pargd (x)
end
# MEMCHK -- Enable runtime dynamic memory verification. System dependent,
# should be commented out unless a Fortran callable MEMVER is available for
# linking.
procedure memchk()
begin
# call memver (2)
end
|