Skip to content

Commit

Permalink
add constants to the q3c_prm structure
Browse files Browse the repository at this point in the history
  • Loading branch information
segasai committed Jul 2, 2024
1 parent 47911f2 commit 7a7037e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 29 deletions.
18 changes: 13 additions & 5 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ typedef long double q3c_coord_t;
#endif

struct q3c_prm
{
const q3c_ipix_t nside;
const q3c_ipix_t *xbits;
const q3c_ipix_t *ybits;
const q3c_ipix_t *xbits1;
const q3c_ipix_t *ybits1;
};
struct q3c_prm_write
{
q3c_ipix_t nside;
q3c_ipix_t *xbits;
Expand Down Expand Up @@ -257,11 +265,11 @@ typedef struct

typedef enum {Q3C_CIRCLE, Q3C_POLYGON, Q3C_ELLIPSE} q3c_region;

void init_q3c(struct q3c_prm *, q3c_ipix_t);
void init_q3c(struct q3c_prm_write *, q3c_ipix_t);

void init_q3c1(struct q3c_prm *, q3c_ipix_t);
void init_q3c1(struct q3c_prm_write *, q3c_ipix_t);

void q3c_dump_prm(struct q3c_prm *,char *);
void q3c_dump_prm(struct q3c_prm_write *,char *);

void q3c_ang2ipix(struct q3c_prm *, q3c_coord_t, q3c_coord_t, q3c_ipix_t *);

Expand Down Expand Up @@ -341,8 +349,8 @@ int q3c_check_sphere_point_in_poly(struct q3c_prm *hprm, int n,

char q3c_get_region_facenum(q3c_region region, void *data);

q3c_ipix_t q3c_xiyi2ipix(q3c_ipix_t nside, q3c_ipix_t *xbits,
q3c_ipix_t *ybits, char face_num,
q3c_ipix_t q3c_xiyi2ipix(const q3c_ipix_t nside, const q3c_ipix_t *xbits,
const q3c_ipix_t *ybits, char face_num,
q3c_ipix_t xi, q3c_ipix_t yi);

void q3c_multi_face_check(q3c_coord_t *xmin0, q3c_coord_t *ymin0,
Expand Down
6 changes: 3 additions & 3 deletions prepare.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
#include "common.h"
int main()
{
struct q3c_prm hprm1;
struct q3c_prm_write hprm1;

init_q3c1(&hprm1,1073741824);
init_q3c1(&hprm1, 1073741824);

q3c_dump_prm(&hprm1,"dump.c");
q3c_dump_prm(&hprm1, "dump.c");

return 0;

Expand Down
49 changes: 28 additions & 21 deletions q3cube.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ void q3c_ang2ipix_xy (struct q3c_prm *hprm, q3c_coord_t ra0, q3c_coord_t dec0,
{
q3c_coord_t x0 = 0, y0 = 0, ra1, dec1, tmp0, td1;
q3c_coord_t ra,dec;
q3c_ipix_t nside = hprm->nside, *xbits = hprm->xbits,
*ybits = hprm->ybits, xi, yi;
const q3c_ipix_t nside = hprm->nside, *xbits = hprm->xbits,
*ybits = hprm->ybits;
q3c_ipix_t xi, yi;
char face_num;

/* We check against crazy right ascensions */
Expand Down Expand Up @@ -561,8 +562,9 @@ void q3c_get_nearby(struct q3c_prm *hprm, q3c_region region, void *region_data,
q3c_ipix_t *ipix)
{
q3c_coord_t xmin, xmax, ymin, ymax, xesize, yesize, points[4];
q3c_ipix_t nside = hprm->nside, *xbits = hprm->xbits, *ybits = hprm->ybits,
*ipix_cur = ipix, ipix0, xi, yi, n0, n1, ixmin,
const q3c_ipix_t nside = hprm->nside, *xbits = hprm->xbits, *ybits = hprm->ybits;

q3c_ipix_t *ipix_cur = ipix, ipix0, xi, yi, n0, n1, ixmin,
ixmax, iymin, iymax, xistack[4], yistack[4], facestack[4],
nstack[4];
char face_num, face_num0, multi_flag;
Expand Down Expand Up @@ -963,8 +965,8 @@ void q3c_get_nearby(struct q3c_prm *hprm, q3c_region region, void *region_data,
/* Converts integer coordinates on cube face to
* ipix number by performing bit interleaving
*/
q3c_ipix_t q3c_xiyi2ipix(q3c_ipix_t nside, q3c_ipix_t *xbits,
q3c_ipix_t *ybits, char face_num,
q3c_ipix_t q3c_xiyi2ipix(const q3c_ipix_t nside, const q3c_ipix_t *xbits,
const q3c_ipix_t *ybits, char face_num,
q3c_ipix_t xi, q3c_ipix_t yi)
{

Expand All @@ -980,8 +982,9 @@ q3c_ipix_t q3c_xiyi2ipix(q3c_ipix_t nside, q3c_ipix_t *xbits,
void q3c_ipix2ang(struct q3c_prm *hprm, q3c_ipix_t ipix,
q3c_coord_t *ra, q3c_coord_t *dec)
{
q3c_ipix_t nside = hprm->nside, ipix1, *xbits1 = hprm->xbits1,
*ybits1 = hprm->ybits1, i2, i3, x0, y0;
const q3c_ipix_t nside = hprm->nside, *xbits1 = hprm->xbits1,
*ybits1 = hprm->ybits1;
q3c_ipix_t ipix1, i2, i3, x0, y0;

q3c_coord_t x, y, ra0;
char face_num = ipix / (nside * nside);
Expand Down Expand Up @@ -1058,8 +1061,9 @@ q3c_coord_t q3c_pixarea(struct q3c_prm *hprm, q3c_ipix_t ipix, int depth)
* In the future I should split the ipix2xy and xy2ang codepaths
* and put them in the separate functions
*/
q3c_ipix_t nside = hprm->nside, ipix1, *xbits1 = hprm->xbits1,
*ybits1 = hprm->ybits1, i2, i3, x0, y0, idx,
const q3c_ipix_t nside = hprm->nside, *xbits1 = hprm->xbits1,
*ybits1 = hprm->ybits1;
q3c_ipix_t ipix1, i2, i3, x0, y0, idx,
ix1, iy1, ix2, iy2;
q3c_coord_t x1, y1, x2, y2, result;
/* char face_num = ipix / (nside * nside);*/
Expand Down Expand Up @@ -1176,7 +1180,7 @@ char q3c_xy2facenum(q3c_coord_t x, q3c_coord_t y, char face_num0)
* hprm -- Pointer to main Q3C structure
* nside -- Nside parameter (number of quadtree subdivisions)
*/
void init_q3c1(struct q3c_prm *hprm, q3c_ipix_t nside)
void init_q3c1(struct q3c_prm_write *hprm, q3c_ipix_t nside)
{
int i, k, m, l;
const q3c_ipix_t nbits = Q3C_INTERLEAVED_NBITS;
Expand Down Expand Up @@ -1290,15 +1294,15 @@ void init_q3c1(struct q3c_prm *hprm, q3c_ipix_t nside)


/* Dump the definitions of main Q3C arrays into a .c file */
void q3c_dump_prm(struct q3c_prm *hprm,char *filename)
void q3c_dump_prm(struct q3c_prm_write *hprm,char *filename)
{
FILE *fp = fopen(filename, "w");
int i, x = 1 << Q3C_INTERLEAVED_NBITS;
q3c_ipix_t *xbits = hprm->xbits, *ybits = hprm->ybits,
*xbits1 = hprm->xbits1, *ybits1 = hprm->ybits1;

fprintf(fp, "#include \"common.h\"\n");
fprintf(fp, "\nq3c_ipix_t ____xbits[%d]={", x);
fprintf(fp, "\nconst q3c_ipix_t ____xbits[%d]={", x);
fprintf(fp, " ");

for(i = 0; i < x; i++)
Expand All @@ -1311,7 +1315,7 @@ void q3c_dump_prm(struct q3c_prm *hprm,char *filename)
}
fprintf(fp, "};");

fprintf(fp, "\nq3c_ipix_t ____ybits[%d]={",x);
fprintf(fp, "\nconst q3c_ipix_t ____ybits[%d]={",x);
fprintf(fp, " ");

for(i = 0; i < x; i++)
Expand All @@ -1324,7 +1328,7 @@ void q3c_dump_prm(struct q3c_prm *hprm,char *filename)
}
fprintf(fp, "};");

fprintf(fp, "\nq3c_ipix_t ____xbits1[%d]={", x);
fprintf(fp, "\nconst q3c_ipix_t ____xbits1[%d]={", x);
fprintf(fp, " ");

for(i = 0; i < x; i++)
Expand All @@ -1337,7 +1341,7 @@ void q3c_dump_prm(struct q3c_prm *hprm,char *filename)
}
fprintf(fp, "};");

fprintf(fp, "\nq3c_ipix_t ____ybits1[%d]={",x);
fprintf(fp, "\nconst q3c_ipix_t ____ybits1[%d]={",x);
fprintf(fp, " ");

for(i = 0; i < x; i++)
Expand All @@ -1350,7 +1354,7 @@ void q3c_dump_prm(struct q3c_prm *hprm,char *filename)
}
fprintf(fp, "};\n");

fprintf(fp, "struct q3c_prm hprm={"
fprintf(fp, "const struct q3c_prm hprm={"
Q3C_IPIX_FMT ",____xbits,____ybits,____xbits1,____ybits1};\n", hprm->nside);
fclose(fp);
}
Expand Down Expand Up @@ -2362,7 +2366,7 @@ void q3c_output_stack( struct q3c_prm *hprm,
{
int i, j;
q3c_ipix_t xi, yi, ipix_tmp1, ipix_tmp2, ntmp1;
q3c_ipix_t *xbits = hprm->xbits, *ybits = hprm->ybits;
const q3c_ipix_t *xbits = hprm->xbits, *ybits = hprm->ybits;

struct q3c_square *cur_square;
/* Run through fully covered squares (we take them from out_stack) */
Expand Down Expand Up @@ -2461,7 +2465,8 @@ void q3c_radial_query(struct q3c_prm *hprm, q3c_coord_t ra0,
xc_cur = 0, yc_cur = 0, cur_size, xesize, yesize,
points[4];

q3c_ipix_t n0, nside = hprm->nside;
q3c_ipix_t n0;
const q3c_ipix_t nside = hprm->nside;

char face_num, multi_flag = 0, face_count, face_num0, full_flags[3] = {0,0,0};
int out_ipix_arr_fulls_pos = 0;
Expand Down Expand Up @@ -2673,7 +2678,8 @@ void q3c_poly_query(struct q3c_prm *hprm, q3c_poly *qp,
xc_cur = 0, yc_cur = 0, cur_size, xesize, yesize,
points[4];

q3c_ipix_t n0, nside = hprm->nside;
q3c_ipix_t n0;
const q3c_ipix_t nside = hprm->nside;

char face_num, multi_flag = 0, face_count, face_num0, large_flag = 0;
int out_ipix_arr_fulls_pos = 0;
Expand Down Expand Up @@ -2854,7 +2860,8 @@ void q3c_ellipse_query(struct q3c_prm *hprm, q3c_coord_t ra0,
yc_cur = 0, cur_size, xesize, yesize,
points[4], axx, ayy, axy, ax, ay, a;

q3c_ipix_t n0, nside = hprm->nside;
q3c_ipix_t n0;
const q3c_ipix_t nside = hprm->nside;

char face_num, multi_flag = 0, face_count, face_num0;
int out_ipix_arr_fulls_pos = 0;
Expand Down

0 comments on commit 7a7037e

Please sign in to comment.