1pro detect_tk_error, nside, pixel, pixel2, error, legend=legend 2 3if total(abs(pixel2-pixel)) ne 0 then begin 4 np = n_elements(pixel) 5 bad = where(pixel2 ne pixel, nbad) 6 print, 'Nside = ',nside 7 if (defined(legend)) then print, legend 8 print, nbad,' / ',np,' pixels : ' 9 nbad <= 5 10 print, 'In: ',pixel[bad[0:nbad-1]] 11 print, 'Out: ',pixel2[bad[0:nbad-1]] 12 print, 'Diff: ',pixel2[bad[0:nbad-1]]-pixel[bad[0:nbad-1]] 13 error = error + 1 14endif 15return 16end 17; ----------------------------------------------------------------------------- 18; 19; Copyright (C) 1997-2013 Krzysztof M. Gorski, Eric Hivon, Anthony J. Banday 20; 21; 22; 23; 24; 25; This file is part of HEALPix. 26; 27; HEALPix is free software; you can redistribute it and/or modify 28; it under the terms of the GNU General Public License as published by 29; the Free Software Foundation; either version 2 of the License, or 30; (at your option) any later version. 31; 32; HEALPix is distributed in the hope that it will be useful, 33; but WITHOUT ANY WARRANTY; without even the implied warranty of 34; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 35; GNU General Public License for more details. 36; 37; You should have received a copy of the GNU General Public License 38; along with HEALPix; if not, write to the Free Software 39; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 40; 41; For more information about HEALPix see http://healpix.sourceforge.net 42; 43; ----------------------------------------------------------------------------- 44pro test_tk, nside, upix, help=help, random=random 45;+ 46; test_tk [,nside ,upix, help=, random= ] 47; 48; tests the consistency of Healpix toolkit routines (pix2*, ang2*, vec2*, ang2vec, vec2ang) 49; 50; by default, all pixels in 0, Npix-1 are tested (Npix=12*nside*nside) 51; unless upix or random are defined 52; 53; OPTIONAL INPUT 54; nside (default = 32) 55; upix , integer scalar or vector, list of hand-picked pixels 56; 57; KEYWORD 58; HELP= : if set, this information header is printed 59; 60; RANDOM= : float scalar, some pixels (Npix * random + 1) are picked randomly 61; in [0, Npix-1] 62; 63; 64; EXAMPLES: 65; test_tk 66; test_tk, 1024 67; test_tk, 8192, random=1.d-3 68; test_tk, 2L^29, random=1.d-12 69; 70; HISTORY: 71; see test_tk2 for a slightly longer set of tests 72; 2008-03-17: enabled Nside > 8192 73; 2011-08: use detect_tk_error 74; 2017-06: cosmetic editions 75;- 76 77t0 = systime(1) 78routine = 'test_tk' 79syntax = routine+' [nside, upix, HELP=, RANDOM=]' 80 81if keyword_set(help) then begin 82 doc_library,routine 83 return 84endif 85 86if undefined(nside) then nside = 32 87lnside = long(nside) 88 89npix = nside2npix(lnside,err=err_nside) 90snpix = strtrim(string(npix,form='(i20)'),2) 91snpix1 = strtrim(string(npix-1,form='(i20)'),2) 92snside = strtrim(string(nside,form='(i9)'),2) 93 94if (err_nside ne 0) then begin 95 print, syntax 96 print,'Invalid Nside' 97 return 98endif 99 100if defined(random) then begin 101 nr = min([npix, long(npix*random)+1]) 102 print,'Nside = '+snside 103 print,nr,' pixels are picked randomly in [0, '+snpix1+']' 104 if (nside gt 8192) then begin 105 pixel =long64( randomu(seed,nr, /double) * npix ) 106 endif else begin 107 pixel =long( randomu(seed,nr, /double) * npix ) 108 endelse 109 print,min(pixel),max(pixel) 110endif 111if defined(upix) then begin 112 if min(upix) ge 0 and max(upix) lt npix then begin 113 pixel = upix 114 print,'Nside = '+snside 115 print,'test selected pixels in ',min(upix), max(upix) 116 endif else begin 117 print,'invalid choice of pixels' 118 return 119 endelse 120endif 121if undefined(pixel) then begin 122 pixel = lindgen(npix) 123 print,'Nside = '+snside 124 print,'test all pixels in [0, '+snpix1+']' 125endif 126 127error = 0 128 129;-------------------------- 130pix2ang_ring, nside, pixel, theta, phi 131ang2pix_ring, nside, theta, phi, pixel2 132detect_tk_error, nside, pixel, pixel2, error, legend='ERROR: pix <-> ang RING' 133 134 135pix2ang_nest, nside, pixel, theta, phi 136ang2pix_nest, nside, theta, phi, pixel2 137detect_tk_error, nside, pixel, pixel2, error, legend='ERROR: pix <-> ang NEST' 138;--------------------- 139 140pix2vec_ring, nside, pixel, vec 141vec2pix_ring, nside, vec*!DPI, pixel2 142detect_tk_error, nside, pixel, pixel2, error, legend='ERROR: pix <-> vec RING' 143 144pix2vec_nest, nside, pixel, vec 145vec2pix_nest, nside, vec*5.d0, pixel2 146detect_tk_error, nside, pixel, pixel2, error, legend='ERROR: pix <-> vec NEST' 147;--------------------- 148 149ring2nest, nside, pixel, pix_n 150nest2ring, nside, pix_n, pixel2 151detect_tk_error, nside, pixel, pixel2, error, legend='ERROR: NEST <-> RING' 152;--------------------- 153 154 155pix2ang_ring, nside, pixel, theta, phi 156ang2vec, theta, phi, vec 157vec2pix_nest, nside, vec, pixel1 158nest2ring, nside, pixel1, pixel2 159detect_tk_error, nside, pixel, pixel2, error, legend='ERROR: R -> A -> V -> N -> R' 160;--------------------- 161 162pix2vec_ring, nside, pixel, vec 163vec2ang, vec, theta, phi 164ang2pix_nest, nside, theta, phi, pixel1 165nest2ring, nside, pixel1, pixel2 166detect_tk_error, nside, pixel, pixel2, error, legend='ERROR: R -> V -> A -> N -> R' 167;--------------------- 168t1 = systime(1) 169 170if (error eq 0) then begin 171 print, ' -----------------------' 172 print, ' TEST PASSED ('+snside+')' 173 print, ' -----------------------' 174 print, 'Time [s]: ', t1-t0 175endif 176 177return 178end 179