Changeset 655


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

# on 2002/10/24 19:24:01, toby did:
Add export capability to comma separated value (.csv) files for spreadsheets
and graphics programs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/liveplot

    • Property rcs:date changed from 2002/09/05 18:16:49 to 2002/10/24 19:24:01
    • Property rcs:lines changed from +6 -6 to +40 -2
    • Property rcs:rev changed from 1.28 to 1.29
    r642 r655  
    828828    }
    829829}
     830#-------------------------------------------------------------------------
     831# export current plot as .csv file
     832#-------------------------------------------------------------------------
     833proc makecsvfile {} {
     834    global graph box expnam hst
     835    global tcl_platform graph
     836    set typelist {
     837        {{Comma separated} {.csv}        }
     838        {{Text File}       {.txt}        }
     839    }
     840    set file [tk_getSaveFile -filetypes $typelist \
     841            -initialfile ${expnam}_$hst.csv]
     842    if {$file == ""} return
     843    foreach vec {xvec obsvec calcvec bckvec diffvec wifdvec} \
     844            var {X    O      C       B      D       CC     } {
     845        set $var {}
     846        catch {set $var [$vec range 0 end]}
     847    }
     848    set fp [open $file w]
     849    # get x and y axis limits
     850    foreach v {x y} {
     851        foreach "${v}min ${v}max" [$graph(blt) ${v}axis limits] {}
     852        puts $fp "\"$v axis range [set ${v}min] to [set ${v}max]\""
     853        global ${v}units
     854        puts $fp "\"$v axis label [set ${v}units]\""
     855    }
     856    puts $fp {"Columns are X I(obs) I(calc) I(bkg) Obs-Calc cum-chi**2 refpos ref-phase ref-hkl"}
     857    global refhkllist refphaselist refpos
     858    foreach x $X o $O c $C b $B d $D cc $CC \
     859            hkl $refhkllist rphase $refphaselist rp $refpos {
     860        # replace commas with spaces
     861        regsub -all "," $hkl " " hkl
     862        puts $fp ", $x, $o, $c, $b, $d, $cc, $rp, $rphase, [list $hkl],"
     863    }
     864    close $fp
     865}
    830866
    831867proc setlblopts {} {
     
    19652001}
    19662002.a.file.menu add command -label Quit -command "destroy ."
     2003.a.file.menu.export add command -label "as .csv file" \
     2004        -command makecsvfile
    19672005
    19682006pack [menubutton .a.options -text Options -underline 0 -menu .a.options.menu] \
Note: See TracChangeset for help on using the changeset viewer.