1 /*
2  				fitscat_defs.h
3 
4 *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 *
6 *	Part of:	The LDAC Tools
7 *
8 *	Author:		E.BERTIN, DeNIS/LDAC
9 *
10 *	Contents:	Simplified version of the LDACTools: internal defs
11 *
12 *	Last modify:	16/08/2004
13 *
14 *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15 */
16 
17 /* Check if we are using a configure script here */
18 #ifndef HAVE_CONFIG_H
19 #define		VERSION		"2.0"
20 #define		DATE		"2003-x-x"
21 #define		HAVE_SYS_MMAN_H	1
22 #endif
23 
24 /*------------------------ what, who, when and where ------------------------*/
25 
26 #define		BANNER		"LDACTools"
27 #define		COPYRIGHT	"Emmanuel BERTIN (bertin@iap.fr)"
28 #define		INSTITUTE	"IAP/Leiden"
29 
30 
31 /*----------------------------- External constants --------------------------*/
32 
33 extern int	bswapflag;		/* != 0 if bytes are swapped/IEEE */
34 
35 /*----------------------------- Internal constants --------------------------*/
36 
37 #define	OUTPUT		stdout		/* where all msgs are sent */
38 #define	KBYTE		1024		/* 1 kbyte! */
39 #define	MBYTE		(1024*KBYTE)	/* 1 Mbyte! */
40 #define	GBYTE		(1024*MBYTE)	/* 1 Gbyte! */
41 #define	DATA_BUFSIZE	(4*MBYTE)	/* data buffer size for I/O's */
42 #define	BODY_DEFRAM	(256*MBYTE)	/* a fair number by 1999 standards */
43 #define	BODY_DEFVRAM	(1.9*GBYTE)	/* a fair number by 1999 standards */
44 #define	BODY_DEFSWAPDIR	"/tmp"		/* OK at least for Unix systems */
45 
46 #define	BIG		1e+30		/* a huge number */
47 #ifndef PI
48 #define	PI		3.14159265359	/* never met before? */
49 #endif
50 
51 /* NOTES:
52 We must have:		MAXCHARS >= 16
53 			DATA_BUFSIZE >= 2 although DATA_BUFSIZE >= 100000
54 					  is better!!
55 */
56 
57 /*--------------------- in case of missing constants ------------------------*/
58 
59 #ifndef         SEEK_SET
60 #define         SEEK_SET        0
61 #endif
62 #ifndef         SEEK_CUR
63 #define         SEEK_CUR        1
64 #endif
65 
66 #ifndef	EXIT_SUCCESS
67 #define	EXIT_SUCCESS		0
68 #endif
69 #ifndef	EXIT_FAILURE
70 #define	EXIT_FAILURE		-1
71 #endif
72 
73 /*--------------------------------- typedefs --------------------------------*/
74 typedef	unsigned char	BYTE;			/* a byte */
75 typedef	int		LONG;			/* for DEC-Alpha... */
76 
77 /*------------------------------- Other Macros -----------------------------*/
78 
79 #if _LARGEFILE_SOURCE
80 #define	FSEEKO	fseeko
81 #define	FTELLO	ftello
82 #else
83 #define	FSEEKO	fseek
84 #define	FTELLO	ftell
85 #endif
86 
87 #define QFREAD(ptr, size, file, fname) \
88 		{if (fread(ptr, (size_t)(size), (size_t)1, file)!=1) \
89 		  error(EXIT_FAILURE, "*Error* while reading ", fname);;}
90 
91 #define QFWRITE(ptr, size, file, fname) \
92 		{if (fwrite(ptr, (size_t)(size), (size_t)1, file)!=1) \
93 		   error(EXIT_FAILURE, "*Error* while writing ", fname);;}
94 
95 #define	QFSEEK(file, offset, pos, fname) \
96 		{if (FSEEKO(file, offset, pos)) \
97 		   error(EXIT_FAILURE,"*Error*: File positioning failed in ", \
98 			fname);;}
99 
100 #define	QFTELL(file, pos, fname) \
101 		{if ((pos=FTELLO(file))==-1) \
102 		   error(EXIT_FAILURE,"*Error*: File position unknown in ", \
103 			fname);;}
104 
105 
106 #define	QFREE(x)	{free(x); x = NULL;}
107 
108 #define	QCALLOC(ptr, typ, nel) \
109 		{if (!(ptr = (typ *)calloc((size_t)(nel),sizeof(typ)))) \
110 		   error(EXIT_FAILURE, "Not enough memory for ", \
111 			#ptr " (" #nel " elements) !");;}
112 
113 #define	QMALLOC(ptr, typ, nel) \
114 		{if (!(ptr = (typ *)malloc((size_t)(nel)*sizeof(typ)))) \
115 		   error(EXIT_FAILURE, "Not enough memory for ", \
116 			#ptr " (" #nel " elements) !");;}
117 
118 #define	QMEMCPY(ptrin, ptrout, typ, nel) \
119 		{if (!(ptrout = (typ *)malloc((size_t)(nel)*sizeof(typ)))) \
120 		   error(EXIT_FAILURE, "Not enough memory for ", \
121 			#ptrout " (" #nel " elements) !"); \
122 		memcpy(ptrout, ptrin, (size_t)(nel)*sizeof(typ));}
123 
124 #define	QREALLOC(ptr, typ, nel) \
125 		{if (!(ptr = (typ *)realloc(ptr, (size_t)(nel)*sizeof(typ)))) \
126 		   error(EXIT_FAILURE, "Not enough memory for ", \
127 			#ptr " (" #nel " elements) !");;}
128 
129 #define	RINT(x)	(int)(floor(x+0.5))
130 
131 
132 #define	QPRINTF		if (qflag) fprintf
133 
134 #define	QFPRINTF(w,x)	{if (qflag) \
135 				fprintf(w, "\33[1M> %s\n\33[1A",x);;}
136 
137 
138 #define	QGETKEY(tab, key, keyname, dest) \
139 	{if (!(key = name_to_key(tab, keyname))) \
140 	   error(EXIT_FAILURE, "*Error*: No such parameter in catalog: ", \
141 			keyname); \
142 	 dest = key->ptr;}
143 
144 #define MIN(a,b) (a<b?a:b)
145