#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_CUR_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_CUR_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_CUR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_CUR_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_CUR_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_CUR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_CUR_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_CUR_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_CUR_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_CUR_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_CUR_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_CUR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_CUR_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_CUR_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_CUR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_CUR_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_CUR_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_CUR_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_CUR_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_CUR_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_CUR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_CUR_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_CUR_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_CUR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_CUR_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_CUR_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_CUR_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_CUR_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_CUR_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_CUR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_CUR_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_CUR_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_CUR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_CUR_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_CUR_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_CUR_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_CUR_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_CUR_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_CUR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_CUR_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_CUR_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_CUR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_CUR_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_CUR_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_CUR_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_CUR_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_CUR_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_CUR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_CUR_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_CUR_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_CUR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_CUR_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_CUR_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_CUR_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_CUR_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_CUR_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_CUR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_CUR_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_CUR_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_CUR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_CUR_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_CUR_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_CUR_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_CUR_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_CUR_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_CUR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_CUR_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_CUR_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_CUR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_CUR_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_CUR_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_CUR_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_CUR_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_CUR_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_CUR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_CUR_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_CUR_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_CUR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_CUR_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_CUR_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_CUR_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_CUR_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_CUR_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_CUR_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_CUR_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_CUR_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_CUR_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_CUR_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_CUR_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_CUR_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_CUR_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_CUR_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_CUR_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_CUR_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_CUR_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_CUR_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_CUR_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_CUR_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_CUR_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_CUR_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_CUR_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_CUR_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_CUR_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_CUR_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_CUR_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_CUR_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_CUR_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_CUR_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_CUR_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_CUR_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_CUR_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_CUR_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_CUR_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_CUR_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_CUR_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_CUR_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_CUR_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_CUR_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_CUR_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_CUR_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_CUR_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_CUR_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_CUR_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_CUR_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_CUR_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_CUR_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_CUR_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_CUR_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_CUR_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_CUR_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_CUR_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_CUR_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_CUR_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_CUR_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_CUR_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_CUR_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_CUR_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_CUR_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_CUR_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_CUR_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_CUR_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_CUR_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_CUR_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_CUR_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_CUR_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_CUR_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_CUR_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_CUR_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_CUR_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_CUR_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_CUR_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_CUR_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_CUR_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_CUR_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_CUR_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_CUR_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_CUR_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_CUR_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_CUR_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_CUR_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_CUR_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_CUR_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_CUR_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_CUR_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_CUR_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_CUR_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_CUR_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_CUR_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_CUR_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_CUR_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_CUR_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_CUR_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):FREQ_CUR_LAST_N_MAX",    "$(P,undefined):FREQ_CUR_MAX" )
alias( "$(P,undefined):FREQ_CUR_LAST_N_AVG",    "$(P,undefined):FREQ_CUR_AVG" )
alias( "$(P,undefined):FREQ_CUR_LAST_N_MIN",    "$(P,undefined):FREQ_CUR_MIN" )
alias( "$(P,undefined):FREQ_CUR_LAST_N_RMS",    "$(P,undefined):FREQ_CUR_RMS" )
alias( "$(P,undefined):FREQ_CUR_LAST_N_STD",    "$(P,undefined):FREQ_CUR_STD" )
alias( "$(P,undefined):FREQ_CUR_LAST_N_SLOPE",  "$(P,undefined):FREQ_CUR_SLOPE" )
alias( "$(P,undefined):FREQ_CUR_LAST_N_OFFSET", "$(P,undefined):FREQ_CUR_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_ERR_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_ERR_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_ERR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_ERR_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_ERR_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_ERR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_ERR_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_ERR_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_ERR_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_ERR_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_ERR_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_ERR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_ERR_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_ERR_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_ERR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_ERR_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_ERR_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_ERR_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_ERR_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_ERR_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_ERR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_ERR_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_ERR_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_ERR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_ERR_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_ERR_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_ERR_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_ERR_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_ERR_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_ERR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_ERR_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_ERR_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_ERR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_ERR_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_ERR_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_ERR_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_ERR_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_ERR_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_ERR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_ERR_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_ERR_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_ERR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_ERR_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_ERR_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_ERR_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_ERR_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_ERR_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_ERR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_ERR_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_ERR_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_ERR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_ERR_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_ERR_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_ERR_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_ERR_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_ERR_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_ERR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_ERR_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_ERR_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_ERR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_ERR_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_ERR_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_ERR_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_ERR_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_ERR_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_ERR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_ERR_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_ERR_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_ERR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_ERR_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_ERR_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_ERR_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_ERR_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_ERR_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_ERR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_ERR_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_ERR_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_ERR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_ERR_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_ERR_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_ERR_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_ERR_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_ERR_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_ERR_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_ERR_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_ERR_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_ERR_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_ERR_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_ERR_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_ERR_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_ERR_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_ERR_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_ERR_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_ERR_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_ERR_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_ERR_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_ERR_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_ERR_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_ERR_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_ERR_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_ERR_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_ERR_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_ERR_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_ERR_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_ERR_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_ERR_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_ERR_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_ERR_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_ERR_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_ERR_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_ERR_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_ERR_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_ERR_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_ERR_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_ERR_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_ERR_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_ERR_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_ERR_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_ERR_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_ERR_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_ERR_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_ERR_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_ERR_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_ERR_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_ERR_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_ERR_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_ERR_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_ERR_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_ERR_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_ERR_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_ERR_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_ERR_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_ERR_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_ERR_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_ERR_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_ERR_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_ERR_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_ERR_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_ERR_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_ERR_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_ERR_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_ERR_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_ERR_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_ERR_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_ERR_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_ERR_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_ERR_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_ERR_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_ERR_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_ERR_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_ERR_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_ERR_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_ERR_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_ERR_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_ERR_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_ERR_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_ERR_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_ERR_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_ERR_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_ERR_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_ERR_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_ERR_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_ERR_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_ERR_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_ERR_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_ERR_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_ERR_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_ERR_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_ERR_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_ERR_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_ERR_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):FREQ_ERR_LAST_N_MAX",    "$(P,undefined):FREQ_ERR_MAX" )
alias( "$(P,undefined):FREQ_ERR_LAST_N_AVG",    "$(P,undefined):FREQ_ERR_AVG" )
alias( "$(P,undefined):FREQ_ERR_LAST_N_MIN",    "$(P,undefined):FREQ_ERR_MIN" )
alias( "$(P,undefined):FREQ_ERR_LAST_N_RMS",    "$(P,undefined):FREQ_ERR_RMS" )
alias( "$(P,undefined):FREQ_ERR_LAST_N_STD",    "$(P,undefined):FREQ_ERR_STD" )
alias( "$(P,undefined):FREQ_ERR_LAST_N_SLOPE",  "$(P,undefined):FREQ_ERR_SLOPE" )
alias( "$(P,undefined):FREQ_ERR_LAST_N_OFFSET", "$(P,undefined):FREQ_ERR_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_ERR_SMOOTHED_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_ERR_SMOOTHED CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_ERR_SMOOTHED.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_ERR_SMOOTHED_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_ERR_SMOOTHED CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_ERR_SMOOTHED.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_ERR_SMOOTHED_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_ERR_SMOOTHED CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_ERR_SMOOTHED.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_ERR_SMOOTHED_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_ERR_SMOOTHED CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_ERR_SMOOTHED.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_ERR_SMOOTHED_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_ERR_SMOOTHED CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_ERR_SMOOTHED.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_ERR_SMOOTHED_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_ERR_SMOOTHED CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_ERR_SMOOTHED.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_ERR_SMOOTHED_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_ERR_SMOOTHED CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_ERR_SMOOTHED.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_ERR_SMOOTHED_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_ERR_SMOOTHED CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_ERR_SMOOTHED.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_ERR_SMOOTHED_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_ERR_SMOOTHED CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_ERR_SMOOTHED.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "Hz/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_ERR_SMOOTHED_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Hz" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_MAX",    "$(P,undefined):FREQ_ERR_SMOOTHED_MAX" )
alias( "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_AVG",    "$(P,undefined):FREQ_ERR_SMOOTHED_AVG" )
alias( "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_MIN",    "$(P,undefined):FREQ_ERR_SMOOTHED_MIN" )
alias( "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_RMS",    "$(P,undefined):FREQ_ERR_SMOOTHED_RMS" )
alias( "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_STD",    "$(P,undefined):FREQ_ERR_SMOOTHED_STD" )
alias( "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_SLOPE",  "$(P,undefined):FREQ_ERR_SMOOTHED_SLOPE" )
alias( "$(P,undefined):FREQ_ERR_SMOOTHED_LAST_N_OFFSET", "$(P,undefined):FREQ_ERR_SMOOTHED_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_MOTOR_POS_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_MOTOR_POS_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_MOTOR_POS CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_POS_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_MOTOR_POS_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_MOTOR_POS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_MOTOR_POS_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_MOTOR_POS_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_MOTOR_POS_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_MOTOR_POS_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_MOTOR_POS_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_MOTOR_POS CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_POS_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_MOTOR_POS_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_MOTOR_POS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_MOTOR_POS_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_MOTOR_POS_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_MOTOR_POS_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_MOTOR_POS_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_MOTOR_POS_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_MOTOR_POS CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_POS_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_MOTOR_POS_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_MOTOR_POS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_MOTOR_POS_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_MOTOR_POS_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_MOTOR_POS_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_MOTOR_POS_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_MOTOR_POS_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_MOTOR_POS CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_POS_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_MOTOR_POS_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_MOTOR_POS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_MOTOR_POS_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_MOTOR_POS_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_MOTOR_POS_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_MOTOR_POS_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_MOTOR_POS_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_MOTOR_POS CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_POS_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_MOTOR_POS_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_MOTOR_POS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_MOTOR_POS_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_MOTOR_POS_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_MOTOR_POS_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_MOTOR_POS_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_MOTOR_POS_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_MOTOR_POS CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_POS_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_MOTOR_POS_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_MOTOR_POS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_MOTOR_POS_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_MOTOR_POS_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_MOTOR_POS_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_MOTOR_POS_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_MOTOR_POS_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_MOTOR_POS CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_POS_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_MOTOR_POS_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_MOTOR_POS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_MOTOR_POS_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_MOTOR_POS_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_MOTOR_POS_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_MOTOR_POS_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_MOTOR_POS_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_MOTOR_POS CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_POS_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_MOTOR_POS_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_MOTOR_POS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_MOTOR_POS_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_MOTOR_POS_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_MOTOR_POS_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_MOTOR_POS_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_MOTOR_POS_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_MOTOR_POS CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_POS_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_MOTOR_POS_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_MOTOR_POS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_MOTOR_POS_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_MOTOR_POS_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_MOTOR_POS_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_MOTOR_POS_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_MOTOR_POS_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_POS_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_MOTOR_POS_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_MOTOR_POS_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_MOTOR_POS_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_MOTOR_POS_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_MOTOR_POS_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_MOTOR_POS_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_MOTOR_POS_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_MOTOR_POS_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_POS_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_MOTOR_POS_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_MOTOR_POS_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_MOTOR_POS_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_MOTOR_POS_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_MOTOR_POS_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_MOTOR_POS_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_MOTOR_POS_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_MOTOR_POS_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_POS_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_MOTOR_POS_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_MOTOR_POS_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_MOTOR_POS_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_MOTOR_POS_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_MOTOR_POS_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_MOTOR_POS_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_MOTOR_POS_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_MOTOR_POS_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_POS_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_MOTOR_POS_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_MOTOR_POS_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_MOTOR_POS_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_MOTOR_POS_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_MOTOR_POS_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_MOTOR_POS_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_MOTOR_POS_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_MOTOR_POS_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_POS_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_MOTOR_POS_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_MOTOR_POS_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_MOTOR_POS_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_MOTOR_POS_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_MOTOR_POS_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_MOTOR_POS_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_MOTOR_POS_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_MOTOR_POS_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_POS_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_MOTOR_POS_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_MOTOR_POS_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_MOTOR_POS_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_MOTOR_POS_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_MOTOR_POS_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_MOTOR_POS_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_MOTOR_POS_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_MOTOR_POS_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_POS_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_MOTOR_POS_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_MOTOR_POS_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_MOTOR_POS_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_MOTOR_POS_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_MOTOR_POS_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_MOTOR_POS_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_MOTOR_POS_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_MOTOR_POS_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_POS_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_MOTOR_POS_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_MOTOR_POS_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_MOTOR_POS_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_MOTOR_POS_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_MOTOR_POS_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_MOTOR_POS_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_MOTOR_POS_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_MOTOR_POS_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_POS_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_MOTOR_POS_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_MOTOR_POS_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_MOTOR_POS_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_MOTOR_POS_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_MOTOR_POS_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_MOTOR_POS_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_POS_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):FREQ_MOTOR_POS_LAST_N_MAX",    "$(P,undefined):FREQ_MOTOR_POS_MAX" )
alias( "$(P,undefined):FREQ_MOTOR_POS_LAST_N_AVG",    "$(P,undefined):FREQ_MOTOR_POS_AVG" )
alias( "$(P,undefined):FREQ_MOTOR_POS_LAST_N_MIN",    "$(P,undefined):FREQ_MOTOR_POS_MIN" )
alias( "$(P,undefined):FREQ_MOTOR_POS_LAST_N_RMS",    "$(P,undefined):FREQ_MOTOR_POS_RMS" )
alias( "$(P,undefined):FREQ_MOTOR_POS_LAST_N_STD",    "$(P,undefined):FREQ_MOTOR_POS_STD" )
alias( "$(P,undefined):FREQ_MOTOR_POS_LAST_N_SLOPE",  "$(P,undefined):FREQ_MOTOR_POS_SLOPE" )
alias( "$(P,undefined):FREQ_MOTOR_POS_LAST_N_OFFSET", "$(P,undefined):FREQ_MOTOR_POS_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_MOTOR_TGT_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_MOTOR_TGT CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_MOTOR_TGT.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_MOTOR_TGT_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_MOTOR_TGT_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_MOTOR_TGT CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_TGT_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_MOTOR_TGT_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_MOTOR_TGT.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_MOTOR_TGT_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_MOTOR_TGT_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_MOTOR_TGT_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_MOTOR_TGT_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_MOTOR_TGT_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_MOTOR_TGT CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_TGT_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_MOTOR_TGT_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_MOTOR_TGT.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_MOTOR_TGT_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_MOTOR_TGT_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_MOTOR_TGT_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_MOTOR_TGT_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_MOTOR_TGT_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_MOTOR_TGT CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_TGT_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_MOTOR_TGT_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_MOTOR_TGT.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_MOTOR_TGT_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_MOTOR_TGT_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_MOTOR_TGT_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_MOTOR_TGT_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_MOTOR_TGT_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_MOTOR_TGT CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_TGT_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_MOTOR_TGT_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_MOTOR_TGT.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_MOTOR_TGT_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_MOTOR_TGT_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_MOTOR_TGT_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_MOTOR_TGT_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_MOTOR_TGT_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_MOTOR_TGT CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_TGT_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_MOTOR_TGT_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_MOTOR_TGT.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_MOTOR_TGT_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_MOTOR_TGT_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_MOTOR_TGT_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_MOTOR_TGT_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_MOTOR_TGT_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_MOTOR_TGT CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_TGT_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_MOTOR_TGT_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_MOTOR_TGT.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_MOTOR_TGT_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_MOTOR_TGT_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_MOTOR_TGT_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_MOTOR_TGT_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_MOTOR_TGT_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_MOTOR_TGT CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_TGT_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_MOTOR_TGT_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_MOTOR_TGT.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_MOTOR_TGT_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_MOTOR_TGT_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_MOTOR_TGT_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FREQ_MOTOR_TGT_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FREQ_MOTOR_TGT_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FREQ_MOTOR_TGT CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_TGT_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FREQ_MOTOR_TGT_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FREQ_MOTOR_TGT.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FREQ_MOTOR_TGT_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FREQ_MOTOR_TGT_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):FREQ_MOTOR_TGT_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_MOTOR_TGT_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_MOTOR_TGT_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_TGT_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_MOTOR_TGT_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_MOTOR_TGT_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_MOTOR_TGT_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_MOTOR_TGT_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_MOTOR_TGT_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_MOTOR_TGT_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_MOTOR_TGT_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_MOTOR_TGT_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_TGT_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_MOTOR_TGT_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_MOTOR_TGT_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_MOTOR_TGT_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_MOTOR_TGT_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_MOTOR_TGT_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_MOTOR_TGT_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_MOTOR_TGT_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_MOTOR_TGT_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_TGT_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_MOTOR_TGT_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_MOTOR_TGT_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_MOTOR_TGT_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_MOTOR_TGT_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_MOTOR_TGT_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_MOTOR_TGT_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_MOTOR_TGT_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_MOTOR_TGT_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_TGT_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_MOTOR_TGT_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_MOTOR_TGT_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_MOTOR_TGT_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_MOTOR_TGT_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_MOTOR_TGT_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_MOTOR_TGT_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_MOTOR_TGT_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_MOTOR_TGT_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_TGT_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_MOTOR_TGT_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_MOTOR_TGT_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_MOTOR_TGT_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_MOTOR_TGT_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_MOTOR_TGT_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_MOTOR_TGT_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_MOTOR_TGT_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_MOTOR_TGT_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_TGT_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_MOTOR_TGT_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_MOTOR_TGT_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_MOTOR_TGT_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_MOTOR_TGT_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_MOTOR_TGT_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_MOTOR_TGT_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_MOTOR_TGT_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_MOTOR_TGT_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_TGT_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_MOTOR_TGT_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_MOTOR_TGT_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_MOTOR_TGT_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_MOTOR_TGT_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_MOTOR_TGT_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_MOTOR_TGT_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FREQ_MOTOR_TGT_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FREQ_MOTOR_TGT_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FREQ_MOTOR_TGT_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FREQ_MOTOR_TGT_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FREQ_MOTOR_TGT_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FREQ_MOTOR_TGT_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FREQ_MOTOR_TGT_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FREQ_MOTOR_TGT_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FREQ_MOTOR_TGT_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FREQ_MOTOR_TGT_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_MAX",    "$(P,undefined):FREQ_MOTOR_TGT_MAX" )
alias( "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_AVG",    "$(P,undefined):FREQ_MOTOR_TGT_AVG" )
alias( "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_MIN",    "$(P,undefined):FREQ_MOTOR_TGT_MIN" )
alias( "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_RMS",    "$(P,undefined):FREQ_MOTOR_TGT_RMS" )
alias( "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_STD",    "$(P,undefined):FREQ_MOTOR_TGT_STD" )
alias( "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_SLOPE",  "$(P,undefined):FREQ_MOTOR_TGT_SLOPE" )
alias( "$(P,undefined):FREQ_MOTOR_TGT_LAST_N_OFFSET", "$(P,undefined):FREQ_MOTOR_TGT_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PHASE_MOTOR_POS_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PHASE_MOTOR_POS_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PHASE_MOTOR_POS CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PHASE_MOTOR_POS_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PHASE_MOTOR_POS_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PHASE_MOTOR_POS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PHASE_MOTOR_POS_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PHASE_MOTOR_POS_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):PHASE_MOTOR_POS_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PHASE_MOTOR_POS_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PHASE_MOTOR_POS_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PHASE_MOTOR_POS CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PHASE_MOTOR_POS_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PHASE_MOTOR_POS_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PHASE_MOTOR_POS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PHASE_MOTOR_POS_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PHASE_MOTOR_POS_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PHASE_MOTOR_POS_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PHASE_MOTOR_POS_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PHASE_MOTOR_POS_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PHASE_MOTOR_POS CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PHASE_MOTOR_POS_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PHASE_MOTOR_POS_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PHASE_MOTOR_POS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PHASE_MOTOR_POS_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PHASE_MOTOR_POS_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PHASE_MOTOR_POS_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PHASE_MOTOR_POS_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PHASE_MOTOR_POS_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PHASE_MOTOR_POS CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PHASE_MOTOR_POS_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PHASE_MOTOR_POS_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PHASE_MOTOR_POS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PHASE_MOTOR_POS_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PHASE_MOTOR_POS_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PHASE_MOTOR_POS_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PHASE_MOTOR_POS_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PHASE_MOTOR_POS_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PHASE_MOTOR_POS CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PHASE_MOTOR_POS_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PHASE_MOTOR_POS_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PHASE_MOTOR_POS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PHASE_MOTOR_POS_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PHASE_MOTOR_POS_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PHASE_MOTOR_POS_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PHASE_MOTOR_POS_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PHASE_MOTOR_POS_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PHASE_MOTOR_POS CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PHASE_MOTOR_POS_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PHASE_MOTOR_POS_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PHASE_MOTOR_POS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PHASE_MOTOR_POS_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PHASE_MOTOR_POS_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PHASE_MOTOR_POS_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PHASE_MOTOR_POS_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PHASE_MOTOR_POS_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PHASE_MOTOR_POS CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PHASE_MOTOR_POS_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PHASE_MOTOR_POS_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PHASE_MOTOR_POS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PHASE_MOTOR_POS_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PHASE_MOTOR_POS_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PHASE_MOTOR_POS_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PHASE_MOTOR_POS_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PHASE_MOTOR_POS_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PHASE_MOTOR_POS CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PHASE_MOTOR_POS_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PHASE_MOTOR_POS_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PHASE_MOTOR_POS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PHASE_MOTOR_POS_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PHASE_MOTOR_POS_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):PHASE_MOTOR_POS_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PHASE_MOTOR_POS_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PHASE_MOTOR_POS_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PHASE_MOTOR_POS CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PHASE_MOTOR_POS_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PHASE_MOTOR_POS_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PHASE_MOTOR_POS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PHASE_MOTOR_POS_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PHASE_MOTOR_POS_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):PHASE_MOTOR_POS_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PHASE_MOTOR_POS_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PHASE_MOTOR_POS_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PHASE_MOTOR_POS_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PHASE_MOTOR_POS_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PHASE_MOTOR_POS_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PHASE_MOTOR_POS_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PHASE_MOTOR_POS_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PHASE_MOTOR_POS_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PHASE_MOTOR_POS_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ps/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PHASE_MOTOR_POS_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PHASE_MOTOR_POS_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PHASE_MOTOR_POS_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PHASE_MOTOR_POS_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PHASE_MOTOR_POS_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PHASE_MOTOR_POS_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PHASE_MOTOR_POS_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PHASE_MOTOR_POS_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PHASE_MOTOR_POS_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ps/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PHASE_MOTOR_POS_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PHASE_MOTOR_POS_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PHASE_MOTOR_POS_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PHASE_MOTOR_POS_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PHASE_MOTOR_POS_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PHASE_MOTOR_POS_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PHASE_MOTOR_POS_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PHASE_MOTOR_POS_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PHASE_MOTOR_POS_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ps/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PHASE_MOTOR_POS_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PHASE_MOTOR_POS_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PHASE_MOTOR_POS_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PHASE_MOTOR_POS_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PHASE_MOTOR_POS_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PHASE_MOTOR_POS_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PHASE_MOTOR_POS_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PHASE_MOTOR_POS_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PHASE_MOTOR_POS_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ps/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PHASE_MOTOR_POS_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PHASE_MOTOR_POS_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PHASE_MOTOR_POS_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PHASE_MOTOR_POS_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PHASE_MOTOR_POS_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PHASE_MOTOR_POS_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PHASE_MOTOR_POS_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PHASE_MOTOR_POS_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PHASE_MOTOR_POS_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ps/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PHASE_MOTOR_POS_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PHASE_MOTOR_POS_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PHASE_MOTOR_POS_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PHASE_MOTOR_POS_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PHASE_MOTOR_POS_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PHASE_MOTOR_POS_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PHASE_MOTOR_POS_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PHASE_MOTOR_POS_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PHASE_MOTOR_POS_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ps/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PHASE_MOTOR_POS_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PHASE_MOTOR_POS_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PHASE_MOTOR_POS_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PHASE_MOTOR_POS_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PHASE_MOTOR_POS_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PHASE_MOTOR_POS_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PHASE_MOTOR_POS_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PHASE_MOTOR_POS_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PHASE_MOTOR_POS_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ps/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PHASE_MOTOR_POS_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PHASE_MOTOR_POS_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PHASE_MOTOR_POS_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PHASE_MOTOR_POS_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PHASE_MOTOR_POS_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PHASE_MOTOR_POS_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PHASE_MOTOR_POS_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PHASE_MOTOR_POS_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PHASE_MOTOR_POS_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ps/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PHASE_MOTOR_POS_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PHASE_MOTOR_POS_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PHASE_MOTOR_POS_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PHASE_MOTOR_POS_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PHASE_MOTOR_POS_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PHASE_MOTOR_POS_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PHASE_MOTOR_POS_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PHASE_MOTOR_POS_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PHASE_MOTOR_POS_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ps/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PHASE_MOTOR_POS_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):PHASE_MOTOR_POS_LAST_N_MAX",    "$(P,undefined):PHASE_MOTOR_POS_MAX" )
alias( "$(P,undefined):PHASE_MOTOR_POS_LAST_N_AVG",    "$(P,undefined):PHASE_MOTOR_POS_AVG" )
alias( "$(P,undefined):PHASE_MOTOR_POS_LAST_N_MIN",    "$(P,undefined):PHASE_MOTOR_POS_MIN" )
alias( "$(P,undefined):PHASE_MOTOR_POS_LAST_N_RMS",    "$(P,undefined):PHASE_MOTOR_POS_RMS" )
alias( "$(P,undefined):PHASE_MOTOR_POS_LAST_N_STD",    "$(P,undefined):PHASE_MOTOR_POS_STD" )
alias( "$(P,undefined):PHASE_MOTOR_POS_LAST_N_SLOPE",  "$(P,undefined):PHASE_MOTOR_POS_SLOPE" )
alias( "$(P,undefined):PHASE_MOTOR_POS_LAST_N_OFFSET", "$(P,undefined):PHASE_MOTOR_POS_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):M1_MOTR_C_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):M1_MOTR_C_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):M1_MOTR_C CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):M1_MOTR_C_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):M1_MOTR_C_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):M1_MOTR_C.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):M1_MOTR_C_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):M1_MOTR_C_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):M1_MOTR_C_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):M1_MOTR_C_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):M1_MOTR_C_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):M1_MOTR_C CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):M1_MOTR_C_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):M1_MOTR_C_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):M1_MOTR_C.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):M1_MOTR_C_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):M1_MOTR_C_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):M1_MOTR_C_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):M1_MOTR_C_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):M1_MOTR_C_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):M1_MOTR_C CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):M1_MOTR_C_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):M1_MOTR_C_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):M1_MOTR_C.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):M1_MOTR_C_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):M1_MOTR_C_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):M1_MOTR_C_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):M1_MOTR_C_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):M1_MOTR_C_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):M1_MOTR_C CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):M1_MOTR_C_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):M1_MOTR_C_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):M1_MOTR_C.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):M1_MOTR_C_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):M1_MOTR_C_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):M1_MOTR_C_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):M1_MOTR_C_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):M1_MOTR_C_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):M1_MOTR_C CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):M1_MOTR_C_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):M1_MOTR_C_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):M1_MOTR_C.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):M1_MOTR_C_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):M1_MOTR_C_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):M1_MOTR_C_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):M1_MOTR_C_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):M1_MOTR_C_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):M1_MOTR_C CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):M1_MOTR_C_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):M1_MOTR_C_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):M1_MOTR_C.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):M1_MOTR_C_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):M1_MOTR_C_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):M1_MOTR_C_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):M1_MOTR_C_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):M1_MOTR_C_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):M1_MOTR_C CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):M1_MOTR_C_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):M1_MOTR_C_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):M1_MOTR_C.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):M1_MOTR_C_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):M1_MOTR_C_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):M1_MOTR_C_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):M1_MOTR_C_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):M1_MOTR_C_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):M1_MOTR_C CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):M1_MOTR_C_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):M1_MOTR_C_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):M1_MOTR_C.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):M1_MOTR_C_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):M1_MOTR_C_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):M1_MOTR_C_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):M1_MOTR_C_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):M1_MOTR_C_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):M1_MOTR_C CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):M1_MOTR_C_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):M1_MOTR_C_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):M1_MOTR_C.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):M1_MOTR_C_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):M1_MOTR_C_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):M1_MOTR_C_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):M1_MOTR_C_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):M1_MOTR_C_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):M1_MOTR_C_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):M1_MOTR_C_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):M1_MOTR_C_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):M1_MOTR_C_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):M1_MOTR_C_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):M1_MOTR_C_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):M1_MOTR_C_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):M1_MOTR_C_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):M1_MOTR_C_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):M1_MOTR_C_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):M1_MOTR_C_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):M1_MOTR_C_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):M1_MOTR_C_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):M1_MOTR_C_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):M1_MOTR_C_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):M1_MOTR_C_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):M1_MOTR_C_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):M1_MOTR_C_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):M1_MOTR_C_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):M1_MOTR_C_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):M1_MOTR_C_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):M1_MOTR_C_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):M1_MOTR_C_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):M1_MOTR_C_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):M1_MOTR_C_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):M1_MOTR_C_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):M1_MOTR_C_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):M1_MOTR_C_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):M1_MOTR_C_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):M1_MOTR_C_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):M1_MOTR_C_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):M1_MOTR_C_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):M1_MOTR_C_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):M1_MOTR_C_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):M1_MOTR_C_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):M1_MOTR_C_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):M1_MOTR_C_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):M1_MOTR_C_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):M1_MOTR_C_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):M1_MOTR_C_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):M1_MOTR_C_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):M1_MOTR_C_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):M1_MOTR_C_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):M1_MOTR_C_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):M1_MOTR_C_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):M1_MOTR_C_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):M1_MOTR_C_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):M1_MOTR_C_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):M1_MOTR_C_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):M1_MOTR_C_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):M1_MOTR_C_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):M1_MOTR_C_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):M1_MOTR_C_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):M1_MOTR_C_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):M1_MOTR_C_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):M1_MOTR_C_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):M1_MOTR_C_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):M1_MOTR_C_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):M1_MOTR_C_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):M1_MOTR_C_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):M1_MOTR_C_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):M1_MOTR_C_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):M1_MOTR_C_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):M1_MOTR_C_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):M1_MOTR_C_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):M1_MOTR_C_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):M1_MOTR_C_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):M1_MOTR_C_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):M1_MOTR_C_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):M1_MOTR_C_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):M1_MOTR_C_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):M1_MOTR_C_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):M1_MOTR_C_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):M1_MOTR_C_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):M1_MOTR_C_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):M1_MOTR_C_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):M1_MOTR_C_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):M1_MOTR_C_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):M1_MOTR_C_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):M1_MOTR_C_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):M1_MOTR_C_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):M1_MOTR_C_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):M1_MOTR_C_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):M1_MOTR_C_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):M1_MOTR_C_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):M1_MOTR_C_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):M1_MOTR_C_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):M1_MOTR_C_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):M1_MOTR_C_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):M1_MOTR_C_LAST_N_MAX",    "$(P,undefined):M1_MOTR_C_MAX" )
alias( "$(P,undefined):M1_MOTR_C_LAST_N_AVG",    "$(P,undefined):M1_MOTR_C_AVG" )
alias( "$(P,undefined):M1_MOTR_C_LAST_N_MIN",    "$(P,undefined):M1_MOTR_C_MIN" )
alias( "$(P,undefined):M1_MOTR_C_LAST_N_RMS",    "$(P,undefined):M1_MOTR_C_RMS" )
alias( "$(P,undefined):M1_MOTR_C_LAST_N_STD",    "$(P,undefined):M1_MOTR_C_STD" )
alias( "$(P,undefined):M1_MOTR_C_LAST_N_SLOPE",  "$(P,undefined):M1_MOTR_C_SLOPE" )
alias( "$(P,undefined):M1_MOTR_C_LAST_N_OFFSET", "$(P,undefined):M1_MOTR_C_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_WRITE_MOTOR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_WRITE_MOTOR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_WRITE_MOTOR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_WRITE_MOTOR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_WRITE_MOTOR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_WRITE_MOTOR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_WRITE_MOTOR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_WRITE_MOTOR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_WRITE_MOTOR_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_WRITE_MOTOR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_WRITE_MOTOR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_WRITE_MOTOR_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_WRITE_MOTOR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_WRITE_MOTOR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_WRITE_MOTOR_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_WRITE_MOTOR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_WRITE_MOTOR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_WRITE_MOTOR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_WRITE_MOTOR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_WRITE_MOTOR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_WRITE_MOTOR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "mm/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_WRITE_MOTOR_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mm" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_MAX",    "$(P,undefined):PID_COARSE_WRITE_MOTOR_MAX" )
alias( "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_AVG",    "$(P,undefined):PID_COARSE_WRITE_MOTOR_AVG" )
alias( "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_MIN",    "$(P,undefined):PID_COARSE_WRITE_MOTOR_MIN" )
alias( "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_RMS",    "$(P,undefined):PID_COARSE_WRITE_MOTOR_RMS" )
alias( "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_STD",    "$(P,undefined):PID_COARSE_WRITE_MOTOR_STD" )
alias( "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_SLOPE",  "$(P,undefined):PID_COARSE_WRITE_MOTOR_SLOPE" )
alias( "$(P,undefined):PID_COARSE_WRITE_MOTOR_LAST_N_OFFSET", "$(P,undefined):PID_COARSE_WRITE_MOTOR_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_D_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_D_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_D CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_D_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_D_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_D.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_D_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_D_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_D_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_D_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_D_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_D CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_D_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_D_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_D.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_D_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_D_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_D_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_D_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_D_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_D CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_D_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_D_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_D.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_D_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_D_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_D_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_D_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_D_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_D CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_D_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_D_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_D.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_D_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_D_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_D_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_D_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_D_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_D CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_D_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_D_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_D.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_D_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_D_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_D_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_D_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_D_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_D CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_D_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_D_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_D.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_D_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_D_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_D_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_D_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_D_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_D CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_D_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_D_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_D.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_D_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_D_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_D_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_D_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_D_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_D CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_D_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_D_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_D.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_D_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_D_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_D_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_D_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_D_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_D CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_D_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_D_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_D.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_D_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_D_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_D_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_D_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_D_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_D_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_D_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_D_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_D_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_D_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_D_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_D_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_D_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_D_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_D_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_D_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_D_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_D_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_D_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_D_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_D_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_D_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_D_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_D_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_D_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_D_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_D_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_D_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_D_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_D_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_D_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_D_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_D_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_D_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_D_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_D_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_D_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_D_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_D_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_D_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_D_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_D_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_D_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_D_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_D_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_D_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_D_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_D_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_D_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_D_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_D_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_D_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_D_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_D_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_D_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_D_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_D_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_D_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_D_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_D_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_D_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_D_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_D_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_D_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_D_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_D_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_D_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_D_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_D_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_D_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_D_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_D_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_D_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_D_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_D_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_D_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_D_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_D_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_D_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_D_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_D_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_D_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_D_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_D_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_D_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_D_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_D_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_D_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_D_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_D_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_D_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_D_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_D_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_D_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):PID_COARSE_D_LAST_N_MAX",    "$(P,undefined):PID_COARSE_D_MAX" )
alias( "$(P,undefined):PID_COARSE_D_LAST_N_AVG",    "$(P,undefined):PID_COARSE_D_AVG" )
alias( "$(P,undefined):PID_COARSE_D_LAST_N_MIN",    "$(P,undefined):PID_COARSE_D_MIN" )
alias( "$(P,undefined):PID_COARSE_D_LAST_N_RMS",    "$(P,undefined):PID_COARSE_D_RMS" )
alias( "$(P,undefined):PID_COARSE_D_LAST_N_STD",    "$(P,undefined):PID_COARSE_D_STD" )
alias( "$(P,undefined):PID_COARSE_D_LAST_N_SLOPE",  "$(P,undefined):PID_COARSE_D_SLOPE" )
alias( "$(P,undefined):PID_COARSE_D_LAST_N_OFFSET", "$(P,undefined):PID_COARSE_D_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_ERR_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_ERR_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_ERR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_ERR_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_ERR_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_ERR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_ERR_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_ERR_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_ERR_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_ERR_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_ERR_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_ERR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_ERR_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_ERR_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_ERR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_ERR_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_ERR_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_ERR_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_ERR_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_ERR_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_ERR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_ERR_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_ERR_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_ERR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_ERR_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_ERR_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_ERR_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_ERR_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_ERR_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_ERR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_ERR_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_ERR_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_ERR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_ERR_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_ERR_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_ERR_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_ERR_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_ERR_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_ERR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_ERR_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_ERR_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_ERR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_ERR_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_ERR_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_ERR_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_ERR_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_ERR_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_ERR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_ERR_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_ERR_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_ERR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_ERR_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_ERR_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_ERR_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_ERR_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_ERR_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_ERR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_ERR_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_ERR_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_ERR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_ERR_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_ERR_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_ERR_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_ERR_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_ERR_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_ERR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_ERR_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_ERR_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_ERR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_ERR_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_ERR_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_ERR_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_ERR_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_ERR_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_ERR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_ERR_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_ERR_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_ERR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_ERR_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_ERR_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_ERR_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_ERR_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_ERR_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_ERR_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_ERR_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_ERR_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_ERR_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_ERR_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_ERR_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_ERR_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_ERR_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_ERR_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_ERR_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_ERR_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_ERR_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_ERR_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_ERR_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_ERR_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_ERR_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_ERR_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_ERR_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_ERR_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_ERR_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_ERR_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_ERR_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_ERR_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_ERR_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_ERR_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_ERR_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_ERR_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_ERR_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_ERR_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_ERR_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_ERR_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_ERR_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_ERR_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_ERR_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_ERR_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_ERR_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_ERR_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_ERR_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_ERR_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_ERR_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_ERR_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_ERR_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_ERR_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_ERR_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_ERR_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_ERR_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_ERR_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_ERR_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_ERR_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_ERR_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_ERR_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_ERR_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_ERR_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_ERR_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_ERR_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_ERR_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_ERR_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_ERR_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_ERR_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_ERR_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_ERR_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_ERR_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_ERR_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_ERR_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_ERR_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_ERR_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_ERR_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_ERR_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_ERR_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_ERR_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_ERR_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_ERR_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_ERR_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_ERR_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_ERR_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_ERR_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_ERR_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_ERR_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_ERR_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_ERR_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_ERR_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_ERR_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_ERR_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_ERR_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_ERR_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_ERR_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_ERR_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_ERR_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_ERR_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):PID_COARSE_ERR_LAST_N_MAX",    "$(P,undefined):PID_COARSE_ERR_MAX" )
alias( "$(P,undefined):PID_COARSE_ERR_LAST_N_AVG",    "$(P,undefined):PID_COARSE_ERR_AVG" )
alias( "$(P,undefined):PID_COARSE_ERR_LAST_N_MIN",    "$(P,undefined):PID_COARSE_ERR_MIN" )
alias( "$(P,undefined):PID_COARSE_ERR_LAST_N_RMS",    "$(P,undefined):PID_COARSE_ERR_RMS" )
alias( "$(P,undefined):PID_COARSE_ERR_LAST_N_STD",    "$(P,undefined):PID_COARSE_ERR_STD" )
alias( "$(P,undefined):PID_COARSE_ERR_LAST_N_SLOPE",  "$(P,undefined):PID_COARSE_ERR_SLOPE" )
alias( "$(P,undefined):PID_COARSE_ERR_LAST_N_OFFSET", "$(P,undefined):PID_COARSE_ERR_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_I_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_I_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_I CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_I_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_I_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_I.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_I_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_I_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_I_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_I_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_I_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_I CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_I_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_I_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_I.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_I_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_I_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_I_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_I_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_I_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_I CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_I_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_I_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_I.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_I_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_I_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_I_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_I_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_I_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_I CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_I_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_I_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_I.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_I_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_I_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_I_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_I_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_I_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_I CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_I_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_I_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_I.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_I_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_I_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_I_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_I_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_I_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_I CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_I_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_I_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_I.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_I_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_I_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_I_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_I_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_I_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_I CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_I_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_I_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_I.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_I_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_I_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_I_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_I_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_I_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_I CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_I_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_I_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_I.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_I_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_I_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_I_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_I_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_I_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_I CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_I_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_I_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_I.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_I_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_I_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_I_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_I_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_I_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_I_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_I_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_I_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_I_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_I_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_I_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_I_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_I_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_I_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_I_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_I_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_I_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_I_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_I_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_I_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_I_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_I_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_I_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_I_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_I_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_I_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_I_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_I_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_I_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_I_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_I_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_I_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_I_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_I_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_I_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_I_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_I_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_I_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_I_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_I_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_I_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_I_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_I_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_I_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_I_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_I_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_I_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_I_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_I_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_I_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_I_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_I_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_I_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_I_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_I_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_I_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_I_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_I_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_I_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_I_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_I_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_I_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_I_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_I_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_I_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_I_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_I_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_I_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_I_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_I_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_I_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_I_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_I_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_I_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_I_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_I_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_I_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_I_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_I_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_I_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_I_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_I_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_I_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_I_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_I_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_I_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_I_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_I_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_I_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_I_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_I_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_I_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_I_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_I_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):PID_COARSE_I_LAST_N_MAX",    "$(P,undefined):PID_COARSE_I_MAX" )
alias( "$(P,undefined):PID_COARSE_I_LAST_N_AVG",    "$(P,undefined):PID_COARSE_I_AVG" )
alias( "$(P,undefined):PID_COARSE_I_LAST_N_MIN",    "$(P,undefined):PID_COARSE_I_MIN" )
alias( "$(P,undefined):PID_COARSE_I_LAST_N_RMS",    "$(P,undefined):PID_COARSE_I_RMS" )
alias( "$(P,undefined):PID_COARSE_I_LAST_N_STD",    "$(P,undefined):PID_COARSE_I_STD" )
alias( "$(P,undefined):PID_COARSE_I_LAST_N_SLOPE",  "$(P,undefined):PID_COARSE_I_SLOPE" )
alias( "$(P,undefined):PID_COARSE_I_LAST_N_OFFSET", "$(P,undefined):PID_COARSE_I_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_OUTPUT_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_OUTPUT CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_OUTPUT.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_OUTPUT_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_OUTPUT_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_OUTPUT CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_OUTPUT_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_OUTPUT_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_OUTPUT.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_OUTPUT_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_OUTPUT_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_OUTPUT_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_OUTPUT_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_OUTPUT_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_OUTPUT CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_OUTPUT_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_OUTPUT_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_OUTPUT.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_OUTPUT_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_OUTPUT_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_OUTPUT_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_OUTPUT_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_OUTPUT_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_OUTPUT CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_OUTPUT_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_OUTPUT_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_OUTPUT.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_OUTPUT_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_OUTPUT_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_OUTPUT_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_OUTPUT_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_OUTPUT_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_OUTPUT CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_OUTPUT_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_OUTPUT_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_OUTPUT.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_OUTPUT_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_OUTPUT_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_OUTPUT_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_OUTPUT_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_OUTPUT_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_OUTPUT CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_OUTPUT_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_OUTPUT_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_OUTPUT.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_OUTPUT_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_OUTPUT_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_OUTPUT_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_OUTPUT_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_OUTPUT_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_OUTPUT CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_OUTPUT_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_OUTPUT_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_OUTPUT.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_OUTPUT_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_OUTPUT_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_OUTPUT_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_OUTPUT_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_OUTPUT_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_OUTPUT CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_OUTPUT_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_OUTPUT_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_OUTPUT.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_OUTPUT_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_OUTPUT_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_OUTPUT_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_OUTPUT_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_OUTPUT_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_OUTPUT CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_OUTPUT_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_OUTPUT_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_OUTPUT.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_OUTPUT_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_OUTPUT_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_OUTPUT_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_OUTPUT_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_OUTPUT_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_OUTPUT_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_OUTPUT_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_OUTPUT_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_OUTPUT_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_OUTPUT_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_OUTPUT_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_OUTPUT_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_OUTPUT_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_OUTPUT_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_OUTPUT_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_OUTPUT_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_OUTPUT_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_OUTPUT_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_OUTPUT_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_OUTPUT_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_OUTPUT_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_OUTPUT_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_OUTPUT_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_OUTPUT_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_OUTPUT_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_OUTPUT_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_OUTPUT_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_OUTPUT_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_OUTPUT_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_OUTPUT_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_OUTPUT_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_OUTPUT_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_OUTPUT_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_OUTPUT_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_OUTPUT_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_OUTPUT_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_OUTPUT_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_OUTPUT_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_OUTPUT_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_OUTPUT_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_OUTPUT_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_OUTPUT_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_OUTPUT_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_OUTPUT_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_OUTPUT_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_OUTPUT_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_OUTPUT_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_OUTPUT_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_OUTPUT_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_OUTPUT_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_OUTPUT_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_OUTPUT_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_OUTPUT_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_OUTPUT_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_OUTPUT_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_OUTPUT_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_OUTPUT_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_OUTPUT_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_OUTPUT_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_OUTPUT_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_OUTPUT_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_OUTPUT_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_OUTPUT_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_OUTPUT_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_OUTPUT_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_OUTPUT_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_OUTPUT_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_OUTPUT_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_OUTPUT_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_OUTPUT_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_OUTPUT_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_OUTPUT_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_OUTPUT_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_OUTPUT_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_OUTPUT_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_OUTPUT_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_MAX",    "$(P,undefined):PID_COARSE_OUTPUT_MAX" )
alias( "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_AVG",    "$(P,undefined):PID_COARSE_OUTPUT_AVG" )
alias( "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_MIN",    "$(P,undefined):PID_COARSE_OUTPUT_MIN" )
alias( "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_RMS",    "$(P,undefined):PID_COARSE_OUTPUT_RMS" )
alias( "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_STD",    "$(P,undefined):PID_COARSE_OUTPUT_STD" )
alias( "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_SLOPE",  "$(P,undefined):PID_COARSE_OUTPUT_SLOPE" )
alias( "$(P,undefined):PID_COARSE_OUTPUT_LAST_N_OFFSET", "$(P,undefined):PID_COARSE_OUTPUT_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_P_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_P_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_P CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_P_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_P_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_P.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_P_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_P_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_P_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_P_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_P_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_P CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_P_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_P_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_P.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_P_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_P_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_P_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_P_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_P_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_P CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_P_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_P_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_P.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_P_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_P_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_P_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_P_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_P_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_P CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_P_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_P_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_P.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_P_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_P_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_P_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_P_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_P_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_P CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_P_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_P_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_P.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_P_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_P_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_P_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_P_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_P_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_P CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_P_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_P_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_P.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_P_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_P_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_P_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_P_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_P_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_P CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_P_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_P_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_P.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_P_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_P_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_P_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_P_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_P_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_P CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_P_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_P_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_P.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_P_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_P_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_P_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_P_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_P_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_P CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_P_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_P_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_P.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_P_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_P_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_P_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_P_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_P_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_P_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_P_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_P_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_P_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_P_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_P_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_P_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_P_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_P_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_P_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_P_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_P_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_P_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_P_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_P_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_P_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_P_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_P_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_P_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_P_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_P_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_P_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_P_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_P_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_P_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_P_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_P_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_P_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_P_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_P_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_P_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_P_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_P_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_P_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_P_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_P_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_P_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_P_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_P_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_P_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_P_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_P_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_P_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_P_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_P_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_P_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_P_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_P_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_P_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_P_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_P_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_P_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_P_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_P_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_P_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_P_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_P_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_P_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_P_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_P_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_P_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_P_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_P_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_P_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_P_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_P_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_P_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_P_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_P_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_P_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_P_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_P_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_P_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_P_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_P_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_P_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_P_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_P_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_P_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_P_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_P_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_P_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_P_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_P_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_P_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_P_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_P_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_P_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_P_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):PID_COARSE_P_LAST_N_MAX",    "$(P,undefined):PID_COARSE_P_MAX" )
alias( "$(P,undefined):PID_COARSE_P_LAST_N_AVG",    "$(P,undefined):PID_COARSE_P_AVG" )
alias( "$(P,undefined):PID_COARSE_P_LAST_N_MIN",    "$(P,undefined):PID_COARSE_P_MIN" )
alias( "$(P,undefined):PID_COARSE_P_LAST_N_RMS",    "$(P,undefined):PID_COARSE_P_RMS" )
alias( "$(P,undefined):PID_COARSE_P_LAST_N_STD",    "$(P,undefined):PID_COARSE_P_STD" )
alias( "$(P,undefined):PID_COARSE_P_LAST_N_SLOPE",  "$(P,undefined):PID_COARSE_P_SLOPE" )
alias( "$(P,undefined):PID_COARSE_P_LAST_N_OFFSET", "$(P,undefined):PID_COARSE_P_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_TARGET_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_TARGET_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_TARGET CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_TARGET_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_TARGET_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_TARGET.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_TARGET_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_TARGET_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_TARGET_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_TARGET_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_TARGET_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_TARGET CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_TARGET_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_TARGET_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_TARGET.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_TARGET_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_TARGET_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_TARGET_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_TARGET_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_TARGET_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_TARGET CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_TARGET_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_TARGET_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_TARGET.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_TARGET_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_TARGET_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_TARGET_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_TARGET_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_TARGET_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_TARGET CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_TARGET_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_TARGET_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_TARGET.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_TARGET_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_TARGET_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_TARGET_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_TARGET_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_TARGET_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_TARGET CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_TARGET_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_TARGET_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_TARGET.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_TARGET_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_TARGET_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_TARGET_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_TARGET_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_TARGET_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_TARGET CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_TARGET_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_TARGET_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_TARGET.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_TARGET_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_TARGET_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_TARGET_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_TARGET_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_TARGET_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_TARGET CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_TARGET_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_TARGET_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_TARGET.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_TARGET_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_TARGET_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_TARGET_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_TARGET_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_TARGET_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_TARGET CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_TARGET_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_TARGET_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_TARGET.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_TARGET_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_TARGET_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_TARGET_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PID_COARSE_TARGET_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PID_COARSE_TARGET_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PID_COARSE_TARGET CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PID_COARSE_TARGET_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PID_COARSE_TARGET_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PID_COARSE_TARGET.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PID_COARSE_TARGET_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PID_COARSE_TARGET_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):PID_COARSE_TARGET_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_TARGET_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_TARGET_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_TARGET_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_TARGET_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_TARGET_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_TARGET_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_TARGET_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_TARGET_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_TARGET_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_TARGET_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_TARGET_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_TARGET_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_TARGET_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_TARGET_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_TARGET_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_TARGET_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_TARGET_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_TARGET_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_TARGET_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_TARGET_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_TARGET_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_TARGET_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_TARGET_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_TARGET_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_TARGET_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_TARGET_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_TARGET_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_TARGET_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_TARGET_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_TARGET_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_TARGET_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_TARGET_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_TARGET_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_TARGET_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_TARGET_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_TARGET_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_TARGET_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_TARGET_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_TARGET_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_TARGET_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_TARGET_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_TARGET_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_TARGET_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_TARGET_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_TARGET_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_TARGET_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_TARGET_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_TARGET_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_TARGET_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_TARGET_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_TARGET_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_TARGET_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_TARGET_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_TARGET_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_TARGET_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_TARGET_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_TARGET_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_TARGET_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_TARGET_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_TARGET_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_TARGET_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_TARGET_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_TARGET_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_TARGET_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_TARGET_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_TARGET_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_TARGET_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_TARGET_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_TARGET_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_TARGET_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_TARGET_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_TARGET_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PID_COARSE_TARGET_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PID_COARSE_TARGET_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PID_COARSE_TARGET_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PID_COARSE_TARGET_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PID_COARSE_TARGET_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PID_COARSE_TARGET_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PID_COARSE_TARGET_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PID_COARSE_TARGET_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PID_COARSE_TARGET_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "rad/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PID_COARSE_TARGET_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "rad" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):PID_COARSE_TARGET_LAST_N_MAX",    "$(P,undefined):PID_COARSE_TARGET_MAX" )
alias( "$(P,undefined):PID_COARSE_TARGET_LAST_N_AVG",    "$(P,undefined):PID_COARSE_TARGET_AVG" )
alias( "$(P,undefined):PID_COARSE_TARGET_LAST_N_MIN",    "$(P,undefined):PID_COARSE_TARGET_MIN" )
alias( "$(P,undefined):PID_COARSE_TARGET_LAST_N_RMS",    "$(P,undefined):PID_COARSE_TARGET_RMS" )
alias( "$(P,undefined):PID_COARSE_TARGET_LAST_N_STD",    "$(P,undefined):PID_COARSE_TARGET_STD" )
alias( "$(P,undefined):PID_COARSE_TARGET_LAST_N_SLOPE",  "$(P,undefined):PID_COARSE_TARGET_SLOPE" )
alias( "$(P,undefined):PID_COARSE_TARGET_LAST_N_OFFSET", "$(P,undefined):PID_COARSE_TARGET_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PIEZO_AMP_IN_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PIEZO_AMP_IN_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PIEZO_AMP_IN CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_IN_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PIEZO_AMP_IN_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PIEZO_AMP_IN.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PIEZO_AMP_IN_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PIEZO_AMP_IN_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):PIEZO_AMP_IN_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PIEZO_AMP_IN_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PIEZO_AMP_IN_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PIEZO_AMP_IN CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_IN_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PIEZO_AMP_IN_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PIEZO_AMP_IN.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PIEZO_AMP_IN_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PIEZO_AMP_IN_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PIEZO_AMP_IN_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PIEZO_AMP_IN_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PIEZO_AMP_IN_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PIEZO_AMP_IN CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_IN_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PIEZO_AMP_IN_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PIEZO_AMP_IN.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PIEZO_AMP_IN_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PIEZO_AMP_IN_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PIEZO_AMP_IN_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PIEZO_AMP_IN_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PIEZO_AMP_IN_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PIEZO_AMP_IN CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_IN_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PIEZO_AMP_IN_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PIEZO_AMP_IN.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PIEZO_AMP_IN_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PIEZO_AMP_IN_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PIEZO_AMP_IN_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PIEZO_AMP_IN_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PIEZO_AMP_IN_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PIEZO_AMP_IN CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_IN_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PIEZO_AMP_IN_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PIEZO_AMP_IN.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PIEZO_AMP_IN_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PIEZO_AMP_IN_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PIEZO_AMP_IN_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PIEZO_AMP_IN_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PIEZO_AMP_IN_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PIEZO_AMP_IN CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_IN_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PIEZO_AMP_IN_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PIEZO_AMP_IN.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PIEZO_AMP_IN_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PIEZO_AMP_IN_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PIEZO_AMP_IN_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PIEZO_AMP_IN_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PIEZO_AMP_IN_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PIEZO_AMP_IN CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_IN_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PIEZO_AMP_IN_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PIEZO_AMP_IN.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PIEZO_AMP_IN_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PIEZO_AMP_IN_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PIEZO_AMP_IN_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PIEZO_AMP_IN_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PIEZO_AMP_IN_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PIEZO_AMP_IN CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_IN_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PIEZO_AMP_IN_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PIEZO_AMP_IN.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PIEZO_AMP_IN_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PIEZO_AMP_IN_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):PIEZO_AMP_IN_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PIEZO_AMP_IN_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PIEZO_AMP_IN_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PIEZO_AMP_IN CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_IN_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PIEZO_AMP_IN_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PIEZO_AMP_IN.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PIEZO_AMP_IN_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PIEZO_AMP_IN_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):PIEZO_AMP_IN_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PIEZO_AMP_IN_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PIEZO_AMP_IN_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_IN_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PIEZO_AMP_IN_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PIEZO_AMP_IN_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PIEZO_AMP_IN_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PIEZO_AMP_IN_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PIEZO_AMP_IN_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PIEZO_AMP_IN_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "V" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "V/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PIEZO_AMP_IN_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PIEZO_AMP_IN_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_IN_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PIEZO_AMP_IN_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PIEZO_AMP_IN_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PIEZO_AMP_IN_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PIEZO_AMP_IN_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PIEZO_AMP_IN_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PIEZO_AMP_IN_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "V" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "V/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PIEZO_AMP_IN_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PIEZO_AMP_IN_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_IN_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PIEZO_AMP_IN_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PIEZO_AMP_IN_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PIEZO_AMP_IN_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PIEZO_AMP_IN_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PIEZO_AMP_IN_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PIEZO_AMP_IN_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "V" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "V/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PIEZO_AMP_IN_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PIEZO_AMP_IN_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_IN_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PIEZO_AMP_IN_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PIEZO_AMP_IN_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PIEZO_AMP_IN_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PIEZO_AMP_IN_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PIEZO_AMP_IN_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PIEZO_AMP_IN_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "V" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "V/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PIEZO_AMP_IN_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PIEZO_AMP_IN_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_IN_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PIEZO_AMP_IN_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PIEZO_AMP_IN_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PIEZO_AMP_IN_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PIEZO_AMP_IN_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PIEZO_AMP_IN_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PIEZO_AMP_IN_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "V" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "V/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PIEZO_AMP_IN_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PIEZO_AMP_IN_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_IN_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PIEZO_AMP_IN_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PIEZO_AMP_IN_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PIEZO_AMP_IN_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PIEZO_AMP_IN_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PIEZO_AMP_IN_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PIEZO_AMP_IN_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "V" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "V/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PIEZO_AMP_IN_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PIEZO_AMP_IN_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_IN_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PIEZO_AMP_IN_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PIEZO_AMP_IN_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PIEZO_AMP_IN_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PIEZO_AMP_IN_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PIEZO_AMP_IN_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PIEZO_AMP_IN_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "V" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "V/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PIEZO_AMP_IN_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PIEZO_AMP_IN_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_IN_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PIEZO_AMP_IN_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PIEZO_AMP_IN_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PIEZO_AMP_IN_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PIEZO_AMP_IN_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PIEZO_AMP_IN_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PIEZO_AMP_IN_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "V" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "V/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PIEZO_AMP_IN_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PIEZO_AMP_IN_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_IN_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PIEZO_AMP_IN_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PIEZO_AMP_IN_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PIEZO_AMP_IN_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PIEZO_AMP_IN_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PIEZO_AMP_IN_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PIEZO_AMP_IN_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "V" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "V/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_IN_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):PIEZO_AMP_IN_LAST_N_MAX",    "$(P,undefined):PIEZO_AMP_IN_MAX" )
alias( "$(P,undefined):PIEZO_AMP_IN_LAST_N_AVG",    "$(P,undefined):PIEZO_AMP_IN_AVG" )
alias( "$(P,undefined):PIEZO_AMP_IN_LAST_N_MIN",    "$(P,undefined):PIEZO_AMP_IN_MIN" )
alias( "$(P,undefined):PIEZO_AMP_IN_LAST_N_RMS",    "$(P,undefined):PIEZO_AMP_IN_RMS" )
alias( "$(P,undefined):PIEZO_AMP_IN_LAST_N_STD",    "$(P,undefined):PIEZO_AMP_IN_STD" )
alias( "$(P,undefined):PIEZO_AMP_IN_LAST_N_SLOPE",  "$(P,undefined):PIEZO_AMP_IN_SLOPE" )
alias( "$(P,undefined):PIEZO_AMP_IN_LAST_N_OFFSET", "$(P,undefined):PIEZO_AMP_IN_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PIEZO_AMP_MON_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PIEZO_AMP_MON_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PIEZO_AMP_MON CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_MON_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PIEZO_AMP_MON_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PIEZO_AMP_MON.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PIEZO_AMP_MON_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PIEZO_AMP_MON_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):PIEZO_AMP_MON_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PIEZO_AMP_MON_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PIEZO_AMP_MON_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PIEZO_AMP_MON CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_MON_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PIEZO_AMP_MON_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PIEZO_AMP_MON.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PIEZO_AMP_MON_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PIEZO_AMP_MON_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PIEZO_AMP_MON_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PIEZO_AMP_MON_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PIEZO_AMP_MON_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PIEZO_AMP_MON CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_MON_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PIEZO_AMP_MON_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PIEZO_AMP_MON.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PIEZO_AMP_MON_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PIEZO_AMP_MON_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PIEZO_AMP_MON_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PIEZO_AMP_MON_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PIEZO_AMP_MON_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PIEZO_AMP_MON CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_MON_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PIEZO_AMP_MON_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PIEZO_AMP_MON.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PIEZO_AMP_MON_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PIEZO_AMP_MON_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):PIEZO_AMP_MON_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PIEZO_AMP_MON_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PIEZO_AMP_MON_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PIEZO_AMP_MON CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_MON_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PIEZO_AMP_MON_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PIEZO_AMP_MON.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PIEZO_AMP_MON_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PIEZO_AMP_MON_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PIEZO_AMP_MON_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PIEZO_AMP_MON_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PIEZO_AMP_MON_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PIEZO_AMP_MON CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_MON_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PIEZO_AMP_MON_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PIEZO_AMP_MON.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PIEZO_AMP_MON_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PIEZO_AMP_MON_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PIEZO_AMP_MON_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PIEZO_AMP_MON_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PIEZO_AMP_MON_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PIEZO_AMP_MON CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_MON_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PIEZO_AMP_MON_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PIEZO_AMP_MON.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PIEZO_AMP_MON_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PIEZO_AMP_MON_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):PIEZO_AMP_MON_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PIEZO_AMP_MON_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PIEZO_AMP_MON_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PIEZO_AMP_MON CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_MON_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PIEZO_AMP_MON_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PIEZO_AMP_MON.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PIEZO_AMP_MON_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PIEZO_AMP_MON_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):PIEZO_AMP_MON_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):PIEZO_AMP_MON_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):PIEZO_AMP_MON_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):PIEZO_AMP_MON CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_MON_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):PIEZO_AMP_MON_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):PIEZO_AMP_MON.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):PIEZO_AMP_MON_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):PIEZO_AMP_MON_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):PIEZO_AMP_MON_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PIEZO_AMP_MON_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PIEZO_AMP_MON_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_MON_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PIEZO_AMP_MON_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PIEZO_AMP_MON_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PIEZO_AMP_MON_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PIEZO_AMP_MON_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PIEZO_AMP_MON_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PIEZO_AMP_MON_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "V" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "V/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PIEZO_AMP_MON_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PIEZO_AMP_MON_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_MON_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PIEZO_AMP_MON_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PIEZO_AMP_MON_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PIEZO_AMP_MON_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PIEZO_AMP_MON_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PIEZO_AMP_MON_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PIEZO_AMP_MON_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "V" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "V/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PIEZO_AMP_MON_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PIEZO_AMP_MON_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_MON_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PIEZO_AMP_MON_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PIEZO_AMP_MON_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PIEZO_AMP_MON_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PIEZO_AMP_MON_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PIEZO_AMP_MON_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PIEZO_AMP_MON_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "V" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "V/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PIEZO_AMP_MON_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PIEZO_AMP_MON_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_MON_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PIEZO_AMP_MON_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PIEZO_AMP_MON_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PIEZO_AMP_MON_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PIEZO_AMP_MON_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PIEZO_AMP_MON_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PIEZO_AMP_MON_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "V" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "V/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PIEZO_AMP_MON_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PIEZO_AMP_MON_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_MON_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PIEZO_AMP_MON_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PIEZO_AMP_MON_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PIEZO_AMP_MON_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PIEZO_AMP_MON_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PIEZO_AMP_MON_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PIEZO_AMP_MON_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "V" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "V/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PIEZO_AMP_MON_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PIEZO_AMP_MON_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_MON_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PIEZO_AMP_MON_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PIEZO_AMP_MON_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PIEZO_AMP_MON_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PIEZO_AMP_MON_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PIEZO_AMP_MON_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PIEZO_AMP_MON_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "V" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "V/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PIEZO_AMP_MON_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PIEZO_AMP_MON_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_MON_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PIEZO_AMP_MON_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PIEZO_AMP_MON_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PIEZO_AMP_MON_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PIEZO_AMP_MON_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PIEZO_AMP_MON_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PIEZO_AMP_MON_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "V" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "V/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PIEZO_AMP_MON_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PIEZO_AMP_MON_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_MON_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PIEZO_AMP_MON_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PIEZO_AMP_MON_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PIEZO_AMP_MON_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PIEZO_AMP_MON_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PIEZO_AMP_MON_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PIEZO_AMP_MON_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "V" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "V/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):PIEZO_AMP_MON_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):PIEZO_AMP_MON_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):PIEZO_AMP_MON_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):PIEZO_AMP_MON_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):PIEZO_AMP_MON_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):PIEZO_AMP_MON_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):PIEZO_AMP_MON_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):PIEZO_AMP_MON_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):PIEZO_AMP_MON_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "V" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "V/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):PIEZO_AMP_MON_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "V" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):PIEZO_AMP_MON_LAST_N_MAX",    "$(P,undefined):PIEZO_AMP_MON_MAX" )
alias( "$(P,undefined):PIEZO_AMP_MON_LAST_N_AVG",    "$(P,undefined):PIEZO_AMP_MON_AVG" )
alias( "$(P,undefined):PIEZO_AMP_MON_LAST_N_MIN",    "$(P,undefined):PIEZO_AMP_MON_MIN" )
alias( "$(P,undefined):PIEZO_AMP_MON_LAST_N_RMS",    "$(P,undefined):PIEZO_AMP_MON_RMS" )
alias( "$(P,undefined):PIEZO_AMP_MON_LAST_N_STD",    "$(P,undefined):PIEZO_AMP_MON_STD" )
alias( "$(P,undefined):PIEZO_AMP_MON_LAST_N_SLOPE",  "$(P,undefined):PIEZO_AMP_MON_SLOPE" )
alias( "$(P,undefined):PIEZO_AMP_MON_LAST_N_OFFSET", "$(P,undefined):PIEZO_AMP_MON_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_CTR_TIME_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_CTR_TIME_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_CTR_TIME CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_CTR_TIME_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_CTR_TIME_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_CTR_TIME.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_CTR_TIME_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_CTR_TIME_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_CTR_TIME_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_CTR_TIME_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_CTR_TIME_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_CTR_TIME CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_CTR_TIME_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_CTR_TIME_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_CTR_TIME.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_CTR_TIME_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_CTR_TIME_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_CTR_TIME_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_CTR_TIME_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_CTR_TIME_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_CTR_TIME CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_CTR_TIME_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_CTR_TIME_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_CTR_TIME.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_CTR_TIME_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_CTR_TIME_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_CTR_TIME_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_CTR_TIME_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_CTR_TIME_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_CTR_TIME CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_CTR_TIME_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_CTR_TIME_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_CTR_TIME.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_CTR_TIME_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_CTR_TIME_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_CTR_TIME_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_CTR_TIME_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_CTR_TIME_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_CTR_TIME CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_CTR_TIME_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_CTR_TIME_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_CTR_TIME.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_CTR_TIME_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_CTR_TIME_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_CTR_TIME_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_CTR_TIME_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_CTR_TIME_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_CTR_TIME CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_CTR_TIME_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_CTR_TIME_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_CTR_TIME.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_CTR_TIME_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_CTR_TIME_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_CTR_TIME_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_CTR_TIME_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_CTR_TIME_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_CTR_TIME CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_CTR_TIME_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_CTR_TIME_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_CTR_TIME.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_CTR_TIME_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_CTR_TIME_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_CTR_TIME_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_CTR_TIME_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_CTR_TIME_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_CTR_TIME CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_CTR_TIME_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_CTR_TIME_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_CTR_TIME.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_CTR_TIME_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_CTR_TIME_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_CTR_TIME_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_CTR_TIME_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_CTR_TIME_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_CTR_TIME CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_CTR_TIME_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_CTR_TIME_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_CTR_TIME.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_CTR_TIME_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_CTR_TIME_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_CTR_TIME_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_CTR_TIME_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_CTR_TIME_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_CTR_TIME_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_CTR_TIME_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_CTR_TIME_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_CTR_TIME_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_CTR_TIME_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_CTR_TIME_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_CTR_TIME_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_CTR_TIME_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_CTR_TIME_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_CTR_TIME_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_CTR_TIME_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_CTR_TIME_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_CTR_TIME_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_CTR_TIME_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_CTR_TIME_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_CTR_TIME_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_CTR_TIME_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_CTR_TIME_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_CTR_TIME_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_CTR_TIME_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_CTR_TIME_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_CTR_TIME_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_CTR_TIME_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_CTR_TIME_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_CTR_TIME_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_CTR_TIME_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_CTR_TIME_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_CTR_TIME_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_CTR_TIME_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_CTR_TIME_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_CTR_TIME_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_CTR_TIME_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_CTR_TIME_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_CTR_TIME_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_CTR_TIME_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_CTR_TIME_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_CTR_TIME_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_CTR_TIME_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_CTR_TIME_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_CTR_TIME_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_CTR_TIME_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_CTR_TIME_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_CTR_TIME_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_CTR_TIME_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_CTR_TIME_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_CTR_TIME_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_CTR_TIME_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_CTR_TIME_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_CTR_TIME_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_CTR_TIME_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_CTR_TIME_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_CTR_TIME_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_CTR_TIME_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_CTR_TIME_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_CTR_TIME_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_CTR_TIME_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_CTR_TIME_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_CTR_TIME_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_CTR_TIME_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_CTR_TIME_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_CTR_TIME_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_CTR_TIME_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_CTR_TIME_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_CTR_TIME_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_CTR_TIME_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_CTR_TIME_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_CTR_TIME_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_CTR_TIME_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_CTR_TIME_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_CTR_TIME_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_CTR_TIME_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_CTR_TIME_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_CTR_TIME_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_CTR_TIME_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_CTR_TIME_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_CTR_TIME_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_CTR_TIME_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_CTR_TIME_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_CTR_TIME_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_CTR_TIME_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_CTR_TIME_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_CTR_TIME_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_CTR_TIME_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_CTR_TIME_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_CTR_TIME_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_CTR_TIME_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_CTR_TIME_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_CTR_TIME_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_CTR_TIME_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):FS_CTR_TIME_LAST_N_MAX",    "$(P,undefined):FS_CTR_TIME_MAX" )
alias( "$(P,undefined):FS_CTR_TIME_LAST_N_AVG",    "$(P,undefined):FS_CTR_TIME_AVG" )
alias( "$(P,undefined):FS_CTR_TIME_LAST_N_MIN",    "$(P,undefined):FS_CTR_TIME_MIN" )
alias( "$(P,undefined):FS_CTR_TIME_LAST_N_RMS",    "$(P,undefined):FS_CTR_TIME_RMS" )
alias( "$(P,undefined):FS_CTR_TIME_LAST_N_STD",    "$(P,undefined):FS_CTR_TIME_STD" )
alias( "$(P,undefined):FS_CTR_TIME_LAST_N_SLOPE",  "$(P,undefined):FS_CTR_TIME_SLOPE" )
alias( "$(P,undefined):FS_CTR_TIME_LAST_N_OFFSET", "$(P,undefined):FS_CTR_TIME_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_TIMING_ERROR_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_TIMING_ERROR_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_TIMING_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_TIMING_ERROR_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_TIMING_ERROR_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_TIMING_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_TIMING_ERROR_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_TIMING_ERROR_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_TIMING_ERROR_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_TIMING_ERROR_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_TIMING_ERROR_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_TIMING_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_TIMING_ERROR_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_TIMING_ERROR_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_TIMING_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_TIMING_ERROR_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_TIMING_ERROR_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_TIMING_ERROR_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_TIMING_ERROR_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_TIMING_ERROR_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_TIMING_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_TIMING_ERROR_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_TIMING_ERROR_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_TIMING_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_TIMING_ERROR_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_TIMING_ERROR_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_TIMING_ERROR_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_TIMING_ERROR_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_TIMING_ERROR_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_TIMING_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_TIMING_ERROR_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_TIMING_ERROR_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_TIMING_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_TIMING_ERROR_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_TIMING_ERROR_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_TIMING_ERROR_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_TIMING_ERROR_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_TIMING_ERROR_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_TIMING_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_TIMING_ERROR_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_TIMING_ERROR_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_TIMING_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_TIMING_ERROR_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_TIMING_ERROR_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_TIMING_ERROR_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_TIMING_ERROR_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_TIMING_ERROR_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_TIMING_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_TIMING_ERROR_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_TIMING_ERROR_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_TIMING_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_TIMING_ERROR_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_TIMING_ERROR_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_TIMING_ERROR_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_TIMING_ERROR_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_TIMING_ERROR_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_TIMING_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_TIMING_ERROR_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_TIMING_ERROR_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_TIMING_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_TIMING_ERROR_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_TIMING_ERROR_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_TIMING_ERROR_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_TIMING_ERROR_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_TIMING_ERROR_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_TIMING_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_TIMING_ERROR_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_TIMING_ERROR_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_TIMING_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_TIMING_ERROR_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_TIMING_ERROR_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_TIMING_ERROR_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_TIMING_ERROR_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_TIMING_ERROR_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_TIMING_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_TIMING_ERROR_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_TIMING_ERROR_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_TIMING_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_TIMING_ERROR_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_TIMING_ERROR_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_TIMING_ERROR_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_TIMING_ERROR_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_TIMING_ERROR_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_TIMING_ERROR_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_TIMING_ERROR_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_TIMING_ERROR_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_TIMING_ERROR_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_TIMING_ERROR_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_TIMING_ERROR_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_TIMING_ERROR_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_TIMING_ERROR_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_TIMING_ERROR_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_TIMING_ERROR_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_TIMING_ERROR_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_TIMING_ERROR_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_TIMING_ERROR_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_TIMING_ERROR_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_TIMING_ERROR_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_TIMING_ERROR_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_TIMING_ERROR_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_TIMING_ERROR_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_TIMING_ERROR_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_TIMING_ERROR_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_TIMING_ERROR_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_TIMING_ERROR_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_TIMING_ERROR_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_TIMING_ERROR_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_TIMING_ERROR_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_TIMING_ERROR_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_TIMING_ERROR_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_TIMING_ERROR_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_TIMING_ERROR_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_TIMING_ERROR_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_TIMING_ERROR_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_TIMING_ERROR_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_TIMING_ERROR_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_TIMING_ERROR_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_TIMING_ERROR_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_TIMING_ERROR_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_TIMING_ERROR_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_TIMING_ERROR_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_TIMING_ERROR_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_TIMING_ERROR_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_TIMING_ERROR_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_TIMING_ERROR_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_TIMING_ERROR_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_TIMING_ERROR_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_TIMING_ERROR_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_TIMING_ERROR_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_TIMING_ERROR_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_TIMING_ERROR_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_TIMING_ERROR_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_TIMING_ERROR_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_TIMING_ERROR_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_TIMING_ERROR_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_TIMING_ERROR_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_TIMING_ERROR_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_TIMING_ERROR_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_TIMING_ERROR_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_TIMING_ERROR_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_TIMING_ERROR_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_TIMING_ERROR_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_TIMING_ERROR_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_TIMING_ERROR_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_TIMING_ERROR_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_TIMING_ERROR_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_TIMING_ERROR_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_TIMING_ERROR_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_TIMING_ERROR_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_TIMING_ERROR_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_TIMING_ERROR_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_TIMING_ERROR_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_TIMING_ERROR_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_TIMING_ERROR_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_TIMING_ERROR_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_TIMING_ERROR_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_TIMING_ERROR_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_TIMING_ERROR_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_TIMING_ERROR_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_TIMING_ERROR_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_TIMING_ERROR_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_TIMING_ERROR_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_TIMING_ERROR_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):FS_TIMING_ERROR_LAST_N_MAX",    "$(P,undefined):FS_TIMING_ERROR_MAX" )
alias( "$(P,undefined):FS_TIMING_ERROR_LAST_N_AVG",    "$(P,undefined):FS_TIMING_ERROR_AVG" )
alias( "$(P,undefined):FS_TIMING_ERROR_LAST_N_MIN",    "$(P,undefined):FS_TIMING_ERROR_MIN" )
alias( "$(P,undefined):FS_TIMING_ERROR_LAST_N_RMS",    "$(P,undefined):FS_TIMING_ERROR_RMS" )
alias( "$(P,undefined):FS_TIMING_ERROR_LAST_N_STD",    "$(P,undefined):FS_TIMING_ERROR_STD" )
alias( "$(P,undefined):FS_TIMING_ERROR_LAST_N_SLOPE",  "$(P,undefined):FS_TIMING_ERROR_SLOPE" )
alias( "$(P,undefined):FS_TIMING_ERROR_LAST_N_OFFSET", "$(P,undefined):FS_TIMING_ERROR_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_BUCKET_ERROR_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_BUCKET_ERROR_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_BUCKET_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_BUCKET_ERROR_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_BUCKET_ERROR_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_BUCKET_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_BUCKET_ERROR_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_BUCKET_ERROR_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_BUCKET_ERROR_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_BUCKET_ERROR_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_BUCKET_ERROR_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_BUCKET_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_BUCKET_ERROR_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_BUCKET_ERROR_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_BUCKET_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_BUCKET_ERROR_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_BUCKET_ERROR_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_BUCKET_ERROR_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_BUCKET_ERROR_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_BUCKET_ERROR_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_BUCKET_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_BUCKET_ERROR_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_BUCKET_ERROR_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_BUCKET_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_BUCKET_ERROR_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_BUCKET_ERROR_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_BUCKET_ERROR_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_BUCKET_ERROR_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_BUCKET_ERROR_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_BUCKET_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_BUCKET_ERROR_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_BUCKET_ERROR_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_BUCKET_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_BUCKET_ERROR_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_BUCKET_ERROR_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_BUCKET_ERROR_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_BUCKET_ERROR_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_BUCKET_ERROR_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_BUCKET_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_BUCKET_ERROR_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_BUCKET_ERROR_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_BUCKET_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_BUCKET_ERROR_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_BUCKET_ERROR_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_BUCKET_ERROR_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_BUCKET_ERROR_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_BUCKET_ERROR_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_BUCKET_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_BUCKET_ERROR_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_BUCKET_ERROR_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_BUCKET_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_BUCKET_ERROR_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_BUCKET_ERROR_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_BUCKET_ERROR_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_BUCKET_ERROR_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_BUCKET_ERROR_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_BUCKET_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_BUCKET_ERROR_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_BUCKET_ERROR_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_BUCKET_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_BUCKET_ERROR_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_BUCKET_ERROR_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_BUCKET_ERROR_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_BUCKET_ERROR_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_BUCKET_ERROR_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_BUCKET_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_BUCKET_ERROR_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_BUCKET_ERROR_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_BUCKET_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_BUCKET_ERROR_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_BUCKET_ERROR_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_BUCKET_ERROR_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_BUCKET_ERROR_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_BUCKET_ERROR_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_BUCKET_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_BUCKET_ERROR_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_BUCKET_ERROR_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_BUCKET_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_BUCKET_ERROR_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_BUCKET_ERROR_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_BUCKET_ERROR_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_BUCKET_ERROR_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_BUCKET_ERROR_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_BUCKET_ERROR_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_BUCKET_ERROR_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_BUCKET_ERROR_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_BUCKET_ERROR_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_BUCKET_ERROR_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_BUCKET_ERROR_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_BUCKET_ERROR_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "buckets/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_BUCKET_ERROR_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_BUCKET_ERROR_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_BUCKET_ERROR_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_BUCKET_ERROR_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_BUCKET_ERROR_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_BUCKET_ERROR_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_BUCKET_ERROR_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_BUCKET_ERROR_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_BUCKET_ERROR_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "buckets/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_BUCKET_ERROR_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_BUCKET_ERROR_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_BUCKET_ERROR_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_BUCKET_ERROR_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_BUCKET_ERROR_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_BUCKET_ERROR_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_BUCKET_ERROR_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_BUCKET_ERROR_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_BUCKET_ERROR_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "buckets/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_BUCKET_ERROR_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_BUCKET_ERROR_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_BUCKET_ERROR_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_BUCKET_ERROR_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_BUCKET_ERROR_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_BUCKET_ERROR_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_BUCKET_ERROR_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_BUCKET_ERROR_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_BUCKET_ERROR_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "buckets/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_BUCKET_ERROR_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_BUCKET_ERROR_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_BUCKET_ERROR_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_BUCKET_ERROR_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_BUCKET_ERROR_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_BUCKET_ERROR_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_BUCKET_ERROR_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_BUCKET_ERROR_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_BUCKET_ERROR_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "buckets/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_BUCKET_ERROR_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_BUCKET_ERROR_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_BUCKET_ERROR_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_BUCKET_ERROR_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_BUCKET_ERROR_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_BUCKET_ERROR_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_BUCKET_ERROR_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_BUCKET_ERROR_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_BUCKET_ERROR_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "buckets/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_BUCKET_ERROR_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_BUCKET_ERROR_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_BUCKET_ERROR_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_BUCKET_ERROR_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_BUCKET_ERROR_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_BUCKET_ERROR_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_BUCKET_ERROR_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_BUCKET_ERROR_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_BUCKET_ERROR_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "buckets/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_BUCKET_ERROR_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_BUCKET_ERROR_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_BUCKET_ERROR_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_BUCKET_ERROR_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_BUCKET_ERROR_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_BUCKET_ERROR_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_BUCKET_ERROR_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_BUCKET_ERROR_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_BUCKET_ERROR_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "buckets/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_BUCKET_ERROR_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_BUCKET_ERROR_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_BUCKET_ERROR_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_BUCKET_ERROR_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_BUCKET_ERROR_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_BUCKET_ERROR_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_BUCKET_ERROR_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_BUCKET_ERROR_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_BUCKET_ERROR_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "buckets/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_BUCKET_ERROR_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "buckets" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):FS_BUCKET_ERROR_LAST_N_MAX",    "$(P,undefined):FS_BUCKET_ERROR_MAX" )
alias( "$(P,undefined):FS_BUCKET_ERROR_LAST_N_AVG",    "$(P,undefined):FS_BUCKET_ERROR_AVG" )
alias( "$(P,undefined):FS_BUCKET_ERROR_LAST_N_MIN",    "$(P,undefined):FS_BUCKET_ERROR_MIN" )
alias( "$(P,undefined):FS_BUCKET_ERROR_LAST_N_RMS",    "$(P,undefined):FS_BUCKET_ERROR_RMS" )
alias( "$(P,undefined):FS_BUCKET_ERROR_LAST_N_STD",    "$(P,undefined):FS_BUCKET_ERROR_STD" )
alias( "$(P,undefined):FS_BUCKET_ERROR_LAST_N_SLOPE",  "$(P,undefined):FS_BUCKET_ERROR_SLOPE" )
alias( "$(P,undefined):FS_BUCKET_ERROR_LAST_N_OFFSET", "$(P,undefined):FS_BUCKET_ERROR_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_UNFIXED_ERROR_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_UNFIXED_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_UNFIXED_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_UNFIXED_ERROR_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_UNFIXED_ERROR_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_UNFIXED_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_UNFIXED_ERROR_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_UNFIXED_ERROR_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_UNFIXED_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_UNFIXED_ERROR_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_UNFIXED_ERROR_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_UNFIXED_ERROR_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_UNFIXED_ERROR_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_UNFIXED_ERROR_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_UNFIXED_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_UNFIXED_ERROR_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_UNFIXED_ERROR_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_UNFIXED_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_UNFIXED_ERROR_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_UNFIXED_ERROR_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_UNFIXED_ERROR_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_UNFIXED_ERROR_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_UNFIXED_ERROR_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_UNFIXED_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_UNFIXED_ERROR_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_UNFIXED_ERROR_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_UNFIXED_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_UNFIXED_ERROR_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_UNFIXED_ERROR_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_UNFIXED_ERROR_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_UNFIXED_ERROR_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_UNFIXED_ERROR_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_UNFIXED_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_UNFIXED_ERROR_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_UNFIXED_ERROR_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_UNFIXED_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_UNFIXED_ERROR_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_UNFIXED_ERROR_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_UNFIXED_ERROR_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_UNFIXED_ERROR_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_UNFIXED_ERROR_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_UNFIXED_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_UNFIXED_ERROR_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_UNFIXED_ERROR_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_UNFIXED_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_UNFIXED_ERROR_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_UNFIXED_ERROR_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_UNFIXED_ERROR_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_UNFIXED_ERROR_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_UNFIXED_ERROR_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_UNFIXED_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_UNFIXED_ERROR_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_UNFIXED_ERROR_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_UNFIXED_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_UNFIXED_ERROR_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_UNFIXED_ERROR_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_UNFIXED_ERROR_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_UNFIXED_ERROR_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_UNFIXED_ERROR_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_UNFIXED_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_UNFIXED_ERROR_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_UNFIXED_ERROR_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_UNFIXED_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_UNFIXED_ERROR_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_UNFIXED_ERROR_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_UNFIXED_ERROR_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):FS_UNFIXED_ERROR_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):FS_UNFIXED_ERROR_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):FS_UNFIXED_ERROR CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):FS_UNFIXED_ERROR_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):FS_UNFIXED_ERROR_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):FS_UNFIXED_ERROR.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):FS_UNFIXED_ERROR_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):FS_UNFIXED_ERROR_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):FS_UNFIXED_ERROR_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ps/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_UNFIXED_ERROR_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_UNFIXED_ERROR_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_UNFIXED_ERROR_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_UNFIXED_ERROR_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_UNFIXED_ERROR_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_UNFIXED_ERROR_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_UNFIXED_ERROR_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_UNFIXED_ERROR_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_UNFIXED_ERROR_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ps/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_UNFIXED_ERROR_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_UNFIXED_ERROR_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_UNFIXED_ERROR_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_UNFIXED_ERROR_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_UNFIXED_ERROR_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_UNFIXED_ERROR_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_UNFIXED_ERROR_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_UNFIXED_ERROR_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_UNFIXED_ERROR_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ps/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_UNFIXED_ERROR_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_UNFIXED_ERROR_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_UNFIXED_ERROR_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_UNFIXED_ERROR_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_UNFIXED_ERROR_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_UNFIXED_ERROR_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_UNFIXED_ERROR_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_UNFIXED_ERROR_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_UNFIXED_ERROR_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ps/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_UNFIXED_ERROR_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_UNFIXED_ERROR_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_UNFIXED_ERROR_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_UNFIXED_ERROR_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_UNFIXED_ERROR_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_UNFIXED_ERROR_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_UNFIXED_ERROR_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_UNFIXED_ERROR_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_UNFIXED_ERROR_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ps/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_UNFIXED_ERROR_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_UNFIXED_ERROR_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_UNFIXED_ERROR_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_UNFIXED_ERROR_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_UNFIXED_ERROR_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_UNFIXED_ERROR_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_UNFIXED_ERROR_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_UNFIXED_ERROR_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_UNFIXED_ERROR_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ps/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_UNFIXED_ERROR_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_UNFIXED_ERROR_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_UNFIXED_ERROR_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_UNFIXED_ERROR_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_UNFIXED_ERROR_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_UNFIXED_ERROR_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_UNFIXED_ERROR_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_UNFIXED_ERROR_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_UNFIXED_ERROR_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ps/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_UNFIXED_ERROR_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_UNFIXED_ERROR_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_UNFIXED_ERROR_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_UNFIXED_ERROR_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_UNFIXED_ERROR_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_UNFIXED_ERROR_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_UNFIXED_ERROR_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_UNFIXED_ERROR_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_UNFIXED_ERROR_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ps/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):FS_UNFIXED_ERROR_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):FS_UNFIXED_ERROR_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):FS_UNFIXED_ERROR_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):FS_UNFIXED_ERROR_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):FS_UNFIXED_ERROR_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):FS_UNFIXED_ERROR_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):FS_UNFIXED_ERROR_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):FS_UNFIXED_ERROR_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):FS_UNFIXED_ERROR_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ps/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):FS_UNFIXED_ERROR_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ps" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_MAX",    "$(P,undefined):FS_UNFIXED_ERROR_MAX" )
alias( "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_AVG",    "$(P,undefined):FS_UNFIXED_ERROR_AVG" )
alias( "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_MIN",    "$(P,undefined):FS_UNFIXED_ERROR_MIN" )
alias( "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_RMS",    "$(P,undefined):FS_UNFIXED_ERROR_RMS" )
alias( "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_STD",    "$(P,undefined):FS_UNFIXED_ERROR_STD" )
alias( "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_SLOPE",  "$(P,undefined):FS_UNFIXED_ERROR_SLOPE" )
alias( "$(P,undefined):FS_UNFIXED_ERROR_LAST_N_OFFSET", "$(P,undefined):FS_UNFIXED_ERROR_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetMeasMean_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetMeasMean_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetMeasMean CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetMeasMean_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetMeasMean_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetMeasMean.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetMeasMean_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetMeasMean_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetMeasMean_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetMeasMean_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetMeasMean_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetMeasMean CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetMeasMean_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetMeasMean_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetMeasMean.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetMeasMean_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetMeasMean_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetMeasMean_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetMeasMean_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetMeasMean_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetMeasMean CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetMeasMean_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetMeasMean_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetMeasMean.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetMeasMean_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetMeasMean_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetMeasMean_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetMeasMean_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetMeasMean_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetMeasMean CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetMeasMean_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetMeasMean_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetMeasMean.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetMeasMean_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetMeasMean_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetMeasMean_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetMeasMean_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetMeasMean_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetMeasMean CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetMeasMean_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetMeasMean_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetMeasMean.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetMeasMean_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetMeasMean_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetMeasMean_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetMeasMean_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetMeasMean_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetMeasMean CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetMeasMean_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetMeasMean_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetMeasMean.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetMeasMean_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetMeasMean_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetMeasMean_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetMeasMean_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetMeasMean_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetMeasMean CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetMeasMean_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetMeasMean_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetMeasMean.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetMeasMean_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetMeasMean_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetMeasMean_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetMeasMean_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetMeasMean_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetMeasMean CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetMeasMean_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetMeasMean_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetMeasMean.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetMeasMean_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetMeasMean_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetMeasMean_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetMeasMean_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetMeasMean_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetMeasMean CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetMeasMean_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetMeasMean_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetMeasMean.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetMeasMean_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetMeasMean_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetMeasMean_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetMeasMean_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetMeasMean_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetMeasMean_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetMeasMean_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetMeasMean_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetMeasMean_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetMeasMean_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetMeasMean_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetMeasMean_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):GetMeasMean_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "s" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "s/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetMeasMean_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetMeasMean_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetMeasMean_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetMeasMean_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetMeasMean_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetMeasMean_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetMeasMean_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetMeasMean_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetMeasMean_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):GetMeasMean_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "s" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "s/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetMeasMean_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetMeasMean_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetMeasMean_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetMeasMean_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetMeasMean_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetMeasMean_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetMeasMean_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetMeasMean_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetMeasMean_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):GetMeasMean_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "s" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "s/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetMeasMean_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetMeasMean_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetMeasMean_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetMeasMean_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetMeasMean_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetMeasMean_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetMeasMean_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetMeasMean_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetMeasMean_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):GetMeasMean_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "s" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "s/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetMeasMean_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetMeasMean_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetMeasMean_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetMeasMean_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetMeasMean_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetMeasMean_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetMeasMean_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetMeasMean_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetMeasMean_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):GetMeasMean_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "s" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "s/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetMeasMean_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetMeasMean_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetMeasMean_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetMeasMean_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetMeasMean_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetMeasMean_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetMeasMean_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetMeasMean_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetMeasMean_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):GetMeasMean_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "s" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "s/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetMeasMean_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetMeasMean_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetMeasMean_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetMeasMean_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetMeasMean_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetMeasMean_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetMeasMean_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetMeasMean_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetMeasMean_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):GetMeasMean_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "s" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "s/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetMeasMean_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetMeasMean_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetMeasMean_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetMeasMean_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetMeasMean_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetMeasMean_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetMeasMean_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetMeasMean_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetMeasMean_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):GetMeasMean_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "s" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "s/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetMeasMean_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetMeasMean_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetMeasMean_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetMeasMean_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetMeasMean_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetMeasMean_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetMeasMean_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetMeasMean_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetMeasMean_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):GetMeasMean_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "s" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "s/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):GetMeasMean_LAST_N_MAX",    "$(P,undefined):GetMeasMean_MAX" )
alias( "$(P,undefined):GetMeasMean_LAST_N_AVG",    "$(P,undefined):GetMeasMean_AVG" )
alias( "$(P,undefined):GetMeasMean_LAST_N_MIN",    "$(P,undefined):GetMeasMean_MIN" )
alias( "$(P,undefined):GetMeasMean_LAST_N_RMS",    "$(P,undefined):GetMeasMean_RMS" )
alias( "$(P,undefined):GetMeasMean_LAST_N_STD",    "$(P,undefined):GetMeasMean_STD" )
alias( "$(P,undefined):GetMeasMean_LAST_N_SLOPE",  "$(P,undefined):GetMeasMean_SLOPE" )
alias( "$(P,undefined):GetMeasMean_LAST_N_OFFSET", "$(P,undefined):GetMeasMean_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetMeasMean_ns_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetMeasMean_ns_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetMeasMean_ns CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetMeasMean_ns_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetMeasMean_ns_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetMeasMean_ns.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetMeasMean_ns_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetMeasMean_ns_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetMeasMean_ns_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetMeasMean_ns_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetMeasMean_ns_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetMeasMean_ns CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetMeasMean_ns_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetMeasMean_ns_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetMeasMean_ns.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetMeasMean_ns_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetMeasMean_ns_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetMeasMean_ns_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetMeasMean_ns_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetMeasMean_ns_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetMeasMean_ns CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetMeasMean_ns_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetMeasMean_ns_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetMeasMean_ns.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetMeasMean_ns_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetMeasMean_ns_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetMeasMean_ns_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetMeasMean_ns_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetMeasMean_ns_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetMeasMean_ns CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetMeasMean_ns_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetMeasMean_ns_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetMeasMean_ns.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetMeasMean_ns_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetMeasMean_ns_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetMeasMean_ns_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetMeasMean_ns_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetMeasMean_ns_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetMeasMean_ns CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetMeasMean_ns_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetMeasMean_ns_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetMeasMean_ns.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetMeasMean_ns_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetMeasMean_ns_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetMeasMean_ns_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetMeasMean_ns_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetMeasMean_ns_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetMeasMean_ns CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetMeasMean_ns_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetMeasMean_ns_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetMeasMean_ns.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetMeasMean_ns_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetMeasMean_ns_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetMeasMean_ns_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetMeasMean_ns_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetMeasMean_ns_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetMeasMean_ns CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetMeasMean_ns_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetMeasMean_ns_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetMeasMean_ns.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetMeasMean_ns_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetMeasMean_ns_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetMeasMean_ns_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetMeasMean_ns_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetMeasMean_ns_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetMeasMean_ns CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetMeasMean_ns_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetMeasMean_ns_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetMeasMean_ns.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetMeasMean_ns_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetMeasMean_ns_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetMeasMean_ns_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetMeasMean_ns_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetMeasMean_ns_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetMeasMean_ns CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetMeasMean_ns_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetMeasMean_ns_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetMeasMean_ns.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetMeasMean_ns_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetMeasMean_ns_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetMeasMean_ns_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetMeasMean_ns_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetMeasMean_ns_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetMeasMean_ns_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetMeasMean_ns_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetMeasMean_ns_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetMeasMean_ns_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetMeasMean_ns_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetMeasMean_ns_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetMeasMean_ns_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):GetMeasMean_ns_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetMeasMean_ns_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetMeasMean_ns_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetMeasMean_ns_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetMeasMean_ns_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetMeasMean_ns_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetMeasMean_ns_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetMeasMean_ns_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetMeasMean_ns_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetMeasMean_ns_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):GetMeasMean_ns_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetMeasMean_ns_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetMeasMean_ns_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetMeasMean_ns_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetMeasMean_ns_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetMeasMean_ns_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetMeasMean_ns_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetMeasMean_ns_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetMeasMean_ns_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetMeasMean_ns_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):GetMeasMean_ns_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetMeasMean_ns_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetMeasMean_ns_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetMeasMean_ns_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetMeasMean_ns_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetMeasMean_ns_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetMeasMean_ns_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetMeasMean_ns_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetMeasMean_ns_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetMeasMean_ns_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):GetMeasMean_ns_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetMeasMean_ns_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetMeasMean_ns_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetMeasMean_ns_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetMeasMean_ns_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetMeasMean_ns_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetMeasMean_ns_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetMeasMean_ns_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetMeasMean_ns_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetMeasMean_ns_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):GetMeasMean_ns_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetMeasMean_ns_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetMeasMean_ns_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetMeasMean_ns_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetMeasMean_ns_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetMeasMean_ns_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetMeasMean_ns_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetMeasMean_ns_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetMeasMean_ns_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetMeasMean_ns_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):GetMeasMean_ns_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetMeasMean_ns_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetMeasMean_ns_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetMeasMean_ns_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetMeasMean_ns_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetMeasMean_ns_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetMeasMean_ns_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetMeasMean_ns_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetMeasMean_ns_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetMeasMean_ns_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):GetMeasMean_ns_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetMeasMean_ns_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetMeasMean_ns_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetMeasMean_ns_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetMeasMean_ns_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetMeasMean_ns_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetMeasMean_ns_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetMeasMean_ns_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetMeasMean_ns_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetMeasMean_ns_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):GetMeasMean_ns_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetMeasMean_ns_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetMeasMean_ns_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetMeasMean_ns_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetMeasMean_ns_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetMeasMean_ns_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetMeasMean_ns_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetMeasMean_ns_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetMeasMean_ns_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetMeasMean_ns_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):GetMeasMean_ns_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "ns/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetMeasMean_ns_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "ns" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):GetMeasMean_ns_LAST_N_MAX",    "$(P,undefined):GetMeasMean_ns_MAX" )
alias( "$(P,undefined):GetMeasMean_ns_LAST_N_AVG",    "$(P,undefined):GetMeasMean_ns_AVG" )
alias( "$(P,undefined):GetMeasMean_ns_LAST_N_MIN",    "$(P,undefined):GetMeasMean_ns_MIN" )
alias( "$(P,undefined):GetMeasMean_ns_LAST_N_RMS",    "$(P,undefined):GetMeasMean_ns_RMS" )
alias( "$(P,undefined):GetMeasMean_ns_LAST_N_STD",    "$(P,undefined):GetMeasMean_ns_STD" )
alias( "$(P,undefined):GetMeasMean_ns_LAST_N_SLOPE",  "$(P,undefined):GetMeasMean_ns_SLOPE" )
alias( "$(P,undefined):GetMeasMean_ns_LAST_N_OFFSET", "$(P,undefined):GetMeasMean_ns_OFFSET" )
#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "LAST_N Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetOffsetInvMeasMean_LAST_N
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetOffsetInvMeasMean_LAST_N_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetOffsetInvMeasMean CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "0" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetOffsetInvMeasMean_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetOffsetInvMeasMean_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetOffsetInvMeasMean.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetOffsetInvMeasMean_LAST_N:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "0")
	field(INPC, "0" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "N")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetOffsetInvMeasMean_LAST_N:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetOffsetInvMeasMean_LAST_N:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "N")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetOffsetInvMeasMean_1MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetOffsetInvMeasMean_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetOffsetInvMeasMean CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "60" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetOffsetInvMeasMean_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetOffsetInvMeasMean_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetOffsetInvMeasMean.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetOffsetInvMeasMean_1MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "1")
	field(INPC, "60" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "s")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetOffsetInvMeasMean_1MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetOffsetInvMeasMean_1MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "s")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetOffsetInvMeasMean_6MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetOffsetInvMeasMean_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetOffsetInvMeasMean CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "360" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetOffsetInvMeasMean_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetOffsetInvMeasMean_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetOffsetInvMeasMean.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetOffsetInvMeasMean_6MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "360" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetOffsetInvMeasMean_6MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetOffsetInvMeasMean_6MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "30MIN Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetOffsetInvMeasMean_30MIN
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetOffsetInvMeasMean_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetOffsetInvMeasMean CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "1800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetOffsetInvMeasMean_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetOffsetInvMeasMean_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetOffsetInvMeasMean.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetOffsetInvMeasMean_30MIN:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "1800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetOffsetInvMeasMean_30MIN:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetOffsetInvMeasMean_30MIN:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "1HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetOffsetInvMeasMean_1HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetOffsetInvMeasMean_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetOffsetInvMeasMean CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "3600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetOffsetInvMeasMean_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetOffsetInvMeasMean_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetOffsetInvMeasMean.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetOffsetInvMeasMean_1HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "60")
	field(INPC, "3600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "min")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetOffsetInvMeasMean_1HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetOffsetInvMeasMean_1HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "min")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "6HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetOffsetInvMeasMean_6HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetOffsetInvMeasMean_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetOffsetInvMeasMean CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "21600" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetOffsetInvMeasMean_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetOffsetInvMeasMean_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetOffsetInvMeasMean.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetOffsetInvMeasMean_6HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "21600" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetOffsetInvMeasMean_6HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetOffsetInvMeasMean_6HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "24HR Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetOffsetInvMeasMean_24HR
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetOffsetInvMeasMean_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetOffsetInvMeasMean CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "86400" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetOffsetInvMeasMean_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetOffsetInvMeasMean_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetOffsetInvMeasMean.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetOffsetInvMeasMean_24HR:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "86400" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetOffsetInvMeasMean_24HR:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetOffsetInvMeasMean_24HR:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "3DAY Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetOffsetInvMeasMean_3DAY
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetOffsetInvMeasMean_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetOffsetInvMeasMean CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "259200" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetOffsetInvMeasMean_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetOffsetInvMeasMean_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetOffsetInvMeasMean.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetOffsetInvMeasMean_3DAY:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "3600")
	field(INPC, "259200" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "hr")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetOffsetInvMeasMean_3DAY:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetOffsetInvMeasMean_3DAY:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "hr")
	field(PREC,  "3")
}

#
# Template for generating aSub records which accumulate
# a history of the specified PV over the specified time period.
#
#	Macros:
#		PV			- Name of PV to track
#		PERIOD		- Time period over which to retain history, in seconds
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		X_EGU		- Units to display on the time axis
#		S_PER_X_EGU	- Conversion between seconds and X_EGU, e.g. 3600 for hrs
#		NAME		- Name of this time period
#		DESC		- Description of Time Period, default "WEEK Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P,undefined):GetOffsetInvMeasMean_WEEK
#

# History asub
# Monitors an scalar value and records it's history
#	over the specified time period.
# The delay between samples is determined by the time
# period divided by the size of the output array.
#	Inputs:
#		A	- a single scalar value of type double
#		T	- unsigned integer time period in seconds
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P,undefined):GetOffsetInvMeasMean_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P,undefined):GetOffsetInvMeasMean CP NMS" )

	field( FTT, "DOUBLE" )
	field( NOT, 1 )
	field( INPT, "604800" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P,undefined):GetOffsetInvMeasMean_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(P,undefined):GetOffsetInvMeasMean_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( NELM, 300 )
	field( TSEL, "$(P,undefined):GetOffsetInvMeasMean.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(P,undefined):GetOffsetInvMeasMean_WEEK:CALCX") 
{
	field(DESC, "x-axis times")
	field(CALC, "B>0?(IX-A)*C/(A*B):IX")
	field(INPA, "300")
	field(INPB, "86400")
	field(INPC, "604800" )
	field(NELM, "300")
	field(PINI, "YES")
	field(SCAN, "Passive")
	field(EGU,  "days")
	field(PREC,  "3")
	field(OUT, "$(P,undefined):GetOffsetInvMeasMean_WEEK:X-AXIS CP")
}

record(waveform, "$(P,undefined):GetOffsetInvMeasMean_WEEK:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "300")
	field(EGU,  "days")
	field(PREC,  "3")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetOffsetInvMeasMean_LAST_N_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetOffsetInvMeasMean_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetOffsetInvMeasMean_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetOffsetInvMeasMean_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetOffsetInvMeasMean_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetOffsetInvMeasMean_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetOffsetInvMeasMean_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetOffsetInvMeasMean_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetOffsetInvMeasMean_LAST_N_OFFSET PP" )
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_LAST_N_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_LAST_N_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_LAST_N_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_LAST_N_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "s" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_LAST_N_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_LAST_N_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "s/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetOffsetInvMeasMean_1MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetOffsetInvMeasMean_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetOffsetInvMeasMean_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetOffsetInvMeasMean_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetOffsetInvMeasMean_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetOffsetInvMeasMean_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetOffsetInvMeasMean_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetOffsetInvMeasMean_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetOffsetInvMeasMean_1MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_1MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_1MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_1MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_1MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "s" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_1MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_1MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "s/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetOffsetInvMeasMean_6MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetOffsetInvMeasMean_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetOffsetInvMeasMean_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetOffsetInvMeasMean_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetOffsetInvMeasMean_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetOffsetInvMeasMean_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetOffsetInvMeasMean_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetOffsetInvMeasMean_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetOffsetInvMeasMean_6MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_6MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_6MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_6MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_6MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "s" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_6MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_6MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "s/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetOffsetInvMeasMean_30MIN_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetOffsetInvMeasMean_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetOffsetInvMeasMean_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetOffsetInvMeasMean_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetOffsetInvMeasMean_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetOffsetInvMeasMean_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetOffsetInvMeasMean_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetOffsetInvMeasMean_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetOffsetInvMeasMean_30MIN_OFFSET PP" )
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_30MIN_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_30MIN_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_30MIN_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_30MIN_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "s" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_30MIN_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_30MIN_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "s/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetOffsetInvMeasMean_1HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetOffsetInvMeasMean_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetOffsetInvMeasMean_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetOffsetInvMeasMean_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetOffsetInvMeasMean_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetOffsetInvMeasMean_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetOffsetInvMeasMean_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetOffsetInvMeasMean_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetOffsetInvMeasMean_1HR_OFFSET PP" )
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_1HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_1HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_1HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_1HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "s" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_1HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_1HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "s/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetOffsetInvMeasMean_6HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetOffsetInvMeasMean_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetOffsetInvMeasMean_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetOffsetInvMeasMean_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetOffsetInvMeasMean_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetOffsetInvMeasMean_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetOffsetInvMeasMean_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetOffsetInvMeasMean_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetOffsetInvMeasMean_6HR_OFFSET PP" )
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_6HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_6HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_6HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_6HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "s" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_6HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_6HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "s/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetOffsetInvMeasMean_24HR_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetOffsetInvMeasMean_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetOffsetInvMeasMean_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetOffsetInvMeasMean_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetOffsetInvMeasMean_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetOffsetInvMeasMean_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetOffsetInvMeasMean_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetOffsetInvMeasMean_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetOffsetInvMeasMean_24HR_OFFSET PP" )
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_24HR_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_24HR_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_24HR_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_24HR_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "s" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_24HR_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_24HR_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "s/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetOffsetInvMeasMean_3DAY_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetOffsetInvMeasMean_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetOffsetInvMeasMean_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetOffsetInvMeasMean_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetOffsetInvMeasMean_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetOffsetInvMeasMean_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetOffsetInvMeasMean_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetOffsetInvMeasMean_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetOffsetInvMeasMean_3DAY_OFFSET PP" )
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_3DAY_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_3DAY_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_3DAY_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_3DAY_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "s" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_3DAY_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_3DAY_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "s/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# EPICS Template for waveform processing
#
# This template is used to process waveform records
# and write the results as new waveforms and scalar PV's
#
# Required Macro Definitions
# WAVE			- Waveform name, for example AMO_KB1_WAV_01
# EGU			- Engineering units: fs, C, mm, etc.
#
# Optional macros
# NELM          - Number of elements per history array (default 300)

# RMS asub
# Processing this PV computes the RMS value for the input array
# generating FitTime and Charge PV's for each cavity
#
# Inputs
# INPA:	Waveform PV, Type DOUBLE, any length
#
# Outputs
# OUTA:	RMS    - ai PV - RMS over all samples
# OUTB:	MIN    - ai PV - Min of all samples
# OUTC:	MAX    - ai PV - Max of all samples
# OUTD:	AVG    - ai PV - Average sample value
# OUTE: STD - ai PV - Std deviation 
# OUTF: SLOPE  - ai PV - Slope of linear least squares fit
# OUTG: OFFSET - ai PV - Offset of linear least squares fit
record( aSub, "$(P,undefined):GetOffsetInvMeasMean_WEEK_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "300" )
	field( INPA, "$(P,undefined):GetOffsetInvMeasMean_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P,undefined):GetOffsetInvMeasMean_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P,undefined):GetOffsetInvMeasMean_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P,undefined):GetOffsetInvMeasMean_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P,undefined):GetOffsetInvMeasMean_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P,undefined):GetOffsetInvMeasMean_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P,undefined):GetOffsetInvMeasMean_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P,undefined):GetOffsetInvMeasMean_WEEK_OFFSET PP" )
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_WEEK_MAX" )
{
	field( DESC, "MAX for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_WEEK_AVG" )
{
	field( DESC, "AVG of waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_WEEK_MIN" )
{
	field( DESC, "MIN for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_WEEK_RMS" )
{
	field( DESC, "RMS for waveform" )
	field( LOLO, "0" )
	field( LOW,  "0"  )
	field( HIGH, "0" )
	field( HIHI, "0" )
	field( EGU,  "s" )
	field( PREC, "4" )
	field( LLSV,  "MAJOR" )
	field( LSV,   "MINOR" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_WEEK_STD" )
{
	field( DESC, "StdDev for waveform" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_WEEK_SLOPE" )
{
	field( DESC, "Best fit linear slope" )
	field( EGU,  "s/s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

record( ai, "$(P,undefined):GetOffsetInvMeasMean_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "s" )
	field( PREC, "4" )
	info(autosaveFields, "HHSV HIGH HIHI HSV LLSV LOLO LOW LSV PREC")
}

# In some screens, you want to say "display statistic X" without being too
# particular about the data set. Use these aliases to hide that part of the PV

alias( "$(P,undefined):GetOffsetInvMeasMean_LAST_N_MAX",    "$(P,undefined):GetOffsetInvMeasMean_MAX" )
alias( "$(P,undefined):GetOffsetInvMeasMean_LAST_N_AVG",    "$(P,undefined):GetOffsetInvMeasMean_AVG" )
alias( "$(P,undefined):GetOffsetInvMeasMean_LAST_N_MIN",    "$(P,undefined):GetOffsetInvMeasMean_MIN" )
alias( "$(P,undefined):GetOffsetInvMeasMean_LAST_N_RMS",    "$(P,undefined):GetOffsetInvMeasMean_RMS" )
alias( "$(P,undefined):GetOffsetInvMeasMean_LAST_N_STD",    "$(P,undefined):GetOffsetInvMeasMean_STD" )
alias( "$(P,undefined):GetOffsetInvMeasMean_LAST_N_SLOPE",  "$(P,undefined):GetOffsetInvMeasMean_SLOPE" )
alias( "$(P,undefined):GetOffsetInvMeasMean_LAST_N_OFFSET", "$(P,undefined):GetOffsetInvMeasMean_OFFSET" )
