diff options
Diffstat (limited to 'ds9/library')
-rw-r--r-- | ds9/library/plot.tcl | 422 | ||||
-rw-r--r-- | ds9/library/plotbar.tcl | 12 | ||||
-rw-r--r-- | ds9/library/plotconfig.tcl | 287 | ||||
-rw-r--r-- | ds9/library/plotdata.tcl | 428 |
4 files changed, 721 insertions, 428 deletions
diff --git a/ds9/library/plot.tcl b/ds9/library/plot.tcl index 9c261e1..cdaa659 100644 --- a/ds9/library/plot.tcl +++ b/ds9/library/plot.tcl @@ -357,331 +357,6 @@ proc PlotChangeMode {varname} { } } -proc PlotDataSet {varname dim data} { - upvar #0 $varname var - global $varname - - set tt $var(graph,total) - set cc $var(graph,current) - - switch -- $dim { - 4 { - # first data set - PlotDataSetOne $varname "4.1" $data - - # set color - set col $var(graph$cc,color) - set var(graph$cc,color) [PlotNextColor $var(graph$cc,color)] - - # second data set - PlotDataSetOne $varname "4.2" $data - set var(graph$cc,color) $col - } - 5 { - # first data set - PlotDataSetOne $varname "5.1" $data - - # set color - set col $var(graph$cc,color) - set var(graph$cc,color) [PlotNextColor $var(graph$cc,color)] - - # second data set - PlotDataSetOne $varname "5.2" $data - set var(graph$cc,color) $col - } - default {PlotDataSetOne $varname $dim $data} - } -} - -proc PlotDataSetOne {varname dim data} { - upvar #0 $varname var - global $varname - - set tt $var(graph,total) - set cc $var(graph,current) - - # look for no data - if {[string length $data] == 0} { - return - } - - # total length - set ll [llength $data] - - # incr count - incr ${varname}(graph$cc,data,total) - set nn $var(graph$cc,data,total) - set var(graph$cc,data,current) $nn - - # new vector names - set xdata ap${varname}xx${nn} - set ydata ap${varname}yy${nn} - set xedata ap${varname}xe${nn} - set yedata ap${varname}ye${nn} - - # basics xy - set var(graph$cc,manage) 1 - set var(graph$cc,name) "Dataset $nn" - set var(graph$cc,xdata) $xdata - set var(graph$cc,ydata) $ydata - global $var(graph$cc,xdata) $var(graph$cc,ydata) - blt::vector create $var(graph$cc,xdata) $var(graph$cc,ydata) - - # substitute all separtors - regsub -all {[\n\r\t, ]+} $data { } data - # remove all non-numeric data - regsub -all {[^0-9.e\- ]+} $data {} data - - set x {} - set y {} - set xe {} - set ye {} - switch -- $dim { - 2 - - xy { - set var(graph$cc,dim) xy - set var(graph$cc,xedata) {} - set var(graph$cc,yedata) {} - - for {set ii 0} {$ii<$ll} {incr ii 2} { - lappend x [lindex $data $ii] - lappend y [lindex $data [expr $ii+1]] - } - $var(graph$cc,xdata) set $x - $var(graph$cc,ydata) set $y - } - - xyex { - set var(graph$cc,dim) xyex - set var(graph$cc,xedata) $xedata - set var(graph$cc,yedata) {} - - global $var(graph$cc,xedata) - blt::vector create $var(graph$cc,xedata) - - for {set ii 0} {$ii<$ll} {incr ii 3} { - lappend x [lindex $data $ii] - lappend y [lindex $data [expr $ii+1]] - lappend xe [lindex $data [expr $ii+2]] - } - $var(graph$cc,xdata) set $x - $var(graph$cc,ydata) set $y - $var(graph$cc,xedata) set $xe - } - - 3 - - xyey { - set var(graph$cc,dim) xyey - set var(graph$cc,xedata) {} - set var(graph$cc,yedata) $yedata - - global $var(graph$cc,yedata) - blt::vector create $var(graph$cc,yedata) - - for {set ii 0} {$ii<$ll} {incr ii 3} { - lappend x [lindex $data $ii] - lappend y [lindex $data [expr $ii+1]] - lappend ye [lindex $data [expr $ii+2]] - } - $var(graph$cc,xdata) set $x - $var(graph$cc,ydata) set $y - $var(graph$cc,yedata) set $ye - } - - xyexey { - set var(graph$cc,dim) xyexey - set var(graph$cc,xedata) $xedata - set var(graph$cc,yedata) $yedata - - global $var(graph$cc,xedata) $var(graph$cc,yedata) - blt::vector create $var(graph$cc,xedata) $var(graph$cc,yedata) - - for {set ii 0} {$ii<$ll} {incr ii 4} { - lappend x [lindex $data $ii] - lappend y [lindex $data [expr $ii+1]] - lappend xe [lindex $data [expr $ii+2]] - lappend ye [lindex $data [expr $ii+3]] - } - $var(graph$cc,xdata) set $x - $var(graph$cc,ydata) set $y - $var(graph$cc,xedata) set $xe - $var(graph$cc,yedata) set $ye - } - - 4.1 { - set var(graph$cc,dim) xyey - set var(graph$cc,xedata) {} - set var(graph$cc,yedata) $yedata - - global $var(graph$cc,yedata) - blt::vector create $var(graph$cc,yedata) - - for {set ii 0} {$ii<$ll} {incr ii 4} { - lappend x [lindex $data $ii] - lappend y [lindex $data [expr $ii+1]] - lappend ye [lindex $data [expr $ii+2]] - } - $var(graph$cc,xdata) set $x - $var(graph$cc,ydata) set $y - $var(graph$cc,yedata) set $ye - } - - 4.2 { - set var(graph$cc,dim) xy - set var(graph$cc,xedata) {} - set var(graph$cc,yedata) {} - - for {set ii 0} {$ii<$ll} {incr ii 4} { - lappend x [lindex $data $ii] - lappend y [lindex $data [expr $ii+3]] - } - $var(graph$cc,xdata) set $x - $var(graph$cc,ydata) set $y - } - - 5.1 { - set var(graph$cc,dim) xyey - set var(graph$cc,xedata) {} - set var(graph$cc,yedata) $yedata - - global $var(graph$cc,yedata) - blt::vector create $var(graph$cc,yedata) - - for {set ii 0} {$ii<$ll} {incr ii 5} { - lappend x [lindex $data $ii] - lappend y [lindex $data [expr $ii+1]] - lappend ye [lindex $data [expr $ii+2]] - } - $var(graph$cc,xdata) set $x - $var(graph$cc,ydata) set $y - $var(graph$cc,yedata) set $ye - } - - 5.2 { - set var(graph$cc,dim) xyey - set var(graph$cc,xedata) {} - set var(graph$cc,yedata) $yedata - - global $var(graph$cc,yedata) - blt::vector create $var(graph$cc,yedata) - - for {set ii 0} {$ii<$ll} {incr ii 5} { - lappend x [lindex $data $ii] - lappend y [lindex $data [expr $ii+3]] - lappend ye [lindex $data [expr $ii+4]] - } - $var(graph$cc,xdata) set $x - $var(graph$cc,ydata) set $y - $var(graph$cc,yedata) set $ye - } - } - - set var(graph$cc,$nn,manage) 1 - set var(graph$cc,$nn,dim) $var(graph$cc,dim) - - set var(graph$cc,$nn,xdata) $var(graph$cc,xdata) - set var(graph$cc,$nn,ydata) $var(graph$cc,ydata) - set var(graph$cc,$nn,xedata) $var(graph$cc,xedata) - set var(graph$cc,$nn,yedata) $var(graph$cc,yedata) - - PlotGetVar $varname $nn - - # update data set menu - $var(mb).graph.select add radiobutton -label "$var(graph$cc,name)" \ - -variable ${varname}(graph$cc,data,current) -value $nn \ - -command [list PlotCurrentData $varname] - - PlotAddData $varname - $var(proc,updateelement) $varname -} - -proc PlotDupData {varname mm} { - upvar #0 $varname var - global $varname - - set tt $var(graph,total) - set cc $var(graph,current) - - if {$var(graph$cc,data,total) == 0} { - return - } - - # incr count - incr ${varname}(graph$cc,data,total) - set nn $var(graph$cc,data,total) - set pp [expr $nn-1] - - # new vector names - set var(graph$cc,$nn,name) "Dataset $nn" - set var(graph$cc,$nn,xdata) ap${varname}xx${nn} - set var(graph$cc,$nn,ydata) ap${varname}yy${nn} - set var(graph$cc,$nn,xedata) ap${varname}xe${nn} - set var(graph$cc,$nn,yedata) ap${varname}ye${nn} - global $var(graph$cc,$mm,xdata) $var(graph$cc,$mm,ydata) \ - $var(graph$cc,$mm,xedata) $var(graph$cc,$mm,yedata) - global $var(graph$cc,$nn,xdata) $var(graph$cc,$nn,ydata) \ - $var(graph$cc,$nn,xedata) $var(graph$cc,$nn,yedata) - - $var(graph$cc,$mm,xdata) dup $var(graph$cc,$nn,xdata) - $var(graph$cc,$mm,ydata) dup $var(graph$cc,$nn,ydata) - if {$var(graph$cc,$mm,xedata) != {}} { - $var(graph$cc,$mm,xedata) dup $var(graph$cc,$nn,xedata) - } else { - set var(graph$cc,$nn,xedata) {} - } - if {$var(graph$cc,$mm,yedata) != {}} { - $var(graph$cc,$mm,yedata) dup $var(graph$cc,$nn,yedata) - } else { - set var(graph$cc,$nn,yedata) {} - } - - set var(graph$cc,$nn,manage) 1 - set var(graph$cc,$nn,dim) $var(graph$cc,$mm,dim) - - set var(graph$cc,$nn,show) $var(graph$cc,$mm,show) - set var(graph$cc,$nn,shape,symbol) $var(graph$cc,$mm,shape,symbol) - set var(graph$cc,$nn,shape,fill) $var(graph$cc,$mm,shape,fill) - set var(graph$cc,$nn,shape,color) $var(graph$cc,$mm,shape,color) - set var(graph$cc,$nn,smooth) $var(graph$cc,$mm,smooth) - set var(graph$cc,$nn,color) [PlotNextColor $var(graph$cc,$mm,color)] - set var(graph$cc,$nn,fill) $var(graph$cc,$mm,fill) - set var(graph$cc,$nn,fill,color) \ - [PlotNextColor $var(graph$cc,$mm,fill,color)] - set var(graph$cc,$nn,width) $var(graph$cc,$mm,width) - set var(graph$cc,$nn,dash) $var(graph$cc,$mm,dash) - - set var(graph$cc,$nn,error) $var(graph$cc,$mm,error) - set var(graph$cc,$nn,error,cap) $var(graph$cc,$mm,error,cap) - set var(graph$cc,$nn,error,color) $var(graph$cc,$mm,error,color) - set var(graph$cc,$nn,error,width) $var(graph$cc,$mm,error,width) - - set var(graph$cc,$nn,bar,relief) $var(graph$cc,$mm,bar,relief) - - # update data set menu - $var(mb).graph.select add radiobutton -label "$var(graph$cc,$nn,name)" \ - -variable ${varname}(graph$cc,data,current) -value $nn \ - -command [list PlotCurrentData $varname] - - # make current - set var(graph$cc,data,current) $nn - - set var(graph$cc,manage) $var(graph$cc,$nn,manage) - set var(graph$cc,dim) $var(graph$cc,$nn,dim) - - set var(graph$cc,xdata) $var(graph$cc,$nn,xdata) - set var(graph$cc,ydata) $var(graph$cc,$nn,ydata) - set var(graph$cc,xedata) $var(graph$cc,$nn,xedata) - set var(graph$cc,yedata) $var(graph$cc,$nn,yedata) - - PlotSetVar $varname $nn - - PlotAddData $varname - $var(proc,updateelement) $varname - $var(proc,updategraph) $varname - PlotStats $varname - PlotList $varname -} - proc PlotDestroy {varname} { upvar #0 $varname var global $varname @@ -841,36 +516,6 @@ proc PlotListDestroyCB {varname} { set var(list) 0 } -proc PlotLoadData {varname} { - upvar #0 $varname var - global $varname - - set filename [OpenFileDialog apdatafbox] - if {$filename != {}} { - set dim xy - if {[PlotDataFormatDialog dim]} { - PlotLoadDataFile $varname $filename $dim - } - } -} - -# used by backup -proc PlotLoadDataFile {varname filename dim} { - upvar #0 $varname var - global $varname - - set ch [open $filename] - set data [read $ch] - close $ch - - PlotRaise $varname - - PlotDataSet $varname $dim $data - $var(proc,updategraph) $varname - PlotStats $varname - PlotList $varname -} - proc PlotNextColor {which} { switch -- $which { black {return red} @@ -908,73 +553,6 @@ proc PlotRaise {varname} { return 0 } -proc PlotSaveData {varname} { - upvar #0 $varname var - global $varname - - set tt $var(graph,total) - set cc $var(graph,current) - - if {$var(graph$cc,xdata) == {}} { - return - } - - PlotSaveDataFile $varname [SaveFileDialog apdatafbox] -} - -proc PlotSaveDataFile {varname filename} { - upvar #0 $varname var - global $varname - - set tt $var(graph,total) - set cc $var(graph,current) - - if {$var(graph$cc,xdata) == {}} { - return - } - - if {$filename == {}} { - return - } - - global $var(graph$cc,xdata) $var(graph$cc,ydata) \ - $var(graph$cc,xedata) $var(graph$cc,yedata) - set ll [$var(graph$cc,xdata) length] - set xx [$var(graph$cc,xdata) range] - set yy [$var(graph$cc,ydata) range] - - set ch [open $filename w] - switch $var(graph$cc,dim) { - xy { - for {set ii 0} {$ii<$ll} {incr ii} { - puts $ch "[lindex $xx $ii] [lindex $yy $ii]" - } - } - xyex { - set xe [$var(graph$cc,xedata) range] - for {set ii 0} {$ii<$ll} {incr ii} { - puts $ch "[lindex $xx $ii] [lindex $yy $ii] [lindex $xe $ii]" - } - } - xyey { - set ye [$var(graph$cc,yedata) range] - for {set ii 0} {$ii<$ll} {incr ii} { - puts $ch "[lindex $xx $ii] [lindex $yy $ii] [lindex $ye $ii]" - } - } - xyexey { - set xe [$var(graph$cc,xedata) range] - set ye [$var(graph$cc,yedata) range] - for {set ii 0} {$ii<$ll} {incr ii} { - puts $ch "[lindex $xx $ii] [lindex $yy $ii] [lindex $xe $ii] [lindex $ye $ii]" - } - } - } - close $ch - - PlotRaise $varname -} - proc PlotStats {varname} { upvar #0 $varname var global $varname diff --git a/ds9/library/plotbar.tcl b/ds9/library/plotbar.tcl index 875b1ef..62b7811 100644 --- a/ds9/library/plotbar.tcl +++ b/ds9/library/plotbar.tcl @@ -95,19 +95,19 @@ proc PlotBarDialog {varname wtt title xaxis yaxis} { # Relief menu $var(mb).data.relief $var(mb).data.relief add radiobutton -label [msgcat::mc {Flat}] \ - -variable ${varname}(bar,relief) -value flat \ + -variable ${varname}(graph$cc,bar,relief) -value flat \ -command [list PlotBarUpdateElement $varname] $var(mb).data.relief add radiobutton -label [msgcat::mc {Sunken}] \ - -variable ${varname}(bar,relief) -value sunken \ + -variable ${varname}(graph$cc,bar,relief) -value sunken \ -command [list PlotBarUpdateElement $varname] $var(mb).data.relief add radiobutton -label [msgcat::mc {Raised}] \ - -variable ${varname}(bar,relief) -value raised \ + -variable ${varname}(graph$cc,bar,relief) -value raised \ -command [list PlotBarUpdateElement $varname] $var(mb).data.relief add radiobutton -label [msgcat::mc {Solid}] \ - -variable ${varname}(bar,relief) -value solid \ + -variable ${varname}(graph$cc,bar,relief) -value solid \ -command [list PlotBarUpdateElement $varname] $var(mb).data.relief add radiobutton -label [msgcat::mc {Groove}] \ - -variable ${varname}(bar,relief) -value groove \ + -variable ${varname}(graph$cc,bar,relief) -value groove \ -command [list PlotBarUpdateElement $varname] # Error @@ -190,7 +190,7 @@ proc PlotBarUpdateElement {varname} { $var(graph$cc) element configure "d-${nn}" \ -label $var(graph$cc,name) -hide [expr !$var(graph$cc,show)] \ - -relief $var(bar,relief) -color $var(graph$cc,color) \ + -relief $var(graph$cc,bar,relief) -color $var(graph$cc,color) \ -showerrorbars $show -errorbarcolor $var(graph$cc,error,color) \ -errorbarwidth $var(graph$cc,error,width) -errorbarcap $cap } diff --git a/ds9/library/plotconfig.tcl b/ds9/library/plotconfig.tcl new file mode 100644 index 0000000..085faaa --- /dev/null +++ b/ds9/library/plotconfig.tcl @@ -0,0 +1,287 @@ +# Copyright (C) 1999-2018 +# Smithsonian Astrophysical Observatory, Cambridge, MA, USA +# For conditions of distribution and use, see copyright notice in "copyright" + +package provide DS9 1.0 + +proc PlotLoadConfig {varname} { + upvar #0 $varname var + global $varname + + PlotLoadConfigFile $varname [OpenFileDialog apconfigfbox] +} + +# used by backup +proc PlotLoadConfigFile {varname filename} { + upvar #0 $varname var + global $varname + + set tt $var(graph,total) + set cc $var(graph,current) + + if {$filename == {}} { + return + } + + source $filename + # array set $varname [array get analysisplot] + + set var(graph,bg) $analysisplot(graph,bg) + + set var(graph,title) $analysisplot(graph,title) + set var(graph,title,family) $analysisplot(graph,title,family) + set var(graph,title,size) $analysisplot(graph,title,size) + set var(graph,title,weight) $analysisplot(graph,title,weight) + set var(graph,title,slant) $analysisplot(graph,title,slant) + + set var(legend) $analysisplot(legend) + set var(legend,title) $analysisplot(legend,title) + set var(legend,position) $analysisplot(legend,position) + set var(legend,title,family) $analysisplot(legend,title,family) + set var(legend,title,size) $analysisplot(legend,title,size) + set var(legend,title,weight) $analysisplot(legend,title,weight) + set var(legend,title,slant) $analysisplot(legend,title,slant) + set var(legend,font,family) $analysisplot(legend,font,family) + set var(legend,font,size) $analysisplot(legend,font,size) + set var(legend,font,weight) $analysisplot(legend,font,weight) + set var(legend,font,slant) $analysisplot(legend,font,slant) + + set var(axis,x,title) $analysisplot(axis,x,title) + set var(axis,x,grid) $analysisplot(axis,x,grid) + set var(axis,x,log) $analysisplot(axis,x,log) + set var(axis,x,flip) $analysisplot(axis,x,flip) + set var(axis,x,auto) $analysisplot(axis,x,auto) + set var(axis,x,min) $analysisplot(axis,x,min) + set var(axis,x,max) $analysisplot(axis,x,max) + set var(axis,x,format) $analysisplot(axis,x,format) + + set var(axis,y,title) $analysisplot(axis,y,title) + set var(axis,y,grid) $analysisplot(axis,y,grid) + set var(axis,y,log) $analysisplot(axis,y,log) + set var(axis,y,flip) $analysisplot(axis,y,flip) + set var(axis,y,auto) $analysisplot(axis,y,auto) + set var(axis,y,min) $analysisplot(axis,y,min) + set var(axis,y,max) $analysisplot(axis,y,max) + set var(axis,y,format) $analysisplot(axis,y,format) + + set var(axis,title,family) $analysisplot(axis,title,family) + set var(axis,title,size) $analysisplot(axis,title,size) + set var(axis,title,weight) $analysisplot(axis,title,weight) + set var(axis,title,slant) $analysisplot(axis,title,slant) + + set var(axis,font,family) $analysisplot(axis,font,family) + set var(axis,font,size) $analysisplot(axis,font,size) + set var(axis,font,weight) $analysisplot(axis,font,weight) + set var(axis,font,slant) $analysisplot(axis,font,slant) + + set var(graph$cc,show) $analysisplot(show) + set var(graph$cc,smooth) $analysisplot(smooth) + set var(graph$cc,color) $analysisplot(color) + set var(graph$cc,fill) $analysisplot(fill) + set var(graph$cc,fill,color) $analysisplot(fill,color) + set var(graph$cc,width) $analysisplot(width) + set var(graph$cc,dash) $analysisplot(dash) + + set var(graph$cc,shape,symbol) $analysisplot(shape,symbol) + set var(graph$cc,shape,fill) $analysisplot(shape,fill) + set var(graph$cc,shape,color) $analysisplot(shape,color) + + set var(graph$cc,error) $analysisplot(error) + set var(graph$cc,error,cap) $analysisplot(error,cap) + set var(graph$cc,error,color) $analysisplot(error,color) + set var(graph$cc,error,width) $analysisplot(error,width) + + set var(graph$cc,bar,relief) $analysisplot(bar,relief) + set var(graph$cc,bar,mode) $analysisplot(bar,mode) + + unset analysisplot + + # backward compatibility + FixVar ${varname}(axis,x,grid) ${varname}(graph,x,grid) + FixVar ${varname}(axis,x,log) ${varname}(graph,x,log) + FixVar ${varname}(axis,x,flip) ${varname}(graph,x,flip) + FixVar ${varname}(axis,y,grid) ${varname}(graph,y,grid) + FixVar ${varname}(axis,y,log) ${varname}(graph,y,log) + FixVar ${varname}(axis,y,flip) ${varname}(graph,y,flip) + + FixVar ${varname}(graph,title,family) ${varname}(titleFont) + FixVar ${varname}(graph,title,size) ${varname}(titleSize) + FixVar ${varname}(graph,title,weight) ${varname}(titleWeight) + FixVar ${varname}(graph,title,slant) ${varname}(titleSlant) + + FixVar ${varname}(axis,title,family) ${varname}(textlabFont) + FixVar ${varname}(axis,title,size) ${varname}(textlabSize) + FixVar ${varname}(axis,title,weight) ${varname}(textlabWeight) + FixVar ${varname}(axis,title,slant) ${varname}(textlabSlant) + + FixVar ${varname}(axis,font,family) ${varname}(numlabFont) + FixVar ${varname}(axis,font,size) ${varname}(numlabSize) + FixVar ${varname}(axis,font,weight) ${varname}(numlabWeight) + FixVar ${varname}(axis,font,slant) ${varname}(numlabSlant) + + FixVar ${varname}(graph$cc,show) ${varname}(linear) + FixVar ${varname}(graph$cc,shape,color) ${varname}(discrete,color) + FixVar ${varname}(graph$cc,shape,fill) ${varname}(discrete,fill) + FixVar ${varname}(graph$cc,width) ${varname}(linear,width) + FixVar ${varname}(graph$cc,color) ${varname}(linear,color) + if {[info exists ${varname}(linear,dash)]} { + set var(linear,dash) [FromYesNo $var(linear,dash)] + } + FixVar ${varname}(graph$cc,dash) ${varname}(linear,dash) + + if {[info exists ${varname}(discrete)]} { + if {$var(discrete)} { + FixVar ${varname}(graph$cc,shape,symbol) \ + ${varname}(discrete,symbol) + } else { + FixVarRm ${varname}(discrete,symbol) + } + } + + FixVarRm ${varname}(bar) + FixVarRm ${varname}(bar,color) + + FixVarRm ${varname}(discrete) + + FixVarRm ${varname}(quadratic) + FixVarRm ${varname}(quadratic,width) + FixVarRm ${varname}(quadratic,color) + FixVarRm ${varname}(quadratic,dash) + + FixVarRm ${varname}(step) + FixVarRm ${varname}(step,color) + FixVarRm ${varname}(step,dash) + FixVarRm ${varname}(step,width) + + if {[info exists var(grid)]} { + set var(axis,x,grid) $var(grid) + set var(axis,y,grid) $var(grid) + unset var(grid) + } + if {[info exists var(format)]} { + set var(graph,format) $var(format) + set var(axis,x,format) $var(format,x) + set var(axis,y,format) $var(format,y) + unset var(format) + unset var(format,x) + unset var(format,y) + } + + if {[info exists var(grid,log)]} { + switch $var(grid,log) { + linearlinear { + set var(axis,x,log) 0 + set var(axis,y,log) 0 + } + linearlog { + set var(axis,x,log) 0 + set var(axis,y,log) 1 + } + loglinear { + set var(axis,x,log) 1 + set var(axis,y,log) 0 + } + loglog { + set var(axis,x,log) 1 + set var(axis,y,log) 1 + } + } + unset var(grid,log) + } + + $var(proc,updategraph) $varname + $var(proc,updateelement) $varname +} + +proc PlotSaveConfig {varname} { + upvar #0 $varname var + global $varname + + PlotSaveConfigFile $varname [SaveFileDialog apconfigfbox] +} + +proc PlotSaveConfigFile {varname filename} { + upvar #0 $varname var + global $varname + + set tt $var(graph,total) + set cc $var(graph,current) + + if {$filename == {}} { + return + } + + set ch [open $filename w] + + set analysisplot(graph,bg) $var(graph,bg) + + set analysisplot(graph,title) $var(graph,title) + set analysisplot(graph,title,family) $var(graph,title,family) + set analysisplot(graph,title,size) $var(graph,title,size) + set analysisplot(graph,title,weight) $var(graph,title,weight) + set analysisplot(graph,title,slant) $var(graph,title,slant) + + set analysisplot(legend) $var(legend) + set analysisplot(legend,title) $var(legend,title) + set analysisplot(legend,position) $var(legend,position) + set analysisplot(legend,title,family) $var(legend,title,family) + set analysisplot(legend,title,size) $var(legend,title,size) + set analysisplot(legend,title,weight) $var(legend,title,weight) + set analysisplot(legend,title,slant) $var(legend,title,slant) + set analysisplot(legend,font,family) $var(legend,font,family) + set analysisplot(legend,font,size) $var(legend,font,size) + set analysisplot(legend,font,weight) $var(legend,font,weight) + set analysisplot(legend,font,slant) $var(legend,font,slant) + + set analysisplot(axis,x,title) $var(axis,x,title) + set analysisplot(axis,x,grid) $var(axis,x,grid) + set analysisplot(axis,x,log) $var(axis,x,log) + set analysisplot(axis,x,flip) $var(axis,x,flip) + set analysisplot(axis,x,auto) $var(axis,x,auto) + set analysisplot(axis,x,min) $var(axis,x,min) + set analysisplot(axis,x,max) $var(axis,x,max) + set analysisplot(axis,x,format) $var(axis,x,format) + + set analysisplot(axis,y,title) $var(axis,y,title) + set analysisplot(axis,y,grid) $var(axis,y,grid) + set analysisplot(axis,y,log) $var(axis,y,log) + set analysisplot(axis,y,flip) $var(axis,y,flip) + set analysisplot(axis,y,auto) $var(axis,y,auto) + set analysisplot(axis,y,min) $var(axis,y,min) + set analysisplot(axis,y,max) $var(axis,y,max) + set analysisplot(axis,y,format) $var(axis,y,format) + + set analysisplot(axis,title,family) $var(axis,title,family) + set analysisplot(axis,title,size) $var(axis,title,size) + set analysisplot(axis,title,weight) $var(axis,title,weight) + set analysisplot(axis,title,slant) $var(axis,title,slant) + + set analysisplot(axis,font,family) $var(axis,font,family) + set analysisplot(axis,font,size) $var(axis,font,size) + set analysisplot(axis,font,weight) $var(axis,font,weight) + set analysisplot(axis,font,slant) $var(axis,font,slant) + + set analysisplot(show) $var(graph$cc,show) + set analysisplot(smooth) $var(graph$cc,smooth) + set analysisplot(color) $var(graph$cc,color) + set analysisplot(fill) $var(graph$cc,fill) + set analysisplot(fill,color) $var(graph$cc,fill,color) + set analysisplot(width) $var(graph$cc,width) + set analysisplot(dash) $var(graph$cc,dash) + + set analysisplot(shape,symbol) $var(graph$cc,shape,symbol) + set analysisplot(shape,fill) $var(graph$cc,shape,fill) + set analysisplot(shape,color) $var(graph$cc,shape,color) + + set analysisplot(error) $var(graph$cc,error) + set analysisplot(error,cap) $var(graph$cc,error,cap) + set analysisplot(error,color) $var(graph$cc,error,color) + set analysisplot(error,width) $var(graph$cc,error,width) + + set analysisplot(bar,relief) $var(graph$cc,bar,relief) + set analysisplot(bar,mode) $var(graph$cc,bar,mode) + + puts $ch "array set analysisplot \{ [array get analysisplot] \}" + close $ch +} + diff --git a/ds9/library/plotdata.tcl b/ds9/library/plotdata.tcl new file mode 100644 index 0000000..025447e --- /dev/null +++ b/ds9/library/plotdata.tcl @@ -0,0 +1,428 @@ +# Copyright (C) 1999-2018 +# Smithsonian Astrophysical Observatory, Cambridge, MA, USA +# For conditions of distribution and use, see copyright notice in "copyright" + +package provide DS9 1.0 + +proc PlotLoadData {varname} { + upvar #0 $varname var + global $varname + + set filename [OpenFileDialog apdatafbox] + if {$filename != {}} { + set dim xy + if {[PlotDataFormatDialog dim]} { + PlotLoadDataFile $varname $filename $dim + } + } +} + +# used by backup +proc PlotLoadDataFile {varname filename dim} { + upvar #0 $varname var + global $varname + + set ch [open $filename] + set data [read $ch] + close $ch + + PlotRaise $varname + + PlotDataSet $varname $dim $data + $var(proc,updategraph) $varname + PlotStats $varname + PlotList $varname +} + +proc PlotSaveData {varname} { + upvar #0 $varname var + global $varname + + set tt $var(graph,total) + set cc $var(graph,current) + + if {$var(graph$cc,xdata) == {}} { + return + } + + PlotSaveDataFile $varname [SaveFileDialog apdatafbox] +} + +proc PlotSaveDataFile {varname filename} { + upvar #0 $varname var + global $varname + + set tt $var(graph,total) + set cc $var(graph,current) + + if {$var(graph$cc,xdata) == {}} { + return + } + + if {$filename == {}} { + return + } + + global $var(graph$cc,xdata) $var(graph$cc,ydata) \ + $var(graph$cc,xedata) $var(graph$cc,yedata) + set ll [$var(graph$cc,xdata) length] + set xx [$var(graph$cc,xdata) range] + set yy [$var(graph$cc,ydata) range] + + set ch [open $filename w] + switch $var(graph$cc,dim) { + xy { + for {set ii 0} {$ii<$ll} {incr ii} { + puts $ch "[lindex $xx $ii] [lindex $yy $ii]" + } + } + xyex { + set xe [$var(graph$cc,xedata) range] + for {set ii 0} {$ii<$ll} {incr ii} { + puts $ch "[lindex $xx $ii] [lindex $yy $ii] [lindex $xe $ii]" + } + } + xyey { + set ye [$var(graph$cc,yedata) range] + for {set ii 0} {$ii<$ll} {incr ii} { + puts $ch "[lindex $xx $ii] [lindex $yy $ii] [lindex $ye $ii]" + } + } + xyexey { + set xe [$var(graph$cc,xedata) range] + set ye [$var(graph$cc,yedata) range] + for {set ii 0} {$ii<$ll} {incr ii} { + puts $ch "[lindex $xx $ii] [lindex $yy $ii] [lindex $xe $ii] [lindex $ye $ii]" + } + } + } + close $ch + + PlotRaise $varname +} + +proc PlotDataSet {varname dim data} { + upvar #0 $varname var + global $varname + + set tt $var(graph,total) + set cc $var(graph,current) + + switch -- $dim { + 4 { + # first data set + PlotDataSetOne $varname "4.1" $data + + # set color + set col $var(graph$cc,color) + set var(graph$cc,color) [PlotNextColor $var(graph$cc,color)] + + # second data set + PlotDataSetOne $varname "4.2" $data + set var(graph$cc,color) $col + } + 5 { + # first data set + PlotDataSetOne $varname "5.1" $data + + # set color + set col $var(graph$cc,color) + set var(graph$cc,color) [PlotNextColor $var(graph$cc,color)] + + # second data set + PlotDataSetOne $varname "5.2" $data + set var(graph$cc,color) $col + } + default {PlotDataSetOne $varname $dim $data} + } +} + +proc PlotDataSetOne {varname dim data} { + upvar #0 $varname var + global $varname + + set tt $var(graph,total) + set cc $var(graph,current) + + # look for no data + if {[string length $data] == 0} { + return + } + + # total length + set ll [llength $data] + + # incr count + incr ${varname}(graph$cc,data,total) + set nn $var(graph$cc,data,total) + set var(graph$cc,data,current) $nn + + # new vector names + set xdata ap${varname}xx${nn} + set ydata ap${varname}yy${nn} + set xedata ap${varname}xe${nn} + set yedata ap${varname}ye${nn} + + # basics xy + set var(graph$cc,manage) 1 + set var(graph$cc,name) "Dataset $nn" + set var(graph$cc,xdata) $xdata + set var(graph$cc,ydata) $ydata + global $var(graph$cc,xdata) $var(graph$cc,ydata) + blt::vector create $var(graph$cc,xdata) $var(graph$cc,ydata) + + # substitute all separtors + regsub -all {[\n\r\t, ]+} $data { } data + # remove all non-numeric data + regsub -all {[^0-9.e\- ]+} $data {} data + + set x {} + set y {} + set xe {} + set ye {} + switch -- $dim { + 2 - + xy { + set var(graph$cc,dim) xy + set var(graph$cc,xedata) {} + set var(graph$cc,yedata) {} + + for {set ii 0} {$ii<$ll} {incr ii 2} { + lappend x [lindex $data $ii] + lappend y [lindex $data [expr $ii+1]] + } + $var(graph$cc,xdata) set $x + $var(graph$cc,ydata) set $y + } + + xyex { + set var(graph$cc,dim) xyex + set var(graph$cc,xedata) $xedata + set var(graph$cc,yedata) {} + + global $var(graph$cc,xedata) + blt::vector create $var(graph$cc,xedata) + + for {set ii 0} {$ii<$ll} {incr ii 3} { + lappend x [lindex $data $ii] + lappend y [lindex $data [expr $ii+1]] + lappend xe [lindex $data [expr $ii+2]] + } + $var(graph$cc,xdata) set $x + $var(graph$cc,ydata) set $y + $var(graph$cc,xedata) set $xe + } + + 3 - + xyey { + set var(graph$cc,dim) xyey + set var(graph$cc,xedata) {} + set var(graph$cc,yedata) $yedata + + global $var(graph$cc,yedata) + blt::vector create $var(graph$cc,yedata) + + for {set ii 0} {$ii<$ll} {incr ii 3} { + lappend x [lindex $data $ii] + lappend y [lindex $data [expr $ii+1]] + lappend ye [lindex $data [expr $ii+2]] + } + $var(graph$cc,xdata) set $x + $var(graph$cc,ydata) set $y + $var(graph$cc,yedata) set $ye + } + + xyexey { + set var(graph$cc,dim) xyexey + set var(graph$cc,xedata) $xedata + set var(graph$cc,yedata) $yedata + + global $var(graph$cc,xedata) $var(graph$cc,yedata) + blt::vector create $var(graph$cc,xedata) $var(graph$cc,yedata) + + for {set ii 0} {$ii<$ll} {incr ii 4} { + lappend x [lindex $data $ii] + lappend y [lindex $data [expr $ii+1]] + lappend xe [lindex $data [expr $ii+2]] + lappend ye [lindex $data [expr $ii+3]] + } + $var(graph$cc,xdata) set $x + $var(graph$cc,ydata) set $y + $var(graph$cc,xedata) set $xe + $var(graph$cc,yedata) set $ye + } + + 4.1 { + set var(graph$cc,dim) xyey + set var(graph$cc,xedata) {} + set var(graph$cc,yedata) $yedata + + global $var(graph$cc,yedata) + blt::vector create $var(graph$cc,yedata) + + for {set ii 0} {$ii<$ll} {incr ii 4} { + lappend x [lindex $data $ii] + lappend y [lindex $data [expr $ii+1]] + lappend ye [lindex $data [expr $ii+2]] + } + $var(graph$cc,xdata) set $x + $var(graph$cc,ydata) set $y + $var(graph$cc,yedata) set $ye + } + + 4.2 { + set var(graph$cc,dim) xy + set var(graph$cc,xedata) {} + set var(graph$cc,yedata) {} + + for {set ii 0} {$ii<$ll} {incr ii 4} { + lappend x [lindex $data $ii] + lappend y [lindex $data [expr $ii+3]] + } + $var(graph$cc,xdata) set $x + $var(graph$cc,ydata) set $y + } + + 5.1 { + set var(graph$cc,dim) xyey + set var(graph$cc,xedata) {} + set var(graph$cc,yedata) $yedata + + global $var(graph$cc,yedata) + blt::vector create $var(graph$cc,yedata) + + for {set ii 0} {$ii<$ll} {incr ii 5} { + lappend x [lindex $data $ii] + lappend y [lindex $data [expr $ii+1]] + lappend ye [lindex $data [expr $ii+2]] + } + $var(graph$cc,xdata) set $x + $var(graph$cc,ydata) set $y + $var(graph$cc,yedata) set $ye + } + + 5.2 { + set var(graph$cc,dim) xyey + set var(graph$cc,xedata) {} + set var(graph$cc,yedata) $yedata + + global $var(graph$cc,yedata) + blt::vector create $var(graph$cc,yedata) + + for {set ii 0} {$ii<$ll} {incr ii 5} { + lappend x [lindex $data $ii] + lappend y [lindex $data [expr $ii+3]] + lappend ye [lindex $data [expr $ii+4]] + } + $var(graph$cc,xdata) set $x + $var(graph$cc,ydata) set $y + $var(graph$cc,yedata) set $ye + } + } + + set var(graph$cc,$nn,manage) 1 + set var(graph$cc,$nn,dim) $var(graph$cc,dim) + + set var(graph$cc,$nn,xdata) $var(graph$cc,xdata) + set var(graph$cc,$nn,ydata) $var(graph$cc,ydata) + set var(graph$cc,$nn,xedata) $var(graph$cc,xedata) + set var(graph$cc,$nn,yedata) $var(graph$cc,yedata) + + PlotGetVar $varname $nn + + # update data set menu + $var(mb).graph.select add radiobutton -label "$var(graph$cc,name)" \ + -variable ${varname}(graph$cc,data,current) -value $nn \ + -command [list PlotCurrentData $varname] + + PlotAddData $varname + $var(proc,updateelement) $varname +} + +proc PlotDupData {varname mm} { + upvar #0 $varname var + global $varname + + set tt $var(graph,total) + set cc $var(graph,current) + + if {$var(graph$cc,data,total) == 0} { + return + } + + # incr count + incr ${varname}(graph$cc,data,total) + set nn $var(graph$cc,data,total) + set pp [expr $nn-1] + + # new vector names + set var(graph$cc,$nn,name) "Dataset $nn" + set var(graph$cc,$nn,xdata) ap${varname}xx${nn} + set var(graph$cc,$nn,ydata) ap${varname}yy${nn} + set var(graph$cc,$nn,xedata) ap${varname}xe${nn} + set var(graph$cc,$nn,yedata) ap${varname}ye${nn} + global $var(graph$cc,$mm,xdata) $var(graph$cc,$mm,ydata) \ + $var(graph$cc,$mm,xedata) $var(graph$cc,$mm,yedata) + global $var(graph$cc,$nn,xdata) $var(graph$cc,$nn,ydata) \ + $var(graph$cc,$nn,xedata) $var(graph$cc,$nn,yedata) + + $var(graph$cc,$mm,xdata) dup $var(graph$cc,$nn,xdata) + $var(graph$cc,$mm,ydata) dup $var(graph$cc,$nn,ydata) + if {$var(graph$cc,$mm,xedata) != {}} { + $var(graph$cc,$mm,xedata) dup $var(graph$cc,$nn,xedata) + } else { + set var(graph$cc,$nn,xedata) {} + } + if {$var(graph$cc,$mm,yedata) != {}} { + $var(graph$cc,$mm,yedata) dup $var(graph$cc,$nn,yedata) + } else { + set var(graph$cc,$nn,yedata) {} + } + + set var(graph$cc,$nn,manage) 1 + set var(graph$cc,$nn,dim) $var(graph$cc,$mm,dim) + + set var(graph$cc,$nn,show) $var(graph$cc,$mm,show) + set var(graph$cc,$nn,shape,symbol) $var(graph$cc,$mm,shape,symbol) + set var(graph$cc,$nn,shape,fill) $var(graph$cc,$mm,shape,fill) + set var(graph$cc,$nn,shape,color) $var(graph$cc,$mm,shape,color) + set var(graph$cc,$nn,smooth) $var(graph$cc,$mm,smooth) + set var(graph$cc,$nn,color) [PlotNextColor $var(graph$cc,$mm,color)] + set var(graph$cc,$nn,fill) $var(graph$cc,$mm,fill) + set var(graph$cc,$nn,fill,color) \ + [PlotNextColor $var(graph$cc,$mm,fill,color)] + set var(graph$cc,$nn,width) $var(graph$cc,$mm,width) + set var(graph$cc,$nn,dash) $var(graph$cc,$mm,dash) + + set var(graph$cc,$nn,error) $var(graph$cc,$mm,error) + set var(graph$cc,$nn,error,cap) $var(graph$cc,$mm,error,cap) + set var(graph$cc,$nn,error,color) $var(graph$cc,$mm,error,color) + set var(graph$cc,$nn,error,width) $var(graph$cc,$mm,error,width) + + set var(graph$cc,$nn,bar,relief) $var(graph$cc,$mm,bar,relief) + + # update data set menu + $var(mb).graph.select add radiobutton -label "$var(graph$cc,$nn,name)" \ + -variable ${varname}(graph$cc,data,current) -value $nn \ + -command [list PlotCurrentData $varname] + + # make current + set var(graph$cc,data,current) $nn + + set var(graph$cc,manage) $var(graph$cc,$nn,manage) + set var(graph$cc,dim) $var(graph$cc,$nn,dim) + + set var(graph$cc,xdata) $var(graph$cc,$nn,xdata) + set var(graph$cc,ydata) $var(graph$cc,$nn,ydata) + set var(graph$cc,xedata) $var(graph$cc,$nn,xedata) + set var(graph$cc,yedata) $var(graph$cc,$nn,yedata) + + PlotSetVar $varname $nn + + PlotAddData $varname + $var(proc,updateelement) $varname + $var(proc,updategraph) $varname + PlotStats $varname + PlotList $varname +} + |