[comp.sources.misc] v06i089: Random Weather Generator - patch1

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

Posting-number: Volume 6, Issue 89
Submitted-by: slocum@hi-csc.UUCP
Archive-name: rndweather.p1

This is the first patch to the recently posted Random Weather Generator.

Bug fixed:
     o  Overflow on negative temperature - Temperature variable
        changed to short.

Enhancements:
     o  VMS port modifications.
     o  The Middle Earth calendar has Lithe and Yule in separate
        months, instead of being printed as part of Forelithe
        and Foreyule.
     o  The desired starting and ending years can be specified
        on the command line.  The command 'england 1066 1075' 
        will print weather for the ten years from 1066 through 1075.

My thanks to the following people who reported the bug and suggested
the modifications:

    "251 degrees in a Minnesota winter" bug:
        Michael Kent <...!{uflorida, uunet}!aleytys!mike>
        Mark E Hunter <meh@wucs1.wustl.edu>
        Dan Farmer <ajm@mentor.cc.purdue.edu>
        Kevin W. Thomas <uokmax!kwthomas@uokmax.ecn.uoknor.edu>

    VMS and Shire calendar modifications:
        Karsten Spang, NBI, Copenhagen <SPANG@nbivax.nbi.dk>

Brett Slocum   UUCP: ...uunet!hi-csc!slocum
               Arpa: hi-csc!slocum@uunet.uu.net
"My name is Inigo Montoya. You killed my father. Prepare to die."

#--------------------------------CUT HERE-------------------------------------
#! /bin/sh
#
# This is a shell archive.  Save this into a file, edit it
# and delete all lines above this comment.  Then give this
# file to sh by executing the command "sh file".  The files
# will be extracted into the current directory owned by
# you with default permissions.
#
# The files contained herein are:
#
# -rwxrwx---  1 atchan         21 Apr 12 10:40 patchlevel.h
# -rwxrwx---  1 195         11391 Apr 12 10:34 patch1
#
echo 'x - patchlevel.h'
if test -f patchlevel.h; then echo 'shar: not overwriting patchlevel.h'; else
sed 's/^X//' << '________This_Is_The_END________' > patchlevel.h
X#define PATCHLEVEL 1
________This_Is_The_END________
if test `wc -l < patchlevel.h` -ne 1; then
	echo 'shar: patchlevel.h was damaged during transit (should have been 1 bytes)'
fi
fi		; : end of overwriting check
echo 'x - patch1'
if test -f patch1; then echo 'shar: not overwriting patch1'; else
sed 's/^X//' << '________This_Is_The_END________' > patch1
X*** oMakefile	Wed Mar 22 10:29:57 1989
X--- Makefile	Wed Apr 12 09:21:49 1989
X***************
X*** 30,35
X  # GULF         - useful for Gulf States, Mediterranean, etc.
X  # N_PACIFIC    - useful for Japan, Korea, Southern Alaskan coast, etc.
X  
X  england: weather.c weather.h gregorian.h mid_atlantic.h
X  	cc -DGREGORIAN -DMID_ATLANTIC -o england -g weather.c
X  
X
X--- 30,40 -----
X  # GULF         - useful for Gulf States, Mediterranean, etc.
X  # N_PACIFIC    - useful for Japan, Korea, Southern Alaskan coast, etc.
X  
X+ # uncomment the appropriate line for System V or VMS
X+ #CFLAGS = -DVMS
X+ #CFLAGS = -DSYSV
X+ CFLAGS = 
X+ 
X  england: weather.c weather.h gregorian.h mid_atlantic.h
X  	cc -DGREGORIAN -DMID_ATLANTIC -o england -g weather.c
X*** omiddle_earth.h	Wed Feb  1 11:27:17 1989
X--- middle_earth.h	Wed Apr 12 09:38:03 1989
X***************
X*** 18,29
X  #define ASTRON      3
X  #define THRIMIDGE   4
X  #define FORELITHE   5
X! #define AFTERLITHE  6
X! #define WEDMATH     7
X! #define HALIMATH    8
X! #define WINTERFILTH 9
X! #define BLOTMATH    10
X! #define FOREYULE    11
X  
X  #define FIRST_MONTH AFTERYULE
X  #define LAST_MONTH  FOREYULE
X
X--- 18,31 -----
X  #define ASTRON      3
X  #define THRIMIDGE   4
X  #define FORELITHE   5
X! #define LITHE       6
X! #define AFTERLITHE  7
X! #define WEDMATH     8
X! #define HALIMATH    9
X! #define WINTERFILTH 10
X! #define BLOTMATH    11
X! #define FOREYULE    12
X! #define YULE        13
X  
X  #define FIRST_MONTH AFTERYULE
X  #define LAST_MONTH  YULE
X***************
X*** 26,32
X  #define FOREYULE    11
X  
X  #define FIRST_MONTH AFTERYULE
X! #define LAST_MONTH  FOREYULE
X  
X  #define N_MONTHS (LAST_MONTH - FIRST_MONTH) + 1
X  
X
X--- 28,34 -----
X  #define YULE        13
X  
X  #define FIRST_MONTH AFTERYULE
X! #define LAST_MONTH  YULE
X  
X  #define N_MONTHS (LAST_MONTH - FIRST_MONTH) + 1
X  
X***************
X*** 37,42
X      "Astron",
X      "Thrimidge",
X      "Forelithe",
X      "Afterlithe",
X      "Wedmath",
X      "Halimath",
X
X--- 39,45 -----
X      "Astron",
X      "Thrimidge",
X      "Forelithe",
X+     "Lithe",
X      "Afterlithe",
X      "Wedmath",
X      "Halimath",
X***************
X*** 43,48
X      "Winterfilth",
X      "Blotmath",
X      "Foreyule",
X  };
X  
X  UBYTE Day_Table[N_MONTHS] = {30, 30, 30, 30, 30, 31, 30, 30, 30, 30, 30, 34};
X
X--- 46,52 -----
X      "Winterfilth",
X      "Blotmath",
X      "Foreyule",
X+     "Yule",
X  };
X  
X  UBYTE Day_Table[N_MONTHS] = {30, 30, 30, 30, 30, 30, 1, 30, 30, 30, 30, 30, 30, 4};
X***************
X*** 45,51
X      "Foreyule",
X  };
X  
X! UBYTE Day_Table[N_MONTHS] = {30, 30, 30, 30, 30, 31, 30, 30, 30, 30, 30, 34};
X  
X  void
X  print_holiday(day, month)
X
X--- 49,55 -----
X      "Yule",
X  };
X  
X! UBYTE Day_Table[N_MONTHS] = {30, 30, 30, 30, 30, 30, 1, 30, 30, 30, 30, 30, 30, 4};
X  
X  void
X  print_holiday(day, month)
X***************
X*** 64,71
X       case THRIMIDGE:
X           break;
X       case FORELITHE:
X-          if (day == 31) 
X-              printf(" Midsummer Day");
X           break;
X       case AFTERLITHE:
X           break;
X
X--- 68,73 -----
X       case THRIMIDGE:
X           break;
X       case FORELITHE:
X           break;
X       case LITHE:
X           printf(" Midsummer Day");
X***************
X*** 67,72
X           if (day == 31) 
X               printf(" Midsummer Day");
X           break;
X       case AFTERLITHE:
X           break;
X       case WEDMATH:
X
X--- 69,77 -----
X           break;
X       case FORELITHE:
X           break;
X+      case LITHE:
X+          printf(" Midsummer Day");
X+          break;
X       case AFTERLITHE:
X           break;
X       case WEDMATH:
X***************
X*** 78,85
X       case BLOTMATH:
X           break;
X       case FOREYULE:
X!          if ((day >= 31) AND (day <= 34))
X!              printf(" Yule");
X           break;
X       }
X  }
X
X--- 83,91 -----
X       case BLOTMATH:
X           break;
X       case FOREYULE:
X!          break;
X!      case YULE:
X!          printf(" Yule");
X           break;
X       }
X  }
X*** oweather.c	Wed Feb  1 15:50:51 1989
X--- weather.c	Wed Apr 12 10:18:18 1989
X***************
X*** 8,13
X   *  This program or its derivatives may not be sold for profit without    *
X   *  permission of the author.                                             *
X   *                                                                        *
X   *  Original UNIX Version: Brett Slocum UUCP: ...uunet!hi-csc!slocum      *
X   *                                      ARPA: hi-csc!slocum@uunet.uu.net  *
X   *                                                                        *
X
X--- 8,22 -----
X   *  This program or its derivatives may not be sold for profit without    *
X   *  permission of the author.                                             *
X   *                                                                        *
X+  *  To run:   <region name> [<start year> <end year>]                     *
X+  *                                                                        *
X+  *      If the start and end years are not supplied, the program          *
X+  *  produces one year of weather.                                         *
X+  *                                                                        *
X+  *  Example:  england 1066 1075                                           *
X+  *            will produce 10 years of weather starting in 1066 and       *
X+  *            in 1075.                                                    *
X+  *                                                                        *
X   *  Original UNIX Version: Brett Slocum UUCP: ...uunet!hi-csc!slocum      *
X   *                                      ARPA: hi-csc!slocum@uunet.uu.net  *
X   *                                                                        *
X***************
X*** 11,16
X   *  Original UNIX Version: Brett Slocum UUCP: ...uunet!hi-csc!slocum      *
X   *                                      ARPA: hi-csc!slocum@uunet.uu.net  *
X   *                                                                        *
X   **************************************************************************/
X  
X  #include "weather.h"
X
X--- 20,35 -----
X   *  Original UNIX Version: Brett Slocum UUCP: ...uunet!hi-csc!slocum      *
X   *                                      ARPA: hi-csc!slocum@uunet.uu.net  *
X   *                                                                        *
X+  *  Bugs reported and modifications suggested by:                         *
X+  *      "251 degrees in a Minnesota winter" bug:                          *
X+  *          Michael Kent <...!{uflorida, uunet}!aleytys!mike>             *
X+  *          Mark E Hunter <meh@wucs1.wustl.edu>                           *
X+  *          Dan Farmer <ajm@mentor.cc.purdue.edu>                         *
X+  *          Kevin W. Thomas <uokmax!kwthomas@uokmax.ecn.uoknor.edu>       *
X+  *                                                                        *
X+  *      VMS and Shire calendar modifications:                             *
X+  *          Karsten Spang, NBI, Copenhagen <SPANG@nbivax.nbi.dk>          *
X+  *                                                                        *
X   **************************************************************************/
X  
X  #include "weather.h"
X***************
X*** 62,69
X  WEATHER_T  Weather;              /* today's weather */
X  OVERCAST_T Sky;                  /* today's sky conditions */
X  
X! UBYTE Temperature = 0,           /* today's actual temperature */
X!       Duration = 0;              /* today's precipitation duration */
X  
X  BOOL Duration_Hours = TRUE,      /* flag that indicates whether precip lasted */
X                                   /* hours (TRUE) or minutes (FALSE) */
X
X--- 81,88 -----
X  WEATHER_T  Weather;              /* today's weather */
X  OVERCAST_T Sky;                  /* today's sky conditions */
X  
X! short Temperature = 0;           /* today's actual temperature */
X! UBYTE Duration = 0;              /* today's precipitation duration */
X  
X  BOOL Duration_Hours = TRUE,      /* flag that indicates whether precip lasted */
X                                   /* hours (TRUE) or minutes (FALSE) */
X***************
X*** 424,432
X       int cum_temp;               /* cumulative temp used for calculating average temp */
X       unsigned int sunshine = 0;  /* number of days of sunshine */
X       MONTH_T month;              /* month counter */
X!      UBYTE day,                  /* day counter */
X!            year,                 /* year counter */
X!            n_years = 1;          /* number of years */
X  
X       srandom((int)time(0));
X       if (argc > 1)
X
X--- 443,452 -----
X       int cum_temp;               /* cumulative temp used for calculating average temp */
X       unsigned int sunshine = 0;  /* number of days of sunshine */
X       MONTH_T month;              /* month counter */
X!      UBYTE day;                  /* day counter */
X!      int year,                   /* year counter */
X!          start_year = 1,         /* starting year */
X!          end_year = 1;           /* ending year */
X  
X       srandom((int)time(0));
X       if ((argc > 1) AND (argc <= 3)) 
X***************
X*** 429,436
X             n_years = 1;          /* number of years */
X  
X       srandom((int)time(0));
X!      if (argc > 1)
X!          n_years = atoi(argv[1]);
X       init_winter();
X       for (year = 1; year <= n_years; year++)
X       {
X
X--- 449,465 -----
X           end_year = 1;           /* ending year */
X  
X       srandom((int)time(0));
X!      if ((argc > 1) AND (argc <= 3)) 
X!      {
X!          start_year = atoi(argv[1]);
X!          end_year = atoi(argv[2]);
X!      }
X!      else
X!      if (argc != 1)
X!      {
X!          printf("Usage: %s [<start year> <end year>]\n", argv[0]);
X!          exit(0);
X!      }
X       init_winter();
X       for (year = start_year; year <= end_year; year++)
X       {
X***************
X*** 432,438
X       if (argc > 1)
X           n_years = atoi(argv[1]);
X       init_winter();
X!      for (year = 1; year <= n_years; year++)
X       {
X           Rainfall = 0.0;
X           Snowfall = 0.0;
X
X--- 461,467 -----
X           exit(0);
X       }
X       init_winter();
X!      for (year = start_year; year <= end_year; year++)
X       {
X           Rainfall = 0.0;
X           Snowfall = 0.0;
X***************
X*** 439,445
X           sunshine = 0;
X           init_stat();
X           printf("%64c%6s\n", ' ',"Snow");
X!          printf("Year %3d%11s%11s%14s%10s%10s%7s%7s\n", year, "Weather", "Sky", "Temperature", "Precip", "Wind", "Depth", "Notes");
X           for (month = FIRST_MONTH; month <= LAST_MONTH; month++)
X           {
X               cum_temp = 0;
X
X--- 468,474 -----
X           sunshine = 0;
X           init_stat();
X           printf("%64c%6s\n", ' ',"Snow");
X!          printf("Year %4d%10s%11s%14s%10s%10s%7s%7s\n", year, "Weather", "Sky", "Temperature", "Precip", "Wind", "Depth", "Notes");
X           for (month = FIRST_MONTH; month <= LAST_MONTH; month++)
X           {
X               cum_temp = 0;
X*** oweather.h	Fri Dec 16 14:00:23 1988
X--- weather.h	Wed Apr 12 09:21:55 1989
X***************
X*** 3,8
X  #define random lrand48
X  #endif
X  
X  #define DIE(n) ((int)(random() % (unsigned)n)+1)
X  #define MIN(a,b) ((a<b) ? a : b)
X  #define MAX(a,b) ((a>b) ? a : b)
X
X--- 3,13 -----
X  #define random lrand48
X  #endif
X  
X+ #ifdef VMS
X+ #define srandom srand
X+ #define random rand
X+ #endif
X+ 
X  #define DIE(n) ((int)(random() % (unsigned)n)+1)
X  #define MIN(a,b) ((a<b) ? a : b)
X  #define MAX(a,b) ((a>b) ? a : b)
________This_Is_The_END________
if test `wc -l < patch1` -ne 366; then
	echo 'shar: patch1 was damaged during transit (should have been 366 bytes)'
fi
fi		; : end of overwriting check
exit 0