crg_h

/*
**	Copyright 1991, Universities Research Association.  All rights reserved.
*/
/******************************************************************************/
/* crg.h
**  
**	prototypes and defined constants for argument values for
**	ul_crg library routines
**
*/
/******************************************************************************/

#ifndef CRG_DEFINED				/* do this only once */
#define	CRG_DEFINED

/******************************************************************************/
/* 
**	macros
*/
/******************************************************************************/

/******************************************************************************/
/* 
**	defined constants for argument values and structure definitions
**	and data structures
*/
/******************************************************************************/

/*
** cnv_time_energy...
*/
/** The first 2 of these assume the time is relative to either
a $42 (Start of ramp) or $6D (start of deceleration). 
The second 2 (with the _41 suffix) assume the time is relative to a $41
(Tevatron Ramp Reset). This change was made on about 5/17/00 by ppb.
Previously the function assumed the times were relative to the $41. **/

#define	CNV_TIME_TO_ENERGY		0	/* convert time to energy */
#define	CNV_ENERGY_TO_TIME		1	/* convert energy to time */
#define	CNV_TIME_TO_ENERGY_41		2	/* convert time to energy */
#define	CNV_ENERGY_TO_TIME_41		3	/* convert energy to time */

/*
** cnv_time_energy data structure definitions
*/
/*
** CRG TECAR ramp file structures
*/
#define	CRG_ACTIVE_TECAR	0
#define	CRG_MAX_NBR_FILES	24
#define	CRG_MAX_NBR_SLOTS	253
#define	CRG_B0_TIMES		6
#define	CRG_D0_TIMES		6
#define	CRG_COLL_TIMES		7


typedef struct					/* file record structure for energy-time conversion data */
    {
    short	numseg;				/* # of ramp segments */
    float	cnvdata[CRG_MAX_NBR_SLOTS][4];	/* conversion data */
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ ENERGY_TIME;

typedef struct crg_tecar_struct
    {
    int	clinks;
    int		active_file;
    int		file_number;
    int		nbr_slots;
    float	time[CRG_MAX_NBR_SLOTS];
    float	energy[CRG_MAX_NBR_SLOTS];
    float	edot[CRG_MAX_NBR_SLOTS];
    float	edbldot[CRG_MAX_NBR_SLOTS];
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ CRG_TECAR;

typedef struct crg_ramp_ftn
    {
    short	nsegte;
    float	tecseg[CRG_MAX_NBR_SLOTS][4];
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ CRG_RAMP_FTN;

#define	CRG_MAX_PARAMS		20		/* max # C49 parameters */
#define	CRG_MAX_COLL_MODES	5		/* # collider seqdat modes */

typedef struct					/* C49 setting broadcast */
    {
    int	ct_timeup;			/* time updated (clinks) */
    int		ct_numof;			/* # of actual params */
    int		ct_dis[CRG_MAX_PARAMS];		/* psuedo devices to set */
    float	ct_values[CRG_MAX_COLL_MODES][CRG_MAX_PARAMS];	/* inner-order: "macro - 100" */
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ CRG_TUNER;

#define	CRG_MAX_SEPARATORS	6
#define	CRG_MAX_LOWBETA_QUADS	19
#define	CRG_MAX_FEEDDOWNS	27
#define	CRG_MAX_CORRECTORS	14
#define	CRG_HOR_PLANE		1
#define	CRG_VER_PLANE		2
				/* A structure for extracting crg  */
				/* currents for lattice models */
				/* for a user selected file and slot */
				/* This is for collider mode only */
typedef struct
    {
    int		file_number;			/* CRG file number */
    float	energy;				/* Slot energy */
    float	bus_current;
    float	qf;
    float	qd;
    float	sf;
    float	sd;
    float	sq;
    float	sqa0;
    float	sqb0;
    float	sqd0;
    float	hsep[CRG_MAX_SEPARATORS];	/* These are in the C49 page order */
    float	vsep[CRG_MAX_SEPARATORS];	/* These are in the C49 page order */
    float	b0_quads[CRG_MAX_LOWBETA_QUADS];	/* so are these */
    float	d0_quads[CRG_MAX_LOWBETA_QUADS];
    float	feeddowns[CRG_MAX_FEEDDOWNS];
    float	b0_hcor[CRG_MAX_CORRECTORS];
    float	b0_vcor[CRG_MAX_CORRECTORS];
    float	d0_hcor[CRG_MAX_CORRECTORS];
    float	d0_vcor[CRG_MAX_CORRECTORS];
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ CRG_COLLIDER_DATA;

/* defines for crg_squeeze_info.c */

//#define RAMP_LOWBETA_SQUEEZE   6
// Get squeeze times from the LBCON squeeze ramp instead!
#define RAMP_LOWBETA_SQUEEZE   28

/* These codes specify which parameter to use as the input
 * for the squeeze info query */
#define SLOT_INPUT   0
#define LBSEQ_INPUT  1
#define TIME_INPUT   2

#define MAX_NBR_SLOTS 32

/******************************************************************************/
/*
**	function prototypes
*/
/******************************************************************************/

#ifdef __cplusplus
extern "C" {
#endif

int cnv_time_energy(float *time, float *energy, int type, int file_number);
int crg_active_file(int *file_number);
int crg_collider_data(CRG_COLLIDER_DATA *return_data);
int crg_param_read(int file_number, CRG_TECAR *this_ramp);
int crg_read_b2min_breakpoints_c(int file, float *breakpoints,
				 int *num_breakpoints);
int crg_read_b2min_slope(float *slope);
int crg_read_tuner(CRG_TUNER *device_data);
int crg_separator_angle_to_volts(int file_number, float energy,
				 float *angles, float *volts,
				 int plane);
int crg_separator_volts_to_angle(int file_number, float energy,
				 float *angles, float *volts,
				 int plane);
int crg_squeeze_info(int *file_number, int *slot_number,
		     int *lbseq, int *lattice, float *time, 
		     int *num_slots, int input_key);
int crg_tecar_c_to_ftn(int *file_number, CRG_RAMP_FTN *ramp_data);
int crg_tecar_read(int file_number, CRG_TECAR *this_ramp);
int crg_get_inj_slot(int file_number);
float crg_correct_current(float*,float*,float);
int crg_get_capdep_slot(int file_number);
int crg_dfg_di(int group_id, int *num_di, int *di_array);
int crg_B0_hdfg_di(int *num_di, int *di_array);
int crg_B0_vdfg_di(int *num_di, int *di_array);
int crg_D0_hdfg_di(int *num_di, int *di_array);
int crg_D0_vdfg_di(int *num_di, int *di_array);

#ifdef __cplusplus
}
#endif


/******************************************************************************/
/*
**	equivalent name definitions
*/
/******************************************************************************/

#define	CNV_TIME_ENERGY			cnv_time_energy
#define	CRG_ACTIVE_FILE			crg_active_file
/* #define	CRG_COLLIDER_DATA		crg_collider_data */
#define	CRG_PARAM_READ			crg_param_read
#define	CRG_READ_B2MIN_BREAKPOINTS_C	crg_read_b2min_breakpoints_c
#define	CRG_READ_B2MIN_SLOPE		crg_read_b2min_slope
#define	CRG_READ_TUNER			crg_read_tuner
#define	CRG_SEPARATOR_ANGLE_TO_VOLTS	crg_separator_angle_to_volts
#define	CRG_SEPARATOR_VOLTS_TO_ANGLE	crg_separator_volts_to_angle
#define	CRG_SQUEEZE_INFO		crg_squeeze_info
#define	CRG_TECAR_C_TO_FTN		crg_tecar_c_to_ftn
#define	CRG_TECAR_READ			crg_tecar_read

#endif