-
Notifications
You must be signed in to change notification settings - Fork 5
/
mk_pix2xy.c
94 lines (85 loc) · 2.47 KB
/
mk_pix2xy.c
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
/* -----------------------------------------------------------------------------
*
* Copyright (C) 1997-2010 Krzysztof M. Gorski, Eric Hivon,
* Benjamin D. Wandelt, Anthony J. Banday,
* Matthias Bartelmann,
* Reza Ansari & Kenneth M. Ganga
*
*
* This file is part of HEALPix.
*
* HEALPix is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* HEALPix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HEALPix; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* For more information about HEALPix see http://healpix.jpl.nasa.gov
*
*----------------------------------------------------------------------------- */
/* mk_pix2xy.c
*
*/
/* Standard Includes */
#include <math.h>
#include "chealpix.h"
void
mk_pix2xy(int *pix2x, int *pix2y)
{
/*
* =======================================================================
* subroutine mk_pix2xy
* =======================================================================
* constructs the array giving x and y in the face from pixel number for
* the nested (quad-cube like) ordering of pixels
*
* the bits corresponding to x and y are interleaved in the pixel number
* one breaks up the pixel number by even and odd bits
* =======================================================================
*/
int i,
kpix,
jpix,
IX,
IY,
IP,
ID;
for (i = 0; i < 1023; i++)
pix2x[i] = 0;
for (kpix = 0; kpix < 1024; kpix++)
{
jpix = kpix;
IX = 0;
IY = 0;
IP = 1;
//!bit position(in x and y)
while (jpix != 0)
{
//!go through all the bits
ID = (int) fmod(jpix, 2);
//!bit value(in kpix), goes in ix
jpix = jpix / 2;
IX = ID * IP + IX;
ID = (int) fmod(jpix, 2);
//!bit value(in kpix), goes in iy
jpix = jpix / 2;
IY = ID * IP + IY;
IP = 2 * IP;
//!next bit(in x and y)
}
pix2x[kpix] = IX;
//!in 0, 31
pix2y[kpix] = IY;
//!in 0, 31
}
/* Later */
return;
}