/*+++++++++
.Header		qbox.h
.LANGUAGE	C
.AUTHOR		Francois Ochsenbein [ESO-IPG]
.KEYWORDS	Coordinate Indexing
.COMMENTS	This header contains declarations for mathematical functions 
		and macros for spherical coordinate indexing.

.VERSION 1.0	28-Dec-1998
.VERSION 2.0	25-Jan-2005
----------------*/

#ifndef  QBOX_DEF
#define  QBOX_DEF	0

#define DEF_tr_uu
int tr_uu();
#include <trigo.h>		/* Use system Math Library */

#ifndef _ARGS
#ifdef __STDC__
#define _ARGS(A)	A       /* ANSI */
#else
#define _ARGS(A)	()      /* Traditional */
#define const
#endif
#endif

/*=========================================================================
		1. Constants
 *=========================================================================*/

#define QBOX_NONE	0	/* No object can be convenient 		*/
#define QBOX_ANY	(-1)	/* Any object is OK (no need to test)	*/
#define QBOX_SOME	1	/* Test must be performed		*/

/*=========================================================================
		2. Functions
 *=========================================================================*/

typedef int (*QBOX_ActionRoutine)_ARGS((int qboxno, int status));

	/* a) COOCUBE routines (projections onto 6 faces)	*/

int	tr_pu6 _ARGS((double proj[2], double u[3], int face_no));
int	tr_up6 _ARGS((double u[3], double proj[2], int face_no));

	/* b) Define the Level of Cells	*/

int	qbox_set _ARGS((int level));
int	qbox_get _ARGS((void));
char   *qbox2a  _ARGS((int qboxno)) ;
char   *qbox8a  _ARGS((int qboxno, char *buf8)) ;
int     qbox_a  _ARGS((char *str));

	/* c) Compute Cell Number	*/

int	qbox_o	 _ARGS((double opos[2]));
int	qbox_u	 _ARGS((double u[3]));
int	qbox__o	 _ARGS((int lev, double opos[2]));
int	qbox__u	 _ARGS((int lev, double u[3]));

	/* d) Derivative of Cell Number: tell center of qbox, radius...	*/

int	qbox_level  _ARGS((int qboxno));
int	qbox_face   _ARGS((int qboxno));	/* Returns 1..6	*/
int	qbox_lower  _ARGS((int qboxno)); 	/* Smallest box number */
int	qbox_upper  _ARGS((int qboxno)); 	/* Largest  box number */
double	qbox_radius _ARGS((int qboxno));	/* Exact radius */
double	qbox_size   _ARGS((int qboxno));	/* Box length   */
double	qbox_radmax _ARGS((int qboxno));	/* Upper limit  */
double	qbox_surf   _ARGS((int qboxno));
int	qbox_co	    _ARGS((int qboxno, double o_qbox_center[2]));
int	qbox_cu	    _ARGS((int qboxno, double u_qbox_center[3]));
int	qbox_cp	    _ARGS((int qboxno, double proj_qbox_center[2]));
int	qbox_limp   _ARGS((int qboxno, double *pmin, double *pmax));
int	qbox_limu   _ARGS((int qboxno, double *umin, double *umax));

	/* e) Locate nearby cells	*/
int	qbox_adj    _ARGS((int qboxno, int dir /* (0123)=(+x,+y,-y,-x)*/));
int	qbox_nearby _ARGS((int qboxno, int *nearby_8));
int     qbox_around _ARGS((double uc[3], int *contig_9, double *sin2r2_9));

	/* f) Selection of Cells	*/

QBOX_ActionRoutine qbox_act _ARGS((QBOX_ActionRoutine));
			/* Select from (center, radius)	*/
int	qbox_or      _ARGS((double o[2], double radius));
int	qbox_ur      _ARGS((double u[3], double radius));
int	qbox_ob      _ARGS((double o[2], double boxy[2]));
int	qbox_obrot   _ARGS((double o[2], double boxy[2], 
				double togal_matrix[3][3]));
			/* Select from limits in 1 pos	*/
int	qbox_ra      _ARGS((double ra_range[2]));
int	qbox_dec     _ARGS((double dec_range[2]));
int	qbox_lon     _ARGS((double lon_range[2], double togal_matrix[3][3]));
int	qbox_lat     _ARGS((double lat_range[2], double togal_matrix[3][3]));
			/* Select from limits in 2 pos	*/
int	qbox_radec   _ARGS((double  ra[2], double dec[2]));
int	qbox_lonlat  _ARGS((double lon[2], double lat[2], double rm[3][3]));

#endif

