home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume36 / hodge-c / part03 < prev    next >
Encoding:
Text File  |  1993-03-23  |  60.1 KB  |  2,476 lines

  1. Newsgroups: comp.sources.misc
  2. From: heitkoet@lusty.informatik.uni-dortmund.de (Joerg Heitkoetter)
  3. Subject: v36i037:  hodge-c - An implementation of Gerhard & Schuster's hodge-podge machine, Part03/33
  4. Message-ID: <1993Mar23.060847.2794@sparky.imd.sterling.com>
  5. X-Md4-Signature: ba039a09ecf0594ac038824ff414a303
  6. Date: Tue, 23 Mar 1993 06:08:47 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: heitkoet@lusty.informatik.uni-dortmund.de (Joerg Heitkoetter)
  10. Posting-number: Volume 36, Issue 37
  11. Archive-name: hodge-c/part03
  12. Environment: ImageMagick, KHOROS
  13.  
  14. #!/bin/sh
  15. # this is Part.03 (part 3 of a multipart archive)
  16. # do not concatenate these parts, unpack them in order with /bin/sh
  17. # file hodge-c-0.98j/getopt.c continued
  18. #
  19. if test ! -r _shar_seq_.tmp; then
  20.     echo 'Please unpack part 1 first!'
  21.     exit 1
  22. fi
  23. (read Scheck
  24.  if test "$Scheck" != 3; then
  25.     echo Please unpack part "$Scheck" next!
  26.     exit 1
  27.  else
  28.     exit 0
  29.  fi
  30. ) < _shar_seq_.tmp || exit 1
  31. if test ! -f _shar_wnt_.tmp; then
  32.     echo 'x - still skipping hodge-c-0.98j/getopt.c'
  33. else
  34. echo 'x - continuing file hodge-c-0.98j/getopt.c'
  35. sed 's/^X//' << 'SHAR_EOF' >> 'hodge-c-0.98j/getopt.c' &&
  36. X     Start processing options with ARGV-element 1 (since ARGV-element 0
  37. X     is the program name); the sequence of previously skipped
  38. X     non-option ARGV-elements is empty.  */
  39. X
  40. X    if (optind == 0) {
  41. X    first_nonopt = last_nonopt = optind = 1;
  42. X
  43. X    nextchar = NULL;
  44. X
  45. X       /* Determine how to handle the ordering of options and nonoptions.  */
  46. X
  47. X    if (optstring[0] == '-') {
  48. X        ordering = RETURN_IN_ORDER;
  49. X        ++optstring;
  50. X    } else if (optstring[0] == '+') {
  51. X        ordering = REQUIRE_ORDER;
  52. X        ++optstring;
  53. X    } else if (getenv ("POSIXLY_CORRECT") != NULL)
  54. X        ordering = REQUIRE_ORDER;
  55. X    else
  56. X        ordering = PERMUTE;
  57. X    }
  58. X    if (nextchar == NULL || *nextchar == '\0') {
  59. X    if (ordering == PERMUTE) {
  60. X       /* If we have just processed some options following some non-options,
  61. X         exchange them so that the options come first.  */
  62. X
  63. X        if (first_nonopt != last_nonopt && last_nonopt != optind)
  64. X        exchange ((char **) argv);
  65. X        else if (last_nonopt != optind)
  66. X        first_nonopt = optind;
  67. X
  68. X       /* Now skip any additional non-options
  69. X         and extend the range of non-options previously skipped.  */
  70. X
  71. X        while (optind < argc
  72. X            && (argv[optind][0] != '-' || argv[optind][1] == '\0')
  73. X
  74. #ifdef GETOPT_COMPAT
  75. X            && (longopts == NULL
  76. X            || argv[optind][0] != '+' || argv[optind][1] == '\0')
  77. #endif /* GETOPT_COMPAT */
  78. X
  79. X        )
  80. X        optind++;
  81. X        last_nonopt = optind;
  82. X    }
  83. X       /* Special ARGV-element `--' means premature end of options.
  84. X     Skip it like a null option,
  85. X     then exchange with previous non-options as if it were an option,
  86. X     then skip everything else like a non-option.  */
  87. X
  88. X    if (optind != argc && !strcmp (argv[optind], "--")) {
  89. X        optind++;
  90. X
  91. X        if (first_nonopt != last_nonopt && last_nonopt != optind)
  92. X        exchange ((char **) argv);
  93. X        else if (first_nonopt == last_nonopt)
  94. X        first_nonopt = optind;
  95. X        last_nonopt = argc;
  96. X
  97. X        optind = argc;
  98. X    }
  99. X       /* If we have done all the ARGV-elements, stop the scan
  100. X     and back over any non-options that we skipped and permuted.  */
  101. X
  102. X    if (optind == argc) {
  103. X       /* Set the next-arg-index to point at the non-options
  104. X         that we previously skipped, so the caller will digest them.  */
  105. X        if (first_nonopt != last_nonopt)
  106. X        optind = first_nonopt;
  107. X        return EOF;
  108. X    }
  109. X       /* If we have come to a non-option and did not permute it,
  110. X     either stop the scan or describe it to the caller and pass it by.  */
  111. X
  112. X    if ((argv[optind][0] != '-' || argv[optind][1] == '\0')
  113. X
  114. #ifdef GETOPT_COMPAT
  115. X        && (longopts == NULL
  116. X            || argv[optind][0] != '+' || argv[optind][1] == '\0')
  117. #endif /* GETOPT_COMPAT */
  118. X
  119. X        ) {
  120. X        if (ordering == REQUIRE_ORDER)
  121. X        return EOF;
  122. X        optarg = argv[optind++];
  123. X        return 1;
  124. X    }
  125. X       /* We have found another option-ARGV-element.
  126. X     Start decoding its characters.  */
  127. X
  128. X    nextchar = (argv[optind] + 1
  129. X            + (longopts != NULL && argv[optind][1] == '-'));
  130. X    }
  131. X    if (longopts != NULL
  132. X        && ((argv[optind][0] == '-'
  133. X         && (argv[optind][1] == '-' || long_only))
  134. X
  135. #ifdef GETOPT_COMPAT
  136. X        || argv[optind][0] == '+'
  137. #endif /* GETOPT_COMPAT */
  138. X
  139. X        )) {
  140. X    const struct option *p;
  141. X    char *s = nextchar;
  142. X    int exact = 0;
  143. X    int ambig = 0;
  144. X    const struct option *pfound = NULL;
  145. X    int indfound = 0;
  146. X
  147. X    while (*s && *s != '=')
  148. X        s++;
  149. X
  150. X       /* Test all options for either exact match or abbreviated matches.  */
  151. X    for (p = longopts, option_index = 0; p -> name;
  152. X        p++, option_index++)
  153. X        if (!strncmp (p -> name, nextchar, s - nextchar)) {
  154. X        if (s - nextchar == strlen (p -> name)) {
  155. X           /* Exact match found.  */
  156. X            pfound = p;
  157. X            indfound = option_index;
  158. X            exact = 1;
  159. X            break;
  160. X        } else if (pfound == NULL) {
  161. X           /* First nonexact match found.  */
  162. X            pfound = p;
  163. X            indfound = option_index;
  164. X        } else
  165. X           /* Second nonexact match found.  */
  166. X            ambig = 1;
  167. X        }
  168. X    if (ambig && !exact) {
  169. X        if (opterr)
  170. X        fprintf (stderr, "%s: option `%s' is ambiguous\n",
  171. X             argv[0], argv[optind]);
  172. X        nextchar += strlen (nextchar);
  173. X        optind++;
  174. X        return '?';
  175. X    }
  176. X    if (pfound != NULL) {
  177. X        option_index = indfound;
  178. X        optind++;
  179. X        if (*s) {
  180. X           /* Don't test has_arg with >, because some C compilers don't
  181. X         allow it to be used on enums. */
  182. X        if (pfound -> has_arg)
  183. X            optarg = s + 1;
  184. X        else {
  185. X            if (opterr) {
  186. X            if (argv[optind - 1][1] == '-')
  187. X               /* --option */
  188. X                fprintf (stderr,
  189. X                     "%s: option `--%s' doesn't allow an argument\n",
  190. X                     argv[0], pfound -> name);
  191. X            else
  192. X               /* +option or -option */
  193. X                fprintf (stderr,
  194. X                     "%s: option `%c%s' doesn't allow an argument\n",
  195. X                     argv[0], argv[optind - 1][0], pfound -> name);
  196. X            }
  197. X            nextchar += strlen (nextchar);
  198. X            return '?';
  199. X        }
  200. X        } else if (pfound -> has_arg == 1) {
  201. X        if (optind < argc)
  202. X            optarg = argv[optind++];
  203. X        else {
  204. X            if (opterr)
  205. X            fprintf (stderr, "%s: option `%s' requires an argument\n",
  206. X                 argv[0], argv[optind - 1]);
  207. X            nextchar += strlen (nextchar);
  208. X            return '?';
  209. X        }
  210. X        }
  211. X        nextchar += strlen (nextchar);
  212. X        if (longind != NULL)
  213. X        *longind = option_index;
  214. X        if (pfound -> flag) {
  215. X        *(pfound -> flag) = pfound -> val;
  216. X        return 0;
  217. X        }
  218. X        return pfound -> val;
  219. X    }
  220. X       /* Can't find it as a long option.  If this is not getopt_long_only,
  221. X     or the option starts with '--' or is not a valid short
  222. X     option, then it's an error.
  223. X     Otherwise interpret it as a short option. */
  224. X    if (!long_only || argv[optind][1] == '-'
  225. X
  226. #ifdef GETOPT_COMPAT
  227. X        || argv[optind][0] == '+'
  228. #endif /* GETOPT_COMPAT */
  229. X
  230. X        || my_index (optstring, *nextchar) == NULL) {
  231. X        if (opterr) {
  232. X        if (argv[optind][1] == '-')
  233. X           /* --option */
  234. X            fprintf (stderr, "%s: unrecognized option `--%s'\n",
  235. X                 argv[0], nextchar);
  236. X        else
  237. X           /* +option or -option */
  238. X            fprintf (stderr, "%s: unrecognized option `%c%s'\n",
  239. X                 argv[0], argv[optind][0], nextchar);
  240. X        }
  241. X        nextchar += strlen (nextchar);
  242. X        optind++;
  243. X        return '?';
  244. X    }
  245. X    }
  246. X   /* Look at and handle the next option-character.  */
  247. X
  248. X    {
  249. X    char c = *nextchar++;
  250. X    char *temp = my_index (optstring, c);
  251. X
  252. X       /* Increment `optind' when we start to process its last character.  */
  253. X    if (*nextchar == '\0')
  254. X        optind++;
  255. X
  256. X    if (temp == NULL || c == ':') {
  257. X        if (opterr) {
  258. X        if (c < 040 || c >= 0177)
  259. X            fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
  260. X                 argv[0], c);
  261. X        else
  262. X            fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c);
  263. X        }
  264. X        return '?';
  265. X    }
  266. X    if (temp[1] == ':') {
  267. X        if (temp[2] == ':') {
  268. X           /* This is an option that accepts an argument optionally.  */
  269. X        if (*nextchar != '\0') {
  270. X            optarg = nextchar;
  271. X            optind++;
  272. X        } else
  273. X            optarg = 0;
  274. X        nextchar = NULL;
  275. X        } else {
  276. X           /* This is an option that requires an argument.  */
  277. X        if (*nextchar != 0) {
  278. X            optarg = nextchar;
  279. X           /* If we end this ARGV-element by taking the rest as an arg,
  280. X           we must advance to the next element now.  */
  281. X            optind++;
  282. X        } else if (optind == argc) {
  283. X            if (opterr)
  284. X            fprintf (stderr, "%s: option `-%c' requires an argument\n",
  285. X                 argv[0], c);
  286. X            c = '?';
  287. X        } else
  288. X           /* We already incremented `optind' once;
  289. X         increment it again when taking next ARGV-elt as argument.  */
  290. X            optarg = argv[optind++];
  291. X        nextchar = NULL;
  292. X        }
  293. X    }
  294. X    return c;
  295. X    }
  296. }
  297. X
  298. int
  299. getopt (argc, argv, optstring)
  300. X    int argc;
  301. X    char *const *argv;
  302. X    const char *optstring;
  303. {
  304. X    return _getopt_internal (argc, argv, optstring,
  305. X                 (const struct option *) 0,
  306. X                 (int *) 0,
  307. X                 0);
  308. }
  309. X
  310. #ifdef TEST
  311. /* Compile with -DTEST to make an executable for use in testing
  312. X   the above definition of `getopt'.  */
  313. X
  314. int
  315. main (argc, argv)
  316. X    int argc;
  317. X    char **argv;
  318. {
  319. X    int c;
  320. X    int digit_optind = 0;
  321. X
  322. X    while (1) {
  323. X    int this_option_optind = optind ? optind : 1;
  324. X
  325. X    c = getopt (argc, argv, "abc:d:0123456789");
  326. X    if (c == EOF)
  327. X        break;
  328. X
  329. X    switch (c) {
  330. X     case '0':
  331. X     case '1':
  332. X     case '2':
  333. X     case '3':
  334. X     case '4':
  335. X     case '5':
  336. X     case '6':
  337. X     case '7':
  338. X     case '8':
  339. X     case '9':
  340. X         if (digit_optind != 0 && digit_optind != this_option_optind)
  341. X         printf ("digits occur in two different argv-elements.\n");
  342. X         digit_optind = this_option_optind;
  343. X         printf ("option %c\n", c);
  344. X         break;
  345. X
  346. X     case 'a':
  347. X         printf ("option a\n");
  348. X         break;
  349. X
  350. X     case 'b':
  351. X         printf ("option b\n");
  352. X         break;
  353. X
  354. X     case 'c':
  355. X         printf ("option c with value `%s'\n", optarg);
  356. X         break;
  357. X
  358. X     case '?':
  359. X         break;
  360. X
  361. X     default:
  362. X         printf ("?? getopt returned character code 0%o ??\n", c);
  363. X    }
  364. X    }
  365. X
  366. X    if (optind < argc) {
  367. X    printf ("non-option ARGV-elements: ");
  368. X    while (optind < argc)
  369. X        printf ("%s ", argv[optind++]);
  370. X    printf ("\n");
  371. X    }
  372. X    exit (0);
  373. }
  374. X
  375. #endif /* TEST */
  376. SHAR_EOF
  377. echo 'File hodge-c-0.98j/getopt.c is complete' &&
  378. chmod 0640 hodge-c-0.98j/getopt.c ||
  379. echo 'restore of hodge-c-0.98j/getopt.c failed'
  380. Wc_c="`wc -c < 'hodge-c-0.98j/getopt.c'`"
  381. test 18860 -eq "$Wc_c" ||
  382.     echo 'hodge-c-0.98j/getopt.c: original size 18860, current size' "$Wc_c"
  383. rm -f _shar_wnt_.tmp
  384. fi
  385. # ============= hodge-c-0.98j/getopt.h ==============
  386. if test -f 'hodge-c-0.98j/getopt.h' -a X"$1" != X"-c"; then
  387.     echo 'x - skipping hodge-c-0.98j/getopt.h (File already exists)'
  388.     rm -f _shar_wnt_.tmp
  389. else
  390. > _shar_wnt_.tmp
  391. echo 'x - extracting hodge-c-0.98j/getopt.h (Text)'
  392. sed 's/^X//' << 'SHAR_EOF' > 'hodge-c-0.98j/getopt.h' &&
  393. X
  394. /* Declarations for getopt.
  395. X   Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
  396. X
  397. X   This program is free software; you can redistribute it and/or modify
  398. X   it under the terms of the GNU General Public License as published by
  399. X   the Free Software Foundation; either version 2, or (at your option)
  400. X   any later version.
  401. X
  402. X   This program is distributed in the hope that it will be useful,
  403. X   but WITHOUT ANY WARRANTY; without even the implied warranty of
  404. X   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  405. X   GNU General Public License for more details.
  406. X
  407. X   You should have received a copy of the GNU General Public License
  408. X   along with this program; if not, write to the Free Software
  409. X   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  410. X
  411. #ifndef _GETOPT_H_
  412. #define _GETOPT_H_
  413. X
  414. /* For communication from `getopt' to the caller.
  415. X   When `getopt' finds an option that takes an argument,
  416. X   the argument value is returned here.
  417. X   Also, when `ordering' is RETURN_IN_ORDER,
  418. X   each non-option ARGV-element is returned here.  */
  419. X
  420. extern char *optarg;
  421. X
  422. /* Index in ARGV of the next element to be scanned.
  423. X   This is used for communication to and from the caller
  424. X   and for communication between successive calls to `getopt'.
  425. X
  426. X   On entry to `getopt', zero means this is the first call; initialize.
  427. X
  428. X   When `getopt' returns EOF, this is the index of the first of the
  429. X   non-option elements that the caller should itself scan.
  430. X
  431. X   Otherwise, `optind' communicates from one call to the next
  432. X   how much of ARGV has been scanned so far.  */
  433. X
  434. extern int optind;
  435. X
  436. /* Callers store zero here to inhibit the error message `getopt' prints
  437. X   for unrecognized options.  */
  438. X
  439. extern int opterr;
  440. X
  441. /* Describe the long-named options requested by the application.
  442. X   The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
  443. X   of `struct option' terminated by an element containing a name which is
  444. X   zero.
  445. X
  446. X   The field `has_arg' is:
  447. X   no_argument        (or 0) if the option does not take an argument,
  448. X   required_argument    (or 1) if the option requires an argument,
  449. X   optional_argument     (or 2) if the option takes an optional argument.
  450. X
  451. X   If the field `flag' is not NULL, it points to a variable that is set
  452. X   to the value given in the field `val' when the option is found, but
  453. X   left unchanged if the option is not found.
  454. X
  455. X   To have a long-named option do something other than set an `int' to
  456. X   a compiled-in constant, such as set a value from `optarg', set the
  457. X   option's `flag' field to zero and its `val' field to a nonzero
  458. X   value (the equivalent single-letter option character, if there is
  459. X   one).  For long options that have a zero `flag' field, `getopt'
  460. X   returns the contents of the `val' field.  */
  461. X
  462. struct option {
  463. X
  464. #ifdef    __STDC__
  465. X    const char *name;
  466. #else
  467. X    char *name;
  468. #endif
  469. X
  470. X   /* has_arg can't be an enum because some compilers complain about
  471. X     type mismatches in all the code that assumes it is an int.  */
  472. X    int has_arg;
  473. X    int *flag;
  474. X    int val;
  475. };
  476. X
  477. /* Names for the values of the `has_arg' field of `struct option'.  */
  478. X
  479. enum _argtype {
  480. X    no_argument,
  481. X    required_argument,
  482. X    optional_argument
  483. };
  484. X
  485. #ifdef __STDC__
  486. extern int getopt (int argc, char *const *argv, const char *shortopts);
  487. extern int getopt_long (int argc, char *const *argv, const char *shortopts,
  488. X            const struct option *longopts, int *longind);
  489. extern int getopt_long_only (int argc, char *const *argv,
  490. X                 const char *shortopts,
  491. X                 const struct option *longopts, int *longind);
  492. X
  493. /* Internal only.  Users should not call this directly.  */
  494. extern int _getopt_internal (int argc, char *const *argv,
  495. X                 const char *shortopts,
  496. X                 const struct option *longopts, int *longind,
  497. X                 int long_only);
  498. #else /* not __STDC__ */
  499. extern int getopt ();
  500. extern int getopt_long ();
  501. extern int getopt_long_only ();
  502. X
  503. extern int _getopt_internal ();
  504. #endif /* not __STDC__ */
  505. X
  506. #endif /* _GETOPT_H_ */
  507. SHAR_EOF
  508. chmod 0640 hodge-c-0.98j/getopt.h ||
  509. echo 'restore of hodge-c-0.98j/getopt.h failed'
  510. Wc_c="`wc -c < 'hodge-c-0.98j/getopt.h'`"
  511. test 3956 -eq "$Wc_c" ||
  512.     echo 'hodge-c-0.98j/getopt.h: original size 3956, current size' "$Wc_c"
  513. rm -f _shar_wnt_.tmp
  514. fi
  515. # ============= hodge-c-0.98j/getopt1.c ==============
  516. if test -f 'hodge-c-0.98j/getopt1.c' -a X"$1" != X"-c"; then
  517.     echo 'x - skipping hodge-c-0.98j/getopt1.c (File already exists)'
  518.     rm -f _shar_wnt_.tmp
  519. else
  520. > _shar_wnt_.tmp
  521. echo 'x - extracting hodge-c-0.98j/getopt1.c (Text)'
  522. sed 's/^X//' << 'SHAR_EOF' > 'hodge-c-0.98j/getopt1.c' &&
  523. X
  524. /* Getopt for GNU.
  525. X   Copyright (C) 1987, 88, 89, 90, 91, 1992 Free Software Foundation, Inc.
  526. X
  527. X   This program is free software; you can redistribute it and/or modify
  528. X   it under the terms of the GNU General Public License as published by
  529. X   the Free Software Foundation; either version 2, or (at your option)
  530. X   any later version.
  531. X
  532. X   This program is distributed in the hope that it will be useful,
  533. X   but WITHOUT ANY WARRANTY; without even the implied warranty of
  534. X   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  535. X   GNU General Public License for more details.
  536. X
  537. X   You should have received a copy of the GNU General Public License
  538. X   along with this program; if not, write to the Free Software
  539. X   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  540. X
  541. #ifdef    LIBC
  542. /* For when compiled as part of the GNU C library.  */
  543. #include <ansidecl.h>
  544. #endif
  545. X
  546. #include "getopt.h"
  547. X
  548. #ifndef __STDC__
  549. #define const
  550. #endif
  551. X
  552. #if defined(STDC_HEADERS) || defined(__GNU_LIBRARY__) || defined (LIBC)
  553. #include <stdlib.h>
  554. #else /* STDC_HEADERS or __GNU_LIBRARY__ */
  555. char *getenv ();
  556. #endif /* STDC_HEADERS or __GNU_LIBRARY__ */
  557. X
  558. #if !defined (NULL)
  559. #define NULL 0
  560. #endif
  561. X
  562. int
  563. getopt_long (argc, argv, options, long_options, opt_index)
  564. X    int argc;
  565. X    char *const *argv;
  566. X    const char *options;
  567. X    const struct option *long_options;
  568. X    int *opt_index;
  569. {
  570. X    return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
  571. }
  572. X
  573. /* Like getopt_long, but '-' as well as '--' can indicate a long option.
  574. X   If an option that starts with '-' (not '--') doesn't match a long option,
  575. X   but does match a short option, it is parsed as a short option
  576. X   instead. */
  577. X
  578. int
  579. getopt_long_only (argc, argv, options, long_options, opt_index)
  580. X    int argc;
  581. X    char *const *argv;
  582. X    const char *options;
  583. X    const struct option *long_options;
  584. X    int *opt_index;
  585. {
  586. X    return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
  587. }
  588. X
  589. #ifdef TEST
  590. #include <stdio.h>
  591. X
  592. int
  593. main (argc, argv)
  594. X    int argc;
  595. X    char **argv;
  596. {
  597. X    int c;
  598. X    int digit_optind = 0;
  599. X
  600. X    while (1) {
  601. X    int this_option_optind = optind ? optind : 1;
  602. X    int option_index = 0;
  603. X    static struct option long_options[] =
  604. X    {
  605. X        {"add", 1, 0, 0},
  606. X        {"append", 0, 0, 0},
  607. X        {"delete", 1, 0, 0},
  608. X        {"verbose", 0, 0, 0},
  609. X        {"create", 0, 0, 0},
  610. X        {"file", 1, 0, 0},
  611. X        {0, 0, 0, 0}
  612. X    };
  613. X
  614. X    c = getopt_long (argc, argv, "abc:d:0123456789",
  615. X             long_options, &option_index);
  616. X    if (c == EOF)
  617. X        break;
  618. X
  619. X    switch (c) {
  620. X     case 0:
  621. X         printf ("option %s", long_options[option_index].name);
  622. X         if (optarg)
  623. X         printf (" with arg %s", optarg);
  624. X         printf ("\n");
  625. X         break;
  626. X
  627. X     case '0':
  628. X     case '1':
  629. X     case '2':
  630. X     case '3':
  631. X     case '4':
  632. X     case '5':
  633. X     case '6':
  634. X     case '7':
  635. X     case '8':
  636. X     case '9':
  637. X         if (digit_optind != 0 && digit_optind != this_option_optind)
  638. X         printf ("digits occur in two different argv-elements.\n");
  639. X         digit_optind = this_option_optind;
  640. X         printf ("option %c\n", c);
  641. X         break;
  642. X
  643. X     case 'a':
  644. X         printf ("option a\n");
  645. X         break;
  646. X
  647. X     case 'b':
  648. X         printf ("option b\n");
  649. X         break;
  650. X
  651. X     case 'c':
  652. X         printf ("option c with value `%s'\n", optarg);
  653. X         break;
  654. X
  655. X     case 'd':
  656. X         printf ("option d with value `%s'\n", optarg);
  657. X         break;
  658. X
  659. X     case '?':
  660. X         break;
  661. X
  662. X     default:
  663. X         printf ("?? getopt returned character code 0%o ??\n", c);
  664. X    }
  665. X    }
  666. X
  667. X    if (optind < argc) {
  668. X    printf ("non-option ARGV-elements: ");
  669. X    while (optind < argc)
  670. X        printf ("%s ", argv[optind++]);
  671. X    printf ("\n");
  672. X    }
  673. X    exit (0);
  674. }
  675. X
  676. #endif /* TEST */
  677. SHAR_EOF
  678. chmod 0640 hodge-c-0.98j/getopt1.c ||
  679. echo 'restore of hodge-c-0.98j/getopt1.c failed'
  680. Wc_c="`wc -c < 'hodge-c-0.98j/getopt1.c'`"
  681. test 3564 -eq "$Wc_c" ||
  682.     echo 'hodge-c-0.98j/getopt1.c: original size 3564, current size' "$Wc_c"
  683. rm -f _shar_wnt_.tmp
  684. fi
  685. # ============= hodge-c-0.98j/hodge.1 ==============
  686. if test -f 'hodge-c-0.98j/hodge.1' -a X"$1" != X"-c"; then
  687.     echo 'x - skipping hodge-c-0.98j/hodge.1 (File already exists)'
  688.     rm -f _shar_wnt_.tmp
  689. else
  690. > _shar_wnt_.tmp
  691. echo 'x - extracting hodge-c-0.98j/hodge.1 (Text)'
  692. sed 's/^X//' << 'SHAR_EOF' > 'hodge-c-0.98j/hodge.1' &&
  693. .\" $Id: hodge.1,v 1.1 1993/03/16 10:35:58 joke Exp $
  694. .TH HODGE-C 1 "9 March 1993" "Version 0.98j"
  695. X
  696. \" this noise gets my name right!
  697. .nr 99 \n(.s
  698. .nr 98 \n(.f
  699. .ds 11 "\fRo
  700. .nr 11 \w'\s10\*(11'
  701. .nr 10 0u
  702. .if \n(ct>1 .nr 10 \n(10+\s10.25m\s0
  703. .nr 13 \s10.1m\s0
  704. .if \n(ct>1 .nr 13 \s10.15m\s0
  705. .ds 12 \s10\v'-.67m'..\v'.67m\s0'
  706. .nr 12 \w'\s10\*(12'
  707. .as 11 \h'-\n(11u-\n(12u/2u+\n(13u'\v'0-\n(10u'\*(12\v'\n(10u'\h'-\n(12u+\n(11u/2u-\n(13u'
  708. .ds o \x'0'\f1\s10\*(11\s\n(99\f\n(98
  709. X
  710. .SH NAME
  711. .B hodge
  712. \- an implementation of Gerhard & Schuster's hodge-podge machine
  713. X
  714. .SH SYNOPSIS
  715. .LP
  716. .B hodge
  717. [
  718. .I options
  719. ]
  720. .TP
  721. X        [\fB-A, --animation-file-name \fI<name>\fR]
  722. .TP
  723. X        [\fB-C, --color-map-file-name \fI<name>\fR]
  724. .TP
  725. X        [\fB-D, --dump-data-file-name \fI<name>\fR]
  726. .TP
  727. X        [\fB-F, --number-of-frames \fI<number>\fR]
  728. .TP
  729. X        [\fB-G, --groth-rate \fI<number>\fR]
  730. .TP
  731. X        [\fB-J, --ill-cells-denominator \fI<number>\fR]
  732. .TP
  733. X        [\fB-K, --infected-cells-denominator \fI<number>\fR]
  734. .TP
  735. X        [\fB-M, --monitor-process \fI<process>\fR]
  736. .TP
  737. X        [\fB-N, --number-of-cell-states \fI<number>\fR]
  738. .TP
  739. X        [\fB-P, --plot-file-name \fI<name>\fR]
  740. .TP
  741. X        [\fB-S, --size-of-grid \fI<size>\fR]
  742. .TP
  743. X        [\fB-T, --time-steps \fI<number>\fR]
  744. .TP
  745. X        [\fB-X, --start-of-film \fI<timestep>\fR]
  746. .TP
  747. X        [\fB-Y, --skip-between-takes \fI<number>\fR]
  748. .TP
  749. X        [\fB-b, --batch\fR]
  750. .TP
  751. X        [\fB-d, --no-dump\fR]
  752. .TP
  753. X        [\fB-f, --number-of-dumps \fI<number>\fR]
  754. .TP
  755. X        [\fB-g, --gnuplot-data-format\fR]
  756. .TP
  757. X        [\fB-h, --help\fR]
  758. .TP
  759. X        [\fB-i, --idl-data-format\fR]
  760. .TP
  761. X        [\fB-m, --moore-neighbourhood\fR]
  762. .TP
  763. X        [\fB-n, --no-film\fR]
  764. .TP
  765. X        [\fB-o, --on-line-visualization\fR]
  766. .TP
  767. X        [\fB-s, --seed-for-random \fI<seedvalue>\fR]
  768. .TP
  769. X        [\fB-t, --torus\fR]
  770. .TP
  771. X        [\fB-v, --version\fR]
  772. .TP
  773. X        [\fB-w, --warranty\fR]
  774. .TP
  775. X        [\fB-x, --start-of-dump \fI<timestep>\fR]
  776. .TP
  777. X        [\fB-y, --skip-between-dumps \fI<number>\fR]
  778. X
  779. .SH DESCRIPTION
  780. .B hodge
  781. implements a class of cellular automata (CA), that are also known as
  782. .B hodge-podge machines.
  783. They have caught great attention when being discussed in A.K. Dewdney's
  784. ``Computer Recreations'' column in
  785. .I Scientific American.
  786. .BR hodge ,
  787. resembles the currently closest to reality simulation of the
  788. Belousov-Zhabotinskii (BZ) reaction, the most complex anorganic,
  789. oscillating reaction; but hasn't been invented for this special
  790. purpose though
  791. (refer to the
  792. .SM BIBLIOGRAPHY
  793. section below).
  794. X
  795. .BR hodge 's
  796. input and output streams, and all of it's default parameters
  797. may be changed using various options (see the 
  798. .SM OPTIONS
  799. section below).
  800. X
  801. By default
  802. .B hodge
  803. generates 3 types of data files:
  804. .TP \w'\(bu'u+2n
  805. \(bu
  806. a single
  807. .I plot file,
  808. containing a per line statistical shapshot of the CA's internal state
  809. .TP
  810. \(bu
  811. one or more
  812. .I dump file(s),
  813. each containing a snapshot of all cell values of the CA, in either
  814. .B Gnuplot 
  815. (line-oriented) or
  816. .B IDL
  817. (block-oriented) format, and
  818. .TP
  819. \(bu
  820. one or more
  821. .I animation data file(s),
  822. each containing a snapshot of all cell values of the CA, written
  823. in
  824. .I portable pixmap format,
  825. using as much colors, as specified with the
  826. `--number-of-cell-states' option.
  827. .PP
  828. Please, refer to the
  829. .SM FORMATS
  830. section below.
  831. X
  832. .SH ANIMATION
  833. .BR hodge 's
  834. main purpose is to generate the previously mentioned shapshot files
  835. for `making movies'.
  836. All you need is, eg. E. I. du Pont de Nemours & Company's
  837. .B ImageMagick
  838. PD software (available via
  839. .I anonymous ftp
  840. from
  841. .B export.lcs.mit.edu,
  842. as file `contrib/ImageMagick.tar.Z.') using the package's
  843. .BR animate (1)
  844. command you'll soon see BZ waves move across the grid.
  845. An example for this is given in the
  846. .B hodge/movie
  847. folder of the
  848. .SM HODGE-C
  849. distribution.
  850. X
  851. A different approach is to use IDL from Research Systems, Inc.
  852. Boulder, CO, USA. An example for this purpose is given in
  853. the 
  854. .B hodge/idl
  855. folder of the
  856. .SM HODGE-C
  857. distribution.
  858. X
  859. An animation companion to
  860. .BR pixmon (1)
  861. called
  862. .BR playmate (1)
  863. is also in the making, and will be distributed in near future
  864. (refer to the
  865. .SM AVAILABILITY
  866. section below).
  867. Its application is rather simple: all there is to do is to
  868. include a ``tee-log'' in the `--monitor-process' eg.:
  869. .TP
  870. .B --monitor-process 'tee >pmdata.pix | pixmon ...'
  871. .PP
  872. to collect
  873. .BR pixmon (1)
  874. data, that is later turned into animated pixmaps by
  875. .BR playmate (1).
  876. X
  877. A final, powerful and low cost solution for animation is to
  878. install the
  879. .SM KHOROS
  880. visualization package on your system. It comes for free from
  881. the University of New Mexico, and is better than most
  882. commercial products.
  883. .SM KHOROS
  884. also features an easy to use
  885. .I graphical programming interface
  886. called
  887. .SM CANTATA
  888. and is very easy to learn for beginners in
  889. .I scientific visualization.
  890. .SM KHOROS
  891. features a bunch of converters to it's internal
  892. .BR VIFF (5)
  893. format, that is easily generated from
  894. .BR hodge 's
  895. dump (eg. \fBasc2viff\fR(1)) and animation data files
  896. (eg. \fBpbm2viff\fR(1), \fBrast2viff\fR, \fBraw2viff\fR(1), etc.)
  897. X
  898. .SH OPTIONS
  899. .TP
  900. .B \-A, \-\-animation-file-name \fIfilename\fR
  901. Set the animation data file name pattern. (Defaults to
  902. \fIhodge-%0003d.ppm\fR.)
  903. .TP
  904. .B \-C, \-\-color-map-file-name \fIfilename\fR
  905. Set the color map file name. (Defaults to
  906. \fIhodge.map\fR.)
  907. .TP
  908. .B \-D, \-\-dump-data-file-name \fIfilename\fR
  909. Set the data file name pattern. (Defaults to
  910. \fIhodge-%0003d.dmp\fR.)
  911. .TP
  912. .B \-F, \-\-number-of-frames \fInumber\fR
  913. Set the number of frames, ie. the number of animation data files
  914. to write.
  915. .TP
  916. .B \-G, \-\-groth-rate \fInumber\fR
  917. The rate the value of an infected cell increases;
  918. described as parameter
  919. .B g
  920. in A.K. Dewdney's article (defaults to 25).
  921. .TP
  922. .B \-J, \-\-ill-cells-denominator \fInumber\fR
  923. This parameter is used in the equation A/k1 + B/k2,
  924. where A is the count of all
  925. .SM ILL
  926. neighbour cells and B is a counter of all
  927. .SM INFECTED
  928. neighbour cells; this is parameter
  929. .B k1
  930. (k2) in A.K. Dewdney's article (defaults to 2).
  931. .TP
  932. .B \-K, \-\-infected-cells-denominator \fInumber\fR
  933. This parameter is used in the equation A/k1 + B/k2,
  934. where A is the count of all 
  935. .SM ILL
  936. neighbour cells and B is a counter of all
  937. .SM INFECTED
  938. neighbour cells; this is parameter
  939. .B k2
  940. (k1) in A.K. Dewdney's article (defaults to 3).
  941. .TP
  942. .B \-M, \-\-monitor-process \fIprocess\fR
  943. Set a monitor process;
  944. .B hodge
  945. opens a pipe to the given process and writes it's CA's contents
  946. to this pipe, enabling the process to visualize the
  947. incoming data.
  948. Defining a monitor process, implies the `--on-line-visualization'
  949. option. (See the
  950. .SM OPTION SUMMARY
  951. for the process default.)
  952. .TP
  953. .B \-N, \-\-number-of-cell-states \fInumber\fR
  954. Set the number of states a
  955. .SM SANE
  956. cell has to go through, being
  957. .SM INFECTED
  958. to finally become an
  959. .SM ILL
  960. cell (defaults to 100).
  961. .TP
  962. .B \-P, \-\-plot-file \fIfilename\fR
  963. Plot data will go to \fIfilename\fR
  964. (defaults to \fIhodge.plt\fR).
  965. .TP
  966. .B \-S, \-\-size-of-grid \fIsize\fR
  967. Set the CA's grid size, ie. the grid's
  968. .I x
  969. and
  970. .I y
  971. dimensions (\fIx=y\fR).
  972. .TP
  973. .B \-T, \-\-time-steps \fInumber\fR
  974. Run the simulation for
  975. .I number
  976. of timesteps.
  977. .TP
  978. .B \-X, \-\-start-of-film \fItimestep\fR
  979. Set the time step, when to start writing animation data.
  980. .TP
  981. .B \-Y, \-\-skip-between-takes \fInumber\fR
  982. Set the amount of timesteps to pass between successive animation
  983. data takes.
  984. .TP
  985. .B \-b, \-\-batch
  986. Run
  987. .B hodge
  988. in batch mode, ie. don't prompt the user for any input; and
  989. don't produce any user notification output.
  990. .TP
  991. .B \-d, \-\-no-dump
  992. Don't write any dump files.
  993. .TP
  994. .B \-f, \-\-number-of-dumps \fInumber\fR
  995. Set the number of dump files to write.
  996. .TP
  997. .B \-g, \-\-gnuplot-data-format
  998. Set the
  999. .I dump file format
  1000. to
  1001. .B Gnuplot
  1002. (default).
  1003. .TP
  1004. .B \-h, \-\-help
  1005. Print a usage message containing all options.
  1006. .TP
  1007. .B \-i, \-\-idl-data-format
  1008. Set the
  1009. .I dump file format
  1010. to
  1011. .B IDL.
  1012. .TP
  1013. .B \-m, \-\-moore-neighbourhood
  1014. Use a
  1015. .I Moore neighbourhood,
  1016. during computation of the CA's next state,
  1017. by default a
  1018. .I Von-Neumann neighbourhood
  1019. is used, ie. to North, East, South and
  1020. West, North-East, South-East, South-West and North-West are added,
  1021. when using this flag.
  1022. .TP
  1023. .B \-n, \-\-no-film
  1024. Don't write any animation data files.
  1025. .TP
  1026. .B \-o, \-\-on-line-visualization
  1027. Start the process given with the `--monitor-process' option,
  1028. and display the CA's contents on each time step.
  1029. (Note: you need either the
  1030. .BR pixmon (1)
  1031. facility, or an appropriate double.)
  1032. .TP
  1033. .B \-s, \-\-seed-for-random \fIseed value\fR
  1034. Set the random number generator's seed with the integer
  1035. .I seed value.
  1036. .TP
  1037. .B \-t, \-\-torus
  1038. Make the 2D space of the CA grid borderless, ie. the 2D grid
  1039. is folded to a 3D torus.
  1040. .TP
  1041. .B \-v, \-\-version
  1042. Print a version and copyright message.
  1043. .TP
  1044. .B \-w, \-\-warranty
  1045. Print a warranty information message.
  1046. .TP
  1047. .B \-x, \-\-start-of-dump \fItimestep\fR
  1048. Set the time step, when to start dumping.
  1049. .TP
  1050. .B \-y, \-\-skip-between-dumps \fInumber\fR
  1051. Set the amount of timesteps to pass between successive dumps.
  1052. X
  1053. .SH OPTION SUMMARY
  1054. To give no option at all is the same as to give the following options:
  1055. .TP
  1056. --monitor-process        'pixmon -dx 128 -dy 128 -scale 5 -cmap hodge.map'
  1057. .TP
  1058. --animation-file-name    hodge-%0003d.ppm
  1059. .TP
  1060. --color-map-file-name    hodge.map
  1061. .TP
  1062. --number-of-frames    1
  1063. .TP
  1064. --start-of-film        1
  1065. .TP
  1066. --skip-between-takes    1
  1067. .TP
  1068. --dump-data-file-name    hodge-%0003d.dmp
  1069. .TP
  1070. --gnuplot-data-format
  1071. .TP
  1072. --start-of-dump        1
  1073. .TP
  1074. --skip-between-dumps    1
  1075. .TP
  1076. --time-steps        1000
  1077. .TP
  1078. --grid-size        128
  1079. .TP
  1080. --number-of-cell-states    100
  1081. .TP
  1082. --ill-cells-denominator    2
  1083. .TP
  1084. --infected-cells-denominator    3
  1085. .TP
  1086. --groth-rate        25
  1087. .TP
  1088. --plot-file-name        hodge.plt
  1089. .TP
  1090. --seed-for-random    12345678
  1091. X
  1092. .SH FORMATS
  1093. The only
  1094. .SM INPUT FORMAT
  1095. .B hodge
  1096. acknowledges, is a
  1097. .I color map file,
  1098. using 256 colors with the following
  1099. .B RGB
  1100. format:
  1101. .LP
  1102. .nf
  1103. .DT
  1104. .ft B
  1105. X    #     File:        demo.map
  1106. X    #    Creator:    joke
  1107. X    # <- this is a comment line: '#' in the 1st column
  1108. X    <red intensity 0>    <green intensity 0>    <blue intensity 0>
  1109. X    <red intensity 1>    <green intensity 1>    <blue intensity 1>
  1110. X    <red intensity 2>    <green intensity 2>    <blue intensity 2>
  1111. X                \&.\&.\&.
  1112. X    <red intensity 255>    <green intensity 255>    <blue intensity 255>
  1113. .ft R
  1114. .fi
  1115. X
  1116. Thus a non-commented color map file consist of 256 lines each one
  1117. containing such a color description. Eg. to get a greyscale `color'
  1118. map, simply use the same intensities for all colors.
  1119. X
  1120. The
  1121. .SM OUTPUT FORMATS
  1122. are as follows:
  1123. .TP \w'\(bu'u+2n
  1124. \(bu
  1125. The
  1126. .I plot file format
  1127. is precisely specified as:
  1128. .LP
  1129. .nf
  1130. .DT
  1131. .ft B
  1132. X    <timestep 0> <# sane> <# infected> <# ill> <percentage of infected cells>
  1133. X    <timestep 1> <# sane> <# infected> <# ill> <percentage of infected cells>
  1134. X    <timestep 2> <# sane> <# infected> <# ill> <percentage of infected cells>
  1135. X                    \&.\&.\&.
  1136. X    <timestep n> <# sane> <# infected> <# ill> <percentage of infected cells>
  1137. .ft R
  1138. .fi
  1139. X
  1140. on a per line base, with
  1141. .B <timestep 0>
  1142. running from 1 to n, the latter being specified by the
  1143. `--time-steps' option.
  1144. .TP \w'\(bu'u+2n
  1145. \(bu
  1146. The
  1147. .I dump file format
  1148. depends on whether the
  1149. .B Gnuplot
  1150. data file format, or the
  1151. .B IDL
  1152. data file format has been chosen, with the first being the default,
  1153. when no user-specification via run-time option has taken place.
  1154. .RS
  1155. .TP \w'\(bu'u+2n
  1156. \(bu
  1157. The
  1158. .B Gnuplot
  1159. (line-oriented) data file format:
  1160. .LP
  1161. .nf
  1162. .DT
  1163. .ft B
  1164. X    <xcell index 0> <ycell index 0> <xycell value 0,0>
  1165. X    <xcell index 1> <ycell index 0> <xycell value 1,0>
  1166. X    <xcell index 2> <ycell index 0> <xycell value 2,0>
  1167. X            \&.\&.\&.
  1168. X    <xcell index n> <ycell index 0> <xycell value n,0>
  1169. X
  1170. X    <xcell index 0> <ycell index 1> <xycell value 0,0>
  1171. X    <xcell index 1> <ycell index 1> <xycell value 1,1>
  1172. X    <xcell index 2> <ycell index 1> <xycell value 2,1>
  1173. X            \&.\&.\&.
  1174. X    <xcell index n> <ycell index 1> <xycell value n,1>
  1175. X
  1176. X            \&.\&.\&.
  1177. X    <xcell index n> <ycell index n> <xycell value n,n>
  1178. .ft R
  1179. .fi
  1180. .TP \w'\(bu'u+2n
  1181. \(bu
  1182. The
  1183. .B IDL
  1184. (block-oriented) data file format:
  1185. .LP
  1186. .nf
  1187. .DT
  1188. .ft B
  1189. X    <xcell-index 0>
  1190. X    <xcell-index 1>
  1191. X    <xcell-index 2>
  1192. X    \&.\&.\&.
  1193. X
  1194. X    <ycell-index 0>
  1195. X    <ycell-index 1>
  1196. X    <ycell-index 2>
  1197. X    \&.\&.\&.
  1198. X
  1199. X    <xycell value 0,0>
  1200. X    <xycell value 1,0>
  1201. X    <xycell value n,0>
  1202. X    \&.\&.\&.
  1203. X    <xycell value n,n>
  1204. .ft R
  1205. .fi
  1206. .RE
  1207. .TP \w'\(bu'u+2n
  1208. \(bu
  1209. The
  1210. .I animation file format
  1211. is the portable pixmap format, as defined by
  1212. .I Jeff Poskanzer
  1213. for his bitmap conversion collection
  1214. .B pbmplus.
  1215. I thus direct the reader to the appropriate manual page(s) of
  1216. that package, ie.
  1217. .BR pbmplus (1),
  1218. and
  1219. .BR ppm (5).
  1220. X
  1221. .SH EXAMPLES
  1222. The following are two examples displaying the dumps of a
  1223. .I 2x2
  1224. grid:
  1225. .PP
  1226. The
  1227. .B Gnuplot
  1228. data file format:
  1229. .LP
  1230. .nf
  1231. .DT
  1232. .ft R
  1233. X    1    1    0
  1234. X    1    2    10
  1235. X
  1236. X    2    1    37
  1237. X    2    2    100
  1238. .fi
  1239. .PP
  1240. The
  1241. .B IDL
  1242. data file format:
  1243. .LP
  1244. .nf
  1245. .DT
  1246. X    1
  1247. X    2
  1248. X    1
  1249. X    2
  1250. X
  1251. X    1
  1252. X    2
  1253. X    1
  1254. X    2
  1255. X
  1256. X    0
  1257. X    10
  1258. X    37
  1259. X    100
  1260. .ft R
  1261. .fi
  1262. X
  1263. .SH FILES
  1264. Unless specified otherwise
  1265. .B hodge
  1266. reads in the first, and writes the following files at run-time:
  1267. .LP
  1268. .nf
  1269. .DT
  1270. .ft R
  1271. hodge.map        \fIdefault color map\fR
  1272. .PP
  1273. hodge.plt        \fIplot data file\fR
  1274. hodge-xyz.ppm        \fIanimation data file(s) in ppm format\fR
  1275. hodge-xyz.dmp        \fIdump data file(s) in either Gnuplot or IDL format\fR
  1276. .ft R
  1277. .fi
  1278. .PP
  1279. The distribution of
  1280. .SM HODGE-C
  1281. contains, besides the usual source and makefiles, the following files:
  1282. .LP
  1283. .nf
  1284. .DT
  1285. .ft R
  1286. INSTALL        \fIhints for installation of \fBhodge\fI on your system\fR
  1287. configure        \fIC shell script to configure \fBhodge\fI for your system\fR
  1288. config/*.cf        \fIvarious system's configuration files\fR
  1289. .PP
  1290. contrib/infekt2.c        \fIMartin Gerhard's original source\fR
  1291. .PP
  1292. cmaps/*.map        \fIvarious color maps\fR
  1293. .PP
  1294. khoros/README    \fIhints for making movies with \fBKHOROS\fR
  1295. khoros/movie        \fIC shell script to run \fBhodge\fR
  1296. khoros/bz-*.vif        \fIdemo animation data\fR
  1297. .PP
  1298. magick/README    \fIhints for making movies with \fBIMAGEMAGICK\fR
  1299. magick/movie        \fIC shell script to run \fBhodge\fR
  1300. magick/bz-*.gif        \fIdemo animation data\fR
  1301. magick/gif2vif        \fIshell script converting GIF to VIFF files\fR
  1302. .PP
  1303. idl/README        \fIhints for making movies with \fBIDL\fR
  1304. idl/idemo        \fIC shell script to run \fBhodge\fR
  1305. idl/iload            \fIshell script that uncompresses and loads idata.Z\fR
  1306. idl/idata.Z        \fIdemo animation data\fR
  1307. .PP
  1308. typ?            \fIdemo C shell script to produce type #? (1-4) plot files\fR
  1309. typ?.gnu            \fBgnuplot\fR(1) \fIcommand file to produce 2D and 3D plots\fR
  1310. .ft R
  1311. .fi
  1312. X
  1313. .SH BUGS
  1314. .B hodge
  1315. has even more options than
  1316. .B ls.
  1317. .PP
  1318. The pseudo code given in the
  1319. .I Scientific American
  1320. article contains a subtle bug: Dewdney confused the meaning of
  1321. A and B, ie. he says ``A counts the infected neighbours and B the ill ones,''
  1322. but it's the other way round. For the interested,
  1323. .I Martin Gerhard's
  1324. original 
  1325. .SM ATART ST
  1326. version of the hodge-podge machine is included in this distribution.
  1327. X
  1328. .SH ALGORITHM
  1329. Due to this confusion I give here the correct algorithm core in pseudo code:
  1330. .LP
  1331. .nf
  1332. .DT
  1333. .ft B
  1334. X    foreach cell do
  1335. X        A := count of ill neighbour cells            // range: [0..8]
  1336. X        B := count of infected neighbour cells        // range: [0..8]
  1337. X        S := value of all neighbour cells + value of cell    // range: [0..8*n]
  1338. X
  1339. X        case state(cell) of
  1340. X            SANE:
  1341. X                begin
  1342. X                    newval := A/k1 + B/k2
  1343. X                end
  1344. X
  1345. X            INFECTED:
  1346. X                begin
  1347. X                    B := B + 1        // count self (sic!)
  1348. X                    newval := S/B + g    // ...else B could be zero 
  1349. X                end
  1350. X
  1351. X            ILL:
  1352. X                begin
  1353. X                    newval := 0        // 0 means SANE
  1354. X                end
  1355. X        esac
  1356. X
  1357. X        if newval > MAXVALUE            // number-of-cell-states option (=n)
  1358. X            value(cell) := 0
  1359. X        else
  1360. X            value(cell) := newval
  1361. X    od
  1362. .ft R
  1363. .fi
  1364. X
  1365. .SH BIBLIOGRAPHY
  1366. .PP
  1367. .B BZ specific publications:
  1368. .PP
  1369. A.K. Dewdney,
  1370. Computer Recreations,
  1371. .I Scientific American,
  1372. August, 1988.
  1373. .PP
  1374. Stefan C. Mueller, Theo Plesser and Benno Hess,
  1375. The Structure of the Core of
  1376. the Spiral Wave in the
  1377. Belousov-Zhabotinskii Reaction,
  1378. .I Science,
  1379. 230(4726), November, 1985.
  1380. .PP
  1381. Stefan C. Mueller, Theo Plesser and Benno Hess,
  1382. Three-dimensional Representation of Chemical Gradients,
  1383. .I Biophysical Chemistry,
  1384. February, 1987.
  1385. .PP
  1386. .B Cellular automata theory and practice:
  1387. .PP
  1388. D. Farmer, T. Toffoli and S. Wolfram,
  1389. .I Cellular Automata,
  1390. North-Holland, Amsterdam, 1984.
  1391. .PP
  1392. S. Wolfram,
  1393. .I Theory and Applications of Cellular Automata,
  1394. World Scientific Publishing, Singapore, 1986.
  1395. .PP
  1396. Christopher G. Langton,
  1397. .I Artificial Life,
  1398. Addison-Wesley, Redwood City, CA, 1989.
  1399. (The Proceedings of an Interdisciplinary Workshop on
  1400. the Synthesis and Simulation of Living Systems
  1401. held September, 1987 in Los Alamos, New Mexico.)
  1402. .PP
  1403. Christopher G. Langton, et al.,
  1404. .I Artificial Life II,
  1405. .I A proceedings volume in the
  1406. .I Santa Fe Institute Studies
  1407. .I in the Science of Complexity,
  1408. Addison-Wesley, Reading, MA, 1990.
  1409. (Proceedings of the Workshop on Artificial Life
  1410. held February, 1990 in Santa Fe, New Mexico.)
  1411. .PP
  1412. .B Introductory books:
  1413. .PP
  1414. Paul Davies,
  1415. .I Cosmic Blueprint,
  1416. Heinemann, London, UK, 1988.
  1417. .PP
  1418. John Briggs and F. David Peat,
  1419. .I An Illustrated Guide to Chaos Theory
  1420. .I and the Science of Wholeness,
  1421. Harper & Row, New York, NY 1989.
  1422. X
  1423. .SH SEE ALSO
  1424. .BR gnuplot (1),
  1425. .BR imagemagick (1),
  1426. .BR khoros (1),
  1427. .BR pbmplus (1),
  1428. .BR pixmon (1),
  1429. .BR playmate (1),
  1430. .BR xv (1),
  1431. .BR ppm (5)
  1432. X
  1433. .SH AUTHOR
  1434. Copyright 
  1435. .if t \(co 
  1436. .if n (C)
  1437. 1993 by
  1438. .if n Joerg Heitkoetter
  1439. .if t J\*org Heitk\*otter
  1440. .nf
  1441. Systems Analysis Group, University of Dortmund, Germany.
  1442. .nf
  1443. Send bugs, comments, etc., to (joke@ls11.informatik.uni-dortmund.de).
  1444. .fi
  1445. X
  1446. .SH CREDITS
  1447. I'd like to thank
  1448. .I Joachim Sprave,
  1449. of the Systems Analysis Group for lending and extending his
  1450. .BR pixmon (1)
  1451. visualization package, to suit my needs; moreover
  1452. .I Uli Hermes
  1453. and
  1454. .I Frank Kursawe
  1455. for help with
  1456. .B IDL.
  1457. I am also greatfully indepted to
  1458. .I Heike Schuster
  1459. and
  1460. .I Martin Gerhard
  1461. for their enthusiasm and friendly explanations, when we met at the
  1462. Biomathematics Research Group, at the former Max-Planck-Institute
  1463. for Nutrition Physiology, in 1988, which has been renamed to MPI for
  1464. Molecular Physiology, in February 1993.
  1465. More thanks go to
  1466. .I Jenna W. Dea,
  1467. currently at UCSC, for lots of questions on CAs, and giving me
  1468. an opportunity; to once again spend my time on things, I do not have time
  1469. for.
  1470. X
  1471. .SH AVAILABILITY
  1472. .LP
  1473. This work is protected by the terms of the
  1474. .SM GNU
  1475. General Public License. Please refer to the
  1476. .SM LICENSE
  1477. file accompanying the sources of this software package for a lengthy, boring,
  1478. but absolute complete description.
  1479. X
  1480. The sources come from
  1481. .SM MAGPIE
  1482. \-\- The European Free Software Factory Project.
  1483. For more information on
  1484. .SM MAGPIE
  1485. send email to (joke@ls11.informatik.uni-dortmund.de).
  1486. X
  1487. .SM HODGE-C
  1488. is available via anonymous ftp from the group's server
  1489. .B lumpi.informatik.uni-dortmunde.de
  1490. (129.217.36.140)
  1491. as file `hodge-c-0.98j.tar.Z' in /pub/CA/src.
  1492. X
  1493. .SH WARRANTY
  1494. .LP
  1495. This program is free software; you can redistribute it and/or modify
  1496. it under the terms of the
  1497. .SM GNU
  1498. General Public License as published by
  1499. the Free Software Foundation; either version 2 of the License, or
  1500. (at your option) any later version.
  1501. X
  1502. This program is distributed in the hope that it will be useful,
  1503. but
  1504. .SM WITHOUT ANY WARRANTY;
  1505. without even the implied warranty of
  1506. .SM MERCHANTABILITY
  1507. or
  1508. .SM FITNESS FOR A PARTICULAR PURPOSE.
  1509. See the
  1510. .SM GNU
  1511. General Public License for more details.
  1512. X
  1513. You should have received a copy of the
  1514. .SM GNU
  1515. General Public License
  1516. along with this program; if not, write to the Free Software
  1517. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1518. SHAR_EOF
  1519. chmod 0640 hodge-c-0.98j/hodge.1 ||
  1520. echo 'restore of hodge-c-0.98j/hodge.1 failed'
  1521. Wc_c="`wc -c < 'hodge-c-0.98j/hodge.1'`"
  1522. test 19077 -eq "$Wc_c" ||
  1523.     echo 'hodge-c-0.98j/hodge.1: original size 19077, current size' "$Wc_c"
  1524. rm -f _shar_wnt_.tmp
  1525. fi
  1526. # ============= hodge-c-0.98j/hodge.c ==============
  1527. if test -f 'hodge-c-0.98j/hodge.c' -a X"$1" != X"-c"; then
  1528.     echo 'x - skipping hodge-c-0.98j/hodge.c (File already exists)'
  1529.     rm -f _shar_wnt_.tmp
  1530. else
  1531. > _shar_wnt_.tmp
  1532. echo 'x - extracting hodge-c-0.98j/hodge.c (Text)'
  1533. sed 's/^X//' << 'SHAR_EOF' > 'hodge-c-0.98j/hodge.c' &&
  1534. X
  1535. /* HODGE-C -- A C implementation of Gerhard & Schuster's hodge-podge machine */
  1536. X
  1537. /* hodge.c -- main program
  1538. X
  1539. X   Copyright (C) 1993 Joerg Heitkoetter
  1540. X
  1541. X   This program is free software; you can redistribute it and/or modify
  1542. X   it under the terms of the GNU General Public License as published by
  1543. X   the Free Software Foundation; either version 2, or (at your option)
  1544. X   any later version.
  1545. X
  1546. X   This program is distributed in the hope that it will be useful,
  1547. X   but WITHOUT ANY WARRANTY; without even the implied warranty of
  1548. X   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1549. X   GNU General Public License for more details.
  1550. X
  1551. X   You should have received a copy of the GNU General Public License
  1552. X   along with this program; if not, write to the Free Software
  1553. X   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  1554. X
  1555. #ifndef lint
  1556. static char *rcsid = "$Id: hodge.c,v 1.2 1993/03/19 11:28:28 heitkoet Exp heitkoet $";
  1557. #endif
  1558. X
  1559. #include "hodge.h"
  1560. #include "getopt.h"
  1561. #include "version.h"
  1562. X
  1563. /* flags */
  1564. bool moore = FALSE;            /* von-Neumann default */
  1565. bool torus = FALSE;            /* bounded by default */
  1566. bool film = TRUE;            /* generate a film by default */
  1567. bool moni = FALSE;            /* generate online visualisation */
  1568. bool batch = FALSE;            /* generate no user feedback */
  1569. bool dump = TRUE;            /* generate any dump file */
  1570. bool idl = FALSE;            /* generate IDL data file */
  1571. bool gnuplot = TRUE;            /* generated Gnuplot data file */
  1572. X
  1573. int n = 100;                /* number of states from SANE to ILL */
  1574. int ncells = 128;            /* number of each side of grid */
  1575. int nticks = 1000;            /* timer ticks to computer */
  1576. X
  1577. int random_seed = 12345678;        /* seed for random number generator */
  1578. X
  1579. int nsane;                /* number of sane cells */
  1580. int ninfected;                /* number of infected cells */
  1581. int nill;                /* number of ill cells */
  1582. X
  1583. int nframes = 1;            /* number of frames to write */
  1584. int startoffilm = 0;            /* time step to start film */
  1585. int skipbetweentakes = 1;        /* take every new state */
  1586. int framestotake;            /* frames left to take (= nframes) */
  1587. X
  1588. int ndumps = 1;                /* number of dumps to write */
  1589. int startofdump = 0;            /* time step to start dump */
  1590. int skipbetweendumps = 1;        /* dump every new state */
  1591. int dumpstomake;            /* dumps left to make (= ndumps) */
  1592. X
  1593. int k1 = 2;                /* G&S's default */
  1594. int k2 = 3;                /* G&S's default */
  1595. int g = 25;                /* some nice waves */
  1596. X
  1597. char *afilename = "hodge-%0003d.ppm";    /* default frame prefix file */
  1598. char *cfilename = "hodge.col";        /* default color map file */
  1599. char *dfilename = "hodge-%0003d.dmp";    /* default dump data file */
  1600. char *pfilename = "hodge.plt";        /* default plot data file */
  1601. X
  1602. X                    /* default monitor process */
  1603. char *mfilename = "pixmon -dx 128 -dy 128 -scale 4 -cmap hodge.col";
  1604. X
  1605. X
  1606. /* global stuff */
  1607. char *program_name;            /* who am i? */
  1608. X
  1609. FILE *rep;                /* pointer to report file */
  1610. FILE *mon;                /* pointer to monitor process */
  1611. X
  1612. grid_t cell, ncell;            /* the CA storage */
  1613. X
  1614. cmap_t cmap;                /* color map */
  1615. X
  1616. X
  1617. /* program options */
  1618. static struct option opts[] =
  1619. {
  1620. X    {
  1621. X    "animation-file-name", 1, 0, 'A'
  1622. X    },
  1623. X    {
  1624. X    "color-map-file-name", 1, 0, 'C'
  1625. X    },
  1626. X    {
  1627. X    "dump-data-file-name", 1, 0, 'D'
  1628. X    },
  1629. X    {
  1630. X    "number-of-frames", 1, 0, 'F'
  1631. X    },
  1632. X    {
  1633. X    "groth-rate", 1, 0, 'G'
  1634. X    },
  1635. X    {
  1636. X    "ill-cells-denominator", 1, 0, 'J'
  1637. X    },
  1638. X    {
  1639. X    "infected-cells-denominator", 1, 0, 'K'
  1640. X    },
  1641. X    {
  1642. X    "number-of-cell-states", 1, 0, 'N'
  1643. X    },
  1644. X    {
  1645. X    "monitor-process", 1, 0, 'M'
  1646. X    },
  1647. X    {
  1648. X    "plot-file-name", 1, 0, 'P'
  1649. X    },
  1650. X    {
  1651. X    "size-of-grid", 1, 0, 'S'
  1652. X    },
  1653. X    {
  1654. X    "time-steps", 1, 0, 'T'
  1655. X    },
  1656. X    {
  1657. X    "start-of-film", 1, 0, 'X'
  1658. X    },
  1659. X    {
  1660. X    "skip-between-takes", 1, 0, 'Y'
  1661. X    },
  1662. X    {
  1663. X    "batch", 0, 0, 'b'
  1664. X    },
  1665. X    {
  1666. X    "no-dump", 0, 0, 'd'
  1667. X    },
  1668. X    {
  1669. X    "number-of-dumps", 1, 0, 'f'
  1670. X    },
  1671. X    {
  1672. X    "gnuplot-data-format", 0, 0, 'g'
  1673. X    },
  1674. X    {
  1675. X    "help", 0, 0, 'h'
  1676. X    },
  1677. X    {
  1678. X    "idl-data-format", 0, 0, 'i'
  1679. X    },
  1680. X    {
  1681. X    "moore-neighbourhood", 0, 0, 'm'
  1682. X    },
  1683. X    {
  1684. X    "no-film", 0, 0, 'n'
  1685. X    },
  1686. X    {
  1687. X    "on-line-visualization", 0, 0, 'o'
  1688. X    },
  1689. X    {
  1690. X    "seed-for-random", 1, 0, 's'
  1691. X    },
  1692. X    {
  1693. X    "torus", 0, 0, 't'
  1694. X    },
  1695. X    {
  1696. X    "version", 0, 0, 'v'
  1697. X    },
  1698. X    {
  1699. X    "warranty", 0, 0, 'w'
  1700. X    },
  1701. X    {
  1702. X    "start-of-dump", 1, 0, 'x'
  1703. X    },
  1704. X    {
  1705. X    "skip-between-dumps", 1, 0, 'y'
  1706. X    },
  1707. X    {
  1708. X    0, 0, 0, 0
  1709. X    }
  1710. };
  1711. X
  1712. main (argc, argv)
  1713. X    int argc;
  1714. X    char **argv;
  1715. {
  1716. X    int c, index;
  1717. X
  1718. X   /* whoami? */
  1719. X    program_name = *argv;
  1720. X
  1721. X   /* parse args */
  1722. X    while ((c = getopt_long (argc, argv, "A:C:D:F:G:J:K:M:N:P:S:T:X:Y:bdghimnos:tvwx:y:", opts, &index)) != EOF) {
  1723. X
  1724. X       /* long option? */
  1725. X    if (c == 0) {
  1726. X        c = opts[index].val;
  1727. X    }
  1728. X
  1729. X       /* setup program parameters */
  1730. X    switch (c) {
  1731. X
  1732. X        /* set animation data name format */
  1733. X     case 'A':
  1734. X         afilename = optarg;
  1735. X         break;
  1736. X
  1737. X        /* set color map file name */
  1738. X     case 'C':
  1739. X         cfilename = optarg;
  1740. X         break;
  1741. X
  1742. X        /* set dump data file name format */
  1743. X     case 'D':
  1744. X         dfilename = optarg;
  1745. X         break;
  1746. X
  1747. X        /* set number of frames included in the film */
  1748. X     case 'F':
  1749. X         nframes = atoi (optarg);
  1750. X         break;
  1751. X
  1752. X        /* set groth rate of INFECTion */
  1753. X     case 'G':
  1754. X         g = atoi (optarg);
  1755. X         break;
  1756. X
  1757. X        /* set ILL cells denominator */
  1758. X     case 'J':
  1759. X         k1 = atoi (optarg);
  1760. X         break;
  1761. X
  1762. X        /* set INFECTED cells denominator */
  1763. X     case 'K':
  1764. X         k2 = atoi (optarg);
  1765. X         break;
  1766. X
  1767. X        /* set monitor process for online visualization */
  1768. X     case 'M':
  1769. X         mfilename = optarg;
  1770. X         moni = TRUE;
  1771. X         break;
  1772. X
  1773. X        /* set number of states from SANE to ILL */
  1774. X     case 'N':
  1775. X         n = atoi (optarg);
  1776. X         break;
  1777. X
  1778. X        /* set plot file name format */
  1779. X     case 'P':
  1780. X         pfilename = optarg;
  1781. X         break;
  1782. X
  1783. X        /* set size of grid */
  1784. X     case 'S':
  1785. X         ncells = atoi (optarg);
  1786. X         break;
  1787. X
  1788. X        /* set time steps to compute */
  1789. X     case 'T':
  1790. X         nticks = atoi (optarg);
  1791. X         break;
  1792. X
  1793. X        /* when shall the film begin? */
  1794. X     case 'X':
  1795. X         startoffilm = atoi (optarg);
  1796. X         break;
  1797. X
  1798. X        /* how many time steps to skip for next frame? */
  1799. X     case 'Y':
  1800. X         skipbetweentakes = atoi (optarg);
  1801. X         break;
  1802. X
  1803. X        /* set mode to batch */
  1804. X     case 'b':
  1805. X         batch = TRUE;
  1806. X         break;
  1807. X
  1808. X        /* turn off data logging */
  1809. X     case 'd':
  1810. X         dump = FALSE;
  1811. X         break;
  1812. X
  1813. X        /* set number of dumps */
  1814. X     case 'f':
  1815. X         ndumps = atoi (optarg);
  1816. X         break;
  1817. X
  1818. X        /* set data logging attribute to Gnuplot */
  1819. X     case 'g':
  1820. X         gnuplot = TRUE;
  1821. X         idl = FALSE;
  1822. X         break;
  1823. X
  1824. X        /* print help info */
  1825. X     case 'h':
  1826. X         usage (0);
  1827. X         break;
  1828. X
  1829. X        /* set data logging attribute to IDL(TM) */
  1830. X     case 'i':
  1831. X         idl = TRUE;
  1832. X         gnuplot = FALSE;
  1833. X         break;
  1834. X
  1835. X        /* set computation attribute */
  1836. X     case 'm':
  1837. X         moore = TRUE;
  1838. X         break;
  1839. X
  1840. X        /* generate a film? */
  1841. X     case 'n':
  1842. X         film = FALSE;
  1843. X         break;
  1844. X
  1845. X        /* generate an online-visualization? */
  1846. X     case 'o':
  1847. X         moni = TRUE;
  1848. X         break;
  1849. X
  1850. X        /* set seed for random number generator */
  1851. X     case 's':
  1852. X         random_seed = atoi (optarg);
  1853. X         break;
  1854. X
  1855. X        /* set grid attribute */
  1856. X     case 't':
  1857. X         torus = TRUE;
  1858. X         break;
  1859. X
  1860. X        /* print version info */
  1861. X     case 'v':
  1862. X         version (0);
  1863. X         break;
  1864. X
  1865. X        /* print version info */
  1866. X     case 'w':
  1867. X         warranty (0);
  1868. X         break;
  1869. X
  1870. X        /* when shall the dump begin? */
  1871. X     case 'x':
  1872. X         startofdump = atoi (optarg);
  1873. X         break;
  1874. X
  1875. X        /* how many time steps to skip for next dump? */
  1876. X     case 'y':
  1877. X         skipbetweendumps = atoi (optarg);
  1878. X         break;
  1879. X
  1880. X        /* print usage info */
  1881. X     default:
  1882. X         usage (1);
  1883. X    }
  1884. X    }
  1885. X
  1886. X   /* open output(s) */
  1887. X    if ((rep = fopen (pfilename, "w")) == NULL)
  1888. X    panic (E_FATAL, "hodge", "can't open file %s", pfilename);
  1889. X
  1890. X    if (moni)
  1891. X    if ((mon = popen (mfilename, "w")) == NULL)
  1892. X        panic (E_FATAL, "hodge", "can't open pipe %s", mfilename);
  1893. X
  1894. X   /* open color map, etc. */
  1895. X    if (film) {
  1896. X    loadcmap (cfilename);
  1897. X        framestotake = nframes;
  1898. X    }
  1899. X
  1900. X   /* init dumping, etc. */
  1901. X    if (dump) {
  1902. X        dumpstomake = ndumps;
  1903. X    }
  1904. X
  1905. X   /* hodge-podge */
  1906. X    hodge (rep);
  1907. X
  1908. X   /* clean-up*/
  1909. X    fclose (rep);
  1910. X    fclose (mon);
  1911. X
  1912. X    return 0;
  1913. }
  1914. X
  1915. /*
  1916. X *    usage -- print usage information
  1917. X */
  1918. void
  1919. usage (code)
  1920. X    int code;
  1921. {
  1922. X    fprintf (stderr, "usage: %s [options]\n\
  1923. X    [-A, --animation-file-name <name>]\n\
  1924. X    [-C, --color-map-file-name <name>]\n\
  1925. X    [-D, --dump-data-file-name <name>]\n\
  1926. X    [-F, --number-of-frames <number>]\n\
  1927. X    [-G, --groth-rate <number>]\n\
  1928. X    [-J, --ill-cells-denominator <number>]\n\
  1929. X    [-K, --infected-cells-denominator <number>]\n\
  1930. X    [-M, --monitor-process <process>]\n\
  1931. X    [-N, --number-of-cell-states <number>]\n\
  1932. X    [-P, --plot-file-name <name>]\n\
  1933. X    [-S, --size-of-grid <size>]\n\
  1934. X    [-T, --time-steps <number>]\n\
  1935. X    [-X, --start-of-film <time step>]\n\
  1936. X    [-Y, --skip-between-takes <number>]\n\
  1937. X    [-b, --batch]\n\
  1938. X    [-d, --no-dump]\n\
  1939. X    [-f, --number-of-dumps <number>]\n\
  1940. X    [-g, --gnuplot-data-format]\n\
  1941. X    [-h, --help]\n\
  1942. X    [-i, --idl-data-format]\n\
  1943. X    [-m, --moore-neighbourhood]\n\
  1944. X    [-n, --no-film]\n\
  1945. X    [-o, --on-line-visualization]\n\
  1946. X    [-s, --seed-for-random <seed value>]\n\
  1947. X    [-t, --torus]\n\
  1948. X    [-v, --version]\n\
  1949. X    [-w, --warranty]\n\
  1950. X    [-x, --start-of-dump <timestep>]\n\
  1951. X    [-y, --skip-between-dumps <number>]\n\
  1952. X    \n", program_name);
  1953. X
  1954. X    exit (code);
  1955. }
  1956. X
  1957. /*
  1958. X *    version -- print version information
  1959. X */
  1960. void
  1961. version (code)
  1962. X    int code;
  1963. {
  1964. X    fprintf (stderr, "This is %s %s version %d.%d%c (%003d)\n",
  1965. X         V_NAME, V_OSTYPE, V_MAJOR, V_MINOR, V_MAGIC, V_MODF);
  1966. X
  1967. X    fprintf (stderr, "Copyright (C) 1993 by Joerg Heitkoetter.");
  1968. X    fprintf (stderr, "Type `%s -w' for WARRANTY.\n", program_name);
  1969. X
  1970. #ifndef LOCAL_MAINTAINER
  1971. X    fprintf (stderr, "Send bugs, comments, etc., to %s.\n", V_EMAIL);
  1972. #else
  1973. X    fprintf (stderr, "Last modification by %s, on %s\n", V_MAINTAINER, V_DATE);
  1974. X    fprintf (stderr, "Send bugs, comments, etc., to %s.\n", V_EMAIL);
  1975. #endif
  1976. X
  1977. X    exit (code);
  1978. }
  1979. X
  1980. /*
  1981. X *    warranty -- print warranty information
  1982. X */
  1983. void
  1984. warranty (code)
  1985. X    int code;
  1986. {
  1987. X    fprintf (stderr, "\
  1988. X    HODGE-C  --  Copyright (C) 1993 by Joerg Heitkoetter\n\
  1989. \n\
  1990. X    Gerhard & Schuster's Hodge-Podge machine in C\n\
  1991. X    See also Computer Recreations in Scientific American, October 1988.\n\
  1992. \n\
  1993. X    This program is free software; you can redistribute it and/or modify\n\
  1994. X    it under the terms of the GNU General Public License as published by\n\
  1995. X    the Free Software Foundation; either version 2 of the License, or\n\
  1996. X    (at your option) any later version.\n\
  1997. \n\
  1998. X    This program is distributed in the hope that it will be useful,\n\
  1999. X    but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
  2000. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n\
  2001. X    GNU General Public License for more details.\n\
  2002. \n\
  2003. X    You should have received a copy of the GNU General Public License\n\
  2004. X    along with this program; if not, write to the Free Software\n\
  2005. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n");
  2006. X
  2007. X    exit (code);
  2008. }
  2009. X
  2010. /*
  2011. X *    hodge -- main loop
  2012. X */
  2013. void
  2014. hodge (rep)
  2015. X    FILE *rep;
  2016. {
  2017. X    int A, B, S;
  2018. X    int i, j;
  2019. X    int t = 0;
  2020. X    int nval;                /* range: [0..8*n + n] */
  2021. X
  2022. X    initialize (random_seed);
  2023. X
  2024. X    while (t++ < nticks) {
  2025. X    nsane = ninfected = nill = 0;
  2026. X
  2027. X    for (i = 0; i < ncells; i++)
  2028. X        for (j = 0; j < ncells; j++) {
  2029. X        A = scount (i, j, ILL);
  2030. X        B = scount (i, j, INFECTED);
  2031. X        S = vsum (i, j) + cell[i][j].value;
  2032. X
  2033. X        switch (cell[i][j].state) {
  2034. X         case SANE:
  2035. X             nsane++;
  2036. X             nval = (cell_v) (A / k1 + B / k2);
  2037. X             break;
  2038. X
  2039. X         case INFECTED:
  2040. X             ninfected++;
  2041. X             B++;        /* add self to INFECTED */
  2042. X             nval = (cell_v) (S / B + g);
  2043. X             break;
  2044. X
  2045. X         case ILL:
  2046. X             nill++;
  2047. X             nval = V_SANE;
  2048. X             break;
  2049. X        }
  2050. X
  2051. X           /* set state & value */
  2052. X        ncell[i][j].state = get_state (&nval);
  2053. X        ncell[i][j].value = (cell_v) nval;
  2054. X        }
  2055. X
  2056. X       /* report statistics, etc. */
  2057. X    report (rep, t);
  2058. X
  2059. X       /* write animation data, etc. */
  2060. X    if (film && t >= startoffilm && framestotake > 0)
  2061. X        grid2ppm (t, cell);
  2062. X
  2063. X       /* dumping data file, etc. */
  2064. X    if (dump && t >= startofdump && dumpstomake > 0)
  2065. X        grid2dump (t, cell);
  2066. X
  2067. X       /* online visualization, etc. */
  2068. X    if (moni)
  2069. X        pixmon (cell);
  2070. X
  2071. X       /* copy new cells to old */
  2072. X    memcpy (cell, ncell, sizeof (grid_t));
  2073. X    }
  2074. }
  2075. X
  2076. /*
  2077. X *    initialize -- init the global data structures
  2078. X */
  2079. void
  2080. initialize (seed)
  2081. X    int seed;
  2082. {
  2083. X    int i, j;
  2084. X
  2085. X    srand (seed);
  2086. X
  2087. X    for (i = 0; i < ncells; i++)
  2088. X    for (j = 0; j < ncells; j++) {
  2089. X        cell[i][j].state = (cell_s) (random () % MAXSTATES);
  2090. X
  2091. X        if (cell[i][j].state == SANE)
  2092. X        cell[i][j].value = V_SANE;
  2093. X        else if (cell[i][j].state == INFECTED)
  2094. X        cell[i][j].value = (cell_v) (rand () % (n - 1) + 1);
  2095. X        else
  2096. X        cell[i][j].value = V_ILL;
  2097. X
  2098. X        ncell[i][j].state = SANE;
  2099. X        ncell[i][j].value = V_SANE;
  2100. X    }
  2101. }
  2102. X
  2103. /*
  2104. X *    get_state -- compute the state from a cell's value
  2105. X */
  2106. cell_s
  2107. get_state (val)
  2108. X    int *val;
  2109. {
  2110. X    if (*val <= V_SANE) {
  2111. X    *val = V_SANE;
  2112. X    return (SANE);
  2113. X    } else {
  2114. X    if (*val >= V_ILL) {
  2115. X        *val = V_ILL;
  2116. X        return (ILL);
  2117. X    } else {
  2118. X        return (INFECTED);
  2119. X    }
  2120. X    }
  2121. }
  2122. X
  2123. /*
  2124. X *    report -- report statistics
  2125. X */
  2126. void
  2127. report (rep, t)
  2128. X    FILE *rep;
  2129. X    int t;
  2130. {
  2131. X    fprintf (rep, "%d\t%d\t%d\t%d\t%lf\n",
  2132. X         t, nsane, ninfected, nill, (double) ninfected / (double) (ncells * ncells));
  2133. }
  2134. X
  2135. /*
  2136. X *    map -- map index to grid structure
  2137. X */
  2138. int
  2139. map (i)
  2140. X    int i;
  2141. {
  2142. X    if (!torus) {
  2143. X    if (i < 0)
  2144. X        return (0);
  2145. X    else if (i == ncells)
  2146. X        return (ncells - 1);
  2147. X    else
  2148. X        return (i);
  2149. X    } else {
  2150. X    if (i < 0)
  2151. X        return (ncells - 1);
  2152. X    else if (i == ncells)
  2153. X        return (0);
  2154. X    else
  2155. X        return (i);
  2156. X    }
  2157. }
  2158. X
  2159. /*
  2160. X *    scount -- count cells in specified state
  2161. X */
  2162. int
  2163. scount (i, j, state)
  2164. X    int i, j;
  2165. X    cell_s state;
  2166. {
  2167. X    int count = 0;
  2168. X
  2169. X   /* always count von-Neumann cells */
  2170. X    if (cell[map (i - 1)][j].state == state)
  2171. X    ++count;
  2172. X    if (cell[i][map (j - 1)].state == state)
  2173. X    ++count;
  2174. X    if (cell[i][map (j + 1)].state == state)
  2175. X    ++count;
  2176. X    if (cell[map (i + 1)][j].state == state)
  2177. X    ++count;
  2178. X
  2179. X   /* sometimes count Moore cells */
  2180. X    if (moore) {
  2181. X    if (cell[map (i - 1)][map (j - 1)].state == state)
  2182. X        ++count;
  2183. X    if (cell[map (i + 1)][map (j - 1)].state == state)
  2184. X        ++count;
  2185. X    if (cell[map (i - 1)][map (j + 1)].state == state)
  2186. X        ++count;
  2187. X    if (cell[map (i + 1)][map (j + 1)].state == state)
  2188. X        ++count;
  2189. X    }
  2190. X    return (count);
  2191. }
  2192. X
  2193. /*
  2194. X *    vsum -- sum up all neighbour cells' values
  2195. X */
  2196. int
  2197. vsum (i, j)
  2198. X    int i, j;
  2199. {
  2200. X    int sum = 0;
  2201. X
  2202. X   /* always sum von-Neumann cells */
  2203. X    sum = cell[map (i - 1)][j].value
  2204. X    + cell[i][map (j - 1)].value
  2205. X    + cell[i][map (j + 1)].value
  2206. X    + cell[map (i + 1)][j].value;
  2207. X
  2208. X   /* sometimes sum Moore cells */
  2209. X    if (moore) {
  2210. X    sum += cell[map (i - 1)][map (j - 1)].value
  2211. X         + cell[map (i + 1)][map (j - 1)].value
  2212. X         + cell[map (i - 1)][map (j + 1)].value
  2213. X         + cell[map (i + 1)][map (j + 1)].value;
  2214. X    }
  2215. X    return (sum);
  2216. }
  2217. X
  2218. /*
  2219. X *    rgb_color -- turn value into an RGB string
  2220. X */
  2221. color_t *
  2222. rgb_color (val)
  2223. X    int val;
  2224. {
  2225. X    color_t rgb;
  2226. X
  2227. X    rgb[0] = cmap[val].red;
  2228. X    rgb[1] = cmap[val].green;
  2229. X    rgb[2] = cmap[val].blue;
  2230. X
  2231. X    return ((color_t *) rgb);
  2232. }
  2233. X
  2234. /*
  2235. X *    grid2ppm -- write out the grid converted to a color portable pixmap
  2236. X */
  2237. void
  2238. grid2ppm (t, grid)
  2239. X    int t;
  2240. X    grid_t grid;
  2241. {
  2242. X    FILE *fp;
  2243. X    int i, j;
  2244. X    static fcount = 0;
  2245. X    char s[MAXFILELEN];
  2246. X
  2247. X    if ((t - startoffilm) % skipbetweentakes == 0) {
  2248. X
  2249. X       /* generate the frame's file name */
  2250. X    sprintf (s, afilename, fcount++);
  2251. X    if ((fp = fopen (s, "w")) == NULL)
  2252. X        panic (E_FATAL, "grid2ppm", "can't open file %s", s);
  2253. X
  2254. X       /* write raw ppm(5) header */
  2255. X    fprintf (fp, "P6\n");
  2256. X    fprintf (fp, "# File:    %s\n", s);
  2257. X    fprintf (fp, "# Creator: %s %s version %d.%d%c (%003d) (C) 1993 by Joerg Heitkoetter\n",
  2258. X         V_NAME, V_OSTYPE, V_MAJOR, V_MINOR, V_MAGIC, V_MODF);
  2259. X    fprintf (fp, "%d %d\n", ncells, ncells);
  2260. X    fprintf (fp, "%d\n", n);
  2261. X
  2262. X       /* turn bitimage into RGB colors */
  2263. X    for (i = 0; i < ncells; i++)
  2264. X        for (j = 0; j < ncells; j++)
  2265. X        fwrite (rgb_color (cell[i][j].value), sizeof (color_t), 1, fp);
  2266. X
  2267. X       /* clean up */
  2268. X    fclose (fp);
  2269. X
  2270. X       /* give some feedback */
  2271. X    if (!batch)
  2272. X        fprintf (stderr, "%s: successfully wrote (%dx%d) file `%s' (%d colors)\n",
  2273. X             program_name, ncells, ncells, s, n+1);
  2274. X
  2275. X       /* adjust frame counter */
  2276. X    --framestotake;
  2277. X    }
  2278. }
  2279. X
  2280. /*
  2281. X *    grid2dump -- write out the grid converted to an IDL(TM) 3D/Gnuplot 3D data file
  2282. X */
  2283. void
  2284. grid2dump (t, grid)
  2285. X    int t;
  2286. X    grid_t grid;
  2287. {
  2288. X    FILE *fp;
  2289. X    int i, j;
  2290. X    char s[MAXFILELEN];
  2291. X
  2292. X    if ((t - startofdump) % skipbetweendumps == 0) {
  2293. X
  2294. X       /* generate the frame's file name */
  2295. X    sprintf (s, dfilename, t);
  2296. X    if ((fp = fopen (s, "w")) == NULL)
  2297. X        panic (E_FATAL, "grid2dump", "can't open file %s", s);
  2298. X
  2299. X       /* write dump header */
  2300. X    fprintf (fp, "# File:    %s\n", s);
  2301. X    fprintf (fp, "# Creator: %s %s version %d.%d%c (%003d) (C) 1993 by Joerg Heitkoetter\n",
  2302. X         V_NAME, V_OSTYPE, V_MAJOR, V_MINOR, V_MAGIC, V_MODF);
  2303. X    fprintf (fp, "# Grid:    %dx%d\n", ncells, ncells);
  2304. X    fprintf (fp, "# Colors:  %d\n", n);
  2305. X
  2306. X    if (idl) {
  2307. X       /* write X axis */
  2308. X        for (i = 0; i < ncells; i++)
  2309. X        fprintf (fp, "%d\n", i+1);
  2310. X
  2311. X       /* write Y axis */
  2312. X        for (i = 0; i < ncells; i++)
  2313. X        fprintf (fp, "%d\n", i+1);
  2314. X
  2315. X       /* write Z axis */
  2316. X        for (i = 0; i < ncells; i++)
  2317. X        for (j = 0; j < ncells; j++)
  2318. X            fprintf (fp, "%d\n", cell[i][j].value);
  2319. X    }
  2320. X
  2321. X    if (gnuplot) {
  2322. X       /* write X, Y, Z axis */
  2323. X        for (i = 0; i < ncells; i++) {
  2324. X        for (j = 0; j < ncells; j++)
  2325. X            fprintf (fp, "%d\t%d\t%d\n", i+1, j+1, cell[i][j].value);
  2326. X        fprintf (fp, "\n");
  2327. X        }
  2328. X    }
  2329. X       /* clean up */
  2330. X    fclose (fp);
  2331. X
  2332. X       /* give some feedback */
  2333. X    if (!batch)
  2334. X        fprintf (stderr, "%s: successfully wrote (%dx%d) dump file `%s' (%d colors)\n",
  2335. X             program_name, ncells, ncells, s, n+1);
  2336. X
  2337. X       /* adjust dump counter */
  2338. X    --dumpstomake;
  2339. X    }
  2340. }
  2341. X
  2342. /*
  2343. X *    loadcmap -- load a color map
  2344. X */
  2345. void
  2346. loadcmap (s)
  2347. X    char *s;
  2348. {
  2349. X    FILE *fp;
  2350. X    char line[MAXLINELEN];
  2351. X    int i, r, g, b;
  2352. X
  2353. X    if ((fp = fopen (s, "r")) == NULL)
  2354. X    panic (E_FATAL, "loadcmap", "can't load color map `%s'", s);
  2355. X
  2356. X    for (i = 0; i < MAXCOLORS; i++) {
  2357. X    if (fgets (line, MAXLINELEN, fp) == NULL)
  2358. X        panic (E_FATAL, "loadcmap", "not enough colors in color map file `%s'", s);
  2359. X
  2360. X    /* comment line? */
  2361. X    if (*line == COMMENTCHAR)
  2362. X        continue;
  2363. X
  2364. X    sscanf (line, " %d %d %d", &r, &g, &b);
  2365. X    cmap[i].red = r & 0xff;
  2366. X    cmap[i].green = g & 0xff;
  2367. X    cmap[i].blue = b & 0xff;
  2368. X    }
  2369. X    if (!batch)
  2370. X    fprintf (stderr, "%s: successfully read in color map `%s'\n",
  2371. X         program_name, cfilename);
  2372. }
  2373. X
  2374. /*
  2375. X *    pixmon -- online visualization using pixmon(1)
  2376. X */
  2377. void
  2378. pixmon (grid)
  2379. X    grid_t grid;
  2380. {
  2381. X    ImgHdr head;
  2382. X    int i, j, bytes;
  2383. X
  2384. X    INIT_IMGHDR (head);
  2385. X
  2386. X    head.dx = ncells;
  2387. X    head.dy = ncells;
  2388. X    head.sizelo = PIX_LO (ncells * ncells);
  2389. X    head.sizehi = PIX_HI (ncells * ncells);
  2390. X
  2391. X    if ((bytes = fwrite (head, 1, sizeof (ImgHdr), mon)) != sizeof (ImgHdr))
  2392. X    panic (E_FATAL, "pixmon", "failed to write header (%d out of %d)", bytes, sizeof (ImgHdr));
  2393. X
  2394. X    for (i = 0; i < ncells; i++)
  2395. X    for (j = 0; j < ncells; j++)
  2396. X        if ((bytes = fwrite (&grid[i][j].value, sizeof (cell_v), 1, mon)) != 1)
  2397. X            panic (E_FATAL, "pixmon", "failed to write grid point (%d, %d)", i, j);
  2398. X
  2399. X    EXIT_IMGHDR (head);
  2400. X    if ((bytes = fwrite (head, 1, sizeof (ImgHdr), mon)) != sizeof (ImgHdr))
  2401. X    panic (E_FATAL, "pixmon", "failed to write kill package (%d out of %d)", bytes, sizeof (ImgHdr));
  2402. }
  2403. SHAR_EOF
  2404. chmod 0640 hodge-c-0.98j/hodge.c ||
  2405. echo 'restore of hodge-c-0.98j/hodge.c failed'
  2406. Wc_c="`wc -c < 'hodge-c-0.98j/hodge.c'`"
  2407. test 19168 -eq "$Wc_c" ||
  2408.     echo 'hodge-c-0.98j/hodge.c: original size 19168, current size' "$Wc_c"
  2409. rm -f _shar_wnt_.tmp
  2410. fi
  2411. # ============= hodge-c-0.98j/hodge.h ==============
  2412. if test -f 'hodge-c-0.98j/hodge.h' -a X"$1" != X"-c"; then
  2413.     echo 'x - skipping hodge-c-0.98j/hodge.h (File already exists)'
  2414.     rm -f _shar_wnt_.tmp
  2415. else
  2416. > _shar_wnt_.tmp
  2417. echo 'x - extracting hodge-c-0.98j/hodge.h (Text)'
  2418. sed 's/^X//' << 'SHAR_EOF' > 'hodge-c-0.98j/hodge.h' &&
  2419. X
  2420. /* HODGE-C -- A C implementation of Gerhard & Schuster's hodge-podge machine */
  2421. X
  2422. /* hodge.h -- program rountine interfaces
  2423. X
  2424. X   Copyright (C) 1993 Joerg Heitkoetter
  2425. X
  2426. X   This program is free software; you can redistribute it and/or modify
  2427. X   it under the terms of the GNU General Public License as published by
  2428. X   the Free Software Foundation; either version 2, or (at your option)
  2429. X   any later version.
  2430. X
  2431. X   This program is distributed in the hope that it will be useful,
  2432. X   but WITHOUT ANY WARRANTY; without even the implied warranty of
  2433. X   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  2434. X   GNU General Public License for more details.
  2435. X
  2436. X   You should have received a copy of the GNU General Public License
  2437. X   along with this program; if not, write to the Free Software
  2438. X   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  2439. X
  2440. /* $Id: hodge.h,v 1.2 1993/03/19 11:28:30 heitkoet Exp heitkoet $ */
  2441. X
  2442. #ifndef __HODGE_H__
  2443. #define __HODGE_H__
  2444. X
  2445. #define MAXCELLS    500
  2446. #define MAXCOLORS    256
  2447. #define MAXTICKS    10000
  2448. #define MAXSTATES    3
  2449. #define MAXFILELEN    256
  2450. #define MAXLINELEN    1024
  2451. X
  2452. #define S_SANE        0
  2453. #define S_INFECTED    1
  2454. #define S_ILL        2
  2455. X
  2456. #define V_SANE        0
  2457. #define V_ILL        n
  2458. X
  2459. #define bool        int
  2460. #define TRUE        1
  2461. #define FALSE        0
  2462. X
  2463. #define COMMENTCHAR    '#'
  2464. X
  2465. X
  2466. typedef enum {
  2467. X      SANE = S_SANE, INFECTED = S_INFECTED, ILL = S_ILL
  2468. SHAR_EOF
  2469. true || echo 'restore of hodge-c-0.98j/hodge.h failed'
  2470. fi
  2471. echo 'End of  part 3'
  2472. echo 'File hodge-c-0.98j/hodge.h is continued in part 4'
  2473. echo 4 > _shar_seq_.tmp
  2474. exit 0
  2475. exit 0 # Just in case...
  2476.