diff options
author | William Joye <wjoye@cfa.harvard.edu> | 2018-04-04 18:24:37 (GMT) |
---|---|---|
committer | William Joye <wjoye@cfa.harvard.edu> | 2018-04-04 18:24:37 (GMT) |
commit | af94af4531e00d53fc38d5efee2631544575cb41 (patch) | |
tree | 38c2845dad6fb10ae6cb7177770e5d8555548211 | |
parent | 761d5e2c12845b4731298d206e27f44979d2be79 (diff) | |
download | blt-af94af4531e00d53fc38d5efee2631544575cb41.zip blt-af94af4531e00d53fc38d5efee2631544575cb41.tar.gz blt-af94af4531e00d53fc38d5efee2631544575cb41.tar.bz2 |
add ds9 plot parser
-rw-r--r-- | ds9/library/plotprocess.tcl | 118 | ||||
-rw-r--r-- | ds9/parsers/plotlex.fcl | 1 | ||||
-rw-r--r-- | ds9/parsers/plotparser.tac | 83 |
3 files changed, 164 insertions, 38 deletions
diff --git a/ds9/library/plotprocess.tcl b/ds9/library/plotprocess.tcl index 376dc75..fc95984 100644 --- a/ds9/library/plotprocess.tcl +++ b/ds9/library/plotprocess.tcl @@ -100,17 +100,25 @@ proc PrefsDialogPlot {} { } proc ProcessPlotCmd {xarname iname buf fn} { + upvar $xarname xar + upvar $iname i + global iap + global debug if {$debug(tcl,parser)} { + set ref [lindex $iap(windows) end] + global cvarname + set cvarname $ref + set iap(name) $iap(tt) + set iap(buf) $buf + set iap(fn) $fn + plot::YY_FLUSH_BUFFER - plot::yy_scan_string [lrange $var $i end] + plot::yy_scan_string [lrange $xar $i end] plot::yyparse incr i [expr $plot::yycnt-1] } else { - upvar $xarname xar - upvar $iname i - global iap set varname $iap(tt) set id 0 @@ -537,6 +545,102 @@ proc ProcessPlotData {varname xarname iname buf} { PlotList $varname } +proc PlotCmdCheck {} { + global cvarname + upvar #0 $cvarname cvar + + if {![info exists cvar(top)]} { + Error "[msgcat::mc {Unable to find plot window}] $cvarname" + plot::YYABORT + return + } + if {![winfo exists $cvar(top)]} { + Error "[msgcat::mc {Unable to find plot window}] $cvarname" + plot::YYABORT + return + } +} + +proc PlotCmdRef {ref} { + global iap + global cvarname + + # look for reference in current list + if {[lsearch $iap(windows) $ref] < 0} { + Error "[msgcat:: mc {Unable to find plot window}] $ref" + plot::YYABORT + return + } + set cvarname $ref + PlotCmdCheck +} + +proc PlotCmdNew {name} { + global iap + + if {$name != {}} { + set iap(name) $name + } + + if {$iap(buf) != {}} { + return + } elseif {$iap(fn) != {}} { + if {[file exists $iap(fn)]} { + set ch [open $iap(fn) r] + set iap(buf) [read $ch] + close $ch + return + } + } + set iap(buf) {} +} + +proc PlotCmdLine {title xaxis yaxis dim} { + global iap + PlotLine $iap(name) {} $title $xaxis $yaxis $dim $iap(buf) +} + +proc PlotCmdBar {title xaxis yaxis dim} { + global iap + PlotBar $iap(name) {} $title $xaxis $yaxis $dim $iap(buf) +} + +proc PlotCmdScatter {title xaxis yaxis dim} { + global iap + PlotScatter $iap(name) {} $title $xaxis $yaxis $dim $iap(buf) +} + +proc PlotCmdAnalysisPlotStdin {which} { + global iap + AnalysisPlotStdin $which $iap(name) {} $iap(buf) +} + +proc PlotCmdData {dim} { + global cvarname + upvar #0 $cvarname cvar + + if {$iap(buf) == {}} { + if {$iap(fn) != {}} { + if {[file exists $iap(fn)]} { + set ch [open $iap(fn) r] + set iap(buf) [read $ch] + close $ch + } + } + if {$iap(buf) == {}} { + Error "[msgcat:: mc {Unable to load plot data}] $fn" + plot::YYABORT + return + } + } + + PlotRaise $cvarname + PlotDataSet $cvarname $dim $iap(buf) + $var(proc,updategraph) $cvarname + PlotStats $cvarname + PlotList $cvarname +} + proc PlotCmdLoad {fn dim} { global cvarname @@ -583,6 +687,12 @@ proc PlotCmdSet {which value {cmd {}}} { } } +proc PlotCmdPrint {} { + global cvarname + + PlotPostScript $cvarname +} + proc PlotCmdUpdateGraph {which value} { global cvarname upvar #0 $cvarname cvar diff --git a/ds9/parsers/plotlex.fcl b/ds9/parsers/plotlex.fcl index 6b3ce2f..9724089 100644 --- a/ds9/parsers/plotlex.fcl +++ b/ds9/parsers/plotlex.fcl @@ -95,6 +95,7 @@ square {return $SQUARE_} stacked {return $STACKED_} stats {return $STATS_} step {return $STEP_} +stdin {return $STDIN_} style {return $STYLE_} sunken {return $SUNKEN_} tabloid {return $TABLOID_} diff --git a/ds9/parsers/plotparser.tac b/ds9/parsers/plotparser.tac index e983352..e592a67 100644 --- a/ds9/parsers/plotparser.tac +++ b/ds9/parsers/plotparser.tac @@ -96,6 +96,7 @@ %token STACKED_ %token STATS_ %token STEP_ +%token STDIN_ %token STYLE_ %token SUNKEN_ %token TABLOID_ @@ -123,14 +124,53 @@ command : plot | plot {yyclearin; YYACCEPT} STRING_ ; -plot : new - | NEW_ new + plot : {PlotCmdNew {}; PlotCmdLine {} {} {} xy} + | LINE_ {PlotCmdNew {}; PlotCmdLine {} {} {} xy} + | BAR_ {PlotCmdNew {}; PlotCmdBar {} {} {} xy} + | SCATTER_ {PlotCmdNew {}; PlotCmdScatter {} {} {} xy} + + | NEW_ {PlotCmdNew {}} new + | NEW_ NAME_ STRING_ {PlotCmdNew $2} new +# | NEW_ STRING_ {PlotCmdNew $2} new + | {PlotCmdCheck} plotCmd - | STRING_ {PlotCmdRef $1} | STRING_ {PlotCmdRef $1} plotCmd ; -plotCmd : DATA_ dim # +new : line + | LINE_ line + | BAR_ bar + | SCATTER_ scatter + ; + +line : STDIN_ {PlotCmdAnalysisPlotStdin line} + | STRING_ STRING_ STRING_ dim {PlotCmdLine $1 $2 $3 $4} + | STRING_ STRING_ STRING_ INT_ {PlotCmdLine $1 $2 $3 $4} + ; + +bar : STDIN_ {PlotCmdAnalysisPlotStdin bar} + | STRING_ STRING_ STRING_ dim {PlotCmdBar $1 $2 $3 $4} + | STRING_ STRING_ STRING_ INT_ {PlotCmdBar $1 $2 $3 $4} + ; + +scatter : STDIN_ {PlotCmdAnalysisPlotStdin scatter} + | STRING_ STRING_ STRING_ dim {PlotCmdScatter $1 $2 $3 $4} + | STRING_ STRING_ STRING_ INT_ {PlotCmdScatter $1 $2 $3 $4} + ; + +xy : 'x' {set _x} + | 'X' {set _ x} + | 'y' {set _ y} + | 'Y' {set _ y} + ; + +dim : XY_ {set _ xy} + | XYEX_ {set _ xyex} + | XYEY_ {set _ xyey} + | XYEXEY_ {set _ xyexey} + ; + +plotCmd : DATA_ dim {PlotCmdData $1} | LOAD_ load | SAVE_ STRING_ {PlotCmdSave $2} @@ -140,8 +180,8 @@ plotCmd : DATA_ dim # | LIST_ yesno {PlotCmdSet list $2 PlotList} | LOADCONFIG_ STRING_ {PlotCmdLoadConfig $2} | SAVECONFIG_ STRING_ {PlotCmdSaveConfig $2} - | PAGESETUP_ pagesetup # - | PRINT_ print # + | PAGESETUP_ pagesetup + | PRINT_ print | CLOSE_ {global cvarname; PlotDestroy $cvarname} | MODE_ mode {PlotCmdSet mode $2 PlotChangeMode} @@ -167,37 +207,11 @@ plotCmd : DATA_ dim # | SELECT_ INT_ # backward compatibility +# | LINE_ oldline | GRAPH_ oldgraph - | LINE_ oldline | VIEW_ oldview ; -new : line - | BAR_ bar - | SCATTER_ scatter - ; - -line : {PlotCmdLine {} {} {} {} xy} - ; - -bar : {PlotCmdBar {} {} {} {} xy} - ; - -scatter : {PlotCmdScatter {} {} {} {} xy} - ; - -dim : XY_ {set _ xy} - | XYEX_ {set _ xyex} - | XYEY_ {set _ xyey} - | XYEXEY_ {set _ xyexey} - ; - -xy : 'x' {set _x} - | 'X' {set _ x} - | 'y' {set _ y} - | 'Y' {set _ y} - ; - load : STRING_ {PlotCmdLoad $1 xy} | STRING_ dim {PlotCmdLoad $1 $2} ; @@ -221,7 +235,8 @@ pageSize : LETTER_ {set _ letter} | A4_ {set _ a4} ; -print : DESTINATION_ printDest {global ps; set ps(dest) $2} +print : {PlotCmdPrint} + | DESTINATION_ printDest {global ps; set ps(dest) $2} | COMMAND_ STRING_ {global ps; set ps(cmd) $2} | FILENAME_ STRING_ {global ps; set ps(filename) $2} | COLOR_ printColor {global ps; set ps(color) $2} |