[comp.sources.misc] v18i001: planet - planet generation simulator, Part01/04

allen@viewlogic.com (Dave Allen) (04/08/91)

Submitted-by: Dave Allen <allen@viewlogic.com>
Posting-number: Volume 18, Issue 1
Archive-name: planet/part01
Supersedes: tec: Volume 10, Issue 77-78

This is version 1 of a scientific planet generator (as opposed to a
die-rolling planet generator).  It is written in C and runs in graphics
mode under Xwindows, or in text-only mode under UN*X.  There are three
programs: 

   - tec: a continental drift simulator
   - clim: a climate generator
   - globe: computes and displays a rotating planet

Dave
----
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 4)."
# Contents:  README doc/about.tec doc/readme.tec doc/params.tec
#   doc/readme.globe doc/readme.clim doc/params.clim example/clim.out
# Wrapped by allen@baja on Sat Mar 23 16:18:36 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f README -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"README\"
else
echo shar: Extracting \"README\" \(849 characters\)
sed "s/^X//" >README <<'END_OF_README'
XThis is version 1 of a scientific planet generator (as opposed to a
Xdie-rolling planet generator).  It is written in C and runs in graphics
Xmode under Xwindows, or in text-only mode under UN*X.  There are three
Xprograms: 
X
X   - tec: a continental drift simulator
X   - clim: a climate generator
X   - globe: computes and displays a rotating planet
X
XCopyright (c) 1991 by David Allen.  You may distribute this freely as long
Xas you leave my name and copyright notice intact.
X
XI'd really like your comments and feedback; send e-mail to
Xallen@viewlogic.com, or send us-mail to David Allen, 10 O'Moore Ave,
XMaynard, MA 01754.
X
XThere are three subdirectories:
X
X   - src: contains all source and a UN*X Makefile
X   - example: contains some sample input and output files
X   - doc: contains details about how to use the programs and how they work.
X
XHave fun!
END_OF_README
if test 849 -ne `wc -c <README`; then
    echo shar: \"README\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f doc/about.tec -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"doc/about.tec\"
else
echo shar: Extracting \"doc/about.tec\" \(10300 characters\)
sed "s/^X//" >doc/about.tec <<'END_OF_doc/about.tec'
XI.  MOTIVATION AND APPROACH
X
XI wanted to write a program to generate maps of many imaginary worlds using
Xa microcomputer.  Fractal techniques produce unacceptably random-looking maps.
XIn other related fields, people have used simplified models of physical
Xprocesses and then tweaked the model parameters to give results that "looked
Xright".  Dole [1] simulated accretion of planets around stars.  Hart [2]
Xsimulated the evolution of a planetary atmosphere.  Forrester [3] simulated
Xpopulation dynamics for near-future Earth.  My approach was to find a physical
Xmodel for continent formation, and then write a program to implement that model.
X
XGeologists have proposed [4] that several times in history, the continents
Xof Earth have drifted together to form a single "supercontinent", which later
Xbroke apart.  A recent paper [5] suggested a physical model for this
X"supercontinent cycle", and I used that model for my program.
X
XTheir hypothesis runs like this.  (Disclaimer - I don't know anything about
Xgeology except what I got from reading a few papers.)  The Earth generates
Xheat by radioactive decay; this heat is conducted away more slowly by
Xcontinental crust than by oceanic crust.  Heat accumulates under large
Xcontinents, causing them to dome upwards and eventually break apart.  After
Xa certain amount of heat has escaped through the new ocean basin, the
Xcontinental fragments are drawn back together by the subsiding basin.
XOver long periods of time, many oceans should open and close in the center
Xof the land area, while the original superocean should remain about the same.
X
XAny map of the Earth shows evidence to support this hypothesis.  The Atlantic
Xand Mediterranean oceans are fairly recent, while the Pacific could be
Xconsidered the superocean.  The Himalayas, the Pyrenees, and the Ukraine
Xmountain ranges could have been formed by collisions between continental
Xfragments.  The "Ring of Fire" around the Pacific represents subduction zones
Xwhere new mountains, such as the Rockies, are forming as the continents drift
Xfurther apart.  The older, lower Appalachian mountains might have been created
Xduring a collision between Europe and North America in the last supercontinent
Xcycle.
X
X
XII.  REPRESENTATION
X
XOne data structure well-suited for storing topographic maps is a simple
Xtwo-dimensional array, where each array element represents the height
Xof the terrain at that point.  However, the Earth is spherical and a sphere
Xcan't be mapped onto a plane without some distortion.  After trying many
Xmapping methods, I came back to the simplest:  I pretend Columbus was wrong,
Xand the world really is flat.  Since the continents in the physical model
Xdrift toward and away from some central point, it is reasonable, if the map
Xis large enough, to simply throw away the land area that falls off the
Xedge of the map.  I used a simple square, flat surface with no "wraparound."
X
XI could, and probably will at some point, write a couple of paragraphs about
Xwhy doing plate movement on a sphere is so hard.  All of the methods I
Xtried required too much data storage for each point, or too much real
Xnumber computation, or resulted in unacceptable distortion.  The criterion
XI used was to place a small continent, say a 5 x 5 square, anywhere on
Xthe surface.  It should be able to travel one great circle in any direction
Xand remain undisturbed though the entire journey.  The method should not
Xrequire _any_ floating point computation once the initial velocity is
Xcomputed since I want to do many iterations on a microcomputer.
X
XA second representation issue is how to cause plates to drift apart and
Xback together.  Maintaining the detailed structure of the ocean basin is
Xcomplicated; consider a circular landmass which splits along a diameter.
XThe ocean basin structure here is clear, since the rift remains in place and
Xthe new basin extends out from it in both directions.  Now suppose one of
Xthe semicircular fragments splits in half perpendicular to the first split.
XThe motion of the landmasses can be computed easily, but the new rift must
Xdrift as well and the required motions in the basin seem self-contradictory.
X
XI chose to ignore the ocean basin and concentrate on the landmasses.  Thus,
Xrifts are not recorded in any way and the ocean floor does not move.  Since
Xthe basins are not simulated, some mechanism is needed to replace the physical
Xmechanism of the sinking basin sucking the landmasses back together.  This
Xis done by a velocity scaling profile which is coded directly into the
Xmovement routine.  The profile says that after a short time, forward motion
Xof a landmass slows and then stops; after this point the landmass begins to
Xmove backwards towards its origin.
X
X
XIII. ALGORITHM
X
XThe initial supercontinent is generated by a simple fractal algorithm; a
Xfractal mountain is created by superimposing four two-dimensional fractal
Xlines.  The mountain is then turned into a binary blob, that is, everything
Xabove a certain altitude is declared to be land, and everything else becomes
Xwater.  The blob is then "improved" by removing islands and internal oceans.
XThis technique produces very irregular circular blobs of varying sizes.
X
XThe program then repeats a sequence of operations for each timestep.  First,
Xa rift may be generated, splitting some continent into pieces; new velocities
Xare generated for the new landmasses.  Second, the distance each landmass will
Xmove this timestep is determined by applying the velocity profile described
Xabove to the landmass velocity.  Third, the landmasses are moved and mountains
Xare built.  Fourth, where the movement routine has caused landmasses to
Xoverlap, new velocities are computed for the overlapping landmasses, and they
Xmay be merged into a single landmass if they overlap sufficiently.  Fifth, the
Xentire topography is eroded; if a square is higher than the square next to
Xit, the altitudes are made more equal.  Finally, the screen is redrawn.
X
XIn step one, random coordinates are generated until a location is found
Xwhich is at least five squares from any ocean.  This location will be the
Xcenter of a rift, which is represented as a randomly curving line.  The
Xdistance requirement is there to ensure that if a rift occurs, it occurs
Xon a fairly large continent where internal heat would accumulate.  When
Xthe rift is drawn, it is allowed to bend randomly but is drawn using
Xconventional digital line-drawing techniques (i.e. Bresenham's algorithm).
XThe rift drawing routine terminates when the rift hits ocean.  If the growing
Xrift hits another landmass, which could occur if two landmasses were touching
Xbut had not yet merged, the rift is aborted since the result would be a very
Xunnatural looking U-shaped continent.
X
XOnce the rift is created, a segmentation algorithm determines how
Xmany new landmasses were formed.  There should only be two new landmasses,
Xbut splinters can be formed if the rift runs along a narrow peninsula or
Xtoo close to a coast.  The algorithm detects and erases such splinters.
XThe landmasses are given an initial velocity which makes them drift directly
Xaway from the rift.  The velocities are inversely dependent on the area
Xof the landmass so that smaller masses move faster.  After the initial
Xvelocities have been determined, the rift is erased.
X
XThe second and third steps are concerned with moving the landmasses.  This
Xis done with a slightly simpler version of Bresenham's algorithm.  The velocity
Xprofile described in Section II is applied so that landmasses will drift
Xapart at first, but will then slow down and come back together.  Because a
Xlandmass can split up again, the process does not simply reassemble the
Xoriginal supercontinent when they drift back together.
X
XMountains are built under two conditions: where two landmasses collide, and
Xwhere landmass subsumes ocean basin.  Both conditions are detected and resolved
Xin the movement routine.  Movement is performed from a source array to a
Xdestination array.  A loop steps over every square in the source array.  If
Xthere is land in a square, its new position is computed based on what
Xlandmass the square belongs to.  If there is ocean basin there in the source
Xarray, the square belongs to the leading edge of a landmass which is subsuming
Xocean basin.  A constant is added to the height of the land in that square.
XIf there is land there in the destination array, then the two landmasses are
Xcolliding.  There is a collision array which records how many times each
Xpair of landmasses collide in any given timestep, and the movement routine
Xincrements the appropriate element of this array for each collision.
XMountains are built in this case by adding half the height of the lower
Xterrain to the height of the higher terrain.
X
XStep four uses the collision information provided by the movement routine
Xto adjust the velocities of colliding landmasses and perhaps merge them.
XFor each pair of colliding landmasses, the routine determines how "strong"
Xthe collision is this timestep.  The velocities are adjusted, again in
Xinverse proportion to the landmass areas, so that the continents begin
Xto come to rest with respect to each other.  If the relative velocity of
Xthe two landmasses, after adjustment, is small enough, then the masses
Xare merged.  This is the mechanism that reassembles the continental
Xfragments into a supercontinent.
X
XErosion is the final, and most computation-intensive, step of the simulation.
XEach pair of adjacent squares is considered exactly once.  If either square
Xis part of a landmass, erosion occurs.  Some fraction of the difference between
Xthe two squares' altitudes is subtracted from the taller and added to the
Xshorter.  This is a very simple algorithm since it ignores many factors,
Xbut more detail would make the simulation even slower.
X
X
XIV.  REFERENCES
X
X1.  Dole, Stephen H., "Computer Simulation of the Formation of Planetary
X    Systems", Icarus 13 (1970), pp 494-508.
X2.  Hart, Michael H., ""The Evolution of the Atmosphere of the Earth", Icarus
X    33 (1978), pp 23-39.
X3.  Forrester, J.W., World Dynamics, Wright-Allen Press (1973).
X4.  Wilson, J. Tuzo, "Continental Drift", Scientific American 208, 4 (April
X    1963), pp 86-100.
X5.  Nance, R.D., Worsley, T.R., and Moody, J.B., "The Supercontinent Cycle",
X    Scientific American (July 1988), pp 72-79.
END_OF_doc/about.tec
if test 10300 -ne `wc -c <doc/about.tec`; then
    echo shar: \"doc/about.tec\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f doc/readme.tec -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"doc/readme.tec\"
else
echo shar: Extracting \"doc/readme.tec\" \(3896 characters\)
sed "s/^X//" >doc/readme.tec <<'END_OF_doc/readme.tec'
XThis is the README file for Version 5 of tec, a plate tectonic simulator.
XIt is written in C and runs on any Xwindows system (X11R4) or any UN*X
Xmachine using text or PostScript output.  Copyright (c) 1991 by David Allen.
XYou may distribute this freely as long as you leave my name and copyright
Xnotice intact.
X
XI'd really like your comments and feedback; send e-mail to
Xallen@viewlogic.com, or send us-mail to David Allen, 10 O'Moore Ave,
XMaynard, MA 01754.
X
XVersion history:
X1.  Posted to rec.games.frp and rec.games.programmer on 11 / 15 / 89
X    - Runs only on Amiga, produces long text summary.
X    - Includes PostScript translator for any PostScript printer.
X2.  (Unreleased)
X    - Added text-only mode so it runs on UN*X machines.
X    - Added summary text output mode that fits on 80-character lines.
X    - PostScript support merged into main program.
X3.  Posted to comp.sources.misc, v10i077-78, on 2 / 15 / 90.
X    - Parameters can come from an input file (see params.tec).
X    - Ported to Sun workstation by the author.
X    - Ported to IBM PC by Peter Lind.
X4.  (Unreleased)
X    - Ported to Xwindows by George Ferguson.
X    - Autoscaling to produce specified hydrographics percentage.
X    - Underscan mode to reduce drift "off the edge of the world".
X5.  Posted to comp.sources.misc on 3 / 23 / 1991.
X    - Merged with globe display and climate generator
X    - Scope reduced to Xwindow graphics
X
XCredits:
XBrian Love - conversion to Amiga Lattice C 5.02, Amiga beta tester.
XPeter Lind - port to IBM PC Turbo C with CGA/MCGA/EGA/VGA.
XAndrew Hay - improved random number seeding (now BSD independent).
XFred Smith - added support for IBM PC Hercules mono graphics card.
XHoward Johnson, Dave Pare - bug fixes.
XGeorge Ferguson - port to XWindows.
X
X
XWHAT DOES THE TECTONIC SIMULATOR DO?
X
XTEC draws a map of some imaginary world and puts one big continent on it.
XThe program then graphically simulates the breakup of this supercontinent by
Xrifts and the drifting of the continents.  Mountains are built by
Xsubsuming and by continental collision, and are reduced by erosion.  As
Xmore time passes, the continents tend to drift back into a supercontinent
Xand split up again, forming what some authors call a "supercontinent cycle."
X
XThe program produces a map of an imaginary world which contains realistic
Xlooking mountain ranges and continents which sometimes look like they fit
Xtogether (like South America and Africa on Earth).
X
XI've included some sample output in the files example/tec.out.[1-3]; they are
Xshort text files.  0's indicate ocean, 1's indicate land, and 2's indicate
Xmountains.  Take a look.
X
X
XHOW DO I RUN IT?
X
XTo compile tec, go to the src directory and type "make tec".  To run tec,
Xtype "tec".  You can provide many optional parameter settings; place them
Xin a file and run tec with "tec filename".  Output from tec goes to stdout;
Xredirect it to a file to save it, as in "tec filename > outfile".
X
XWhen tec runs, it opens a graphics screen.  A big purple blob pops up.
XThis is the initial supercontinent.  Every second or so (depending on
Xmachine speed) another "step" will be computed and drawn.
X
XAltitudes are represented by colors; black is the lowest (ocean), and goes
Xthrough the spectrum from lowest to highest: purple, blue, green, yellow,
Xorange, red and finally white.  There are about 30 visibly different altitude
Xranges, since each color has several shades.
X
XAs time passes, you will see the supercontinent split up; green and yellow
Xmountains will appear on the leading edges of drifting continents; when
Xcontinents slow down, reverse course, and collide, higher orange and red
Xmountains will appear.  If you watch carefully, you can see erosion on
Xmountains that are not growing; they turn darker and travel down through
Xthe color ranges.
X
XAt any time, you can type "q" into the graphics window to end the program.
XIt will stop automatically after 100 steps.
END_OF_doc/readme.tec
if test 3896 -ne `wc -c <doc/readme.tec`; then
    echo shar: \"doc/readme.tec\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f doc/params.tec -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"doc/params.tec\"
else
echo shar: Extracting \"doc/params.tec\" \(5857 characters\)
sed "s/^X//" >doc/params.tec <<'END_OF_doc/params.tec'
XIf you give tec a filename as a command line argument, it will read 
Xparameters from that file.  If you hand it '-' as an argument, it will
Xread them from stdin.  For example, you could type "tec - < foo", or
X"tec foo".  The '-' option is handy for pipes.
X
XThe parameter file is optional; all of the parameters you can change
Xhave defaults.  Thus, the parameter file need contain only the parameters
Xyou want to change.  A parameter file looks like LISP; for example,
Xto change the XSIZE parameter, the file would have the one line
X
X(XSIZE 40)
X
XParameters can also be vectors; for example
X
X(MOVERATE (1 1 1))
X
XThe parameters are either easy or hard.  This rating concerns how much
Xyou have to know about the simulation to change the parameters.  Easy
Xones just affect run time, resolution, and so on.  Hard ones should
Xonly be changed if you understand the code pretty well.
X
XEasy parameters:
XPRINTMODE - 0 produces no output, 1 produces a long text file (default),
X            3 produces a summary text file and 4 produces PostScript
X            grayscale drawings.
XDRAWEVERY - How many steps should be iterated for each output.  Default 1,
X            but this produces an awful lot of text.  Reasonable values
X            for non-interactive runs are 5 or 10.  Supercontinents appear
X            every 25 steps or so.  A value of zero implies that only the
X            final map, at the last timestep, should be output.
XMAXSTEP   - How many steps to run before terminating.  Default 100.
XXSIZE     - Horizontal size of arrays.  Default 90.  To produce summaries
X            that fit on a normal page, I used 72.
XYSIZE     - Vertical size of arrays.  Default 90.  To produce the summaries
X            included in tec.out.[1-3], I used 48.
XHYDROPCT -  The percentage of the grid that should be covered by water.
X            Default is 70.  A threshhold is found for the initial blob to meet
X            this goal within about 2-3%.  If DRAWEVERY is also set to 0 (see
X            above), then at the last step the ocean level is forced up or
X            down to satisfy the requirement.  This may cause a PANIC error if
X            there just isn't enough land to do it.
XUNDERSCAN - If a potential rift gets within this many squares of the edge, it
X            is thrown away.  This keeps new fragments from appearing near the
X            edge, which in turn means that far less land falls off the edge
X            of the map.  This is a hack; the default is 0, which is no change;
X            for 100 x 100 maps, 10 is the best choice.
X
XSo to produce a text file with 10 pictures, you could use 
X
X(PRINTMODE 2) (DRAWEVERY 10) (XSIZE 72) (YSIZE 48)
X
XTo produce a 20-page PostScript output with a little more detail, use
X
X(PRINTMODE 4) (DRAWEVERY 5)
X
XHard Parameters:
XZINIT     - Initial altitude of supercontinent.  Default 22.
XZSUBSUME  - Altitude added to leading edge of drifting plate.  Default 16.
XZCOAST    - Sea level.  Everything below this is under water.  Default 16.
XZSHELF    - Minimum altitude for continental shelf.  Default 8.
XZMOUNTAIN - Used in PRINTMODE 2; altitude above which a square is counted
X            as mountain instead of land.  Default 48.
XZERODE    - Minimum altitude used in erosion.  Default 16.  Decrease this
X            number and continents grow faster at the margins; increase it
X            and they grow more slowly.  Increase it too much and weird
X            things happen to your mountains.
XMAXBUMP   - If two plates overlap on more than this number of squares,
X            the plates must be merged together.  Default 50. 
XBUMPTOL   - If the relative velocity of two touching plates is less than this
X            value, the plates will be merged together.  Default 50.
XMOVERATE  - A vector of real numbers describing the rate at which plates
X            move apart, slow down, and then drift back together.  Each
X            plate has an age, measured in steps from its creation.  The age
X            is used as an offset into the vector.  The result is a real
X            between -1.0 and +1.0 which is multiplied by the plate's original
X            movement vector.  The default vector is
X 
X            (1.0 1.0 1.0 0.7 0.4 0.1 -0.2 -0.5 -0.8 -1.0)
X
X            It can be interpreted this way.  The first three steps a plate is
X            in motion, it moves at its normal velocity.  During the 4-6
X            steps, it slows down.  During the 7-10 steps, it moves the
X            opposite way from the way it started, at increasing speeds.
X            Thereafter, it keeps moving at its final velocity.
XRIFTPCT   - Percent chance that a rift will occur in a given step.  Default 40.
XMAXCTRTRY - The number of tries the rift routine will make to find an
X            acceptable place to start a rift.  Default 50.
XRIFTDIST  - The minimum allowable distance between a proposed rift center
X            and the nearest coast.  Default 5.
XDOERODE   - Whether or not to compute erosion.  Default 1; if 0, the program
X            will run about twice as fast but will generate way too many
X            mountains, since the only thing that gets rid of mountains
X            is erosion.
XERODERND  - The rounding factor used in erosion.  Default 4.  As this 
X            parameter goes from 0 to 7, erosion occurs faster.
XBENDEVERY - Each time a rift grows by this many squares, it is allowed to
X            bend a little bit.  Default 6.
XBENDBY    - When a rift bends, it bends by a random angle in the range
X            -BENDBY ... +BENDBY multiplied by pi/2000.  Default value is 100.
X            If BENDBY is too high or BENDEVERY is too low, very curvy rifts
X            will be generated, with unrealistic results.
XSPPEDBASE - The minimum speed at which new plates will travel.  Default 200.
XSPEEDRNG  - The actual speed at which a plate travels is SPEEDBASE +
X            rnd (SPEEDRNG).  Default value is 300.
END_OF_doc/params.tec
if test 5857 -ne `wc -c <doc/params.tec`; then
    echo shar: \"doc/params.tec\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f doc/readme.globe -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"doc/readme.globe\"
else
echo shar: Extracting \"doc/readme.globe\" \(1735 characters\)
sed "s/^X//" >doc/readme.globe <<'END_OF_doc/readme.globe'
XThis is the README file for Version 1 of globe, a program which takes
Xa square map, wraps it around a globe, and displays an animation of the
Xglobe rotating.  It is written in C and runs on any Xwindows system (X11R4).
XCopyright (c) 1991 by David Allen.  You may distribute this freely as long
Xas you leave my name and copyright notice intact.
X
XI'd really like your comments and feedback; send e-mail to
Xallen@viewlogic.com, or send us-mail to David Allen, 10 O'Moore Ave,
XMaynard, MA 01754.
X
XWHAT DOES THE GLOBE PROGRAM DO?
X
XGiven a square map, for example, one produced by TEC, this program shows
Xwhat the map would look like from space.  Since a square is flat, and
Xa sphere is round, some distortion is involved.  
X
XHOW DO I RUN IT?
X
XTo compile globe, go to the src directory and type "make globe".  To run it,
Xgo to the example directory and type "../src/globe globe.in".  This directs
Xthe program to read the map stored in the file globe.in.
X
XWhen globe runs, it opens a graphics screen.  After a couple of seconds,
Xa purple globe pops up.  There are 18 frames in the animation; the colors
Xindicate altitudes.  Unlike tec, the ocean is displayed as bright purple
Xrather than black.
X
XAt any time, you can type "q" into the graphics window to end the program.
XIt will stop automatically after 10000 steps (a fairly long time).
X
XYou can display your own maps created using tec.  For example, create
Xa tec input file with this single line:
X
X(MAXSTEP 20) (UNDERSCAN 10) (PRINTMODE 1)
X
XThen type "tec filename > tec.out" (where filename is the name of the
Xinput file you just created).  Tec should run for a couple of seconds
Xand then produce a file called tec.out.  Then type "globe tec.out" and
Xyou will see your own globe rotating.
END_OF_doc/readme.globe
if test 1735 -ne `wc -c <doc/readme.globe`; then
    echo shar: \"doc/readme.globe\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f doc/readme.clim -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"doc/readme.clim\"
else
echo shar: Extracting \"doc/readme.clim\" \(3183 characters\)
sed "s/^X//" >doc/readme.clim <<'END_OF_doc/readme.clim'
XThis is the README file for Version 1 of clim, a program which computes
Xthe climate for a planet: temperature, pressure zones, wind patterns, rain
Xpatterns, and finally climate based on temperature and rain.  It is
Xwritten in C and runs on any Xwindows system (X11R4).  Copyright (c) 1991
Xby David Allen.  You may distribute this freely as long as you leave my
Xname and copyright notice intact.
X
XI'd really like your comments and feedback; send e-mail to
Xallen@viewlogic.com, or send us-mail to David Allen, 10 O'Moore Ave,
XMaynard, MA 01754.
X
XWHAT DOES CLIM DO?
X
XGiven a topographical map, for example, one produced by TEC, this program
Xcomputes temperature, pressure, wind, rain and climate.  The information
Xused in these computations comes from any college-level meterology text.
XOutput is produced as an animation on the graphics screen, on in text
Xfiles including PostScript output.
X
XI have included a sample text map showing climate for one world; it is
Xin example/clim.out.
X
XHOW DO I RUN IT?
X
XTo compile clim, go to the src directory and type "make clim".  To run it,
Xgo to the example directory and type "../src/clim clim.in".  This directs
Xthe program to read the map stored in the file clim.in.
X
XWhen clim runs, it opens a graphics screen.  It prints about 40 lines of
Xstatus information to stderr, then begins to animate the results.
X
XAt any time, you can type "q" into the graphics window to end the program.
XYou can flip between the types of display with these keys:
X   h: display temperature; default.  Temperature is displayed using the
X      full spectrum; purple is coldest, then blue, and so on; red is
X      hottest.  There are about 30 visibly different shades.  Black
X      lines indicate coastline; white lines surround mountains.
X   p: display pressure.  Zones of low pressure are surrounded by white
X      lines; zones of high pressure are surrounded by black lines.  Ocean
X      is blue, land is red, and mountains are grey.
X   w: display wind patterns.  Winds run in circles, especially over the
X      ocean.  Black horizontal lines are westbound; white horizontals are
X      eastbound; black verticals are southbound; white verticals are 
X      northbound.  Ocean is blue, land is red, mountains are grey.
X   r: display rainfall.  Amount of rainfall is displayed using the full
X      spectrum; purple is driest, then blue; red is wettest.  Black lines
X      indicate coastline; white lines surround mountains.
X   c: display climate.  The following colors are used:
X      dark blue:  Ocean           orange:        Savannah
X      light grey: Icebergs        dark green:    Decidous forest 
X      dark grey:  Tundra          bright green:  Jungle
X      brown:      Steppe          bright blue:   Swamp
X      yellow:     Desert
X
XTo produce your own maps for use with clim, you can use tec.  For example,
Xcreate a tec input file with this single line:
X
X(XSIZE 60) (YSIZE 30) (PRINTMODE 3) (MAXSTEP 20)
X
XThen type "tec filename > tec.out" (where filename is the name of the
Xinput file you just created).  Tec should run for a couple of seconds
Xand then produce a file called tec.out.  Then type "clim tec.out" and
Xyou will see the climate for your own planet.
END_OF_doc/readme.clim
if test 3183 -ne `wc -c <doc/readme.clim`; then
    echo shar: \"doc/readme.clim\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f doc/params.clim -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"doc/params.clim\"
else
echo shar: Extracting \"doc/params.clim\" \(9407 characters\)
sed "s/^X//" >doc/params.clim <<'END_OF_doc/params.clim'
XIf you give clim a filename as a command line argument, it will read 
Xparameters from that file.  If you hand it '-' as an argument, it will
Xread them from stdin.  For example, you could type "clim - < foo", or
X"clim foo".  The '-' option is handy for pipes.
X
XThe parameter file is optional; all of the parameters you can change
Xhave defaults.  Thus, the parameter file need contain only the parameters
Xyou want to change.  A parameter file looks like LISP; for example,
Xto change the XSIZE parameter, the file would have the one line
X
X(XSIZE 40)
X
XParameters can also be vectors; for example
X
X(RAINCUT (40 60 110 160 180))
X
XPrinting and sizing parameters:
X
XXSIZE     - Horizontal size of arrays.  Default 60.
XYSIZE     - Vertical size of arrays.  Default 30.
XBSIZE     - Number of seasons in animation and computation.  Default 4.  Note
X            that the storage arrays are statically sized with the constant
X            MAXB (in const.h); to increase BSIZE, you must increase MAXB and
X            recompile.
XPRINTMODE - Default 0.  The value 4 produces PostScript output; any other
X            value produces short summary output.
XPRINTEMP  - Default 0.  Any nonzero value produces one text map for each
X            season, where the entries represent scaled temperature by a single
X            hex digit (0..F).  A key is also printed, containing the Farenheit
X            temperature equivalents for each digit.
XPRINTPR   - Default 0.  Any nonzero value produces one text map for each
X            season, where the entries are 1 for a region of low pressure,
X            2 for a region of high pressure, and 3 for the heat equator
X            (a zone of low pressure).
XPRINTWIND - Default 0.  Any nonzero value produces one text map for each
X            season, where the entries are a single hex digit interpreted as
X            a bitmap.  Northbound winds are indicated by bit 0, southbound
X            by bit 1, eastbound by bit 2 and westbound by bit 3.  For example,
X            5 indicates NE winds.
XPRINTRAIN - Default 0.  Any nonzero value produces one text map for each
X            season, where the entries range from 0..F.  Zero indicates no
X            rainfall, and F indicates a lot.
XPRINTCLIM - Default 0.  Any nonzero value produces one text map for each
X            season, where each entry is in the range 0..A.  Here is a key:
X            0  Ocean         7  Savannah
X            3  Icebergs      8  Deciduous forest
X            4  Tundra        9  Jungle
X            5  Steppe        A  Swamp
X            6  Desert
X
XSo to produce a text file showing the climate and rainfall, you could use:
X
X(PRINTCLIM 1) (PRINTRAIN 1)
X
X
XThe rest of the parameters deal with the computational models.
X
XParameters affecting temperature
X
XTILT      - Default 23.0.  This is the tilt of the planet with respect to
X            its plane of orbit, in degrees.  Smaller numbers produce less 
X            seasonality; numbers above 45 violate some of the assumptions
X            of the models used.
XECCENT    - Default 0.0.  The eccentricity of the planet's orbit; this
X            parameter affects seasonality as well.  Numbers above 0.5 are
X            probably unrealistic.
XECCPHASE  - Default 0.0.  This parameter describes the phase offset of the
X            eccentricity with respect to the tilt, in radians.  You can
X            produce climates with complicated seasonality by varying this.
XLCONST    - Default 275.0.  The basic temperature for land squares, assuming
X            no tilt, eccentricity, or nearby ocean.
XLCOS      - Default 45.0.  The amount by which land temperatures should vary
X            from north pole to equator.  Land temperature, ignoring ocean
X            effects, varies from LCONST - LCOS/2 at the poles to LCONST +
X            LCOS/2 at the equator.
XLTILT     - Default 1.0.  The fraction of the tilt parameter that should be
X            applied to temperature adjustment for land.  Typically, land
X            temperatures vary more from season to season than the ocean
X            temperatures do, so LTILT should be higher than OTILT.
XLSMOOTH   - Default 0.6.  One equation governs the effect of land on ocean
X            temperatures and vice versa.  The equation involves LSMOOTH,
X            LDIV, OSMOOTH and ODIV.  Given the land and sea temperatures, and
X            the number of land squares in a 11 x 5 box around the square,
X            the final temperature is a weighted sum of the two temperatures.
X            The weights are related to LSMOOTH and OSMOOTH, and the importance
X            of nearby land is diminished by increasing LDIV or ODIV.
XLDIV      - Default 180.0.  See above.
XOCONST    - Default 275.0.  Same as LCONST, only for the ocean.
XOCOS      - Default 30.0.   Same as LCOS, only for the ocean.
XOTILT     - Default 0.2.    See LTILT.
XOSMOOTH   - Default 0.2.    See LSMOOTH.
XODIV      - Default 250.0.  See LSMOOTH.
X
XParameters affecting pressure
X
XOLTHRESH  - Default 1.  Ocean pressure zones essentially ignore land masses
X            whose radius is equal to or less than this number, like islands.
XOOTHRESH  - Default 5.  Ocean pressure zones must be at least this many 
X            squares away from the nearest (non-ignored) land.
XOLMIN     - Default 40.  If the unscaled temperature of an ocean square is
X            greater than OLMIN and less than OLMAX, then that square is a
X            low pressure zone.
XOLMAX     - Default 65.  See above.
XOHMIN     - Default 130.  If the unscaled temperature of an ocean square is
X            greater than OHMIN and less than OHMAX, then that square is a
X            high pressure zone.
XOHMAX     - Default 180.  See above.
XLOTHRESH  - Default 3.  Land pressure zones essentially ignore ocean bodies
X            whose radius is less than or equal to this number, like lakes.
XLLTHRESH  - Default 7.  Land pressure zones must be at least this many 
X            squares away from the nearest (non-ignored) ocean.
XLLMIN     - Default 220.  If the unscaled temperature of a land square is
X            greater than LLMIN and less than LLMAX, then that square is a
X            low pressure zone.
XLLMAX     - Default 255.  See above.
XLHMIN     - Default 0.  If the unscaled temperature of a land square is
X            greater than LHMIN and less than LHMAX, then that square is a
X            high pressure zone.
XLHMAX     - Default 20.  See above.
X
XParameters affecting wind
X
XBARSEP    - Default 16.  Winds are determined from pressure; a smooth
X            pressure map ranging from 0..255 is built by interpolating between
X            highs and lows.  Wind lines are contour lines on this map, and
X            BARSEP indicates the pressure difference between lines on the map.
X
XParameters affecting rainfall
X
XMAXFETCH  - Default 5.  Fetch is the term that describes how many squares a
X            given wind line travels over water.  A high fetch indicates a
X            moist wind.  This number is the maximum depth for the tree walking
X            algorithm which finds fetch; the effect of wind in one square
X            can travel at most this number of squares before stopping.
XRAINCONST - Default 32.  This is the base amount of rainfall in each square.
XLANDEL    - Default -10.  This is the amount by which rainfall is increased
X            in every land or mountain square; that is, rainfall goes down.
XMOUNTDEL  - Default 32.  For each unit of fetch which is stopped by a mountain,
X            rainfall in the mountain square increases by this amount.
XFETCHDEL  - Default 4.  The amount of rainfall in a square is increased by
X            this number for each unit of fetch in the square.
XHEQDEL    - Default 32.  The amount of rainfall in a square is increased by
X            this amount if the square is on the heat equator.
XNRHEQDEL  - Default 24.  The amount of rainfall in a square is increased by
X            this amount if the square is next to a square on the heat equator.
XFLANKDEL  - Default -24.  The amount of rainfall in a square is increased by
X            this amount if the square is on the "flank" of a circular wind
X            pattern.  This happens when the wind blows south.
XNRFDEL    - Default -3.  The amount of rainfall in a square is increased by
X            this amount for each adjacent square which is on a "flank".
X
XParameters affecting climate determination
X
XICEBERGK  - Default 263.  If an ocean square is below this temperature
X            (measured in deg Kelvin) all year round, then the ocean square
X            is icebergs.
XTEMPCUT   - Default is the vector (0 40 90 120).  The climate array found
X            in climate.c/climkey is 4 x 5; the first index is based on
X            average annual temperature.  The temperature is relative, based
X            on the range 0..255; this vector determines the cutoff points.
X            For example, with the default vector, a scaled temperature of 20
X            falls into the first "bin" and 121 falls into the fourth.
XRAINCUT   - Default is the vector (40 60 110 160 180).  The second index of
X            the climate array is based on average annual rainfall, scaled into
X            the range 0..255.  This vector determines the cutoff points.  For
X            example, rainfall of 35 falls into the first "bin".
XMTDELTA   - Default 20.  This is the amount, in degrees Farenheit, by which
X            temperature in the mountains is decreased before the climate 
X            lookup is performed.
END_OF_doc/params.clim
if test 9407 -ne `wc -c <doc/params.clim`; then
    echo shar: \"doc/params.clim\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f example/clim.out -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"example/clim.out\"
else
echo shar: Extracting \"example/clim.out\" \(1830 characters\)
sed "s/^X//" >example/clim.out <<'END_OF_example/clim.out'
X333333333333333333333333333333333333333333333333333333333333
X333333333333333333333333333333333333333333333333333333333333
X333333333333333333333333333334444444444444433333333333333333
X333333333333333333333333333300088885555555550000003333333333
X000000000000000000000000000000008888555555555888000000000000
X000000000000000080000000000000000088555555588888800000000000
X000000000000885550000000000000000000005555555558850000000000
X000000000000887667000000000000000000006655555555557000000000
X000000000000877666780000000000000000006666666667667700000000
X000000000000877666788000000000000000007666666667777880000000
X000000000000876666778800000000000000007766667778887880000000
X000000000000866666777888000000000000006666677778888800000000
X000000000000666666777779900000000000007797900000009000000000
X000000000000666666777777999000000000000000000000000000000000
X000000000000777766777777799990000000000000000000000000000000
X000000000000999777777777779999900000000000000000000000000000
X000000000000A999999999999999999A0000000000000000000000000000
X000000000000A99997777777777777900000000000000000000000000000
X000000000000999979777677777770000000000000000000000000000000
X000000000000988888766677667700000000000000000000000000000000
X000000000000008888876666677800000000000000000000000000000000
X000000000000000088887767677000000000000000000000000000000000
X000000000000000000080007700000000000000000000000000000000000
X000000000000000000000000000000000000000000000000000000000000
X000000000000000000000000000000000000000000000000000000000000
X000000000000000000000000000000000000000000000000000000000000
X000000000000000000000000000000000000000000000000000000000000
X333333333333333333333333333333333333333333333333333333333333
X333333333333333333333333333333333333333333333333333333333333
X333333333333333333333333333333333333333333333333333333333333
END_OF_example/clim.out
if test 1830 -ne `wc -c <example/clim.out`; then
    echo shar: \"example/clim.out\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 1 \(of 4\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 3 4 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 4 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0

exit 0 # Just in case...
-- 
Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
Sterling Software, IMD           UUCP:     uunet!sparky!kent
Phone:    (402) 291-8300         FAX:      (402) 291-4362
Please send comp.sources.misc-related mail to kent@uunet.uu.net.