[comp.sources.misc] v07i077: Whales and Plankton, part 04/13

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

Posting-number: Volume 7, Issue 77
Submitted-by: loy@gtx.UUCP (Bob Loy)
Archive-name: whpl/part04

# whpl04of13.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:21 MST 1989
export PATH; PATH=/bin:$PATH
echo shar: extracting "'whio.c2'" '(29258 characters)'
if test -f 'whio.c2'
then
	echo shar: will not over-write existing file "'whio.c2'"
else
sed 's/^X//' << \SHAR_EOF > 'whio.c2'
X
X/*---------------------------------------------------------------------------*
X@
X@@  void  saveworld() - Saves the location array.
X@   output:  Stores the state of plankton on planet Wa-Tor in file "world",
X@               as ASCII data.  Matches no known format standard
X@   caller:  finish()
X@   calls :  malloc(), fopen()
X@
X@   Note  :  Presently lacks (as of ver 1.10) a complement function to
X@               read it back in in a subsequent run
X@
X@*---------------------------------------------------------------------------*/
X
Xvoid
Xsaveworld()
X{
X  FILE   *whwor;
X  char   *toout;
X  Uint   siz = area + vbias + vbias + 1;
X  register  int     step = 0;
X  register  int     bump;
X  int     dex = 1;
X  char    out;
X
X  toout = malloc(siz);
X  if (toout == NULL)
X    {
X      if (debug >= 2)
X          fprintf(stderr, "\nWorld malloc problems.\n");
X      return;
X    }
X  while (step < area)
X    {
X      bump = step;
X      while (bump < step + vbias)
X        {
X          out = 0x40;
X          if (locarr[bump + HBIAS * 0] == '.')
X              out |= 0x01;
X          if (locarr[bump + HBIAS * 1] == '.')
X              out |= 0x02;
X          if (locarr[bump + HBIAS * 2] == '.')
X              out |= 0x04;
X          if (locarr[bump + HBIAS * 3] == '.')
X              out |= 0x08;
X          if (locarr[bump + HBIAS * 4] == '.')
X              out |= 0x10;
X          if (locarr[bump + HBIAS * 5] == '.')
X              out |= 0x20;
X          if (out == 0x7F)
X              out = 0x3F;
X          toout[dex - 1] = out;
X          dex++;
X          if (!(dex % 51) && (dex > 25))
X            {
X              toout[dex - 1] = '\n';
X              dex++;
X            }
X          bump += 6;
X        }
X      step += vbias;
X    }
X  toout[dex - 1] = '\n';
X  whwor = fopen("world", "w");
X  fwrite(toout, sizeof(char), dex, whwor);
X  fclose(whwor);
X  free((char*) toout);
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  void  listout() - Complete dump of all whale structures to stdout.
X@   input :  Whole whale list
X@   caller:  finish()
X@   calls :  fprintf()
X@   proc  :  Primarily a debugging tool.
X@
X@*---------------------------------------------------------------------------*/
X
Xvoid
Xlistout()
X{
X  register  int     j, k;
X
X  fprintf(stdout, "\n");
X  fprintf(stdout, "Whale structure size = %u\n\n", whale_size);
X  for (j = 0; j < numwh; j++)
X    {
X      fprintf(stdout, " &^  Whale %3d :\n", j);
X      fprintf(stdout, "  Whale_id:\n");
X      fprintf(stdout, "    %10u", whale[j].self.datrun);
X      fprintf(stdout, " %10u", whale[j].self.gennum);
X      fprintf(stdout, " %10u", whale[j].self.mutate);
X      fprintf(stdout, " %s\n", whale[j].self.gns);
X      fprintf(stdout, "  Father:\n");
X      fprintf(stdout, "    %10u", whale[j].father.datrun);
X      fprintf(stdout, " %10u", whale[j].father.gennum);
X      fprintf(stdout, " %10u", whale[j].father.mutate);
X      fprintf(stdout, " %s\n", whale[j].father.gns);
X      fprintf(stdout, "  Mother:\n");
X      fprintf(stdout, "    %10u", whale[j].mother.datrun);
X      fprintf(stdout, " %10u", whale[j].mother.gennum);
X      fprintf(stdout, " %10u", whale[j].mother.mutate);
X      fprintf(stdout, " %s\n", whale[j].mother.gns);
X      fprintf(stdout, "  Offspring:\n");
X      for (k = 0; k < whale[j].childex; k++)
X        {
X          fprintf(stdout, "    %10u", whale[j].offspr[k].datrun);
X          fprintf(stdout, " %10u", whale[j].offspr[k].gennum);
X          fprintf(stdout, " %10u", whale[j].offspr[k].mutate);
X          fprintf(stdout, " %s\n", whale[j].offspr[k].gns);
X        }
X      fprintf(stdout, "  sortfield  =  %d\n", whale[j].sortfield);
X      fprintf(stdout, "  energy     = %7d\n", whale[j].energy);
X      fprintf(stdout, "  endex      =  %hd\n", whale[j].endex);
X      fprintf(stdout, "  Enrecs:\n");
X      for (k = 0; k < whale[j].endex; k++)
X        {
X          fprintf(stdout, "    %7d\n", whale[j].enrec[k]);
X        }
X      fprintf(stdout, "  die        =  %hd\n", whale[j].die);
X      fprintf(stdout, "  locatn     =  %d\n", whale[j].locatn);
X      fprintf(stdout, "  age        =  %d\n", whale[j].age);
X      fprintf(stdout, "  sex        =  %c\n", whale[j].sex);
X      fprintf(stdout, "  offratio   =  %d\n", whale[j].offratio);
X      fprintf(stdout, "  rating     =  %d\n", whale[j].rating);
X      fprintf(stdout, "  lastrat    =  %d\n", whale[j].lastrat);
X      fprintf(stdout, "  ancesave   =  %d\n", whale[j].ancesave);
X      fprintf(stdout, "  ancesmax   =  %hd\n", whale[j].ancesmax);
X      fprintf(stdout, "  ancesmin   =  %hd\n", whale[j].ancesmin);
X      fprintf(stdout, "  childex    =  %hd\n", whale[j].childex);
X      fprintf(stdout, "  allchldn   =  %hd\n", whale[j].allchldn);
X      fprintf(stdout, "  hunttype   =  %c\n", whale[j].hunttype);
X      fprintf(stdout, "  hgperchr   =  %c\n", whale[j].hgperchr);
X      fprintf(stdout, "  feedtype   =  %c\n", whale[j].feedtype);
X      fprintf(stdout, "  fgperchr   =  %c\n", whale[j].fgperchr);
X      fprintf(stdout, "  huntdex    =  %hd\n", whale[j].huntdex);
X      fprintf(stdout, "  feeddex    =  %hd\n", whale[j].feeddex);
X      fprintf(stdout, "  countgene  =  %c\n", whale[j].countgene);
X      fprintf(stdout, "  extragene  =  %c\n", whale[j].extragene);
X      fprintf(stdout, "  lastfed    =  %d\n", whale[j].lastfed);
X      fprintf(stdout, "  huntfeed   =  %c\n", whale[j].huntfeed);
X      for (k = 0; k < 5; k++)
X          fprintf(stdout, "%6hd,%3hd,%4hd ", whale[j].comp[k].diff,
X                  whale[j].comp[k].totl, whale[j].comp[k].rank);
X      fprintf(stdout, "\n");
X      for (k = 5; k < 10; k++)
X          fprintf(stdout, "%6hd,%3hd,%4hd ", whale[j].comp[k].diff,
X                  whale[j].comp[k].totl, whale[j].comp[k].rank);
X      fprintf(stdout, "\n");
X      for (k = 10; k < 15; k++)
X          fprintf(stdout, "%6hd,%3hd,%4hd ", whale[j].comp[k].diff,
X                  whale[j].comp[k].totl, whale[j].comp[k].rank);
X      fprintf(stdout, "\n");
X      for (k = 15; k < 20; k++)
X          fprintf(stdout, "%6hd,%3hd,%4hd ", whale[j].comp[k].diff,
X                  whale[j].comp[k].totl, whale[j].comp[k].rank);
X      fprintf(stdout, "\n");
X      fprintf(stdout, "  huntgene:\n  ");
X      for (k = 0; k < 16; k++)
X          fprintf(stdout, " %2hd", whale[j].huntgene[k]);
X      fprintf(stdout, "\n");
X      fprintf(stdout, "  feedgene:\n  ");
X      for (k = 0; k < 16; k++)
X          fprintf(stdout, " %2hd", whale[j].feedgene[k]);
X      fprintf(stdout, "\n");
X    }
X  fprintf(stdout, "\n");
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  void  whaleout(whale num, out fname, limit) - Outputs basic whale record.
X@   input :  Individual whale number, file for output
X@   output:  See "WHALE FILE BODY" note in fileout(), below
X@   caller:  kidsout(), fileout(), statout(), lastuff(), quiklist()
X@   calls :  fprintf()
X@
X@*---------------------------------------------------------------------------*/
X
Xvoid
Xwhaleout(j, whout, lim)
X  int     j;
X  FILE   *whout;
X  short   lim;
X{
X  register  int     k;
X  char    genes[7];
X
X  genes[0] = whale[j].hunttype;
X  genes[1] = whale[j].hgperchr;
X  genes[2] = whale[j].feedtype;
X  genes[3] = whale[j].fgperchr;
X  genes[4] = whale[j].countgene;
X  genes[5] = whale[j].extragene;
X  genes[6] = '\0';
X  if (!lim)
X    {
X      fprintf(whout, "\n# %4d", j);
X      fprintf(whout, "\nwh  ");
X    }
X  fprintf(whout, " %10u", whale[j].self.datrun);
X  fprintf(whout, " %10u", whale[j].self.gennum);
X  fprintf(whout, " %10u", whale[j].self.mutate);
X  fprintf(whout, " %s", genes);
X  fprintf(whout, "\n");
X  if (lim)
X      return;
X  if (whale[j].die >= dielim && !creonlyflg)
X      fprintf(whout, "   D");
X  else
X      fprintf(whout, "   L");
X  fprintf(whout, "  %c", whale[j].sex);
X  fprintf(whout, "   %3d", whale[j].age);
X  fprintf(whout, " %5d", whale[j].offratio);
X  fprintf(whout, "  %7d", whale[j].rating);
X  fprintf(whout, "\n");
X  fprintf(whout, " ");
X  for (k = 0; k < 16; k++)
X      fprintf(whout, " %2hd", whale[j].huntgene[k]);
X  fprintf(whout, "\n");
X  fprintf(whout, " ");
X  for (k = 0; k < 16; k++)
X      fprintf(whout, " %2hd", whale[j].feedgene[k]);
X  fprintf(whout, "\n");
X  fprintf(whout, "en   ");
X  fprintf(whout, "   %2hd\n", whale[j].endex);
X      for (k = 0; k < whale[j].endex; k++)
X          fprintf(whout, "   %7d\n", whale[j].enrec[k]);
X  fprintf(whout, "rat  ");
X  fprintf(whout, " %7d\n", whale[j].lastrat);
X  for (k = 0; k < 4; k++)
X      fprintf(whout, "%6hd %3hd %4hd ", whale[j].comp[k].diff,
X              whale[j].comp[k].totl, whale[j].comp[k].rank);
X  fprintf(whout, "\n");
X  for (k = 4; k < 8; k++)
X      fprintf(whout, "%6hd %3hd %4hd ", whale[j].comp[k].diff,
X              whale[j].comp[k].totl, whale[j].comp[k].rank);
X  fprintf(whout, "\n");
X  for (k = 8; k < 12; k++)
X      fprintf(whout, "%6hd %3hd %4hd ", whale[j].comp[k].diff,
X              whale[j].comp[k].totl, whale[j].comp[k].rank);
X  fprintf(whout, "\n");
X  for (k = 12; k < 16; k++)
X      fprintf(whout, "%6hd %3hd %4hd ", whale[j].comp[k].diff,
X              whale[j].comp[k].totl, whale[j].comp[k].rank);
X  fprintf(whout, "\n");
X  for (k = 16; k < 20; k++)
X      fprintf(whout, "%6hd %3hd %4hd ", whale[j].comp[k].diff,
X              whale[j].comp[k].totl, whale[j].comp[k].rank);
X  fprintf(whout, "\n");
X  fprintf(whout, "anc  ");
X  fprintf(whout, " %7d", whale[j].ancesave);
X  fprintf(whout, " %3hd", whale[j].ancesmax);
X  fprintf(whout, " %3hd", whale[j].ancesmin);
X  fprintf(whout, "\n");
X  fprintf(whout, "   %10u", whale[j].father.datrun);
X  fprintf(whout, " %10u", whale[j].father.gennum);
X  fprintf(whout, " %10u", whale[j].father.mutate);
X  fprintf(whout, " %s", whale[j].father.gns);
X  fprintf(whout, "\n");
X  fprintf(whout, "   %10u", whale[j].mother.datrun);
X  fprintf(whout, " %10u", whale[j].mother.gennum);
X  fprintf(whout, " %10u", whale[j].mother.mutate);
X  fprintf(whout, " %s", whale[j].mother.gns);
X  fprintf(whout, "\n");
X  fprintf(whout, "off  ");
X  fprintf(whout, " %2hd", whale[j].childex);
X  fprintf(whout, " %4hd", whale[j].allchldn);
X  fprintf(whout, "\n");
X  for (k = 0; k < whale[j].childex; k++)
X    {
X      fprintf(whout, "     %10u", whale[j].offspr[k].datrun);
X      fprintf(whout, " %10u", whale[j].offspr[k].gennum);
X      fprintf(whout, " %10u", whale[j].offspr[k].mutate);
X      fprintf(whout, " %s\n", whale[j].offspr[k].gns);
X    }
X  fprintf(whout, "\n");
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  void  kidsout(whale number) - Saves whale record into ofspring file.
X@   input :  Individual whale number
X@   output:  See "WHALE FILE BODY" note in fileout(), below
X@   caller:  mate()
X@   calls :  whaleout(); fopen(), fprintf()
X@   proc  :  Called when a whale's .childex index into it's .offspr[] array
X@               is full, and the index must be reset to 1;
X@
X@*---------------------------------------------------------------------------*/
X
Xvoid
Xkidsout(whal)
X  int     whal;
X{
X  FILE   *whkid;
X  static  char    kid[20];
X  static  char    datr[11];
X  static  char    temp[11];
X  int     j = FNMTRUNC - 1;
X
X  sprintf(temp, "%10u", daterun);
X  do{
X      j++;
X      datr[j - FNMTRUNC] = temp[j];
X    } while (temp[j] != '\0');
X  kid[0] = '\0';
X  strcat(kid, whstr);
X  strcat(kid, "o");
X  strcat(kid, datr);
X  whkid = fopen(kid, "a");
X  fprintf(whkid, "\n");
X  fprintf(whkid, "  CHILDREN FILE of whales:\n");
X  whaleout(whal, whkid, 0);
X  fprintf(whkid, "\n");
X  fclose(whkid);
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  void  genelist(array for list) - Stores each unique gene pairing in array.
X@@              Only types checked for (v1.10) are the huntgene-feedgene pair.
X@   input :  Whole whale list
X@   output:  Combines gene pairings into a short, and stores unique values in
X@               filegenes[], the array of shorts
X@   caller:  fileout()
X@   calls :  fprintf()
X@
X@*---------------------------------------------------------------------------*/
X
Xvoid
Xgenelist(filegenes, marker)
X  Ulong  *filegenes;
X  short  *marker;
X{
X  register  int     j;
X  Ulong   temp, final;
X  short   new;
X
X  for (j = 0; j < numwh; j++)
X    {
X      final = (Ulong) whale[j].hunttype;
X      final <<= 24;
X      temp = (Ulong) whale[j].hgperchr;
X      temp <<= 16;
X      final += temp;
X      temp = (Ulong) whale[j].feedtype;
X      temp <<= 8;
X      final += temp;
X      temp = (Ulong) whale[j].fgperchr;
X      final += temp;
X      for (new = 0; new <= *marker; new++)
X        {
X          if (filegenes[new] == final)
X            {
X              new = -1;
X              break;
X            }
X        }
X      if (new > -1)
X        {
X          filegenes[*marker] = final;
X          (*marker)++;
X          if (*marker >= 37)
X            {
X              if (debug >= 2)
X                  fprintf(stderr,
X                          "genelist(): more genes than we can count!\n");
X              return;
X            }
X        }
X    }
X}
X
X/*---------------------------------------------------------------------------*
X@^
X@@  void  fileout(interim) - Output file creation and writing.
X@   input :  Whole whale list
X@   caller:  interim(), finish()
X@   calls :  genelist(), whaleout(), fopen(), fprintf()
X@^  output:  fileout() writes to two output files, appending to the archive
X@^              file and creating and writing to the whale file.
X@^{
X@^  Notes on some of the nomenclature used in these comments:
X@^     'Run' stands for one execution of Whales & Plankton, from command line
X@^        invocation through to the output of these and other record files.
X@^     'Depth of ancestry' refers to number of generations down from original,
X@^        randomly created whales
X@^     Whale ID string is a whale's unique "name", given at its original crea-
X@^        tion, and that stays with it, through possibly many runs and files.
X@^        This ID string is derived from DATRUN, run, GENNUM, year, MUTATE,
X@^        gene string, and the order in which whale was created or spawned in
X@^        the given run, in this fashion:
X@^     Given in whpl.h:   DATRUN = 2088000000,  GENNUM = 1000000000, and
X@^           MUTATE = 1000000000,  a whale named:
X@^        2088091401 1000010034 1000000000 a1m4zz  might come from:
X@^                                             ^^---'z'="zero"; not used v1.10
X@^                                           ^^---One parent's feed gene types
X@^                                         ^^---Other parent's hunt gene types
X@^                           ^^---34th whale involved in this run
X@^                        ^---from "year" var; means whale was spawned
X@^                               in this particular mate cycle
X@^             ^^^^^---from -r 'run' command line option = 91401,
X@^                          this suggested format being:
X@^                          month, day, and which run on that day
X@^
X@^  The formats of the two files:
X@^
X@^  ARCHIVE FILE:
X@^     The archive file consists of lists of whale ID's, headed by the
X@^        filename the whales can be found in:
X@^
X@^    File:  whc091401
X@^     2088091401 1000000000 1000000000 a1m4zz
X@^     2088091401 1000000001 1000000000 a1a1zz
X@^     2088091401 1000000002 1000000000 m4a1zz
X@^            ...
X@^     2088091401 1000000025 1000000000 a1m4zz
X@^     2088091401 1000010026 1000000000 a1a1zz
X@^            ...
X@^     2088091401 1000010034 1000000000 m4m4zz
X@^            ...
X@^     2088091401 1000040060 1000000000 a1m4zz
X@^ 
X@^    File:  whc091402
X@^     2088091402 1000000000 1000000000 m4a1zz
X@^            ...
X@^            ...
X@^         ...and can contain any number of appended file lists.
X@^
X@^  WHALE FILE:
X@^     The whale file consists of two parts, header and body.
X@^        WHALE FILE HEADER:
X@^        Some of these values are hard coded in this function (sorry), while
X@^           others come from whpl.h constants, or from variables, most of
X@^           which are declared at the top of whpl.c:
X@^
X@^    whpl.c     1.10      Version of whpl.c creating this file
X@^    FV            1      File version for this type of file
X@^    AR       250000      Area of Wa-Tor planet 2-D contiguous map (locarr[])
X@^    VB          500      Vertical Bias (must divide into Area evenly)
X@^    NW           25      Number of whales this run started with
X@^    CR            5      Which of those that were newly created
X@^    MO           30      Months; number of move turns in this run
X@^    MV         2500      Moves per whale per month
X@^    ER       003001      Energy Ratio: 1st half = increase when whale feeds;
X@^                             2nd half = decrease for a move with no feeding
X@^    YR            5      Years; number of mating periods in this run
X@^    FM          500      %-tile level above which females may mate
X@^    ML            4      Max number of males females may attract to mate
X@^    I1            1      Inbreeding allowed? (0 = min, 1 = most; see mate())
X@^    I2            1      Inbreeding allowed? (0 = min, 1 = most; see mate())
X@^    TC            0      Cloning allowed? (0 = min, 2 = most; see mate())
X@^    CG            4      From COUNTVAL; will = 0 if whale.countgene is used
X@^                             in COUNTVAL's place in future releases.
X@^    NO            0      NORMAL; 1 means movewhale() moves are normalized
X@^    BG            0      BRKGENE; how fast to switch from hunt mode to feed
X@^                             mode (or vice-versa), 0 or 1; 1 is fastest
X@^    BC            1      BRKCHRMO; FOR FUTURE USE; same as BRKGENE for chrms
X@^    MU            0      FOR FUTURE USE: 0 means no gene mutating this run
X@^    WD          250      %-tile level below which whales die
X@^    DL            0      Die Limit: times whale can be < WD before actually
X@^                            dying; 0 means dynamically changed during run
X@^    DM            1      Whales die just B4 mating=1, just after=2, other=0
X@^    PF        41666      Plankton population Floor; start regrowing here
X@^    PC        83332      Plank Ceiling; not used v1.10, available in code
X@^    PL0          64      Beginning plankton seeding density, expressed as
X@^                             a fraction of 4096
X@^    PL1  0111121000      Alternative to PC, above: PL1 = order of calls to
X@^    PL2  0210000000          plankgrow(X) after seeding; PL2 = order after
X@^    PL3                      PF is hit.  PL3 & PL4 for future use, perhaps
X@^    PL4                      to describe periodic reseedings during run
X@^    IN FILE:             IN is also one of these 2-char file header tags
X@^      Number     61      Total whales produced this run (incl starting wh's)
X@^      Live       24      Total whales left alive at end of run
X@^      Breeds             The list of various gene combos which whales in
X@^             a1a1zz          this file have, format being:
X@^             m4m4zz          (1)huntgene type, (2)hunt genes per chromosome,
X@^             a1m4zz          (3)feedgene type, (4)feed genes per chromosome,
X@^             m4a1zz          (5)countgene, (6)extragene
X@^                       
X@^                         Then come records of individual whales:
X@^
X@^           WHALE FILE BODY
X@^    #    1
X@^    wh   2088091401 1000000001 1000000000 m4m4zz
X@^       D  F     4    -1   987760
X@^      30 31 19  4 63 38 17 58 59 33 35 49 50  7 51 43
X@^       .
X@^       .
X@^       .
X@^           (complete example, 34th whale in file):
X@^                    <-- At least one blank space preceding each record.
X@^    #   34          <-- Whale number (unique to this file only)
X@^    wh   2088091401 1000010034 1000000000 m4a1zz   <-- Four-part whale ID
X@^       L  F     3    -1  1168340  <-- live or dead, sex, age, ratio of
X@^                    offspring to age (-1 if children < 4), cumulative rating
X@^      49 40 35 36 50 49 49 37 41 52 37 18 23 19 42 34   <-- hunt gene set
X@^      40 47  3 44 30 25 39 31 62 33  5 43 24 63 44 58   <-- feed gene set
X@^    en       1      <-- number of energy records which follow (= number of
X@^                        runs that whale has survived)
X@^       1067238      <-- Finishing energy level(s) at end of run(s)
X@^    rat   1168340   <-- Rating for most recent run
X@^      2250  61  852      0   0    0      0   0    0      0   0    0
X@^         0   0    0      0   0    0      0   0    0      0   0    0
X@^         0   0    0      0   0    0      0   0    0      0   0    0
X@^         0   0    0      0   0    0      0   0    0      0   0    0
X@^         0   0    0      0   0    0      0   0    0      0   0    0
X@^      ^^^^^^^^^^^^^<-- 3-part 'success' record for up to 20 runs, if whale
X@^               survives that long: Average depth of ancestry of all whales
X@^               in run, number of whales in run, percentile ranking of this
X@^               whale this run (based on finishing energy level)
X@^    anc     3555   6   0  <-- Ancestry: average depth of ancestry, maximum
X@^                                  depth, minumum depth,
X@^       2088091302 1000030054 1000000000 m4m4zz  <-- father ID
X@^       2088091401 1000000023 1000000000 m4a1zz  <-- mother ID
X@^    off   2    2   <-- Offspring: num printed below, total num ever spawned
X@^               (only 50 can be stored/read into whale structure, excess
X@^               automatically saved in a permanent file with prefix "who"
X@^               (very few whales get anywhere near 50))
X@^         2088091401 1000020045 1000000000 m4a1zz  ]<-- children ID's
X@^         2088091401 1000030052 1000000000 a1m4zz
X@^
X@^    #   35          <-- Next whale
X@^
X@*---------------------------------------------------------------------------*/
X
Xvoid
Xfileout(interm)
X{
X  register  int     j = FNMTRUNC - 1;
X  FILE   *mainout;
X  static  char    who[20];
X  static  char    datr[11];
X  static  char    temp[11];
X  short   plumin;
X  Ulong   filegenes[38];
X  Ulong   intermed;
X  short   marker = 0;
X  char    hftemp;
X  char    hfgenes[7];
X
X  hfgenes[4] = 'z';   /* Force to 'zero' in ver 1.10 */
X  hfgenes[5] = 'z';   /* Force to 'zero' in ver 1.10 */
X  hfgenes[6] = '\0';
X  plumin = PLUS * 1000 + MINUS;
X  sprintf(temp, "%10u", daterun);
X  do{
X      j++;
X      datr[j - FNMTRUNC] = temp[j];
X    } while (temp[j] != '\0');
X  who[0] = '\0';
X  strcat(who, whstr);
X  strcat(who, keychr);
X  strcat(who, datr);
X  if (interm)
X    {
X      strcat(who, chapend);
X      strcat(who, chappend);
X    }
X  mainout = fopen(who, "w+");
X  wharc = fopen(wharcfile, "a");
X  fprintf(wharc, "\n");
X  fprintf(wharc, "File:  %s\n", who);
X  fprintf(mainout, "\n");
X  fprintf(mainout, "%s\n\n", glsccsid);
X  fprintf(mainout, "  FV   %10d\n", FILVER);
X  fprintf(mainout, "  AR   %10u\n", area);
X  fprintf(mainout, "  VB   %10u\n", vbias);
X  fprintf(mainout, "  NW   %10d\n", initwh);
X  fprintf(mainout, "  CR   %10d\n", created);
X  fprintf(mainout, "  MO   %10d\n", MONTHS);
X  fprintf(mainout, "  MV   %10d\n", MVGRP);
X  fprintf(mainout, "  ER       %06hd\n", plumin);
X  fprintf(mainout, "  YR   %10d\n", year);
X  fprintf(mainout, "  FM          500\n");
X  fprintf(mainout, "  ML   %10d\n", MALIM);
X  fprintf(mainout, "  I1   %10d\n", INBREED1);
X  fprintf(mainout, "  I2   %10d\n", INBREED1);
X  fprintf(mainout, "  TC   %10d\n", TOCLONE);
X  fprintf(mainout, "  CG   %10d\n", COUNTVAL);
X  fprintf(mainout, "  NO   %10d\n", NORMAL);
X  fprintf(mainout, "  BG   %10d\n", BRKGENE);
X  fprintf(mainout, "  BC   %10d\n", BRKCHRMO);
X  fprintf(mainout, "  MU            0\n");
X  fprintf(mainout, "  WD          250\n");
X  fprintf(mainout, "  DL   %10d\n", DIELIM);
X  fprintf(mainout, "  DM            1\n");
X  fprintf(mainout, "  PF   %10u\n", regrow);
X  fprintf(mainout, "  PC   %10u\n", stopgrow);
X  fprintf(mainout, "  PL0          64\n");
X  fprintf(mainout, "  PL1  0111121000\n");
X  fprintf(mainout, "  PL2  0210000000\n");
X  fprintf(mainout, "  PL3            \n");
X  fprintf(mainout, "  PL4            \n");
X  fprintf(mainout, "\n");
X  fprintf(mainout, "  IN FILE: \n");
X  fprintf(mainout, "    Number   %4d\n", numwh);
X  fprintf(mainout, "    Live     %4d\n", truwh);
X  fprintf(mainout, "    Breeds\n");
X  genelist(filegenes, &marker);
X  for (j = 0; j < marker; j++)
X    {
X      intermed = filegenes[j];
X      hftemp = (Uchar) intermed & 0xFF;
X      hfgenes[3] = hftemp;
X      intermed >>= 8;
X      hftemp = (char) intermed & 0xFF;
X      hfgenes[2] = hftemp;
X      intermed >>= 8;
X      hftemp = (Uchar) intermed & 0xFF;
X      hfgenes[1] = hftemp;
X      intermed >>= 8;
X      hftemp = (char) intermed & 0xFF;
X      hfgenes[0] = hftemp;
X      fprintf(mainout,
X              "           %s\n", hfgenes);
X    }
X  fprintf(mainout, "\n");
X  for (j = 0; j < numwh; j++)
X    {
X      fprintf(wharc, " %10u", whale[j].self.datrun);
X      fprintf(wharc, " %10u", whale[j].self.gennum);
X      fprintf(wharc, " %10u", whale[j].self.mutate);
X      fprintf(wharc, " %s\n", whale[j].self.gns);
X      whaleout(j, mainout, 0);
X    }
X  fprintf(mainout, "\n");
X  fclose(mainout);
X  fclose(wharc);
X}
X
X/*---------------------------------------------------------------------------*
X@^
X@@  void  statout(enerlist) - Statistic file creation and writing.
X@   input :  enerlist[] array
X@   caller:  lastuff()
X@   calls :  whaleout(); fopen(), fprintf()
X@^  output:  statout() writes to one file, name beginning with the letters
X@^              "whs".  All the run's whales appear in this file, ordered
X@^              by their energy at the time this function is called.
X@^           The format:
X@^
X@^    energy, orat, ansave, age, die,                    whale
X@^   1079521    -1    4989    0    0    88091401 10040061
X@^   1067238    -1    3555    3    0    88091401 10010034
X@^   1059732  2850    6384    2    0    88091401 10020045
X@^                         ...
X@^   1018474    -1    3681    6    0    88091302 10030054
X@^         4    -1    1835   17    1    88090903 10030041
X@^         4    -1       0    4    1    88091401 10000023
X@^                         ...
X@^         0    -1       0    4    1    88091401 10000019
X@^         0    -1    3801    9    1    88091301 10020049
X@
X@*---------------------------------------------------------------------------*/
X
Xvoid
Xstatout(enerlist, interm)
X  energarr  *enerlist;
X  short   interm;
X{
X  register  int     j = FNMTRUNC - 1;
X  FILE   *whstat;
X  static  char    whs[20];
X  static  char    datr[11];
X  static  char    temp[11];
X
X  sprintf(temp, "%10u", daterun);
X  do{
X      j++;
X      datr[j - FNMTRUNC] = temp[j];
X    } while (temp[j] != '\0');
X  whs[0] = '\0';
X  strcat(whs, whstr);
X  strcat(whs, "s");
X  strcat(whs, datr);
X  if (interm)
X    {
X      strcat(whs, chapend);
X      strcat(whs, chappend);
X    }
X  whstat = fopen(whs, "w");
X  fprintf(whstat,
X          "   energy, ansave, orat, age, die,                    whale\n");
X  for (j = numwh - 1; j >= 0; j--)
X    {
X      fprintf(whstat, "  %7d %7d %5d  %3d  %3d   ",
X              enerlist[j].ener,
X              whale[enerlist[j].whal].ancesave,
X              whale[enerlist[j].whal].offratio,
X              whale[enerlist[j].whal].age,
X              whale[enerlist[j].whal].die);
X      whaleout(enerlist[j].whal, whstat, 1);
X    }
X  fclose(whstat);
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  void  lastuff(interim) - Last computations & etc. before file output.
X@   input :  Whole whale list
X@   output:  Sorts energy list of all whales before passing it to statout()
X@            Stores each whale's energy in it's enrec[20] array
X@            Computes various ratings for each whale:   whale[].-
X@               offratio  = offspring to age ratio (if age >= 4)
X@               comp.diff = variable diffic (see proc comment)
X@               comp.totl = numwh; global var of current number of whales
X@               comp.rank = percentile rank of finishing energy
X@               lastrat = a rating computed for this run (see proc comment)
X@               rating  = variable sumrat; weighted average of whale's
X@                  lastrats for all runs (see proc comment)
X@            I've found none of these ratings particularly useful - The Author
X@            May print "FULL" or "OVERWRITTEN" warnings on stderr concerning
X@               internal arrays in individual whale records
X@   caller:  interim(), finish()
X@   calls :  statout(), whaleout(), qlohi(); qsort(), log(), calloc(),
X@               may call exit()
X@   proc  :  Ratings other than offratio are computed from the base variable
X@               diffic, which is the average of the run's whales' .ancesave
X@               fields.  This is stored directly in the .comp.diff field of
X@               the whale's internal array of "success" structures (see struct
X@               definitions in whpl.h).
X@            lastrat is computed from the whale's percentile rating multiplied
X@               by the results of taking the natural log of diffic, more or 
X@               less (there is some scaling & other fudging also going on)
X@            rating, is a weighted average of lastrats.  The present run gets
X@               a weight of 3, the previous (if any) 2, and all the ones even
X@               more previous, 1.
X@
X@   Note  :  In the whale.comp.rank field, live whales get a rank of at least
X@               250, while dead whales get a rank of 125.
X@
X@*---------------------------------------------------------------------------*/
SHAR_EOF
if test 29258 -ne "`wc -c < 'whio.c2'`"
then
	echo shar: error transmitting "'whio.c2'" '(should have been 29258 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.
                                |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~