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.

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.