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

# $Log: not supported by cvs2svn $
# Revision 1.1  2011/08/05 18:58:41  shang
# for collecting ITS and linac current and RF gun waveforms
#

set CVSRevisionAuthor "\$Revision: 1.2 $ \$Author: shang $"
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 AcquireITSGunRFWaveform {args} {
    set subDir ""
    APSParseArguments {subDir}
    
    global archiveDir xstart xend scalarsFile
    set ext [clock format [clock seconds] -format %Y-%j-%m%d-%H%M%S]
    set dir /home/helios/oagData/$subDir
    set file $dir/${ext}.sdds
    if [catch {exec sddswmonitor $file \
		   -scalars=$scalarsFile \
		   -PVnames=LI:MON:chan1ScaledWaveWF,LI:MON:chan2ScaledWaveWF,LI:MON:scaledTimeAxisWF \
		   -steps=1  } result] {
        return -code error "AcqureLinacGunRFWaveform2: error in sddswmonitor: $result"
    }
    if [catch {exec sddsprocess $file -nowarnings -pipe=out \
		   -process=LI:MON:chan1ScaledWaveWF,max,PeakPower \
		   "-redefine=col,Time,LI:MON:scaledTimeAxisWF,symbol=Time,units=\$gm\$rs" \
		   "-redefine=param,ITSRFGFwdPwr,ITSRFGFwdPwr 1.0e6 /,units=MW" \
		   "-reprint=param,RFGFPWRString,ITS RG RF Gun Peak FWD Power = %0.2f %s,ITSRFGFwdPwr,ITSRFGFwdPwr.units" \
		   "-reprint=param,RFGHTRPWRString,ITS Heater Power = %0.2f %s,ITSHeaterPower,ITSHeaterPower.units" \
		   "-reprint=param,RFGSupplyTempString,ITS RFG H2O Supply Temp = %0.2f %s,ITSWaterSupplyTemp,ITSWaterSupplyTemp.units" \
		   "-reprint=param,RFGReturnTempString,ITS RFG H2O Return Temp = %0.2f %s,ITSWaterReturnTemp,ITSWaterReturnTemp.units" \
		   | sddsprocess -pipe=in $file.proc \
		   "-redefine=col,ForwardPower,LI:MON:chan1ScaledWaveWF PeakPower / ITSRFGFwdPwr *,symbol=FWD Power,units=MW" \
		   "-redefine=col,ReflectPower,LI:MON:chan2ScaledWaveWF PeakPower / ITSRFGFwdPwr *,symbol=REF Power,units=MW" } result] {
        return -code error "AcqureLinacGunRFWaveform4: 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 \
      $file.proc  \
      -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 AcquireLinacICTWaveform {args} {
    set subDir ""
    APSParseArguments {subDir}
    global archiveDir xstart xend scalarsFile
    set dir /home/helios/oagData/$subDir
    if [catch {exec cavget -list=L1:RFG:RF:SW2:positionMI -printErrors -pend=30} gun] {
	return -code error "Error in reading RG gun type: $gun"
    }
    switch $gun {
	RG2 {
	    set gun 2
	}
	RG1 {
	    set gun 1
	}
    }
    set ext [clock format [clock seconds] -format %Y-%j-%m%d-%H%M%S]
    set file $dir/RG-${gun}${ext}.sdds
    if [catch {exec sddswmonitor $file \
		   -scalars=$scalarsFile \
		   -PVnames=L1:SCOPE1:scaledTimeAxisWF,L1:SCOPE1:chan4ScaledWaveWF \
		   -steps=1  } result] {
        return -code error "AcqureLiancICTWaveform2: error in sddswmonitor: $result"
    }
    if [catch {exec sddsprocess $file $file.proc -define=col,Time,L1:SCOPE1:scaledTimeAxisWF,units=\$gm\$rs \
		   -define=col,ICTcurrent,L1:SCOPE1:chan4ScaledWaveWF,units=Volts \
		   "-print=par,ICTpeakCurrentString,RG$gun peak current = %0.2f %s,RG${gun}PeakCurrent,RG${gun}PeakCurrent.units" } result] {
	return -code error "AcqureLiancICTWaveform3: error in processing data: $result"
    }
    exec sddsplot -col=Time,ICTcurrent -topline=@ICTpeakCurrentString $file.proc &
}

proc AcquireLinacGunRFWaveform {args} {
    set subDir ""
    APSParseArguments {subDir}
    if [catch {exec cavget -list=L1:RFG:RF:SW2:positionMI -printErrors -pend=30} gun] {
	return -code error "Error in reading RG gun type: $gun"
    }
    
    global archiveDir xstart xend scalarsFile
    set dir /home/helios/oagData/$subDir
    SetStatus "Colllecting linac RF waveform..."
    if {0} {
    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 "AcqureLinacGunRFWaveform1: 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
    #}
    switch $gun {
	RG2 {
	    set gun 2
	}
	RG1 {
	    set gun 1
	}
    }
    set ext [clock format [clock seconds] -format %Y-%j-%m%d-%H%M%S]
    set file $dir/RG${gun}${ext}.sdds
    if [catch {exec sddswmonitor $file \
                 -scalars=$scalarsFile \
                 -PVnames=LI:MON:chan1ScaledWaveWF,LI:MON:chan2ScaledWaveWF,LI:MON:scaledTimeAxisWF \
                 -steps=1  } result] {
        return -code error "AcqureLinacGunRFWaveform2: error in sddswmonitor: $result"
    }
    if [catch {exec sddsprocess $file -nowarnings -pipe=out \
		   -process=LI:MON:chan1ScaledWaveWF,max,PeakPower \
		   "-redefine=col,Time,LI:MON:scaledTimeAxisWF,symbol=Time,units=\$gm\$rs" \
		   "-redefine=param,LinacRFGFwdPwr,LinacRFGFwdPwr 1.0e6 /,units=MW" \
		   "-reprint=param,RFGFPWRString,Linac RG RF Gun Peak FWD Power = %0.2f %s,LinacRFGFwdPwr,LinacRFGFwdPwr.units" \
		   "-reprint=param,RFGHTRPWRString,RF Heater Power = %0.2f %s,RG${gun}HeaterPower,RG${gun}HeaterPower.units" \
		   "-reprint=param,RFGSupplyTempString,RG${gun} H2O Supply Temp = %0.2f %s,RG${gun}WaterSupplyTemp,RG${gun}WaterSupplyTemp.units" \
		   "-reprint=param,RFGReturnTempString,RG${gun} H2O Return Temp = %0.2f %s,RG${gun}WaterReturnTemp,RG${gun}WaterReturnTemp.units" \
		   | sddsprocess -pipe=in $file.proc \
		   "-redefine=col,ForwardPower,LI:MON:chan1ScaledWaveWF PeakPower / LinacRFGFwdPwr *,symbol=FWD Power,units=MW" \
		   "-redefine=col,ReflectPower,LI:MON:chan2ScaledWaveWF PeakPower / LinacRFGFwdPwr *,symbol=REF Power,units=MW" } result] {
        return -code error "AcqureLinacGunRFWaveform4: 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 \
      $file.proc  \
      -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 PlotWaveform {args} {
    global EPS PNG xstart xend plotData plotFiles
    
    switch $plotData {
	ITS_current {
	    set dir /home/helios/oagData/ITS/cmData
	    set prefix ""
	}
	ITS_RF {
	    set dir /home/helios/oagData/ITS/gunRF
	    set prefix ""
	    set xend 2.5
	}
	RG1_RF -
	RG2_RF {
	    set dir /home/helios/oagData/linac/gunRF
	    set prefix [string range $plotData 0 2]
	    set xend 3.5
	}
	RG1_current -
	RG2_current {
	    set dir /home/helios/oagData/linac/cmData
	    set prefix [string range $plotData 0 2]
	}
    }
    cd $dir
    set files [lsort -decreasing [glob -nocomplain ${prefix}*.sdds.proc]]
    if ![llength $files] {
        SetStatus "No data found for $plotData in $dir."
        return
    }
    APSScrolledListWindow .its -name "Select files for plot" \
	-label "Select Files for plot." \
	-itemList $files  -selectionVar plotFiles
    tkwait variable plotFiles
    
    SetStatus "plotting $plotData data in $dir..."
    global figureDir
    
    if [llength $plotFiles]>1 {
	if [regexp {RF} $plotData] {
	    eval exec sddsplot $plotFiles -limits=xminimum=$xstart,xmaximum=$xend -leg=file,edit=%/.sdds.proc// -layout=1,2 \
		-scale=$xstart,$xend,0,0 \
		-subticksettings=xdivisions=5,ydivisions=5 \
		\"-title=Forward Power Waveforms\" \
		-col=Time,ForwardPower  -graph=line,vary \
		-endp  \
		-col=Time,ReflectPower \
		-graph=line,vary \
		\"-title=Reflect Power Waveforms\"
	} else {
	    if [regexp {ITS} $plotData] {
		eval exec sddsplot $plotFiles -grap=line,vary -leg=file,edit=%/.sdds.proc// -layout=1,3 \
                    -subticksettings=xdivisions=5,ydivisions=5 \
                    -col=Time,ICTcurrent \"-title=ICT Baseline Subtracted Waveforms and Integrals\" -endp \
		    -col=Time,FCcurrent \"-title=FC Baseline Subtracted Waveforms and Integrals\" -endp \
                    -col=Time,Current \"-title=FC Current Waveform\" -endp &
	    } else {
		eval exec sddsplot $plotFiles -grap=line,vary -leg=file,edit=%/.sdds.proc// -col=Time,ICTcurrent &
	    }
	}
    } else {
	if [regexp {RF} $plotData] {
	    exec sddsplot -limits=xminimum=$xstart,xmaximum=$xend -leg \
		-scale=$xstart,$xend,0,0 \
		-subticksettings=xdivisions=5,ydivisions=5 \
		-title=@TimeStamp,scale=0.6 \
		$plotFiles  \
		-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 &
	    
	} else {
	    if [regexp {ITS} $plotData] {
		exec sddsplot $plotFiles -layout=1,2 -graph=line,vary "-topline=@TimeStamp" \
		    -subticksettings=xdivisions=5,ydivisions=5 \
		    -col=Time,ICTcurrent -leg=spec=ICT \
		    -string=@ICTIntegString,p=0.1,q=0.15,scale=0.9 \
		    -col=Time,FCcurrent  -leg=spec=FC \
		    -string=@FCIntegString,p=0.1,q=0.05,scale=0.9 \
		    -param=ICTcurrentPeakTime,ICTcurrentPeak \
		    -graph=symb,sca=3,type=0,sub=2 "-leg=spec=ICT Peak" \
		    -string=@ICTcurrentPeakString,p=0.1,q=0.35,scale=0.9 \
		    -param=FCcurrentPeakTime,FCcurrentPeak  \
		    -graph=symb,sca=3,type=1,sub=3 "-leg=spec=FC Peak" \
		    -string=@FCcurrentPeakString,p=0.1,q=0.25,scale=0.9 \
		    "-title=FC and ICT Baseline Subtracted Waveforms and Integrals" -end \
		    -col=Time,Current -leg=spec=FC \
		    -string=@ChargeString,p=0.1,q=0.05,scale=0.9 \
		    -param=CurrentPeakTime,CurrentPeak  \
		    -graph=symb,sca=3,sub=1 -leg=spec=Peak \
		    -string=@CurrentPeakString,p=0.1,q=0.15,scale=0.9 \
		    "-title=FC Current Waveform" &
	    } else {
		exec sddsplot $plotFiles -col=Time,ICTcurrent -topline=@ICTpeakCurrentString &
	    }
	}
    }
}

proc SetStatus {text} {
    global status
    set status "$text"
    update
}

proc SetupDMUscopeMux {args} {
    global dataType
    if [regexp {ICT} $dataType] {
	SetStatus "No need to switch DMU mux for current waveform."
	return
    }
    SetStatus "switching DMU mux to $dataType"
    if [catch {exec sddscasr -restore /home/helios/oagData/ITS/gun_initialize.sdds } result] {
	return -code error $result
    }
    after 1000
    if [regexp {ITS} $dataType] {
	exec cavput -list=LTS:MTM:EDM1:chan1SelReqMO=1,LTS:MTM:EDM1:chan2SelReqMO=2
	exec cavput -list=LTS:MTM:EDM1:chan1SelReqMO=0,LTS:MTM:EDM1:chan2SelReqMO=0
	exec cavput -list=LTS:MTM:EDM1:chan1SelReqMO=1,LTS:MTM:EDM1:chan2SelReqMO=2
    } elseif [regexp {Linac} $dataType] {
	exec cavput -list=L1:MTM:EDM2:chan1SelReqMO=3,L1:MTM:EDM2:chan2SelReqMO=4
	exec cavput -list=L1:MTM:EDM2:chan1SelReqMO=0,L1:MTM:EDM2:chan2SelReqMO=0
	exec cavput -list=L1:MTM:EDM2:chan1SelReqMO=3,L1:MTM:EDM2:chan2SelReqMO=4
    }
    after 2000
    SetStatus "done."
}

proc AcquireITSCurrentWaveform {args} {
    set subDir ""
    APSParseArguments {subDir}
    global archiveDir dataType scalarsFile ictTurns cableImpedance droopFactor
    SetStatus "Colllecting ITS data..."
    set dir /home/helios/oagData/$subDir
    set ext [clock format [clock seconds] -format %Y-%j-%m%d-%H%M%S]
    if [catch {exec sddswmonitor $archiveDir/its.wmon $dir/$ext.sdds \
		   -scalars=$scalarsFile  -steps=1  } result] {
        return -code error "AcquireITSWaveform1: error in sddswmonitor: $result"
    }
    #time waveform is in microseconds (us), current (ICTcurrent and FCcurrent) waveforms are in Volts units
    if [catch {exec sddsbaseline $dir/$ext.sdds -pipe=out -col=ICTcurrent,FCcurrent -select=endpoints=10 -method=average \
		   | sddsprocess -pipe -filter=col,Time,0,0,! \
		   | sddsprocess -pipe \
		   "-redefine=par,ICTturns,$ictTurns,type=long" \
		   "-redefine=par,CableImpedance,$cableImpedance" \
		   "-redefine=par,DroopFactor,$droopFactor" \
		   "-redefine=col,ICTcurrent,ICTcurrent,units=Volts" \
		   "-redefine=col,FCcurrent,FCcurrent,units=Volts" \
		   -process=ICTcurrent,integ,ICTInteg,functionOf=Time \
		   -process=FCcurrent,integ,FCInteg,functionOf=Time \
		   "-redefine=param,Charge,ICTInteg ${ictTurns} * ${cableImpedance} / 1.0e3 * ${droopFactor} *,units=nC" \
		   "-redefine=param,ICTInteg,ICTInteg 1.0e3 *,units=nVs" \
		   "-print=param,ChargeString,ICT Charge = %0.2f %s,Charge,Charge.units" \
		   "-print=param,ICTIntegString,ICT Integ = %0.2f %s,ICTInteg,ICTInteg.units" \
		   "-redefine=param,FCInteg,FCInteg 1.0e3 *,units=nVs" \
		   "-redefine=col,Current,FCcurrent FCInteg / Charge * 1000.0 *,units=mA" \
		   -process=Current,integ,CurrentInteg,functionOf=Time \
		   "-redefine=param,ChargeFromCurrent,CurrentInteg 1000.0 / 1.0e3 *,units=nC" \
		   "-print=param,FCIntegString,FC Integ = %0.2f %s,FCInteg,FCInteg.units" \
		   "-redefine=col,Time,Time,units=\$gm\$rs" \
		   | sddssmooth -pipe \
		   -col=Current -points=3 -passes=5 \
		   | sddsprocess -pipe=in $dir/$ext.sdds.proc \
		   -process=ICTcurrent,minimum,ICTcurrentPeak \
		   -process=ICTcurrent,minimum,ICTcurrentPeakTime,functionOf=Time,position \
		   "-print=param,ICTcurrentPeakString,ICT Peak = %0.2f %s,ICTcurrentPeak,ICTcurrentPeak.units" \
		   -process=FCcurrent,minimum,FCcurrentPeak \
		   -process=FCcurrent,minimum,FCcurrentPeakTime,functionOf=Time,position \
		   "-print=param,FCcurrentPeakString,FC Peak = %0.2f %s,FCcurrentPeak,FCcurrentPeak.units" \
		   -process=Current,minimum,CurrentPeak \
		   -process=Current,minimum,CurrentPeakTime,functionOf=Time,position \
		   "-print=param,CurrentPeakString,Peak Current = %0.2f %s,CurrentPeak,CurrentPeak.units"} result] {
	return -code error "Error in processing ICT/FC data: $result"
    }
    
    exec sddsplot $dir/$ext.sdds.proc -layout=1,2 -graph=line,vary "-topline=@TimeStamp" \
	-subticksettings=xdivisions=5,ydivisions=5 \
	-col=Time,ICTcurrent  -leg=spec=ICT \
	-string=@ICTIntegString,p=0.1,q=0.15,scale=0.9 \
	-col=Time,FCcurrent  -leg=spec=FC \
	-string=@FCIntegString,p=0.1,q=0.05,scale=0.9 \
	-param=ICTcurrentPeakTime,ICTcurrentPeak \
	-graph=symb,sca=3,type=0,sub=2 "-leg=spec=ICT Peak" \
	-string=@ICTcurrentPeakString,p=0.1,q=0.35,scale=0.9 \
	-param=FCcurrentPeakTime,FCcurrentPeak  \
	-graph=symb,sca=3,type=1,sub=3 "-leg=spec=FC Peak" \
	-string=@FCcurrentPeakString,p=0.1,q=0.25,scale=0.9 \
	"-title=FC and ICT Baseline Subtracted Waveforms and Integrals" -end \
	-col=Time,Current  -leg=spec=FC \
	-string=@ChargeString,p=0.1,q=0.05,scale=0.9 \
	-param=CurrentPeakTime,CurrentPeak  \
	-graph=symb,sca=3,sub=1 -leg=spec=Peak \
	-string=@CurrentPeakString,p=0.1,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 {
	    set output $figureDir/ITS_current_$ext.eps
	    set device ceps
	} elseif $png {
	    set output $figureDir/ITS_current-$ext.png
	    set device png
	}
	exec sddsplot -layout=1,2 -graph=line,vary "-topline=@TimeStamp" \
	    -subticksettings=xdivisions=5,ydivisions=5 \
	    -col=Time,ICTcurrent $dir/$ext.sdds.proc -leg=spec=ICT \
	    -string=@ICTIntegString,p=0.1,q=0.15,scale=0.9 \
	    -col=Time,FCcurrent $dir/$ext.sdds.proc -leg=spec=FC \
	    -string=@FCIntegString,p=0.1,q=0.05,scale=0.9 \
	    -param=ICTcurrentPeakTime,ICTcurrentPeak $dir/$ext.sdds.proc \
	    -graph=symb,sca=3,type=0,sub=2 "-leg=spec=ICT Peak" \
	    -string=@ICTcurrentPeakString,p=0.1,q=0.35,scale=0.9 \
	    -param=FCcurrentPeakTime,FCcurrentPeak $dir/$ext.sdds.proc \
	    -graph=symb,sca=3,type=1,sub=3 "-leg=spec=FC Peak" \
	    -string=@FCcurrentPeakString,p=0.1,q=0.25,scale=0.9 \
	    "-title=FC and ICT Baseline Subtracted Waveforms and Integrals" -end \
	    -col=Time,Current $dir/$ext.sdds.proc -leg=spec=FC \
	    -string=@ChargeString,p=0.1,q=0.05,scale=0.9 \
	    -param=CurrentPeakTime,CurrentPeak $dir/$ext.sdds.proc \
	    -graph=symb,sca=3,sub=1 -leg=spec=Peak \
	    -string=@CurrentPeakString,p=0.1,q=0.15,scale=0.9 \
	    "-title=FC Current Waveform" \
	    -output=$output \
	    -dev=$device,onwhite
    }
}


proc AcquireWaveform {args} {
    global archiveDir dataType scalarsFile subDir

    if [catch {SetupDMUscopeMux} result] {
	SetStatus $result
	return
    }
    switch $dataType {
	ITS_ICT_FC {
	    if [catch { AcquireITSCurrentWaveform -subDir $subDir} result] {
		SetStatus  "Error in collecting ITS current waveform: $result"
		return
	    }
	}
	ITS_RF {
	    if [catch {AcquireITSGunRFWaveform -subDir $subDir} result] {
		SetStatus  "Error in collecting ITS RF gun waveform: $result"
		return
	    }
	}
	Linac_ICT {
	    if [catch {AcquireLinacICTWaveform -subDir $subDir} result] {
		SetStatus "Error in collecting linac ICT waveform: $result"
		return
	    }
	}
	Linac_RF {
	    if [catch {AcquireLinacGunRFWaveform -subDir $subDir} result] {
		SetStatus "Error in collecting linac RF waveform: $result"
		return
	    }
	}
    }
    SetStatus "done."
}

proc ChangeXStopAndSubDir {args} {
    set value ""
    APSParseArguments {value}
    global xend subDir dataType
    set xend $value
    switch $dataType {
	ITS_ICT_FC {
	    set subDir ITS/cmData
	}
	ITS_RF {
	    set subDir ITS/gunRF
	}
	Linac_ICT {
	    set subDir linac/cmData
	}
	Linac_RF {
	    set subDir linac/gunRF
	}
    }
}

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 archiveDir /home/helios/oagData/ITS/
set ictScopeChannel Ch1
set fcScopeChannel Ch3
set ictTurns 10.0
set cableImpedance 50.0
set droopFactor 1.1
set plotOnly 0
set scalarsFile /home/helios/oagData/ITS/ITS_LinacRFGun_scalars.mon

set dataType ITS_ICT_FC
set subDir ITS/cmData
APSRadioButtonFrame .sel -parent .userFrame -label "Collect data for?" -buttonList {ITS_ICT_FC_CurrWf ITS_RFWf Linac_ICT_VWf Linac_RFWf} \
    -valueList {ITS_ICT_FC ITS_RF Linac_ICT Linac_RF} -variable dataType -orientation horizontal \
    -commandList {"ChangeXStopAndSubDir -value 2.5" "ChangeXStopAndSubDir -value 2.5" "ChangeXStopAndSubDir -value 3.5" "ChangeXStopAndSubDir -value 3.5"}
set plotData ITS_current

set width 30
APSFrameGrid .grid -parent .userFrame -xList {x1 x2}
set w1 .userFrame.grid.x1
set w2 .userFrame.grid.x2
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

set xstart -0.5
set xend 2.0

APSLabeledEntry .xstart -parent $w1 -label "X-axis start:" -width $width -textVariable xstart
APSLabeledEntry .xend -parent $w2 -label "X-axis stop:" -width $width -textVariable xend

APSRadioButtonFrame .plot -parent .userFrame -label "Plot data for?" -buttonList {ITS_current ITS_RF RG1_current RG2_current RG1_RF RG2_RF} \
    -valueList {ITS_current ITS_RF RG1_current RG2_current RG1_RF RG2_RF} -variable plotData -orientation horizontal 

APSButton .acq1 -parent .userFrame -text "Acquire Waveform" -command "AcquireWaveform"
APSButton .plot1 -parent .userFrame -text "Plot" -command "PlotWaveform"
APSButton .setup -parent .userFrame -text "Setup Mux" -command "SetupDMUscopeMux"
set figureDir $env(HOME)
