#!/bin/sh  
# \
exec oagwish "$0" "$@"



set CVSRevisionAuthor "\$Revision: 1.11 $ \$Author: soliday $"
set auto_path [linsert $auto_path 0  /usr/local/oag/apps/lib/$env(HOST_ARCH)]
set auto_path [linsert $auto_path 0 /usr/local/oag/lib_patch/$env(HOST_ARCH)]
APSStandardSetup

proc ConvertICTFCWaveform {args} {
    global waveformDir archiveDir fileRoot fcScopeChannel ictScopeChannel ictTurns cableImpedance droopFactor plotOnly
    global dataDirectory
    
    set tmpRoot /tmp/[APSTmpString]
    if ![file exist $archiveDir] {
        exec mkdir -p $archiveDir
        exec chmod 0755 $archiveDir
    }
    cd $archiveDir
    if ![file exists $waveformDir/$dataDirectory] {
        SetStatus "Data directory $waveformDir/$dataDirectory does not exist!"
        return
    }
    if ![file exists $waveformDir/$dataDirectory/${fileRoot}_${ictScopeChannel}.wfm] {
        SetStatus "$waveformDir/$dataDirectory/${fileRoot}_${ictScopeChannel}.wfm does not exist!"
        return
    }
    if ![file exists $waveformDir/$dataDirectory/${fileRoot}_${fcScopeChannel}.wfm] {
        SetStatus "$waveformDir/$dataDirectory/${fileRoot}_${fcScopeChannel}.wfm does not exist!"
        return
    }
    
    if ![file exists ${fileRoot}_${ictScopeChannel}.wfm] {
        exec cp ${waveformDir}/$dataDirectory/${fileRoot}_${ictScopeChannel}.wfm .
    }
    if ![file exists ${fileRoot}_${fcScopeChannel}.wfm] {
        exec cp ${waveformDir}/$dataDirectory/${fileRoot}_${fcScopeChannel}.wfm .
    }
    set timeStamp [clock format [file mtime $waveformDir/$dataDirectory/${fileRoot}_${ictScopeChannel}.wfm]]
    if {![file exists ${fileRoot}_${ictScopeChannel}.sdds] || ![file exists ${fileRoot}_${fcScopeChannel}.sdds]} {
        if [catch {exec sddslogger -erase -step=1 /home/helios/oagData/ITS/ICTFC_scalars.mon $tmpRoot.1
            exec sddsexpand $tmpRoot.1 -pipe=out \
                     | sddsconvert -pipe=in $tmpRoot.2 -del=par,Time } result] {
            return -code error "Unable to read ITCFC scalars: $result"
        }
        
        # Convert the waveform files to sdds files and add gun PVs.
        
        foreach root [list ${fileRoot}_${ictScopeChannel} ${fileRoot}_${fcScopeChannel}] {
            if [catch {exec wfm2sdds -pipe=out $root.wfm \
                         | sddsxref -pipe $tmpRoot.2 -transfer=par,* \
                         | sddsprocess -pipe=in $root.sdds } result] {
                return -code error "Error in processing ICT FC ($root) waveform files: $result"
            }
            if [catch {exec sddsbaseline $root.sdds $root.base \
                         -col=Signal \
                         -select=endpoints=10 \
                         -method=average } result] {
                return -code error "Error in getting the baseline of $root: $result"
            }
        }
        # Process the ICT signal to get the total charge
        if [catch {exec sddsprocess ${fileRoot}_${ictScopeChannel}.base ${fileRoot}_${ictScopeChannel}.charge \
                     -process=Signal,integ,SignalInteg,functionOf=t \
                     "-redefine=param,Charge,SignalInteg ${ictTurns} * ${cableImpedance} / 1.0e9 * ${droopFactor} *,units=nC" \
                     "-redefine=param,SignalInteg,SignalInteg 1.0e9 *,units=nVs" \
                     "-print=param,ChargeString,ICT Charge = %0.2f %s,Charge,Charge.units" \
                     "-print=param,SignalIntegString,ICT Integ = %0.2f %s,SignalInteg,SignalInteg.units" \
                     "-redefine=col,t,t 1.0e6 *,units=\$gm\$rs"
            exec sddssmooth -pipe=out ${fileRoot}_${ictScopeChannel}.charge \
                     -col=Signal -points=11 -passes=50 \
                     | sddsprocess -pipe=in ${fileRoot}_${ictScopeChannel}.smo \
                     -process=Signal,minimum,SignalPeak \
                     -process=Signal,minimum,SignalPeakTime,functionOf=t,position \
                     "-print=param,SignalPeakString,ICT Peak = %0.2f %s,SignalPeak,SignalPeak.units" } result] {
            return -code error "Error in processing ICT signal: $result"
        }
        
        # Process the FC signal and use the ICT total charge to get the current signal
        
        if [catch {exec sddsprocess -pipe=out ${fileRoot}_${fcScopeChannel}.base \
                     -process=Signal,integ,SignalInteg,functionOf=t \
                     "-redefine=param,SignalInteg,SignalInteg 1.0e9 *,units=nVs" \
                     | sddsxref -pipe ${fileRoot}_${ictScopeChannel}.charge \
                     -transfer=param,Charge -leave=* \
                     | sddsprocess -pipe=in ${fileRoot}_${fcScopeChannel}.current \
                     "-redefine=col,Current,Signal SignalInteg / Charge * 1000.0 *,units=mA" \
                     -process=Current,integ,CurrentInteg,functionOf=t \
                     "-redefine=param,ChargeFromCurrent,CurrentInteg 1000.0 / 1.0e9 *,units=nC" \
                     "-print=param,ChargeString,ICT Charge = %0.2f %s,Charge,Charge.units" \
                     "-print=param,SignalIntegString,FC Integ = %0.2f %s,SignalInteg,SignalInteg.units" \
                     "-redefine=col,t,t 1.0e6 *,units=\$gm\$rs"
            exec sddssmooth -pipe=out ${fileRoot}_${fcScopeChannel}.current \
                     -col=Signal,Current -points=11 -passes=50 \
                     | sddsprocess -pipe=in ${fileRoot}_${fcScopeChannel}.smo \
                     -process=Signal,minimum,SignalPeak \
                     -process=Signal,minimum,SignalPeakTime,functionOf=t,position \
                     "-print=param,SignalPeakString,FC Peak = %0.2f %s,SignalPeak,SignalPeak.units" \
                     -process=Current,minimum,CurrentPeak \
                     -process=Current,minimum,CurrentPeakTime,functionOf=t,position \
                     "-print=param,CurrentPeakString,Peak Current = %0.2f %s,CurrentPeak,CurrentPeak.units"} result] {
            return -code error "Error in processing FC signal: $result"
        }
    }
    if {0} {
    exec sddsplot -layout=1,2 -graph=line,vary "-topline=$timeStamp" \
      -subticksettings=xdivisions=5,ydivisions=5 \
      -col=t,Signal ${fileRoot}_${ictScopeChannel}.sdds -leg=spec=Orig \
      -col=t,Signal ${fileRoot}_${ictScopeChannel}.base -leg=spec=Base_Sub \
      "-title=ICT Raw and Baseline Subtracted Waveforms" -end \
      -col=t,Signal ${fileRoot}_${fcScopeChannel}.sdds -leg=spec=Orig \
      -col=t,Signal ${fileRoot}_${fcScopeChannel}.base -leg=spec=Base_Sub \
      "-title=FC Raw and Baseline Subtracted Waveforms" \&
    }
    exec sddsplot -layout=1,2 -graph=line,vary "-topline=$timeStamp" \
      -subticksettings=xdivisions=5,ydivisions=5 \
      -col=t,Signal ${fileRoot}_${ictScopeChannel}.charge -leg=spec=ICT \
      -string=@SignalIntegString,p=0.6,q=0.15,scale=0.9 \
      -col=t,Signal ${fileRoot}_${fcScopeChannel}.current -leg=spec=FC \
      -string=@SignalIntegString,p=0.6,q=0.05,scale=0.9 \
      -param=SignalPeakTime,SignalPeak ${fileRoot}_${ictScopeChannel}.smo \
      -graph=symb,sca=3,type=0,sub=2 "-leg=spec=ICT Peak" \
      -string=@SignalPeakString,p=0.6,q=0.35,scale=0.9 \
      -param=SignalPeakTime,SignalPeak ${fileRoot}_${fcScopeChannel}.smo \
      -graph=symb,sca=3,type=1,sub=3 "-leg=spec=FC Peak" \
      -string=@SignalPeakString,p=0.6,q=0.25,scale=0.9 \
      "-title=FC and ICT Baseline Subtracted Waveforms and Integrals" -end \
      -col=t,Current ${fileRoot}_${fcScopeChannel}.current -leg=spec=FC \
      -string=@ChargeString,p=0.6,q=0.05,scale=0.9 \
      -param=CurrentPeakTime,CurrentPeak ${fileRoot}_${fcScopeChannel}.smo \
      -graph=symb,sca=3,sub=1 -leg=spec=Peak \
      -string=@CurrentPeakString,p=0.6,q=0.15,scale=0.9 \
      "-title=FC Current Waveform" \&
    global EPS PNG
    if {$EPS || $PNG} {
        global figureDir
        APSDialogBox .fig -name "Directory for figures" 
        APSLabeledEntry .dir -parent .fig.userFrame -label "Directory for saving figures:"  \
          -textVariable figureDir -width 70
        APSButton .daily -parent .fig.userFrame.dir -text "daily" -size small \
          -command "set figureDir [APSGoToDailyDirectory]"
        tkwait window .fig
        if $EPS {
            exec sddsplot -layout=1,2 -graph=line,vary "-topline=$timeStamp" \
              -subticksettings=xdivisions=5,ydivisions=5 \
              -col=t,Signal ${fileRoot}_${ictScopeChannel}.charge -leg=spec=ICT \
              -string=@SignalIntegString,p=0.6,q=0.15,scale=0.9 \
              -col=t,Signal ${fileRoot}_${fcScopeChannel}.current -leg=spec=FC \
              -string=@SignalIntegString,p=0.6,q=0.05,scale=0.9 \
              -param=SignalPeakTime,SignalPeak ${fileRoot}_${ictScopeChannel}.smo \
              -graph=symb,sca=3,type=0,sub=2 "-leg=spec=ICT Peak" \
              -string=@SignalPeakString,p=0.6,q=0.35,scale=0.9 \
              -param=SignalPeakTime,SignalPeak ${fileRoot}_${fcScopeChannel}.smo \
              -graph=symb,sca=3,type=1,sub=3 "-leg=spec=FC Peak" \
              -string=@SignalPeakString,p=0.6,q=0.25,scale=0.9 \
              "-title=FC and ICT Baseline Subtracted Waveforms and Integrals" -end \
              -col=t,Current ${fileRoot}_${fcScopeChannel}.current -leg=spec=FC \
              -string=@ChargeString,p=0.6,q=0.05,scale=0.9 \
              -param=CurrentPeakTime,CurrentPeak ${fileRoot}_${fcScopeChannel}.smo \
              -graph=symb,sca=3,sub=1 -leg=spec=Peak \
              -string=@CurrentPeakString,p=0.6,q=0.15,scale=0.9 \
              "-title=FC Current Waveform" \
              -output=$figureDir/${fileRoot}_${ictScopeChannel}_${fcScopeChannel}.eps \
              -dev=ceps,onwhite
        }
        if $PNG {
             exec sddsplot -layout=1,2 -graph=line,vary "-topline=$timeStamp" \
              -subticksettings=xdivisions=5,ydivisions=5 \
              -col=t,Signal ${fileRoot}_${ictScopeChannel}.charge -leg=spec=ICT \
              -string=@SignalIntegString,p=0.6,q=0.15,scale=0.9 \
              -col=t,Signal ${fileRoot}_${fcScopeChannel}.current -leg=spec=FC \
              -string=@SignalIntegString,p=0.6,q=0.05,scale=0.9 \
              -param=SignalPeakTime,SignalPeak ${fileRoot}_${ictScopeChannel}.smo \
              -graph=symb,sca=3,type=0,sub=2 "-leg=spec=ICT Peak" \
              -string=@SignalPeakString,p=0.6,q=0.35,scale=0.9 \
              -param=SignalPeakTime,SignalPeak ${fileRoot}_${fcScopeChannel}.smo \
              -graph=symb,sca=3,type=1,sub=3 "-leg=spec=FC Peak" \
              -string=@SignalPeakString,p=0.6,q=0.25,scale=0.9 \
              "-title=FC and ICT Baseline Subtracted Waveforms and Integrals" -end \
              -col=t,Current ${fileRoot}_${fcScopeChannel}.current -leg=spec=FC \
              -string=@ChargeString,p=0.6,q=0.05,scale=0.9 \
              -param=CurrentPeakTime,CurrentPeak ${fileRoot}_${fcScopeChannel}.smo \
              -graph=symb,sca=3,sub=1 -leg=spec=Peak \
               -string=@CurrentPeakString,p=0.6,q=0.15,scale=0.9 \
               "-title=FC Current Waveform" \
               -output=$figureDir/${fileRoot}_${ictScopeChannel}_${fcScopeChannel}.png \
               -dev=png,onwhite
        }
    }
}

proc AcquireITSGunRFWaveform {args} {
    global outputDir itsRootname xstart xend
    
    if ![file exist $outputDir] {
        exec mkdir -p $outputDir
        exec chmod 0755 $outputDir
    }
    cd $outputDir
    set fileRoot $itsRootname
    
    if [catch {exec  cavput -list=LTS:PT3:DC1ARF.SPD=On,LTS:PT3:DC1BRF.SPD=On,LTS:PT3:DC1ARF.AQWF=Scan,LTS:PT3:DC1BRF.AQWF=Scan \
                 -pend=30} result] {
        return -code error "AcqureITSGunRFWaveform1: unable to setup LTS: $result"
    }
    set endTime [expr [clock seconds] + 10000]
    SetStatus "waiting for waveform to settle..."
    exec cawait -waitFor=LTS:PT3:DC1BRF.SPD,sameAs=Off -interval=1 -timeLimit=10
    exec cawait -waitFor=LTS:PT3:DC1ARF.SPD,sameAs=Off -interval=1 -timeLimit=10
    
    #while {1} {
    #    after 1000
    #    update
    #}
    SetStatus "Collecting waveform ..."
    set ext [clock format [clock seconds] -format %Y-%m%d-%H%M%S]
    if [catch {exec sddswmonitor ${fileRoot}_${ext}.sdds \
                 -scalars=/home/helios/LINAC/daily/2011/07/17/2/RG2_RF_Waveforms/RFGunRF_scalars.mon \
                 -PVnames=LI:MON:chan1ScaledWaveWF,LI:MON:chan2ScaledWaveWF,LI:MON:scaledTimeAxisWF \
                 -steps=1  } result] {
        return -code error "AcqureITSGunRFWaveform2: error in sddswmonitor: $result"
    }
    if [catch {exec sddsprocess ${fileRoot}_${ext}.sdds -nowarnings -pipe=out \
		   -process=LI:MON:chan1ScaledWaveWF,max,PeakPower \
		   "-redefine=col,Time,LI:MON:scaledTimeAxisWF,symbol=Time,units=\$gm\$rs" \
		   "-redefine=param,RFGFPWR,L1:RFG:DC2ARF.VAL 1.0e6 /,units=MW" \
		   "-reprint=param,RFGFPWRString,RG2 RF Gun Peak FWD Power = %0.2f %s,RFGFPWR,RFGFPWR.units" \
		   "-redefine=param,RFGHTRPWR,L1:RG2:HTR:PowerCC,units=W" \
		   "-reprint=param,RFGHTRPWRString,RF Heater Power = %0.2f %s,RFGHTRPWR,RFGHTRPWR.units" \
		   "-redefine=param,RFGSupplyTemp,L1:WS1:RfGun2H2OSupTempAI,units=F" \
		   "-reprint=param,RFGSupplyTempString,RG2 H2O Supply Temp = %0.2f %s,RFGSupplyTemp,RFGSupplyTemp.units" \
		   "-redefine=param,RFGReturnTemp,L1:WS1:RfGun2H2ORetTempAI,units=F" \
		   "-reprint=param,RFGReturnTempString,RG2 H2O Return Temp = %0.2f %s,RFGReturnTemp,RFGReturnTemp.units" \
		   | sddsprocess -pipe=in ${fileRoot}_${ext}.sdds \
		   "-redefine=col,ForwardPower,LI:MON:chan1ScaledWaveWF PeakPower / RFGFPWR *,symbol=FWD Power,units=MW" \
		   "-redefine=col,ReflectPower,LI:MON:chan2ScaledWaveWF PeakPower / RFGFPWR *,symbol=REF Power,units=MW" } result] {
        return -code error "AcqureITSGunRFWaveform2: error in sddsprocess: $result"
    }
    SetStatus "done."
    exec sddsplot -limits=xminimum=$xstart,xmaximum=$xend -leg \
	-scale=$xstart,$xend,0,0 \
      -subticksettings=xdivisions=5,ydivisions=5 \
      -title=@TimeStamp,scale=0.6 \
      ${fileRoot}_${ext}.sdds \
      -topline=@RFGFPWRString,scale=0.5 \
      -string=@RFGHTRPWRString,p=0.1,q=0.90 \
      -string=@RFGSupplyTempString,p=0.1,q=0.85 \
      -string=@RFGReturnTempString,p=0.1,q=0.80 \
      "-col=Time,*Power" -graph=line,vary \&
   return 
}

proc PlotITSGunRFWaveform {args} {
    global outputDir itsRootname itsFiles EPS PNG xstart xend
    if ![file exist $outputDir] {
        SetStatus "No data has been collected in $outputDir!"
        return
    }
    cd $outputDir
    set files [lsort -decreasing [glob -nocomplain ${itsRootname}*.sdds]]
    if ![llength $files] {
        SetStatus "No data found in $outputDir."
        return
    }
    APSScrolledListWindow .its -name "Select files for plot" \
      -label "Select Files for plot." \
      -itemList $files  -selectionVar itsFiles
    tkwait variable itsFiles
   
    SetStatus "plotting data in $outputDir..."
    set cols [exec sddsquery -col [lindex $itsFiles 0]]
    if [lsearch $cols "Time"]>=0 {
	set col -col=Time,*Power
	set col1 -col=Time,ForwardPower
	set col2 -col=Time,ReflectPower
    } else {
	set col -col=LTS:PT3:DC1BRF.TMFP,LTS*PWFP
	set col1 -col=LTS:PT3:DC1BRF.TMFP,LTS:PT3:DC1ARF.PWFP
	set col2 -col=LTS:PT3:DC1BRF.TMFP,LTS:PT3:DC1BRF.PWFP
    }
    if [llength $itsFiles]>1 {
	
        eval exec sddsplot $itsFiles -limits=xminimum=$xstart,xmaximum=$xend -leg=file,edit=%/$itsRootname//%/_//%/.sdds// -layout=1,2 \
	    -scale=$xstart,$xend,0,0 \
          -subticksettings=xdivisions=5,ydivisions=5 \
          \"-title=Forward Power Waveforms\" \
          $col1 -graph=line,vary \
          -endp  \
          $col2 -graph=line,vary \
          \"-title=Reflect Power Waveforms\"  &
        if {$EPS || $PNG} {
            global figureDir
            APSDialogBox .fig -name "Directory for figures" 
            APSLabeledEntry .dir -parent .fig.userFrame -label "Directory for saving figures:"  \
              -textVariable figureDir -width 70
            APSButton .daily -parent .fig.userFrame.dir -text "daily" -size small \
              -command "set figureDir [APSGoToDailyDirectory]"
            tkwait window .fig
            if $EPS {
                eval exec sddsplot $itsFiles -limits=xminimum=$xstart,xmaximum=$xend  \
		     -scale=$xstart,$xend,0,0 \
                  -leg=file,edit=%/$itsRootname//%/_//%/.sdds// -layout=1,2 \
                  -subticksettings=xdivisions=5,ydivisions=5 \
                  \"-title=Forward Power Waveforms\" \
                  $col1 -graph=line,vary \
                  -endp  \
                  $col2 -graph=line,vary \
                  \"-title=Reflect Power Waveforms\"  \
                  -output=$figureDir/$itsRootname.eps \
                  -dev=ceps,onwhite
            }
            if $PNG {
                eval exec sddsplot $itsFiles -limits=xminimum=$xstart,xmaximum=$xend  \
		     -scale=$xstart,$xend,0,0 \
                  -leg=file,edit=%/$itsRootname//%/_//%/.sdds// -layout=1,2 \
                  -subticksettings=xdivisions=5,ydivisions=5 \
                  \"-title=Forward Power Waveforms\" \
                  $col1 -graph=line,vary \
                  -endp  \
                  $col2 -graph=line,vary \
                  \"-title=Reflect Power Waveforms\"  \
                  -output=$figureDir/$itsRootname.png \
                  -dev=png,onwhite
            }
        }
    } else {
        exec sddsplot -limits=xminimum=$xstart,xmaximum=$xend -leg \
	     -scale=$xstart,$xend,0,0 \
          -subticksettings=xdivisions=5,ydivisions=5 \
          -title=@TimeStamp,scale=0.6 \
          $itsFiles \
          -topline=@RFGFPWRString,scale=0.5 \
          -string=@RFGHTRPWRString,p=0.1,q=0.90 \
          -string=@RFGSupplyTempString,p=0.1,q=0.85 \
          -string=@RFGReturnTempString,p=0.1,q=0.80 \
          $col -graph=line,vary &
        if {$EPS || $PNG} {
            global figureDir
            APSDialogBox .fig -name "Directory for figures" 
            APSLabeledEntry .dir -parent .fig.userFrame -label "Directory for saving figures:"  \
              -textVariable figureDir -width 70
            APSButton .daily -parent .fig.userFrame.dir -text "daily" -size small \
              -command "set figureDir [APSGoToDailyDirectory]"
            tkwait window .fig
	    if $EPS {
		exec sddsplot -limits=xminimum=$xstart,xmaximum=$xend -leg \
		     -scale=$xstart,$xend,0,0 \
		    -subticksettings=xdivisions=5,ydivisions=5 \
		    -title=@TimeStamp,scale=0.6 \
		    $itsFiles \
		    -topline=@RFGFPWRString,scale=0.5 \
		    -string=@RFGHTRPWRString,p=0.1,q=0.90 \
		    -string=@RFGSupplyTempString,p=0.1,q=0.85 \
		    -string=@RFGReturnTempString,p=0.1,q=0.80 \
		    $col -graph=line,vary \
		    -output=$figureDir/[file root $itsFiles].eps \
		    -device=ceps,onwhite
	    }
	    if $PNG {
		exec sddsplot -limits=xminimum=$xstart,xmaximum=$xend -leg \
		     -scale=$xstart,$xend,0,0 \
		    -subticksettings=xdivisions=5,ydivisions=5 \
		    -title=@TimeStamp,scale=0.6 \
		    $itsFiles \
		    -topline=@RFGFPWRString,scale=0.5 \
		    -string=@RFGHTRPWRString,p=0.1,q=0.90 \
		    -string=@RFGSupplyTempString,p=0.1,q=0.85 \
		    -string=@RFGReturnTempString,p=0.1,q=0.80 \
		    $col -graph=line,vary \
		    -output=$figureDir/[file root $itsFiles].png \
		    -device=png,onwhite
	    }
	}
    }
}

proc ChangeIndex {value} {
    global index fileRoot
    incr index $value
    set date [scan $fileRoot %ld]
    set fileRoot ${date}_[format %03d $index]
}

proc SetStatus {text} {
    global status
    set status "$text"
    update
}
set status ""
APSApplication . -name AcquireICTFCWaveform -version $CVSRevisionAuthor \
    -overview {This utility is for acquring and process ICTFC waveforms}
APSScrolledStatus .status  -parent .userFrame  -textVariable status -width 100 \
  -height 4 -withButtons 1 -packOption "-fill x"

set dataDirectory [clock format [clock seconds] -format %Y%m%d]
set fileRoot [clock format [clock seconds] -format %y%m%d]_000
set waveformDir  /net/ozone/pcfiles/pc/scopeusr_share/tekdpo7
set archiveDir /home/helios/oagData/ITS/cmData/[clock format [clock seconds] -format %Y-%j-%m%d]
set ictScopeChannel Ch1
set fcScopeChannel Ch3
set ictTurns 10.0
set cableImpedance 50.0
set droopFactor 1.1
set plotOnly 0

set wList [APSTabFrame .tab -parent .userFrame -label "" -labelList {ICT-FC-Current ITS-RFG-RF} -width 900 -height 250]
set f1 [lindex $wList 0]
set f2 [lindex $wList 1]
APSLabeledEntry .dir -parent $f1 -textVariable archiveDir \
    -width 70 -label "Archive directory:"
APSLabeledEntry .dir1 -parent $f1 -textVariable waveformDir -width 70 -label "Waveform directory:"
APSButton .ach -parent $f1.dir  -text "archive" -size small -packOption "-side right" \
    -command "set archiveDir /home/helios/oagData/ITS/cmData/[clock format [clock seconds] -format %Y-%j-%m%d]"
APSFrameGrid .grid -parent $f1 -xList {x1 x2}
set w1 $f1.grid.x1
set w2 $f1.grid.x2

set width 30
APSLabeledEntry .root -parent $w1 -textVariable fileRoot -width $width -label "Rootname:"
APSButton .add -parent $w1.root -packOption "-side right" -size small -text "+" \
    -command "ChangeIndex 1"
APSButton .minus -parent $w1.root -packOption "-side right" -size small -text "-" \
    -command "ChangeIndex -1"
APSLabeledEntry .dir -parent $w2 -textVariable dataDirectory -width $width -label "Data directory:" 
APSButton .upate -parent $w2.dir -packOption "-side right" -text "update" -size small \
    -command {set dataDirectory [clock format [clock seconds] -format %Y%m%d]}
APSLabeledEntry .ictc -parent $w1 -label "ICT scope channel" -textVariable ictScopeChannel \
  -width $width
APSLabeledEntry .fc -parent $w2 -label "FC scope channel" -textVariable fcScopeChannel \
  -width $width
APSLabeledEntry .ictturns -parent $w1 -label "ICT turns:" -textVariable ictTurns \
  -width $width
APSLabeledEntry .cable -parent $w2 -label "Cable impedance:" -textVariable cableImpedance \
  -width $width
APSLabeledEntry .factor -parent $w1 -label "Droop factor:" -textVariable droopFactor \
  -width $width
#APSRadioButtonFrame .plot -parent $w2 -label "Plot only?" -buttonList {Yes No} \
#  -valueList {1 0} -variable plotOnly -orientation horizontal
set EPS 0
set PNG 0
APSCheckButtonFrame .fig -parent $w2 -label "Creat EPS/PNG files?"  -buttonList {EPS PNG} \
    -variableList {EPS PNG} -orientation horizontal

APSButton .acq -parent $f1 -text "Convert/Plot ICT Waveform" -command "ConvertICTFCWaveform"
set xstart -0.5
set xend 2.0
set outputDir /home/helios/oagData/ITS/gunRF/[clock format [clock seconds] -format %Y-%j-%m%d]
set itsRootname ITS_RFG_RF_Waveforms
APSLabeledEntry .out -parent $f2 -label "Output directory:" -width 70 -textVariable outputDir
APSButton .arc -parent $f2.out -text "Archive" -size small -command "set outputDir /home/helios/oagData/ITS/gunRF/[clock format [clock seconds] -format %Y-%j-%m%d]"
APSLabeledEntry .root -parent $f2 -label "Rootname:" -width 70 -textVariable itsRootname
APSCheckButtonFrame .fig -parent $f2 -label "Creat EPS/PNG files?"  -buttonList {EPS PNG} \
    -variableList {EPS PNG} -orientation horizontal
APSLabeledEntry .xstart -parent $f2 -label "X-axis start:" -width 70 -textVariable xstart
APSLabeledEntry .xend -parent $f2 -label "X-axis stop:" -width 70 -textVariable xend
APSButton .acq1 -parent $f2 -text "Acquire ITS RFG RF Waveform" -command "AcquireITSGunRFWaveform"
APSButton .plot -parent $f2 -text "Plot" -command "PlotITSGunRFWaveform"
set figureDir $env(HOME)
