Changeset 756


Ignore:
Timestamp:
Dec 4, 2009 5:11:29 PM (13 years ago)
Author:
toby
Message:

# on 2003/11/21 00:46:52, toby did:
add export to grace & .csv options

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/widplt

    • Property rcs:date changed from 2003/11/13 17:21:00 to 2003/11/21 00:46:52
    • Property rcs:lines changed from +6 -2 to +152 -28
    • Property rcs:rev changed from 1.15 to 1.16
    r748 r756  
    6767proc getprofiles {expnam} {
    6868    global WidSetList absSetList wave XY UVWP lblarr ttrange
    69 
    70     if {[expload $expnam] == -1} {
    71         tk_dialog .err "EXP Error" "Warning -- Unable to read $expnam" \
     69    global expmap
     70
     71    if {$expnam != ""} {
     72        if {[expload $expnam] == -1} {
     73            tk_dialog .err "EXP Error" "Warning -- Unable to read $expnam" \
    7274                error 0 OK
    73         return
    74     }
    75     mapexp
    76 
    77     global expmap
     75            return
     76        }
     77        mapexp
     78    } else {
     79        set expmap(powderlist) {}
     80    }
    7881    foreach hist $expmap(powderlist) {
    7982        # wavelength
     
    8588            global ABS
    8689            set ABS($hist) [list \
    87                     [histinfo $hist abscor1] \
    88                     [histinfo $hist abscor2] \
    89                     [histinfo $hist abstype] \
    90                     $drange \
    91                     "Hist $hist" \
    92                     $expmap(htype_$hist)]
     90                                [histinfo $hist abscor1] \
     91                                [histinfo $hist abscor2] \
     92                                [histinfo $hist abstype] \
     93                                $drange \
     94                                "Hist $hist" \
     95                                $expmap(htype_$hist)]
    9396            lappend absSetList $hist
    9497        } else {
     
    106109                if {$ptype == 1} {
    107110                    set UVWP($key) [list [hapinfo $hist $phase pterm1] \
    108                             [hapinfo $hist $phase pterm2] \
    109                             [hapinfo $hist $phase pterm3] 0]
     111                                        [hapinfo $hist $phase pterm2] \
     112                                        [hapinfo $hist $phase pterm3] 0]
    110113                    set XY($key) {0 0}
    111114                } elseif {$ptype == 2} {
    112115                    set UVWP($key) [list [hapinfo $hist $phase pterm1] \
    113                             [hapinfo $hist $phase pterm2] \
    114                             [hapinfo $hist $phase pterm3] \
    115                             [hapinfo $hist $phase pterm9]]
     116                                        [hapinfo $hist $phase pterm2] \
     117                                        [hapinfo $hist $phase pterm3] \
     118                                        [hapinfo $hist $phase pterm9]]
    116119                    set XY($key) [list [hapinfo $hist $phase pterm4] \
    117                             [hapinfo $hist $phase pterm5]]
     120                                      [hapinfo $hist $phase pterm5]]
    118121                } elseif {$ptype == 3 || $ptype == 4} {
    119122                    set UVWP($key) [list [hapinfo $hist $phase pterm1] \
    120                             [hapinfo $hist $phase pterm2] \
    121                             [hapinfo $hist $phase pterm3] \
    122                             [hapinfo $hist $phase pterm4]]
     123                                        [hapinfo $hist $phase pterm2] \
     124                                        [hapinfo $hist $phase pterm3] \
     125                                        [hapinfo $hist $phase pterm4]]
    123126                    if {$ptype == 3} {
    124127                        set XY($key) [list [hapinfo $hist $phase pterm5] \
    125                                 [hapinfo $hist $phase pterm6]]
     128                                          [hapinfo $hist $phase pterm6]]
    126129                    } else {
    127130                        set XY($key) [list [hapinfo $hist $phase pterm5] 0]
     
    956959}
    957960
     961#-------------------------------------------------------------------------
     962# export current plot to Grace
     963#-------------------------------------------------------------------------
     964if {$tcl_platform(platform) == "unix"} {
     965    set graph(GraceFile) /tmp/grace_out.agr
     966} else {
     967    set graph(GraceFile) C:/graceout.agr
     968}
     969proc exportgrace {} {
     970    global graph box
     971    global tcl_platform graph
     972    catch {toplevel .export}
     973    raise .export
     974    eval destroy [grid slaves .export]
     975    set col 5
     976    grid [label .export.1a -text Title:] -column 1 -row 1
     977    set graph(title) [$box cget -title]
     978    grid [entry .export.1b -width 60 -textvariable graph(title)] \
     979            -column 2 -row 1 -columnspan 4
     980    grid [label .export.2a -text Subtitle:] -column 1 -row 2
     981    grid [entry .export.2b -width 60 -textvariable graph(subtitle)] \
     982            -column 2 -row 2 -columnspan 4
     983    grid [label .export.3a -text "File name:"] -column 1 -row 3
     984    grid [entry .export.3b -width 60 -textvariable graph(GraceFile)] \
     985            -column 2 -row 3 -columnspan 4
     986    grid [button .export.help -text Help -bg yellow \
     987            -command "MakeWWWHelp liveplot.html grace"] \
     988            -column [incr col -1] -row 4
     989    grid [button .export.c -text "Close" \
     990            -command "set graph(export) 0; destroy .export"] \
     991            -column [incr col -1] -row 4
     992    if {$tcl_platform(platform) == "unix" && [auto_execok xmgrace] != ""} {
     993        grid [button .export.d -text "Export & \nstart grace" \
     994            -command "set graph(export) 1; destroy .export"] \
     995                -column [incr col -1] -row 4
     996    }
     997    grid [button .export.e -text "Export" \
     998            -command "set graph(export) 2; destroy .export"] \
     999            -column [incr col -1] -row 4
     1000    tkwait window .export
     1001    if {$graph(export) == 0} return
     1002    if {[catch {
     1003        set fp [open $graph(GraceFile) w]
     1004        puts $fp [output_grace $box $graph(title) $graph(subtitle)]
     1005        close $fp
     1006    } errmsg]} {
     1007        MyMessageBox -parent . -title "Export Error" \
     1008                -message "An error occured during the export: $errmsg" \
     1009                -icon error -type Ignore -default ignore
     1010        return
     1011    }
     1012
     1013    if {$graph(export) == 1} {
     1014        set err [catch {exec xmgrace $graph(GraceFile) &} errmsg]
     1015        if $err {
     1016        MyMessageBox -parent . -title "Grace Error" \
     1017                -message "An error occured launching grace (xmgrace): $errmsg" \
     1018                -icon error -type Ignore -default ignore
     1019        }
     1020    } else {
     1021        MyMessageBox -parent . -title "OK" \
     1022                -message "File $graph(GraceFile) created" \
     1023                -type OK -default ok
     1024    }
     1025}
     1026#-------------------------------------------------------------------------
     1027# export current plot as .csv file
     1028#-------------------------------------------------------------------------
     1029proc makecsvfile {} {
     1030    global graph box expnam program
     1031    global tcl_platform graph
     1032    set typelist {
     1033        {{Comma separated} {.csv}        }
     1034        {{Text File}       {.txt}        }
     1035    }
     1036    set file [tk_getSaveFile -filetypes $typelist \
     1037            -initialfile ${expnam}_$program.csv]
     1038    if {$file == ""} return
     1039    set varlist {}
     1040    set line {}
     1041    foreach element_name [$box element names] {
     1042        lappend varlist ${element_name}_x
     1043        set ${element_name}_x [$box element cget $element_name -xdata]
     1044        lappend varlist ${element_name}_y
     1045        set ${element_name}_y [$box element cget $element_name -ydata]
     1046        append line [$box element cget $element_name -label] "-X, "
     1047        append line [$box element cget $element_name -label] "-Y, "
     1048    }
     1049    set fp [open $file w]
     1050    # get x and y axis limits
     1051    foreach v {x y} {
     1052        foreach "${v}min ${v}max" [$box ${v}axis limits] {}
     1053        puts $fp "\"$v axis range [set ${v}min] to [set ${v}max]\""
     1054        puts $fp "\"$v axis label [$box ${v}axis cget -title]\""
     1055    }
     1056    puts $fp $line
     1057    set i 0
     1058    set done 1
     1059    while {$done} {
     1060        set line {}
     1061        set done 0
     1062        foreach var $varlist {
     1063            set val [lindex [set $var] $i]
     1064            if {$val != ""} {set done 1}
     1065            append line "$val, "
     1066        }
     1067        if {$done} {puts $fp $line}
     1068        incr i
     1069    }
     1070    close $fp
     1071}
     1072
     1073
    9581074set graph(legend) 0
    9591075set graph(equivwave) {}
     
    10661182    .a.file.menu add cascade -label "Edit Curve" -menu .a.file.menu.edit
    10671183}
     1184#.a.file.menu add command -label "Make PostScript" -command makepostscriptout
    10681185menu .a.file.menu.edit
    1069 .a.file.menu add command -label "Make PostScript" -command makepostscriptout
     1186.a.file.menu add cascade -label "Export plot" -menu .a.file.menu.export
     1187menu .a.file.menu.export
     1188.a.file.menu.export add command -label "Make PostScript" \
     1189    -command makepostscriptout
     1190if {$blt_version > 2.3 && $blt_version != 8.0} {
     1191    source [file join $expgui(scriptdir) graceexport.tcl]
     1192    .a.file.menu.export add command -label "to Grace" -command exportgrace
     1193}
     1194.a.file.menu.export add command -label "as .csv file" \
     1195        -command makecsvfile
    10701196.a.file.menu add command -label Quit -command "destroy ."
    10711197pack [menubutton .a.options -text Options -underline 0 -menu .a.options.menu] \
     
    11061232#----------------------------------------------------------------
    11071233# OK now go get the profile info
    1108 if {$expnam != ""} {
    1109     getprofiles $expnam
    1110 }
     1234getprofiles $expnam
    11111235#----------------------------------------------------------------
    11121236
Note: See TracChangeset for help on using the changeset viewer.