v07i076: Whales and Plankton, part 03/13

Brandon S. Allbery - comp.sources.misc allbery at uunet.UU.NET
Wed Jul 19 11:33:05 AEST 1989


Posting-number: Volume 7, Issue 76
Submitted-by: loy at gtx.UUCP (Bob Loy)
Archive-name: whpl/part03

# whpl03of13.shar
#---cut here---cut here---cut here---cut here---cut here---
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files.
# This archive created: Sat Jan 14 04:04:12 MST 1989
export PATH; PATH=/bin:$PATH
echo shar: extracting "'enerank.c'" '(10720 characters)'
if test -f 'enerank.c'
then
	echo shar: will not over-write existing file "'enerank.c'"
else
sed 's/^X//' << \SHAR_EOF > 'enerank.c'
X
X#ifndef lint
X   static char sccsid[] = "  %M%     %I%  ";
X   static char dateid[] = "    %E%  ";
X#endif
X
X/*@#==========================================================================*
X@@#
X@@@#@^ enerank.c
X@#
X@#  Purpose:
X@@#          Create new file of whales based on value of either energy or
X@@#          percentile rank of the whales in the file(s) input to program.
X@@#          Actually, a way to practice "unnatural selection".
X@#
X@#@^Options:
X@#@^   -e <value>  select whales whose energy >= this value
X@#@^   -r <value>  select whales whose percentile rank >= this value
X@#@^         (only one can be used at a time; if both are on command line,
X@#@^          default will be last one typed in)
X@#@^
X@#  Examples:
X@#     enerank whn022222 -r 900
X@#           all whales of rank 900 or higher in "whn022222" will be written
X@#           to "whr900"
X@#     enerank -e 1000000 whn022222 -r 900
X@#           same as above; -e option overridden
X@#     enerank -e953621 whn022222 whn022223
X@#           all whales in "whn022222" & "whn022223" which finished with
X@#           energy of 953621 or higher will be written to "whr953621"
X@#     enerank -r750 `cat afile`
X@#           (where "afile" is a list of whale files, separated either by 
X@#           spaces or newlines), whales >= rank 750 will be selected from all
X@#           the whale files listed in "afile".  Output file will be "whr750"
X@#
X@#  Compiling:
X@#     cc -O enerank.c -o enerank
X@#
X@#  Functions:
X@#     int     read_infile();
X@#     void    finish_whale();
X@#     void    write_outfile();
X@#     int     skip_arg();
X@#     short   cmd_line();
X@#     void    main();
X@#
X@#  General Comments:
X@#     Note: Header information for output file will be taken from FIRST
X@#        command line argument opened for reading.
X@#
X@#---------------------------------------------------------------------------*/
X
X/*---------------------------------------------------------------------------*
X Top-level Declaration - includes, defines, externs & globals.
X*----------------------------------------------------------------------------*/
X
X#include <stdio.h>
X
X            /* EXTERNS FROM */
X      /* Functions From libraries: */
X   extern  FILE   *fopen();
X   extern  int     scanf();
X   extern  int     fprintf();
X   extern  int     strncmp();
X   extern  char   *strcpy();
X   extern  void    exit();
X
X      /* Functions From : */
X      /* Variables From : */
X
X            /* EXTERNS TO */
X      /* Functions To : */
X      /* Variables To : */
X
X            /* GLOBALS */
X   static  char    eerr = 'q';
X   static  char    cmndlnrank[9];
X   static  int     rankval = 0;
X   static  FILE   *outfp;
X   static  FILE   *infp;
X   static  char    whinstr[99];
X   static  char   *test = whinstr;
X   static  long    tell;
X   static  long    whthis = 0;
X   static  long    whthat = 0;
X   static  long    whtot = 0;
X   static  long    whgood = 0;
X
X
X/*---------------------------------------------------------------------------*
X@
X@@  int   read_infile();  Reads just enough of each whale record to find the
X@@              last energy level or last percentile rank of the whale.
X@   input :  global char  eerr
X@   caller:  main()
X@   calls :  fgets(), sscanf()
X@
X@*---------------------------------------------------------------------------*/
X
Xint
Xread_infile()
X{
X  int     edex;
X  short   j;
X  short   rk[4];
X
X  whthis++;
X  fgets(whinstr, 97, infp);
X  fgets(whinstr, 97, infp);
X  fgets(whinstr, 97, infp);
X  fgets(whinstr, 97, infp);
X  fgets(whinstr, 97, infp);
X  sscanf(whinstr, "%*s%d", &edex);
X  if (edex == 0 && eerr == 'e')
X    {
X      fprintf(stderr,
X              "read_infile(): Immature whale!  Has no energy yet\n\n");
X      return(0);
X    }
X  for (j = 0; j < edex; j++)
X      fgets(whinstr, 97, infp);
X  if (eerr == 'e')
X    {
X      sscanf(whinstr, "%d", &edex);
X      return(edex);
X    }
X  fgets(whinstr, 97, infp);
X      /* Case statements fall through on purpose */
X  switch(edex)
X    {
X      case  0:
X          fprintf(stderr,
X                  "read_infile(): Immature whale!  Has no rank yet\n\n");
X          return(0);
X      case 20:
X      case 19:
X      case 18:
X      case 17:
X          fgets(whinstr, 97, infp);
X      case 16:
X      case 15:
X      case 14:
X      case 13:
X          fgets(whinstr, 97, infp);
X      case 12:
X      case 11:
X      case 10:
X      case  9:
X          fgets(whinstr, 97, infp);
X      case  8:
X      case  7:
X      case  6:
X      case  5:
X          fgets(whinstr, 97, infp);
X      case  4:
X      case  3:
X      case  2:
X      case  1:
X          fgets(whinstr, 97, infp);
X          break;
X      default:
X          fprintf(stderr, "\nread_infile(): switch error\n");
X          return(0);
X    }
X  sscanf(whinstr, "%*hd%*hd%hd%*hd%*hd%hd%*hd%*hd%hd%*hd%*hd%hd",
X          &rk[0], &rk[1], &rk[2], &rk[3]);
X  for(j = 0; j < 4; j++)
X    {
X      if (rk[j] == 0)
X          break;
X    }
X  return(rk[j - 1]);
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  void  finish_whale();  Finds next whale in input file, keeping present
X@@              whale from being written out.
X@   caller:  main()
X@   calls :  fgets()
X@
X@*---------------------------------------------------------------------------*/
X
Xvoid
Xfinish_whale()
X{
X  do{
X      tell = ftell(infp);
X      test = fgets(whinstr, 97, infp);
X      if(whinstr[0] == '#')
X          break;
X    } while(test != NULL);
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  void  write_outfile();  Writes out present whale to output file, and
X@@              finds next whale in input file.
X@   caller:  main()
X@   calls :  fgets(), fputs()
X@
X@*---------------------------------------------------------------------------*/
X
Xvoid
Xwrite_outfile()
X{
X  fseek(infp, tell, 0);
X  test = fgets(whinstr, 97, infp);
X  do{
X      fputs(whinstr, outfp);
X      tell = ftell(infp);
X      test = fgets(whinstr, 97, infp);
X      if(whinstr[0] == '#')
X          break;
X    } while(test != NULL);
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  int   skip_arg();  Signals arguments beginning "-" so program won't try
X@@              to open them as filenames.
X@   caller:  main()
X@   return:  2  if function finds arg with a space before its value
X@   return:  1  if function finds arg with no space before its value
X@            0  otherwise (will be treated as input filename)
X@
X@*---------------------------------------------------------------------------*/
X
Xint
Xskip_arg(j, argv)
X  int     j;
X  char   *argv[];
X{
X  if(argv[j][0] == '-')
X    {
X      if (argv[j][2] == '\0')
X          return(2);
X      else
X          return(1);
X    }
X  else
X      return(0);
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  short cmd_line(count, strings);  Gets filename(s) and args from cmnd line.
X@   output:  Opens named input file(s)
X@   caller:  main()
X@   return:  0  if function makes it to end
X@            1  if file opens with error
X@
X@*---------------------------------------------------------------------------*/
X
Xshort
Xcmd_line(argc, argv)
X  int     argc;
X  char   *argv[];
X{
X  int     namepos = 0;
X  int     j, k;
X
X  fprintf(stderr, "\n");
X      /* Check for file name, occurs when first char is not '-' */
X  for(j = 0; j < argc; j++)
X    {
X      if(argv[j][0] == '-')
X        {
X          if (eerr != 'q')
X              fprintf(stderr,
X                     "  Warning: -%c opt overridden by second opt\n\n", eerr);
X          eerr = argv[j][1];
X          if (argv[j][2] == '\0')
X            {
X              j++;
X              k = -1;
X              do{
X                  k++;
X                  cmndlnrank[k] = argv[j][k];
X                } while (argv[j][k] != '\0');
X            }
X          else
X            {
X              k = 1;
X              do{
X                  k++;
X                  cmndlnrank[k - 2] = argv[j][k];
X                } while (argv[j][k] != '\0');
X            }
X          rankval = atoi(cmndlnrank);
X        }
X      if(*argv[j] != '-')
X          namepos = j;
X    }
X      /* If nothing on command line besides program name or -r */
X  if(!namepos)
X    {
X      fprintf(stderr, "\n  No input filename(s)!\n\n");
X      return(1);
X    }
X  if (eerr == 'q')
X    {
X      fprintf(stderr, "\n  No rank or energy cutoff on command line!\n\n");
X      return(1);
X    }
X  return(0);
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  void  main();  Calling module for enerank.c
X@   input :  As many input files as are on command line
X@   calls :  cmd_line(), skip_arg(), read_infile(); fopen(), fclose(),
X@            ftell(), exit()
X@
X@*---------------------------------------------------------------------------*/
X
Xvoid
Xmain(argc, argv)
X  int     argc;
X  char   *argv[];
X{
X  static  char    filenm[15] = "whr";
X  static  short   once = 1;
X  int     whalerank;
X  int     whalenergy;
X  int     j;
X  int     ret;
X
X  if(cmd_line(argc, argv))
X    {
X      fprintf(stderr, "  Problems with command line input.  Exiting.\n\n");
X      exit(9);
X    }
X  strcat(filenm, cmndlnrank);
X  outfp = fopen(filenm, "w");
X  if (outfp == NULL)
X    {
X      fprintf(stderr, "\nUnable to open output file: \"%s\"\n", filenm);
X      fprintf(stderr, "  Program exiting.\n\n");
X      exit(8);
X    }
X  fprintf(stderr, "  Output file: \"%s\" opened.\n\n", filenm);
X  j = 1;
X  while(ret = skip_arg(j, argv))
X    {
X      j++;
X      if (ret == 2)
X          j++;
X    }
X  while((infp = fopen(argv[j], "r")) != NULL)
X    {
X      tell = ftell(infp);
X      test = fgets(whinstr, 97, infp);
X      while(whinstr[0] != '#')
X        {
X          if(once)
X              fputs(whinstr, outfp);
X          tell = ftell(infp);
X          test = fgets(whinstr, 97, infp);
X          if(test == NULL)
X              break;
X        }
X      while(test != NULL)
X        {
X          once = 0;
X          if(whinstr[0] == '#')
X            {
X              whalerank = read_infile();
X              if(whalerank >= rankval)
X                {
X                  write_outfile();
X                  whthat++;
X                }
X              else
X                  finish_whale();
X            }
X        }
X      fprintf(stdout, "Whales this file:  ");
X      fprintf(stdout, "chose %4d  of %4d\n", whthat, whthis);
X      whtot += whthis;
X      whgood += whthat;
X      whthis = 0;
X      whthat = 0;
X      j++;
X      if(j >= argc)
X          break;
X      while(ret = skip_arg(j, argv))
X        {
X          j++;
X          if (ret == 2)
X              j++;
X          if(j + 1 >= argc)
X              break;
X        }
X    }
X  fprintf(stdout, "Whales all files:  ");
X  fprintf(stdout, "chose %4d  of %4d\n", whgood, whtot);
X  fprintf(stdout, "\n");
X  fclose(infp);
X  fclose(outfp);
X  exit(0);
X}
SHAR_EOF
if test 10720 -ne "`wc -c < 'enerank.c'`"
then
	echo shar: error transmitting "'enerank.c'" '(should have been 10720 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'whio.c'" '(18374 characters)'
if test -f 'whio.c'
then
	echo shar: will not over-write existing file "'whio.c'"
else
sed 's/^X//' << \SHAR_EOF > 'whio.c'
X
X/*---------------------------------------------------------------------------*
X *
X *   Copyright (c) 1987, 1988   Bob Loy
X *
X *   Please don't try to make money from whpl.c or associated files whpl.h,
X *       whx.c, genes.c, whio.c, or rando.c.  Also, don't be changing my
X *       name in this notice.
X *   Permission is otherwise granted to the user to freely delete or modify
X *       or add to any of the code in the above-named source files.
X *
X *   In other words, Experiment!
X *
X *---------------------------------------------------------------------------*/
X#ifndef lint
X   static char sccsid[] = "  whio.c     1.13  ";
X   static char dateid[] = "    88/12/18  ";
X#endif
X/*@#==========================================================================*
X@@#{
X@@@#   whio.c
X@#
X@#  Purpose:
X@@#          Command line input and file output for whpl.c.
X@#
X@#  Options:
X@#     -a <+/-int>  increases/decreases number of whales beyond constant
X@#                        NUMWH or number read in from file
X@#     -d <int>     sets debug level for output fprintf() statements
X@#     -e           forces read to end of input file
X@#     -g <string>  gene types to be placed into newly created whales
X@#     -h <int>     height of locarr[] array, overrides constant VBIAS
X@#     -i <fname>   input file; must be in a standard whale file format
X@#     -k           turns off screen display
X@#     -l           will read only live whales from input file
X@#     -m           reserved; will be for mutation modes in future releases
X@#     -n <int>     forces read of only the first <int> whales from file
X@#     -o <char>    change third letter of output filename
X@#     -p <int>     population of whales at which to write interim files
X@#     -r <int>     user-input run tag; added to constant DATRUN
X@#     -s <int>     size of locarr[] array, overrides constant AREA
X@#     -t <int>     show whale tracks rather than do a run
X@#     -v <int>     use with -t opt; area of screen to display on
X@#     -w <int>     only create new whalefile, no feeding or mating
X@#     -x <int>     the display's upper-left X AND Y locations; overrides
X@#                        STARTX and STARTY
X@#     -y <int>     continuous run up to # of years; may dump interim files
X@#     -z <fname>   alternate archive file name
X@#
X@#  Example:
X@#@^   Command line examples:
X@#@^      Based on, in whpl.h, DATRUN being 2088120000 and FNMTRUNC being 4,
X@#@^      output files would be:
X@#@^   whx                   <-- whc120000, whs120000, wha1200, & world
X@#@^   whx -o q -z whfoo     <-- whq120000, whs120000, whfoo, & world
X@#@^   whx -r 1704           <-- whc121704, whs121704, wha1200, & world
X@#@^   whx -r 1704 -y 20     <-- will run for 20 years (mate cycles); final
X@#@^                             files same as whx -r 1704; but also will
X@#@^                             likely create interim files whc121704aa,
X@#@^                             whc121704ab, ~ac, ~ad, ... ~zz; & interims
X@#@^                             whs121704aa, whs121704ab, ~ac, ... ~zz,
X@#@^                             as necessary
X@#@^   whx -r 1704 -w 8      <-- whc121704 & wha1200  (files ONLY; no run)
X@#@^   whx -o n -r 1705 -i whc121704     <-- whn121705, whs121705, world,
X@#@^                             & wha1200
X@#@^              ...in all the above, new info is appended to wha1200 if
X@#@^                         that file already exists, otherwise it's created
X@#
X@#        Based on NUMWH in whpl.h being 25, starting num of whales would be:
X@#     whx                           <-- 25 newly created (random) whales
X@#     whx -a 15                     <-- 40 newly created (random) whales
X@#     whx -a -15                    <-- 10 newly created (random) whales
X@#     whx -i whn010101              <-- Number of whales read from "Number"
X@#                                          field in whn010101 file header
X@#     whx -l -i whn010101           <-- Number of whales read from "Live"
X@#                                          field in whn010101 file header
X@#     whx -n 5 -i whn010101         <-- the first 5 whales of whn010101
X@#     whx -e -i whn010101           <-- all the whales in whn010101
X@#     whx -n 5 -a 5 -i whn010101    <-- 10; the first 5 whales of whn010101,
X@#                                          plus 5 new ones
X@#     whx -e -a 8 -i whn010101      <-- all the whales in whn010101, plus
X@#                                          8 new ones
X@#     whx -e -l -a 8 -i whn010101   <-- all the live whales in whn010101,
X@#                                          plus 8 new ones
X@#                ...note that any read from a file (-i) will override NUMWH
X@#
X@#        Misc examples:
X@#     whx -g c at i0zz     <-- gene type constant INGENTYP overridden (in v1.10,
X@#                             the zz can be left off, being unused genes)
X@#     whx -d 9          <-- turns on all debug statements to stdout & stderr
X@#     whx -k -d 0       <-- turns off display output and all debug statements
X@#     whx -p 40         <-- will write out interim files each time whale
X@#                             population exceeds 40; overrides INTERLIM
X@#     whx -x 20         <-- display will start at 20, 20 on output device
X@#     whx -x0 -s1036800 -h900   <-- display will start at 0, 0, and the
X@#                                     locarr array will be sized 1152 * 900
X@#                                     (constants AREA & VBIAS overridden)
X@#
X@#        Use of -t option:
X@#     whx -t 1       <-- shows whale tracks in 8 areas on left side of screen
X@#     whx -t 2       <-- like above, but trades hunt and feed gene sets for
X@#                          each whale
X@#     whx -t 3       <-- shows tracks of hunt genes only
X@#     whx -t 4       <-- shows tracks of feed genes only
X@#     whx -t 1 -v 3  <-- shows whale tracks in 16 areas on full screen (-v2:
X@#                          right screen; -v1: default, left screen)
X@#     whx -t 1 -g a1o4zz     <-- shows whale tracks; all with this breed type
X@#     whx -t 1 -i whn021104  <-- reads whales from file and shows them in
X@#                                  order; will overwrite screen if necessary
X@#     whx -t3 -iwhn021104 ; whx -v2 -t4 -iwhn021104  <-- reads whales from
X@#                                  file and shows hunt genes on left of
X@#                                  screen, and feed genes on the right
X@#
X@#  Compiling:
X@#     cc -O whio.c -c
X@#        or:
X@#     cc -DSUN -O whio.c -c
X@#        (-DSUN compiles for display on SMI bitmapped workstaions)
X@#
X@#  Dependencies:
X@#     whpl.h, whpl.c
X@#
X@#  Subordinate To:
X@#     whx.c
X@#
X@#  Functions:
X@#     void    ophandle();
X@#     void    printscreen();
X@#     void    saveworld();
X@#     void    listout();
X@#     void    whaleout();
X@#     void    kidsout();
X@#     void    genelist();
X@#     void    fileout();
X@#     void    statout();
X@#     void    lastuff();
X@#     void    whaleinit();  
X@#     void    look();  
X@#
X@#  General Comments:
X@#@^
X@#@^      I've found the following filename standards to be useful for keeping
X@#@^   track of the output from many runs of whpl.  As a nomenclature
X@#@^   convention, "WHF" is used below to denote a program-readable "whale
X@#@^   file" made up of records of individual whales (see fileout() for
X@#@^   complete description):
X@#@^        wha* - archive file: list of every whale created or spawned in
X@#@^                   every run appending to this file.  Program creates
X@#@^                   this prefix by default, eg, wha1200 (see fileout()).
X@#@^        whc* - created whales: WHF containing at least one new (randomly
X@#@^                   created, rather than inherited, genesets) whale.  Pro-
X@#@^                   gram creates this prefix by default, eg, whc120105.
X@#@^        whd* - dead whales: WHF of whales who have died at least once.
X@#@^        whg* - gene or sex modified whales: output of utility program
X@#@^                   symmet.c
X@#@^        whl* - live whales: WHF of successful whales; can be created from
X@#@^                   run(s)'s output file(s) by utility sortcount.c.
X@#@^        whm* - mutated whales: WHF for future ( > v1.10) versions of whpl,
X@#@^                   where random mutating of genes may happen during runs.
X@#@^        whn* - next whales: WHF from runs reading in output from previous
X@#@^                   runs.  Program can easily create this prefix by use of
X@#@^                   the -o cmnd line opt, eg: -o n , yielding whn120105
X@#@^        who* - offspring: WHF (without usual header (see fileout()) to
X@#@^                   which a whale record will be dumped when that whale's
X@#@^                   child ID array gets full in the middle of a run.
X@#@^        whr* - high rank whales: WHF of whales selected by energy level or
X@#@^                   rank.  Automatically output by utility enerank.c.
X@#@^        whs* - stat file: some whale information, ordered by energy level.
X@#@^                   Program creates this by default, eg, whs120105.
X@#@^        whx* - utilities: intermediate file prefix created by certain
X@#@^                   utility programs like sortcount.c.
X@#}
X@#---------------------------------------------------------------------------*/
X
X/*---------------------------------------------------------------------------*
X Top-level Declaration - includes, defines, externs & globals.
X*----------------------------------------------------------------------------*/
X
X#include "whpl.h"
X
X            /* EXTERNS FROM */ 
X      /* Functions From libraries: */
X   extern  void    exit(), qsort();
X   extern  char   *calloc(), *malloc(), *realloc();
X   extern  FILE   *fopen();
X   extern  int     fclose();
X
X      /* Functions From rando.c: */
X   extern  long    randout();
X
X      /* Functions From whpl.c: */
X   extern  int     qlohi();
X
X      /* Variables From whpl.c: */
X   extern  int     debug;
X   extern  whale_type   *whale;
X   extern  Uchar  *locarr;
X   extern  Uint    area;
X   extern  Uint    vbias;
X   extern  FILE   *whin;
X   extern  char    whinfile[];
X   extern  char    whinstr[];
X   extern  Uint    numwh;
X   extern  Uint    whale_size;
X   extern  Uint    truwh;
X   extern  short   endexwarn;
X   extern  char    ingentyp[];
X   extern  char    glsccsid[];
X   extern  Uint    daterun;
X   extern  int     dielim;
X   extern  int     year;
X
X
X            /* EXTERNS TO */
X      /* Functions To whpl.c: */
X   void    kidsout();
X
X      /* Functions To whx.c: */
X   void    ophandle();
X   void    printscreen();
X   void    saveworld();
X   void    listout();
X   void    whaleout();
X   void    fileout();
X   void    lastuff();
X   void    whaleinit();  
X   void    look();  
X
X      /* Variables To whx.c: */
X   char    wharcfile[40];           /*  Holds name of archive out-file */
X   char    chapend[2] = "a";        /*  Fnames append for interim output */
X   char    chappend[2] = "a";       /*  Fnames append for interim output */
X   short   wharcflg = FALSE;        /*  Flag for -z command line option */
X   short   yearflg = 0;             /*  Value for -y command line option */
X   int     interlim = INTERLIM;     /*  Pop. level to write interim files */
X   Uint    initwh;                  /*  Num of whales at start of run */
X   short   created;                 /*  For new whales created this run */
X   int     regrow;                  /*  Lower plankton population limit */
X   short   trakflg = 0;             /*  Value for -t command line option */
X   int     stopgrow;                /*  Upper plankton pop. limit  */
X
X            /* GLOBALS */
X   static  Uint    startx = STARTX;       /*  } Top left corner for out- */
X   static  Uint    starty = STARTY;       /*  }    put display device  */
X   static  FILE   *wharc;                 /*  Pointer to whale input file  */
X   static  char    whstr[3] = "wh";       /*  Whale fnames start with this */
X   static  char    keychr[2] = "c";       /*  For third letter of out-file */
X   static  short   kldispflg = FALSE;     /*  Flag for -k cmnd line opt  */
X   static  int     run = 0;               /*  Modified by -r cmnd option */
X   static  short   geneflg = FALSE;       /*  Flag for -g cmnd line option */
X   static  short   eofflg = FALSE;        /*  Flag for -e cmnd line option */
X   static  short   infileflg = FALSE;     /*  Flag for -i cmnd line option */
X   static  short   liveflg = FALSE;       /*  Flag for -l cmnd line option */
X   static  short   creonlyflg = 0;        /*  Flag/Value for -w cmnd opt */
X   static  short   addflg = 0;            /*  Value for -a cmnd line option */
X   static  Uint    readflg = 0;           /*  Value for -n cmnd line option */
X   static  short   viewflg = 1;           /*  Value for -v cmnd line option */
X
X
X/*---------------------------------------------------------------------------*
X@
X@@  void  ophandle(argc, argv) - Decipher command line arguments.
X@   output:  Sets flags & loads values into variables
X@   caller:  main()
X@   calls :  getopt(), may call exit()
X@
X@*---------------------------------------------------------------------------*/
X 
Xvoid
Xophandle(argc, argv)
X  int    argc;
X  char   *argv[];
X{
X  extern int    optind;
X  extern char   *optarg;
X  short  c;
X
X      /* Check command line arguments */
X  while ((c = getopt(argc, argv,
X          "a:d:eg:h:i:kln:o:p:r:s:t:v:w:x:y:z:")) != EOF)
X  switch(c)
X    {
X      case 'a':
X      case 'A':
X          addflg = atoi(optarg);
X          break;
X      case 'd':
X      case 'D':
X          debug = atoi(optarg);
X          break;
X      case 'e':
X      case 'E':
X          eofflg = TRUE;
X          break;
X      case 'g':
X      case 'G':
X          strncpy(ingentyp, optarg, 6);
X          geneflg = TRUE;
X          break;
X      case 'h':
X      case 'H':
X          vbias = atoi(optarg);
X          break;
X      case 'i':
X      case 'I':
X          strncpy(whinfile, optarg, 39);
X          infileflg = TRUE;
X          break;
X      case 'k':
X      case 'K':
X          kldispflg = TRUE;
X          break;
X      case 'l':
X      case 'L':
X          liveflg = TRUE;
X          break;
X      case 'n':
X      case 'N':
X          readflg = atoi(optarg);
X          break;
X      case 'o':
X      case 'O':
X          strncpy(keychr, optarg, 2);
X          break;
X      case 'p':
X      case 'P':
X          interlim = atoi(optarg);
X          break;
X      case 'r':
X      case 'R':
X          run = atoi(optarg);
X          daterun += run;
X          break;
X      case 's':
X      case 'S':
X          area = atoi(optarg);
X          break;
X      case 't':
X      case 'T':
X          trakflg = atoi(optarg);
X          break;
X      case 'v':
X      case 'V':
X          viewflg = atoi(optarg);
X          break;
X      case 'w':
X      case 'W':
X          creonlyflg = atoi(optarg);
X          if (creonlyflg == 0)
X              creonlyflg = NUMWH;
X          break;
X      case 'x':
X      case 'X':
X          startx = atoi(optarg);
X          starty = atoi(optarg);
X          break;
X      case 'y':
X      case 'Y':
X          yearflg = atoi(optarg);
X          break;
X      case 'z':
X      case 'Z':
X          strncpy(wharcfile, optarg, 39);
X          wharcflg = TRUE;
X          break;
X      default:
X          if (debug >= 1)
X            {
X              fprintf(stderr, "\n");
X              fprintf(stderr, "usage: ");
X              fprintf(stderr,
X                      "whx -r<run #> -y<years in run> -g<gene types>\n");
X              fprintf(stderr,
X               "           -i<input fname> -n<number to read fm infile>\n");
X              fprintf(stderr,
X               "           -e(read whole infile) -l(read only live whales)\n");
X              fprintf(stderr,
X               "           -a<xtra whales> -o<out-filename mod>\n");
X              fprintf(stderr,
X               "           -p<interim files> -z<alternate archive fname>\n");
X              fprintf(stderr,
X               "           -w<number of 'blank' whales>\n");
X              fprintf(stderr,
X               "           -t<gene set trades> -v<display them where>\n");
X              fprintf(stderr,
X               "           -d<debug level> -k(kill display)\n");
X              fprintf(stderr,
X               "           -x<screen topleft X & Y>\n");
X              fprintf(stderr,
X               "           -s<size of world> -h<height of world>\n");
X            }
X          exit(2);
X          break;
X    }
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  void  printscreen() - Display routine for Sun workstations.
X@   input :  Globals  startx & starty which are equal to constants STARTX &
X@               STARTY, or modified from the command line
X@   output:  Pixel by pixel display of the plankton in locarr[]
X@   caller:  main(), plankcall(), look()
X@   calls :  pr_open(), pr_put(), pr_close()
X@   proc  :  If startx & starty both = 0 locarr display top left will be at
X@               screen top left.  Otherwise there will be a margin to the
X@               top &/or left of the program output.
X@
X@   Note  :  #ifdef SUN compile condition
X@   Note  :  There is NO checking against the right & bottom limits of the
X@               device screen.
X@   Note  :  To show whales instead of the plankton (but not in real time),
X@               use the -t command line option.
X@            I experimented a bit with also displaying the whale tracks in
X@               real-time, but it really slowed down the program, and trying
X@               to show both the whales and the plankton at the same time,
X@               which would be the most interesting display, is pretty useless
X@               on a monochrome screen (Sun 3/50).  Now, someday when I have a
X@               COLOR screen to play with...
X@
X@*---------------------------------------------------------------------------*/
X
Xvoid
Xprintscreen()
X{
X#ifdef SUN
X  struct  pixrect  *screen;
X  register  int     j, x, y;
X
X  if (kldispflg == TRUE)
X      return;
X       /* Don't behave & stay in a nice window, grab the whole frame buffer */
X  screen = pr_open("/dev/fb");
X  x = startx;
X  y = starty;
X  for (j = 0; j < area; j++)
X    {
X      if (locarr[j] == ' ')
X          pr_put(screen, x, y, 0);
X      else if (locarr[j] == '.')
X          pr_put(screen, x, y, 1);
X      else
X          fprintf(stdout, "locarr[%d] = %d, and %c\n", j, locarr[j], locarr[j]);
X      y++;
X      if (y >= starty + vbias)
X        {
X          y = starty;
X          x++;
X        }
X    }
X  pr_close(screen);
X#endif
X}
SHAR_EOF
if test 18374 -ne "`wc -c < 'whio.c'`"
then
	echo shar: error transmitting "'whio.c'" '(should have been 18374 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0
---

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                |
             Bob Loy            |     Life is the detour you take on the
    ...!sun!sunburn!gtx!loy     |     way to where you're really going.
                                |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the Comp.sources.misc mailing list