H3C HEALPix library for PostgreSQL  (version 1.2)
h3c_util.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 Gilles Landais (CDS)
3 
4  Author: Gilles Landais, Strasbourg astronomical Data Center (CDS)
5  Email: gilles.landais@unistra.fr
6 
7  This file is part of H3C.
8 
9  H3C is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13 
14  H3C is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with H3C; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23 
32 #ifndef H3C_UTIL_H
33 #define H3C_UTIL_H
34 
35 /* define nside */
36 #ifndef H3C_DEFAULT_NSIDE
37 #define H3C_DEFAULT_NSIDE 32768
38 #endif
39 
40 /* define number of blocks used for cone search */
41 #ifndef H3C_DEFAULT_MEM_BLOCK
42 #define H3C_DEFAULT_MEM_BLOCK 100
43 #endif
44 
45 /* define number of blocks used for xmatch */
46 #ifndef H3C_DEFAULT_NEARBY_MEM_BLOCK
47 #define H3C_DEFAULT_NEARBY_MEM_BLOCK 8
48 #endif
49 
50 /* define the maximum of ipix memorized */
51 #ifndef H3C_DEFAULT_MAX_IPIX
52 #define H3C_DEFAULT_MAX_IPIX 2000000
53 #endif
54 
55 #define H3C_DEBUG DEBUG1
56 #define H3C_INFO INFO
57 #define H3C_ERROR ERROR
58 
59 #define H3C_STEP_ALLOC 50
60 #define H3C_LIST(a,n) n = H3C_STEP_ALLOC; \
61 a = (h3c_ipix_t *)malloc(sizeof(h3c_ipix_t)*H3C_STEP_ALLOC);
62 #define H3C_PUSH(a,b,c,val) if ((++b)%H3C_STEP_ALLOC == 0){\
63 if (c > H3C_DEFAULT_MAX_IPIX) h3c_log(H3C_ERROR, "too much ipix: abort");\
64 c += H3C_STEP_ALLOC; a=(h3c_ipix_t*)realloc(a, sizeof(h3c_ipix_t)*c);}\
65 (a)[(b)-1] = val;
66 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70  /* function's declarations */
71  void h3c_debug_init_clock();
72  void h3c_log(int level, char *fmt, ...);
73  h3c_coord_t h3c_theta2dec(h3c_coord_t);
74  h3c_coord_t h3c_dec2theta(h3c_coord_t);
75  h3c_coord_t h3c_phi2ra(h3c_coord_t);
76  h3c_coord_t h3c_ra2phi(h3c_coord_t);
77  int h3c_order(int nside);
78  h3c_ipix_t h3c_npix(int nside);
79  h3c_coord_t h3c_radius(int nside);
80 
81  int h3c_get_order_old(int nside);
82  int h3c_number_ipix_old(int nside);
83  h3c_coord_t h3c_radius_old(int nside);
84 
85  h3c_ipix_t *h3c_disk_ipix(h3c_coord_t, h3c_coord_t, h3c_coord_t, int, int *) ;
86  int h3c_disk_ipix_it(h3c_coord_t, h3c_coord_t, h3c_coord_t, int, h3c_ipix_t *, int);
87  h3c_coord_t h3c_dist(h3c_coord_t, h3c_coord_t, h3c_coord_t, h3c_coord_t);
88  h3c_coord_t h3c_sindist(h3c_coord_t, h3c_coord_t, h3c_coord_t, h3c_coord_t);
89  h3c_ipix_t *h3c_polygon_ipix(h3c_coord_t *, h3c_coord_t *, int, int, int *);
90  int h3c_polygon_ipix_it(h3c_coord_t *, h3c_coord_t *, int, int, h3c_ipix_t *, int);
91  char h3c_in_ellipse(h3c_coord_t, h3c_coord_t, h3c_coord_t, h3c_coord_t, h3c_coord_t, h3c_coord_t, h3c_coord_t);
92  int h3c_poly_is_convex(int n, h3c_coord_t *, h3c_coord_t *);
93  int h3c_check_sphere_circle_intersect_poly(int n, h3c_coord_t in_ra[], h3c_coord_t in_dec[],
94  h3c_coord_t ra0, h3c_coord_t dec0, h3c_coord_t radius);
96  h3c_coord_t in_ra1[],
97  h3c_coord_t in_dec1[],
98  int n2,
99  h3c_coord_t in_ra2[],
100  h3c_coord_t in_dec2[]);
101  h3c_coord_t h3c_polygon_area(h3c_coord_t *in_ra, h3c_coord_t *in_dec, int n);
102  void h3c_box_2_polygon(h3c_coord_t in_ra, h3c_coord_t in_dec,
103  h3c_coord_t width, h3c_coord_t height,
104  h3c_coord_t poly_ra[4], h3c_coord_t poly_dec[4]);
105  void h3c_pix2ang_nest(long nside, h3c_ipix_t ipnest, h3c_coord_t *theta, h3c_coord_t *phi);
106  void h3c_ang2pix_nest(long nside, h3c_coord_t theta, h3c_coord_t phi, h3c_ipix_t *ipnest);
107  void h3c_ring2nest(long nside, h3c_ipix_t ipring, h3c_ipix_t *ipnest);
108 
109  h3c_ipix_t *h3c_query_disc (h3c_coord_t ra, h3c_coord_t dec, h3c_coord_t radius, int nside, int *count);
110 #ifdef __cplusplus
111 }
112 #endif
113 
114 
115 #endif
116 
117 
h3c_npix
h3c_ipix_t h3c_npix(int nside)
get the number of ipix in the entire sphere
Definition: h3c_util.c:194
h3c_check_poly_intersect_poly
int h3c_check_poly_intersect_poly(int n1, h3c_coord_t in_ra1[], h3c_coord_t in_dec1[], int n2, h3c_coord_t in_ra2[], h3c_coord_t in_dec2[])
check if a polygon intersects a vertex of an other polygon
Definition: h3c_poly_more.c:575
h3c_in_ellipse
char h3c_in_ellipse(h3c_coord_t, h3c_coord_t, h3c_coord_t, h3c_coord_t, h3c_coord_t, h3c_coord_t, h3c_coord_t)
verify if a point is inside an ellipse
Definition: h3c_util.c:615
h3c_sindist
h3c_coord_t h3c_sindist(h3c_coord_t, h3c_coord_t, h3c_coord_t, h3c_coord_t)
calculate the sinus distance (to be compatible with Q3C)
Definition: h3c_util.c:486
h3c_order
int h3c_order(int nside)
get the order from the nside number
Definition: h3c_util.c:173
h3c_radius
h3c_coord_t h3c_radius(int nside)
get the max radius of ipix for a given nside
Definition: h3c_util.c:204
h3c_check_sphere_circle_intersect_poly
int h3c_check_sphere_circle_intersect_poly(int n, h3c_coord_t in_ra[], h3c_coord_t in_dec[], h3c_coord_t ra0, h3c_coord_t dec0, h3c_coord_t radius)
check if a circle intersects a vertex of a polygon
Definition: h3c_poly_more.c:320
h3c_polygon_area
h3c_coord_t h3c_polygon_area(h3c_coord_t *in_ra, h3c_coord_t *in_dec, int n)
calculate the area of a polygon
Definition: h3c_poly_more.c:649
h3c_theta2dec
h3c_coord_t h3c_theta2dec(h3c_coord_t)
get the declination from the theta value
Definition: h3c_util.c:125
h3c_polygon_ipix
h3c_ipix_t * h3c_polygon_ipix(h3c_coord_t *, h3c_coord_t *, int, int, int *)
retrieve the ipix list for a polygon
Definition: h3c_poly_more.c:426
h3c_dec2theta
h3c_coord_t h3c_dec2theta(h3c_coord_t)
get the theta value from the declination
Definition: h3c_util.c:136
h3c_debug_init_clock
void h3c_debug_init_clock()
initalize the debugger timer
Definition: h3c_util.c:114
h3c_disk_ipix
h3c_ipix_t * h3c_disk_ipix(h3c_coord_t, h3c_coord_t, h3c_coord_t, int, int *)
(c++ interface) get the ipix list of a cone
Definition: h3c_util.c:225
h3c_poly_is_convex
int h3c_poly_is_convex(int n, h3c_coord_t *, h3c_coord_t *)
verify if the polygon is convex
Definition: h3c_poly_more.c:220
h3c_dist
h3c_coord_t h3c_dist(h3c_coord_t, h3c_coord_t, h3c_coord_t, h3c_coord_t)
calculate the distance between 2 points
Definition: h3c_util.c:460
h3c_log
void h3c_log(int level, char *fmt,...)
print statistics
Definition: h3c_util.c:57
h3c_ra2phi
h3c_coord_t h3c_ra2phi(h3c_coord_t)
get the phi value from the right ascension
Definition: h3c_util.c:161
h3c_phi2ra
h3c_coord_t h3c_phi2ra(h3c_coord_t)
get the right ascension from the phi value
Definition: h3c_util.c:149