#
# 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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):AvgPhotonsPerPulse_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):AvgPhotonsPerPulse_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( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):AvgPhotonsPerPulse_LAST_N PP" )

}

record( waveform, "$(P):AvgPhotonsPerPulse_LAST_N" )
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "photons" )
	field( NELM, 300 )
	field( TSEL, "$(P):AvgPhotonsPerPulse.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):AvgPhotonsPerPulse_LAST_N:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):AvgPhotonsPerPulse_LAST_N:X-AXIS PP" )
}

record( waveform, "$(P):AvgPhotonsPerPulse_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):AvgPhotonsPerPulse_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):AvgPhotonsPerPulse_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):AvgPhotonsPerPulse_1MIN PP" )

}

record( waveform, "$(P):AvgPhotonsPerPulse_1MIN" )
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "photons" )
	field( NELM, 300 )
	field( TSEL, "$(P):AvgPhotonsPerPulse.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):AvgPhotonsPerPulse_1MIN:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):AvgPhotonsPerPulse_1MIN:X-AXIS PP" )
}

record( waveform, "$(P):AvgPhotonsPerPulse_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):AvgPhotonsPerPulse_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):AvgPhotonsPerPulse_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):AvgPhotonsPerPulse_6MIN PP" )

}

record( waveform, "$(P):AvgPhotonsPerPulse_6MIN" )
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "photons" )
	field( NELM, 300 )
	field( TSEL, "$(P):AvgPhotonsPerPulse.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):AvgPhotonsPerPulse_6MIN:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):AvgPhotonsPerPulse_6MIN:X-AXIS PP" )
}

record( waveform, "$(P):AvgPhotonsPerPulse_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):AvgPhotonsPerPulse_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):AvgPhotonsPerPulse_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):AvgPhotonsPerPulse_30MIN PP" )

}

record( waveform, "$(P):AvgPhotonsPerPulse_30MIN" )
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "photons" )
	field( NELM, 300 )
	field( TSEL, "$(P):AvgPhotonsPerPulse.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):AvgPhotonsPerPulse_30MIN:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):AvgPhotonsPerPulse_30MIN:X-AXIS PP" )
}

record( waveform, "$(P):AvgPhotonsPerPulse_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):AvgPhotonsPerPulse_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):AvgPhotonsPerPulse_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):AvgPhotonsPerPulse_1HR PP" )

}

record( waveform, "$(P):AvgPhotonsPerPulse_1HR" )
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "photons" )
	field( NELM, 300 )
	field( TSEL, "$(P):AvgPhotonsPerPulse.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):AvgPhotonsPerPulse_1HR:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):AvgPhotonsPerPulse_1HR:X-AXIS PP" )
}

record( waveform, "$(P):AvgPhotonsPerPulse_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):AvgPhotonsPerPulse_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):AvgPhotonsPerPulse_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):AvgPhotonsPerPulse_6HR PP" )

}

record( waveform, "$(P):AvgPhotonsPerPulse_6HR" )
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "photons" )
	field( NELM, 300 )
	field( TSEL, "$(P):AvgPhotonsPerPulse.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):AvgPhotonsPerPulse_6HR:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):AvgPhotonsPerPulse_6HR:X-AXIS PP" )
}

record( waveform, "$(P):AvgPhotonsPerPulse_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):AvgPhotonsPerPulse_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):AvgPhotonsPerPulse_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):AvgPhotonsPerPulse_24HR PP" )

}

record( waveform, "$(P):AvgPhotonsPerPulse_24HR" )
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "photons" )
	field( NELM, 300 )
	field( TSEL, "$(P):AvgPhotonsPerPulse.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):AvgPhotonsPerPulse_24HR:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):AvgPhotonsPerPulse_24HR:X-AXIS PP" )
}

record( waveform, "$(P):AvgPhotonsPerPulse_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):AvgPhotonsPerPulse_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):AvgPhotonsPerPulse_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):AvgPhotonsPerPulse_3DAY PP" )

}

record( waveform, "$(P):AvgPhotonsPerPulse_3DAY" )
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "photons" )
	field( NELM, 300 )
	field( TSEL, "$(P):AvgPhotonsPerPulse.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):AvgPhotonsPerPulse_3DAY:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):AvgPhotonsPerPulse_3DAY:X-AXIS PP" )
}

record( waveform, "$(P):AvgPhotonsPerPulse_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):AvgPhotonsPerPulse_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):AvgPhotonsPerPulse_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):AvgPhotonsPerPulse_WEEK PP" )

}

record( waveform, "$(P):AvgPhotonsPerPulse_WEEK" )
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "photons" )
	field( NELM, 300 )
	field( TSEL, "$(P):AvgPhotonsPerPulse.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):AvgPhotonsPerPulse_WEEK:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):AvgPhotonsPerPulse_WEEK:X-AXIS PP" )
}

record( waveform, "$(P):AvgPhotonsPerPulse_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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):AvgPhotonsPerPulse_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):AvgPhotonsPerPulse_LAST_N CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):AvgPhotonsPerPulse_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "photons" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):AvgPhotonsPerPulse_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):AvgPhotonsPerPulse_1MIN CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):AvgPhotonsPerPulse_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "photons" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):AvgPhotonsPerPulse_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):AvgPhotonsPerPulse_6MIN CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):AvgPhotonsPerPulse_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "photons" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):AvgPhotonsPerPulse_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):AvgPhotonsPerPulse_30MIN CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):AvgPhotonsPerPulse_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "photons" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):AvgPhotonsPerPulse_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):AvgPhotonsPerPulse_1HR CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):AvgPhotonsPerPulse_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "photons" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):AvgPhotonsPerPulse_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):AvgPhotonsPerPulse_6HR CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):AvgPhotonsPerPulse_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "photons" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):AvgPhotonsPerPulse_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):AvgPhotonsPerPulse_24HR CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):AvgPhotonsPerPulse_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "photons" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):AvgPhotonsPerPulse_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):AvgPhotonsPerPulse_3DAY CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):AvgPhotonsPerPulse_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "photons" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):AvgPhotonsPerPulse_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):AvgPhotonsPerPulse_WEEK CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):AvgPhotonsPerPulse_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "photons" )
	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):AvgPhotonsPerPulse_LAST_N_AVG",    "$(P):AvgPhotonsPerPulse_AVG" )
alias( "$(P):AvgPhotonsPerPulse_LAST_N_MAX",    "$(P):AvgPhotonsPerPulse_MAX" )
alias( "$(P):AvgPhotonsPerPulse_LAST_N_MIN",    "$(P):AvgPhotonsPerPulse_MIN" )
alias( "$(P):AvgPhotonsPerPulse_LAST_N_RMS",    "$(P):AvgPhotonsPerPulse_RMS" )
alias( "$(P):AvgPhotonsPerPulse_LAST_N_STD",    "$(P):AvgPhotonsPerPulse_STD" )
alias( "$(P):AvgPhotonsPerPulse_LAST_N_SLOPE",  "$(P):AvgPhotonsPerPulse_SLOPE" )
alias( "$(P):AvgPhotonsPerPulse_LAST_N_OFFSET", "$(P):AvgPhotonsPerPulse_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):AvgPulseIntensity_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):AvgPulseIntensity_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( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):AvgPulseIntensity_LAST_N PP" )

}

record( waveform, "$(P):AvgPulseIntensity_LAST_N" )
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "mJ" )
	field( NELM, 300 )
	field( TSEL, "$(P):AvgPulseIntensity.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):AvgPulseIntensity_LAST_N:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):AvgPulseIntensity_LAST_N:X-AXIS PP" )
}

record( waveform, "$(P):AvgPulseIntensity_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):AvgPulseIntensity_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):AvgPulseIntensity_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):AvgPulseIntensity_1MIN PP" )

}

record( waveform, "$(P):AvgPulseIntensity_1MIN" )
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "mJ" )
	field( NELM, 300 )
	field( TSEL, "$(P):AvgPulseIntensity.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):AvgPulseIntensity_1MIN:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):AvgPulseIntensity_1MIN:X-AXIS PP" )
}

record( waveform, "$(P):AvgPulseIntensity_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):AvgPulseIntensity_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):AvgPulseIntensity_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):AvgPulseIntensity_6MIN PP" )

}

record( waveform, "$(P):AvgPulseIntensity_6MIN" )
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "mJ" )
	field( NELM, 300 )
	field( TSEL, "$(P):AvgPulseIntensity.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):AvgPulseIntensity_6MIN:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):AvgPulseIntensity_6MIN:X-AXIS PP" )
}

record( waveform, "$(P):AvgPulseIntensity_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):AvgPulseIntensity_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):AvgPulseIntensity_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):AvgPulseIntensity_30MIN PP" )

}

record( waveform, "$(P):AvgPulseIntensity_30MIN" )
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "mJ" )
	field( NELM, 300 )
	field( TSEL, "$(P):AvgPulseIntensity.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):AvgPulseIntensity_30MIN:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):AvgPulseIntensity_30MIN:X-AXIS PP" )
}

record( waveform, "$(P):AvgPulseIntensity_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):AvgPulseIntensity_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):AvgPulseIntensity_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):AvgPulseIntensity_1HR PP" )

}

record( waveform, "$(P):AvgPulseIntensity_1HR" )
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "mJ" )
	field( NELM, 300 )
	field( TSEL, "$(P):AvgPulseIntensity.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):AvgPulseIntensity_1HR:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):AvgPulseIntensity_1HR:X-AXIS PP" )
}

record( waveform, "$(P):AvgPulseIntensity_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):AvgPulseIntensity_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):AvgPulseIntensity_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):AvgPulseIntensity_6HR PP" )

}

record( waveform, "$(P):AvgPulseIntensity_6HR" )
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "mJ" )
	field( NELM, 300 )
	field( TSEL, "$(P):AvgPulseIntensity.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):AvgPulseIntensity_6HR:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):AvgPulseIntensity_6HR:X-AXIS PP" )
}

record( waveform, "$(P):AvgPulseIntensity_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):AvgPulseIntensity_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):AvgPulseIntensity_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):AvgPulseIntensity_24HR PP" )

}

record( waveform, "$(P):AvgPulseIntensity_24HR" )
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "mJ" )
	field( NELM, 300 )
	field( TSEL, "$(P):AvgPulseIntensity.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):AvgPulseIntensity_24HR:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):AvgPulseIntensity_24HR:X-AXIS PP" )
}

record( waveform, "$(P):AvgPulseIntensity_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):AvgPulseIntensity_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):AvgPulseIntensity_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):AvgPulseIntensity_3DAY PP" )

}

record( waveform, "$(P):AvgPulseIntensity_3DAY" )
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "mJ" )
	field( NELM, 300 )
	field( TSEL, "$(P):AvgPulseIntensity.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):AvgPulseIntensity_3DAY:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):AvgPulseIntensity_3DAY:X-AXIS PP" )
}

record( waveform, "$(P):AvgPulseIntensity_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):AvgPulseIntensity_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):AvgPulseIntensity_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):AvgPulseIntensity_WEEK PP" )

}

record( waveform, "$(P):AvgPulseIntensity_WEEK" )
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "mJ" )
	field( NELM, 300 )
	field( TSEL, "$(P):AvgPulseIntensity.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):AvgPulseIntensity_WEEK:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):AvgPulseIntensity_WEEK:X-AXIS PP" )
}

record( waveform, "$(P):AvgPulseIntensity_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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):AvgPulseIntensity_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):AvgPulseIntensity_LAST_N CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):AvgPulseIntensity_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mJ" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):AvgPulseIntensity_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):AvgPulseIntensity_1MIN CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):AvgPulseIntensity_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mJ" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):AvgPulseIntensity_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):AvgPulseIntensity_6MIN CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):AvgPulseIntensity_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mJ" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):AvgPulseIntensity_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):AvgPulseIntensity_30MIN CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):AvgPulseIntensity_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mJ" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):AvgPulseIntensity_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):AvgPulseIntensity_1HR CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):AvgPulseIntensity_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mJ" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):AvgPulseIntensity_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):AvgPulseIntensity_6HR CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):AvgPulseIntensity_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mJ" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):AvgPulseIntensity_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):AvgPulseIntensity_24HR CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):AvgPulseIntensity_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mJ" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):AvgPulseIntensity_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):AvgPulseIntensity_3DAY CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):AvgPulseIntensity_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mJ" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):AvgPulseIntensity_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):AvgPulseIntensity_WEEK CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):AvgPulseIntensity_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mJ" )
	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):AvgPulseIntensity_LAST_N_AVG",    "$(P):AvgPulseIntensity_AVG" )
alias( "$(P):AvgPulseIntensity_LAST_N_MAX",    "$(P):AvgPulseIntensity_MAX" )
alias( "$(P):AvgPulseIntensity_LAST_N_MIN",    "$(P):AvgPulseIntensity_MIN" )
alias( "$(P):AvgPulseIntensity_LAST_N_RMS",    "$(P):AvgPulseIntensity_RMS" )
alias( "$(P):AvgPulseIntensity_LAST_N_STD",    "$(P):AvgPulseIntensity_STD" )
alias( "$(P):AvgPulseIntensity_LAST_N_SLOPE",  "$(P):AvgPulseIntensity_SLOPE" )
alias( "$(P):AvgPulseIntensity_LAST_N_OFFSET", "$(P):AvgPulseIntensity_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):MeanCharge_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):MeanCharge_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( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):MeanCharge_LAST_N PP" )

}

record( waveform, "$(P):MeanCharge_LAST_N" )
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "Coul" )
	field( NELM, 300 )
	field( TSEL, "$(P):MeanCharge.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):MeanCharge_LAST_N:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):MeanCharge_LAST_N:X-AXIS PP" )
}

record( waveform, "$(P):MeanCharge_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):MeanCharge_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):MeanCharge_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):MeanCharge_1MIN PP" )

}

record( waveform, "$(P):MeanCharge_1MIN" )
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "Coul" )
	field( NELM, 300 )
	field( TSEL, "$(P):MeanCharge.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):MeanCharge_1MIN:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):MeanCharge_1MIN:X-AXIS PP" )
}

record( waveform, "$(P):MeanCharge_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):MeanCharge_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):MeanCharge_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):MeanCharge_6MIN PP" )

}

record( waveform, "$(P):MeanCharge_6MIN" )
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "Coul" )
	field( NELM, 300 )
	field( TSEL, "$(P):MeanCharge.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):MeanCharge_6MIN:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):MeanCharge_6MIN:X-AXIS PP" )
}

record( waveform, "$(P):MeanCharge_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):MeanCharge_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):MeanCharge_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):MeanCharge_30MIN PP" )

}

record( waveform, "$(P):MeanCharge_30MIN" )
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "Coul" )
	field( NELM, 300 )
	field( TSEL, "$(P):MeanCharge.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):MeanCharge_30MIN:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):MeanCharge_30MIN:X-AXIS PP" )
}

record( waveform, "$(P):MeanCharge_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):MeanCharge_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):MeanCharge_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):MeanCharge_1HR PP" )

}

record( waveform, "$(P):MeanCharge_1HR" )
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "Coul" )
	field( NELM, 300 )
	field( TSEL, "$(P):MeanCharge.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):MeanCharge_1HR:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):MeanCharge_1HR:X-AXIS PP" )
}

record( waveform, "$(P):MeanCharge_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):MeanCharge_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):MeanCharge_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):MeanCharge_6HR PP" )

}

record( waveform, "$(P):MeanCharge_6HR" )
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "Coul" )
	field( NELM, 300 )
	field( TSEL, "$(P):MeanCharge.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):MeanCharge_6HR:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):MeanCharge_6HR:X-AXIS PP" )
}

record( waveform, "$(P):MeanCharge_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):MeanCharge_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):MeanCharge_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):MeanCharge_24HR PP" )

}

record( waveform, "$(P):MeanCharge_24HR" )
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "Coul" )
	field( NELM, 300 )
	field( TSEL, "$(P):MeanCharge.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):MeanCharge_24HR:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):MeanCharge_24HR:X-AXIS PP" )
}

record( waveform, "$(P):MeanCharge_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):MeanCharge_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):MeanCharge_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):MeanCharge_3DAY PP" )

}

record( waveform, "$(P):MeanCharge_3DAY" )
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "Coul" )
	field( NELM, 300 )
	field( TSEL, "$(P):MeanCharge.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):MeanCharge_3DAY:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):MeanCharge_3DAY:X-AXIS PP" )
}

record( waveform, "$(P):MeanCharge_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):MeanCharge_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):MeanCharge_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):MeanCharge_WEEK PP" )

}

record( waveform, "$(P):MeanCharge_WEEK" )
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "Coul" )
	field( NELM, 300 )
	field( TSEL, "$(P):MeanCharge.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):MeanCharge_WEEK:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):MeanCharge_WEEK:X-AXIS PP" )
}

record( waveform, "$(P):MeanCharge_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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):MeanCharge_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):MeanCharge_LAST_N CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):MeanCharge_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Coul" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):MeanCharge_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):MeanCharge_1MIN CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):MeanCharge_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Coul" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):MeanCharge_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):MeanCharge_6MIN CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):MeanCharge_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Coul" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):MeanCharge_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):MeanCharge_30MIN CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):MeanCharge_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Coul" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):MeanCharge_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):MeanCharge_1HR CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):MeanCharge_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Coul" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):MeanCharge_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):MeanCharge_6HR CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):MeanCharge_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Coul" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):MeanCharge_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):MeanCharge_24HR CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):MeanCharge_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Coul" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):MeanCharge_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):MeanCharge_3DAY CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):MeanCharge_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Coul" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):MeanCharge_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):MeanCharge_WEEK CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):MeanCharge_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "Coul" )
	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):MeanCharge_LAST_N_AVG",    "$(P):MeanCharge_AVG" )
alias( "$(P):MeanCharge_LAST_N_MAX",    "$(P):MeanCharge_MAX" )
alias( "$(P):MeanCharge_LAST_N_MIN",    "$(P):MeanCharge_MIN" )
alias( "$(P):MeanCharge_LAST_N_RMS",    "$(P):MeanCharge_RMS" )
alias( "$(P):MeanCharge_LAST_N_STD",    "$(P):MeanCharge_STD" )
alias( "$(P):MeanCharge_LAST_N_SLOPE",  "$(P):MeanCharge_SLOPE" )
alias( "$(P):MeanCharge_LAST_N_OFFSET", "$(P):MeanCharge_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):CrossSection_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):CrossSection_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( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):CrossSection_LAST_N PP" )

}

record( waveform, "$(P):CrossSection_LAST_N" )
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "cm^2" )
	field( NELM, 300 )
	field( TSEL, "$(P):CrossSection.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):CrossSection_LAST_N:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):CrossSection_LAST_N:X-AXIS PP" )
}

record( waveform, "$(P):CrossSection_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):CrossSection_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):CrossSection_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):CrossSection_1MIN PP" )

}

record( waveform, "$(P):CrossSection_1MIN" )
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "cm^2" )
	field( NELM, 300 )
	field( TSEL, "$(P):CrossSection.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):CrossSection_1MIN:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):CrossSection_1MIN:X-AXIS PP" )
}

record( waveform, "$(P):CrossSection_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):CrossSection_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):CrossSection_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):CrossSection_6MIN PP" )

}

record( waveform, "$(P):CrossSection_6MIN" )
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "cm^2" )
	field( NELM, 300 )
	field( TSEL, "$(P):CrossSection.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):CrossSection_6MIN:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):CrossSection_6MIN:X-AXIS PP" )
}

record( waveform, "$(P):CrossSection_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):CrossSection_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):CrossSection_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):CrossSection_30MIN PP" )

}

record( waveform, "$(P):CrossSection_30MIN" )
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "cm^2" )
	field( NELM, 300 )
	field( TSEL, "$(P):CrossSection.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):CrossSection_30MIN:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):CrossSection_30MIN:X-AXIS PP" )
}

record( waveform, "$(P):CrossSection_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):CrossSection_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):CrossSection_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):CrossSection_1HR PP" )

}

record( waveform, "$(P):CrossSection_1HR" )
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "cm^2" )
	field( NELM, 300 )
	field( TSEL, "$(P):CrossSection.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):CrossSection_1HR:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):CrossSection_1HR:X-AXIS PP" )
}

record( waveform, "$(P):CrossSection_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):CrossSection_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):CrossSection_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):CrossSection_6HR PP" )

}

record( waveform, "$(P):CrossSection_6HR" )
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "cm^2" )
	field( NELM, 300 )
	field( TSEL, "$(P):CrossSection.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):CrossSection_6HR:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):CrossSection_6HR:X-AXIS PP" )
}

record( waveform, "$(P):CrossSection_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):CrossSection_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):CrossSection_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):CrossSection_24HR PP" )

}

record( waveform, "$(P):CrossSection_24HR" )
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "cm^2" )
	field( NELM, 300 )
	field( TSEL, "$(P):CrossSection.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):CrossSection_24HR:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):CrossSection_24HR:X-AXIS PP" )
}

record( waveform, "$(P):CrossSection_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):CrossSection_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):CrossSection_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):CrossSection_3DAY PP" )

}

record( waveform, "$(P):CrossSection_3DAY" )
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "cm^2" )
	field( NELM, 300 )
	field( TSEL, "$(P):CrossSection.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):CrossSection_3DAY:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):CrossSection_3DAY:X-AXIS PP" )
}

record( waveform, "$(P):CrossSection_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):CrossSection_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):CrossSection_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):CrossSection_WEEK PP" )

}

record( waveform, "$(P):CrossSection_WEEK" )
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "cm^2" )
	field( NELM, 300 )
	field( TSEL, "$(P):CrossSection.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):CrossSection_WEEK:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):CrossSection_WEEK:X-AXIS PP" )
}

record( waveform, "$(P):CrossSection_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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):CrossSection_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):CrossSection_LAST_N CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):CrossSection_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "cm^2" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):CrossSection_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):CrossSection_1MIN CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):CrossSection_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "cm^2" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):CrossSection_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):CrossSection_6MIN CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):CrossSection_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "cm^2" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):CrossSection_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):CrossSection_30MIN CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):CrossSection_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "cm^2" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):CrossSection_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):CrossSection_1HR CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):CrossSection_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "cm^2" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):CrossSection_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):CrossSection_6HR CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):CrossSection_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "cm^2" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):CrossSection_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):CrossSection_24HR CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):CrossSection_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "cm^2" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):CrossSection_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):CrossSection_3DAY CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):CrossSection_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "cm^2" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):CrossSection_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):CrossSection_WEEK CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):CrossSection_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "cm^2" )
	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):CrossSection_LAST_N_AVG",    "$(P):CrossSection_AVG" )
alias( "$(P):CrossSection_LAST_N_MAX",    "$(P):CrossSection_MAX" )
alias( "$(P):CrossSection_LAST_N_MIN",    "$(P):CrossSection_MIN" )
alias( "$(P):CrossSection_LAST_N_RMS",    "$(P):CrossSection_RMS" )
alias( "$(P):CrossSection_LAST_N_STD",    "$(P):CrossSection_STD" )
alias( "$(P):CrossSection_LAST_N_SLOPE",  "$(P):CrossSection_SLOPE" )
alias( "$(P):CrossSection_LAST_N_OFFSET", "$(P):CrossSection_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):milliJoulesPerPulse_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):milliJoulesPerPulse_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( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):milliJoulesPerPulse_LAST_N PP" )

}

record( waveform, "$(P):milliJoulesPerPulse_LAST_N" )
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "mJ" )
	field( NELM, 300 )
	field( TSEL, "$(P):milliJoulesPerPulse.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):milliJoulesPerPulse_LAST_N:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):milliJoulesPerPulse_LAST_N:X-AXIS PP" )
}

record( waveform, "$(P):milliJoulesPerPulse_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):milliJoulesPerPulse_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):milliJoulesPerPulse_1MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):milliJoulesPerPulse_1MIN PP" )

}

record( waveform, "$(P):milliJoulesPerPulse_1MIN" )
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "mJ" )
	field( NELM, 300 )
	field( TSEL, "$(P):milliJoulesPerPulse.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):milliJoulesPerPulse_1MIN:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):milliJoulesPerPulse_1MIN:X-AXIS PP" )
}

record( waveform, "$(P):milliJoulesPerPulse_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):milliJoulesPerPulse_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):milliJoulesPerPulse_6MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):milliJoulesPerPulse_6MIN PP" )

}

record( waveform, "$(P):milliJoulesPerPulse_6MIN" )
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "mJ" )
	field( NELM, 300 )
	field( TSEL, "$(P):milliJoulesPerPulse.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):milliJoulesPerPulse_6MIN:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):milliJoulesPerPulse_6MIN:X-AXIS PP" )
}

record( waveform, "$(P):milliJoulesPerPulse_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):milliJoulesPerPulse_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):milliJoulesPerPulse_30MIN_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):milliJoulesPerPulse_30MIN PP" )

}

record( waveform, "$(P):milliJoulesPerPulse_30MIN" )
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "mJ" )
	field( NELM, 300 )
	field( TSEL, "$(P):milliJoulesPerPulse.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):milliJoulesPerPulse_30MIN:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):milliJoulesPerPulse_30MIN:X-AXIS PP" )
}

record( waveform, "$(P):milliJoulesPerPulse_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):milliJoulesPerPulse_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):milliJoulesPerPulse_1HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):milliJoulesPerPulse_1HR PP" )

}

record( waveform, "$(P):milliJoulesPerPulse_1HR" )
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "mJ" )
	field( NELM, 300 )
	field( TSEL, "$(P):milliJoulesPerPulse.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):milliJoulesPerPulse_1HR:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):milliJoulesPerPulse_1HR:X-AXIS PP" )
}

record( waveform, "$(P):milliJoulesPerPulse_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):milliJoulesPerPulse_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):milliJoulesPerPulse_6HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):milliJoulesPerPulse_6HR PP" )

}

record( waveform, "$(P):milliJoulesPerPulse_6HR" )
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "mJ" )
	field( NELM, 300 )
	field( TSEL, "$(P):milliJoulesPerPulse.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):milliJoulesPerPulse_6HR:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):milliJoulesPerPulse_6HR:X-AXIS PP" )
}

record( waveform, "$(P):milliJoulesPerPulse_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):milliJoulesPerPulse_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):milliJoulesPerPulse_24HR_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):milliJoulesPerPulse_24HR PP" )

}

record( waveform, "$(P):milliJoulesPerPulse_24HR" )
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "mJ" )
	field( NELM, 300 )
	field( TSEL, "$(P):milliJoulesPerPulse.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):milliJoulesPerPulse_24HR:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):milliJoulesPerPulse_24HR:X-AXIS PP" )
}

record( waveform, "$(P):milliJoulesPerPulse_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):milliJoulesPerPulse_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):milliJoulesPerPulse_3DAY_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):milliJoulesPerPulse_3DAY PP" )

}

record( waveform, "$(P):milliJoulesPerPulse_3DAY" )
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "mJ" )
	field( NELM, 300 )
	field( TSEL, "$(P):milliJoulesPerPulse.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):milliJoulesPerPulse_3DAY:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):milliJoulesPerPulse_3DAY:X-AXIS PP" )
}

record( waveform, "$(P):milliJoulesPerPulse_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):milliJoulesPerPulse_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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):milliJoulesPerPulse_WEEK_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):milliJoulesPerPulse_WEEK PP" )

}

record( waveform, "$(P):milliJoulesPerPulse_WEEK" )
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "mJ" )
	field( NELM, 300 )
	field( TSEL, "$(P):milliJoulesPerPulse.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):milliJoulesPerPulse_WEEK:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):milliJoulesPerPulse_WEEK:X-AXIS PP" )
}

record( waveform, "$(P):milliJoulesPerPulse_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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):milliJoulesPerPulse_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):milliJoulesPerPulse_LAST_N CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):milliJoulesPerPulse_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mJ" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):milliJoulesPerPulse_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):milliJoulesPerPulse_1MIN CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):milliJoulesPerPulse_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mJ" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):milliJoulesPerPulse_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):milliJoulesPerPulse_6MIN CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):milliJoulesPerPulse_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mJ" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):milliJoulesPerPulse_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):milliJoulesPerPulse_30MIN CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):milliJoulesPerPulse_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mJ" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):milliJoulesPerPulse_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):milliJoulesPerPulse_1HR CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):milliJoulesPerPulse_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mJ" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):milliJoulesPerPulse_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):milliJoulesPerPulse_6HR CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):milliJoulesPerPulse_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mJ" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):milliJoulesPerPulse_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):milliJoulesPerPulse_24HR CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):milliJoulesPerPulse_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mJ" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):milliJoulesPerPulse_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):milliJoulesPerPulse_3DAY CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):milliJoulesPerPulse_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mJ" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):milliJoulesPerPulse_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):milliJoulesPerPulse_WEEK CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):milliJoulesPerPulse_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mJ" )
	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):milliJoulesPerPulse_LAST_N_AVG",    "$(P):milliJoulesPerPulse_AVG" )
alias( "$(P):milliJoulesPerPulse_LAST_N_MAX",    "$(P):milliJoulesPerPulse_MAX" )
alias( "$(P):milliJoulesPerPulse_LAST_N_MIN",    "$(P):milliJoulesPerPulse_MIN" )
alias( "$(P):milliJoulesPerPulse_LAST_N_RMS",    "$(P):milliJoulesPerPulse_RMS" )
alias( "$(P):milliJoulesPerPulse_LAST_N_STD",    "$(P):milliJoulesPerPulse_STD" )
alias( "$(P):milliJoulesPerPulse_LAST_N_SLOPE",  "$(P):milliJoulesPerPulse_SLOPE" )
alias( "$(P):milliJoulesPerPulse_LAST_N_OFFSET", "$(P):milliJoulesPerPulse_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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):LCLS:BeamRate: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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):LCLS:BeamRate: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( EFLG, "ON CHANGE" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P):LCLS:BeamRate:Smoothed CP NMS" )

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):LCLS:BeamRate:Smoothed_LAST_N PP" )

}

record( waveform, "$(P):LCLS:BeamRate:Smoothed_LAST_N" )
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "Hz" )
	field( NELM, 300 )
	field( TSEL, "$(P):LCLS:BeamRate:Smoothed.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):LCLS:BeamRate:Smoothed_LAST_N:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):LCLS:BeamRate:Smoothed_LAST_N:X-AXIS PP" )
}

record( waveform, "$(P):LCLS:BeamRate: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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):LCLS:BeamRate: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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):LCLS:BeamRate: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( EFLG, "ON CHANGE" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P):LCLS:BeamRate:Smoothed CP NMS" )

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):LCLS:BeamRate:Smoothed_1MIN PP" )

}

record( waveform, "$(P):LCLS:BeamRate:Smoothed_1MIN" )
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "Hz" )
	field( NELM, 300 )
	field( TSEL, "$(P):LCLS:BeamRate:Smoothed.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):LCLS:BeamRate:Smoothed_1MIN:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):LCLS:BeamRate:Smoothed_1MIN:X-AXIS PP" )
}

record( waveform, "$(P):LCLS:BeamRate: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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):LCLS:BeamRate: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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):LCLS:BeamRate: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( EFLG, "ON CHANGE" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P):LCLS:BeamRate:Smoothed CP NMS" )

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):LCLS:BeamRate:Smoothed_6MIN PP" )

}

record( waveform, "$(P):LCLS:BeamRate:Smoothed_6MIN" )
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "Hz" )
	field( NELM, 300 )
	field( TSEL, "$(P):LCLS:BeamRate:Smoothed.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):LCLS:BeamRate:Smoothed_6MIN:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):LCLS:BeamRate:Smoothed_6MIN:X-AXIS PP" )
}

record( waveform, "$(P):LCLS:BeamRate: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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):LCLS:BeamRate: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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):LCLS:BeamRate: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( EFLG, "ON CHANGE" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P):LCLS:BeamRate:Smoothed CP NMS" )

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):LCLS:BeamRate:Smoothed_30MIN PP" )

}

record( waveform, "$(P):LCLS:BeamRate:Smoothed_30MIN" )
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "Hz" )
	field( NELM, 300 )
	field( TSEL, "$(P):LCLS:BeamRate:Smoothed.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):LCLS:BeamRate:Smoothed_30MIN:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):LCLS:BeamRate:Smoothed_30MIN:X-AXIS PP" )
}

record( waveform, "$(P):LCLS:BeamRate: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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):LCLS:BeamRate: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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):LCLS:BeamRate: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( EFLG, "ON CHANGE" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P):LCLS:BeamRate:Smoothed CP NMS" )

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):LCLS:BeamRate:Smoothed_1HR PP" )

}

record( waveform, "$(P):LCLS:BeamRate:Smoothed_1HR" )
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "Hz" )
	field( NELM, 300 )
	field( TSEL, "$(P):LCLS:BeamRate:Smoothed.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):LCLS:BeamRate:Smoothed_1HR:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):LCLS:BeamRate:Smoothed_1HR:X-AXIS PP" )
}

record( waveform, "$(P):LCLS:BeamRate: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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):LCLS:BeamRate: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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):LCLS:BeamRate: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( EFLG, "ON CHANGE" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P):LCLS:BeamRate:Smoothed CP NMS" )

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):LCLS:BeamRate:Smoothed_6HR PP" )

}

record( waveform, "$(P):LCLS:BeamRate:Smoothed_6HR" )
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "Hz" )
	field( NELM, 300 )
	field( TSEL, "$(P):LCLS:BeamRate:Smoothed.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):LCLS:BeamRate:Smoothed_6HR:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):LCLS:BeamRate:Smoothed_6HR:X-AXIS PP" )
}

record( waveform, "$(P):LCLS:BeamRate: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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):LCLS:BeamRate: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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):LCLS:BeamRate: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( EFLG, "ON CHANGE" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P):LCLS:BeamRate:Smoothed CP NMS" )

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):LCLS:BeamRate:Smoothed_24HR PP" )

}

record( waveform, "$(P):LCLS:BeamRate:Smoothed_24HR" )
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "Hz" )
	field( NELM, 300 )
	field( TSEL, "$(P):LCLS:BeamRate:Smoothed.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):LCLS:BeamRate:Smoothed_24HR:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):LCLS:BeamRate:Smoothed_24HR:X-AXIS PP" )
}

record( waveform, "$(P):LCLS:BeamRate: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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):LCLS:BeamRate: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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):LCLS:BeamRate: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( EFLG, "ON CHANGE" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P):LCLS:BeamRate:Smoothed CP NMS" )

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):LCLS:BeamRate:Smoothed_3DAY PP" )

}

record( waveform, "$(P):LCLS:BeamRate:Smoothed_3DAY" )
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "Hz" )
	field( NELM, 300 )
	field( TSEL, "$(P):LCLS:BeamRate:Smoothed.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):LCLS:BeamRate:Smoothed_3DAY:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):LCLS:BeamRate:Smoothed_3DAY:X-AXIS PP" )
}

record( waveform, "$(P):LCLS:BeamRate: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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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):LCLS:BeamRate: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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):LCLS:BeamRate: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( EFLG, "ON CHANGE" )

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(P):LCLS:BeamRate:Smoothed CP NMS" )

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(P):LCLS:BeamRate:Smoothed_WEEK PP" )

}

record( waveform, "$(P):LCLS:BeamRate:Smoothed_WEEK" )
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "Hz" )
	field( NELM, 300 )
	field( TSEL, "$(P):LCLS:BeamRate:Smoothed.TIME" )
	info( autosaveFields, "EGU" )
}

# Create an array of time coordinates in the specified units
record( acalcout, "$(P):LCLS:BeamRate:Smoothed_WEEK:CALCX" ) 
{
	field( DESC, "x-axis times" )
	field( CALC, "(B>0)?(IX+1-A)*C/(A*B):(IX+1-A)" )
	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):LCLS:BeamRate:Smoothed_WEEK:X-AXIS PP" )
}

record( waveform, "$(P):LCLS:BeamRate: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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):LCLS:BeamRate: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):LCLS:BeamRate:Smoothed_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P):LCLS:BeamRate:Smoothed_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P):LCLS:BeamRate:Smoothed_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P):LCLS:BeamRate:Smoothed_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P):LCLS:BeamRate:Smoothed_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P):LCLS:BeamRate:Smoothed_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P):LCLS:BeamRate:Smoothed_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P):LCLS:BeamRate:Smoothed_LAST_N_OFFSET PP" )
}

record( ai, "$(P):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):LCLS:BeamRate: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):LCLS:BeamRate:Smoothed_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P):LCLS:BeamRate:Smoothed_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P):LCLS:BeamRate:Smoothed_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P):LCLS:BeamRate:Smoothed_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P):LCLS:BeamRate:Smoothed_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P):LCLS:BeamRate:Smoothed_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P):LCLS:BeamRate:Smoothed_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P):LCLS:BeamRate:Smoothed_1MIN_OFFSET PP" )
}

record( ai, "$(P):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):LCLS:BeamRate: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):LCLS:BeamRate:Smoothed_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P):LCLS:BeamRate:Smoothed_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P):LCLS:BeamRate:Smoothed_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P):LCLS:BeamRate:Smoothed_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P):LCLS:BeamRate:Smoothed_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P):LCLS:BeamRate:Smoothed_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P):LCLS:BeamRate:Smoothed_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P):LCLS:BeamRate:Smoothed_6MIN_OFFSET PP" )
}

record( ai, "$(P):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):LCLS:BeamRate: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):LCLS:BeamRate:Smoothed_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P):LCLS:BeamRate:Smoothed_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P):LCLS:BeamRate:Smoothed_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P):LCLS:BeamRate:Smoothed_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P):LCLS:BeamRate:Smoothed_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P):LCLS:BeamRate:Smoothed_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P):LCLS:BeamRate:Smoothed_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P):LCLS:BeamRate:Smoothed_30MIN_OFFSET PP" )
}

record( ai, "$(P):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):LCLS:BeamRate: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):LCLS:BeamRate:Smoothed_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P):LCLS:BeamRate:Smoothed_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P):LCLS:BeamRate:Smoothed_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P):LCLS:BeamRate:Smoothed_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P):LCLS:BeamRate:Smoothed_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P):LCLS:BeamRate:Smoothed_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P):LCLS:BeamRate:Smoothed_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P):LCLS:BeamRate:Smoothed_1HR_OFFSET PP" )
}

record( ai, "$(P):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):LCLS:BeamRate: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):LCLS:BeamRate:Smoothed_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P):LCLS:BeamRate:Smoothed_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P):LCLS:BeamRate:Smoothed_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P):LCLS:BeamRate:Smoothed_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P):LCLS:BeamRate:Smoothed_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P):LCLS:BeamRate:Smoothed_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P):LCLS:BeamRate:Smoothed_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P):LCLS:BeamRate:Smoothed_6HR_OFFSET PP" )
}

record( ai, "$(P):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):LCLS:BeamRate: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):LCLS:BeamRate:Smoothed_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P):LCLS:BeamRate:Smoothed_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P):LCLS:BeamRate:Smoothed_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P):LCLS:BeamRate:Smoothed_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P):LCLS:BeamRate:Smoothed_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P):LCLS:BeamRate:Smoothed_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P):LCLS:BeamRate:Smoothed_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P):LCLS:BeamRate:Smoothed_24HR_OFFSET PP" )
}

record( ai, "$(P):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):LCLS:BeamRate: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):LCLS:BeamRate:Smoothed_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P):LCLS:BeamRate:Smoothed_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P):LCLS:BeamRate:Smoothed_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P):LCLS:BeamRate:Smoothed_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P):LCLS:BeamRate:Smoothed_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P):LCLS:BeamRate:Smoothed_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P):LCLS:BeamRate:Smoothed_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P):LCLS:BeamRate:Smoothed_3DAY_OFFSET PP" )
}

record( ai, "$(P):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):LCLS:BeamRate: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):LCLS:BeamRate:Smoothed_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(P):LCLS:BeamRate:Smoothed_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(P):LCLS:BeamRate:Smoothed_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(P):LCLS:BeamRate:Smoothed_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(P):LCLS:BeamRate:Smoothed_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(P):LCLS:BeamRate:Smoothed_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(P):LCLS:BeamRate:Smoothed_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(P):LCLS:BeamRate:Smoothed_WEEK_OFFSET PP" )
}

record( ai, "$(P):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate: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):LCLS:BeamRate:Smoothed_LAST_N_AVG",    "$(P):LCLS:BeamRate:Smoothed_AVG" )
alias( "$(P):LCLS:BeamRate:Smoothed_LAST_N_MAX",    "$(P):LCLS:BeamRate:Smoothed_MAX" )
alias( "$(P):LCLS:BeamRate:Smoothed_LAST_N_MIN",    "$(P):LCLS:BeamRate:Smoothed_MIN" )
alias( "$(P):LCLS:BeamRate:Smoothed_LAST_N_RMS",    "$(P):LCLS:BeamRate:Smoothed_RMS" )
alias( "$(P):LCLS:BeamRate:Smoothed_LAST_N_STD",    "$(P):LCLS:BeamRate:Smoothed_STD" )
alias( "$(P):LCLS:BeamRate:Smoothed_LAST_N_SLOPE",  "$(P):LCLS:BeamRate:Smoothed_SLOPE" )
alias( "$(P):LCLS:BeamRate:Smoothed_LAST_N_OFFSET", "$(P):LCLS:BeamRate: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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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 "256S Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P):milliJoulesPerPulse_256S
#

# 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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):milliJoulesPerPulse_256S_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 256 )
	field( OUTA, "$(P):milliJoulesPerPulse_256S PP" )

}

record( waveform, "$(P):milliJoulesPerPulse_256S" )
{
    field( DESC, "256S Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "" )
	field( NELM, 256 )
	field( TSEL, "$(P):milliJoulesPerPulse.TIME" )
	info( autosaveFields, "EGU" )
}

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

record( waveform, "$(P):milliJoulesPerPulse_256S:X-AXIS" ) 
{
	field( DESC, "x-axis times" )
	field( SCAN, "Passive" )
	field( DTYP, "Soft Channel" )
	field( FTVL, "FLOAT" )
	field( NELM, "256" )
	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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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 "256S Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P):AvgPhotonsPerPulse_256S
#

# 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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):AvgPhotonsPerPulse_256S_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 256 )
	field( OUTA, "$(P):AvgPhotonsPerPulse_256S PP" )

}

record( waveform, "$(P):AvgPhotonsPerPulse_256S" )
{
    field( DESC, "256S Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "" )
	field( NELM, 256 )
	field( TSEL, "$(P):AvgPhotonsPerPulse.TIME" )
	info( autosaveFields, "EGU" )
}

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

record( waveform, "$(P):AvgPhotonsPerPulse_256S:X-AXIS" ) 
{
	field( DESC, "x-axis times" )
	field( SCAN, "Passive" )
	field( DTYP, "Soft Channel" )
	field( FTVL, "FLOAT" )
	field( NELM, "256" )
	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
#						If zero, each sample gets shifted into the buffer
#		PUBLISH		- Publish period for updating output array, in seconds
#						If zero, publish on each update
#		N_SAMPLES	- Number of samples to keep, Output waveform's NELEM
#						Defaults to 300
#		EGU			- EGU for sample data, defaults to ""
#		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 "256S Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(P):AvgPulseIntensity_256S
#

# 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
#		P	- double publish interval in seconds (Use 0 for update on change)
#		T	- double history interval in seconds (Use 0 for update on change)
#	Outputs:
#		A	- Array of double's containing samples of A
#				taken over the last T seconds.
#
record( aSub, "$(P):AvgPulseIntensity_256S_SUB" )
{
	field( DESC, "Keeps History of PV" )
	field( SCAN, ".1 second" )
	field( PINI, "NO" )
	field( INAM, "History_Init" )
	field( SNAM, "History_Process" )
	field( EFLG, "ON CHANGE" )

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

	field( FTP, "DOUBLE" )
	field( NOP, 1 )
	field( INPP, "0.1" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 256 )
	field( OUTA, "$(P):AvgPulseIntensity_256S PP" )

}

record( waveform, "$(P):AvgPulseIntensity_256S" )
{
    field( DESC, "256S Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "" )
	field( NELM, 256 )
	field( TSEL, "$(P):AvgPulseIntensity.TIME" )
	info( autosaveFields, "EGU" )
}

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

record( waveform, "$(P):AvgPulseIntensity_256S:X-AXIS" ) 
{
	field( DESC, "x-axis times" )
	field( SCAN, "Passive" )
	field( DTYP, "Soft Channel" )
	field( FTVL, "FLOAT" )
	field( NELM, "256" )
	field( EGU,  "N" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):milliJoulesPerPulse_256S_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):milliJoulesPerPulse_256S CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):milliJoulesPerPulse_256S_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "mJ" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):AvgPhotonsPerPulse_256S_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):AvgPhotonsPerPulse_256S CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

record( ai, "$(P):AvgPhotonsPerPulse_256S_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "arbitrary" )
	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
#
# Optional macros
# NELM          - Number of elements per history array (default 300)
# EGU			- Engineering units: fs, C, mm, etc. (default "")
# RMS_LOLO		- Low, low, limit (default "0")
# RMS_LOW		- Low limit (default "0")
# RMS_HIGH		- High limit (default "0")
# RMS_HIHI		- High, high, limit (default "0")

# 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):AvgPulseIntensity_256S_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):AvgPulseIntensity_256S CPP NMS" )

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

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

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

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

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

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

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

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

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

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

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

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

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

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

