1 /* 2 * xearth.h 3 * kirk johnson 4 * july 1993 5 * 6 * Copyright (C) 1989, 1990, 1993-1995, 1999 Kirk Lauritz Johnson 7 * 8 * Parts of the source code (as marked) are: 9 * Copyright (C) 1989, 1990, 1991 by Jim Frost 10 * Copyright (C) 1992 by Jamie Zawinski <jwz@lucid.com> 11 * 12 * Permission to use, copy, modify and freely distribute xearth for 13 * non-commercial and not-for-profit purposes is hereby granted 14 * without fee, provided that both the above copyright notice and this 15 * permission notice appear in all copies and in supporting 16 * documentation. 17 * 18 * Unisys Corporation holds worldwide patent rights on the Lempel Zev 19 * Welch (LZW) compression technique employed in the CompuServe GIF 20 * image file format as well as in other formats. Unisys has made it 21 * clear, however, that it does not require licensing or fees to be 22 * paid for freely distributed, non-commercial applications (such as 23 * xearth) that employ LZW/GIF technology. Those wishing further 24 * information about licensing the LZW patent should contact Unisys 25 * directly at (lzw_info@unisys.com) or by writing to 26 * 27 * Unisys Corporation 28 * Welch Licensing Department 29 * M/S-C1SW19 30 * P.O. Box 500 31 * Blue Bell, PA 19424 32 * 33 * The author makes no representations about the suitability of this 34 * software for any purpose. It is provided "as is" without express or 35 * implied warranty. 36 * 37 * THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 38 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, 39 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT 40 * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 41 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 42 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 43 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 44 */ 45 46 #ifndef _XEARTH_H_ 47 #define _XEARTH_H_ 48 49 #include <X11/Xos.h> 50 #include <stdio.h> 51 #include <stdlib.h> 52 #include <math.h> 53 #include <assert.h> 54 #include <time.h> 55 #include "port.h" 56 #include "extarr.h" 57 #include "kljcpyrt.h" 58 59 #define VersionString "1.1" 60 #define HomePageURL "http://www.cs.colorado.edu/~tuna/xearth/index.html" 61 62 /* if NO_RANDOM is defined, use lrand48() and srand48() 63 * instead of random() and srandom() 64 */ 65 #ifdef NO_RANDOM 66 #define random() lrand48() 67 #define srandom(x) srand48((long) (x)) 68 #endif /* NO_RANDOM */ 69 70 #ifndef M_PI 71 #define M_PI 3.14159265358979323846 72 #endif /* !M_PI */ 73 74 /* a particularly large number 75 */ 76 #define BigNumber (1e6) 77 78 /* rotational period of the earth (seconds) 79 */ 80 #define EarthPeriod (86400) 81 82 /* default width and height, if not otherwise specified 83 */ 84 #define DefaultWdthHght (512) 85 86 /* default border width, if not otherwise specified 87 */ 88 #define DefaultBorderWidth (1) 89 90 /* types of pixels 91 */ 92 #define PixTypeSpace (0) 93 #define PixTypeLand (1) 94 #define PixTypeWater (2) 95 #define PixTypeStar (3) 96 #define PixTypeGridLand (4) 97 #define PixTypeGridWater (5) 98 99 /* types of dots 100 */ 101 #define DotTypeStar (0) 102 #define DotTypeGrid (1) 103 104 /* types of viewing positions 105 */ 106 #define ViewPosTypeFixed (0) 107 #define ViewPosTypeSun (1) 108 #define ViewPosTypeOrbit (2) 109 #define ViewPosTypeRandom (3) 110 #define ViewPosTypeMoon (4) 111 112 /* types of viewing rotations 113 */ 114 #define ViewRotNorth (0) 115 #define ViewRotGalactic (1) 116 117 /* types of projections 118 */ 119 #define ProjTypeOrthographic (0) 120 #define ProjTypeMercator (1) 121 #define ProjTypeCylindrical (2) 122 123 /* types of marker label alignment 124 */ 125 #define MarkerAlignDefault (0) 126 #define MarkerAlignLeft (1) 127 #define MarkerAlignRight (2) 128 #define MarkerAlignAbove (3) 129 #define MarkerAlignBelow (4) 130 131 /* vector rotation 132 */ 133 #define XFORM_ROTATE(p,vpi) \ 134 do { \ 135 double _p0_, _p1_, _p2_; \ 136 double _c_, _s_, _t_; \ 137 _p0_ = p[0]; \ 138 _p1_ = p[1]; \ 139 _p2_ = p[2]; \ 140 _c_ = vpi.cos_lon; \ 141 _s_ = vpi.sin_lon; \ 142 _t_ = (_c_ * _p0_) - (_s_ * _p2_); \ 143 _p2_ = (_s_ * _p0_) + (_c_ * _p2_); \ 144 _p0_ = _t_; \ 145 _c_ = vpi.cos_lat; \ 146 _s_ = vpi.sin_lat; \ 147 _t_ = (_c_ * _p1_) - (_s_ * _p2_); \ 148 _p2_ = (_s_ * _p1_) + (_c_ * _p2_); \ 149 _p1_ = _t_; \ 150 _c_ = vpi.cos_rot; \ 151 _s_ = vpi.sin_rot; \ 152 _t_ = (_c_ * _p0_) - (_s_ * _p1_); \ 153 _p1_ = (_s_ * _p0_) + (_c_ * _p1_); \ 154 _p0_ = _t_; \ 155 p[0] = _p0_; \ 156 p[1] = _p1_; \ 157 p[2] = _p2_; \ 158 } while (0) 159 160 /* mercator projection (xyz->xy) 161 * [the argument to MERCATOR_Y() is thresholded against 0.9999999999 162 * and -0.9999999999 instead of 1.0 and -1.0 to avoid numerical 163 * difficulties that can arise when the argument of tan() gets close 164 * to PI/2; thanks to Bill Leonard for helping debug this.] 165 */ 166 #define MERCATOR_X(x, z) (atan2((x), (z))) 167 #define MERCATOR_Y(y) (((y) >= 0.9999999999) ? (BigNumber) \ 168 : (((y) <= -0.9999999999) ? (-BigNumber) \ 169 : log(tan((asin(y)/2) + (M_PI/4))))) 170 #define INV_MERCATOR_Y(y) (sin(2 * (atan(exp(y)) - (M_PI/4)))) 171 172 /* cylindrical projection (xyz->xy) 173 */ 174 #define CYLINDRICAL_X(x, z) (atan2((x), (z))) 175 #define CYLINDRICAL_Y(y) (((y) >= 0.9999999999) ? (BigNumber) \ 176 : (((y) <= -0.9999999999) ? (-BigNumber) \ 177 : (tan(asin(y))))) 178 #define INV_CYLINDRICAL_Y(y) (sin(atan(y))) 179 180 /* xy->screen projections 181 */ 182 #define XPROJECT(x) ((proj_info.proj_scale*(x))+proj_info.proj_xofs) 183 #define YPROJECT(y) (proj_info.proj_yofs-(proj_info.proj_scale*(y))) 184 #define INV_XPROJECT(x) (((x)-proj_info.proj_xofs)*proj_info.inv_proj_scale) 185 #define INV_YPROJECT(y) ((proj_info.proj_yofs-(y))*proj_info.inv_proj_scale) 186 187 #ifdef __alpha 188 /* on alpha systems, trade off space for more efficient access 189 */ 190 typedef int s8or32; 191 typedef unsigned u8or32; 192 typedef int s16or32; 193 typedef unsigned u16or32; 194 #else 195 /* other systems can access 8- and 16-bit items efficiently 196 */ 197 typedef char s8or32; 198 typedef unsigned char u8or32; 199 typedef short s16or32; 200 typedef unsigned short u16or32; 201 #endif 202 203 typedef struct 204 { 205 double cos_lat, sin_lat; /* cos/sin of view_lat */ 206 double cos_lon, sin_lon; /* cos/sin of view_lon */ 207 double cos_rot, sin_rot; /* cos/sin of view_rot */ 208 } ViewPosInfo; 209 210 typedef struct 211 { 212 double proj_scale; 213 double proj_xofs; 214 double proj_yofs; 215 double inv_proj_scale; 216 } ProjInfo; 217 218 typedef struct 219 { 220 short y; 221 short lo_x; 222 short hi_x; 223 short val; 224 } ScanBit; 225 226 typedef struct 227 { 228 short x; 229 short y; 230 u_char type; 231 } ScanDot; 232 233 typedef struct 234 { 235 float lat; 236 float lon; 237 char *label; 238 int align; 239 } MarkerInfo; 240 241 /* dither.c */ 242 extern int dither_ncolors; 243 extern u_char *dither_colormap; 244 extern void dither_setup _P((int)); 245 extern void dither_row _P((u_char *, u16or32 *)); 246 extern void dither_cleanup _P((void)); 247 extern void mono_dither_setup _P((void)); 248 extern void mono_dither_row _P((u_char *, u16or32 *)); 249 extern void mono_dither_cleanup _P((void)); 250 251 /* gif.c */ 252 extern void gif_output _P((void)); 253 254 /* mapdata.c */ 255 extern short map_data[]; 256 257 /* markers.c */ 258 extern MarkerInfo *marker_info; 259 extern void load_marker_info _P((char *)); 260 extern void show_marker_info _P((char *)); 261 262 /* ppm.c */ 263 extern void ppm_output _P((void)); 264 265 /* render.c */ 266 extern void render _P((int (*)(u_char *))); 267 extern void do_dots _P((void)); 268 269 /* resources.c */ 270 extern char *get_string_resource _P((const char *, const char *)); 271 extern int get_boolean_resource _P((const char *, const char *)); 272 extern int get_integer_resource _P((const char *, const char *)); 273 extern double get_float_resource _P((const char *, const char *)); 274 extern unsigned int get_pixel_resource _P((const char *, const char *)); 275 276 /* scan.c */ 277 extern ViewPosInfo view_pos_info; 278 extern ProjInfo proj_info; 279 extern ExtArr scanbits; 280 extern void scan_map _P((void)); 281 282 /* sunpos.c */ 283 extern void sun_position _P((time_t, double *, double *)); 284 extern void moon_position _P((time_t, double *, double *)); 285 286 /* x11.c */ 287 extern void command_line_x _P((int, char *[])); 288 extern void x11_output _P((void)); 289 290 /* xearth.c */ 291 extern char *progname; 292 extern int proj_type; 293 extern double view_lon; 294 extern double view_lat; 295 extern double view_rot; 296 extern double view_mag; 297 extern int do_shade; 298 extern double sun_lon; 299 extern double sun_lat; 300 extern int wdth; 301 extern int hght; 302 extern int shift_x; 303 extern int shift_y; 304 extern int do_stars; 305 extern double star_freq; 306 extern int big_stars; 307 extern int do_grid; 308 extern int grid_big; 309 extern int grid_small; 310 extern int do_label; 311 extern int do_markers; 312 extern char *markerfile; 313 extern int wait_time; 314 extern double time_warp; 315 extern int fixed_time; 316 extern int day; 317 extern int night; 318 extern int terminator; 319 extern double xgamma; 320 extern int use_two_pixmaps; 321 extern int num_colors; 322 extern int do_fork; 323 extern int priority; 324 extern time_t current_time; 325 326 extern void compute_positions _P((void)); 327 extern char **tokenize _P((char *, int *, const char **)); 328 extern void decode_proj_type _P((char *)); 329 extern void decode_rotation _P((char *)); 330 extern void decode_viewing_pos _P((char *)); 331 extern void decode_sun_pos _P((char *)); 332 extern void decode_size _P((char *)); 333 extern void decode_shift _P((char *)); 334 extern void xearth_bzero _P((char *, unsigned)); 335 extern void version_info _P((int)); 336 extern void usage _P((const char *)) _noreturn; 337 extern void warning _P((const char *)); 338 extern void fatal _P((const char *)) _noreturn; 339 340 #ifdef USE_EXACT_SQRT 341 342 #define SQRT(x) (((x) <= 0.0) ? (0.0) : (sqrt(x))) 343 344 #else 345 346 /* 347 * brute force approximation for sqrt() over [0,1] 348 * - two quadratic regions 349 * - returns zero for args less than zero 350 */ 351 #define SQRT(x) \ 352 (((x) > 0.13) \ 353 ? ((((-0.3751672414*(x))+1.153263483)*(x))+0.2219037586) \ 354 : (((x) > 0.0) \ 355 ? ((((-9.637346154*(x))+3.56143)*(x))+0.065372935) \ 356 : (0.0))) 357 358 #endif /* USE_EXACT_SQRT */ 359 360 #ifndef isupper 361 # define isupper(c) ((c) >= 'A' && (c) <= 'Z') 362 #endif 363 #ifndef _tolower 364 # define _tolower(c) ((c) - 'A' + 'a') 365 #endif 366 367 #endif 368