Chinese Iching Random Weather Predictions

Chinese Iching Random Weather Predictions

This page is under development. Comments are welcome, but please load any comments in the comments section at the bottom of the page. Please include your wiki MONIKER in your comment with the same courtesy that I will give you. Its very hard to reply intelligibly without some background of the correspondent. Thanks,gold




Introduction

Here is some starter code for Chinese Iching Random Weather Predictions. The Iching is the ancient fortune telling book of China. The Iching literature mentions various methods for casting fortune patterns.In researching for the Iching Fortunes page on this wiki,I ran into several mentions of using the Iching to predict the weather. In the iching itself,there are at least some inferences on weather.On the public wall in Beijing, the Iching trigrams were generally posted as a daily weather prediction in Ming times. This page is more an investigation into the mindset of the Chinese sages,using TCL visual and random subroutines


The Iching is the ancient fortune telling book of China. The Iching literature mentions various methods for casting fortune patterns of Iching. The various methods include hot ironing of turtle shells (-t.),manipulations of yarrow sticks, flipping coins,throwing shaman bones, and dice.One analogy from North America is a shaman throwing or shuffling stick dice.


I made three stick dice for Iching by cutting a dowel of square cross section into three sticks.For the three stick dice, the flat sides are marked or burned with 2 or 3 holes alternately.Two sticks are marked with {3 2 3 2} dots on the sides. One stick is marked with {3 3 3 2} dots on the sides.In casting such three dice,the possible sums are 6,7,8, or 9. Further, the stick dice are cast six times to obtain whole lines or broken lines in a pattern or set of six lines.A set of six Iching lines is called a guain the orient or a hexagram in some translations of the Chinese.


In the Iching interpretations, casts of6 and 8 are broken or yin (female) lines,while casts of 7 and 9 are whole or yang (male) lines.The yin numbers of 6 and 8 are even numbers.The yang numbers of 7 and 9 are odd numbers.The casts are recorded by pencil with the first line at bottom and marking up the column.It is possible to record the numbers from the casts with tally sticks or Chinese counting rods,which are somewhat reminiscent of the Iching patterns themselves.After marking the original pattern or hexagram, sometimes a second follow-up hexagram is developed by swapping throws of 6 for a 7and throws of 9 for a 6. These swaps effectively trade a broken line(6) for a whole line(7)and a whole line(9) for a broken line(6). The throws for the changing lines (6&9) may not always be come out in the first hexagram or its component lines, so the followup hexagram may not exist {under consistent rules}.If the first hexagram is interpreted on a line by line basis, any changing lines(6&9) or second hexagram offers some modification or discount on the interpretation of the first hexagram


Continuing with the development of hexagrams, there would be 2**6 or 64 hexagrams.And the ancient Chinese were not finished with 64 hexagrams.At least one western Han text(Chiao shih Yi Lin ) gives consideration to transforms of 64*64 dimensions or 4096. So the Chinese busted into the barrier, 2 ** 12 = 4096.


In developing a computer program or application,it is helpful to develop analogs for the individual tasks of the application.An Iching application would have to compose, beg, or borrow TCL procedures for random casts,tallies of scores, accounting files,display hexagram lines on a screen, swapping changing lines, hexagram pattern recognition and ranking interpretations. For computer procedures, the patterns are effectively a horizontal bar code of 6 lines in modern terms.


In the process of designing the basic subroutine tasks, we could throw in some switches, logic chains, or daisy chains that break the outset rules given above.For example, TCL is so good at swapping lines (6&9)for the second hexagram, that it would be easy to put a switch that generates or swaps all hexagram lines (6,7,8,&9)for their opposites.Also from some scripts of the Chinese Chou dynasty,different Iching fortune methods of yarrow sticks or coins would generate different probabilities of obtaining each hexagram line. Might be interesting to have a back door in the program to check (or adapt} the different probabilities of stick or coin throws. Several authors have pointed out that a few of the hexagrams look similar to Chinese characters or even Mayan calendar notation. Without wading too deep into alternate realities, the Iching hexagrams could be used as numerals,script alphabet, game tokens, symbol recognition code,or maybe a programming language (like Greek letters for APL operators). Such rule breaking helps keep the finished program more flexible.


In the West, Leibniz recognized that the whole and broken lines in the hexagram patterns couldbe counted as ones and zeros, respectively in a binary number system. For example, a cast or list of { 6,7,8,9,6,7 } could be expressed as a binary number, 010101. For computer procedures,the patterns are effectively a horizontal bar code of 6 lines.The probability of each line by the yarrow stick method or coin casting method is different. of each lie by the yarrow stick method or coin casting method is different.

The probability of the yarrow stick method is 1,3,5,7 over 16.
The number 6 or old yin is 1/16 or 0.0625
The number 7 or young yang is 3/16 or 0.1875.
The number 8 or young yin is 5/16 or 0.3125.
The number 9 or old yang is 7/16 or .4375.
For the yarrow sticks, the combined probability of any throw is
.0625 + .1875 + .3125 + .4375 = 1
=====
----
For the iching dice pictured below, the three sticks read 2,3,and 3 which totals 8. The combined probability of casting 2,3, and 3 is 0.3125 (with the sticks). For the coins,the probability of the coin casting method is 2,2,6,6 over 16.
----

The number 6 or old yin is 2/6 or 0.125. The number 7 or young yang is 2/16 or 0.125. The number 8 or young yin is 6/16 or 0.375. The number 9 or old yang is 6/16 or .375. For the coins, the combined probability of any throw is .125 + .125 + .375 + .375 = 1 =====


For a system of 2 sided sticks or coins of the number N, the probability of getting all zeros or ones would be: set aa expr { (1./(2**$N))} ;# generic TCL For three coins, the formula would be set aa expr { (1./(2**3)} or 1/8 For example the trigrams known as heaven (111) and earth (000) would have a probability of 1/8. For six coins, the formula would be set aa expr { (1./(2**6)} or 1/64. For N dice, the probability that a one or zero would show up on one of N dice would be set aa expr { (1.-(1./(2**$N)))}


The Chinese believed that weather was the combination of the 5 elements or chi forces in the airnamely, rain, sunshine, heat, cold and wind .they reasoned that the weather was the combination ofchi forces between heaven and earth.For example, the combination of cold and rain produces snow.


Using the trigrams as symbols , the combination of two infer the mixing of conditions. Further, the trigrams were associated with directions. foretell the weather 1. based on the primary trigram 2. the combination of trigrams 3. the season 4. prevailing conditions


The fortnight periods, more specific as to expected conditions. and 5 seasons. spring, summer, late summer, autumn, and winter.


It is possible to make a iching gnomon using a pointed stick andboard. These individual markers will register binary ones and zerosas the sun rises from 600 to 1200 hours. And flipping the orientation of the board, measure the hours 1200 to 1800 hours. For the iching gnomonbelow, the shadow of 1300 hours is across the first bar, which isone hour after noon, meaning 1300 hours. The six binary bars show011111.

When the goinon end of the board is pointed at the morning sun, the goinon will measure the hours (600+N) until noon. When the goinon end of the board is pointed at the afternoon sun, the goinon will measure the hours (1200+N) until the sun goes down. As the goinon shadow passes a stick mark, the sequence of 6 binary numbers is 111111, 011111,001111,000111,000011,000001 or decimals 63,31,15,7,3,1


In the context of the oracle bones,the Shang were careful to record the weather as the hunting party or warrior raid set out,presumably early in the morning.Secondly they recorded the oracle forecast and result.These observations on the oracle bones contain elements of the scientific method.


For a trigram, returning 2 out of 3 yin lines might give a rainy forecast at binomial probability of 0.375.Any area with roughly 10 rainy days a month over the summer would have a probability of10/30 or 0.333. Here is possible theory that the trigram probability and the rainy day probability are somewhat comparable.


For Shanghai on 8Jul2010, the two trigrams developed were 2 and 3 which indicates southwest and rain conditions. The interpolated mean temperature was 24 C. The internet reported rain and winds in the southwest at 7 mph, 27 C, and 79 per cent humidity. The Shanghai timezone was loaded into the code on the fly.


For Beijing on 11Jul2010, the temp was 22C,light rain,east wind at 9 mph, humidity 83%. The picked trigrams were 3 and 5, meaning hot sunny and windy, pretty much a bust for the Iching. Interpolated temperature was 23.9C and chance of rainy day was 0.47. --- For Chicago on 11Jul2010, the temp was 29C, ,northwest wind at 16 kmph, .The picked trigrams were 5 and 5,meaning windy and change with SE wind,pretty much a strike out for the Iching. Interpolated temperature was 17C and chance of rainy day was 0.27.Shanghai was checked on 21JUL2010, the weather was mostly cloudy and 27 degrees C.Reported 84 %humidity and SE winds at 9mph. Iching forecast was trigrams 3 and 4,meaning hot sunny, and stormy.Mean temp was 30.47 C.and0.33 chance of rainy day. Iching prediction seemed moderately accurate.


Shanghai was checked on 21JUL2010, the weather was mostly cloudy and 27 degrees C.Reported 84 %humidity and SE winds at 9mph.Iching forecast was trigrams 3 and 4,meaning hot sunny, and stormy.Mean temp was 30.47 C.and0.33 chance of rainy day. Ichingprediction seemed moderately accurate.


The weather fronts do seem to come in cycles. The theory of weekend rain proposes greater chance on rain on weekends Would like to gather some more testcases and profiles, maybe some kind of neural filter or fuzzy logic could be developed.A very interesting cosine model for daily temperature by Martinez was found in the literature. A normalized solar loading curve were calculated at another site.


With the buttons in the little canvas demo, one can call up separate routines to layout the different boards and install the various options .In a teamwork situation, programming teams could divide up the several tasks with the framework.In the button call up of the canvas demo, separate tasks can laid in successive statements to clear board,set states, layout the board, .Loading three statements in the button might be ClrCanvas .cv; set state3 3;board .cv; This gets a little lengthy for a button line, so these statements could be stacked in a separate subroutine.With some global statements for any constants and passing the canvas name as $w, the subroutine could be written like

  proc stackedlist {w} {
    global state3
    ClrCanvas $w
    set state3 3
    board $w
  }

Screenshots Section

figure 1.

figure 2.

figure 3.

figure 4.

figure 5.

figure 6.


figure. EIGHT TRIGRAMS: WEATHER ASSOCIATIONS (seer proc)


+----------------------------------------------------------------------------------+
| EIGHT TRIGRAMS: WEATHER ASSOCIATIONS  (seer proc, state3 = 0..7)               |
|    xpieces = { \u2630 \u2631 \u2632 \u2633 \u2634 \u2635 \u2636 \u2637 }        |
|                                                                                  |
| +-------+----------+-----------+-----------+--------------------------------+   |
| |state3 | name     | element   | direction | weather prediction             |   |
| +-------+----------+-----------+-----------+--------------------------------+   |
| |   0   | Force    | Heaven    | northwest | colder and change, ice, snow   |   |
| |   1   | Open     | Swamp     | west      | damp and dewy, rain            |   |
| |   2   | Radiance | Fire      | south     | hot and sunny, less clouds     |   |
| |   3   | Shake    | Thunder   | east      | stormy                         |   |
| |   4   | Ground   | Wind      | southeast | windy and change               |   |
| |   5   | Gorge    | Water     | north     | colder and rain, snow, fog     |   |
| |   6   | Bound    | Mountain  | northeast | change for better, clouds      |   |
| |   7   | Field    | Earth     | southwest | cloudy, foggy                  |   |
| +-------+----------+-----------+-----------+--------------------------------+   |
|                                                                                  |
|    Two trigrams picked per forecast:                                            |
|      trigram1 = lpick {0 1 2 3 4 5 6 7}  --> primary condition                 |
|      trigram2 = lpick {0 1 2 3 4 5 6 7}  --> secondary modifier                |
|    Example: trigrams 2 + 3  --> "hot sunny" + "stormy"                         |
|    Combined: hot stormy conditions with possible thunder                        |
+----------------------------------------------------------------------------------+

figure. CHINESE FIVE ELEMENTS: CHI WEATHER FORCES


+----------------------------------------------------------------------------------+
| CHINESE FIVE ELEMENTS (CHI FORCES) GOVERNING WEATHER                            |
|    Chinese belief: weather = combination of chi between Heaven and Earth        |
|                                                                                  |
| +----------+------------+----------------------------------------------------+  |
| | element  | chi force  | weather role                                       |  |
| +----------+------------+----------------------------------------------------+  |
| | water    | rain       | precipitation, humidity, fog                       |  |
| | fire     | sunshine   | heat, solar radiation, drought                     |  |
| | wood     | heat       | warming, growth season, summer expansion           |  |
| | metal    | cold       | cooling, autumn contraction, winter frost          |  |
| | earth    | wind       | air movement, fronts, seasonal transitions         |  |
| +----------+------------+----------------------------------------------------+  |
|                                                                                  |
|    Combination rules (examples):                                                |
|      cold + rain  --> snow                                                      |
|      heat + wind  --> dry storm, dust                                           |
|      rain + wind  --> typhoon / monsoon conditions                              |
|      fire + water --> fog, steam, humid overcast                                |
|                                                                                  |
|    Trigram pairing for forecast:                                                |
|      1. primary trigram  --> dominant condition                                 |
|      2. combination of two trigrams --> mixing of chi forces                    |
|      3. season modifier  --> chseason proc (spring/summer/late summer/          |
|                              autumn/winter)                                     |
|      4. prevailing conditions --> meanmonth data tables                         |
+----------------------------------------------------------------------------------+

figure. CHINESE SEASONS AND FORTNIGHTS (chseason + cmonth procs)


+----------------------------------------------------------------------------------+
| CHINESE SEASONS AND FORTNIGHTS  (chseason + cmonth procs)                      |
|    Input: julian day number (1..365) from clock format %j                      |
|                                                                                  |
|    FIVE CHINESE SEASONS (chseason proc):                                        |
| +----------+-------------+--------------------------------------------------+  |
| | season   | julian days | western equivalent                               |  |
| +----------+-------------+--------------------------------------------------+  |
| | spring   |  20 ..  93  | late Jan to early Apr                            |  |
| | summer   |  93 .. 167  | early Apr to mid Jun                             |  |
| | late sum | 167 .. 242  | mid Jun to Aug                                   |  |
| | autumn   | 242 .. 315  | Aug to mid Nov                                   |  |
| | winter   | 315 .. 365  | mid Nov to year end                              |  |
| |          |   0 ..   6  | start of year also winter                        |  |
| +----------+-------------+--------------------------------------------------+  |
|                                                                                  |
|    SAMPLE FORTNIGHTS (cmonth proc, 24 solar terms, partial list):               |
| +----------+-------------+  +----------+-------------+                          |
| | fortnight| julian days |  | fortnight| julian days |                          |
| +----------+-------------+  +----------+-------------+                          |
| | great cold|  21..  36  |  | summer solst| 173..189 |                          |
| | beg.spring|  36..  51  |  | slight heat | 189..205 |                          |
| | rain water|  51..  66  |  | great heat  | 205..220 |                          |
| | excit.insct|  66.. 81  |  | autumn begin| 220..236 |                          |
| | spring eqx|  81..  96  |  | white dew   | 251..267 |                          |
| | grain rains| 126.. 142 |  | autumn eqx  | 267..282 |                          |
| | summer beg | 142.. 158 |  | winter beg  | 312..327 |                          |
| | grain fill | 158.. 173 |  | winter solst| 356..365 |                          |
| +----------+-------------+  +----------+-------------+                          |
+----------------------------------------------------------------------------------+

figure. MEANMONTH PROC: MONTHLY DATA TABLE LOOKUP


+----------------------------------------------------------------------------------+
| MEANMONTH PROC: MONTHLY CLIMATE DATA LOOKUP                                     |
|    proc meanmonth {julianday monthdata}                                         |
|      set month [ expr {$julianday / 30} ]    <- integer division = month index  |
|      return [ lindex $monthdata $month ]                                        |
|                                                                                  |
|    Note: integer division auto-truncates; no need for int() or float divide.    |
|    (Optimization noted by wiki commenter, adopted by gold)                      |
|                                                                                  |
|    Called with four data lists per city zone:                                   |
| +----------------+----------------------------------------------------------+   |
| | list variable  | contents                                                  |   |
| +----------------+----------------------------------------------------------+   |
| | meanmin        | mean minimum temperature C, 12-14 monthly values        |   |
| | meanmax        | mean maximum temperature C, 12-14 monthly values        |   |
| | meanrainmm     | mean precipitation mm per month, 12-14 values           |   |
| | rainydays      | mean rainy days per month, 12-14 values                 |   |
| +----------------+----------------------------------------------------------+   |
|                                                                                  |
|    Derived outputs (weathermean proc):                                          |
|      mean1 = mean min temp C                                                    |
|      mean2 = mean max temp C                                                    |
|      mean3 = mean precipitation mm per month                                   |
|      mean4 = rainy days per month                                               |
|      mean5 = chance of rainy day = rainydays / 30.0                            |
|      mean6 = mean precipitation mm per day = meanrainmm / 30.0                |
+----------------------------------------------------------------------------------+

figure. CITY CLIMATE DATA TABLES (weathermean proc)


+----------------------------------------------------------------------------------+
| CITY CLIMATE DATA TABLES  (weathermean proc, four cities)                       |
|    Zone string passed from button command to pick proc to weathermean           |
|                                                                                  |
| SHANGHAI  (zone :Asia/Shanghai)                                                 |
|   meanmax(Jan..Dec): 7.7  8.6  12.7 18.6 23.5 27.2 31.6 31.5 27.2 22.3 16.7 10.6|
|   meanmin(Jan..Dec): 0.5  1.5   5.1 10.6 15.7 20.3 24.8 24.7 20.5 14.7  8.6  2.4|
|   rainymm(Jan..Dec):  39   59   81  102  115  152  128  133  156   61   51   35 |
|   rainydays/month:     9   10   13   13   14   12   10   12    9    8    7    7 |
|                                                                                  |
| HONG KONG  (zone :Asia/Hong_Kong)                                               |
|   meanmax(Jan..Dec): 18.6 18.6 21.5 25.1 28.4 30.4 31.3 31.1 30.2 27.7 24.0 20.3|
|   meanmin(Jan..Dec): 14.1 14.4 16.9 20.6 23.9 26.1 26.7 26.4 25.6 23.4 19.4 15.7|
|   rainymm(Jan..Dec): 24.9 52.3 71.4 188.5 329.5 388.1 374.4 444.6 287.5 151.9 35.1 34.5|
|   rainydays/month:   5.6  9.5 10.5 11.7 15.5 18.8 17.8 17.4 14.8  8.1  5.7  4.3|
|                                                                                  |
| BEIJING  (zone :Asia/Taipei used as proxy)                                      |
|   meanmax(Jan..Dec): 1.6  4.0 11.3 19.9 26.4 30.3 30.8 29.5 25.8 19.0 10.1  3.3|
|   meanmin(Jan..Dec):-9.4 -6.9 -0.6  7.2 13.2 18.2 21.6 20.4 14.2  7.3 -0.4 -6.9|
|   rainymm(Jan..Dec):  3    6    9   26   29   71  176  182   49   19    6    2  |
|   rainydays/month:    2    3    4    5    6    9   14   12    7    5    3    2  |
|                                                                                  |
| CHICAGO  (zone :America/Chicago)                                                |
|   meanmax(Jan..Dec):-1.7  0.8  7.7 14.8 21.2 26.4 28.7 27.7 23.8 17.4  9.1  1.1|
|   meanmin(Jan..Dec):-10.6 -8.2 -1.9  3.7  8.7 14.2 17.0 16.4 12.2  5.7 -0.2 -7.2|
|   rainymm(Jan..Dec): 38.9 34.5 68.3 92.5 84.3 96.0 93.0 107.2 97.0 61.2 74.2 62.7|
|   rainydays/month:   7.3  6.2  9.0  9.5  8.9  8.0  8.0  7.5  7.7  6.6  7.9  7.8|
+----------------------------------------------------------------------------------+

figure. COSINE TEMPERATURE MODEL (tempform proc)


+----------------------------------------------------------------------------------+
| COSINE TEMPERATURE MODEL  (tempform proc, Martinez model)                       |
|    Estimates temperature at any hour from daily min and max                     |
|    Reference: www.ejournal.unam.mx/atm/Vol04-3/ATM04302.pdf                    |
|                                                                                  |
|    Inputs: aa = mean_min (C), bb = mean_max (C), cc = current_hour (0..24)     |
|                                                                                  |
|    bigterm = ((aa+bb)/2) + ((bb-aa)/2)   <- amplitude term                     |
|                                                                                  |
|    Morning branch (cc <= 14):                                                   |
|      term2 = pi * (cc + 10) / (10 + 6)                                         |
|      result = -1 * bigterm * cos(term2)                                         |
|                                                                                  |
|    Afternoon branch (cc > 14):                                                  |
|      term3 = pi * (cc - 14) / (14 - 13)                                        |
|      result = bigterm * cos(term3) * -1                                         |
|                                                                                  |
|    Output: abs(result) = estimated temperature at hour cc                       |
|                                                                                  |
|    Shape of daily cycle:                                                        |
|    temp                                                                          |
|    max |          *****                                                          |
|        |       ***     ***                                                       |
|    mid |     **           **        <- cosine gives smooth bell shape           |
|        |   **               **                                                  |
|    min |***                   ***                                               |
|        +--+--+--+--+--+--+--+--+-> hour                                        |
|        0  3  6  9 12 14 18 21 24                                                |
|        ^dawn  ^peak ~14h  ^sunset                                               |
|                                                                                  |
|    Linear interpolation fallback (interlinear proc):                           |
|      result = ((x2-x1)*(y3-y1)/(x3-x1)) + y1                                  |
|      Used when hour < 12: interpolate between midnight min and noon max        |
|      Used when hour >= 12: interpolate between noon max and midnight min       |
+----------------------------------------------------------------------------------+

figure. ICHING GNOMON: BINARY HOUR MARKER


+----------------------------------------------------------------------------------+
| ICHING GNOMON: BINARY HOUR MARKER  (sundial / shadow board)                    |
|    Pointed stick and board; shadow crosses 6 binary bars as sun moves           |
|                                                                                  |
|    Construction: board with 6 evenly-spaced vertical bars                       |
|    Gnomon end pointed at morning sun --> measures hours 600 to 1200             |
|    Gnomon end pointed at afternoon sun --> measures hours 1200 to 1800          |
|                                                                                  |
|    Shadow progression (morning, board pointed East):                            |
|    +------+----------+------------------+                                       |
|    | time | bar index| binary reading   |                                       |
|    +------+----------+------------------+                                       |
|    |  600 |    0     | 111111  = 63     |  all bars in shadow                   |
|    |  700 |    1     | 011111  = 31     |  bar 6 lit, 5 shaded                  |
|    |  800 |    2     | 001111  = 15     |  bars 6-5 lit                         |
|    |  900 |    3     | 000111  =  7     |  bars 6-4 lit                         |
|    | 1000 |    4     | 000011  =  3     |  bars 6-3 lit                         |
|    | 1100 |    5     | 000001  =  1     |  bars 6-2 lit                         |
|    | 1200 |    6     | 000000  =  0     |  all bars lit (noon)                  |
|    +------+----------+------------------+                                       |
|                                                                                  |
|    Example on page: shadow at 1300 hours crosses first bar                     |
|    --> one hour after noon = 1300  binary reading = 011111                     |
|                                                                                  |
|    Binary sequence registers hours as 6-bit binary countdown:                  |
|    63,31,15,7,3,1  (morning)  then 1,3,7,15,31,63  (afternoon reverse)        |
|    Each step = one hour marker; full day readable from single board             |
+----------------------------------------------------------------------------------+

figure. TRIGRAM PROBABILITY BY CASTING METHOD


+----------------------------------------------------------------------------------+
| TRIGRAM PROBABILITY BY CASTING METHOD                                           |
|                                                                                  |
|    Yarrow stick method (1,3,5,7 over 16):                                      |
| +--------+----------+------------+--------------------------------------------+|
| | value  | name     | prob       | notes                                      ||
| +--------+----------+------------+--------------------------------------------+|
| |  6     | old yin  | 1/16=0.0625| rarest; changes to yang in 2nd hex        ||
| |  7     | yng yang | 3/16=0.1875| static yang                                ||
| |  8     | yng yin  | 5/16=0.3125| most common; static yin                   ||
| |  9     | old yang | 7/16=0.4375| most likely in yarrow; changes to yin     ||
| +--------+----------+------------+--------------------------------------------+|
|    Note: page lists yarrow as 1,3,5,7 but standard reference                  |
|    gives 1,7,5,3 over 16 (6=1/16, 7=7/16, 8=5/16, 9=3/16).                  |
|                                                                                  |
|    Coin toss method (2,2,6,6 over 16):                                         |
| +--------+----------+------------+--------------------------------------------+|
| |  6     | old yin  | 2/16=0.125 | changes to yang in 2nd hex                ||
| |  7     | yng yang | 2/16=0.125 | static yang                                ||
| |  8     | yng yin  | 6/16=0.375 | most common in coin toss                  ||
| |  9     | old yang | 6/16=0.375 | equally common as 8 in coin toss          ||
| +--------+----------+------------+--------------------------------------------+|
|                                                                                  |
|    Three stick dice (from page, 8Jul2010 cast):                                |
|      sticks read 2, 3, and 3  --> sum = 8 (young yin, broken static line)     |
|      combined probability of casting (2,3,3) with sticks = 0.3125             |
|                                                                                  |
|    Trigram probability (3 coins, binomial):                                    |
|      P(all yin, Earth 000) = (1/2)^3 = 1/8 = 0.125                            |
|      P(all yang, Heaven 111) = (1/2)^3 = 1/8 = 0.125                          |
|      P(2-of-3 yin) = C(3,2)*(1/2)^3 = 3/8 = 0.375 --> rainy forecast prob    |
+----------------------------------------------------------------------------------+

figure. RAINY DAY PROBABILITY: TRIGRAM vs CLIMATE DATA


+----------------------------------------------------------------------------------+
| RAINY DAY PROBABILITY: TRIGRAM vs CLIMATE DATA COMPARISON                       |
|                                                                                  |
|    Trigram theory (3-line binary):                                              |
|      2-of-3 yin lines --> rainy forecast                                        |
|      P(2 or more yin of 3) = C(3,2)*(0.5)^3 + C(3,3)*(0.5)^3                 |
|                             = 3/8 + 1/8 = 4/8 = 0.5 (fully symmetric)         |
|      Or using broken line (yin) probability alone:                              |
|      P(2-of-3 yin) = 0.375  (binomial, p=0.5)                                 |
|                                                                                  |
|    Climate comparison (from page):                                              |
| +----------+-------+----------+-------------------------------------------+   |
| | city     | month | rainydays| P(rainy day) = rainydays/30               |   |
| +----------+-------+----------+-------------------------------------------+   |
| | Shanghai | Jul   |  10      | 10/30 = 0.333                             |   |
| | Beijing  | Jul   |  14      | 14/30 = 0.467                             |   |
| | Chicago  | Jul   |   8      |  8/30 = 0.267                             |   |
| | Shanghai | Jul21 | ~10      | ~0.333                                    |   |
| +----------+-------+----------+-------------------------------------------+   |
|                                                                                  |
|    Theory: trigram P(rainy) ~= 0.375 vs typical summer P(rain) 0.27-0.47      |
|    Observation: they are roughly comparable for moderate-rain regions           |
|    "possible theory that trigram probability and rainy day probability          |
|     are somewhat comparable" -- gold                                            |
+----------------------------------------------------------------------------------+

figure. LIVE FORECAST TESTCASES: RESULTS VS ACTUAL WEATHER


+----------------------------------------------------------------------------------+
| LIVE FORECAST TESTCASES: RESULTS VS ACTUAL WEATHER                              |
|                                                                                  |
| +----------+--------+--------------+------------------------------------------+|
| | city     | date   | Iching cast  | accuracy vs actual                       ||
| +----------+--------+--------------+------------------------------------------+|
| | Shanghai |8Jul10  | trig 2+3     | rain and SW winds 7mph, 27C, 79% RH      ||
| |          |        | SW + rain    | MATCH: predicted SW rain correctly        ||
| |          |        | mean T=24C   | actual 27C -- close                       ||
| +----------+--------+--------------+------------------------------------------+|
| | Beijing  |11Jul10 | trig 3+5     | actual: 22C, light rain, E wind 9mph     ||
| |          |        | hot sunny    | MISS: predicted hot/sunny, got rain      ||
| |          |        | + windy      | "pretty much a bust"                      ||
| |          |        | mean T=23.9C | actual 22C -- close temperature only      ||
| +----------+--------+--------------+------------------------------------------+|
| | Chicago  |11Jul10 | trig 5+5     | actual: 29C, NW wind 16 kmph             ||
| |          |        | windy+change | MISS: predicted SE wind, got NW wind     ||
| |          |        | mean T=17C   | actual 29C -- temperature miss           ||
| |          |        | P(rain)=0.27 | "pretty much a strike out"               ||
| +----------+--------+--------------+------------------------------------------+|
| | Shanghai |21Jul10 | trig 3+4     | actual: mostly cloudy, 27C, 84% RH       ||
| |          |        | hot sunny    | PARTIAL: mean T=30.47C (close-ish)       ||
| |          |        | + stormy     | P(rain)=0.33, prediction "moderately     ||
| |          |        |              | accurate"                                ||
| +----------+--------+--------------+------------------------------------------+|
|                                                                                  |
|    Overall: temperature interpolation works reasonably well;                    |
|    directional / precipitation Iching predictions are random chance ~25-50%    |
+----------------------------------------------------------------------------------+

figure. PICK PROC: FULL CANVAS FORECAST FLOW


+----------------------------------------------------------------------------------+
| PICK PROC: FULL CANVAS FORECAST FLOW  (proc pick {w zone})                     |
|                                                                                  |
|    Input: w = canvas widget,  zone = TCL timezone string                        |
|         |                                                                        |
|         v                                                                        |
|    STEP 1: Pick two random trigrams (state3 values 0..7)                       |
|      state3a = lpick {0 1 2 3 4 5 6 7}  --> primary trigram                    |
|      state3b = lpick {0 1 2 3 4 5 6 7}  --> secondary trigram                  |
|      Display large unicode trigram chars at x=100,y=100 and x=300,y=100        |
|      Display weather text at y=180 and y=200  (seer proc)                      |
|         |                                                                        |
|         v                                                                        |
|    STEP 2: Get system time and timezone                                         |
|      systemTime = clock seconds                                                 |
|      day = clock format systemTime -format %j   (julian day 1..365)            |
|      hour = clock format systemTime -format %k -timezone $zone                 |
|      Display: "julian date is ..."  at y=425                                   |
|      Display: full clock format string at y=440                                |
|         |                                                                        |
|         v                                                                        |
|    STEP 3: Season and fortnight from julian day                                 |
|      mean25 = chseason(day)   --> spring / summer / late summer / autumn / winter|
|      mean20 = cmonth(day)     --> specific fortnight name                       |
|      Display: "chinese season is *" at y=225                                   |
|      Display: "chinese fortnight is *" at y=245                               |
|         |                                                                        |
|         v                                                                        |
|    STEP 4: Call weathermean proc                                                |
|      --> draws all temperature and precipitation stats onto canvas              |
+----------------------------------------------------------------------------------+

figure. WEATHERMEAN PROC: CANVAS OUTPUT LAYOUT


+----------------------------------------------------------------------------------+
| WEATHERMEAN PROC: CANVAS OUTPUT LAYOUT  (proc weathermean {w zone})            |
|                                                                                  |
|    Canvas .cv, 400 x 450 pixels, background tan                                 |
|                                                                                  |
|    y=100  Trigram 1 unicode char (Helvetica 120)                                |
|    y=180  seer text: primary trigram weather description                        |
|    y=200  seer text: secondary trigram weather description                      |
|    y=225  "chinese season is  *  [spring/summer/late summer/autumn/winter]"    |
|    y=245  "chinese fortnight is * [beginning of spring / rain water / ...]"    |
|    y=265  "cosine formula temp:  XX.XX C"                                       |
|    y=280  "mean interpolated temp (HH H) C deg: XX.XX"                         |
|    y=300  "mean min temp: XX.X"                                                 |
|    y=320  "mean max temp: XX.X"                                                 |
|    y=340  "mean precipitation mm per month: XXX"                               |
|    y=360  "mean precipitation mm per day: XX.XX"                               |
|    y=380  "rainy days per month: XX.XX"                                         |
|    y=400  "chance of rainy day in month: X.XX"                                 |
|    y=425  "julian date is NNN"                                                  |
|    y=440  full clock format string (date, time, timezone)                       |
|                                                                                  |
|    Key derived values:                                                          |
|      cosine temp = abs(tempform(meanmin, meanmax, hour))                        |
|      chance of rain = meanmonth(day, rainydays) / 30.0                         |
|      mm per day = meanmonth(day, meanrainmm) / 30.0                            |
+----------------------------------------------------------------------------------+

figure. GUI BUTTON LAYOUT AND ZONE ASSIGNMENTS


+----------------------------------------------------------------------------------+
| GUI BUTTON LAYOUT AND TIMEZONE ASSIGNMENTS                                      |
|                                                                                  |
|    Window: .f1 (canvas), .f2 (buttons), background orange, border brown raised  |
|    Canvas: .cv, 400x450, bg=tan                                                 |
|                                                                                  |
| +--------+------------+------------------------+-----------------------------+  |
| | button | label      | command                | timezone string             |  |
| +--------+------------+------------------------+-----------------------------+  |
| | .b0    | clear      | clrcanvas .cv          | (none)                      |  |
| | .b1    | chicago    | pick .cv               | :America/Chicago            |  |
| | .b2    | hongkong   | pick .cv               | :Asia/Hong_Kong             |  |
| | .b3    | shanghai   | pick .cv               | :Asia/Shanghai              |  |
| | .b4    | beijing    | pick .cv               | :Asia/Taipei  (proxy)       |  |
| | .b5    | board      | board .cv              | (resets background)         |  |
| | .b6    | cos        | sinwave .cv            | (console cos wave output)   |  |
| | .b7    | exit       | leave .cv              | (exits program)             |  |
| +--------+------------+------------------------+-----------------------------+  |
|                                                                                  |
|    Buttons packed left to right: .b0 .b1 .b2 .b3 .b4 .b5 .b6 .b7 .b8          |
|    board proc: clrcanvas + configure bg orange/brown raised border 30           |
|                                                                                  |
|    Stacked button example (from page):                                          |
|      proc stackedlist {w} {                                                     |
|        global state3                                                            |
|        ClrCanvas $w                                                             |
|        set state3 3                                                             |
|        board $w  }                                                              |
+----------------------------------------------------------------------------------+

figure. SHANG ORACLE BONE SCIENTIFIC METHOD PARALLEL


+----------------------------------------------------------------------------------+
| SHANG ORACLE BONES: EARLY WEATHER OBSERVATION PROTOCOL                          |
|    Shang dynasty (~1200 BCE): weather recorded on oracle bones (jiaguwen)       |
|                                                                                  |
|    Oracle bone observation sequence (Shang hunting/raiding parties):            |
|         |                                                                        |
|    STEP 1: Record weather at departure (early morning)                          |
|      Cloud cover, wind direction, precipitation, temperature (qualitative)      |
|         |                                                                        |
|    STEP 2: Record oracle forecast                                               |
|      Crack turtle shell or ox shoulder bone with hot iron rod                   |
|      Interpret crack patterns as yes/no or condition forecasts                  |
|         |                                                                        |
|    STEP 3: Record actual result                                                 |
|      Weather observed during the expedition                                     |
|      Hunt or raid outcome                                                        |
|                                                                                  |
|    Assessment (gold):                                                           |
|      "These observations on the oracle bones contain elements of                |
|       the scientific method."                                                   |
|                                                                                  |
|    Beijing public wall (Ming dynasty, ~1368-1644 CE):                          |
|      I Ching trigrams posted daily as public weather prediction                 |
|      Eight trigrams displayed for eight directional weather zones               |
|      Public record of forecast vs outcome (informal validation)                 |
+----------------------------------------------------------------------------------+

figure. INTERLINEAR PROC AND TEMPERATURE INTERPOLATION


+----------------------------------------------------------------------------------+
| INTERLINEAR PROC AND TEMPERATURE INTERPOLATION  (proc interlinear)             |
|    Linear interpolation between two known points                                |
|                                                                                  |
|    proc interlinear { xx1 xx2 xx3 yy1 yy3 }:                                   |
|      return ((xx2-xx1)*(yy3-yy1)/(xx3-xx1)) + yy1                             |
|                                                                                  |
|    Usage in weathermean (hour < 12 branch):                                    |
|      interlinear 0.00001  $hour  12.  $meanmin  $meanmax                       |
|      ^x1=midnight  ^x2=now  ^x3=noon  ^y1=min    ^y2=max                       |
|      Interpolates temperature from near-midnight minimum to noon maximum        |
|                                                                                  |
|    Usage in weathermean (hour >= 12 branch):                                   |
|      interlinear 12.  $hour  24.  $meanmax  $meanmin                           |
|      Interpolates temperature from noon maximum back to midnight minimum        |
|                                                                                  |
|    Example (Shanghai 8Jul2010, hour=10, meanmin=24.8, meanmax=31.6):           |
|      morning interp = ((10-0)*(31.6-24.8)/(12-0)) + 24.8                       |
|                     = (10*6.8/12) + 24.8  = 5.67 + 24.8  = 30.47 C            |
|                                                                                  |
|    Cosine formula result for same case:                                         |
|      tempform(24.8, 31.6, 10)  --> abs(result) = 30.47 C  (comparable)        |
|      Actual reported: 27C  -->  model overestimates by ~3.5C in this case      |
+----------------------------------------------------------------------------------+

figure. OVERALL PROGRAM FLOW


+----------------------------------------------------------------------------------+
| OVERALL PROGRAM FLOW  (Chinese Iching Random Weather Predictions, gold Jul2010)|
|                                                                                  |
|    package require Tk                                                            |
|    set xpieces { unicode trigram chars 0..7 }                                   |
|         |                                                                        |
|         v                                                                        |
|    Define utility procs:                                                        |
|      lpick, average, pi, interlinear                                            |
|      meanmonth, chseason, cmonth                                                |
|      tempform, tempformxxx (draft)                                              |
|      listnumbers, sinwave (cosine wave to console)                              |
|      clrcanvas, board, seer, leave                                              |
|      pick, weathermean, stackedlist                                             |
|         |                                                                        |
|         v                                                                        |
|    Build GUI:                                                                   |
|      frame .f1 + canvas .cv (400x450, tan) --> packed in .f1                   |
|      frame .f2 + buttons .b0..b8 --> packed left in .f2                        |
|         |                                                                        |
|         v                                                                        |
|    board .cv  (initial display)                                                 |
|         |                                                                        |
|         v                                                                        |
|    User pushes city button (chicago/hongkong/shanghai/beijing):                 |
|      clrcanvas + pick .cv $zone                                                 |
|        --> 2x random trigram picks + seer text                                  |
|        --> julian day + season + fortnight from clock                           |
|        --> weathermean: full temperature + rain stats on canvas                 |
|        --> cosine formula temp + linear interpolation temp                      |
+----------------------------------------------------------------------------------+


References*

TEMPERATURE AND THE ASSIGNMENT OF THE HEXAGRAMS OF THE I-CHING TO THE CALENDAR
EDWARD A. HACKER 1 
1 NORTHEASTERN UNIVERSITY, BOSTON, MASSACHUSETTS 
http://www3.interscience.wiley.com/journal/119856417/abstract 

Journal of Chinese Philosophy
Volume 9 Issue 4, Pages 395 - 400
Published Online: 28 Jun 2008

appendix TCL programs

    # pretty print from autoindent and ased
    # based on
    # demo2-canvas.tcl - HaJo Gurt - 2005-12-13 - https://wiki.tcl-lang.org/15073
    #:by gold,   chinese  iChing random weather    
    # written on Windowws XP on eTCL
    # working under TCL version 8.5.6 and eTCL 1.0.1
    # gold on TCL WIKI , 17Jul2010    
    set xpieces {  \u2630 \u2631 \u2632 \u2633 \u2634 \u2635 \u2636 \u2637}
    package require Tk
    proc lpick L {lindex $L [expr int(rand()*[llength $L])];}
    proc average L {expr ([join $L +])/[llength $L].}
    
 
     proc meanmonth {julianday monthdata} {
        set month [ expr {$julianday / 30} ]
        return [ lindex $monthdata $month ]
        }
    proc chseason {aa} {
        set chinaseason "?"
        if { $aa >= 20 && $aa <= 93 } {set chinaseason "spring"}
        if { $aa >= 93 && $aa <= 167 } {set chinaseason "summer"}
        if { $aa >= 167 && $aa <= 242 } {set chinaseason "late summer"}
        if { $aa >= 242 && $aa <= 315} {set chinaseason "autumn"}
        if { $aa >= 315 && $aa <= 365} {set chinaseason "winter"}
        if { $aa >= 0 && $aa <= 6} {set chinaseason "winter"}
        return $chinaseason }
    
    proc cmonth {aa} {
        
        set cmonth "?"
        if { $aa >= 36 && $aa <= 51 } {set cmonth "beginning of spring"}
        if { $aa >= 51 && $aa <= 66 } {set cmonth "rain water"}
        if { $aa >= 66 && $aa <= 81 } {set cmonth "excited insects"}
        if { $aa >= 81 && $aa <= 96} {set cmonth "spring equinox"}
        if { $aa >= 96 && $aa <= 157} {set cmonth "clear and bright"}
        if { $aa >= 157 && $aa <= 126} {set cmonth "grain rains        "}
        if { $aa >= 126 && $aa <= 142} {set cmonth "summer begins"}
        if { $aa >= 142 && $aa <= 158} {set cmonth "grain filling"}
        if { $aa >= 158 && $aa <= 173} {set cmonth "grain in ear"}
        if { $aa >= 173 && $aa <= 189} {set cmonth "summer solstice"}
        if { $aa >= 189 && $aa <= 205} {set cmonth "slight heat"}
        if { $aa >= 205 && $aa <= 220} {set cmonth "great heat"}
        if { $aa >= 220 && $aa <= 236} {set cmonth "autumn begins"}
        if { $aa >= 236 && $aa <= 251} {set cmonth "limit of heat"}
        if { $aa >= 251 && $aa <= 267} {set cmonth "white dew"}
        if { $aa >= 267 && $aa <= 282} {set cmonth "autumn equinox"}
        if { $aa >= 282 && $aa <= 297} {set cmonth "cold dew"}
        if { $aa >= 297 && $aa <= 312} {set cmonth "hoar frost descends"}
        if { $aa >= 312 && $aa <= 327} {set cmonth "Winter begins"}
        if { $aa >= 327 && $aa <= 341} {set cmonth "slight snow"}
        if { $aa >= 341 && $aa <= 356} {set cmonth "great snow"}
        if { $aa >= 356 && $aa <= 365} {set cmonth "winter solstice"}
        if { $aa >= 1 && $aa <= 6} {set cmonth "winter solstice"}
        if { $aa >= 6 && $aa <= 21} {set cmonth "slight cold"}
        if { $aa >= 21 && $aa <= 36} {set cmonth "great cold"}
        if { $aa >= 366} {set cmonth "?"}
        return $cmonth    }
    
    proc pi {} {expr acos(-1)}
    
    proc interlinear { xx1 xx2 xx3 yy1 yy3 } {
        return [expr {  ((($xx2-$xx1)*($yy3-$yy1))/($xx3-$xx1))+ $yy1 } ] ;}
    
    proc tempform { aa bb cc } {
        set  hour1 $cc
        
        set bigterm [ expr {(($aa+$bb)/2.)+(($bb-$aa)/2.)} ]
        set hour3 6
        
        set term2 [ expr { [pi]*($hour1+ 10)/(10+$hour3)    }]
        set hour2 12
        set hour3 14
        #set cc 20
        if { $cc <= 14} {
            #set res [ expr { -1.*$bigterm*cos( $term2 )     }]
            set res [ expr { -1.*$bigterm*cos( $term2 )     }]
            #puts "first $res"
            return $res}
        
        set term3 [ expr { [pi]*($hour1+ 10)/(10+$hour3)    }]
        
        if { $cc > 14} {
            set hour3 13
            set term3 [ expr { [pi]*($hour1- 14)/(14-$hour3)    }]
            set res [ expr { $bigterm*cos( $term3 ) *-1.    }]}
        #puts "second  $res"
        return $res
    }
    
    proc tempformxxx { aa bb cc } {
        set  hour1 $cc
        
        set bigterm [ expr {(($aa+$bb)/2.)+(($bb-$aa)/2.)} ]
        
        set term5 [ expr { }]
        
        set term2 [ expr { [pi]*($term5)/(10+$hour1)     }]
        
        set hour2 12
        set hour3 14
        set cc 9
        if { $cc <= 14} {
            
            set hprime5 [ expr { }]
            
            set term2 [ expr { [pi]*($hprime5)/(10+$hour1)     }]
            
            set res [ expr { -1.*$bigterm*cos( $term2 )     }]
            #puts "first $res"
            return $res}
        
        set term3 [ expr { [pi]*($hour1+ 10)/(10+$hour3)    }]
        
        if { $cc > 14} {
            set hour3 13
            set term3 [ expr { [pi]*($hour1- 14)/(14-$hour3)    }]
            set res [ expr { $bigterm*cos( $term3 ) *-1.    }]}
        #puts "second  $res"
        return $res
    }
    
    proc listnumbers { aa bb} { for {set i [ expr {int($aa)}]} {$i<=$bb} {incr i} {lappend dd [ expr .1* $i] };return $dd}
    
    proc sinwave { w } {
        console show
        
        set goo [listnumbers 1 70 ]
        foreach item   $goo  {
            puts [ expr { cos ($item) } ]
        }
        
    }
    
    proc clrcanvas {w} {
        $w delete  "all"
    }
    
    proc pick {w zone } {
        global y xpieces
        incr y 10
        set txt canvas
        
        set boo 50
        set font2  "Helvetica 120"
        set font5  "Helvetica 10"
        set color4 blue
        set state3 [lpick { 0 1 2 3 4 5 6 7  } ]
        set texter [ lindex  $xpieces $state3]
        $w create text 100   100 -text $texter -font $font2 -width $boo -fill $color4 -tag obj_357034101
        
        $w create text 200   180 -text [seer $state3 ]  -tags "text"  -font $font5
        set texter [ lpick $xpieces]
        
        set state3 [lpick { 0 1 2 3 4 5 6 7  } ]
        set texter [ lindex  $xpieces $state3]
        
        $w create text  300   100 -text $texter -font $font2 -width $boo -fill $color4 -tag obj_672148664
        set systemTime [clock seconds]
        
        # "The time is: [clock format $systemTime -format %H:%M:%S]"
        # "The date is: [clock format $systemTime -format %j]"
        # [clock format $systemTime -format {Today is: %A, the %d of %B, %Y}]
        set day [clock format $systemTime -format %j ]
        $w create text 200   200 -text [seer $state3 ]  -tags "text"  -font $font5
        set juliandater "julian date is [clock format $systemTime -format %j -timezone $zone]"
        set mean20 [ cmonth $day ]
        set mean25 [ chseason $day ]
        $w create text 200   225 -text "chinese season is    * $mean25 " -tags "text"  -font $font5
        $w create text 200   245 -text "chinese fortnight  is    * $mean20 " -tags "text"  -font $font5
        
        $w create text 200   425 -text "$juliandater  " -tags "text"  -font $font5
        
        $w create text 200   440 -text [  clock format [clock scan now] -timezone $zone]  -tags "text"  -font $font5
        weathermean .cv $zone
        
    }
    
    proc weathermean {w zone} {
        set boo 50
        set font2  "Helvetica 120"
        set font5  "Helvetica 10"
        set meanmax { 1.6 4.0 11.3 19.9 26.4 30.3 30.8 29.5 25.8 19.0 10.1 3.3 3.3}
        
        if { $zone == ":Asia/Shanghai" } {
            set meanrainmm { 39 59 81 102 115 152 128 133 156 61 51 35 35 35 35 35}
            
            set rainydays { 9 10 13 13 14 12 10 12 9 8 7 7 7 7 7  }
            
            set meanmin { .5 1.5 5.1 10.6 15.7 20.3 24.8 24.7 20.5 14.7 8.6 2.4 2.4 2.4 2.4 2.4   }
            set meanmax { 7.7 8.6 12.7 18.6 23.5 27.2 31.6 31.5 27.2 22.3 16.7 10.6 10.6 10.6  }
        }
        
        if { $zone == ":Asia/Hong_Kong" } {
            set meanrainmm { 24.9 52.3 71.4 188.5 329.5 388.1 374.4 444.6 287.5 151.9 35.1 34.5 34.5 34.5}
            
            set rainydays { 5.6 9.5 10.5 11.7 15.5   18.8 17.8 17.4 14.8 8.1 5.7 4.3 4.3 4.3 4.3}
            
            set meanmin { 14.1 14.4 16.9 20.6 23.9 26.1 26.7 26.4 25.6 23.4 19.4 15.7 15.7 15.7}
            set meanmax { 18.6 18.6 21.5 25.1 28.4 30.4 31.3 31.1 30.2 27.7 24.0 20.3 20.3 20.3  }
        }
        
        if { $zone == ":Asia/Taipei" } {
            #beijing
            set meanrainmm { 3 6  9 26 29 71  176 182  49  19 6 2 2 2 2}
            
            set rainydays { 2 3 4 5 6 9 14 12 7 5 3  2 2 2 2}
            
            set meanmin {  -9.4 -6.9 -0.6 7.2 13.2 18.2 21.6  20.4  14.2  7.3 -.4 -6.9 -6.9 -6.9}
            set meanmax { 1.6 4.0 11.3 19.9 26.4 30.3 30.8 29.5 25.8 19.0 10.1 3.3 3.3 v3.3   }
        }
        
        if { $zone == ":America/Chicago" } {
            set meanrainmm {   38.9 34.5 68.3 92.5 84.3 96.0 93.0 107.2 97.0 61.2 74.2 62.7 62.7 }
            
            set rainydays { 7.3 6.2 9.0 9.5 8.9 8.0 8.0 7.5 7.7 6.6 7.9 7.8 7.8 7.8 }
            
            set meanmin { -10.6 -8.2 -1.9 3.7 8.7 14.2 17.0 16.4 12.2 5.7 -0.2 -7.2 -7.2 -7.2  }
            set meanmax {-1.7 0.8 7.7 14.8 21.2 26.4 28.7 27.7 23.8 17.4 9.1 1.1 1.1 1.1  }
        }
        
        set systemTime [clock seconds]
        
        set day [clock format $systemTime -format %j ]
        set mean1 " mean min temp [ meanmonth $day $meanmin] "
        set mean2 "mean max temp [ meanmonth $day $meanmax]"
        set mean3 " mean perc.  in mm per m [ meanmonth $day  $meanrainmm] "
        set mean4 " Rainy days per m [format "%6.2f" [ meanmonth $day $rainydays]]  "
        
        set mean5 " chance of rainy day in month[format "%6.2f" [expr {[ meanmonth $day $rainydays]/30.}]]"
        
        set mean6 " mean perc. in mm per day [format "%6.2f" [ expr {[ meanmonth $day  $meanrainmm]/30.}]] "
        set systemTime [clock seconds]
        set hour [clock format $systemTime -format %k -timezone $zone]
        #set hour 13.
        set mean7 [ meanmonth $day $meanmin]
        set mean8 [ meanmonth $day $meanmax]
        if { $hour < 12. } { set mean7 " mean interpolated temp.($hour H) C deg. [format "%6.2f" [interlinear .00001 10. 12. $mean7 $mean8 ]] "}
        if { $hour >= 12. } { set mean7 " mean interpolated temp.($hour H) C deg. [format "%6.2f" [interlinear 12. $hour 24. $mean7 $mean8 ] ] "}
        
        set kick [ tempform [ meanmonth $day $meanmin]  [ meanmonth $day $meanmax]   $hour]
        set kick [ expr { abs($kick) } ]
        set mean8 " cosine' formula   [format "%6.2f" $kick] C. "
        
        set mean9 " chinese fortnight [cmonth $day ]"
        #set mean7 " mean interpolated temp. C deg.  [interlinear 12. $hour 24. $mean7 $mean8 ] "
        $w create text 200   300 -text $mean1  -tags "text"  -font $font5
        
        $w create text 200   320 -text $mean2  -tags "text"  -font $font5
        $w create text 200   340 -text $mean3  -tags "text"  -font $font5
        $w create text 200   360 -text $mean6  -tags "text"  -font $font5
        $w create text 200   380 -text $mean4  -tags "text"  -font $font5
        $w create text 200   400 -text $mean5  -tags "text"  -font $font5
        $w create text 200   280 -text $mean7  -tags "text"  -font $font5
        $w create text 200   265 -text $mean8  -tags "text"  -font $font5
        
        #console show
        #puts [ tempform [ meanmonth $day $meanmin]  [ meanmonth $day $meanmax]   $hour     ]
    }
    proc seer {state3} {
        global xpieces
        #set state3 [lpick { 1 2 3 4 5 6 7 8 } ]
        
        if { $state3 == 0 } {return " 1   Force   heaven   northwest   * colder and change,ice,snow"}
        if { $state3 == 1 } {return " 2   Open   swamp   west          * damp and dewy,rain    "}
        if { $state3 == 2 } {return " 3   Radiance   fire   south      * hot and sunny,less clouds"}
        if { $state3 == 3 } {return " 4   Shake   thunder   east       * stormy"}
        if { $state3 == 4 } {return " 5   Ground   wind   southeast    * windy and change"}
        if { $state3 == 5 } {return " 6   Gorge   water   north        * colder and rain,rain,snow,fog "}
        if { $state3 == 6 } {return " 7   Bound   mountain  northeast  * change for better, clouds"}
        if { $state3 == 7 } {return " 8   Field   earth   southwest    *  cloudy,foggy"}
        set guess "?"
        return $guess
    }
    
    proc leave {w} {
        exit
    }
    
    proc board {w} {
        #set state3 1
        set state2 1
        clrcanvas $w
        . configure -background orange -highlightcolor brown -relief raised -border 30
        $w configure -bg tan
        
    }
    
    #: Main :
    frame .f1
    frame .f2
    pack  .f1 .f2
    
    set maxX 400
    set maxY 450
    set y      0
    
    set x1 120
    set x2 150
    set y1  50
    set y2  80
    
    canvas  .cv -width $maxX -height $maxY  -bg tan
    pack    .cv -in .f1
    
    button  .b0 -text "clear" -command { clrcanvas .cv }
    button  .b1 -text "chicago"  -command {clrcanvas .cv;pick .cv :America/Chicago     }
    button  .b2 -text "hongkong"  -command { clrcanvas .cv;pick .cv :Asia/Hong_Kong  }
    button  .b3 -text "shanghai"   -command {clrcanvas .cv;pick .cv :Asia/Shanghai}
    button  .b4 -text "beijing"   -command {clrcanvas .cv;pick   .cv :Asia/Taipei }
    button  .b5 -text "board"   -command { board   .cv }
    button  .b6 -text "cos"   -command { sinwave  .cv }
    button  .b7 -text "exit"   -command {leave   .cv }
    button  .b8 -text "exit"   -command {leave   .cv }
    pack .b0 .b1 .b2 .b3 .b4 .b5  .b6 .b7 .b7 .b8 -in .f2  -side left -padx 2
    board   .cv
    

gold This page is copyrighted under the TCL/TK license terms, this license .


Comments Section

Please place any comments here, Thanks.

gold Changes.

Note that your code here:

  proc meanmonth {julianday monthdata} {
    set goofy [ expr {$julianday / 30.}]
    set month [ expr {int( $goofy)}]
    set answer [lindex $monthdata $month]
    return $answer
  }

Can be more succinctly written as this:

  proc meanmonth {julianday monthdata} {
    return [ lindex $monthdata [ expr { $julianday / 30 } ] ]
  }

Or if you prefer to see the intermediate variable month:

  proc meanmonth {julianday monthdata} {
    set month [ expr {$julianday / 30} ]
    return [ lindex $monthdata $month ]
  }

There is no need to perform a floating point divide only to immediately take the integer part in a separate expr call. Expr performs integer math if passed integer operands, and integer math includes the effect of int() as part of the math itself. You also do not need to set a variable only to immediately return the same. You can pass the result of lindex directly to return.


gold changed proc meanmonth to latter suggestion.


Please place any comments here, Thanks.