home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume06 / rndwethr.p1 < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  14.4 KB

  1. From decwrl!ucbvax!pasteur!ames!lll-winken!uunet!allbery Sun Apr 23 15:40:17 PDT 1989
  2. Article 858 of comp.sources.misc:
  3. Path: decwrl!ucbvax!pasteur!ames!lll-winken!uunet!allbery
  4. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5. Newsgroups: comp.sources.misc
  6. Subject: v06i089: Random Weather Generator - patch1
  7. Message-ID: <53140@uunet.UU.NET>
  8. Date: 23 Apr 89 19:23:05 GMT
  9. Sender: allbery@uunet.UU.NET
  10. Reply-To: slocum@hi-csc.UUCP
  11. Lines: 433
  12. Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  13.  
  14. Posting-number: Volume 6, Issue 89
  15. Submitted-by: slocum@hi-csc.UUCP
  16. Archive-name: rndweather.p1
  17.  
  18. This is the first patch to the recently posted Random Weather Generator.
  19.  
  20. Bug fixed:
  21.      o  Overflow on negative temperature - Temperature variable
  22.         changed to short.
  23.  
  24. Enhancements:
  25.      o  VMS port modifications.
  26.      o  The Middle Earth calendar has Lithe and Yule in separate
  27.         months, instead of being printed as part of Forelithe
  28.         and Foreyule.
  29.      o  The desired starting and ending years can be specified
  30.         on the command line.  The command 'england 1066 1075' 
  31.         will print weather for the ten years from 1066 through 1075.
  32.  
  33. My thanks to the following people who reported the bug and suggested
  34. the modifications:
  35.  
  36.     "251 degrees in a Minnesota winter" bug:
  37.         Michael Kent <...!{uflorida, uunet}!aleytys!mike>
  38.         Mark E Hunter <meh@wucs1.wustl.edu>
  39.         Dan Farmer <ajm@mentor.cc.purdue.edu>
  40.         Kevin W. Thomas <uokmax!kwthomas@uokmax.ecn.uoknor.edu>
  41.  
  42.     VMS and Shire calendar modifications:
  43.         Karsten Spang, NBI, Copenhagen <SPANG@nbivax.nbi.dk>
  44.  
  45. Brett Slocum   UUCP: ...uunet!hi-csc!slocum
  46.                Arpa: hi-csc!slocum@uunet.uu.net
  47. "My name is Inigo Montoya. You killed my father. Prepare to die."
  48.  
  49. #--------------------------------CUT HERE-------------------------------------
  50. #! /bin/sh
  51. #
  52. # This is a shell archive.  Save this into a file, edit it
  53. # and delete all lines above this comment.  Then give this
  54. # file to sh by executing the command "sh file".  The files
  55. # will be extracted into the current directory owned by
  56. # you with default permissions.
  57. #
  58. # The files contained herein are:
  59. #
  60. # -rwxrwx---  1 atchan         21 Apr 12 10:40 patchlevel.h
  61. # -rwxrwx---  1 195         11391 Apr 12 10:34 patch1
  62. #
  63. echo 'x - patchlevel.h'
  64. if test -f patchlevel.h; then echo 'shar: not overwriting patchlevel.h'; else
  65. sed 's/^X//' << '________This_Is_The_END________' > patchlevel.h
  66. X#define PATCHLEVEL 1
  67. ________This_Is_The_END________
  68. if test `wc -l < patchlevel.h` -ne 1; then
  69.     echo 'shar: patchlevel.h was damaged during transit (should have been 1 bytes)'
  70. fi
  71. fi        ; : end of overwriting check
  72. echo 'x - patch1'
  73. if test -f patch1; then echo 'shar: not overwriting patch1'; else
  74. sed 's/^X//' << '________This_Is_The_END________' > patch1
  75. X*** oMakefile    Wed Mar 22 10:29:57 1989
  76. X--- Makefile    Wed Apr 12 09:21:49 1989
  77. X***************
  78. X*** 30,35
  79. X  # GULF         - useful for Gulf States, Mediterranean, etc.
  80. X  # N_PACIFIC    - useful for Japan, Korea, Southern Alaskan coast, etc.
  81. X  
  82. X  england: weather.c weather.h gregorian.h mid_atlantic.h
  83. X      cc -DGREGORIAN -DMID_ATLANTIC -o england -g weather.c
  84. X  
  85. X
  86. X--- 30,40 -----
  87. X  # GULF         - useful for Gulf States, Mediterranean, etc.
  88. X  # N_PACIFIC    - useful for Japan, Korea, Southern Alaskan coast, etc.
  89. X  
  90. X+ # uncomment the appropriate line for System V or VMS
  91. X+ #CFLAGS = -DVMS
  92. X+ #CFLAGS = -DSYSV
  93. X+ CFLAGS = 
  94. X+ 
  95. X  england: weather.c weather.h gregorian.h mid_atlantic.h
  96. X      cc -DGREGORIAN -DMID_ATLANTIC -o england -g weather.c
  97. X*** omiddle_earth.h    Wed Feb  1 11:27:17 1989
  98. X--- middle_earth.h    Wed Apr 12 09:38:03 1989
  99. X***************
  100. X*** 18,29
  101. X  #define ASTRON      3
  102. X  #define THRIMIDGE   4
  103. X  #define FORELITHE   5
  104. X! #define AFTERLITHE  6
  105. X! #define WEDMATH     7
  106. X! #define HALIMATH    8
  107. X! #define WINTERFILTH 9
  108. X! #define BLOTMATH    10
  109. X! #define FOREYULE    11
  110. X  
  111. X  #define FIRST_MONTH AFTERYULE
  112. X  #define LAST_MONTH  FOREYULE
  113. X
  114. X--- 18,31 -----
  115. X  #define ASTRON      3
  116. X  #define THRIMIDGE   4
  117. X  #define FORELITHE   5
  118. X! #define LITHE       6
  119. X! #define AFTERLITHE  7
  120. X! #define WEDMATH     8
  121. X! #define HALIMATH    9
  122. X! #define WINTERFILTH 10
  123. X! #define BLOTMATH    11
  124. X! #define FOREYULE    12
  125. X! #define YULE        13
  126. X  
  127. X  #define FIRST_MONTH AFTERYULE
  128. X  #define LAST_MONTH  YULE
  129. X***************
  130. X*** 26,32
  131. X  #define FOREYULE    11
  132. X  
  133. X  #define FIRST_MONTH AFTERYULE
  134. X! #define LAST_MONTH  FOREYULE
  135. X  
  136. X  #define N_MONTHS (LAST_MONTH - FIRST_MONTH) + 1
  137. X  
  138. X
  139. X--- 28,34 -----
  140. X  #define YULE        13
  141. X  
  142. X  #define FIRST_MONTH AFTERYULE
  143. X! #define LAST_MONTH  YULE
  144. X  
  145. X  #define N_MONTHS (LAST_MONTH - FIRST_MONTH) + 1
  146. X  
  147. X***************
  148. X*** 37,42
  149. X      "Astron",
  150. X      "Thrimidge",
  151. X      "Forelithe",
  152. X      "Afterlithe",
  153. X      "Wedmath",
  154. X      "Halimath",
  155. X
  156. X--- 39,45 -----
  157. X      "Astron",
  158. X      "Thrimidge",
  159. X      "Forelithe",
  160. X+     "Lithe",
  161. X      "Afterlithe",
  162. X      "Wedmath",
  163. X      "Halimath",
  164. X***************
  165. X*** 43,48
  166. X      "Winterfilth",
  167. X      "Blotmath",
  168. X      "Foreyule",
  169. X  };
  170. X  
  171. X  UBYTE Day_Table[N_MONTHS] = {30, 30, 30, 30, 30, 31, 30, 30, 30, 30, 30, 34};
  172. X
  173. X--- 46,52 -----
  174. X      "Winterfilth",
  175. X      "Blotmath",
  176. X      "Foreyule",
  177. X+     "Yule",
  178. X  };
  179. X  
  180. X  UBYTE Day_Table[N_MONTHS] = {30, 30, 30, 30, 30, 30, 1, 30, 30, 30, 30, 30, 30, 4};
  181. X***************
  182. X*** 45,51
  183. X      "Foreyule",
  184. X  };
  185. X  
  186. X! UBYTE Day_Table[N_MONTHS] = {30, 30, 30, 30, 30, 31, 30, 30, 30, 30, 30, 34};
  187. X  
  188. X  void
  189. X  print_holiday(day, month)
  190. X
  191. X--- 49,55 -----
  192. X      "Yule",
  193. X  };
  194. X  
  195. X! UBYTE Day_Table[N_MONTHS] = {30, 30, 30, 30, 30, 30, 1, 30, 30, 30, 30, 30, 30, 4};
  196. X  
  197. X  void
  198. X  print_holiday(day, month)
  199. X***************
  200. X*** 64,71
  201. X       case THRIMIDGE:
  202. X           break;
  203. X       case FORELITHE:
  204. X-          if (day == 31) 
  205. X-              printf(" Midsummer Day");
  206. X           break;
  207. X       case AFTERLITHE:
  208. X           break;
  209. X
  210. X--- 68,73 -----
  211. X       case THRIMIDGE:
  212. X           break;
  213. X       case FORELITHE:
  214. X           break;
  215. X       case LITHE:
  216. X           printf(" Midsummer Day");
  217. X***************
  218. X*** 67,72
  219. X           if (day == 31) 
  220. X               printf(" Midsummer Day");
  221. X           break;
  222. X       case AFTERLITHE:
  223. X           break;
  224. X       case WEDMATH:
  225. X
  226. X--- 69,77 -----
  227. X           break;
  228. X       case FORELITHE:
  229. X           break;
  230. X+      case LITHE:
  231. X+          printf(" Midsummer Day");
  232. X+          break;
  233. X       case AFTERLITHE:
  234. X           break;
  235. X       case WEDMATH:
  236. X***************
  237. X*** 78,85
  238. X       case BLOTMATH:
  239. X           break;
  240. X       case FOREYULE:
  241. X!          if ((day >= 31) AND (day <= 34))
  242. X!              printf(" Yule");
  243. X           break;
  244. X       }
  245. X  }
  246. X
  247. X--- 83,91 -----
  248. X       case BLOTMATH:
  249. X           break;
  250. X       case FOREYULE:
  251. X!          break;
  252. X!      case YULE:
  253. X!          printf(" Yule");
  254. X           break;
  255. X       }
  256. X  }
  257. X*** oweather.c    Wed Feb  1 15:50:51 1989
  258. X--- weather.c    Wed Apr 12 10:18:18 1989
  259. X***************
  260. X*** 8,13
  261. X   *  This program or its derivatives may not be sold for profit without    *
  262. X   *  permission of the author.                                             *
  263. X   *                                                                        *
  264. X   *  Original UNIX Version: Brett Slocum UUCP: ...uunet!hi-csc!slocum      *
  265. X   *                                      ARPA: hi-csc!slocum@uunet.uu.net  *
  266. X   *                                                                        *
  267. X
  268. X--- 8,22 -----
  269. X   *  This program or its derivatives may not be sold for profit without    *
  270. X   *  permission of the author.                                             *
  271. X   *                                                                        *
  272. X+  *  To run:   <region name> [<start year> <end year>]                     *
  273. X+  *                                                                        *
  274. X+  *      If the start and end years are not supplied, the program          *
  275. X+  *  produces one year of weather.                                         *
  276. X+  *                                                                        *
  277. X+  *  Example:  england 1066 1075                                           *
  278. X+  *            will produce 10 years of weather starting in 1066 and       *
  279. X+  *            in 1075.                                                    *
  280. X+  *                                                                        *
  281. X   *  Original UNIX Version: Brett Slocum UUCP: ...uunet!hi-csc!slocum      *
  282. X   *                                      ARPA: hi-csc!slocum@uunet.uu.net  *
  283. X   *                                                                        *
  284. X***************
  285. X*** 11,16
  286. X   *  Original UNIX Version: Brett Slocum UUCP: ...uunet!hi-csc!slocum      *
  287. X   *                                      ARPA: hi-csc!slocum@uunet.uu.net  *
  288. X   *                                                                        *
  289. X   **************************************************************************/
  290. X  
  291. X  #include "weather.h"
  292. X
  293. X--- 20,35 -----
  294. X   *  Original UNIX Version: Brett Slocum UUCP: ...uunet!hi-csc!slocum      *
  295. X   *                                      ARPA: hi-csc!slocum@uunet.uu.net  *
  296. X   *                                                                        *
  297. X+  *  Bugs reported and modifications suggested by:                         *
  298. X+  *      "251 degrees in a Minnesota winter" bug:                          *
  299. X+  *          Michael Kent <...!{uflorida, uunet}!aleytys!mike>             *
  300. X+  *          Mark E Hunter <meh@wucs1.wustl.edu>                           *
  301. X+  *          Dan Farmer <ajm@mentor.cc.purdue.edu>                         *
  302. X+  *          Kevin W. Thomas <uokmax!kwthomas@uokmax.ecn.uoknor.edu>       *
  303. X+  *                                                                        *
  304. X+  *      VMS and Shire calendar modifications:                             *
  305. X+  *          Karsten Spang, NBI, Copenhagen <SPANG@nbivax.nbi.dk>          *
  306. X+  *                                                                        *
  307. X   **************************************************************************/
  308. X  
  309. X  #include "weather.h"
  310. X***************
  311. X*** 62,69
  312. X  WEATHER_T  Weather;              /* today's weather */
  313. X  OVERCAST_T Sky;                  /* today's sky conditions */
  314. X  
  315. X! UBYTE Temperature = 0,           /* today's actual temperature */
  316. X!       Duration = 0;              /* today's precipitation duration */
  317. X  
  318. X  BOOL Duration_Hours = TRUE,      /* flag that indicates whether precip lasted */
  319. X                                   /* hours (TRUE) or minutes (FALSE) */
  320. X
  321. X--- 81,88 -----
  322. X  WEATHER_T  Weather;              /* today's weather */
  323. X  OVERCAST_T Sky;                  /* today's sky conditions */
  324. X  
  325. X! short Temperature = 0;           /* today's actual temperature */
  326. X! UBYTE Duration = 0;              /* today's precipitation duration */
  327. X  
  328. X  BOOL Duration_Hours = TRUE,      /* flag that indicates whether precip lasted */
  329. X                                   /* hours (TRUE) or minutes (FALSE) */
  330. X***************
  331. X*** 424,432
  332. X       int cum_temp;               /* cumulative temp used for calculating average temp */
  333. X       unsigned int sunshine = 0;  /* number of days of sunshine */
  334. X       MONTH_T month;              /* month counter */
  335. X!      UBYTE day,                  /* day counter */
  336. X!            year,                 /* year counter */
  337. X!            n_years = 1;          /* number of years */
  338. X  
  339. X       srandom((int)time(0));
  340. X       if (argc > 1)
  341. X
  342. X--- 443,452 -----
  343. X       int cum_temp;               /* cumulative temp used for calculating average temp */
  344. X       unsigned int sunshine = 0;  /* number of days of sunshine */
  345. X       MONTH_T month;              /* month counter */
  346. X!      UBYTE day;                  /* day counter */
  347. X!      int year,                   /* year counter */
  348. X!          start_year = 1,         /* starting year */
  349. X!          end_year = 1;           /* ending year */
  350. X  
  351. X       srandom((int)time(0));
  352. X       if ((argc > 1) AND (argc <= 3)) 
  353. X***************
  354. X*** 429,436
  355. X             n_years = 1;          /* number of years */
  356. X  
  357. X       srandom((int)time(0));
  358. X!      if (argc > 1)
  359. X!          n_years = atoi(argv[1]);
  360. X       init_winter();
  361. X       for (year = 1; year <= n_years; year++)
  362. X       {
  363. X
  364. X--- 449,465 -----
  365. X           end_year = 1;           /* ending year */
  366. X  
  367. X       srandom((int)time(0));
  368. X!      if ((argc > 1) AND (argc <= 3)) 
  369. X!      {
  370. X!          start_year = atoi(argv[1]);
  371. X!          end_year = atoi(argv[2]);
  372. X!      }
  373. X!      else
  374. X!      if (argc != 1)
  375. X!      {
  376. X!          printf("Usage: %s [<start year> <end year>]\n", argv[0]);
  377. X!          exit(0);
  378. X!      }
  379. X       init_winter();
  380. X       for (year = start_year; year <= end_year; year++)
  381. X       {
  382. X***************
  383. X*** 432,438
  384. X       if (argc > 1)
  385. X           n_years = atoi(argv[1]);
  386. X       init_winter();
  387. X!      for (year = 1; year <= n_years; year++)
  388. X       {
  389. X           Rainfall = 0.0;
  390. X           Snowfall = 0.0;
  391. X
  392. X--- 461,467 -----
  393. X           exit(0);
  394. X       }
  395. X       init_winter();
  396. X!      for (year = start_year; year <= end_year; year++)
  397. X       {
  398. X           Rainfall = 0.0;
  399. X           Snowfall = 0.0;
  400. X***************
  401. X*** 439,445
  402. X           sunshine = 0;
  403. X           init_stat();
  404. X           printf("%64c%6s\n", ' ',"Snow");
  405. X!          printf("Year %3d%11s%11s%14s%10s%10s%7s%7s\n", year, "Weather", "Sky", "Temperature", "Precip", "Wind", "Depth", "Notes");
  406. X           for (month = FIRST_MONTH; month <= LAST_MONTH; month++)
  407. X           {
  408. X               cum_temp = 0;
  409. X
  410. X--- 468,474 -----
  411. X           sunshine = 0;
  412. X           init_stat();
  413. X           printf("%64c%6s\n", ' ',"Snow");
  414. X!          printf("Year %4d%10s%11s%14s%10s%10s%7s%7s\n", year, "Weather", "Sky", "Temperature", "Precip", "Wind", "Depth", "Notes");
  415. X           for (month = FIRST_MONTH; month <= LAST_MONTH; month++)
  416. X           {
  417. X               cum_temp = 0;
  418. X*** oweather.h    Fri Dec 16 14:00:23 1988
  419. X--- weather.h    Wed Apr 12 09:21:55 1989
  420. X***************
  421. X*** 3,8
  422. X  #define random lrand48
  423. X  #endif
  424. X  
  425. X  #define DIE(n) ((int)(random() % (unsigned)n)+1)
  426. X  #define MIN(a,b) ((a<b) ? a : b)
  427. X  #define MAX(a,b) ((a>b) ? a : b)
  428. X
  429. X--- 3,13 -----
  430. X  #define random lrand48
  431. X  #endif
  432. X  
  433. X+ #ifdef VMS
  434. X+ #define srandom srand
  435. X+ #define random rand
  436. X+ #endif
  437. X+ 
  438. X  #define DIE(n) ((int)(random() % (unsigned)n)+1)
  439. X  #define MIN(a,b) ((a<b) ? a : b)
  440. X  #define MAX(a,b) ((a>b) ? a : b)
  441. ________This_Is_The_END________
  442. if test `wc -l < patch1` -ne 366; then
  443.     echo 'shar: patch1 was damaged during transit (should have been 366 bytes)'
  444. fi
  445. fi        ; : end of overwriting check
  446. exit 0
  447.  
  448.  
  449.