From: skf5055@tamuts.tamu.edu (Shawn Keith Fox)
Subject: Re: psmap
Organization: Texas A&M University, College Station
Date: Wed, 14 Oct 1992 19:19:27 GMT

Hmmm...  I thought psmap.c was on scam.berkeley.edu, but apparently it
isn't, so I will go ahead and post the code so that anyone else who 
wants it can get it as well.

Shawn Fox
MR

----------------------------Cut Here------------------------------------
#include "stdio.h"

/* starmap.c                                                           */
/* produces a Postscript map from the output of the GB command 'stars' */
/* Copyright: Andreas Girgensohn (andreasg@cs.colorado.edu)            */

struct star {
  int   x,
        y;
  char  name[80];
};

struct star stars[200];
int   nstars,
      highlight_home = 1,
      highlighted_star = -1,	/* star that will be highlighted */
      nrings = 8,		/* number of distance rings around the
				   highlighted star */
      ring_spacing = 50000;

main (argc, argv)
int   argc;
char *argv[];
{
  scan_stars (stdin);
  if (nstars == 0)
    fprintf (stderr, "No stars\n");
  else
    produce_postscript ();
  exit (0);
}

scan_stars (fin)
FILE * fin;
{
  char  line[200];
  int   distance,
        in_stars = 0;

  nstars = 0;
  while (fgets (line, 200, fin) != NULL) {
    if (sscanf (line, "(%*d) %79s ( %d, %d) %d", stars[nstars].name,
	  &(stars[nstars].x), &(stars[nstars].y), &distance) == 4) {
      if (highlight_home && distance == 0)
	highlighted_star = nstars;
      nstars++;
      if (!in_stars)
	in_stars = 1;
    }
    else
      if (in_stars)
	break;
  }
}

produce_postscript () {
  int   min_x,
        max_x,
        min_y,
        max_y,
        i;
  double  scale,
          nscale;

  min_x = max_x = stars[0].x;
  min_y = max_y = stars[0].y;
  for (i = 1; i < nstars; i++) {
    if (stars[i].x < min_x)
      min_x = stars[i].x;
    if (stars[i].x > max_x)
      max_x = stars[i].x;
    if (stars[i].y < min_y)
      min_y = stars[i].y;
    if (stars[i].y > max_y)
      max_y = stars[i].y;
  }
  /* max map size: 8.5in x 11in sheet, 0.5in borders, */
  /* 0.5in on the right for star names */
  /* 72 points = 1in */
  scale = 7.0 * 72 / (max_x - min_x);
  nscale = 10.0 * 72 / (max_y - min_y);
  if (nscale < scale)
    scale = nscale;
  printf ("%%!PS-Adobe-2.0\n\n");
  /* 0,0 is in the topleft corner */
  printf ("0.5 72 mul 10.5 72 mul translate\n");
  printf ("/drawcircle\n");
  printf ("{\n");
  printf ("  newpath 0 360 arc stroke\n");
  printf ("}\n");
  printf ("def\n\n");
  printf ("/drawstar\n");
  printf ("{\n");
  printf ("  /starname exch def\n");
  printf ("  /ypos exch def\n");
  printf ("  /xpos exch def\n");
  printf ("  xpos ypos 2 drawcircle\n");
  printf ("  4 xpos add ypos moveto\n");
  printf ("  starname show\n");
  printf ("}\n");
  printf ("def\n\n");
  printf ("0 setlinewidth\n");
  printf ("newpath -10 10 moveto 7.5 72 mul 10 add 10 lineto\n");
  printf ("7.5 72 mul 10 add %d lineto -10 %d lineto closepath clip\n",
      (int) ((min_y - max_y) * scale) - 10,
      (int) ((min_y - max_y) * scale) - 10);
  if (highlighted_star >= 0 && highlighted_star < nstars) {
    printf ("\n/Times-Bold findfont 9 scalefont setfont\n\n");
    draw_star (stars + highlighted_star, min_x, min_y, scale);
    for (i = 1; i <= nrings; i++)
      printf ("%d %d %d drawcircle\n",
	  (int) ((stars[highlighted_star].x - min_x) * scale),
	  (int) ((min_y - stars[highlighted_star].y) * scale),
	  (int) (i * ring_spacing * scale));
  }
  printf ("\n/Times-Roman findfont 8 scalefont setfont\n\n");
  for (i = 0; i < nstars; i++)
    if (i != highlighted_star)
      draw_star (stars + i, min_x, min_y, scale);
  printf ("\nshowpage\n");
}

draw_star (star, min_x, min_y, scale)
struct star *star;
int   min_x,
      min_y;
double  scale;
{
  printf ("%d %d (%s) drawstar\n", (int) ((star -> x - min_x) * scale),
      (int) ((min_y - star -> y) * scale), star -> name);
}