Article 12758 of alt.sources:
Path: nntpd.lkg.dec.com!pa.dec.com!src.dec.com!crl.dec.com!crl.dec.com!bloom-beacon.mit.edu!spool.mu.edu!newspump.wustl.edu!crcnews.unl.edu!backbone!backbone!wayne
From: wayne@backbone.uucp (Wayne Schlitt)
Newsgroups: alt.sources
Subject: XStar-2.0.0  Orbiting star system simulator    Part06/06
Date: Sun, 27 Aug 1995 23:15:48 GMT
Organization: The Backbone Cabal
Lines: 1078
Sender: wayne@backbone (Wayne Schlitt)
Message-ID: <WAYNE.95Aug27171548@backbone.uucp>
Reply-To: wayne@cse.unl.edu
NNTP-Posting-Host: cse.unl.edu
Originator: wayne@cse.unl.edu


Submitted-by: wayne@backbone.UUCP
Archive-name: XStar-2.0.0/part06


--- cut here ---

# Continuation of Shell Archive, created by backbone!wayne

# This is part 6

# To unpack the enclosed files, please use this file as input to the
# Bourne (sh) shell.  This can be most easily done by the command;
#     sh < thisfilename


# ---------- file xstar.h ----------

filename="xstar.h"

if [ -f $filename ]
then
  echo File \"$filename\" already exists\!  Skipping...
  filename=/dev/null		# throw it away
else
  echo extracting file xstar.h...
fi

cat << 'END-OF-FILE' > $filename
#ifndef include_xstar
#define include_xstar


/*
** XStar -- a animated n-body solver for X windows
** Copyright (C) 1995  Wayne Schlitt (wayne@cse.unl.edu) and others
**
**  This program is free software; you can redistribute it and/or modify
**  it under the terms of the GNU General Public License as published by
**  the Free Software Foundation; either version 2 of the License, or
**  (at your option) any later version.
*/



#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <unistd.h>


/* standard POSIX typedefs */
#ifdef NEEDS_TYPEDEFS
typedef	unsigned char	uchar_t;
typedef	unsigned short	ushort_t;
typedef	unsigned int	uint_t;
typedef	unsigned long	ulong_t;
#endif


/* Constants */

/* Fudge factors
 *
 * The higher FV is, the slower the system runs, but the more accurately it
 * runs.  If you see stars shooting off very quickly when they get close
 * together, then that is a sign that FV is way too small.  If you notice that
 * the star system gains energy over time (stars are moving further out),
 * then that is a sign that FV is not large enough.  In general, the larger
 * FV, the longer the star system will continue to have "interesting" 
 * interactions because all of the stars will stay on the screen.
 *
 * If you see the user falling a sleep because things are running so
 * slowly, then that is a sign that FV is too large.  If you see both
 * things happening, that that is a sign that you need a faster
 * computer.
 *
 *
 * The higher FM is, the more massive the star systems will be and the more
 * the stars will tend to fall in toward the center.  This constant used
 * to have a major effect on init_star(), but it has since been re-written
 * and there are only a few spots where change FM will not have the same
 * effect as changing FV.
 *
 * Note:  These fudge factors are best changed by the -a command line option.
 */
#define FV	(.8)			/* larger values => slower movement */
#define FG	(16.0)			/* don't change			*/
#define FM	(1.0/(16*FG*FV*FV))	/* larger values => move attraction */

/* #define G ((FG*FG)/256.) */
#define G	(1.0)			/* gravitation const (in funny units)*/


/*
 * Units:	xstar	normal
 * distance	1	1 millimeter
 * mass		1	1 gram
 * time		1	8.16859841099e-9 s	(?? is this right?)
 *
 * G = 6.6726E-11 N*m^2/kg^2 = 6.6726E-11 (kg*m/s^2)*m^2/kg^2
 *   = 6.6726E-11 m^3/(s^2 kg)
 */

#ifndef NUM_COLORS
#define NUM_COLORS 48	  /* numbers of colors to rotate through	*/
			  /* limited to a max of 64 by disp_star_type   */
#endif


#define TRUE 1
#define FALSE 0
#define STD_STR 100
#define STARS   15			/* number of stars */
#define DELAY   0			/* microsecond delay between updates */
#define STARAREA 11500.0		/* how crowded stars should be */
#define COLLAPSAR (16.0)		/* mass of a collapsar		*/
#define WINWIDTH 512			/* default window width */
#define WINHEIGHT 512			/* default window height */
#define WINMIN	128			/* minimum window size	*/
#define ALIVE_MASK      (SubstructureNotifyMask | KeyPressMask | PointerMotionMask)
#define MAX_CVAL	65535		/* maximum value of a color	*/
#define POLL_SKIP	64		/* keep a power of 2		*/
#define MAX_COLLAPSAR	6		/* max number of initial collapsars */
#define DEFAULT_COLLIDE 1.		/* default collide distance	*/

#define MAX_NUM_STARS	((1<<8)-1)	/* maximum number of stars allowed */
					/* as limited by disp_star_type.*/
					/* the last star is used as a flag */

#define K	9			/* # of prev values of a,v to keep  */


/* Error Codes */
#define FATAL   -1
#define WARNING -2

/* Macros */
#define RAND(v) ((lrand48() % v) - (v/2)) /* random number around 0 */
#define array_elem(x)	(sizeof(x)/sizeof(x[0]))
#define collide( i, j, cur, prev, m, vk, ak, sp, sd ) do_collide( i, j, cur, prev, m, vk, ak, sp, sd, __FILE__, __LINE__ )
#define prt_sys_const( n, cur, m, v_0 ) do_prt_sys_const( n, cur, m, v_0, __FILE__, __LINE__ )
#define prt_sys_const_delta( sc0, n, cur, m, v_0 ) do_prt_sys_const_delta( sc0, n, cur, m, v_0, __FILE__, __LINE__ )


/* Type Definitions */
typedef struct _disp
{
        Window  win;
        Display *dpy;
        int     screen;
        Window  root;
        char    *dname;
        long    star, bg; /* colors */
        XColor  bg_xcolor;
        GC      star_gc;
        GC      erase_gc;
        Atom    kill_atom, protocol_atom;
        Colormap cmap;
} disp;

typedef struct
{
    double	x, y;
} point_2d;


/* system constants of motion */
typedef struct
{
    double	k, u;			/* kinetic and potential energies */
    double	e;			/* total energy of the system	*/
    point_2d	cm;			/* center of mass		*/
    point_2d	p;			/* total momentum of the system	*/
    double	l;			/* tot angular momentum of sys	*/
    double	m;			/* total mass of the system	*/
} sys_const;

typedef int	dist_type;
#define	DIST_CENTER	0		/* higher probability toward center */
#define	DIST_UNIFORM	1		/* uniform probability		*/
#define	DIST_RING	2		/* higher probability toward outside */



/* system initialization parameters */
typedef struct
{
    dist_type	star_distrib;		/* distribution method for stars*/
    double	size;			/* area to spread stars over	*/
    int		num_collapsar;		/* number of collapsars to create*/
    int		mono_stars;		/* number of non-binary stars	*/

    int		star_circle;		/* create a circle of stars	*/
    double	cir_dist;		/* size of circle of stars	*/

    int		star_line;		/* create stars in a line	*/
    int		rnd_spacing;		/* random spacing between stars	*/

    int		do_bounce;		/* bounce the stars		*/
    int		no_speed;		/* start with no initial speed	*/
    int		few_stars;		/* start with only a few stars	*/
    int		drift;			/* let stars drift across screen*/

    double	energy_fact;		/* amount of tot energy to give stars*/
    double	calc_energy_fact;	/* should this be variable	*/

    int		min_stars;		/* min # of stars before reset	*/
    int		num_add;		/* number of stars to add	*/
    int		live_stars;		/* number of live stars		*/
} sys_param_type;


/*
 * display point information
 *
 * change hash_table_bits to control the amount of memory used to record
 * displayed points.  Increasing it past 16 bits requires changing the
 * hash index table to be int's instead of shorts.
 */

#ifndef BITS
#define BITS(type)	(8 * (int)sizeof(type))
#endif


#ifndef HASH_TABLE_BITS
#define HASH_TABLE_BITS	15
#endif
#define HASH_TABLE_SIZE	(1L << (HASH_TABLE_BITS) )

#define MAX_DISP_PT	( 3L << (HASH_TABLE_BITS-2) )
#define DEFAULT_DISP_PT	( 1L << (HASH_TABLE_BITS-1) )

#define HASH_PRIME1  3238352189UL
#define HASH_PRIME2  1093769431UL
#define PT_HASH(x,y)	( ((ulong_t)(x)*HASH_PRIME1 + (ulong_t)(y)*HASH_PRIME2) >> (BITS(long) - HASH_TABLE_BITS) )


#define HASH_UNUSED	(MAX_DISP_PT+1)	/* hash entry is usable		*/
#define HASH_SEARCH	(MAX_DISP_PT+2)	/* hash entry is usable but continue */
                                        /* searching */

#define NEXT_H(a)	( ((a) >= HASH_TABLE_SIZE - 1) ? 0 : (a) + 1 )
#define PREV_H(a)	( ((a) == 0) ? HASH_TABLE_SIZE - 1 : (a) - 1 )
#define SUM_H(a,b)	( ((a) + (b) < HASH_TABLE_SIZE) ? (a) + (b) : (a) + (b) - HASH_TABLE_SIZE )
#define DIFF_H(a,b)	( ((a) >= (b)) ? (a) - (b) : (a) + HASH_TABLE_SIZE - (b) )


/*
 * display point structure.
 *
 * hstep must be large enough to hold the difference between the current
 * step number (sd.hstep) and the oldest point on the screen plus a fudge
 * factor to keep reset_hstep() from being called too often.
 *
 * the size of hstep could be made smaller by using a smaller hstep_scale
 * value.  Making it too small, however, will make the updates jerky.
 */

typedef struct
{
    XPoint	pt;
    uint_t	star: 8;		/* star that created this pt	*/
    uint_t	color: 6;		/* color in rainbow mode	*/
    uint_t	hstep: 18;		/* step number of this point	*/
#define MAX_HSTEP	((1 << 18)-1)
    int		:0;			/* no bits available		*/
} disp_point_type;
#define DISP_PT_UNUSED	(MAX_NUM_STARS)	/* unused entry flag		*/

#define NEXT(a)		( ((a) >= num_disp_pt - 1) ? 0 : (a) + 1 )
#define PREV(a)		( ((a) == 0) ? num_disp_pt - 1 : (a) - 1 )
#define SUM(a,b)	( ((a) + (b) < num_disp_pt) ? (a) + (b) : (a) + (b) - num_disp_pt )
#define DIFF(a,b)	( ((a) >= (b)) ? (a) - (b) : (a) + num_disp_pt - (b) )



/*
 * everything you need to know about the current state of the displayed
 * stars.
 */

typedef struct
{
    time_t	tstamp;			/* time since last change	*/
    int		live_erase;		/* num of stars at last erase	*/

    int		num_disp_skipped;	/* steps since last display	*/
    int		num_poll_skipped;	/* steps since last X event poll */
    int		num_visible;		/* number of visible stars	*/
    int		num_seen;		/* number of stars on screen	*/
    int		buffer_factor;		/* X buffering factor		*/

    XPoint	*last_disp;		/* last place star was displayed*/

    int		color_number;		/* what color to draw stars in	*/
    int		*star_color;		/* color of each star		*/
    
    /* full screen erasing trails */
    XPoint	*points;		/* points to be displayed	*/
    XPoint	*tmp_pts;		/* points to be displayed	*/
    int		*pixels;		/* color in multi-color mode	*/
    int		max_points;		/* number of points in buffer	*/
    int		points_used;		/* points used in buffer	*/

    /* self erasing trails */
    disp_point_type	*disp_pts;	/* array of displayed points	*/
    ushort_t	*hash_index;		/* hashed table of disp_pt idx's */

    int		next_free;
    int		next_disp;
    int		next_erase;
    int		erase_hstep;
    int		updt_hstep;

    int		num_disp_pt_32;
    int		num_disp_pt_16;
    int		num_disp_pt_8;
    int		num_disp_pt_4;

    int		redraw_min_x, redraw_max_x, redraw_min_y, redraw_max_y;
    

    /* stats on what has happened */
    int		points_plotted;		/* points plotted since last erase */
    int		total_points;		/* total points plotted		*/
    double	hstep_scale;		/* scaling factor for steps	*/
    int		raw_num_steps;		/* number of steps have been done*/
    int		num_steps;		/* scaled number of steps	*/
    int		raw_hsteps;		/* wrapped number of steps	*/
    int		hsteps;			/* scaled number of steps	*/
    int		erase_disps;		/* num of disps since last erase*/

} star_disp_type;

    

#endif
END-OF-FILE

if [ "$filename" != "/dev/null" ]
then
  size=`wc -c < $filename`

  if [ $size != 10134 ]
  then
    echo $filename changed - should be 10134 bytes, not $size bytes
  fi

  chmod 660 $filename
fi

# ---------- file patchlevel.h ----------

filename="patchlevel.h"

if [ -f $filename ]
then
  echo File \"$filename\" already exists\!  Skipping...
  filename=/dev/null		# throw it away
else
  echo extracting file patchlevel.h...
fi

cat << 'END-OF-FILE' > $filename
#define VERSION		"2.0"
#define PATCHLEVEL	0
END-OF-FILE

if [ "$filename" != "/dev/null" ]
then
  size=`wc -c < $filename`

  if [ $size != 44 ]
  then
    echo $filename changed - should be 44 bytes, not $size bytes
  fi

  chmod 660 $filename
fi

# ---------- file vroot.h ----------

filename="vroot.h"

if [ -f $filename ]
then
  echo File \"$filename\" already exists\!  Skipping...
  filename=/dev/null		# throw it away
else
  echo extracting file vroot.h...
fi

cat << 'END-OF-FILE' > $filename
/*
 * vroot.h -- Virtual Root Window handling header file
 *
 * This header file redefines the X11 macros RootWindow and DefaultRootWindow,
 * making them look for a virtual root window as provided by certain `virtual'
 * window managers like swm and tvtwm. If none is found, the ordinary root
 * window is returned, thus retaining backward compatibility with standard
 * window managers.
 * The function implementing the virtual root lookup remembers the result of
 * its last invocation to avoid overhead in the case of repeated calls
 * on the same display and screen arguments. 
 * The lookup code itself is taken from Tom LaStrange's ssetroot program.
 *
 * Most simple root window changing X programs can be converted to using
 * virtual roots by just including
 *
 * #include "vroot.h"
 *
 * after all the X11 header files.  It has been tested on such popular
 * X clients as xphoon, xfroot, xloadimage, and xaqua.
 *
 * Andreas Stolcke (stolcke@ICSI.Berkeley.EDU), 9/7/90
 */

#include <stdio.h>
#include <X11/X.h>
#include <X11/Xatom.h>

static Window
VirtualRootWindow(dpy, screen)
Display *dpy;
int screen;
{
	static Display *save_dpy = (Display *)0;
	static int save_screen = -1;
	static Window root = (Window)0;

	Atom __SWM_VROOT = None;
	int i;
	Window rootReturn, parentReturn, *children;
	unsigned int numChildren;

	if ( dpy != save_dpy || screen != save_screen ) {
		root = RootWindow(dpy, screen);

		/* go look for a virtual root */
		__SWM_VROOT = XInternAtom(dpy, "__SWM_VROOT", False);
		XQueryTree(dpy, root, &rootReturn, &parentReturn,
				 &children, &numChildren);
		for (i = 0; i < numChildren; i++) {
			Atom actual_type;
			int actual_format;
			unsigned long nitems, bytesafter;
			Window *newRoot = (Window *) NULL;

			if (XGetWindowProperty(dpy, children[i], __SWM_VROOT,
				0, 1, False, XA_WINDOW,
				&actual_type, &actual_format,
				&nitems, &bytesafter,
				(unsigned char **) &newRoot) == Success
			    && newRoot) {
			    root = *newRoot;
			    break;
			}
		}

		/* Let's not waste any memory. */
		XFree( (char *) children);

		save_dpy = dpy;
		save_screen = screen;
	}

	return root;
}

#undef DefaultRootWindow
#define DefaultRootWindow(dpy) RootWindow(dpy, DefaultScreen(dpy))

#undef RootWindow
#define RootWindow(dpy,screen) VirtualRootWindow(dpy,screen)

END-OF-FILE

if [ "$filename" != "/dev/null" ]
then
  size=`wc -c < $filename`

  if [ $size != 2310 ]
  then
    echo $filename changed - should be 2310 bytes, not $size bytes
  fi

  chmod 660 $filename
fi

# ---------- file xstar_ext.h ----------

filename="xstar_ext.h"

if [ -f $filename ]
then
  echo File \"$filename\" already exists\!  Skipping...
  filename=/dev/null		# throw it away
else
  echo extracting file xstar_ext.h...
fi

cat << 'END-OF-FILE' > $filename
#ifndef include_xstar_ext
#define include_xstar_ext


/*
** XStar -- a animated n-body solver for X windows
** Copyright (C) 1995  Wayne Schlitt (wayne@cse.unl.edu) and others
**
**  This program is free software; you can redistribute it and/or modify
**  it under the terms of the GNU General Public License as published by
**  the Free Software Foundation; either version 2 of the License, or
**  (at your option) any later version.
*/




#ifdef RAND48_PROTO
double drand48(void);
long lrand48(void);
void srand48( long seedval );
#endif

/*--------------------------- Function Prototypes ---------------------------*/

extern void
Quit(
#ifdef __STDC__
int signal
#endif
);

extern void    Initialize();

extern void
Parse_Arguments(
#ifdef __STDC__
int  argc,
char **argv,
char **geometry
#endif
);

extern void
Change_Screen_Saver(
#ifdef __STDC__
int
#endif
);

extern void
Traverse_Tree(
#ifdef __STDC__
Display *,
Window
#endif
);

extern void Wait_For_Idleness();

extern Bool
Dummy_Predicate(
#ifdef __STDC__
Display *,
XEvent *,
char *
#endif
);

extern void Create_Big_Window();

extern void
Create_Window(
#ifdef __STDC__
char *
#endif
);

extern void init_stars( point_2d *cur, point_2d *prev, double *m,
		point_2d *vk[], point_2d *ak[],
		int max_stars, sys_param_type *sp, star_disp_type *sd );

extern void new_star( point_2d *cur, point_2d *prev, double *m, 
		point_2d *vk[], point_2d *ak[],
		int max_stars, sys_param_type *sp, star_disp_type *sd,
		int add_collapsar );


extern void set_sys_param( sys_param_type *sp, int max_stars );
    
extern void set_xmva( point_2d *cur, point_2d *prev, double *m,
	      point_2d *vk[], point_2d *ak[],
	      int max_stars, sys_param_type *sp );

extern void set_va( point_2d *cur, point_2d *prev, double *m,
	    point_2d *vk[], point_2d *ak[],
	    sys_param_type *sp,
	    int i );

extern void set_star_disp( star_disp_type *sd, sys_param_type *sp );

extern void set_buffer_factor( star_disp_type *sd, sys_param_type *sp );


extern void init_sys_4( point_2d *cur, point_2d *prev, double *m,
	      point_2d *vk[], point_2d *ak[],
	      int max_stars, sys_param_type *sp );

extern void init_sys_8( point_2d *cur, point_2d *prev, double *m,
	      point_2d *vk[], point_2d *ak[],
	      int max_stars, sys_param_type *sp );

extern void init_sys_8b( point_2d *cur, point_2d *prev, double *m,
	      point_2d *vk[], point_2d *ak[],
	      int max_stars, sys_param_type *sp );

void dump_sys( point_2d *cur, point_2d *prev, double *m,
	      point_2d *vk[], point_2d *ak[],
	      int max_stars, sys_param_type *sp );


extern void init_colors( XColor *colors, GC *color_gcs, star_disp_type *sd, int num_elem );

extern void restart_taylor3( int n, double *m, point_2d *x, point_2d *v );

extern void init_taylor3( int n, double *m, point_2d *x, point_2d *v );

extern void move_stars_taylor3( point_2d *prev, point_2d *cur, double *m, 
		  point_2d *vk[], point_2d *ak[],
		  int max_stars, sys_param_type *sp, star_disp_type *sd );


extern void restart_ab4( int n, double *m, point_2d *x, point_2d *v );

extern void init_ab4( int n, double *m, point_2d *x, point_2d *v );

extern void move_stars_ab4( point_2d *prev, point_2d *cur, double *m, 
		  point_2d *vk[], point_2d *ak[],
		  int max_stars, sys_param_type *sp, star_disp_type *sd );


extern void restart_rk4( int n, double *m, point_2d *x, point_2d *v );

extern void init_rk4( int n, double *m, point_2d *x, point_2d *v );

extern void move_stars_rk4( point_2d *prev, point_2d *cur, double *m, 
		  point_2d *vk[], point_2d *ak[],
		  int max_stars, sys_param_type *sp, star_disp_type *sd );


extern void restart_gpemce8( int n, double *m, point_2d *x, point_2d *v );

extern void init_gpemce8( int n, double *m, point_2d *x, point_2d *v );

extern void move_stars_gpemce8( point_2d *prev, point_2d *cur, double *m, 
		  point_2d *vk[], point_2d *ak[],
		  int max_stars, sys_param_type *sp, star_disp_type *sd );


extern void restart_ab7( int n, double *m, point_2d *x, point_2d *v );

extern void init_ab7( int n, double *m, point_2d *x, point_2d *v );

extern void move_stars_ab7( point_2d *prev, point_2d *cur, double *m, 
		  point_2d *vk[], point_2d *ak[],
		  int max_stars, sys_param_type *sp, star_disp_type *sd );


extern void restart_tam5( int n, double *m, point_2d *x, point_2d *v );

extern void init_tam5( int n, double *m, point_2d *x, point_2d *v );

extern void move_stars_tam5( point_2d *prev, point_2d *cur, double *m, 
		  point_2d *vk[], point_2d *ak[],
		  int max_stars, sys_param_type *sp, star_disp_type *sd );


extern void restart_am7( int n, double *m, point_2d *x, point_2d *v );

extern void init_am7( int n, double *m, point_2d *x, point_2d *v );

extern void move_stars_am7( point_2d *prev, point_2d *cur, double *m, 
		  point_2d *vk[], point_2d *ak[],
		  int max_stars, sys_param_type *sp, star_disp_type *sd );


extern void restart_tab4( int n, double *m, point_2d *x, point_2d *v );

extern void init_tab4( int n, double *m, point_2d *x, point_2d *v );

extern void move_stars_tab4( point_2d *prev, point_2d *cur, double *m, 
		  point_2d *vk[], point_2d *ak[],
		  int max_stars, sys_param_type *sp, star_disp_type *sd );


extern void default_init( int n, double *m, point_2d *x, point_2d *v );


extern void check_bounce( point_2d *prev, point_2d *cur, double *m, 
		  point_2d *vk[], point_2d *ak[],
		  int max_stars, sys_param_type *sp, star_disp_type *sd );


extern void do_collide( int i, int j, point_2d *cur, point_2d *prev, double *m,
		point_2d *vk[], point_2d *ak[],
		sys_param_type *sp, star_disp_type *sd,
		char *file, int line 
		);

extern double kinetic_energy( int i, int n, point_2d *cur, double *m, point_2d *v );

extern double binding_energy( int i, int n, point_2d *cur, double *m, point_2d *v );


extern void calc_sys_const( sys_const *sc,
			   int n, point_2d *cur, double *m,  point_2d *v );
extern void do_prt_sys_const( int n, point_2d *cur, double *m,  point_2d *v, char *file, int line );
extern void do_prt_sys_const_delta( sys_const sc0, int n, point_2d *cur, double *m,  point_2d *v, char *file, int line );

extern void update_screen( sys_param_type *sp, star_disp_type *sd, disp *display );

extern void clear_disp_pt( star_disp_type *sd );

extern void redraw_screen(  point_2d *cur, double *m, sys_param_type *sp, star_disp_type *sd, disp *display );

extern void set_redraw_full( star_disp_type *sd );

extern void plot_collapsars( point_2d *cur, double *m, sys_param_type *sp, star_disp_type *sd, disp *display );


extern void reset_hstep( star_disp_type *sd );


extern void Animate();

extern void
HandleEvent(
#ifdef __STDC__
XEvent *,
star_disp_type *sd
#endif
);

#ifdef USE_USLEEP
extern void alarmhandler();

extern void sleepms(
#ifdef __STDC__
int msec
#endif
);

extern void usleep(
#ifdef __STDC__
unsigned us
#endif
);

#else
extern void    nap();
#endif

extern void    Usage(
#ifdef __STDC__
char *program
#endif
);

extern void    HandleError(
#ifdef __STDC__
char    *description,
int     degree
#endif
);

extern long
GetColor(
#ifdef __STDC__
disp            *display,
char            *color,
XColor          *final_color
#endif
);

extern void *
Safe_Malloc(
#ifdef __STDC__
int bytes
#endif
);

extern void *
Safe_Realloc(
#ifdef __STDC__
void *ptr,
int bytes
#endif
);


/*----------------------------- Global Variables ----------------------------*/

/* X related */
extern int		winX, winY;
extern int		root_xoff, root_yoff;
extern double		center_x, center_y;
extern uint_t		winW, winH;
extern int		half_winW, half_winH;
extern int		max_x, min_x, max_y, min_y;
extern uint_t		far_dist;
extern disp		display;

/* animation related */
extern int     stars;          /* number of stars */
extern int     max_stars;    /* maximum number of stars */
extern int     max_disp_skip;    /* max num of displays to skip */
extern int     delay;   /* delay between updates, in microseconds */
extern int     timeout;            /* time in seconds before screen saving */
extern char    *star_color;
extern char    *bg_color;
extern XColor	colors[NUM_COLORS];
extern GC	color_gcs[NUM_COLORS];
extern int	verbose;
extern int	rotate_colors;
extern int	init_colors_done;
extern int	multi_colors;
extern int	num_disp_pt;

extern int     stop;
extern int     add;           /* flag to add a collapsar */
extern int     add_star;      /* flag to add a star */
extern int     del_star;      /* flag to delete a star */
extern int     erase;          /* flag to erase trails */
extern int     new_start;      /* flag to start a new system trails */
extern int	pause_updt;	/* flag to pause the updates	*/
extern int	screen_exposed;		/* flag to update the screen	*/
extern int	do_redraw;		/* flag to redraw the screen	*/


extern int     root;           /* display in root window */
extern time_t	last_init;

extern double	collapsar;
extern double	fv;
extern double	fv_inv;
extern double	fm;

extern sys_param_type	orig_sp;
extern sys_const orig_sc;
extern star_disp_type	orig_sd;

extern int num_collide;
extern int num_edge;

extern double	collide_dist;

extern void (*move_fna)( point_2d *prev, point_2d *cur, double *m, 
		  point_2d *vk[], point_2d *ak[],
		  int max_stars, sys_param_type *sp, star_disp_type *sd );

extern void (*init_fna)( int n, double *m, point_2d *x, point_2d *v );

extern void (*restart_fna)( int n, double *m, point_2d *x, point_2d *v );

extern double move_cost;

#endif
END-OF-FILE

if [ "$filename" != "/dev/null" ]
then
  size=`wc -c < $filename`

  if [ $size != 9423 ]
  then
    echo $filename changed - should be 9423 bytes, not $size bytes
  fi

  chmod 660 $filename
fi

# ---------- file plot_star.h ----------

filename="plot_star.h"

if [ -f $filename ]
then
  echo File \"$filename\" already exists\!  Skipping...
  filename=/dev/null		# throw it away
else
  echo extracting file plot_star.h...
fi

cat << 'END-OF-FILE' > $filename
/*
** XStar -- a animated n-body solver for X windows
** Copyright (C) 1995  Wayne Schlitt (wayne@cse.unl.edu)
**
**  This program is free software; you can redistribute it and/or modify
**  it under the terms of the GNU General Public License as published by
**  the Free Software Foundation; either version 2 of the License, or
**  (at your option) any later version.
*/



/*
 * this routine is common between all the movement routines, but it's
 * too expensive to make it a function call, so it is inlined via the
 * #include command.
 */

	/* if the star is on the screen, then plot it */
	if( xpt > min_x && ypt > min_y && xpt < max_x && ypt < max_y )
	{
	    if( m_i >= collapsar )
		continue;

	    ++sd->num_visible;
	    ++sd->num_seen;
	    
	    if( xpt != sd->last_disp[i].x || ypt != sd->last_disp[i].y )
	    {
		sd->last_disp[i].x = xpt;
		sd->last_disp[i].y = ypt;
		
		xpt += center_x;
		ypt += center_y;
		    
		if( num_disp_pt )
		{
		    disp_point_type	*new_pt = &sd->disp_pts[sd->next_free];

		    int		hash_loc;
		    int		hashed_idx;
		    int		first_search = -1;


		    new_pt->pt.x  = xpt;
		    new_pt->pt.y  = ypt;
		    new_pt->star  = i;
		    new_pt->color = sd->color_number;
		    new_pt->hstep = sd->hsteps;


		    /*
		     * check to see if there was already a star plotted here
		     */
		    for( hash_loc = PT_HASH( xpt, ypt ),
			hashed_idx = sd->hash_index[ hash_loc ];
			
			hashed_idx != HASH_UNUSED;
			
			hash_loc = NEXT_H( hash_loc ),
			hashed_idx = sd->hash_index[ hash_loc ] )
		    {
			if( hashed_idx == HASH_SEARCH )
			{
			    if( first_search == -1 )
				first_search = hash_loc;

			    continue;
			}
			
			if( sd->disp_pts[ hashed_idx ].pt.x != xpt
			   || sd->disp_pts[ hashed_idx ].pt.y != ypt
			   )
			    continue;


			sd->disp_pts[ hashed_idx ].star = DISP_PT_UNUSED;

			/*
			 * If we have found a search entry, then we should
			 * really use it instead of this entry and we should
			 * delete this entry.  But this case happens so 
			 * rarely (literally one in a million times) that
			 * it isn't worth it...  
			 */
			first_search = -1;

			break;
		    }

		    if( first_search == -1 )
			sd->hash_index[ hash_loc ] = sd->next_free;
		    else
			sd->hash_index[ first_search ] = sd->next_free;
		    
		    
		    sd->next_free = NEXT( sd->next_free );

		}
		else
		{
		    if( multi_colors )
			sd->pixels[sd->points_used] = sd->star_color[ i ];
		    
		    sd->points[sd->points_used].x = xpt;
		    sd->points[(sd->points_used)++].y = ypt;
		}
	    }
	}
	else
	{
	    /* see if the star has left the system */
	    
	    tx = xpt + root_xoff;
	    ty = ypt + root_yoff;
	    
	    if( abs(tx) + abs(ty) > far_dist )
	    {
		num_edge++;
		--sp->live_stars;
		set_buffer_factor( sd, sp );
		if( verbose > 1 )
		{
		    double	k, u;
		    double	dx, dy;
		    double	tdist;
		
		    dx = cur[i].x;
		    dy = cur[i].y;
		    tdist = sqrt( dx*dx + dy*dy );
		    
		    k = kinetic_energy( i, max_stars, cur, m, v_0 );
		    u = binding_energy( i, max_stars, cur, m, v_0 );
		    
		    if( k + u < 0 )
			fprintf( stderr,
				"%2d  %6.1f,%6.1f  %7.4f,%7.4f %6.3f  %6.2f %9.6f %9.6f %9.6f\n",
				i, cur[i].x, cur[i].y, fv*v_0[i].x, fv*v_0[i].y, m[i]/fm,
				tdist, k*fv*fv/fm, u*fv*fv/fm, (k + u)*fv*fv/fm );
	    
		    if( verbose > 1 )
			fprintf( stderr, "%s:%d  live_stars=%d  star %d  |(%g,%g)|=%d\n", __FILE__, __LINE__, sp->live_stars, i, cur[i].x, cur[i].y, tx*tx+ty*ty );
		}
		
		m[i] = m_i = 0.0;
		cur[i].x = cur[i].y = prev[i].x = prev[i].y = -1.0;
		for( k = 0; k < K; k++ )
		{
		    vk[k][i].x = vk[k][i].y = 0;
		    ak[k][i].x = ak[k][i].y = 0;
		}	    

		init_fna( max_stars, m, cur, v_0 );
	    }
	}
END-OF-FILE

if [ "$filename" != "/dev/null" ]
then
  size=`wc -c < $filename`

  if [ $size != 3716 ]
  then
    echo $filename changed - should be 3716 bytes, not $size bytes
  fi

  chmod 660 $filename
fi

echo done

exit 0
--- cut here ---
-- 
Wayne Schlitt can not assert the truth of all statements in this
article and still be consistent.


