home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume12 / starcharts / part01 next >
Encoding:
Internet Message Format  |  1987-11-29  |  46.0 KB

  1. Subject:  v12i071:  StarChart program and Yale star data, Part01/07
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rs@uunet.UU.NET
  5.  
  6. Submitted-by: awpaeth@watcgl.waterloo.edu (Alan W. Paeth)
  7. Posting-number: Volume 12, Issue 71
  8. Archive-name: starchart/part01
  9.  
  10. [  Everything a would-be Carl Sagan needs to get started.  --r$  ]
  11.  
  12. This release provides astronomical charting software for locating the stars,
  13. planets and other cosmic objects, with output to PIC, PostScript, Tektronix,
  14. TTY or HP printing devices.
  15.  
  16. This posting upgrades a previous release (1Q 1987) by adding a Messier catalog
  17. database (star clusters, nebulae and galaxies), mnemonic constellation finder,
  18. star annotations (eg, star designations in Roman or Greek characters, double-
  19. star symbols) and greatly improved command line syntax. A new output driver
  20. has been added. A program for updating stellar coordinates (for epoch
  21. conversion related to the precession of the equinoxes) is also included.
  22.  
  23. A reposting of "yale.star" which locates the brightest stars (about 9000
  24. entries) accompanyies this software posting. StarChart will run on both
  25. the new and old reduced Yale datasets.
  26.  
  27. # This is a shell archive.  Remove anything before this line,
  28. # then unpack it by saving it in a file and typing "sh file".
  29. #
  30. # Wrapped by watcgl!awpaeth on Mon Oct  5 18:38:48 EDT 1987
  31. # Contents:  README Makefile starchart.h starchart.c stardsp.c starhp.c
  32. #    starimages.c
  33.  
  34. echo x - README
  35. sed 's/^@//' > "README" <<'@//E*O*F README//'
  36. STARCHART (rev 2)
  37. ----------------------------------------------------------------------------
  38. Note: This version is upward compatable with the original "starchart" software
  39. family, both in user interface and in continued support of the original
  40. reduced Yale catalog. Thus, it may supplant old copies of the software without
  41. fear that either shell scripts or file formats will become invalid.
  42.  
  43. However, both the new user interface and the extended catalog are
  44. superior, as are extensions for additional labelling (Greek characters,
  45. double star indicators, Messier objects), plus a mnemonic "finder" facility.
  46. ----------------------------------------------------------------------------
  47.  
  48. INSTALLATION INSTRUCTIONS:
  49.  
  50. [1]
  51. Save the new posting of the reduced Yale Star Catalog under the name
  52. "yale.star" (or use a copy of the old version). If the save directory is other
  53. than the one in which the program lives, then check out the Makefile, which
  54. allows path names to be specified for compilation.
  55.  
  56. Sites without much disk space may truncate the file yale.star at any point,
  57. as the data is sorted in order of increasing magnitude (dimming).
  58.  
  59. Additonally, the optional files "messier.star" and "con.locs" should be
  60. placed in the chosen directory. Entries in these files are unsorted. The
  61. optional file "planet.star" is created on an as-needed basis by the softwaare
  62. "planet.c", and might want a home in some less permanent (writable) location.
  63.  
  64. [2]
  65. Do a "make all" to compile all software. They are described in the man pages
  66. "starchart.1" and "planet.1" . All compile using starchart.c as the mainline,
  67. with device driver specifics in modules of appropriate name.
  68.  
  69. [3]
  70. You may now try "man test" to make an Orion pic file similar to the one
  71. posted to the net. Or you may test by outputting to the tty display, using the
  72. version "stardsp". This is described in the EXAMPLE section of the man page.
  73.  
  74. VERSION NOTES:
  75.  
  76. Tty display users (*sigh*) may which to alter "stardsp" to output
  77. to the display using an appropriate number of of rows and columns
  78. on the screen. (Presently 31x79 for a 32x80 display. 23x79 is a
  79. bit sparse).  Find the ROWS and COLS #defines in stardsp.c
  80. and update. Or be really ambitious and recode them as run time
  81. variables.
  82.  
  83. Tektronix emulator users may wish to alter scaling parameters based on the
  84. actual physical dimensions of the display raster, to get the cleanest possible
  85. star glyphs on output. This is described at length in the beginning of the
  86. driver "startek.c".
  87.  
  88. Pic file users: the #define PICFRAG can be adjusted downward
  89. (presently 8) should your pic input overflow pic's buffers. This
  90. happens when a long move,draw,draw,...,draw sequence happens.
  91. Smaller  PICFRAGs make larger files, by forming fragmented
  92. move,draw commands.
  93.  
  94. PostScript users: you may wish to play with the boiler-plate macros which
  95. define star shapes (e.g. 's1' does first magnitude stars). This is mentioned
  96. at the end of starchart.c
  97.  
  98. Laserjet users: the output of starlaser must be directed to
  99. laserjet via raw connection, because it is largely sent in binary
  100. 8-bit format. The graphics memory might overflow if you use the
  101. standard (oldest) 59k buffer laserjet (*sigh*). Anyway, I haven't
  102. ever lost any relevant data on the sheet: the overflow has occurred on
  103. the last few blank pixel rows of the graphics area. If you use
  104. laserjet plus, you shouldn't have any problems.
  105.  
  106. Other devices: don't expect the authors to write a new driver for you :-)
  107. Look through the sources - it's not so difficult after all... The module
  108. "starimages.c" provides support for bitmap devices; the PostScript driver
  109. is a good example of generating output in some graphics language.
  110.  
  111. More ambitious programmers may wish to extend the usefulness of these programs.
  112. Be our guest, but carefully consider the proposed list of suggestions which
  113. intentionally accompanies the main source code body "starchart.c". It is hoped
  114. that future changes and major revisions and their subsequent integration will
  115. be kept relatively simple by coordinating efforts and by not duplicating work.
  116.  
  117. awpaeth@watcgl (original author and revisions editor)
  118. inp@amber.berkeley.EDU (revisionist for user interface)
  119. pl@sibelius.intrin.FI (support for mini-Yale, Messier and finder catalogs)
  120. @//E*O*F README//
  121. chmod u=rwx,g=rwx,o=rwx README
  122.  
  123. echo x - Makefile
  124. sed 's/^@//' > "Makefile" <<'@//E*O*F Makefile//'
  125. #
  126. # Author: Petri Launiainen, Intrinsic Oy, Tampere, FINLAND (pl@intrin.FI)
  127. #
  128. # Based on the work of Alan W. Paeth
  129. #
  130.  
  131. SHELL = /bin/sh
  132.  
  133. #
  134. # put the Yale Star Catalog file path here: because the yale.star is
  135. # static (stars don't change so often :->), consider using some static
  136. # library path here - relative one is used for quick testing
  137.  
  138. #STAR = "/usr/lib/starchart/yale.star"
  139. STAR = "./yale.star"
  140.  
  141. # similarly assign the Messier file path:
  142.  
  143. #MESS = "/usr/lib/starchart/messier.star"
  144. MESS = "./messier.star"
  145.  
  146. # put the planet position file path here: it should be preferably
  147. # relative, thus allowing everyone to change planet positions according
  148. # to their interests.  This file changes when the 'planet' program is
  149. # executed
  150.  
  151. PLANET = "./planet.star"
  152.  
  153. # notice that starchart.o and planet are made dependent on Makefile, due
  154. # to the STAR, MESS and PLANET definitions here
  155.  
  156. # put the installation directory here
  157.  
  158. BINDIR = "/usr/local/bin"
  159.  
  160. CFLAGS = -O -DSTARFILE='$(STAR)' -DPLANETFILE='$(PLANET)' -DMESSFILE='$(MESS)'
  161. LFLAGS = -O
  162.  
  163. # star chart calculation routine file
  164.  
  165. COBJ = starchart.o
  166.  
  167. # default binary names: if you change these, change also the corresponding
  168. # make tags
  169.  
  170. BINS = epoch moonphase planet startek stardsp starpic starhp starlaser starpost
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177. test:
  178.     stardsp -c ori
  179.  
  180. all:    \
  181.     planet\
  182.     starhp\
  183.     stardsp\
  184.     startek\
  185.     starpic\
  186.     starpost\
  187.     starlaser\
  188.     epoch\
  189.     moonphase
  190.  
  191. install: all
  192.     strip $(BINS)
  193.     mv $(BINS) $(BINDIR)
  194.  
  195. starchart.o: starchart.c Makefile starchart.h
  196.  
  197. moonphase: moonphase.o
  198.     cc $(LFLAGS) moonphase.o -lm -o $@
  199.  
  200. epoch: epoch.o
  201.     cc $(LFLAGS) epoch.o -lm -o $@
  202.  
  203. planet:    planet.o Makefile
  204.     cc $(LFLAGS) $(DEFINES) planet.o -lm -o $@
  205.  
  206. stardsp: $(COBJ) stardsp.o
  207.     cc $(LFLAGS) $(COBJ) stardsp.o -lm -o $@
  208.  
  209. starpic: $(COBJ) starpic.o
  210.     cc $(LFLAGS) $(COBJ) starpic.o -lm -o $@
  211.  
  212. startek: $(COBJ) startek.o starimages.o
  213.     cc $(LFLAGS) $(COBJ) startek.o starimages.o -lm -o $@
  214.  
  215. starhp: $(COBJ) starhp.o starimages.o
  216.     cc $(LFLAGS) $(COBJ) starhp.o starimages.o -lm -o $@
  217.  
  218. starlaser: $(COBJ) starlaser.o starimages.o
  219.     cc $(LFLAGS) $(COBJ) starlaser.o starimages.o -lm -o $@
  220.  
  221. starpost: $(COBJ) starpost.o
  222.     cc $(LFLAGS) $(COBJ) starpost.o -lm -o $@
  223.  
  224. make clean:
  225.     rm -f *.o mlog core
  226. @//E*O*F Makefile//
  227. chmod u=rwx,g=rwx,o=rwx Makefile
  228.  
  229. echo x - starchart.h
  230. sed 's/^@//' > "starchart.h" <<'@//E*O*F starchart.h//'
  231. typedef struct
  232.     {
  233.     float racen, dlcen, scale;
  234.     float north, south, east, west;
  235.     float maglim, lbllim;
  236.     int wx, wy, ww, wh;
  237.     float yscale;
  238.     } mapblock, *map;
  239.  
  240. extern mapblock master, thumbnail;
  241. @//E*O*F starchart.h//
  242. chmod u=rwx,g=rwx,o=rwx starchart.h
  243.  
  244. echo x - starchart.c
  245. sed 's/^@//' > "starchart.c" <<'@//E*O*F starchart.c//'
  246. /*
  247.  * starchart.c -- version 2, September 1987
  248.  *
  249.  * (c) copyright 1987 by Alan Paeth (awpaeth@watcgl)
  250.  */
  251.  
  252. /*
  253.  ! Version 2 modification authors:
  254.  !
  255.  !   [a] Petri Launiainen, pl@intrin.FI (with Jyrki Yli-Nokari, jty@intrin.FI)
  256.  !   [b] Bob Tidd, inp@VIOLET.BERKELEY.EDU
  257.  !   [c] Alan Paeth, awpaeth@watcgl
  258.  !
  259.  ! Changes and Additions:
  260.  !
  261.  !a   [1] STARFILE, PLANETFILE, etc. path designations are now in the Makefile
  262.  !ac  [2] Fractional Ra and Decl values are now hh.mm and mm.ss (base 60)
  263.  !a   [3] Command syntax now allows flags as well as old style (arg placement)
  264.  !ab  [4] Extended Yale database (courtesy B. Tidd) also supported on input
  265.  !bc  [5] Greek+Flamsteed numbers now appear as a hardcopy annotation
  266.  !bc  [6] Constellation file finds ra,dl,scale from command line pattern
  267.  !c   [7] New symbols for Nebulae, Galaxies and Clusters added (based on [4])
  268.  !c   [8] Double star indications added (provisions for variable stars) ([4])
  269.  !a   [9] Limiting magnitude flags for stars and labels allowed
  270.  !c  [10] Legend column reformatted to contain additional symbols [4]
  271.  !a  [11] Internal symbol compiler created for raster glyph creation
  272.  !c  [12] add Yale records for "moveto"/"drawto" and text annotations
  273.  !c  [13] added -f file.star to add ephemeride data
  274.  !
  275.  ! Bug Fixes:
  276.  !
  277.  !a   [1] no more core dumps (on SysV) when given bad command line parameters
  278.  !c   [2] Negative RA indications now "wrap" to 24hrs, etc.
  279.  !bc  [3] Mag values *rounded* to nearest unit value (common Atlas convention)
  280.  !c   [4] Removed any device dependent subroutines (eg. getopt).
  281.  !
  282.  ! Final integration by the original author [c].
  283.  ! Questions, suggestions, and fixes should be e-mailed to him.
  284.  */
  285.  
  286. #include <stdio.h>
  287. #include <math.h>
  288. #include <strings.h>
  289. #include <ctype.h>
  290. #include "starchart.h"
  291.  
  292. /*
  293.  * datasets are local, unless defined in Makefile
  294.  */
  295.  
  296. #ifndef STARFILE
  297. #define STARFILE    "./yale.star"
  298. #endif
  299.  
  300. #ifndef PLANETFILE
  301. #define PLANETFILE    "./planet.star"
  302. #endif
  303.  
  304. #ifndef MESSFILE
  305. #define MESSFILE    "./messier.star"
  306. #endif
  307.  
  308. #ifndef CONSTFILE
  309. #define CONSTFILE    "./con.locs"
  310. #endif
  311.  
  312. #define DCOS(x) (cos((x)*3.14159265354/180.0))
  313. #define MAX(a,b) ((a)>(b)?(a):(b))
  314. #define MIN(a,b) ((a)<(b)?(a):(b))
  315.  
  316. #define THUMBDIFF 2.5    /* thumbnail mag lim is brighter */
  317. #define THUMBMAX 5.0    /* but no lower than this value */
  318. #define THUMBRATIO 1.2    /* and scaled by this size (yet is already wider) */
  319. #define THUMBDEG 10.0    /* but this is the floor on finder scale */
  320. #define FSIZESML 8    /* point size for star designation */
  321. #define FSIZELRG 10    /* point size for other object annotations */
  322.  
  323. double max(), modup(), moddown();
  324. double ftod(), htod(), atof();
  325.  
  326. /* globals */
  327.  
  328. char *progname;        /* program name for errors */
  329. double ra, de, sc;    /* global chart attributes */
  330. char *title;
  331. char *userfile;        /* potential .star file of user ephemerides */
  332.  
  333. /* the code */
  334.  
  335. main(argc, argv)
  336.     int argc;
  337.     char *argv[];
  338.     {
  339.     double thumbscale;
  340.     commandline(argc, argv);
  341.     vecopen();
  342.     chartparms(&master, ra, de, sc);
  343.     thumbscale = MAX(sc * THUMBRATIO, THUMBDEG);
  344.     chartparms(&thumbnail, ra, de, thumbscale);
  345.     thumbnail.maglim = MIN(THUMBMAX, master.maglim - THUMBDIFF);
  346.     chartall(&master);
  347.     chartall(&thumbnail);
  348.     chartlegend(&master);
  349.     vecclose();
  350.     exit(0);
  351.     }
  352.  
  353. commandline(argc, argv)
  354.     char **argv;
  355.     {
  356.     int j;
  357.     static char *usage =
  358. "\nusage:\tstar* [ Ra Dcl Scale Title Maglim Labellim ]\nor\tstar* [ -r Ra -d Dcl -s Scale -t Title -m Maglim -l Labellim -f x.star ]\nor\tstar*  [ -c con (3 or 4 letters chosen from con.locs) -l ... ]";
  359.     progname = argv[0];
  360.     title = NULL;
  361.     ra = 0.0;
  362.     de = 0.0;
  363.     sc = 0.0;
  364. /*
  365.  * check command line style
  366.  */
  367.     if (argc == 1) die("No arguments - %s", usage);
  368.     if  ( (argv[1][0] == '-') && isalpha(argv[1][1]) )
  369.     {
  370. /*
  371.  * new style command line (using flags)
  372.  */
  373.     for (j=1; j<argc; j++)
  374.         {
  375.         if (argv[j][0] != '-') die("unknown argument - %s", argv[j]);
  376.         switch (argv[j][1])
  377.         {
  378.         case 'c': findconst(argv[++j]); break;
  379.         case 'r': ra = htod(argv[++j]); break;
  380.         case 'd': de = htod(argv[++j]); break;
  381.         case 's': sc = atof(argv[++j]); break;
  382.         case 'l': master.lbllim = (float)(atof(argv[++j])); break;
  383.         case 'm': master.maglim = (float)(atof(argv[++j])); break;
  384.         case 't': title = argv[++j]; break;
  385.         case 'f': userfile = argv[++j]; break;
  386.         case 'u': die("%s", usage);
  387.         default:  die("unknown switch - %s", argv[j]);
  388.         }
  389.         if (j == argc) die("trailing command line flag - %s", argv[j-1]);
  390.         }
  391.     }
  392.     else
  393.     {
  394. /*
  395.  * old style command line (position dependent)
  396.  */
  397.     switch (argc)
  398.         {
  399.         case 7: master.maglim = (float)(atof(argv[6]));
  400.         case 6: master.lbllim = (float)(atof(argv[5]));
  401.         case 5: title = argv[4];
  402.         case 4: sc = atof(argv[3]);
  403.         case 3: de = htod(argv[2]);
  404.         case 2: ra = htod(argv[1]); break;
  405.         default: die("too many arguments - %s", usage);
  406.         }
  407.     }
  408.     }
  409.  
  410. double ftod(x)
  411.     double x;
  412.     {
  413.     int full;
  414.     full = x;
  415.     return(full + (x-full)*100.0/60.0);
  416.     }
  417.  
  418. double htod(s)
  419.     char *s;
  420.     {
  421. /*
  422.  * htod(str) reads floating point strings of the form {+-}hh.{mm} thus
  423.  * allowing for fractional values in base 60 (ie, degrees/minutes).
  424.  */
  425. /*
  426.     double x, sign;
  427.     int full, frac;
  428.     char *t;
  429.     t = s-1;
  430.     while(*++t)
  431.     {
  432.     if ((*t == ' ') || (*t = '\t') || (*t == '\n')) break;
  433.     if ( ( (*t<'0') || (*t>'9') ) && (*t!='.') && (*t!='+') && (*t!='-'))
  434.         die("non-digit in dd.mm style numeric argument: %s", s);
  435.     }
  436.     if (s == NULL) return 0.0;
  437.     full = frac = 0;
  438.     sign = 1.0;
  439.     if (*s == '-')
  440.     {
  441.     sign = -1.0;
  442.     s++;
  443.     }
  444.     else if (*s == '+') s++;
  445.     while (*s && *s != '.') full = 10 * full + *s++ - '0';
  446.     if (*s++ == '.')
  447.     {
  448.     if (*s) frac = 10 * (*s++ - '0');
  449.     if (*s) frac += *s++ - '0';
  450.     if (frac > 59) frac = 59;
  451.     }
  452.     x = (double) full + ((double) frac) / 60.0;
  453.     return sign * x;
  454. */
  455.     return(ftod(atof(s)));
  456.     }
  457.  
  458. chartparms(chart, ras, decl, scl)
  459.     double ras, decl, scl;
  460.     map chart;
  461.     {
  462.     double adj, xscale;
  463.     chart->racen = ras * 360.0 / 24.0;
  464.     chart->dlcen = decl;
  465.     chart->scale = scl;
  466.     if (chart->scale == 0.0) chart->scale = 15.0;
  467.  
  468.     chart->north = (chart->dlcen + chart->scale / 2.0);
  469.     chart->south = (chart->dlcen - chart->scale / 2.0);
  470. /*
  471.  * xscale is other than chart->scale in order to widen the horizontal viewing
  472.  * area, which otherwise shrinks near the poles under Sanson's projection
  473.  * this happens in polar maps which do not span the celestial equator
  474.  */
  475.     adj = 1.0;
  476.     if (chart->north * chart->south > 0.0)
  477.     adj = max(DCOS(chart->north), DCOS(chart->south));
  478.     xscale = chart->scale/adj;
  479.  
  480.     chart->east  = (chart->racen + xscale*chart->ww/chart->wh / 2.0);
  481.     chart->west  = (chart->racen - xscale*chart->ww/chart->wh / 2.0);
  482.     chart->yscale = chart->wh / chart->scale;
  483.     }
  484.  
  485. chartlegend(chart)
  486.     map chart;
  487.     {
  488.     char ras[2], dls[20], outstr[40];
  489.     if (!title) title = "LEGEND";
  490.     rastr(ras, chart->racen);
  491.     declstr(dls, chart->dlcen);
  492.     sprintf(outstr, "(%s,%s lim: %2.1f)", ras, dls, chart->maglim);
  493.  
  494.     vecsize(16); vecsyms(65, 220, title);
  495.     vecsize(10); vecsyms(65, 185, outstr);
  496.  
  497.     vecsize(12);
  498.     drawStar( 65, 150, 0, 'S', NULL);
  499.     vecsyms(  95, 150,"<0.5");
  500.     if (chart->maglim >= 0.5)
  501.     {
  502.     vecsize(10);
  503.     drawStar(230, 150, 1, 'S', NULL);
  504.     vecsyms( 260, 150,"<1.5");
  505.     }
  506.     if (chart->maglim >= 1.5)
  507.     {
  508.     vecsize( 9);
  509.     drawStar( 65, 125, 2, 'S', NULL);
  510.     vecsyms(  95, 125,"<2.5");
  511.     }
  512.     if (chart->maglim >= 2.5)
  513.     {
  514.     vecsize( 8);
  515.     drawStar(230, 125, 3, 'S', NULL);
  516.     vecsyms(260, 125,"<3.5");
  517.     }
  518.     if (chart->maglim >= 3.5)
  519.     {
  520.     vecsize( 7);
  521.     drawStar( 65, 100, 4, 'S', NULL);
  522.     vecsyms(  95, 100,"<4.5");
  523.     }
  524.     if (chart->maglim > 4.5)
  525.     {
  526.     vecsize( 6);
  527.     drawStar(230, 100, 5, 'S', NULL);
  528.     vecsyms(260, 100,">4.5");
  529.     }
  530.  
  531.     vecsize(10); vecsyms( 95,  75,"double");  drawStar( 65,  75, 2, 'D', NULL);
  532.     vecsize(10); vecsyms(260,  75,"variable");drawStar(230,  75, 2, 'V', NULL);
  533.  
  534.     vecsize(10); vecsyms( 95,  50,"planet");  drawPlan( 65,  50, 1, 'S', NULL);
  535.     vecsize(10); vecsyms(260,  50,"galaxy");  drawGalx(230,  50, 1, 'S', NULL);
  536.  
  537.     vecsize(10); vecsyms( 95,  25,"nebula");  drawNebu( 65,  25, 1, 'S', NULL);
  538.     vecsize(10); vecsyms(260,  25,"cluster"); drawClus(230,  25, 1, 'S', NULL);
  539.     }
  540.  
  541. readstar(file, lat, lon, mag, code, subcode, color, label, name)
  542.     FILE *file;
  543.     double *lat, *lon, *mag;
  544.     char *code, *subcode, *color, *label, *name;
  545.     {
  546. #define LINELEN 80
  547.     char sbuf[LINELEN+1], *ptr;
  548.     double rah, ram, ras, dld, dlm, dl, inten;
  549.     int len, i;
  550. /*
  551.  * file formats:
  552.  * new
  553. 064509-1643-99SDA1a CMASirius
  554. 051432-0812015SDB8b ORIRigel
  555.  * old
  556. 064509-1643-146SSSirius
  557. 051432-08120015SSRigel
  558.  */
  559.     fgets(sbuf, LINELEN, file);
  560.     if (feof(file)) return(1);
  561. /*
  562.  * sscanf of floats is TOOO slow:
  563.  *     sscanf(sbuf, "%2f%2f%2f%c%2f%2f ... );
  564.  * use alternate:
  565.  */
  566. #define F2(i) ((double)((sbuf[i]-'0')*10+sbuf[i+1]-'0'))
  567. #define F3(i) ((double)((sbuf[i]-'0')*100+(sbuf[i+1]-'0')*10+sbuf[i+2]-'0'))
  568. #define F4(i) ((double)((sbuf[i]-'0')*1000+(sbuf[i+1]-'0')*100+(sbuf[i+2])-'0')*10+sbuf[i+3]-'0')
  569.     rah = F2(0);
  570.     ram = F2(2);
  571.     ras = F2(4);
  572.     dld = F2(7);
  573.     dlm = F2(9);
  574. /*
  575.  * common code
  576.  */
  577. #define DLDEGSEC 3600.0
  578. #define DLMINSEC 60.0
  579. #define RAHRSSEC 54000.0
  580. #define RAMINSEC 900.0
  581. #define RASECSEC 15.0
  582.  
  583.     *lon = (RAHRSSEC*rah + RAMINSEC*ram + RASECSEC*ras)/DLDEGSEC;
  584.     dl = (DLDEGSEC*dld + DLMINSEC*dlm)/DLDEGSEC;
  585.     *lat = (sbuf[6]  == '-') ? -dl : dl;
  586.     if  (isdigit(sbuf[14]))
  587.     {
  588. /*
  589.  * old reduced Yale catalog
  590.  */
  591.     inten = F3(12);
  592.     if (sbuf[11] == '0' || sbuf[11] == '+') *mag = inten/100.0;
  593.     else if (sbuf[11] == '-') *mag = -inten/100.0;
  594.     else *mag = F4(11);    /* new feature for stars >= 10.0 mag */
  595.     if (sbuf[11] != 0)
  596.     code[0] = sbuf[15];
  597.     subcode[0] = sbuf[16];
  598.     color [0] = '\0'; strcpy (color, "  "); /* set unknowns to blanks */
  599.     label [0] = '\0';
  600.     name [0] = '\0'; strncat (name, &sbuf[17], strlen (&sbuf [17]) - 1);
  601.     }
  602.     else
  603.     {
  604. /*
  605.  * new reduced Yale catalog
  606.  */
  607.     *mag = ((sbuf[11] == '-') ? -F2(12) : F3(11))/100.0;
  608.     code[0] = sbuf[14];    /* let's get Sirius */
  609.     subcode[0] = sbuf[15];
  610.     color [0] = '\0';
  611.     label [0] = '\0';
  612.     name [0] = '\0';
  613.     switch (code[0])
  614.         {
  615.         case 'C':
  616.         case 'N':
  617.         case 'G':
  618. /*
  619.  * name vs label:
  620.  *
  621.  * A "name" is a common English term for a star or cosmic object (eg Polaris,
  622.  * Pleiades). A label is an official designation for such an object (eg
  623.  * alpha-Ursa Minor, M45). For stars, labels are taken from the two column
  624.  * Bayer/Flamsteed field in the new reduced label format and the proper name
  625.  * from the "name" field (the label field might also include the three letter
  626.  * IAU constellation designation, but at present these are ignored)
  627.  *
  628.  * For non-stellar objects, the Bayer and IAU fields are typically blank (and
  629.  * always ignored), and the "name" field consists of the designation followed
  630.  * by an optional proper name, or perhaps just an annotation, the latter
  631.  * flagged by a leading "," and ignored by the software. For instance, the
  632.  * entry "m45 Pleiades" forms a label "m45" and a name "Pleiades", but the
  633.  * entry "m6  ,butterfly shape" forms merely the label "m6".
  634.  *
  635.  * At the present, the charting software which is supplied this data on a call
  636.  * to "readstar" will print names in favor of labels.
  637.  */
  638. /*
  639.  * extract Messier number and name
  640.  */
  641.         strcpy (color, "  ");
  642.         ptr = &sbuf[23];
  643.         i = 0;
  644.         while (isalnum (*ptr)) label[i++] = *ptr++;
  645.  
  646.         label[i] = '\0';
  647.         i = 0;
  648.         while (*ptr == ' ') ptr++;
  649.         while (*ptr != ',' && *ptr != '\n' && *ptr)
  650.             name[i++] = *ptr++;
  651.         name[i] = '\0';
  652.         break;
  653.     default:
  654. /*
  655.  * extract color, label and name
  656.  */
  657.         strncat (color, &sbuf[16], 2);
  658.         strncat (label, &sbuf[18], strlen (&sbuf [18]) - 1);
  659.         if  ((len = strlen (label)) > 5)
  660.             {
  661.             strncat (name, &label[5], len - 5);
  662.             label [5] = '\0';
  663.             }
  664.         }
  665.     }
  666.     return(0);
  667.     }
  668.  
  669. xform(chart, lat, lon, xloc, yloc)
  670.     map chart;
  671.     double lat, lon;
  672.     int *xloc, *yloc;
  673.     {
  674.  /*
  675.   * This is Sanson's Sinusoidal projection. Its properties:
  676.   *   (1) area preserving
  677.   *   (2) preserves linearity along y axis (declination/azimuth)
  678.   */
  679.     *xloc = chart->wx+chart->ww/2 + (chart->racen-lon)*chart->yscale*DCOS(lat);
  680.     *yloc = chart->wy + (int)((lat - chart->south) * chart->yscale);
  681.     }
  682.  
  683. chartall(chart)
  684.     map chart;
  685.     {
  686. /*
  687.  * we might "die" after drawing the borders, but we want stars to overlay
  688.  * the border for imaging software which may handle the bottom-up 2-1/2D
  689.  * order of printing correctly (eg PostScript).
  690.  */
  691.     chartoutline(chart);
  692.     chartgrid(chart);
  693.     if (!chartfile(chart, STARFILE)) die("open fail on %s", STARFILE);
  694.     chartfile(chart, PLANETFILE);
  695.     chartfile(chart, MESSFILE);
  696.     if (userfile)
  697.        {
  698.        if (!chartfile(chart, userfile)) die("open fail on %s", userfile);
  699.        }
  700.     }
  701.  
  702. chartfile(chart, filename)
  703.     map chart;
  704.     char *filename;
  705.     {
  706. #define READMODE "r"
  707. #define OPENFAIL 0
  708.     FILE *sfile;
  709.     if ((sfile = fopen(filename, READMODE)) == OPENFAIL) return(0);
  710.     chartobjects(chart, sfile);
  711.     fclose(sfile);
  712.     return(1);
  713.     }
  714.  
  715. chartobjects(chart, file)
  716.     map chart;
  717.     FILE *file;
  718.     {
  719.     double lat, lon, mag;
  720.     char code[1], subcode[1], label[100], name [100], color [3], *ptr;
  721.     int xloc, yloc, staronly, smallflag, vecmode, gkflag, xcur, ycur;
  722.  
  723.     for(;;)
  724.     {
  725.     if (readstar(file,&lat,&lon,&mag,code,subcode,color,label,name)) break;
  726.     if ((mag > chart->maglim) && (code[0] == 'S')) break;
  727.     if ((chart->west < 0.0) && (lon>180.0)) lon -= 360.0;
  728.     if ((chart->east > 360.0) && (lon<180.0)) lon += 360.0;
  729.     if ( (lon >= chart->west) && (lon <= chart->east) &&
  730.          (lat >= chart->south) && (lat <= chart->north) &&
  731.          (mag <= chart->maglim) )
  732.         {
  733.         xform(chart, lat, lon, &xloc, &yloc);
  734.         smallflag = vecmode = staronly = gkflag = 0;
  735.         switch(code[0])
  736.         {
  737.         case 'S': drawStar(xloc,yloc,(int)(mag+0.5),subcode[0],color);
  738.               staronly = 1;
  739.               break;
  740.         case 'P': drawPlan(xloc, yloc); break;
  741.         case 'N': drawNebu(xloc, yloc); break;
  742.         case 'G': drawGalx(xloc, yloc); break;
  743.         case 'C': drawClus(xloc, yloc); break;
  744.         case 'I': /* invisible */    break;
  745.         case 'V': vecmode = 1;
  746.               switch (subcode[0])    /* vector: check subcode */
  747.                   {
  748.                   case 'M': vecmove(xloc, yloc); break;
  749.                   case 'D': vecdrawdot(xloc, yloc); break;
  750.                   case 'H': vecdrawhyph(xloc, yloc); break;
  751.                   case 'S':    /* solid */
  752.                   default:  vecdraw(xloc, yloc); break;
  753.                   }
  754.               break;
  755.         }
  756.         if (((mag < chart->lbllim) || !staronly) && !vecmode)
  757.         {
  758. /*
  759.  * pick up object name or label if (star<limit), (nonstar), and (not vector)
  760.  */
  761.         ptr = NULL;
  762.         if (*name != '\0') ptr = name;    /* name > label */
  763.         else if (*label != '\0')
  764.             {
  765.             ptr = label;
  766.             if (staronly)
  767.             {
  768.             smallflag = 1;
  769.             ptr[2] = '\0';    /* snuff the IAU designation */
  770.                 if(islower(ptr[0]) || ptr[0] == 'E' || ptr[0] == 'O' ||
  771.                 ptr[0] == '@' || ptr[0] == '%')
  772.                 {
  773.                 gkflag = 1; /* Greek Bayer char(s) */
  774.                 if (ptr[1] == ' ') ptr[1] = '\0';
  775.                 }
  776.             }
  777.             }
  778.         if  (ptr != NULL)
  779.             {
  780.             vecsize( smallflag ? FSIZESML : FSIZELRG);
  781. /*
  782.  * vecsyms* --
  783.  * some x offset present to avoid overstriking corresponding object. Note
  784.  * that some bias is already precent (obj is center-align, text is left align)
  785.  */
  786.             if (gkflag) vecsymsgk(xloc+10, yloc, ptr);
  787.             else vecsyms(xloc+10, yloc, ptr);
  788.             }
  789.         }
  790.         }
  791.     }
  792.     }
  793.  
  794. /*
  795.  * Chart Construction
  796.  */
  797.  
  798. chartgrid(chart)
  799.     map chart;
  800.     {
  801.     charthgrid(chart, 15.0, 18);
  802.     charthgrid(chart, 5.0, 12);
  803.     charthgrid(chart, 1.0, 6);
  804.     chartvgrid(chart, 10.0, 18);
  805.     chartvgrid(chart, 5.0 , 12);
  806.     chartvgrid(chart, 1.0, 6);
  807.     }
  808.  
  809. chartoutline(chart)
  810.     map chart;
  811.     {
  812.     double start, inc;
  813.     int xloc, xloc2, yloc, yloc2, div, i;
  814.  
  815.     xform(chart, chart->south, chart->west, &xloc,  &yloc);
  816.     xform(chart, chart->south, chart->east, &xloc2, &yloc2);
  817.     vecmovedraw(xloc, yloc, xloc2, yloc2);
  818.     xform(chart, chart->north, chart->west, &xloc,  &yloc);
  819.     xform(chart, chart->north, chart->east, &xloc2, &yloc2);
  820.     vecmovedraw(xloc, yloc, xloc2, yloc2);
  821.  
  822.     inc = (chart->north - chart->south);
  823.     div = (int)(inc);
  824.     if (div < 1) div = 1;
  825.     inc /= div;
  826.     start = chart->south;
  827.     xform(chart, start, chart->west, &xloc, &yloc);
  828.     vecmove(xloc, yloc);
  829.     for (i=0; i < div; i++)
  830.     {
  831.     start += inc;
  832.     xform(chart, start, chart->west, &xloc, &yloc);
  833.     vecdraw(xloc, yloc);
  834.     }
  835.     start = chart->south;
  836.     xform(chart, start, chart->east, &xloc, &yloc);
  837.     vecmove(xloc, yloc);
  838.     for (i=0; i < div; i++)
  839.     {
  840.     start += inc;
  841.     xform(chart, start, chart->east, &xloc, &yloc);
  842.     vecdraw(xloc, yloc);
  843.     }
  844.     }
  845.  
  846. rastr(str, ras)
  847.     char *str;
  848.     double ras;
  849.     {
  850.     int hrs, min;
  851.     if (ras <   0.0) ras += 360.0;
  852.     if (ras > 360.0) ras -= 360.0;
  853.     hrs = (int)(ras/15.0);
  854.     min = (int)((ras - hrs * 15.0) * 4.0);
  855.     sprintf(str, "%2dh", hrs);
  856.     if (min) sprintf(str, "%s%02dm", str, min);
  857.     }
  858.  
  859. declstr(str, dl)
  860.     char *str;
  861.     double dl;
  862.     {
  863.     int deg, min;
  864.     if (dl == 0.0) sprintf(str, "%s", " ");
  865.     else if (dl > 0.0) sprintf(str, "%s", "+");
  866.     else
  867.     {
  868.     sprintf(str, "%s", "-");
  869.     dl = -dl;
  870.     }
  871.     deg = (int)(dl);
  872.     min = (int)((dl - deg) * 60.0);
  873.     sprintf(str, "%s%02dd", str, deg);
  874.     if (min) sprintf(str, "%s%02dm", str, min);
  875.     }
  876.  
  877. charthgrid(chart, inc, hgt)
  878.     map chart;
  879.     double inc;
  880.     {
  881. #define HTICKLIM 2
  882. #define HTEXTLIM 80
  883.     double start, stop, ras;
  884.     int xloc, xloc2, yloc, xloc3, yloc3;
  885.     start = modup(chart->west, inc);
  886.     stop = moddown(chart->east, inc);
  887.     xform(chart, chart->south, start, &xloc, &yloc);
  888.     xform(chart, chart->south, start+inc, &xloc2, &yloc);
  889.     if (xloc - xloc2 > HTICKLIM)
  890.     for (ras = start; ras <= stop; ras += inc)
  891.         {
  892.         xform(chart, chart->south, ras, &xloc3, &yloc3);
  893.         vecmovedraw(xloc3, yloc3-hgt, xloc3, yloc3);
  894.         if (xloc - xloc2 > HTEXTLIM)
  895.         {
  896.         char tstr[20];
  897.         rastr(tstr, ras);
  898.         vecsize(10);
  899.         vecsyms(xloc3+2, yloc-17, tstr);
  900.         }
  901.         }
  902.     }
  903.  
  904. chartvgrid(chart, inc, wid)
  905.     map chart;
  906.     double inc;
  907.     {
  908. #define VTICKLIM 2
  909. #define VTEXTLIM 20
  910.     double start, stop, dl;
  911.     int xloc, yloc, yloc2, xloc3, yloc3;
  912.     start = modup(chart->south, inc);
  913.     stop = moddown(chart->north, inc);
  914.     xform(chart, start, chart->west, &xloc, &yloc);
  915.     xform(chart, start+inc, chart->west, &xloc, &yloc2);
  916.     if (yloc2 - yloc > VTICKLIM)
  917.     {
  918.     for (dl = start; dl <= stop; dl += inc)
  919.         {
  920.         xform(chart, dl, chart->west, &xloc3, &yloc3);
  921.         vecmovedraw(xloc3, yloc3, xloc3+wid, yloc3);
  922.         if (yloc2 - yloc > VTEXTLIM)
  923.         {
  924.         char tstr[20];
  925.         declstr(tstr, dl);
  926.         vecsize(10);
  927.         vecsyms(xloc3+24, yloc3, tstr);
  928.         }
  929.         }
  930.     }
  931.     }
  932.  
  933. /*
  934.  * General Utilities
  935.  */
  936.  
  937. double max(a, b)
  938.     double a, b;
  939.     {
  940.     if (a>b) return(a);
  941.     return(b);
  942.     }
  943.  
  944. double modup(a, b)
  945.     double a, b;
  946.     {
  947.     double new;
  948.     new = ((double)((int)(a/b))*b);
  949.     if (new >= a) return(new);
  950.     return(new += b);
  951.     }
  952.  
  953. double moddown(a, b)
  954.     double a, b;
  955.     {
  956.     double new;
  957.     new = ((double)((int)(a/b))*b);
  958.     if (new <= a) return(new);
  959.     return (new -= b);
  960.     }
  961.  
  962. die(a,b)
  963.     char *a, *b;
  964.     {
  965.     fprintf(stderr,"%s: ", progname);
  966.     fprintf(stderr,a,b);
  967.     fprintf(stderr,"\n");
  968.     exit(1);
  969.     }
  970.  
  971. #define LINELEN 80
  972. static char legend[LINELEN];
  973.  
  974. findconst(tag)
  975. char *tag;
  976.      {
  977. /*
  978.  * lookup "con.locs" for a matching tag, and then substitute initial values
  979.  * for ra, decl, scale, and label. File layout follows:
  980.  *
  981.  * com  13    25   10   Coma Bereneces
  982.  * cor  15.45 28   10   Corona Borealis
  983.  * 0....+....1....+....2....+....3
  984.  */
  985.     char *newline;
  986.     FILE *cfile;
  987.     int taglen;
  988.     char cbuf[LINELEN+1];
  989.  
  990.     if ((cfile = fopen(CONSTFILE, "r")) == NULL)
  991.     die("open fail on %s", CONSTFILE);
  992.     taglen = strlen(tag);
  993.     if ((taglen < 3) || (taglen > 4))
  994.     die("constellation name must be three or four characters");
  995.     for (;;)
  996.     {
  997.     fgets(cbuf, LINELEN, cfile);
  998.     if (ferror(cfile)) die("read error in %s", CONSTFILE);
  999.     if (feof(cfile)) break;
  1000.     if (strncmp(tag, cbuf, taglen) == 0)    /* FOUND */
  1001.         {    
  1002.         sscanf(cbuf, "%*5s%f%f%f %[^\n]", &ra, &de, &sc, legend);
  1003.         ra    = ftod(ra);
  1004.         de    = ftod(de);
  1005.         if ((newline=index(legend, '\n')) != 0) *newline = '\0';
  1006.         title = legend;
  1007.         return;
  1008.         }
  1009.     }
  1010.     die("Constellation '%s' not found", tag);
  1011.     }
  1012.  
  1013. /*
  1014.  ! Future Development
  1015.  !
  1016.  ! Here is my "wish" list of items not added in this version (#2). I have
  1017.  ! intentionally included it here with the source code in an attempt to direct
  1018.  ! the course of further software development.
  1019.  !
  1020.  ! It is hoped that this will simplify the task of coordinating the eventual
  1021.  ! reintegration of new features created by such a large software community.
  1022.  ! Wishes are listed in rough order of simplicity and evolution.
  1023.  !
  1024.  ! Software:
  1025.  !
  1026.  ! [0] add glyphs for double stars/variable stars + Greek on bitmap devices.
  1027.  ! [1] write better PostScript macros.
  1028.  ! [2] integrate a "boundary.star" to draw constellation boundaries.
  1029.  ! [3] rewrite "moonphase" to add ra/decl information, merge into "planet.c".
  1030.  ! [4] break yale.star into constellation files (and remove "cons" field).
  1031.  ! [5] write "orbit.c" for asteroid overlays.
  1032.  ! [6] add a polar plot facility (round window?) for high declinations
  1033.  ! [7] rework planet.star to give planet tracks for a range of dates.
  1034.  !
  1035.  ! Database additions:
  1036.  !
  1037.  ! [1'] convert a larger database (9th-10th mag) into Yale format.
  1038.  ! [2'] Milky Way isophots
  1039.  ! [3'] Ecliptic track (dotted line vectors)
  1040.  ! [4'] IAU Constellation boundaries (see [2])
  1041.  !
  1042.  ! (comments)
  1043.  !
  1044.  ! [0] Is best facilitated by revising the image compiler in "starimages.c".
  1045.  ! [1] Would allow nice glyphs for non-stellar objects, scaled continuously
  1046.  !     to the right size. The code already provides a "halo" feature when
  1047.  !     generating stars in bright to dim (large to small) order, following
  1048.  !     a common aesthetic convention in many atlases. Variable stars are
  1049.  !     given rings, bars pass through double stars, etc., but a more
  1050.  !     comprehensive set of glyphs would be nice.
  1051.  !
  1052.  !     Starchart now allows user specified generation of text and vectors,
  1053.  !     which are useful for giving planet tracks across a range of dates, plus
  1054.  !     constellation boundaries, and possibly shapes of moon phases ([2], [3]).
  1055.  ! [2] I have access to such a database from UC Santa Cruz, and will request
  1056.  !     it once proven software is available. It would then be reworked into
  1057.  !     the "yale.star" format, using the move/draw commands of.
  1058.  ! [3] Burgess' book "Celestial Basic" gives routines for this, but lacks the
  1059.  !     precision of the work by Meesus (see planet.man). Done correctly, one
  1060.  !     should be able to check for eclipses, transits and occultations (this
  1061.  !     will require that "moonphase" know the user's geocentric latitude and
  1062.  !     longitude, due to the libration of the moon owing to parallax). This
  1063.  !     advanced version would print the profile of the moon's limb, with
  1064.  !     terminator. The "basic" version would just give a planet symbol.
  1065.  ! [4] Break-down by constellation would be a simple conceptual organization.
  1066.  !     It is also helpful to users requiring detailed finder charts of select
  1067.  !     regions. At the very least, the thirteen files for ecliptic-based
  1068.  !     constellation (~the Zodiac) would be quite helpful. The three character
  1069.  !     constellation field in the "label" field of the newer (but still
  1070.  !     reduced) version of yale.star would then go.
  1071.  ! [5] I have already produced tables of Keplerian elements for asteroids
  1072.  !     to the 10th mag. I also have code to read the data and solve for various
  1073.  !     related values (e.g. eccentric anomoly from mean anomoly). Left are
  1074.  !     the routines to find earth's position, plus the spherical trig needed
  1075.  !     to convert this into Ra and Decl. This would best be integrated into
  1076.  !     "planet.c", which already does the latter. Interested parties should
  1077.  !     e-mail me for the files "orbit.c" and "asteroids.el".
  1078.  ! [6] xcen and ycen would be ignored, and scale would give the limit of
  1079.  !     declination (90.0-scale). Provisions to choose which pole needed, too.
  1080.  !     I believe stereographic projection would be the best, being both
  1081.  !     conformal and preserving of circles (as circles of new radii).
  1082.  ! [7] A complete rework would probably also place moon and asteroid calcs
  1083.  !     here, in addition to generating "track" output records.
  1084.  !
  1085.  ! [1'] Electronic databases to the 10th mag rumored to exist, containing on
  1086.  !    the order of 40000 stars. Don't ask me where to find them.
  1087.  ! [2'] No idea where to find
  1088.  ! [3'] Should not be too hard
  1089.  */
  1090. @//E*O*F starchart.c//
  1091. chmod u=rwx,g=rx,o=rx starchart.c
  1092.  
  1093. echo x - stardsp.c
  1094. sed 's/^@//' > "stardsp.c" <<'@//E*O*F stardsp.c//'
  1095. /*
  1096.  * TTY Display driver for starchart.c mainline
  1097.  */
  1098.  
  1099. #include <stdio.h>
  1100. #include <ctype.h>
  1101. #include "starchart.h"
  1102.  
  1103. #define MAX(a,b) ((a)>(b)?(a):(b))
  1104. #define ROWS 32
  1105. #define COLS 79
  1106.  
  1107. /*
  1108.  * Chart parameters (limiting magnitude and window x,y,w,h)
  1109.  */
  1110.  
  1111. mapblock thumbnail =    { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
  1112.             3.0, 1.0, 420, 35, 480, 195, 0.0 };
  1113.  
  1114. mapblock master =    { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
  1115.             5.9, 2.0, 20, 265, 880, 500, 0.0 };
  1116.  
  1117. /*
  1118.  * Generic Star Drawing Stuff
  1119.  */
  1120.  
  1121. static int oldx, oldy, scrx, scry;
  1122. static char **linevec;
  1123.  
  1124. vecopen()
  1125.    {
  1126.    int i;
  1127.    linevec = (char**)(calloc(ROWS, sizeof(char*)));
  1128.    for (i=0; i<ROWS; i++) linevec[i] = (char*)(calloc(COLS, sizeof(char)));
  1129.    }
  1130.  
  1131. vecclose()
  1132.     {
  1133.     int i, j, k;
  1134.     char c;
  1135.     for (i=0; i<ROWS; i++)
  1136.     {
  1137.     for (j=COLS-1; j>0; j--) if (linevec[i][j]) break;
  1138.     for (k=0; k<=j; k++) putchar((c=linevec[i][k]) ? c : ' ');
  1139.     putchar('\n');
  1140.     free(linevec[i]);
  1141.     }
  1142.     fflush(stdout);
  1143.     free(linevec);
  1144.     }
  1145.  
  1146. vecsize(points)
  1147.     int points;
  1148.     {
  1149.     }
  1150.  
  1151. vecmove(x, y)
  1152.     {
  1153.     oldx = x;
  1154.     oldy = y;
  1155.     scrx = (x*COLS+512)/1024;
  1156.     scry = (((768-y)*ROWS)+384)/768;
  1157.     }
  1158.  
  1159. vecdrawdot(x, y)
  1160.     {
  1161.     vecdraw(x, y); /* dotted and solid the same */
  1162.     }
  1163.  
  1164. vecdrawhyph(x, y)
  1165.     {
  1166.     vecdraw(x, y); /* dashed (hyphen) and solid the same */
  1167.     }
  1168.  
  1169. vecdraw(x, y)
  1170.     {
  1171.     int dx, dy, savex, savey, i, steps;
  1172.     char c;
  1173.     savex = oldx;
  1174.     savey = oldy;
  1175.     dx = x-oldx;
  1176.     dy = y-oldy;
  1177.     c = (abs(dx) > abs(dy)) ? '-' : '|';
  1178.     steps = MAX(MAX(abs(dx),abs(dy))/12, 1);
  1179.     for(i=0; i<=steps; i++)
  1180.     {
  1181.     vecmove(savex+(i*dx+steps/2)/steps,savey+(i*dy+steps/2)/steps);
  1182.     sym(c);
  1183.     }
  1184.     }
  1185.  
  1186. vecsyms(x, y, s)
  1187.     char *s;
  1188.     {
  1189.     char c;
  1190.     vecmove(x, y);
  1191.     while(c = *s++)
  1192.     {
  1193.     sym(c);
  1194.     scrx++;
  1195.     }
  1196.     }
  1197.  
  1198. vecmovedraw(x1, y1, x2, y2)
  1199.     {
  1200.     vecmove(x1, y1);
  1201.     vecdraw(x2, y2);
  1202.     }
  1203.  
  1204. drawPlan(x, y)
  1205.     {
  1206.     vecsyms(x, y, "+");
  1207.     }
  1208.  
  1209. drawStar(x, y, mag, type, color)
  1210.     char type, *color;
  1211.     {
  1212.     switch (mag)
  1213.     {
  1214.     case -1: draw0(x, y); break;
  1215.     case  0: draw0(x, y); break;
  1216.     case  1: draw1(x, y); break;
  1217.     case  2: draw2(x, y); break;
  1218.     case  3: draw3(x, y); break;
  1219.     case  4: draw4(x, y); break;
  1220.     default: draw5(x, y); break;
  1221.     }
  1222.     }
  1223.  
  1224. draw0(x, y)
  1225.     {
  1226.     vecsyms(x, y, "O");
  1227.     }
  1228.  
  1229. draw1(x, y)
  1230.     {
  1231.     vecsyms(x, y, "*");
  1232.     }
  1233.  
  1234. draw2(x, y)
  1235.     {
  1236.     vecsyms(x, y, "o");
  1237.     }
  1238.  
  1239. draw3(x, y)
  1240.     {
  1241.     vecsyms(x, y, "-");
  1242.     }
  1243.  
  1244. draw4(x, y)
  1245.     {
  1246.     vecsyms(x, y, ",");
  1247.     }
  1248.  
  1249. draw5(x, y)
  1250.     {
  1251.     vecsyms(x, y, ".");
  1252.     }
  1253.  
  1254. drawGalx(x, y)
  1255.     {
  1256.     vecsyms(x, y, "@");
  1257.     }
  1258.  
  1259. drawNebu(x, y)
  1260.     {
  1261.     vecsyms(x, y, "~");
  1262.     }
  1263.  
  1264. drawClus(x, y)
  1265.     {
  1266.     vecsyms(x, y, "%");
  1267.     }
  1268.  
  1269. char overwrite(under, over)
  1270.     char under, over;
  1271.     {
  1272.     if (over == under) return(over);
  1273.     if (!under) return(over);
  1274.     if (!over) return(under);
  1275.     if (isspace(under)) return(over);
  1276.     if (isspace(over)) return(under);
  1277.     if (over == '%') return(over);
  1278.     if (over == '~') return(over);
  1279.     if (over == '@') return(over);
  1280.     if (under == '%') return(under);
  1281.     if (under == '~') return(under);
  1282.     if (under == '@') return(under);
  1283.     if ( isalnum(under) &&  isalnum(over)) return(over);
  1284.     if (!isalnum(under) &&  isalnum(over)) return(over);
  1285.     if ( isalnum(under) && !isalnum(over)) return(under);
  1286.     if ((under == '-') && (over == '|')) return('+');
  1287.     if ((under == '|') && (over == '-')) return('+');
  1288.     if ((under == '+') && (over == '-')) return('+');
  1289.     if ((under == '+') && (over == '|')) return('+');
  1290.     if ((under == ',') && (over == '.')) return(';');
  1291.     if ((under == '.') && (over == ',')) return(';');
  1292.     if ((under == '.') && (over == '.')) return(':');
  1293.     if ((under == '|') && (over == '.')) return('!');
  1294.     if ((under == '|') && (over == ',')) return('!');
  1295.     if ((under == '.') && (over == '|')) return('!');
  1296.     if ((under == ',') && (over == '|')) return('!');
  1297.     if ((under == '.') && (over == '.')) return(':');
  1298.     return(under);
  1299.     }
  1300.  
  1301. sym(c)
  1302.     char c;
  1303.     {
  1304.     if ( (scrx >= 0) && (scrx < COLS) &&
  1305.      (scry >= 0) && (scry < ROWS) )
  1306.     linevec[scry][scrx] = overwrite(linevec[scry][scrx], c );
  1307.     }
  1308.  
  1309. vecsymsgk(str, x, y)
  1310.     char *str;
  1311.     {
  1312.     vecsyms(str, x, y);
  1313.     }
  1314. @//E*O*F stardsp.c//
  1315. chmod u=rwx,g=rwx,o=rwx stardsp.c
  1316.  
  1317. echo x - starhp.c
  1318. sed 's/^@//' > "starhp.c" <<'@//E*O*F starhp.c//'
  1319. /*
  1320. ** Hewlett-Packard 2623 (and equivalent) graphics terminal
  1321. ** driver for starchart.
  1322. ** Low-level routines (starting with 'HP') written and copyrighted by
  1323. ** Jyrki Yli-Nokari (jty@intrin.FI),
  1324. ** Petri Launiainen (pl@intrin.FI),
  1325. ** Intrinsic, Ltd.,  FINLAND.
  1326. **
  1327. ** You may use this code as you wish if credit is given and this message
  1328. ** is retained.
  1329. */
  1330.  
  1331. /*
  1332. ** Star scaling is changed to happen only for the placement,
  1333. ** therefore the stars look always nice
  1334. */
  1335.  
  1336. #include <stdio.h>
  1337. #include "starchart.h"
  1338.  
  1339. #define SCALEU    1
  1340. #define SCALEL    2
  1341.  
  1342. /*
  1343. ** Chart parameters (limiting magnitude and window x,y,w,h)
  1344. */
  1345.  
  1346. mapblock thumbnail =    { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
  1347.             3.2, 1.0, 420, 35, 480, 195, 0.0 };
  1348.  
  1349. mapblock master =    { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
  1350.             8.0, 3.0, 20, 265, 880, 500, 0.0 };
  1351.  
  1352. /*
  1353. ** Generic functions
  1354. */
  1355.  
  1356. vecopen ()
  1357. {
  1358.     HPplot ();
  1359.     HPclear ();
  1360. }
  1361.  
  1362. vecclose ()
  1363. {
  1364.     fflush (stdout);
  1365. }
  1366.  
  1367. vecsize (points)
  1368. int points;
  1369. {
  1370. }
  1371.  
  1372. vecmove (x, y)
  1373. int x,y;
  1374. {
  1375.     x = SCALEU*x/SCALEL; /* adjust to screen size */
  1376.     y = SCALEU*y/SCALEL;
  1377.  
  1378.     HPmove (x, y);
  1379. }
  1380.  
  1381. vecdraw (x, y)
  1382. int x,y;
  1383. {
  1384.     x = SCALEU*x/SCALEL; /* adjust to screen size */
  1385.     y = SCALEU*y/SCALEL;
  1386.  
  1387.     HPdraw (x, y);
  1388. }
  1389.  
  1390. vecdrawdot(x, y)
  1391.     {
  1392.     vecdraw(x, y);    /* solid and dotted currently the same */
  1393.     }
  1394.  
  1395. vecdrawhyph(x, y)
  1396.     {
  1397.     vecdraw(x, y);    /* solid and dashed currently the same */
  1398.     }
  1399.     
  1400. xvecsym (x, y, s)
  1401. int x,y;
  1402. char s;
  1403. {
  1404.     y -= 11; /* center character strings */
  1405.     x = SCALEU*x/SCALEL; /* adjust to screen size */
  1406.     y = SCALEU*y/SCALEL;
  1407.  
  1408.     HPmove (x, y-11); /* center character strings */
  1409.     HPalpha_on ();
  1410.     putchar (s);
  1411.     HPalpha_off ();
  1412. }
  1413.  
  1414. vecsyms (x, y, s)
  1415. int x,y;
  1416. char *s;
  1417. {
  1418.     y -= 11; /* center character strings */
  1419.     x = SCALEU*x/SCALEL; /* adjust to screen size */
  1420.     y = SCALEU*y/SCALEL;
  1421.  
  1422.     HPmove (x, y);
  1423.     HPalpha_on ();
  1424.     fputs (s, stdout);
  1425.     HPalpha_off ();
  1426. }
  1427.  
  1428. vecmovedraw (x1, y1, x2, y2)
  1429. int x1, x2, y1, y2;
  1430. {
  1431.     x1 = SCALEU*x1/SCALEL; /* adjust to screen size */
  1432.     y1 = SCALEU*y1/SCALEL;
  1433.  
  1434.     x2 = SCALEU*x2/SCALEL; /* adjust to screen size */
  1435.     y2 = SCALEU*y2/SCALEL;
  1436.  
  1437.     HPmove (x1, y1);
  1438.     HPdraw (x2, y2);
  1439. }
  1440.  
  1441. drawlen (x, y, dx, dy, len)
  1442. int x, y, dx, dy, len;
  1443. {
  1444.     x = SCALEU*x/SCALEL; /* adjust to screen size */
  1445.     y = SCALEU*y/SCALEL;
  1446.  
  1447.     HPmove (x + dx, y + dy);
  1448.     HPdraw (x + dx + len - 1, y+dy);
  1449. }
  1450.  
  1451. /*
  1452. ** Low Level HP Plotting Routines
  1453. */
  1454.  
  1455. HPplot ()    /* switch to plot mode */
  1456. {
  1457.     fputs ("\033*dcl0,0P\033&k1O\033*m1g", stdout);
  1458. /*
  1459. **    1. Enable graphics display.
  1460. **    2. Disable cursor.
  1461. **    3. Locate cursor to origin.
  1462. **    4. Enable Graphics pad.
  1463. **    5. Solid area fill
  1464. */
  1465. }
  1466.  
  1467. HPalpha_on ()    /* switch to alpha mode */
  1468. {
  1469.     fputs ("\033*dS", stdout);
  1470. }
  1471.  
  1472. HPalpha_off ()    /* switch back to plot mode */
  1473. {
  1474.     fputs ("\033*dT", stdout);
  1475. }
  1476.  
  1477. HPclear ()
  1478. {
  1479.     fputs ("\033*dA\033*m2a1B", stdout);
  1480. /*
  1481. **    1. Clear graphics screen.
  1482. **    2. Draw in "set pixel" mode.
  1483. **    3. Select solid line.
  1484. */
  1485.     fflush (stdout);
  1486. }
  1487.  
  1488. HPmove (x, y)    /* move to (x,y) */
  1489. int x, y;
  1490. {
  1491.     printf ("\033*pa%d,%dZ", x, y);
  1492. }
  1493.  
  1494. HPdraw (x, y)    /* draw to (x,y) */
  1495. int x, y;
  1496. {
  1497.     printf ("\033*pb%d,%dZ", x, y);
  1498. }
  1499.  
  1500. vecsymsgk(str, x, y)
  1501.     char *str;
  1502.     {
  1503.     vecsyms(str, x, y);
  1504.     }
  1505. @//E*O*F starhp.c//
  1506. chmod u=rwx,g=rwx,o=rwx starhp.c
  1507.  
  1508. echo x - starimages.c
  1509. sed 's/^@//' > "starimages.c" <<'@//E*O*F starimages.c//'
  1510. /*
  1511. ** This file defines the star and planet images for vector type devices.
  1512. ** All vector formed images are here (for tektronix, hp series and laserjet)
  1513. **
  1514. ** Original images by Alan W. Paeth, dynamic 'star compilation' and
  1515. ** cluster/galaxy images added by (pl) 15-Mar-87
  1516. */
  1517.  
  1518. #include <stdio.h>
  1519. #define IMAROWS        20
  1520. #define IMACOLS        20        /* both should be more than plenty */
  1521. #define ENDCOORD    32767        /* should be out of offset range */
  1522.  
  1523. /**********************************************************************
  1524. **
  1525. ** cstar:
  1526. **
  1527. ** Parameters:
  1528. **    ptr        char pointer to star row, or NULL to compile
  1529. **
  1530. ** Function:
  1531. **    'compiles' star image data for starlen from char pointers given
  1532. **    this method simplifies the creation and updating of images.
  1533. **    Image can consist of max IMAROWS of data, and the maximum
  1534. **    length/row is IMACOLS.  The lengths of rows MUST be equal !!
  1535. **
  1536. ** Returns:
  1537. **    NULL when ptr != NULL, pointer to allocated vector defining
  1538. **    drawlen information and ending to ENDCOORD value when ptr == NULL
  1539. **
  1540. ** History:
  1541. ** 
  1542. */
  1543. int *
  1544. cstar (ptr)
  1545. char *ptr;
  1546. {
  1547.     static int n;                /* number of lines gathered */
  1548.     static int len;                /* longest line found */
  1549.     static char image [IMAROWS][IMACOLS+1];    /* image data area */
  1550.     int cx, cy;                /* center points */
  1551.     int *retarea;
  1552.     int i,j, x, y, s, l;
  1553.     
  1554.     /*
  1555.      ** this is a two state machine - first it just gathers ptr strings
  1556.     ** until NULL is given, then it 'compiles' the previous strings
  1557.     ** and returns offset values for printing the star.
  1558.     */
  1559.  
  1560.     if  (ptr != NULL) {            /* gather */
  1561.         strcpy (image [n++], ptr);    /* copy data */
  1562.         cx = strlen (ptr);        /* get max len */
  1563.         if  (cx > len)
  1564.             len = cx;
  1565.         return NULL;
  1566.     }
  1567. /*    else {                    /* start 'compilation' */
  1568.     cy = n / 2;                /* align */
  1569.     cx = len / 2;
  1570.  
  1571.     /*
  1572.     ** allocate offset area
  1573.     */
  1574.     retarea = (int *) calloc 
  1575.         (len * n * (n / 2 + 1) * 3 + 1, sizeof (int));
  1576.     if  (retarea == NULL) {
  1577.         perror ("Memory allocation failed");
  1578.         exit (2);
  1579.     }
  1580.     /*
  1581.     ** fill return area
  1582.     */
  1583.     j = 0;
  1584.     for (i = 0; i < n; i++) {
  1585.         l = 0;  s = 0;  x = 0;
  1586.         ptr = image [i];
  1587.         while (*ptr) {
  1588.             if  (*ptr == ' ') {
  1589.                 if  (l) { /* flush */
  1590.                     retarea [j++] = s - cx;
  1591.                     retarea [j++] = i - cy;
  1592.                     retarea [j++] = l;
  1593.                             
  1594.                     l = 0;
  1595.                 }
  1596.             }
  1597.             else {
  1598.                 if  (l)
  1599.                     l++;
  1600.                 else {
  1601.                     s = x;
  1602.                     l = 1;
  1603.                 }
  1604.             }
  1605.             ptr++;
  1606.             x++;
  1607.         } /* while */
  1608.         if  (l) { /* flush */
  1609.             retarea [j++] = s - cx;
  1610.             retarea [j++] = i - cy;
  1611.             retarea [j++] = l;
  1612.         }
  1613.     } /* for */
  1614.     n = 0;
  1615.     retarea [j] = ENDCOORD;
  1616.     return retarea;
  1617. } /* cstar */
  1618.  
  1619. drawPlan(x, y)
  1620. int x,y;
  1621. {
  1622.     static int def, *coord;
  1623.     int i;
  1624.  
  1625.     if  (! def) {
  1626.         def = 1;
  1627.         (void) cstar (" *** ");
  1628.         (void) cstar ("*   *");
  1629.         (void) cstar ("*****");
  1630.         (void) cstar ("*   *");
  1631.         (void) cstar (" *** ");
  1632.         coord = cstar (NULL);
  1633.     }
  1634.  
  1635.     i = 0;
  1636.     while (coord [i] != ENDCOORD) {
  1637.         drawlen (x, y, coord [i], coord [i+1], coord [i+2]);
  1638.         i += 3;
  1639.     }
  1640. }
  1641.  
  1642. drawStar (x, y, mag, type, color)
  1643. int x, y, mag;
  1644. char type, *color;
  1645.     {
  1646.     switch (mag)
  1647.     {
  1648.     case -1:
  1649.     case  0: draw0 (x, y); break;
  1650.     case  1: draw1 (x, y); break;
  1651.     case  2: draw2 (x, y); break;
  1652.     case  3: draw3 (x, y); break;
  1653.     case  4: draw4 (x, y); break;
  1654.     default: draw5 (x, y); break;
  1655.     }
  1656.     }
  1657.  
  1658. draw0(x, y)
  1659. int x, y;
  1660.     {
  1661.     static int def, *coord;
  1662.     int i;
  1663.     if  (! def)
  1664.     {
  1665.     def = 1;
  1666.        (void) cstar (" ***** ");
  1667.     (void) cstar ("*******");
  1668.     (void) cstar ("*** ***");
  1669.     (void) cstar ("**   **");
  1670.     (void) cstar ("*** ***");
  1671.     (void) cstar ("*******");
  1672.     (void) cstar (" ***** ");
  1673.     coord = cstar (NULL);
  1674.         }
  1675.     i = 0;
  1676.     while (coord [i] != ENDCOORD)
  1677.         {
  1678.     drawlen (x, y, coord [i], coord [i+1], coord [i+2]);
  1679.     i += 3;
  1680.     }
  1681.     }
  1682.  
  1683. draw1(x, y)
  1684. int x, y;
  1685. {
  1686.     static int def, *coord;
  1687.     int i;
  1688.  
  1689.     if  (! def) {
  1690.         def = 1;
  1691.            (void) cstar (" *** ");
  1692.         (void) cstar ("*****");
  1693.         (void) cstar ("*****");
  1694.         (void) cstar ("*****");
  1695.         (void) cstar (" *** ");
  1696.         coord = cstar (NULL);
  1697.     }
  1698.  
  1699.     i = 0;
  1700.     while (coord [i] != ENDCOORD) {
  1701.         drawlen (x, y, coord [i], coord [i+1], coord [i+2]);
  1702.         i += 3;
  1703.     }
  1704. }
  1705.  
  1706. draw2(x, y)
  1707. int x, y;
  1708. {
  1709.     static int def, *coord;
  1710.     int i;
  1711.  
  1712.     if  (! def) {
  1713.         def = 1;
  1714.            (void) cstar ("  *  ");
  1715.         (void) cstar (" *** ");
  1716.         (void) cstar ("*****");
  1717.         (void) cstar (" *** ");
  1718.         (void) cstar ("  *  ");
  1719.         coord = cstar (NULL);
  1720.     }
  1721.  
  1722.     i = 0;
  1723.     while (coord [i] != ENDCOORD) {
  1724.         drawlen (x, y, coord [i], coord [i+1], coord [i+2]);
  1725.         i += 3;
  1726.     }
  1727. }
  1728.  
  1729. draw3(x, y)
  1730. int x, y;
  1731. {
  1732.     static int def, *coord;
  1733.     int i;
  1734.  
  1735.     if  (! def) {
  1736.         def = 1;
  1737.         (void) cstar ("***");
  1738.         (void) cstar ("***");
  1739.         (void) cstar ("***");
  1740.         coord = cstar (NULL);
  1741.     }
  1742.  
  1743.     i = 0;
  1744.     while (coord [i] != ENDCOORD) {
  1745.         drawlen (x, y, coord [i], coord [i+1], coord [i+2]);
  1746.         i += 3;
  1747.     }
  1748. }
  1749.  
  1750. draw4(x, y)
  1751. int x, y;
  1752. {
  1753.     static int def, *coord;
  1754.     int i;
  1755.  
  1756.     if  (! def) {
  1757.         def = 1;
  1758.         (void) cstar (" * ");
  1759.         (void) cstar ("***");
  1760.         (void) cstar (" * ");
  1761.         coord = cstar (NULL);
  1762.     }
  1763.  
  1764.     i = 0;
  1765.     while (coord [i] != ENDCOORD) {
  1766.         drawlen (x, y, coord [i], coord [i+1], coord [i+2]);
  1767.         i += 3;
  1768.     }
  1769. }
  1770.  
  1771. draw5(x, y)
  1772. int x, y;
  1773. {
  1774.     static int def, *coord;
  1775.     int i;
  1776.  
  1777.     if  (! def) {
  1778.         def = 1;
  1779.         (void) cstar ("*");
  1780.         coord = cstar (NULL);
  1781.     }
  1782.  
  1783.     i = 0;
  1784.     while (coord [i] != ENDCOORD) {
  1785.         drawlen (x, y, coord [i], coord [i+1], coord [i+2]);
  1786.         i += 3;
  1787.     }
  1788. }
  1789.  
  1790. drawGalx(x, y)
  1791. int x, y;
  1792. {
  1793.     static int def, *coord;
  1794.     int i;
  1795.  
  1796.     if  (! def) {
  1797.         def = 1;
  1798.            (void) cstar (" *** ");
  1799.         (void) cstar ("*    ");
  1800.         (void) cstar (" *** ");
  1801.         (void) cstar ("    *");
  1802.         (void) cstar (" *** ");
  1803.         coord = cstar (NULL);
  1804.     }
  1805.  
  1806.     i = 0;
  1807.     while (coord [i] != ENDCOORD) {
  1808.         drawlen (x, y, coord [i], coord [i+1], coord [i+2]);
  1809.         i += 3;
  1810.     }
  1811. }
  1812.  
  1813. drawClus(x, y)
  1814. int x, y;
  1815. {
  1816.     static int def, *coord;
  1817.     int i;
  1818.  
  1819.     if  (! def) {
  1820.         def = 1;
  1821.            (void) cstar (" * * ");
  1822.         (void) cstar ("* * *");
  1823.         (void) cstar (" * * ");
  1824.         coord = cstar (NULL);
  1825.     }
  1826.  
  1827.     i = 0;
  1828.     while (coord [i] != ENDCOORD) {
  1829.         drawlen (x, y, coord [i], coord [i+1], coord [i+2]);
  1830.         i += 3;
  1831.     }
  1832. }
  1833.  
  1834. drawNebu(x, y)
  1835. int x, y;
  1836. {
  1837.     static int def, *coord;
  1838.     int i;
  1839.  
  1840.     if  (! def) {
  1841.         def = 1;
  1842.            (void) cstar (" ** ");
  1843.         (void) cstar ("*  *");
  1844.         (void) cstar (" ** ");
  1845.         coord = cstar (NULL);
  1846.     }
  1847.  
  1848.     i = 0;
  1849.     while (coord [i] != ENDCOORD) {
  1850.         drawlen (x, y, coord [i], coord [i+1], coord [i+2]);
  1851.         i += 3;
  1852.     }
  1853. }
  1854. @//E*O*F starimages.c//
  1855. chmod u=rwx,g=rwx,o=rwx starimages.c
  1856.  
  1857. exit 0
  1858.  
  1859.