Cherry Blossom Viewing Equation and eTCL Slot Calculator Demo Example

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 understandably without some background of the correspondent. Thanks,gold


gold Here is some eTCL starter code for calculating the cherry blossom equation, used for predicting mean temperature days (DTS) until peak cherry blossom viewing at Japanese weather stations and cities. This report will use less strict definitions and not consider confidence levels, since the main interest is developing a simple and quick slot calculator. The problem of predicting Japanese cherry (sakura) blossom viewing is similar to predicting harvest dates of fruits and vegetables worldwide, so there is considerable economic interest in the equation. Most of the testcases involve replicas or models, using assumptions and rules of thumb.

In planning any software, it is advisable to gather a number of testcases to check the results of the program. The results of the testcases are estimated using the hand calculator and then checked in the eTCL slot calculator. Pseudocode and equations are developed from the hand calculations and theory. Small console programs are written to check or proof the alternate subroutines or procedures, rather than keeping the unblessed code and comment lines in the main slot calculator. Finally the improved or alternate subroutines are loaded into the slot calculator. The eTCL slot calculator is effectively a shell program to input entries, host calculation routines, and display results. Additional significant figures are used to check the eTCL calculator, not to infer the accuracy of inputs and product reports.

Testcases

Testcase 1: Each site has selected DOY ( date of year) to start measurements of daily mean temperature in Kelvin degrees. The mean temperature for 25 days (temperature series entered or list in program) is calculated for the daily value of DTS, mean standard temperature equivalent day. The DTS calculation uses the R gas constant as 8.31432 Joules per (Mole* degree kelvin) and blossom exponential constant which ranges from 6 to 60 Kilojoules per Mole. Testcase 1 uses blossom constant of 17 KJ/Mole. The combined exponential constant is (blossom exponential constant / R_gas_constant)*{(mean_temperature1-standard_temperature2)/(mean_temperature1*standard_temperature2)}. The expression with the temperatures is equivalent to {(1/standard_temperature2)- (1/mean_temperature1)} . The individual DTS value is exp(combined exponential constant). Typical daily value of calculated DTS ranges from 0.4 to 1.0 equivalent day during spring in Japan. The cumulative DTS estimate is divided by 25 days for the bloom prediction DTS delta days. The julian date for the sakura bloom viewing is the DOY or julian equivalent plus the DTS delta days. The cherry blossom equation is very sensitive to the blossom exponential constant, which is selected for the several sakura and plum varieties across Japan.

Push Button Operation

For the push buttons in the eTCL slot calculator, the recommended procedure is push testcase to fill entry frame, change first three entries etc, push solve, and then push report. Report allows copy and paste from console. For testcases in a computer session, the eTCL calculator increments a new testcase number internally, eg. TC(1), TC(2) , TC(3) , TC(N). The testcase number is internal to the calculator and will not be printed until the report button is pushed for the current result numbers. The current result numbers will be cleared on the next solve button. The calculator display has a caution flag subroutine for negative numbers, unrecognizable text characters, and operation outside expected operation range. On a degrading scale, the calculator will post warning flags to the console report, issue degraded accuracy notices, and may reset some negative and offscale numbers to positive defaults. Errors pass through the warning flag routine once on the same testcase and multiple error calls on the same fault are possible. Aside from the TCL calculator display, when one presses the report button on the calculator, one will have console show access to the functions (subroutines).

Pseudocode and Equations

 expr (($aa - $bb)*($aa - $bb)/ ( $cc * [pi]* $dd* $dd*$ee))]} 

Testcases Section

Testcase 1

table 1printed in tcl wiki format
quantity value comment, if any
testcase number:1
weather site number :1.0
julian date start day :42.0
mean day temperature in Kelvin (optional):300.0
standard temperature constant (optional) :288.2
blossom constant (optional) :17000.0
answers: internal constant days :0.0001364
internal constant days : 6.6748e-8
DTS mean temperature days : 7.0
DTS delta days plus julian of start day : 49.0

Testcase 2


Testcase 3


References:

  • Stat

Appendix Code

appendix TCL programs and scripts

        # pretty print from autoindent and ased editor
        # Cherry Blossom Viewing Equation calculator
        # written on Windows XP on eTCL
        # working under TCL version 8.5.6 and eTCL 1.0.1
        # gold on TCL WIKI, 20oct2014
        package require Tk
        namespace path {::tcl::mathop ::tcl::mathfunc}
        frame .frame -relief flat -bg aquamarine4
        pack .frame -side top -fill y -anchor center
        set names {{} {site name number :} }
        lappend names {julian date start day :}
        lappend names {mean day temperature in Kelvin (optional) :}
        lappend names {standard temperature constant (optional) :}
        lappend names {sakura blossom constant (optional) :}
        lappend names {answers: internal constant days: }
        lappend names {internal constant days : }
        lappend names {DTS mean temperature days:}
        foreach i {1 2 3 4 5 6 7 8} {
            label .frame.label$i -text [lindex $names $i] -anchor e
            entry .frame.entry$i -width 35 -textvariable side$i
            grid .frame.label$i .frame.entry$i -sticky ew -pady 2 -padx 1 }
        proc about {} {
            set msg "Calculator for Cherry Blossom Equation             
            from TCL WIKI,
            written on eTCL "
            tk_messageBox -title "About" -message $msg }   
        proc break_flag_routine {     } {
            global side1 side2 side3 side4 side5
            global side6 side7 side8
            global spares 
            global testcase_number
            set t9 $testcase_number
            set product_entries [* $side1 $side2 $side3 $side4 $side5 $side6 $side7 $side8] 
            if { $product_entries < 0.0 } { puts " warning flag! negative numbers detected in product entries ref. tc$t9" }
            foreach item { 1 2 3 4 5 6 7 8 9 10 } {
            set error$item 0 }
            if { $side1 < 0.0 } { set side1 .000001 ; set error1 1 ; set error2 1 }
            if { $side2 < 0.0 } { set side2 .000001 ; set error1 1 ; set error3 1 }
            if { $side3 < 0.0 } { set side3 .000001 ; set error1 1 ; set error4 1}
            if { $side4 < 0.0 } { set side4 .000001 ; set error1 1 ; set error5 1} 
            if { $side5 < 0.0 } { set side5 .000001 ; set error1 1 ; set error6 1}
            if { $side6 < 0.0 } { set side6 .000001 ; set error1 1 ; set error7 1}
            if { $side7 < 0.0 } { set side7 .000001 ; set error1 1 ; set error8 1}
            if { $side8 < 0.0 } { set side8 .000001 ; set error1 1 ; set error9 1}
            if { $side8 > 400.0 } {set error9 1}
            if { $side8 > 1000.0 } {set error10 1}      
            if { $error1 == 1 } { puts " warning flag! negative numbers detected in entries ref. tc$t9" }
            if { $error2 == 1 } { puts " warning flag! setting program default entries to positive ref. tc$t9" }
            if { $error3 == 1 } { puts " lower limit side2! setting program default entry ref. tc$t9" }
            if { $error4 == 1 } { puts " lower limit side3! setting program default entry ref. tc$t9" }
            if { $error5 == 1 } { puts " lower limit side4! defaults set but degrading accuracy ref. tc$t9" }
            if { $error6 == 1 } { puts " lower limit side5! outside expected range ref. tc$t9" }
            if { $error7 == 1 } { puts " lower limit side6! outside expected range ref. tc$t9" }
            if { $error8 == 1 } { puts " lower limit side7! outside expected range ref. tc$t9" }
            if { $error9 == 1 } { puts " upper limit side8! days outside expected range ref. tc$t9" }
            if { $error10 == 1 } { puts " upper limit side8! days far expected range ref. tc$t9" }
            foreach item { 1 2 3 4 5 6 7 8 9 10 } {
            set error$item 0 }
            return 1 } 
        proc fuzzy_round_up {args } {
            set lister {}
            foreach item $args {
            if { $item > [int $item ] &&  $item > 0. } { lappend lister [+ [int $item ] 1.]}                     
            if { $item == [int $item ] } { lappend lister [* $item 1.] }
            if { $item < [int $item ] &&  $item < 0. } { lappend lister [+ [int $item ] -1.]}  
                 }
                return $lister }
        proc mean_temperature_DTS  { temperature0 }   {
            global side1 side2 side3 side4 side5
            global side6 side7 side8
            global testcase_number
            global cumulative_days_dts mean_temperature_days_dts
            global temperature2 site_mean_lag exponent1 temperature2 
            global combo_exponent3 exponent2
            #set exponent2 [- [/ 1. $temperature2 ] [/ 1. $temperature0 ] ]
            set exponent2 [/ [- $temperature0 $temperature2] [* $temperature0  $temperature2 1.] ]            
            #set combo_exponent3 [* $exponent1 $exponent2 1. 1E-3 ]
            #set combo_exponent3 [* $exponent1 $exponent2 1. 1E-2  ]
            set combo_exponent3 [* $exponent1 $exponent2 1.  ]
            puts " exp1  $exponent1 exp2 $exponent2   comb   $combo_exponent3   "
            set mean_temperature_days_dts [exp $combo_exponent3] 
            #set mean_temperature_days_dts [* $mean_temperature_days_dts $site_mean_lag ]
            set mean_temperature_days_dts [* $mean_temperature_days_dts  ]
            set rem $mean_temperature_days_dts
            return $rem}    
        proc calculate {     } {
            global side1 side2 side3 side4 side5
            global side6 side7 side8
            global cumulative_days_dts mean_temperature_days_dts
            global temperature2 site_mean_lag exponent1 
            global combo_exponent3 exponent2 sum_julian
            global testcase_number 
            incr testcase_number 
            set side1 [* $side1 1. ]
            set side2 [* $side2 1. ]
            set side3 [* $side3 1. ]
            set side4 [* $side4 1. ]
            set side5 [* $side5 1. ]
            set side6 [* $side6 1. ]
            set side7 [* $side7 1. ]
            set side8 [* $side8 1. ]
            break_flag_routine
            set site_number $side1
            set start_julian $side2
            set temperature1 $side3
            #set exponent1 [* 9.5E3 1.]
            set sakura_exponent  $side5
            set r_gas_constant 8.31432
            set exponent1 [/ $r_gas_constant  $sakura_exponent ]
            set standard_temperature2 $side4
            set temperature2 $standard_temperature2  
            set site_mean_lag .2
            set cumulative_days_dts 0.
            set counter 0
            foreach item { 300 300 280 300 300 300 300 298 300 300 300 301 300 300 327 300 300 300 298 300 302 308 288 303  295} {
            incr counter
            set cumulative_days_dts  [+ $cumulative_days_dts [ mean_temperature_DTS $item ]]
            puts " single term  [  mean_temperature_DTS $item ] from t1. $item count $counter  \n "
            puts " day mean t.  $item cumulative $cumulative_days_dts ref t. $temperature2 ex. $exponent2" }
            set check_DTS_algorithm [ mean_temperature_DTS $temperature1 ]
            puts " checking DTS_algorithm from loaded mean t1 $temperature1 gives indv. DTS $check_DTS_algorithm ]"
            set cumulative $cumulative_days_dts 
            set cumulative [/ $cumulative 4. ]  
            set cumulative [ fuzzy_round_up  $cumulative  ]
            #set average_entries [/ 5.  [+ $side1 $side2 $side3 $side4 $side5 ]  ] 
            set side6 [abs $exponent2 ]
            set side7 [abs $combo_exponent3]
            set side8 $cumulative 
            set sum_julian [+ $start_julian $cumulative ]                 
                  }
        proc fillup {aa bb cc dd ee ff gg hh} {
            .frame.entry1 insert 0 "$aa"
            .frame.entry2 insert 0 "$bb"
            .frame.entry3 insert 0 "$cc"
            .frame.entry4 insert 0 "$dd"
            .frame.entry5 insert 0 "$ee"
            .frame.entry6 insert 0 "$ff" 
            .frame.entry7 insert 0 "$gg"
            .frame.entry8 insert 0 "$hh" 
             }
        proc clearx {} {
            foreach i {1 2 3 4 5 6 7 8 } {
                .frame.entry$i delete 0 end } }
        proc reportx {} {
            global side1 side2 side3 side4 side5
            global side6 side7 side8 
            global sum_julian
            global testcase_number
            console show;
            puts "%|table $testcase_number|printed in| tcl wiki format|% "
            puts "&| quantity | value| comment, if any|& "
            puts "&| testcase number:|$testcase_number | |&"
            puts "&| weather site number :|$side1|   |&"
            puts "&| julian date start day  :|$side2| |& "
            puts "&| mean day temperature in Kelvin (optional):|$side3| |& "
            puts "&| standard temperature constant (optional) :|$side4|  |&"
            puts "&| blossom constant (optional) :|$side5|  |&"
            puts "&| answers: internal constant days    :|$side6|  |&"  
            puts "&| internal constant days  :| $side7 |  |&"
            puts "&| DTS mean temperature days :| $side8 |  |&"
            puts "&| DTS delta days plus julian of start day :| $sum_julian |  |&"
         }
        frame .buttons -bg aquamarine4
        ::ttk::button .calculator -text "Solve" -command { calculate   }
        ::ttk::button .test2 -text "Testcase1" -command {clearx;fillup 1. 42.0 300.0 288.2   17.E3 .1 .2 7. }
        ::ttk::button .test3 -text "Testcase2" -command {clearx;fillup 2. 44.0 300.0 288.2   56.E3 .1 .2 7. }
        ::ttk::button .test4 -text "Testcase3" -command {clearx;fillup 3. 46.0 300.0 288.2   9.5E3 .1 .2 7. }
        ::ttk::button .clearallx -text clear -command {clearx }
        ::ttk::button .about -text about -command about
        ::ttk::button .cons -text report -command { reportx }
        ::ttk::button .exit -text exit -command {exit}
        pack .calculator  -in .buttons -side top -padx 10 -pady 5
        pack  .clearallx .cons .about .exit .test4 .test3 .test2   -side bottom -in .buttons
        grid .frame .buttons -sticky ns -pady {0 10}
        . configure -background aquamarine4 -highlightcolor brown -relief raised -border 30
        wm title . "Cherry Blossom Equation Calculator "
 

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

Comments Section

Please place any comments here, Thanks.