#
# Template for generating aSub records which accumulate
# a history of the 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
#		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_60 Hist"
#		OUT			- Name of waveform PV where history is written
#						Defaults to $(CH,undefined)CALC_PHASE_LAST_60
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 60 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_LAST_60 PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_LAST_60")
{
    field( DESC, "LAST_60 Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 60 )
	field( TSEL, "$(CH,undefined)CALC_PHASE.TIME" )
	info(autosaveFields, "VAL")
}

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

record(waveform, "$(CH,undefined)CALC_PHASE_LAST_60:X-AXIS") 
{
	field(DESC, "x-axis times")
	field(SCAN, "Passive")
	field(DTYP, "Soft Channel")
	field(FTVL, "FLOAT")
	field(NELM, "60")
	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, "$(CH,undefined)CALC_PHASE_LAST_60_RMS_SUB" )
{
	field( DESC, "Calculate RMS for array" )
	field( SCAN, "Passive" )
	field( PINI, "NO" )
	field( INAM, "RMS_Init" )
	field( SNAM, "RMS_Process" )

	field( FTA,  "DOUBLE" )
	field( NOA,  "60" )
	field( INPA, "$(CH,undefined)CALC_PHASE_LAST_60 CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_LAST_60_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_LAST_60_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_LAST_60_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_LAST_60_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_LAST_60_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_LAST_60_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_LAST_60_OFFSET PP" )
}

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

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

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

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

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

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

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

#
# Template for generating aSub records which accumulate
# a history of the 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
#		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 $(CH,undefined)CALC_PHASE_LAST_N
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_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,  "$(CH,undefined)CALC_PHASE_LAST_N:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_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
#		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 $(CH,undefined)CALC_PHASE_1MIN
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_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,  "$(CH,undefined)CALC_PHASE_1MIN:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_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
#		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 $(CH,undefined)CALC_PHASE_6MIN
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_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,  "$(CH,undefined)CALC_PHASE_6MIN:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_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
#		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 $(CH,undefined)CALC_PHASE_30MIN
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_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,  "$(CH,undefined)CALC_PHASE_30MIN:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_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
#		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 $(CH,undefined)CALC_PHASE_1HR
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_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,  "$(CH,undefined)CALC_PHASE_1HR:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_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
#		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 $(CH,undefined)CALC_PHASE_6HR
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_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,  "$(CH,undefined)CALC_PHASE_6HR:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_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
#		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 $(CH,undefined)CALC_PHASE_24HR
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_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,  "$(CH,undefined)CALC_PHASE_24HR:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_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
#		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 $(CH,undefined)CALC_PHASE_3DAY
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_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,  "$(CH,undefined)CALC_PHASE_3DAY:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_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
#		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 $(CH,undefined)CALC_PHASE_WEEK
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_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,  "$(CH,undefined)CALC_PHASE_WEEK:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_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, "$(CH,undefined)CALC_PHASE_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, "$(CH,undefined)CALC_PHASE_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_LAST_N_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_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, "$(CH,undefined)CALC_PHASE_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_1MIN_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_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, "$(CH,undefined)CALC_PHASE_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_6MIN_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_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, "$(CH,undefined)CALC_PHASE_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_30MIN_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_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, "$(CH,undefined)CALC_PHASE_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_1HR_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_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, "$(CH,undefined)CALC_PHASE_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_6HR_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_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, "$(CH,undefined)CALC_PHASE_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_24HR_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_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, "$(CH,undefined)CALC_PHASE_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_3DAY_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_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, "$(CH,undefined)CALC_PHASE_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_WEEK_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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( "$(CH,undefined)CALC_PHASE_LAST_N_MAX",    "$(CH,undefined)CALC_PHASE_MAX" )
alias( "$(CH,undefined)CALC_PHASE_LAST_N_AVG",    "$(CH,undefined)CALC_PHASE_AVG" )
alias( "$(CH,undefined)CALC_PHASE_LAST_N_MIN",    "$(CH,undefined)CALC_PHASE_MIN" )
alias( "$(CH,undefined)CALC_PHASE_LAST_N_RMS",    "$(CH,undefined)CALC_PHASE_RMS" )
alias( "$(CH,undefined)CALC_PHASE_LAST_N_STD",    "$(CH,undefined)CALC_PHASE_STD" )
alias( "$(CH,undefined)CALC_PHASE_LAST_N_SLOPE",  "$(CH,undefined)CALC_PHASE_SLOPE" )
alias( "$(CH,undefined)CALC_PHASE_LAST_N_OFFSET", "$(CH,undefined)CALC_PHASE_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
#		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 $(CH,undefined)CALC_PHASE_RMS_LAST_N
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE_RMS CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_RMS_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_RMS_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE_RMS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_RMS_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,  "$(CH,undefined)CALC_PHASE_RMS_LAST_N:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_RMS_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
#		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 $(CH,undefined)CALC_PHASE_RMS_1MIN
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE_RMS CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_RMS_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_RMS_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE_RMS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_RMS_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,  "$(CH,undefined)CALC_PHASE_RMS_1MIN:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_RMS_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
#		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 $(CH,undefined)CALC_PHASE_RMS_6MIN
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE_RMS CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_RMS_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_RMS_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE_RMS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_RMS_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,  "$(CH,undefined)CALC_PHASE_RMS_6MIN:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_RMS_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
#		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 $(CH,undefined)CALC_PHASE_RMS_30MIN
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE_RMS CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_RMS_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_RMS_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE_RMS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_RMS_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,  "$(CH,undefined)CALC_PHASE_RMS_30MIN:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_RMS_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
#		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 $(CH,undefined)CALC_PHASE_RMS_1HR
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE_RMS CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_RMS_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_RMS_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE_RMS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_RMS_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,  "$(CH,undefined)CALC_PHASE_RMS_1HR:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_RMS_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
#		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 $(CH,undefined)CALC_PHASE_RMS_6HR
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE_RMS CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_RMS_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_RMS_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE_RMS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_RMS_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,  "$(CH,undefined)CALC_PHASE_RMS_6HR:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_RMS_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
#		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 $(CH,undefined)CALC_PHASE_RMS_24HR
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE_RMS CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_RMS_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_RMS_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE_RMS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_RMS_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,  "$(CH,undefined)CALC_PHASE_RMS_24HR:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_RMS_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
#		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 $(CH,undefined)CALC_PHASE_RMS_3DAY
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE_RMS CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_RMS_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_RMS_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE_RMS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_RMS_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,  "$(CH,undefined)CALC_PHASE_RMS_3DAY:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_RMS_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
#		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 $(CH,undefined)CALC_PHASE_RMS_WEEK
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE_RMS CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_RMS_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_RMS_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE_RMS.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_RMS_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,  "$(CH,undefined)CALC_PHASE_RMS_WEEK:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_RMS_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, "$(CH,undefined)CALC_PHASE_RMS_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, "$(CH,undefined)CALC_PHASE_RMS_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_RMS_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_RMS_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_RMS_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_RMS_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_RMS_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_RMS_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_RMS_LAST_N_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_RMS_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_RMS_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, "$(CH,undefined)CALC_PHASE_RMS_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_RMS_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_RMS_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_RMS_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_RMS_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_RMS_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_RMS_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_RMS_1MIN_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_RMS_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_RMS_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, "$(CH,undefined)CALC_PHASE_RMS_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_RMS_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_RMS_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_RMS_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_RMS_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_RMS_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_RMS_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_RMS_6MIN_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_RMS_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_RMS_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, "$(CH,undefined)CALC_PHASE_RMS_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_RMS_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_RMS_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_RMS_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_RMS_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_RMS_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_RMS_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_RMS_30MIN_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_RMS_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_RMS_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, "$(CH,undefined)CALC_PHASE_RMS_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_RMS_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_RMS_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_RMS_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_RMS_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_RMS_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_RMS_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_RMS_1HR_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_RMS_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_RMS_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, "$(CH,undefined)CALC_PHASE_RMS_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_RMS_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_RMS_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_RMS_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_RMS_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_RMS_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_RMS_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_RMS_6HR_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_RMS_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_RMS_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, "$(CH,undefined)CALC_PHASE_RMS_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_RMS_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_RMS_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_RMS_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_RMS_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_RMS_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_RMS_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_RMS_24HR_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_RMS_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_RMS_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, "$(CH,undefined)CALC_PHASE_RMS_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_RMS_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_RMS_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_RMS_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_RMS_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_RMS_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_RMS_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_RMS_3DAY_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_RMS_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_RMS_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, "$(CH,undefined)CALC_PHASE_RMS_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_RMS_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_RMS_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_RMS_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_RMS_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_RMS_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_RMS_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_RMS_WEEK_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_RMS_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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( "$(CH,undefined)CALC_PHASE_RMS_LAST_N_MAX",    "$(CH,undefined)CALC_PHASE_RMS_MAX" )
alias( "$(CH,undefined)CALC_PHASE_RMS_LAST_N_AVG",    "$(CH,undefined)CALC_PHASE_RMS_AVG" )
alias( "$(CH,undefined)CALC_PHASE_RMS_LAST_N_MIN",    "$(CH,undefined)CALC_PHASE_RMS_MIN" )
alias( "$(CH,undefined)CALC_PHASE_RMS_LAST_N_RMS",    "$(CH,undefined)CALC_PHASE_RMS_RMS" )
alias( "$(CH,undefined)CALC_PHASE_RMS_LAST_N_STD",    "$(CH,undefined)CALC_PHASE_RMS_STD" )
alias( "$(CH,undefined)CALC_PHASE_RMS_LAST_N_SLOPE",  "$(CH,undefined)CALC_PHASE_RMS_SLOPE" )
alias( "$(CH,undefined)CALC_PHASE_RMS_LAST_N_OFFSET", "$(CH,undefined)CALC_PHASE_RMS_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
#		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 $(CH,undefined)CALC_PHASE_STD_LAST_N
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE_STD CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_STD_LAST_N PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_STD_LAST_N")
{
    field( DESC, "LAST_N Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE_STD.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_STD_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,  "$(CH,undefined)CALC_PHASE_STD_LAST_N:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_STD_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
#		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 $(CH,undefined)CALC_PHASE_STD_1MIN
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE_STD CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_STD_1MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_STD_1MIN")
{
    field( DESC, "1MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE_STD.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_STD_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,  "$(CH,undefined)CALC_PHASE_STD_1MIN:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_STD_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
#		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 $(CH,undefined)CALC_PHASE_STD_6MIN
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE_STD CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_STD_6MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_STD_6MIN")
{
    field( DESC, "6MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE_STD.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_STD_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,  "$(CH,undefined)CALC_PHASE_STD_6MIN:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_STD_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
#		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 $(CH,undefined)CALC_PHASE_STD_30MIN
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE_STD CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_STD_30MIN PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_STD_30MIN")
{
    field( DESC, "30MIN Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE_STD.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_STD_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,  "$(CH,undefined)CALC_PHASE_STD_30MIN:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_STD_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
#		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 $(CH,undefined)CALC_PHASE_STD_1HR
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE_STD CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_STD_1HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_STD_1HR")
{
    field( DESC, "1HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE_STD.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_STD_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,  "$(CH,undefined)CALC_PHASE_STD_1HR:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_STD_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
#		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 $(CH,undefined)CALC_PHASE_STD_6HR
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE_STD CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_STD_6HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_STD_6HR")
{
    field( DESC, "6HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE_STD.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_STD_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,  "$(CH,undefined)CALC_PHASE_STD_6HR:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_STD_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
#		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 $(CH,undefined)CALC_PHASE_STD_24HR
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE_STD CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_STD_24HR PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_STD_24HR")
{
    field( DESC, "24HR Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE_STD.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_STD_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,  "$(CH,undefined)CALC_PHASE_STD_24HR:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_STD_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
#		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 $(CH,undefined)CALC_PHASE_STD_3DAY
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE_STD CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_STD_3DAY PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_STD_3DAY")
{
    field( DESC, "3DAY Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE_STD.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_STD_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,  "$(CH,undefined)CALC_PHASE_STD_3DAY:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_STD_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
#		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 $(CH,undefined)CALC_PHASE_STD_WEEK
#

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

	field( FTA,  "DOUBLE" )
	field( NOA,  1 )
	field( INPA, "$(CH,undefined)CALC_PHASE_STD CP NMS" )

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

	field( FTVA, "DOUBLE" )
	field( NOVA, 300 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_STD_WEEK PP" )
	info( autosaveFields, "VALA NEA" )

}

record( waveform, "$(CH,undefined)CALC_PHASE_STD_WEEK")
{
    field( DESC, "WEEK Hist" )
	field( FTVL, "DOUBLE" )
	field( EGU,  "fs" )
	field( NELM, 300 )
	field( TSEL, "$(CH,undefined)CALC_PHASE_STD.TIME" )
	info(autosaveFields, "VAL")
}

# Create an array of time coordinates in the specified units
record(acalcout, "$(CH,undefined)CALC_PHASE_STD_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,  "$(CH,undefined)CALC_PHASE_STD_WEEK:X-AXIS PP" )
}

record(waveform, "$(CH,undefined)CALC_PHASE_STD_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, "$(CH,undefined)CALC_PHASE_STD_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, "$(CH,undefined)CALC_PHASE_STD_LAST_N CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_STD_LAST_N_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_STD_LAST_N_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_STD_LAST_N_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_STD_LAST_N_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_STD_LAST_N_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_STD_LAST_N_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_STD_LAST_N_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_STD_LAST_N_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_STD_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, "$(CH,undefined)CALC_PHASE_STD_1MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_STD_1MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_STD_1MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_STD_1MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_STD_1MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_STD_1MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_STD_1MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_STD_1MIN_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_STD_1MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_STD_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, "$(CH,undefined)CALC_PHASE_STD_6MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_STD_6MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_STD_6MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_STD_6MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_STD_6MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_STD_6MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_STD_6MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_STD_6MIN_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_STD_6MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_STD_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, "$(CH,undefined)CALC_PHASE_STD_30MIN CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_STD_30MIN_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_STD_30MIN_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_STD_30MIN_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_STD_30MIN_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_STD_30MIN_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_STD_30MIN_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_STD_30MIN_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_STD_30MIN_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_STD_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, "$(CH,undefined)CALC_PHASE_STD_1HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_STD_1HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_STD_1HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_STD_1HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_STD_1HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_STD_1HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_STD_1HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_STD_1HR_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_STD_1HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_STD_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, "$(CH,undefined)CALC_PHASE_STD_6HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_STD_6HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_STD_6HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_STD_6HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_STD_6HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_STD_6HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_STD_6HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_STD_6HR_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_STD_6HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_STD_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, "$(CH,undefined)CALC_PHASE_STD_24HR CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_STD_24HR_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_STD_24HR_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_STD_24HR_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_STD_24HR_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_STD_24HR_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_STD_24HR_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_STD_24HR_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_STD_24HR_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_STD_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, "$(CH,undefined)CALC_PHASE_STD_3DAY CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_STD_3DAY_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_STD_3DAY_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_STD_3DAY_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_STD_3DAY_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_STD_3DAY_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_STD_3DAY_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_STD_3DAY_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_STD_3DAY_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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, "$(CH,undefined)CALC_PHASE_STD_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, "$(CH,undefined)CALC_PHASE_STD_WEEK CPP NMS" )

	field( FTVA, "DOUBLE" )
	field( NOVA, 1 )
	field( OUTA, "$(CH,undefined)CALC_PHASE_STD_WEEK_RMS PP" )

	field( FTVB, "DOUBLE" )
	field( NOVB, 1 )
	field( OUTB, "$(CH,undefined)CALC_PHASE_STD_WEEK_MAX PP" )

	field( FTVC, "DOUBLE" )
	field( NOVC, 1 )
	field( OUTC, "$(CH,undefined)CALC_PHASE_STD_WEEK_MIN PP" )

	field( FTVD, "DOUBLE" )
	field( NOVD, 1 )
	field( OUTD, "$(CH,undefined)CALC_PHASE_STD_WEEK_AVG PP" )

	field( FTVE, "DOUBLE" )
	field( NOVE, 1 )
	field( OUTE, "$(CH,undefined)CALC_PHASE_STD_WEEK_STD PP" )

	field( FTVF, "DOUBLE" )
	field( NOVF, 1 )
	field( OUTF, "$(CH,undefined)CALC_PHASE_STD_WEEK_SLOPE PP" )

	field( FTVG, "DOUBLE" )
	field( NOVG, 1 )
	field( OUTG, "$(CH,undefined)CALC_PHASE_STD_WEEK_OFFSET PP" )
}

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

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

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

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

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

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

record( ai, "$(CH,undefined)CALC_PHASE_STD_WEEK_OFFSET" )
{
	field( DESC, "Offset of least squares fit" )
	field( EGU,  "fs" )
	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( "$(CH,undefined)CALC_PHASE_STD_LAST_N_MAX",    "$(CH,undefined)CALC_PHASE_STD_MAX" )
alias( "$(CH,undefined)CALC_PHASE_STD_LAST_N_AVG",    "$(CH,undefined)CALC_PHASE_STD_AVG" )
alias( "$(CH,undefined)CALC_PHASE_STD_LAST_N_MIN",    "$(CH,undefined)CALC_PHASE_STD_MIN" )
alias( "$(CH,undefined)CALC_PHASE_STD_LAST_N_RMS",    "$(CH,undefined)CALC_PHASE_STD_RMS" )
alias( "$(CH,undefined)CALC_PHASE_STD_LAST_N_STD",    "$(CH,undefined)CALC_PHASE_STD_STD" )
alias( "$(CH,undefined)CALC_PHASE_STD_LAST_N_SLOPE",  "$(CH,undefined)CALC_PHASE_STD_SLOPE" )
alias( "$(CH,undefined)CALC_PHASE_STD_LAST_N_OFFSET", "$(CH,undefined)CALC_PHASE_STD_OFFSET" )
