[comp.sources.misc] v09i011: FPLAN 1/6

allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) (11/27/89)

Posting-number: Volume 9, Issue 11
Submitted-by: tynor@prism.gatech.edu (Steve Tynor)
Archive-name: fplan/part01

	FPLAN v.1.1 - Flight Plan program.

	FPLAN is a flight planner intended for use in general
aviation.  FPLAN reads a planfile consisting of departure and
destination airports, navigation aids, intermediate checkpoints, fuel
consumption rates, winds aloft, and produces a flight plan including
wind corrected heading, fuel consumption for each leg, vor fixes for
each checkpoint, etc.  FPLAN uses NAV format databases for upward
compatibility with those widely distributed databases (see the file
WHERE_DBS for details on how to get them).

	How is FPLAN different from NAV? Mainly, it will automatically
compute VOR cross fixes (radial and distance to/from fix) at each
waypoint along the flight and allow you to enter a waypoint as ``15
miles since the previous waypoint along the current heading''. These
features provide a kind of flight plan more useful in VFR / dead
reckoning flight, where frequent checkpoints are necessary.

	This program is in the public domain. Permission to copy,
distribute, modify this program is hearby given as long as this header
remains. If you redistribute this program after modifying it, please
document your changes so that I do not take the blame (or credit) for
those changes.  If you fix bugs or add features, please send me a
patch so that I can keep the `official' version up-to-date. Bug
reports are welcome and I'll make an attempt to fix those that are
reported.

	USE AT YOUR OWN RISK! I assume no responsibility for any
errors in this program, its databases or documentation. I will make an
effort to fix bugs, but if you crash and burn because, for example,
fuel estimates in this program were inaccurate, it's your own fault
for trusting somebody else's code! Remember, as Pilot in Command, it's
_your_ responsibility to do complete preflight planning. Use this
program as a flight planning aid, but verify its results before using
them.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
	Virtue is its own punishment.

	Steve Tynor

	Yellow Jacket Flying Club
	and
	Georgia Tech Research Institute
	Artificial Intelligence Branch
	Georgia Institute of Technology
	tynor@prism.gatech.edu

---- cut here ---- cut here ---- cut here ---- cut here ----
# This is part 1/6 of FPLAN
#!/bin/sh
# shar:	Shell Archiver  (v1.22)
#	Packed Mon Nov 20 19:28:33 EST 1989 by gaffa!tynor
#	from directory /files/home/users/tynor/src/fplan
#
#	Run the following text with /bin/sh to create:
#	  README
#	  NEW_FEATURES
#	  EXAMPLE.fplan
#	  WHERE_DBS
#	  Makefile
#	  paddb.c
#
echo "x - extracting README (Text)"
sed 's/^X//' << 'SHAR_EOF' > README &&
X	FPLAN v.1.1 - Flight Plan program.
X
X	FPLAN is a flight planner intended for use in general
Xaviation.  FPLAN reads a planfile consisting of departure and
Xdestination airports, navigation aids, intermediate checkpoints, fuel
Xconsumption rates, winds aloft, and produces a flight plan including
Xwind corrected heading, fuel consumption for each leg, vor fixes for
Xeach checkpoint, etc.  FPLAN uses NAV format databases for upward
Xcompatibility with those widely distributed databases (see the file
XWHERE_DBS for details on how to get them).
X
X	How is FPLAN different from NAV? Mainly, it will automatically
Xcompute VOR cross fixes (radial and distance to/from fix) at each
Xwaypoint along the flight and allow you to enter a waypoint as ``15
Xmiles since the previous waypoint along the current heading''. These
Xfeatures provide a kind of flight plan more useful in VFR / dead
Xreckoning flight, where frequent checkpoints are necessary.
X
X	This program is in the public domain. Permission to copy,
Xdistribute, modify this program is hearby given as long as this header
Xremains. If you redistribute this program after modifying it, please
Xdocument your changes so that I do not take the blame (or credit) for
Xthose changes.  If you fix bugs or add features, please send me a
Xpatch so that I can keep the `official' version up-to-date. Bug
Xreports are welcome and I'll make an attempt to fix those that are
Xreported.
X
X	USE AT YOUR OWN RISK! I assume no responsibility for any
Xerrors in this program, its databases or documentation. I will make an
Xeffort to fix bugs, but if you crash and burn because, for example,
Xfuel estimates in this program were inaccurate, it's your own fault
Xfor trusting somebody else's code! Remember, as Pilot in Command, it's
X_your_ responsibility to do complete preflight planning. Use this
Xprogram as a flight planning aid, but verify its results before using
Xthem.
X
X=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
X	Virtue is its own punishment.
X
X	Steve Tynor
X
X	Yellow Jacket Flying Club
X	and
X	Georgia Tech Research Institute
X	Artificial Intelligence Branch
X	Georgia Institute of Technology
X	tynor@prism.gatech.edu
SHAR_EOF
chmod 0444 README || echo "restore of README fails"
echo "x - extracting NEW_FEATURES (Text)"
sed 's/^X//' << 'SHAR_EOF' > NEW_FEATURES &&
XThe following list summarizes the difference between FPLAN version 1.0
Xand  1.1:
X
X	- Added 'return' (-r) switch to produce the return trip version
X 	  of an input plan.
X	- Ported to MessyDOS (tested with MSC and Zortech compilers).
X	  Reports from users of FPLAN 1.0 indicate that it ports fairly
X	  easily to other flavors of Unix.
X	- Added a graphic previewer for Sunview.
X	- Added DME fields to VOR fixes.
X	- Slight change in output form.
X	- Added database summary (-d) option (appends a description of each 
X	  airport and navaid used to the end of the flight plan).
X	- Fixed a bug that sometimes printed negative headings.
X	- Fixed a bug that prevented refueling at an enroute airport.
X	- Added index (3) to the strings.c file. Can anyone suggest a
X	  way to portably handle the myriad different string(3) libraries
X	  without totaly redefining everything?
X	- Changed a right recursive rule in grammar to left recursion - longer
X	  plans now supported.
X	- Added documentation on the database file format for those without
X	  access to the NAV documentation or source.
X	- Added a database formatter for creating private databases.
X	- Incremental waypoints may now be specified as a distance to the
X	  _next_ turn point as well as from the _last_.
X
XEnjoy! Let me know what you think.
X
X=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
X	Virtue is its own punishment.
X
X	Steve Tynor
X
X	Yellow Jacket Flying Club
X	and
X	Georgia Tech Research Institute
X	Artificial Intelligence Branch
X	Georgia Institute of Technology
X	tynor@prism.gatech.edu
SHAR_EOF
chmod 0444 NEW_FEATURES || echo "restore of NEW_FEATURES fails"
echo "x - extracting EXAMPLE.fplan (Text)"
sed 's/^X//' << 'SHAR_EOF' > EXAMPLE.fplan &&
X# $Id: EXAMPLE.fplan,v 1.2 89/11/05 11:44:32 tynor Exp $
X# This is an example FPLAN planfile. 
X#
X# It illustrates a simple flight from Chicago O'Hare to Champaign, IL
X# via the DuPage VOR with a 5 knot wind from 320. True airspeed is set
X# for 95 knots. VOR cross fixes from the Peotone VOR (EON) will be
X# computed. Initial fuel is 24.5 gallons and fuel economy is set to 5.4
X# gallons per hour.
X#
X# To generate a flight plan from this plan, type:
X#     fplan EXAMPLE.fplan
X# Since the default format is only 80 columns, the VOR-fix from EON is not
X# show with the previous fplan invocation. If you have a wider terminal, or
X# a wide printer, use the wide format to include the VOR-fix:
X#     fplan -w EXAMPLE.fplan
X
Xnav(2) EON;
Xfuel_amt  24.5;
Xfuel_rate 5.4;
Xtas 95;
Xwind 230@5;
Xfrom ORD;
Xvia  DPA;
Xto   CMI;
X
SHAR_EOF
chmod 0444 EXAMPLE.fplan || echo "restore of EXAMPLE.fplan fails"
echo "x - extracting WHERE_DBS (Text)"
sed 's/^X//' << 'SHAR_EOF' > WHERE_DBS &&
XThe complete NAV databases for the US can be found in several places
Xvia anonymous FTP and/or UUCP.  You'll only need the airports.nav.*
Xand vors.nav.* files to use FPLAN.
X
XThe following notes detail where and how:
X
X>From gatech!cwjcc!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!apple!geoff 
X>Thu Sep 28 09:33:31 EDT 1989
X>
X>Berry Kercheval has kindly provided an additional archive site for the
X>full US NAV database on mordor.s1.gov (26.3.0.95).  Berry will keep the
X>data there for the indefinite future, and may at some point provide
X>newer data.  The existing data will still remain on apple.com for a
X>week or so and will then be deleted.
X>
X>I neglected to mention how to decompress the files once you receive them.
X>You can either say "uncompress airports.nav.Z" and "uncompress vors.nav.Z"
X>or, if you prefer to preserve the compressed versions, utter
X>"zcat airports.nav.Z > airports.nav" and "zcat vors.nav.Z > vors.nav".
X>
X>To get the files from mordor rather than apple, do the following (well,
X>approximately):
X>
X>    apple% ftp mordor.s1.gov
X>    Connected to mordor.s1.gov.
X>    220 mordor FTP server (Version 4.172 Fri Dec 9 10:09:46 PST 1988) ready.
X>    Name (mordor.s1.gov:geoff): anonymous
X>    331 Guest login ok, send ident as password.
X>    Password:
X>    230 Guest login ok, access restrictions apply.
X>    ftp> binary
X>    200 Type set to I.
X>    ftp> get airports.nav.Z
X>    200 PORT command successful.
X>    150 Opening BINARY mode data connection for airports.nav.Z (413613 bytes).
X>    226 Transfer complete.
X>    local: airports.nav.Z remote: airports.nav.Z
X>    413613 bytes received in 11 seconds (36 Kbytes/s)
X>    ftp> get vors.nav.Z
X>    200 PORT command successful.
X>    150 Opening BINARY mode data connection for vors.nav.Z (338505 bytes).
X>    226 Transfer complete.
X>    local: vors.nav.Z remote: vors.nav.Z
X>    338505 bytes received in 6.7 seconds (49 Kbytes/s)
X>    ftp> quit
X>    221 Goodbye.
X
X------------------------------------------------------------------------------
X
X>The complete release, database as well as sources, is also available
X>for anonymous FTP on saqqara.cis.ohio-state.edu:pub/nav/* and for
X>anonymous UUCP (1200, 2400, V.32, or TB+) on osu-cis!~/nav/*, in files
X>named
X>
X>airports.nav.Z-part-a[abcde]   (sliced compressed text files)
X>vors.nav.Z-part-a[abcd]                (sliced compressed text files)
X>nav.{dbs,hdr,man}.shar.Z       (compressed shar archives)
X>nav.top_level.shar.Z           (compressed shar archive)
X>nav.src.shar-a[abcdef].Z       (compressed sliced shar archive)
X>
X>This will probably stay around for a while (at least a positive number
X>of days :-), but there are no guarantees because I'm using the space
X>there as a guest.  Because you won't be able to expand wildcards on
X>osu-cis, you'll need to issue a command for each file you want to get,
X>like
X>
X>       uucp osu-cis!~/nav/vors.nav.Z-part-aa
X>       uucp osu-cis!~/nav/vors.nav.Z-part-ab
X>       ... and so on ...
X>
X>Write to uucp@cis.ohio-state.edu (== osu-cis!uucp) for the generic
X>anonymous-UUCP instructions if you need them.
X
X
X
SHAR_EOF
chmod 0444 WHERE_DBS || echo "restore of WHERE_DBS fails"
echo "x - extracting Makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > Makefile &&
X# $Id: Makefile,v 2.18 89/11/19 16:32:28 tynor Exp Locker: tynor $
X#----------------------------------------------------------------------------
X#	FPLAN - Flight Planner
X#	Steve Tynor
X#	tynor@prism.gatech.edu
X#
X#	This program is in the public domain. Permission to copy,
X# distribute, modify this program is hearby given as long as this header
X# remains. If you redistribute this program after modifying it, please
X# document your changes so that I do not take the blame (or credit) for
X# those changes.  If you fix bugs or add features, please send me a
X# patch so that I can keep the 'official' version up-to-date.
X#
X#	Bug reports are welcome and I'll make an attempt to fix those
X# that are reported.
X#
X# 	USE AT YOUR OWN RISK! I assume no responsibility for any
X# errors in this program, its database or documentation. I will make an
X# effort to fix bugs, but if you crash and burn because, for example,
X# fuel estimates in this program were inaccurate, it's your own fault
X# for trusting somebody else's code! Remember, as PIC, it's _your_
X# responsibility to do complete preflight planning. Use this program as
X# a flight planning aid, but verify its results before using them.
X# ---------------------------------------------------------------------------
X
X# ---------------------------------------------------------------------------
X# EDIT THE FOLLOWING DEFINITIONS TO SUIT LOCAL CONDITIONS:
X# ---------------------------------------------------------------------------
X
X# ---------------------------------------------------------------------------
X# define which C compiler (if GNU, be sure to define as 'gcc -traditional')
XCC = gcc -traditional
X
X# ---------------------------------------------------------------------------
X# define where 'install' should put the man pages and executable:
XBINDIR	 = /usr/local/bin
XMANDIR	 = /usr/local/man
X
X# ---------------------------------------------------------------------------
X# define the install command as 'install' on BSD Unix, otherwise just use 'cp'
XINSTALL  = install
X
X# ---------------------------------------------------------------------------
X# define which graphics subroutines you want to include (currently, Sunview 
X# or nothing).  If you add X, NeWS, NeXT, EGA, etc. support - please mail me
X# your code so I can distribute it!)
X#GFX_OPTIONS = 
XGFX_OPTIONS = -DGFX_SUNVIEW
X
X# ---------------------------------------------------------------------------
X# define which graphics libraries are necessary for linking:
X#GFX_LIBS =
XGFX_LIBS = -lsuntool -lsunwindow -lpixrect
X
X# ---------------------------------------------------------------------------
X# define any flags required for the C compiler:
XCFLAGS   = -g $(GFX_OPTIONS)
X
X# ---------------------------------------------------------------------------
X# command to format the man pages. Note: tbl is necessary for the fplan.1 man
X# page when troffed (not necessary for nroff):
XMAN_FORMAT= nroff
X#MAN_FORMAT= tbl | troff -Tps
X
X# ---------------------------------------------------------------------------
X# NO NEED TO EDIT BELOW HERE.
X# ---------------------------------------------------------------------------
X
X# prevent certain makes (e.g. SunOS) from including wierd flags (like -sun386)
X.c.o:
X	$(CC) -c $(CFLAGS) $(CPPFLAGS) $*.c
X
XOBJS	  = output.o main.o add.o misc.o db.o compute.o fp_yacc.o fp_lex.o \
X	    strings.o reverse.o sv_draw.o
X
XC_SRC     = output.c main.c add.c misc.c db.c compute.c paddb.c \
X	    strings.c reverse.c sv_draw.c wp_info.h mystring.h version.h
X
XOTHER_SRC = fp_lex.l fp_yacc.y
X
X# things required by the DOS version which are generated by Yacc/Lex:
XDOS_SRC   = fp_lex.c fp_yacc.c fp_tok.h dosbuild.bat
X
XMAN	  = fplan.1 fplan.5 paddb.1
X
XFORMATTED_MAN = fplan.man fplan_dbs.man paddb.man
X
XDOC 	  = README NEW_FEATURES EXAMPLE.fplan $(MAN) WHERE_DBS
X
XEXE	  = fplan paddb
X
XDIST_FILES = $(DOC) Makefile $(C_SRC) $(OTHER_SRC) dosbuild.bat 
X
X# where I test the MessyDOS version:
XDOSDIR   = /u/tynor/pc/src/fplan
X
Xall : $(EXE)
Xdoc : $(FORMATTED_MAN)
X
Xpaddb.man : paddb.1
X	cat paddb.1 | $(MAN_FORMAT) -man > paddb.man
Xfplan.man : fplan.1
X	cat fplan.1 | $(MAN_FORMAT) -man > fplan.man
Xfplan_dbs.man : fplan.5
X	cat fplan.5 | $(MAN_FORMAT) -man > fplan_dbs.man
X
Xpaddb : paddb.c
X	$(CC) -o paddb paddb.c
X
Xfplan : $(OBJS)
X	$(CC) -o fplan $(OBJS) $(GFX_LIBS) -lm
X
Xfp_lex.c : fp_lex.l fp_tok.h
X	lex fp_lex.l
X	mv lex.yy.c fp_lex.c
X
Xfp_yacc.c fp_tok.h : fp_yacc.y wp_info.h
X	yacc -d fp_yacc.y
X	mv y.tab.c fp_yacc.c
X	mv y.tab.h fp_tok.h
X
X#------------
Xfp_yacc.o 	: fp_yacc.c
Xfp_lex.o 	: fp_lex.c
Xadd.o 		: add.c wp_info.h 
Xcompute.o 	: compute.c wp_info.h
Xdb.o 		: db.c wp_info.h mystring.h
Xmain.o 		: main.c wp_info.h version.h
Xmisc.o 		: misc.c 
Xoutput.o 	: output.c wp_info.h mystring.h
Xstrings.o 	: strings.c mystring.h
Xreverse.o	: reverse.c wp_info.h
Xsv_draw.o	: sv_draw.c wp_info.h
X#------------
X
X# move the current files into the DOS test directory:
Xdos : $(DOS_SRC)
X	cp $(C_SRC) $(DOSDIR)
X	cp $(DOS_SRC) $(DOSDIR)
X	(cd $(DOSDIR); /u/tynor/bin/2dos $(C_SRC) $(DOS_SRC))
X
XTAGS : $(DIST_FILES)
X	etags $(DIST_FILES)
X
Xclean : 
X	-rm *.o *~ fp_tok.h fp_lex.c fp_yacc.c fplan paddb *.man fplan.0? fplan.tar.Z
X
Xdistribute :
X	# all-in-one compressed tar file for FTP archive:
X	tar cfo fplan.tar $(DIST_FILES)
X	compress fplan.tar
X	# many shar files for newsgroup distribution:
X	cat README > fplan.01
X	echo "" >> fplan.01
X	echo "---- cut here ---- cut here ---- cut here ---- cut here ----" >> fplan.01
X	echo "# This is part 1/6 of FPLAN" >> fplan.01
X	shar2 -D -v README NEW_FEATURES EXAMPLE.fplan WHERE_DBS Makefile paddb.c >> fplan.01
X	echo "#This is part 2/6 of FPLAN" > fplan.02
X	shar2 -D -v fplan.1 fplan.5 paddb.1 >> fplan.02
X	echo "#This is part 3/6 of FPLAN" > fplan.03
X	shar2 -D -v add.c compute.c >> fplan.03
X	echo "#This is part 4/6 of FPLAN" > fplan.04
X	shar2 -D -v output.c >> fplan.04
X	echo "#This is part 5/6 of FPLAN" > fplan.05
X	shar2 -D -v main.c misc.c db.c strings.c >> fplan.05
X	echo "#This is part 6/6 of FPLAN" > fplan.06
X	shar2 -D -v fp_lex.l fp_yacc.y sv_draw.c dosbuild.bat mystring.h wp_info.h reverse.c version.h >> fplan.06
X
Xinstall :
X	$(INSTALL) $(EXE) $(BINDIR)
X	$(INSTALL) fplan.1 paddb.1 $(MANDIR)/man1
X	$(INSTALL) fplan.5 $(MANDIR)/man5
SHAR_EOF
chmod 0644 Makefile || echo "restore of Makefile fails"
echo "x - extracting paddb.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > paddb.c &&
X/*
X * $Id: paddb.c,v 1.1 89/11/11 17:29:43 tynor Exp $
X *----------------------------------------------------------------------------
X *	FPLAN - Flight Planner
X *	Steve Tynor
X *	tynor@prism.gatech.edu
X *
X *	This program is in the public domain. Permission to copy,
X * distribute, modify this program is hearby given as long as this header
X * remains. If you redistribute this program after modifying it, please
X * document your changes so that I do not take the blame (or credit) for
X * those changes.  If you fix bugs or add features, please send me a
X * patch so that I can keep the 'official' version up-to-date.
X *
X *	Bug reports are welcome and I'll make an attempt to fix those
X * that are reported.
X *
X *	USE AT YOUR OWN RISK! I assume no responsibility for any
X * errors in this program, its database or documentation. I will make an
X * effort to fix bugs, but if you crash and burn because, for example,
X * fuel estimates in this program were inaccurate, it's your own fault
X * for trusting somebody else's code! Remember, as PIC, it's _your_
X * responsibility to do complete preflight planning. Use this program as
X * a flight planning aid, but verify its results before using them.
X *----------------------------------------------------------------------------
X */
X
Xstatic char rcsid[] = "$Id: paddb.c,v 1.1 89/11/11 17:29:43 tynor Exp $";
X
X#include <stdio.h>
X#include "version.h"
X
X#define EXIT_GOOD 0
X#define EXIT_BAD  1
X
X#define MAX(a,b) ((a)>=(b)?(a):(b))
X
X/*----------------------------------------------------------------------------*/
Xusage (progname)
X     char *progname;
X{
X   fprintf (stderr, "FPLAN %s\n", VERSION);
X   fprintf (stderr, "usage: %s text-file db-file\n", progname);
X   exit (EXIT_BAD);
X}
X
X/*----------------------------------------------------------------------------*/
Xint main (argc, argv)
X     int argc;
X     char *argv[];
X{
X#define BUFSIZE 200
X   FILE *in, *out;
X   int recl = 0;
X   int len, i;
X   char buffer[BUFSIZE];
X
X#ifdef MSDOS
X#define CREATE_MODE "wb"
X#define LINE_TERMINATOR_LEN 2	/* CR-LF */
X#else
X#define CREATE_MODE "w"
X#define LINE_TERMINATOR_LEN 1	/* LF */
X#endif
X
X   if (argc != 3)
X      usage (argv[0]);
X
X   if (! (in = fopen (argv[1], "r"))) {
X      fprintf (stderr, "ERROR: opening input file: %s\n", argv[1]);
X      usage (argv[0]);
X   }
X
X   if (! (out = fopen (argv[2], CREATE_MODE))) {
X      fprintf (stderr, "ERROR: opening output file: %s\n", argv[2]);
X      usage (argv[0]);
X   }
X
X   /*
X    * first pass: find the max record length
X    */
X   while (fgets (buffer, BUFSIZE, in))
X      recl = MAX (recl, strlen (buffer) - LINE_TERMINATOR_LEN);
X
X   fclose (in);
X
X   /*
X    * second pass: copy each record to the output; pad each record
X    */
X
X   if (! (in = fopen (argv[1], "r"))) {
X      fprintf (stderr, "ERROR: opening input file: %s\n", argv[1]);
X      usage (argv[0]);
X   }
X   while (fgets (buffer, BUFSIZE, in)) {
X      len = strlen (buffer) - LINE_TERMINATOR_LEN;
X      buffer[len] = '\0';
X      fprintf (out, "%s", buffer);
X      for (i = len; i < recl; i++)
X	 putc ('\0', out);
X      putc ('\n', out);
X   }
X   fclose (in);
X   fclose (out);
X}
X
SHAR_EOF
chmod 0444 paddb.c || echo "restore of paddb.c fails"
exit 0