Changeset 45 for trunk/liveplot


Ignore:
Timestamp:
Dec 4, 2009 4:59:28 PM (13 years ago)
Author:
toby
Message:

# on 1999/01/21 22:44:12, toby did:
drop arg #2 (get gsasexe from location/.gsas_config)
use localconfig & .gsas_config
add SaveOptions?
change histdump.inp to histdump$hst.inp in case 2 liveplots are running at once
track mod. time on .EXP file to avoid extra reads
use file read to pull cycle number from .EXP file
comment out background for now

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/liveplot

    • Property rcs:date changed from 1998/11/23 20:35:13 to 1999/01/21 22:44:12
    • Property rcs:rev changed from 1.1 to 1.2
    • Property rcs:lines set to +112 -73
    r9 r45  
    66set expnam [lindex $argv 0]
    77if {$expnam == ""} {puts "error -- no experiment name"; set exitstat 1}
    8 set gsasexe [lindex $argv 1]
    9 if {$gsasexe == ""} {puts "error -- no gsas directory"; set exitstat 1}
    108if $exitstat {
    11     puts "usage: $argv0 expnam gsasexedir \[hist #\] \[legend\]"
     9    puts "usage: $argv0 expnam \[hist #\] \[legend\]"
    1210    destroy .
    1311}
    14 if {[lindex $argv 2] == ""} {
    15     puts "warning -- no histogram number assuming 1"
     12if {[lindex $argv 1] == ""} {
    1613    set hst 1
    1714} else {
    18     set hst [lindex $argv 2]
    19 }
    20 if {[lindex $argv 3] == ""} {
    21     set legend 1
     15    set hst [lindex $argv 1]
     16}
     17if {[lindex $argv 2] == ""} {
     18    set graph(legend) 1
    2219} else {
    23     set legend [lindex $argv 3]
    24 }
     20    set graph(legend) [lindex $argv 2]
     21}
     22
     23
     24if {$tcl_platform(platform) == "windows"} {
     25    set graph(printout) 1
     26} else {
     27    set graph(printout) 0
     28}
     29
     30# default values
     31set graph(outname) out.ps
     32set graph(outcmd) lpr
     33
    2534if [catch {package require BLT} errmsg] {
    2635    tk_dialog .err "BLT Error" "Error -- Unable to load the BLT package" \
     
    7281waitmsg "Loading histogram, Please wait"
    7382
     83#--------------------------------------------------------------
     84# define constants
     85array set peakinfo {
     86    color1 magenta
     87    color2 cyan
     88    color3 yellow
     89    color4 sienna
     90    color5 orange
     91    color6 DarkViolet
     92    color7 HotPink
     93    color8 salmon
     94    color9 LimeGreen
     95}
     96set cycle -1
     97set modtime 0
     98
     99#----------------------------------------------------------------
    74100# where are we?
    75 set scriptname [info script]
     101set expgui(script) [info script]
    76102# translate links -- go six levels deep
    77103foreach i {1 2 3 4 5 6} {
    78     if {[file type $scriptname] == "link"} {
    79         set link [file readlink $scriptname]
     104    if {[file type $expgui(script)] == "link"} {
     105        set link [file readlink $expgui(script)]
    80106        if { [file  pathtype  $link] == "absolute" } {
    81             set scriptname $link
     107h           set expgui(script) $link
    82108        } {
    83             set scriptname [file dirname $scriptname]/$link
     109            set expgui(script) [file dirname $expgui(script)]/$link
    84110        }
    85111    } else {
     
    87113    }
    88114}
    89 set scriptdir [file dirname $scriptname]
     115
     116# fixup relative paths
     117if {[file pathtype $expgui(script)] == "relative"} {
     118    set expgui(script) [file join [pwd] $expgui(script)]
     119}
     120set expgui(scriptdir) [file dirname $expgui(script) ]
     121set expgui(gsasdir) [file dirname $expgui(scriptdir)]
     122set expgui(gsasexe) [file join $expgui(gsasdir) exe]
     123
     124# fetch EXP file processing routines
     125source [file join $expgui(scriptdir) readexp.tcl]
     126
     127# override options with locally defined values
     128if [file exists [file join $expgui(scriptdir) localconfig]] {
     129    source [file join $expgui(scriptdir) localconfig]
     130}
     131if [file exists [file join ~ .gsas_config]] {
     132    source [file join ~ .gsas_config]
     133}
    90134
    91135proc readdata {box} {
    92     global gsasexe expnam reflns
     136    global expgui expnam reflns
    93137    global lasthst
    94     global hst legend peakinfo units
     138    global hst peakinfo units
    95139    $box config -title "(Histogram update in progress)"
    96140    update
     
    102146#       puts $input "$hst"
    103147#       close $input
    104 #       set input [open "| $gsasexe/hstdump $expnam  < histdump.inp" w+]
     148#       set input [open "| $expgui(gsasexe)/hstdump $expnam  < histdump.inp" w+]
    105149###########################################################################
    106150        # use histdump for right now
    107         set input [open histdump.inp w]
     151        set input [open histdump$hst.inp w]
    108152        puts $input "$expnam"
    109153        puts $input "L"
     
    113157        # use hstdmp without an experiment name so that output
    114158        # is not sent to the .LST file
    115         set input [open "| $gsasexe/hstdmp < histdump.inp" r]
     159        set input [open "| $expgui(gsasexe)/hstdmp < histdump$hst.inp" r]
    116160       
    117161        # initalize arrays
     
    159203        if {$units == "Theta"} {set units "2-Theta"}
    160204        close $input
    161         file delete histdump.inp
     205        file delete histdump$hst.inp
    162206        xvec set $xlist
    163207        obsvec set $obslist
     
    183227
    184228proc plotdata {box} {
    185     global expnam hst legend peakinfo units cycle reflns
     229    global expnam hst peakinfo units cycle reflns modtime
    186230    global lasthst graph
    187231
     
    191235        xvec notify now
    192236        set cycle -1
     237        set modtime 0
    193238        $box config -title "Please wait: loading histogram $hst"
    194239        update
     
    202247    $box config -title "$expnam cycle $cycle Hist $hst"
    203248    $box xaxis config -title $units
    204     setlegend $box $legend
     249    setlegend $box $graph(legend)
    205250    # now deal with peaks
    206251    set j 0
     
    372417}
    373418
     419# save some of the global options in ~/.gsas_config
     420proc SaveOptions {} {
     421    global graph
     422    set fp [open [file join ~ .gsas_config] a]
     423    puts $fp "set graph(legend) $graph(legend)"
     424    puts $fp "set graph(printout) $graph(printout)"
     425    puts $fp "set graph(outname) $graph(outname)"
     426    puts $fp "set graph(outcmd) $graph(outcmd)"
     427    close $fp
     428}
     429
    374430proc aboutliveplot {} {
    375431    global Revision
     
    382438}
    383439
    384 if {$tcl_platform(platform) == "windows"} {
    385     set graph(printout) 1
    386 } else {
    387     set graph(printout) 0
    388 }
    389 set graph(outname) out.ps
    390 set graph(outcmd) lpr
    391 
    392440proc getcycle {} {
    393     global expnam gsasexe tcl_platform
     441    global expnam
    394442    set cycle -1
    395443    catch {
    396         # windows-specific code
    397         if {$tcl_platform(platform) == "windows"} {
    398             set fp [open $expnam.EXP r]
    399             set line [read $fp]
    400             close $fp
    401         } else {
    402             set line [exec $gsasexe/convdtos < $expnam.EXP ]
    403         }
    404         regexp {GNLS  RUN.*Total cycles run *([0-9]*) } $line x cycle
     444        set fp [open $expnam.EXP r]
     445        set text [read $fp]
     446        close $fp
     447        regexp {GNLS  RUN.*Total cycles run *([0-9]*) } $text x cycle
    405448    }
    406449    return $cycle
     
    408451
    409452proc updateifnew {} {
    410     global cycle
    411     set newcycle [getcycle]
    412     if {$newcycle != $cycle} {
    413         set cycle $newcycle
    414         # delay one second
    415         after 1000
    416         readdata .g
    417     }
    418     # check every ten seconds
    419     after 10000 updateifnew
    420 }
    421 
    422 # define constants
    423 array set peakinfo {
    424     color1 magenta
    425     color2 cyan
    426     color3 yellow
    427     color4 sienna
    428     color5 orange
    429     color6 DarkViolet
    430     color7 HotPink
    431     color8 salmon
    432     color9 LimeGreen
    433 }
     453    global cycle modtime expnam
     454    if {[file mtime $expnam.EXP] != $modtime} {
     455        set modtime [file mtime $expnam.EXP]
     456        set newcycle [getcycle]
     457        if {$newcycle != $cycle} {
     458            set cycle $newcycle
     459            # delay one second
     460            # after 1000
     461            readdata .g
     462        }
     463    }
     464    # check every second
     465#    after 10000 updateifnew
     466    after 1000 updateifnew
     467}
     468
    434469# vectors
    435470vector xvec
     
    448483$box element create obs -color black -symbol scross -linewidth 0
    449484$box element create calc -color red  -symbol none 
    450 $box element create bckg -color green  -symbol none 
     485#$box element create bckg -color green  -symbol none 
    451486$box element create diff -color blue  -symbol none 
    452487$box element config obs -xdata xvec -ydata obsvec
    453488$box element config calc -xdata xvec -ydata calcvec
    454 $box element config bckg -xdata xvec -ydata bckvec
     489#$box element config bckg -xdata xvec -ydata bckvec
    455490$box element config diff -xdata xvec -ydata diffvec
    456491$box yaxis config -title {}
    457 setlegend $box $legend
     492setlegend $box $graph(legend)
    458493# create a set of markers for each phase
    459494for {set i 1} {$i < 10} {incr i} {
     
    464499}
    465500
    466 global cycle
    467 set cycle -1
    468501updateifnew
    469502frame .a -bd 3 -relief groove
     
    497530            -command "minioptionsbox $num"
    498531}
    499 .a.options.menu add checkbutton -label "Include legend" -variable legend \
    500         -command {setlegend $box $legend}
     532.a.options.menu add checkbutton -label "Include legend" \
     533        -variable graph(legend) \
     534        -command {setlegend $box $graph(legend)}
    501535.a.options.menu add command -label "Set PS output" -command setpostscriptout
    502 
    503 if [file exists $scriptdir/icddcmd.tcl] {source $scriptdir/icddcmd.tcl}
    504 if [file exists $scriptdir/cellgen.tcl] {source $scriptdir/cellgen.tcl}
    505 
    506 if [file exists ~/.liveplotrc] {source ~/.liveplotrc}
     536.a.options.menu add command -label "Save Options" -underline 1 \
     537        -command "SaveOptions"
     538
     539# fetch EXP file processing routines
     540source [file join $expgui(scriptdir) readexp.tcl]
     541
     542set fl [file join $expgui(scriptdir) icddcmd.tcl]
     543if [file exists $fl] {source $fl}
     544set fl [file join $expgui(scriptdir) cellgen.tcl]
     545if [file exists $fl] {source $fl}
    507546
    508547pack [menubutton .a.help -text Help -underline 0 -menu .a.help.menu] -side right
Note: See TracChangeset for help on using the changeset viewer.