home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-12-27 | 55.2 KB | 2,071 lines |
- Newsgroups: comp.sources.misc
- From: tcamp@hercules.acpub.duke.edu (Ted Campbell)
- Subject: v27i011: sfs - Space Flight Simulator, Part11/21
- Message-ID: <1991Dec24.191551.20647@sparky.imd.sterling.com>
- X-Md4-Signature: 3f36da4d83528efde87ed208ab4d7692
- Date: Tue, 24 Dec 1991 19:15:51 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: tcamp@hercules.acpub.duke.edu (Ted Campbell)
- Posting-number: Volume 27, Issue 11
- Archive-name: sfs/part11
- Environment: IBMPC && EGA/VGA, UNIX-PC && MGR, UNIX && X11
-
- #!/bin/sh
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file sfs/as/as_focus.c continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 11; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping sfs/as/as_focus.c'
- else
- echo 'x - continuing file sfs/as/as_focus.c'
- sed 's/^X//' << 'SHAR_EOF' >> 'sfs/as/as_focus.c' &&
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- ****************************************************************/
- X
- #include "stdio.h"
- #include "ctype.h"
- #include "bw.h"
- #include "as.h"
- X
- #ifdef __STDC__
- #include "malloc.h"
- #else
- extern char * malloc();
- #endif
- X
- #define CHECK_PARAMS
- X
- /****************************************************************
- X
- X as_readfd() read a focal data (fd) file
- X
- ****************************************************************/
- X
- as_readfd( fdfile, fstruct )
- X char *fdfile;
- X struct as_focus *fstruct;
- X {
- X FILE *data; /* data file for read */
- X register int c; /* counter */
- X static char x_buffer[ BW_EBUFSIZE ]; /* buffer to read data */
- X char *r; /* return value from as_fgets */
- X
- X /* Send notice */
- X
- X sprintf( bw_ebuf, "Reading focal datafile %s",
- X fdfile );
- X bw_message( bw_ebuf );
- X
- X /*** Try to open the file, return for failure */
- X
- X if ( ( data = fopen( fdfile, "rb" )) == NULL )
- X {
- X sprintf( bw_ebuf, "Cannot open focal data file %s",
- X fdfile );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X
- X /*** Begin reading elements from the file */
- X /*** 0. save fd filename itself */
- X
- X /* allocate memory for name */
- X
- X if ( ( fstruct->fdfile = malloc( strlen( fdfile ) + 2 )) == NULL )
- X {
- X bw_error( "Failed to allocate memory for fd filename. " );
- X return BW_ERROR; /* error return */
- X }
- X strcpy( fstruct->fdfile, fdfile );
- X
- X /*** 1. Read name of the focus */
- X
- X r = as_fgets( x_buffer, 127, data ); /* get a string */
- X if ( r == NULL )
- X {
- X sprintf( bw_ebuf, "Failure to read focal data file %s ", fdfile );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "DEBUG: read name \n" );
- #endif
- X
- X for ( c = 0; x_buffer[ c ] >= ' '; ++c ) /* find end of string */
- X {
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "DEBUG: counting: %3d [char 0x%3x next 0x%3x] \n",
- X c, x_buffer[ c ], x_buffer[ c + 1 ] );
- #endif
- X
- X }
- X x_buffer[ c ] = 0; /* terminate with 0 */
- X
- X /* allocate memory for name */
- X
- X if ( ( fstruct->name = malloc( strlen( x_buffer ) + 2 )) == NULL )
- X {
- X bw_error( "Failed to allocate memory for focal data elements. " );
- X return BW_ERROR; /* error return */
- X }
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "DEBUG: allocated memory \n" );
- #endif
- X
- X strcpy( fstruct->name, x_buffer ); /* copy name to buffer */
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "DEBUG: copied name to buffer \n" );
- #endif
- X
- X /*** 2. Read adjective for the focus */
- X
- X r = as_fgets( x_buffer, 127, data ); /* get a string */
- X if ( r == NULL )
- X {
- X sprintf( bw_ebuf, "Failure to read focal data file %s ", fdfile );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "DEBUG: read adjective \n" );
- #endif
- X
- X for ( c = 0; x_buffer[ c ] >= ' '; ++c ) /* find end of string */
- X {
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "DEBUG: counting: %2d [char 0x%2x next 0x%2x] \n",
- X c, x_buffer[ c ], x_buffer[ c + 1 ] );
- #endif
- X
- X }
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "DEBUG: count complete; c = %d \n", c );
- #endif
- X
- X x_buffer[ c ] = 0; /* terminate with 0 */
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "DEBUG: buffer terminated \n" );
- #endif
- X
- X /* allocate memory for adjective */
- X
- X if ( ( fstruct->adjective = malloc( strlen( x_buffer ) + 2 )) == NULL )
- X {
- X bw_error( "Failed to allocate memory for focal data elements. " );
- X return BW_ERROR; /* error return */
- X }
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "DEBUG: allocated memory \n" );
- #endif
- X
- X strcpy( fstruct->adjective, x_buffer ); /* copy adjective to buffer */
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "DEBUG: copied adjective \n" );
- #endif
- X
- X /*** 3. Read radius of the focus */
- X
- X r = as_fgets( x_buffer, 127, data );
- X if ( r == NULL )
- X {
- X sprintf( bw_ebuf, "Failure to read focal data file %s ", fdfile );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "DEBUG: read radius \n" );
- #endif
- X
- X sscanf( x_buffer, "%lf", &fstruct->radius );
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "DEBUG: scanned radius \n" );
- #endif
- X
- X /*** 4. Read mass of the focus */
- X
- X r = as_fgets( x_buffer, 127, data );
- X if ( r == NULL )
- X {
- X sprintf( bw_ebuf, "Failure to read focal data file %s ", fdfile );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "DEBUG: read mass \n" );
- #endif
- X
- X sscanf( x_buffer, "%lf", &fstruct->mass );
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "DEBUG: scanned mass \n" );
- #endif
- X
- X fstruct->mass *= 5.98e27;
- X
- X /*** 5. Read sidereal period of the focus */
- X
- X r = as_fgets( x_buffer, 127, data );
- X if ( r == NULL )
- X {
- X sprintf( bw_ebuf, "Failure to read focal data file %s ", fdfile );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "DEBUG: read sidereal period \n" );
- #endif
- X
- X sscanf( x_buffer, "%lf", &fstruct->sid_day );
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "DEBUG: scanned sidereal period \n" );
- #endif
- X
- X fclose( data ); /* close the fd file */
- X
- X }
- X
- X
- SHAR_EOF
- echo 'File sfs/as/as_focus.c is complete' &&
- chmod 0644 sfs/as/as_focus.c ||
- echo 'restore of sfs/as/as_focus.c failed'
- Wc_c="`wc -c < 'sfs/as/as_focus.c'`"
- test 6547 -eq "$Wc_c" ||
- echo 'sfs/as/as_focus.c: original size 6547, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= sfs/as/as_orbit.c ==============
- if test -f 'sfs/as/as_orbit.c' -a X"$1" != X"-c"; then
- echo 'x - skipping sfs/as/as_orbit.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting sfs/as/as_orbit.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'sfs/as/as_orbit.c' &&
- /****************************************************************
- X
- X as_orbit.c Orbital calculation routines
- X for astronomy (as) subsystem
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- ****************************************************************/
- X
- #include "math.h"
- #include "time.h"
- #include "bw.h"
- #include "as.h"
- X
- #define KEP_ACCURACY 0.00001
- X
- /****************************************************************
- X
- X or_init() Set up an orbit
- X
- ****************************************************************/
- X
- or_init( orbit, ap, aa )
- X struct as_orbit *orbit;
- X double aa, ap;
- X {
- X
- #ifdef DEBUG
- X if ( orbit->focus->radius <= 0.0 )
- X {
- X sprintf( bw_ebuf, "[pr:] or_init() received orbit->focus->radius = %lf",
- X orbit->focus->radius );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( orbit->focus->sid_day < 0.0 )
- X {
- X sprintf( bw_ebuf, "[pr:] or_init() received orbit->focus->sid_day = %lf",
- X orbit->focus->sid_day );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( orbit->focus->mass < 0.0 )
- X {
- X sprintf( bw_ebuf, "[pr:] or_init() received orbit->focus->mass = %lf",
- X orbit->focus->mass );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( ( orbit->inclination > 180.0 ) || ( orbit->inclination < -180.0 ))
- X {
- X sprintf( bw_ebuf, "[pr:] or_init() received orbit->inclination = %lf",
- X orbit->inclination );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( ( orbit->lon_an > 180.0 ) || ( orbit->lon_an < -180.0 ))
- X {
- X sprintf( bw_ebuf, "[pr:] or_init() received orbit->lon_an = %lf",
- X orbit->lon_an );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( ( orbit->arg_per > 180.0 ) || ( orbit->arg_per < -180.0 ))
- X {
- X sprintf( bw_ebuf, "[pr:] or_init() received orbit->arg_per = %lf",
- X orbit->arg_per );
- X bw_error( bw_ebuf );
- X return;
- X }
- #endif
- X
- X /*** Calculate semimajor axis */
- X
- X orbit->semimajor = ( aa + ap + ( 2 * orbit->focus->radius )) / 2;
- X
- X /*** Calculate orbital center - focus distance */
- X
- X orbit->dist = orbit->semimajor - ( orbit->focus->radius + ap );
- X
- X /*** Calculate semiminor axis */
- X
- X orbit->semiminor = sqrt( (double) ( orbit->semimajor * orbit->semimajor ) - (double) ( orbit->dist * orbit->dist ));
- X
- X /*** Calculate orbital eccentricity */
- X
- X orbit->eccentricity = sqrt( 1.0 - (( orbit->semiminor / (double) orbit->semimajor ) * ( orbit->semiminor / (double) orbit->semimajor )) );
- X
- X /*** Calculate orbital period */
- X
- X orbit->period = sqrt ( ( ( 4.0 * ( PI * (double) PI ) ) / ( UGC * orbit->focus->mass ) )
- X * ( orbit->semimajor * orbit->semimajor * orbit->semimajor ) );
- X
- X /*** Calculate the increment factor of longitude of
- X the ascending node. This factor must be multiplied
- X by a time factor (orbital period or time into orbit,
- X in seconds). See Davidoff, pp. 8-9 and 8-10, and
- X formula 8.14. */
- X
- X if ( orbit->focus->sid_day == 0.0 )
- X {
- X orbit->lif = 0;
- X }
- X else
- X {
- X orbit->lif = (2 * PI) / (double) orbit->focus->sid_day;
- X }
- X
- X }
- X
- /****************************************************************
- X
- X or_kep() Solve Kepler's equation
- X
- X Globals utilized:
- X
- X orbit->eccentricity Eccentricity of the orbital ellipse
- X
- X orbit->semimajor Semimajor axis of the orbital ellipse (km)
- X
- X orbit->period Orbital period (seconds)
- X
- X Input:
- X
- X t Time from periapsis in seconds
- X ( 0 < t < orbit->period )
- X
- X Output:
- X
- X theta Angle between periapsis, geocenter, and
- X current position (theta).
- X
- X r Distance from satellite to focal center,
- X in kilometers
- X
- ****************************************************************/
- X
- or_kep( orbit, t, theta, r )
- X struct as_orbit *orbit;
- X long t;
- X double *theta;
- X long *r;
- X {
- X double z, z3, E;
- X z = 2.0 * PI * ( (double) t / (double) orbit->period );
- X E = z;
- X
- X do
- X {
- X z3 = ( E - ( orbit->eccentricity * sin( E )) - z ) / ( 1 - ( orbit->eccentricity * cos( E )));
- X E = E - z3;
- X }
- X while ( fabs( z3 ) > KEP_ACCURACY );
- X
- X *theta = PI;
- X if ( E != PI )
- X {
- X *theta = 2.0 * atan( sqrt( ( 1 - orbit->eccentricity ) / ( 1 + orbit->eccentricity )) * tan( E / 2.0 ));
- X if ( E > PI )
- X {
- X *theta = ( (double) 2.0 * PI ) + *theta;
- X }
- X }
- X
- X *r = orbit->semimajor * ( 1 - orbit->eccentricity * orbit->eccentricity ) / ( 1 + orbit->eccentricity * cos( *theta ));
- X return 1;
- X }
- X
- X
- /****************************************************************
- X
- X or_ssp() Calculate Subsatellite Point
- X
- X This function utilizes available data on the satellite
- X to return the subsatellite point, that is, the point
- X on the surface of the orbital focus directly under
- X the satellite at a given moment.
- X
- ****************************************************************/
- X
- or_ssp( orbit, t, latitude, longitude, r, n )
- X struct as_orbit *orbit;
- X long t, *r, *n;
- X double *longitude, *latitude;
- X {
- X static long _r, tp;
- X static double theta;
- X double n1, n2, n4, E, lan;
- X long t1;
- X
- #ifdef DEBUG
- X if ( orbit->focus->radius < OR_RAD_MIN )
- X {
- X sprintf( bw_ebuf, "[pr:] or_ssp() received orbit->focus->radius = %lf",
- X orbit->focus->radius );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( orbit->focus->sid_day < OR_SID_MIN )
- X {
- X sprintf( bw_ebuf, "[pr:] or_ssp() received orbit->focus->sid_day = %lf",
- X orbit->focus->sid_day );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( orbit->focus->mass < OR_MAS_MIN )
- X {
- X sprintf( bw_ebuf, "[pr:] or_ssp() received orbit->focus->mass = %le",
- X orbit->focus->mass );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( ( orbit->inclination > OR_INC_MAX ) || ( orbit->inclination < OR_INC_MIN ))
- X {
- X sprintf( bw_ebuf, "[pr:] or_ssp() received orbit->inclination = %lf",
- X orbit->inclination );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( ( orbit->lon_an > OR_LAN_MAX ) || ( orbit->lon_an < OR_LAN_MIN ))
- X {
- X sprintf( bw_ebuf, "[pr:] or_ssp() received orbit->lon_an = %lf",
- X orbit->lon_an );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( ( orbit->arg_per > OR_ARP_MAX ) || ( orbit->arg_per < OR_ARP_MIN ))
- X {
- X sprintf( bw_ebuf, "[pr:] or_ssp() received orbit->arg_per = %lf",
- X orbit->arg_per );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( orbit->period < OR_PER_MIN )
- X {
- X sprintf( bw_ebuf, "[pr:] or_ssp() received orbit->period = %lf",
- X orbit->period );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( ( orbit->eccentricity < OR_ECC_MIN ) || ( orbit->eccentricity > OR_ECC_MAX ))
- X {
- X sprintf( bw_ebuf, "[pr:] or_ssp() received orbit->eccentricity = %lf",
- X orbit->eccentricity );
- X bw_error( bw_ebuf );
- X return;
- X }
- #endif
- X
- X *n = t / (long) orbit->period; /* return number of current orbit */
- X t1 = t - ( orbit->period * ( *n ) ); /* get seconds into this orbit */
- X if ( t1 == 0 )
- X {
- X t1 = 1;
- X }
- X
- X or_kep( orbit, t1, &theta, &_r );
- X *r = _r;
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "or_ssp(): r = %ld (%ld) ", _r, *r );
- X bw_debug( bw_ebuf );
- X sprintf( bw_ebuf, "or_ssp(): theta = %lf", theta );
- X bw_debug( bw_ebuf );
- #endif
- X
- X /*** Calculate the longitude of the ascending node at
- X the beginning of this orbit. See Davidoff, p. 8-9
- X and 8-10, and equations 8.13a, 8.13b, and 8.14. */
- X
- X lan = ( orbit->lon_an * DEG_RAD ) - ( orbit->lif * orbit->period * *n );
- X
- X /*** Calculate the latitude of the SSP. See Davidoff,
- X pp. 8-13 - 8-15, esp. equation 8.20. */
- X
- X *latitude = asin( sin( orbit->inclination * DEG_RAD )
- X * sin( theta + ( orbit->arg_per * DEG_RAD )));
- X
- X if ( ( orbit->inclination >= 0 ) && ( orbit->inclination < 90 ) )
- X {
- X n2 = 1;
- X }
- X else
- X {
- X n2 = 0;
- X }
- X if ( ( ( *latitude ) * RAD_DEG ) < 0.0 )
- X {
- X n4 = 1;
- X }
- X else
- X {
- X n4 = 0;
- X }
- X
- X if ( ( orbit->arg_per > 180 ) && ( orbit->arg_per <= 540 ) )
- X {
- X n1 = 1;
- X }
- X else
- X {
- X n1 = 0;
- X }
- X
- X E = 2 * atan( (double) pow( ( 1 - orbit->eccentricity ) / ( 1 + orbit->eccentricity ), (double) 0.5 )
- X * tan( ( orbit->arg_per * DEG_RAD ) / 2.0 )) + ( 2.0 * PI * n1);
- X tp = ( orbit->period / ( 2.0 * PI ) ) * ( E - sin( E ) );
- X
- X *longitude = as_lfix( lan
- X - pow( (double) -1.0, n2 + n4 )
- X * acos( cos( theta + ( orbit->arg_per * DEG_RAD ))
- X / cos( *latitude ) )
- X - orbit->lif * (double) t1
- X - orbit->lif * (double) tp );
- X
- X /* convert to degrees */
- X
- X *longitude = *longitude * RAD_DEG;
- X *latitude = *latitude * RAD_DEG;
- X
- X }
- X
- double
- as_lfix( l )
- X double l;
- X {
- X double l1;
- X l1 = l;
- X while ( l1 < ( 0 - PI ) )
- X {
- X l1 += ( 2.0 * PI );
- X }
- X while ( l1 > PI )
- X {
- X l1 -= ( 2.0 * PI );
- X }
- X return l1;
- X }
- X
- X
- SHAR_EOF
- chmod 0644 sfs/as/as_orbit.c ||
- echo 'restore of sfs/as/as_orbit.c failed'
- Wc_c="`wc -c < 'sfs/as/as_orbit.c'`"
- test 9998 -eq "$Wc_c" ||
- echo 'sfs/as/as_orbit.c: original size 9998, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= sfs/as/as_spj.c ==============
- if test -f 'sfs/as/as_spj.c' -a X"$1" != X"-c"; then
- echo 'x - skipping sfs/as/as_spj.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting sfs/as/as_spj.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'sfs/as/as_spj.c' &&
- /***************************************************************
- X
- X as_spj.c Spherical projection routines
- X for astronomy (as) subsystem
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- ***************************************************************/
- X
- #include "stdio.h"
- #include "math.h"
- #include "bw.h"
- #include "as.h"
- X
- #ifdef __STDC__
- #include "malloc.h"
- #else
- extern char * malloc();
- #endif
- X
- /***************************************************************
- X
- X spj_readspd() Read an SPJ datafile
- X
- ***************************************************************/
- X
- spj_readspd( datafile, start, end )
- X char *datafile;
- X struct spj_pt *start, *end;
- X {
- X FILE *data;
- X register int c;
- X static char read_buffer[ 128 ];
- X static int co;
- X static double la, lo, di;
- X struct spj_pt *current, *new;
- X
- X /* Open the datafile */
- X
- X if ( ( data = fopen( datafile, "rb" )) == NULL )
- X {
- X sprintf( bw_ebuf, "Failed to open datafile %s", datafile );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X else
- X {
- X sprintf( bw_ebuf, "Reading spherical projection datafile %s",
- X datafile );
- X bw_message( bw_ebuf );
- X }
- X
- X /* Get storage for the first point */
- X
- X if ( ( current = ( struct spj_pt *) malloc( sizeof( struct spj_pt ) )) == NULL )
- X {
- X sprintf( bw_ebuf, "Failed to allocate memory reading %s", datafile );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #ifdef OLD_DEBUG
- X else
- X {
- X sprintf( bw_ebuf, "Memory for %s allocated ok",
- X datafile );
- X bw_message( bw_ebuf );
- X }
- #endif
- X
- X start->next = current;
- X
- X /* Read the data from the file */
- X
- X c = 0;
- X while( feof( data ) == 0 )
- X {
- X
- X as_fgets( read_buffer, 127, data );
- X sscanf( read_buffer, "%d%lf%lf%lf", &co, &la, &lo, &di );
- X current->code = co;
- X current->latitude = la;
- X current->longitude = lo;
- X current->radius = di;
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "[pr:] spj_readsd(): %d: %.1lf %.1lf",
- X c, la, lo );
- X bw_message( bw_ebuf );
- #endif
- X
- X /* Now get a new 'current' */
- X
- X if ( ( new = (struct spj_pt *)
- X malloc( sizeof( struct spj_pt ) )) == 0 )
- X {
- X sprintf( bw_ebuf, "Failed to allocate memory reading %s", datafile );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #ifdef OLD_DEBUG
- X else
- X {
- X sprintf( bw_ebuf, "Memory for %s allocated ok",
- X datafile );
- X bw_message( bw_ebuf );
- X }
- #endif
- X
- X /* Reassign linkage from current to new */
- X
- X if ( feof( data ) == FALSE )
- X {
- X current->next = new;
- X current = new;
- X current->next = end;
- X }
- X
- X if ( ferror( data ) != FALSE )
- X {
- X sprintf( bw_ebuf, "Failed reading %s", datafile );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X ++c;
- X }
- X
- X fclose( data );
- X return TRUE;
- X }
- X
- /***************************************************************
- X
- X spj_calc() Calculate a linked set of SPJ
- X point structures
- X
- ***************************************************************/
- X
- spj_calc( start, end, vlat, vlon, vdis, forced_radius, rotation, mode, poll )
- X struct spj_pt *start, *end;
- X double vlat, vlon, vdis;
- X double forced_radius;
- X double rotation;
- X int mode;
- X int (*poll)();
- X {
- X struct spj_pt *current;
- X static double x, y;
- X static int side;
- X register int d;
- X double radius;
- X
- #ifdef DEBUG
- X if ( ( vlat < -90.0 ) || ( vlat > 90.0 ))
- X {
- X sprintf( bw_ebuf, "[pr:] spj_calc() received vlat = %lf", vlat );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( ( vlon < -180.0 ) || ( vlon > 180.0 ))
- X {
- X sprintf( bw_ebuf, "[pr:] spj_calc() received vlon = %lf", vlon );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( vdis < 0.0 )
- X {
- X sprintf( bw_ebuf, "[pr:] spj_calc() received vdis = %lf", vdis );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( ( rotation < 0.0 ) || ( rotation > 360.0 ))
- X {
- X sprintf( bw_ebuf, "[pr:] spj_calc() received rotation = %lf", rotation );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( ( mode < 0 ) || ( mode > 2 ))
- X {
- X sprintf( bw_ebuf, "[pr: spj_calc() received mode = %d", mode );
- X bw_error( bw_ebuf );
- X return;
- X }
- #endif
- X
- X d = 0;
- X current = start->next;
- X while( current != end )
- X {
- X
- X ++d;
- X
- X if ( forced_radius == 0.0 )
- X {
- X radius = current->radius;
- X }
- X else
- X {
- X radius = forced_radius;
- X }
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, " calculate %d: lat %0.2lf, lon %0.2lf, rad %0.2lf >>",
- X d, current->latitude, current->longitude, radius );
- X bw_message( bw_ebuf );
- X kb_rx();
- #endif
- X
- X spj_point( current->latitude, current->longitude,
- X radius, vlat, vlon, vdis, rotation,
- X mode, &x, &y, &side );
- X current->x = x;
- X current->y = y;
- X current->side = side;
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, " x = %0.2lf, y = %0.2lf, v = %d >>",
- X current->x * ACC_FAC,
- X current->y * ACC_FAC,
- X current->side );
- X bw_message( bw_ebuf );
- X kb_rx();
- #endif
- X
- X /* call poll function */
- X
- X (*poll) ();
- X
- X current = current->next;
- X }
- X }
- X
- /***************************************************************
- X
- X spj_point() Calculate a spherical projection point
- X
- X This routine is, in a sense, the heart of the Space
- X Flight Simulator and other spherical-projection programs
- X related to it, such as the Space Flight Atlas.
- X
- ***************************************************************/
- X
- spj_point( plat, plon, prad, vlat, vlon, vdis, rotation, mode, x, y, side )
- X double plat; /* latitude of point in object coordinates */
- X double plon; /* longitude of point in object coordinates */
- X double prad; /* "radius" i.e., distance from center of
- X object, of the point */
- X double vlat; /* latitude of viewer */
- X double vlon; /* longitude of viewer */
- X double vdis; /* distance of viewer from center of object */
- X double rotation; /* rotation of object in degrees, counter-
- X clockwise;
- X int mode; /* mode of calculation, i.e., side(s) to calculate */
- X double *x; /* return x viewer coordinate in degrees of arc */
- X double *y; /* return y viewer coordinate in degrees of arc */
- X int *side; /* return side of sphere */
- X {
- X static double old_vlat = 361.0;
- X static double old_vlon = 361.0;
- X static double old_vdis = -1.0;
- X static double old_plat = 361.0;
- X static double old_plon = 361.0;
- X static double old_prad = -1.0;
- X static double old_rot = 361.0;
- X static double x_lon = 361.0;
- X static double x_rsin, x_rcos;
- X static double x_cosplat, x_sinplat;
- X static double x_cosvlat, x_sinvlat;
- X static double x_angrad;
- X double x_cosc, x_cosl;
- X double x_temp, y_temp;
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "[pr:] spj_point() received: plat %0.2lf, plon %0.2lf, prad %0.2lf >>",
- X plat, plon, prad );
- X bw_message( bw_ebuf );
- X kb_rx();
- X sprintf( bw_ebuf, "[pr:] spj_point() received: vlat %0.2lf, vlon %0.2lf, vdis %0.2lf >>",
- X vlat, vlon, vdis );
- X bw_message( bw_ebuf );
- X kb_rx();
- X sprintf( bw_ebuf, "[pr:] spj_point() received: rot %0.2lf, mode %d >>",
- X rotation, mode );
- X bw_message( bw_ebuf );
- X kb_rx();
- #endif
- X
- #ifdef DEBUG
- X if ( ( vlat < -90.0 ) || ( vlat > 90.0 ))
- X {
- X sprintf( bw_ebuf, "[pr:] spj_calc() received vlat = %lf", vlat );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( ( vlon < -180.0 ) || ( vlon > 180.0 ))
- X {
- X sprintf( bw_ebuf, "[pr:] spj_calc() received vlon = %lf", vlon );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( vdis < 0.0 )
- X {
- X sprintf( bw_ebuf, "[pr:] spj_calc() received vdis = %lf", vdis );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( ( plat < -90.0 ) || ( plat > 90.0 ))
- X {
- X sprintf( bw_ebuf, "[pr:] spj_calc() received plat = %lf", plat );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( ( plon < -180.0 ) || ( plon > 180.0 ))
- X {
- X sprintf( bw_ebuf, "[pr:] spj_calc() received plon = %lf", plon );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( prad < 0.0 )
- X {
- X sprintf( bw_ebuf, "[pr:] spj_calc() received prad = %lf", prad );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( ( rotation < 0.0 ) || ( rotation > 360.0 ))
- X {
- X sprintf( bw_ebuf, "[pr:] spj_calc() received rotation = %lf", rotation );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( ( mode < 0 ) || ( mode > 2 ))
- X {
- X sprintf( bw_ebuf, "[pr: spj_calc() received mode = %d", mode );
- X bw_error( bw_ebuf );
- X return;
- X }
- #endif
- X
- X /* if longitude is changed, calculate its sine and cosine */
- X
- X if ( plon != old_plon )
- X {
- X x_lon = spj_meridian( vlon, plon );
- X old_plon = plon;
- #ifdef OLD_DEBUG
- X bw_message( "[pr:] spj_point() recalculated plon" );
- X kb_rx();
- #endif
- X }
- X
- X /* if viewer latitude is changed, calculate its sine and cosine */
- X
- X if ( vlat != old_vlat )
- X {
- X x_cosvlat = vpt_cos( vlat );
- X x_sinvlat = vpt_sin( vlat );
- X old_vlat = vlat;
- #ifdef OLD_DEBUG
- X bw_debug( "[pr:] spj_point() recalculated vlat" );
- #endif
- X }
- X
- X /* if point latitude is changed, calculate its sine and cosine */
- X
- X if ( plat != old_plat )
- X {
- X x_cosplat = vpt_cos( plat );
- X x_sinplat = vpt_sin( plat );
- X old_plat = plat;
- #ifdef OLD_DEBUG
- X bw_debug( "[pr:] spj_point() recalculated plat" );
- #endif
- X }
- X
- X /* calculations to determine side */
- X
- X x_cosl = vpt_cos( x_lon ) * x_cosplat;
- X x_cosc = x_sinvlat * x_sinplat + x_cosvlat * x_cosl;
- X
- X /* Note side of sphere, and return if this side is not
- X to be calculated now */
- X
- X if ( x_cosc < 0 )
- X {
- X *side = SPJ_FARSIDE;
- X if ( mode == SPJ_NEARSIDE )
- X {
- X return;
- X }
- X }
- X else
- X {
- X *side = SPJ_NEARSIDE;
- X if ( mode == SPJ_FARSIDE )
- X {
- X return;
- X }
- X }
- X
- X /* if point radius or viewer distance is changed, recalculate
- X the angular radius */
- X
- X if ( ( prad != old_prad ) || ( vdis != old_vdis ))
- X {
- X x_angrad = spj_angrad( vdis, prad );
- X old_prad = prad;
- X old_vdis = vdis;
- #ifdef OLD_DEBUG
- X bw_message( "[pr:] spj_point() recalculated angular radius" );
- X kb_rx();
- #endif
- X }
- X
- X /* Assign unrotated values */
- X
- X *x = x_angrad * ( x_cosplat * vpt_sin( x_lon ) );
- X *y = x_angrad * ( x_cosvlat * x_sinplat - x_sinvlat * x_cosl );
- X
- X /* if rotation has changed, recalculate its sine and cosine */
- X
- X if ( rotation != old_rot )
- X {
- X x_rsin = vpt_sin( rotation );
- X x_rcos = vpt_cos( rotation );
- X old_rot = rotation;
- #ifdef OLD_DEBUG
- X bw_message( "[pr:] spj_point() recalculated rotation" );
- X kb_rx();
- #endif
- X }
- X
- X /* Rotate the image */
- X
- X x_temp = *x;
- X y_temp = *y;
- X *x = 0.0 - (( x_temp * x_rcos ) - ( y_temp * x_rsin ));
- X *y = ( x_temp * x_rsin ) + ( y_temp * x_rcos );
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "[pr:] spj_point() returns: x %0.2lf, y %0.2lf, side %d >>",
- X *x, *y, *side );
- X bw_message( bw_ebuf );
- X kb_rx();
- #endif
- X
- X }
- X
- /***************************************************************
- X
- X spj_meridian() Calculate the distance in degrees
- X between a point's longitude and the
- X viewer's longitude
- X
- ***************************************************************/
- X
- double
- spj_meridian( vlon, plon )
- X double vlon; /* viewer's longitude */
- X double plon; /* point longitude */
- X {
- X double retval;
- X
- X retval = vlon - plon;
- X if ( retval < -180 )
- X {
- X retval += 360;
- X }
- X if ( retval > 180 )
- X {
- X retval -= 360;
- X }
- X return retval;
- X }
- X
- /***************************************************************
- X
- X spj_angrad() Calculate the angular radius of an object
- X given the radius of the object and the
- X distance to the viewer
- X
- ***************************************************************/
- X
- double
- spj_angrad( distance, radius )
- X double distance, radius;
- X {
- X
- #ifdef DEBUG
- X if ( distance == 0.0 )
- X {
- X sprintf( bw_ebuf, "[pr:] spj_angrad() received distance = %lf",
- X distance );
- X bw_error( bw_ebuf );
- X return 1.0;
- X }
- #endif
- X
- X return ( RAD_DEG * atan( radius / distance ));
- X }
- X
- /***************************************************************
- X
- X spj_degfix() Fix degrees, i.e., 0 < d < 360
- X
- ***************************************************************/
- X
- double
- spj_degfix( n )
- X double n;
- X {
- X double retval;
- X
- X retval = n;
- X while ( retval < 0 )
- X {
- X retval += 360;
- X }
- X while ( retval > 360 )
- X {
- X retval -= 360;
- X }
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "spj_degfix(): rec %.2lf, ret %.2lf", n, retval );
- X bw_debug( bw_ebuf );
- #endif
- X
- X return retval;
- X }
- X
- /***************************************************************
- X
- X as_fgets() Gets a string from a bitstream,
- X excluding strings that begin with ';'
- X
- X This function acts exactly as the standard Unix/C
- X fgets() function, except that it rejects lines that
- X begin with a semicolon. This alllows us to imbed
- X comment lines in as datafiles by beginning them with
- X a semicolon.
- X
- ***************************************************************/
- X
- char *
- as_fgets( s, n, stream )
- X char *s;
- X int n;
- X FILE *stream;
- X {
- X char *r;
- X
- X r = (char *) 1;
- X s[ 0 ] = ';';
- X while( s[ 0 ] == ';' )
- X {
- X r = fgets( s, n, stream );
- X if ( r == NULL )
- X {
- X return NULL;
- X }
- X }
- X return r;
- X }
- X
- SHAR_EOF
- chmod 0644 sfs/as/as_spj.c ||
- echo 'restore of sfs/as/as_spj.c failed'
- Wc_c="`wc -c < 'sfs/as/as_spj.c'`"
- test 14480 -eq "$Wc_c" ||
- echo 'sfs/as/as_spj.c: original size 14480, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= sfs/as/as_test.c ==============
- if test -f 'sfs/as/as_test.c' -a X"$1" != X"-c"; then
- echo 'x - skipping sfs/as/as_test.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting sfs/as/as_test.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'sfs/as/as_test.c' &&
- /****************************************************************
- X
- X as_test.c test astronomical (as) subsystem
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- ****************************************************************/
- X
- #include "stdio.h"
- X
- #include "math.h"
- #include "time.h"
- #include "bw.h"
- #include "as.h"
- X
- #ifndef __STDC__
- #define time_t long
- #endif
- X
- struct as_focus test_focus;
- struct as_orbit test_orbit;
- X
- char bw_ebuf[ BW_EBUFSIZE ];
- X
- /***************************************************************
- X
- X main() Main function for stand-alone TEST
- X
- ***************************************************************/
- X
- main()
- X {
- X static char c;
- X int keep_on;
- X
- X keep_on = 1;
- X while( keep_on == 1 )
- X {
- X
- X vpt_init();
- X vpt_level = 1;
- X
- X ast_rollup();
- X printf( "Test \"as\" (Astronomical) Functions: \n" );
- X printf( "---------------------------------- \n" );
- X printf( "\n" );
- X printf( " f - Test Focal Datafile (fd) Read Function \n" );
- X printf( " o - Test Orbital Functions \n" );
- X printf( " r - Test Angular Radius Function \n" );
- X printf( " s - Test Spherical Projection \n" );
- X printf( "\n" );
- X printf( " x - Exit \n" );
- X printf( "\n" );
- X printf( " Select: " );
- X c = getchar();
- X fflush( stdin );
- X
- X switch( c )
- X {
- X case 'F':
- X case 'f':
- X ast_readfd();
- X break;
- X case 'O':
- X case 'o':
- X ast_orbital();
- X break;
- X case 'R':
- X case 'r':
- X ast_angrad();
- X break;
- X case 'S':
- X case 's':
- X ast_spj();
- X break;
- X case 'X':
- X case 'x':
- X ast_rollup();
- X keep_on = 0;
- X break;
- X default:
- X break;
- X }
- X }
- X }
- X
- ast_rollup()
- X {
- X register int c;
- X
- X for ( c = 0; c < 25; ++c )
- X {
- X printf( "\n" );
- X }
- X }
- X
- /***************************************************************
- X
- X ast_orbital() test orbital functions
- X
- ***************************************************************/
- X
- ast_orbital()
- X {
- X static long t, r, n;
- X static double lat, lon, ap, aa;
- X
- X test_orbit.focus = &test_focus;
- X
- X ast_rollup();
- X printf( "Test Orbital Functions \n" );
- X printf( "---------------------- \n\n" );
- X
- X printf( "Radius of the focus (km): " );
- X scanf( "%lf", &test_orbit.focus->radius );
- X
- X printf( "Sidereal period of the focus: " );
- X scanf( "%lf", &test_orbit.focus->sid_day );
- X
- X printf( "Mass of the focus (grams): " );
- X scanf( "%lf", &test_orbit.focus->mass );
- X
- X printf( "Altitude of perigee (km): " );
- X scanf( "%lf", &ap );
- X
- X printf( "Altitude of apogee (km): " );
- X scanf( "%lf", &aa );
- X
- X printf( "Inclination (degrees): " );
- X scanf( "%lf", &test_orbit.inclination );
- X
- X printf( "Longitude of ascending node (degrees): " );
- X scanf( "%lf", &test_orbit.lon_an );
- X
- X printf( "Argument of the perigee (degrees): " );
- X scanf( "%lf", &test_orbit.arg_per );
- X
- X fflush( stdin );
- X
- X or_init( &test_orbit, ap, aa );
- X
- X printf( "\n" );
- X printf( "Focus: Radius = %lf\n", test_orbit.focus->radius );
- X printf( " Sidereal Day = %lf\n", test_orbit.focus->sid_day );
- X printf( " Mass = %lf\n", test_orbit.focus->mass );
- X printf( "Orbital Parameters: Semimajor axis = %lf\n", test_orbit.semimajor );
- X printf( " Semiminor axis = %lf\n", test_orbit.semiminor );
- X printf( " Period (T) = %lf\n", test_orbit.period );
- X printf( " Eccentricity = %lf\n", test_orbit.eccentricity );
- X printf( " Lon. As. Node = %lf\n", test_orbit.lon_an );
- X printf( " Inclination = %lf\n", test_orbit.inclination );
- X printf( " Arg. Perigee = %lf\n", test_orbit.arg_per );
- X printf( " Long. inc. = %lf\n", test_orbit.lif );
- X printf( "\n" );
- X ast_wait();
- X
- X for ( t = 0; t < ( test_orbit.period * 3); t += ( test_orbit.period / 12 ))
- X {
- X or_ssp( &test_orbit, t, &lat, &lon, &r, &n );
- X printf( "Orbit %ld, time %ld: \t\nDistance: %ld km \tlat: %lf deg \tlon: %lf deg\n",
- X n, t, (long) (r - test_orbit.focus->radius ), lat,
- X lon );
- X }
- X }
- X
- /***************************************************************
- X
- X ast_angrad() test angular radius function
- X
- ***************************************************************/
- X
- ast_angrad()
- X {
- X static double distance, radius;
- X double ang_rad;
- X
- X ast_rollup();
- X printf( "Test Angular Radius Function \n" );
- X printf( "-------------------------- \n\n" );
- X
- X printf( "Radius of the focus (km): " );
- X scanf( "%lf", &radius );
- X
- X printf( "Distance to the focus (km): " );
- X scanf( "%lf", &distance );
- X
- X ang_rad = spj_angrad( distance, radius );
- X printf( "\nThe angular radius is %0.9lf degrees. \n", ang_rad );
- X ast_wait();
- X
- X }
- X
- ast_wait()
- X {
- X printf( "\nPress any key: " );
- X getchar();
- X }
- X
- /***************************************************************
- X
- X ast_spj() test spherical projection
- X
- ***************************************************************/
- X
- ast_spj()
- X {
- X static double x, y, side;
- X static double radius, distance;
- X static double vlat, vlon;
- X static double plat, plon;
- X
- X ast_rollup();
- X printf( "Test Spherical Projection Point Calculation Function \n" );
- X printf( "---------------------------------------------------- \n\n" );
- X
- X printf( "Radius of the point (km): " );
- X scanf( "%lf", &radius );
- X printf( "Latitude of the point: " );
- X scanf( "%lf", &plat );
- X printf( "Longitude of the point: " );
- X scanf( "%lf", &plon );
- X printf( "Distance from viewer (km): " );
- X scanf( "%lf", &distance );
- X printf( "Latitude of viewer: " );
- X scanf( "%lf", &vlat );
- X printf( "Longitude of viewer: " );
- X scanf( "%lf", &vlon );
- X
- X spj_point( plat, plon, radius, vlat, vlon, distance, 0.0,
- X SPJ_ALLSIDES, &x, &y, &side );
- X printf( "\n\nPoint is on the " );
- X if ( side == SPJ_NEARSIDE )
- X {
- X printf( "near " );
- X }
- X else
- X {
- X printf( "far " );
- X }
- X printf( "side of the sphere:\n" );
- X printf( "x axis: %lf degrees of arc (left or right)\n", x );
- X printf( "y axis: %lf degrees of arc (up or down)\n", y );
- X ast_wait();
- X
- X }
- X
- /***************************************************************
- X
- X ast_readfd() test read focal data file function
- X
- ***************************************************************/
- X
- ast_readfd()
- X {
- X static char fdfile[ 128 ];
- X
- X ast_rollup();
- X printf( "Test Focal Datafile Read Function \n" );
- X printf( "--------------------------------- \n\n" );
- X
- X printf( "Enter name of a focal data file: " );
- X gets( fdfile );
- X fflush( stdin );
- X
- X if ( as_readfd( fdfile, &test_focus ) == BW_ERROR )
- X {
- X return;
- X }
- X
- X printf( "\n\n" );
- X printf( "Name of orbital focus: %s\n", test_focus.name );
- X printf( "Adjective for orbital focus: %s\n", test_focus.adjective );
- X printf( "Radius of orbital focus: %.0lf km\n", test_focus.radius );
- X printf( "Mass of orbital focus: %.2le kg\n", test_focus.mass );
- X printf( "Sidereal period of orbital focus: %.0lf seconds\n", test_focus.sid_day );
- X
- X ast_wait();
- X
- X }
- X
- bw_message( m )
- X char *m;
- X {
- X fprintf( stderr, "%s\n", m );
- X }
- X
- bw_error( m )
- X char *m;
- X {
- X fprintf( stderr, "ERROR: %s\n", m );
- X getchar();
- X fflush( stdin );
- X }
- X
- #ifdef DEBUG
- bw_debug( m )
- X char *m;
- X {
- X fprintf( stderr, "DEBUG: %s\n", m );
- X getchar();
- X fflush( stdin );
- X }
- #endif
- X
- SHAR_EOF
- chmod 0644 sfs/as/as_test.c ||
- echo 'restore of sfs/as/as_test.c failed'
- Wc_c="`wc -c < 'sfs/as/as_test.c'`"
- test 8757 -eq "$Wc_c" ||
- echo 'sfs/as/as_test.c: original size 8757, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= sfs/as/as_test.mak ==============
- if test -f 'sfs/as/as_test.mak' -a X"$1" != X"-c"; then
- echo 'x - skipping sfs/as/as_test.mak (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting sfs/as/as_test.mak (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'sfs/as/as_test.mak' &&
- PROJ =AS_TEST
- DEBUG =0
- CC =qcl
- CFLAGS_G = /AL /W1 /Za /DDEBUG
- CFLAGS_D = /Zd /Gi$(PROJ).mdt /Od
- CFLAGS_R = /O /Ot /DNDEBUG
- CFLAGS =$(CFLAGS_G) $(CFLAGS_R)
- LFLAGS_G =/NOI
- LFLAGS_D =/INCR /CO
- LFLAGS_R =
- LFLAGS =$(LFLAGS_G) $(LFLAGS_R)
- RUNFLAGS =
- OBJS_EXT =
- LIBS_EXT =
- X
- all: $(PROJ).exe
- X
- as_test.obj: as_test.c
- X
- as_orbit.obj: as_orbit.c
- X
- as_vpt.obj: as_vpt.c
- X
- as_spj.obj: as_spj.c
- X
- as_focus.obj: as_focus.c
- X
- $(PROJ).exe: as_test.obj as_orbit.obj as_vpt.obj as_spj.obj as_focus.obj $(OBJS_EXT)
- X echo >NUL @<<$(PROJ).crf
- as_test.obj +
- as_orbit.obj +
- as_vpt.obj +
- as_spj.obj +
- as_focus.obj +
- $(OBJS_EXT)
- $(PROJ).exe
- X
- $(LIBS_EXT);
- <<
- X link $(LFLAGS) @$(PROJ).crf
- X
- run: $(PROJ).exe
- X $(PROJ) $(RUNFLAGS)
- X
- SHAR_EOF
- chmod 0644 sfs/as/as_test.mak ||
- echo 'restore of sfs/as/as_test.mak failed'
- Wc_c="`wc -c < 'sfs/as/as_test.mak'`"
- test 703 -eq "$Wc_c" ||
- echo 'sfs/as/as_test.mak: original size 703, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= sfs/as/as_vpt.c ==============
- if test -f 'sfs/as/as_vpt.c' -a X"$1" != X"-c"; then
- echo 'x - skipping sfs/as/as_vpt.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting sfs/as/as_vpt.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'sfs/as/as_vpt.c' &&
- /****************************************************************
- X
- X as_vpt.c Variable precision trigonometry routines
- X for astronomy (as) subsystem
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- ****************************************************************/
- X
- #include "math.h"
- #include "bw.h"
- #include "as.h"
- X
- int vpt_level;
- X
- double sin_table[ 91 ];
- X
- vpt_init()
- X {
- X int i;
- X for ( i = 0; i < 91; i++ )
- X {
- X sin_table[ i ] = sin( (double) DEG_RAD * i );
- X }
- X }
- X
- double
- vpt_sin( i )
- X double i;
- X {
- X int target, work;
- X
- X switch( vpt_level )
- X {
- X case 1:
- X work = i;
- X work = (work >= 0) ? work % 360 : 359 - (-work % 360);
- X target = work % 90;
- X if (target != (work % 180) )
- X target = 90 - target;
- X return (work < 180) ?
- X sin_table[ target ] :
- X -sin_table[ target ] ;
- X default:
- X return sin( DEG_RAD * i );
- X }
- X }
- X
- double
- vpt_cos( i )
- X double i;
- X {
- X int target, work;
- X switch( vpt_level )
- X {
- X case 1:
- X work = i;
- X work = (work >= 0) ? work % 360 : 359 - (-work % 360);
- X target = work % 90;
- X if (target == (work % 180) )
- X target = 90 - target;
- X return (90 <= work && work < 270) ?
- X -sin_table[ target ] :
- X sin_table[ target ] ;
- X default:
- X return cos( DEG_RAD * i );
- X }
- X }
- X
- double
- vpt_tan( i )
- X double i;
- X {
- X double c;
- X switch( vpt_level )
- X {
- X case 1:
- X c = vpt_cos( i );
- X if ( c == 0 )
- X {
- X /* really? shouldn't it be +/-infinity */
- X return 0; /* or a signalled error? */
- X }
- X else
- X {
- X return vpt_sin( i ) / c ;
- X }
- X default:
- X return tan( DEG_RAD * i );
- X }
- X }
- X
- X
- SHAR_EOF
- chmod 0644 sfs/as/as_vpt.c ||
- echo 'restore of sfs/as/as_vpt.c failed'
- Wc_c="`wc -c < 'sfs/as/as_vpt.c'`"
- test 2526 -eq "$Wc_c" ||
- echo 'sfs/as/as_vpt.c: original size 2526, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= sfs/bin/callisto.fd ==============
- if test ! -d 'sfs/bin'; then
- echo 'x - creating directory sfs/bin'
- mkdir 'sfs/bin'
- fi
- if test -f 'sfs/bin/callisto.fd' -a X"$1" != X"-c"; then
- echo 'x - skipping sfs/bin/callisto.fd (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting sfs/bin/callisto.fd (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'sfs/bin/callisto.fd' &&
- Callisto
- Callistonian
- 4800
- 0.01779592
- 60300
- SHAR_EOF
- chmod 0644 sfs/bin/callisto.fd ||
- echo 'restore of sfs/bin/callisto.fd failed'
- Wc_c="`wc -c < 'sfs/bin/callisto.fd'`"
- test 44 -eq "$Wc_c" ||
- echo 'sfs/bin/callisto.fd: original size 44, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= sfs/bin/callisto.sfs ==============
- if test -f 'sfs/bin/callisto.sfs' -a X"$1" != X"-c"; then
- echo 'x - skipping sfs/bin/callisto.sfs (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting sfs/bin/callisto.sfs (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'sfs/bin/callisto.sfs' &&
- ;---------------------------------------
- ; callisto.sfs
- ; created Sat May 04 22:21:54 1991
- ;---------------------------------------
- Orbit around Callisto
- tfactor 1
- update 20
- trig 1
- insertion 23000
- ;---------------------------------------
- ; parameters for orbit 1
- ;---------------------------------------
- name 1 Callisto_Orbiter
- focus 1 callisto.fd
- periapsis 1 200.000000
- apoapsis 1 4000.000000
- inclination 1 30.000000
- argper 1 90.000000
- lonan 1 40.000000
- orb 1 orb.spd
- grid 1 latlon.spd
- surface 1 callisto.spd
- ;---------------------------------------
- ; end of file callisto.sfs
- ;---------------------------------------
- SHAR_EOF
- chmod 0644 sfs/bin/callisto.sfs ||
- echo 'restore of sfs/bin/callisto.sfs failed'
- Wc_c="`wc -c < 'sfs/bin/callisto.sfs'`"
- test 638 -eq "$Wc_c" ||
- echo 'sfs/bin/callisto.sfs: original size 638, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= sfs/bin/callisto.spd ==============
- if test -f 'sfs/bin/callisto.spd' -a X"$1" != X"-c"; then
- echo 'x - skipping sfs/bin/callisto.spd (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting sfs/bin/callisto.spd (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'sfs/bin/callisto.spd' &&
- ; callisto.spd
- ;
- ; map of callistonian surface features
- ;
- ;----------------------------------------------------------------
- ;
- ; Valhalla
- ;
- 1001 13.333333 -48.258860 0.000000
- 5 13.750000 -50.477658 0.000000
- 5 14.166667 -52.141757 0.000000
- 5 13.750000 -54.083205 0.000000
- 5 12.500000 -55.469954 0.000000
- 5 12.083333 -56.579353 0.000000
- 5 11.250000 -58.520801 0.000000
- 5 10.833333 -59.907550 0.000000
- 5 10.000000 -61.294299 0.000000
- 5 8.750000 -62.403698 0.000000
- 5 6.250000 -62.681048 0.000000
- 5 5.416667 -61.571649 0.000000
- 5 4.583333 -60.462250 0.000000
- 5 2.500000 -59.352851 0.000000
- 5 0.833333 -57.688752 0.000000
- 5 0.416667 -55.747304 0.000000
- 5 -0.833333 -53.251156 0.000000
- 5 -0.416667 -50.755008 0.000000
- 5 0.833333 -49.368259 0.000000
- 5 4.583333 -47.981510 0.000000
- 5 5.000000 -45.208012 0.000000
- 5 5.833333 -43.543914 0.000000
- 5 9.166667 -43.821263 0.000000
- 5 12.500000 -44.930663 0.000000
- 5 13.333333 -48.258860 0.000000
- 5 13.333333 -48.258860 0.000000
- 1001 15.000000 -45.485362 0.000000
- 5 17.500000 -47.981510 0.000000
- 5 18.333333 -50.755008 0.000000
- 5 18.333333 -54.637904 0.000000
- 5 19.166667 -57.966102 0.000000
- 5 17.500000 -61.294299 0.000000
- 5 16.250000 -63.513097 0.000000
- 5 15.416667 -64.622496 0.000000
- 5 13.333333 -66.841294 0.000000
- 5 11.666667 -69.060092 0.000000
- 5 7.916667 -69.892142 0.000000
- 5 6.250000 -69.060092 0.000000
- 5 5.000000 -67.118644 0.000000
- 5 2.916667 -66.563945 0.000000
- 5 1.250000 -65.731895 0.000000
- 5 0.000000 -63.790447 0.000000
- 5 -1.250000 -62.126348 0.000000
- 5 -2.083333 -60.462250 0.000000
- 5 -3.750000 -57.966102 0.000000
- 5 -3.750000 -54.915254 0.000000
- 5 -2.500000 -50.477658 0.000000
- 5 -1.250000 -48.813559 0.000000
- 5 0.416667 -46.872111 0.000000
- 5 1.666667 -43.821263 0.000000
- 5 4.583333 -42.434515 0.000000
- 5 7.916667 -41.047766 0.000000
- 5 12.083333 -42.157165 0.000000
- 5 14.583333 -45.208012 0.000000
- 5 14.583333 -45.208012 0.000000
- 1001 15.000000 -30.231125 0.000000
- 5 20.000000 -34.946071 0.000000
- 5 21.250000 -38.551618 0.000000
- 5 23.333333 -42.711864 0.000000
- 5 24.166667 -45.208012 0.000000
- 5 24.583333 -48.536210 0.000000
- 5 25.000000 -52.696456 0.000000
- 5 25.833333 -56.579353 0.000000
- 5 25.416667 -59.907550 0.000000
- 5 25.416667 -62.681048 0.000000
- 5 25.000000 -66.563945 0.000000
- 5 22.500000 -70.724191 0.000000
- 5 20.000000 -72.942989 0.000000
- 5 18.333333 -73.497689 0.000000
- 5 17.083333 -74.329738 0.000000
- 5 15.000000 -75.439137 0.000000
- 5 12.500000 -76.271186 0.000000
- 5 9.583333 -76.271186 0.000000
- 5 7.083333 -76.548536 0.000000
- 5 4.166667 -76.825886 0.000000
- 5 2.916667 -76.271186 0.000000
- 5 0.833333 -75.716487 0.000000
- 5 -0.833333 -74.884438 0.000000
- 5 -3.333333 -72.388290 0.000000
- 5 -5.416667 -69.892142 0.000000
- 5 -7.916667 -66.841294 0.000000
- 5 -11.250000 -64.067797 0.000000
- 5 -13.333333 -61.571649 0.000000
- 5 -14.583333 -57.966102 0.000000
- 5 -15.000000 -53.528505 0.000000
- 5 -12.500000 -48.258860 0.000000
- 5 -11.250000 -45.208012 0.000000
- 5 -8.750000 -42.434515 0.000000
- 5 -5.000000 -39.383667 0.000000
- 5 -0.416667 -36.055470 0.000000
- 5 4.166667 -32.727273 0.000000
- 5 9.166667 -30.785824 0.000000
- 5 14.583333 -30.508475 0.000000
- 5 14.583333 -30.508475 0.000000
- 1001 15.000000 -28.012327 0.000000
- 5 21.666667 -32.449923 0.000000
- 5 23.750000 -37.164869 0.000000
- 5 26.250000 -41.602465 0.000000
- 5 27.916667 -45.208012 0.000000
- 5 28.333333 -51.587057 0.000000
- 5 29.166667 -55.192604 0.000000
- 5 29.583333 -58.798151 0.000000
- 5 29.166667 -62.126348 0.000000
- 5 29.166667 -67.118644 0.000000
- 5 28.333333 -70.446841 0.000000
- 5 19.583333 -76.271186 0.000000
- 5 16.250000 -78.489985 0.000000
- 5 12.083333 -80.708783 0.000000
- 5 4.583333 -80.431433 0.000000
- 5 -3.750000 -79.599384 0.000000
- 5 -9.583333 -75.439137 0.000000
- 5 -15.000000 -68.228043 0.000000
- 5 -17.916667 -62.681048 0.000000
- 5 -18.333333 -57.411402 0.000000
- 5 -17.916667 -51.864407 0.000000
- 5 -13.750000 -44.375963 0.000000
- 5 -10.416667 -39.661017 0.000000
- 5 -5.833333 -36.055470 0.000000
- 5 -1.666667 -33.836672 0.000000
- 5 3.333333 -30.508475 0.000000
- 5 15.416667 -28.844376 0.000000
- 5 15.416667 -28.844376 0.000000
- 1001 15.000000 -18.582435 0.000000
- 5 19.583333 -21.078582 0.000000
- 5 23.750000 -28.844376 0.000000
- 5 27.500000 -35.778120 0.000000
- 5 30.416667 -41.047766 0.000000
- 5 32.500000 -44.653313 0.000000
- 5 32.916667 -47.426810 0.000000
- 5 33.333333 -49.645609 0.000000
- 5 32.916667 -56.579353 0.000000
- 5 32.083333 -60.462250 0.000000
- 5 32.500000 -63.513097 0.000000
- 5 29.166667 -72.665639 0.000000
- 5 26.666667 -75.161787 0.000000
- 5 22.083333 -79.322034 0.000000
- 5 18.333333 -81.818182 0.000000
- 5 15.833333 -84.036980 0.000000
- 5 13.333333 -84.314330 0.000000
- 5 7.500000 -84.314330 0.000000
- 5 1.666667 -85.423729 0.000000
- 5 -4.166667 -84.869029 0.000000
- 5 -11.250000 -81.540832 0.000000
- 5 -14.166667 -79.322034 0.000000
- 5 -17.083333 -75.161787 0.000000
- 5 -19.166667 -71.833590 0.000000
- 5 -21.666667 -64.067797 0.000000
- 5 -23.333333 -57.966102 0.000000
- 5 -22.500000 -50.200308 0.000000
- 5 -20.833333 -43.543914 0.000000
- 5 -17.500000 -39.661017 0.000000
- 5 -14.166667 -33.004622 0.000000
- 5 -11.250000 -29.953775 0.000000
- 5 -6.250000 -25.793529 0.000000
- 5 -1.250000 -22.742681 0.000000
- 5 4.583333 -19.969183 0.000000
- 5 14.583333 -18.859784 0.000000
- 5 14.583333 -18.859784 0.000000
- ;----------------------------------------------------------------
- ;
- ; Asgard
- ;
- 1001 30.416667 -135.069337 0.000000
- 5 30.000000 -136.733436 0.000000
- 5 27.500000 -141.448382 0.000000
- 5 26.250000 -143.667180 0.000000
- 5 23.333333 -145.608629 0.000000
- 5 20.416667 -145.331279 0.000000
- 5 18.750000 -143.667180 0.000000
- 5 17.083333 -141.448382 0.000000
- 5 15.833333 -140.338983 0.000000
- 5 16.250000 -135.901387 0.000000
- 5 16.250000 -133.405239 0.000000
- 5 17.500000 -131.463790 0.000000
- 5 19.583333 -129.522342 0.000000
- 5 23.333333 -127.303544 0.000000
- 5 25.833333 -128.135593 0.000000
- 5 27.916667 -129.522342 0.000000
- 5 28.750000 -131.741140 0.000000
- SHAR_EOF
- true || echo 'restore of sfs/bin/callisto.spd failed'
- fi
- echo 'End of part 11'
- echo 'File sfs/bin/callisto.spd is continued in part 12'
- echo 12 > _shar_seq_.tmp
- exit 0
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-