/* HRC Software System Header File

$Header: $

$Log: $

$Revision: 5.0$

*/

/*** General Defines ***/
void *calloc();
#define CALLOC(n,x)  ((x *) calloc(n,sizeof(x)))
#define DEBUG(x)	if( debug >= x )

#define YES 0
#define NO -1
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define ON 0
#define OFF -1
#define OK (0)
#define DONE -1
#define BAD -1
#define GOOD 0
#define NOEVT 1
#define NOP 0
#define OKAY 0

#define EOS '\0'
#define SPACE ' '
#define NL '\n'
#define BUFSIZE 80
#define EOD -1
#define LARGE 2147483647

/*** HRC DATA defines ***/

#define UAMPS 0
#define VAMPS 1

#define DATA 1		
#define NOTYET 0
#define HOUSE 2
#define BADPOS -1
#define INVALID -1

#define DET_CMD 0
#define DET_DATA 1

#define PGOOD 0x00
#define ZERO_SUM 0x01
#define GRID_RATIO 0x02
#define ZERO_PSUM 0x04
#define PHA_RATIO 0x08
#define U_CENTER 0x10
#define V_CENTER 0x20
#define FINE_POS 0x40
#define HOT_SPOT 0x80

#define EVENTS 0
#define SEC 1
#define FRAMES 2

#define CTUE_HRC_FRAME_SIZE 1029 /* (1019 bytes + 6 CCSDS + 4 SYNC) */
#define LAB_HRC_FRAME_SIZE 8192 /* Somewhat arbitrary */
#define FAST_HRC_FRAME_SIZE 8192 /* A singe event * 512*/

#define USI unsigned short int
#define UC unsigned char

/* raw data structure LAB */
struct  raw_data {
  int read_count;	/* number of bytes read on read_data call */
  unsigned char tm[LAB_HRC_FRAME_SIZE];
  int ID;
  int frame_count;
  long buf_time;
};

/* tm data structure CTUE */
struct  Tm_data {
  int read_count;	/* number of bytes read on read_data call */
  unsigned char tm[CTUE_HRC_FRAME_SIZE];
  int ID;
  int frame_count;
  long buf_time;
};

/* fast tm data structure FAST */
struct  Ftm_data {
  int read_count;	/* number of bytes read on read_data call */
  unsigned char tm[FAST_HRC_FRAME_SIZE];
  int ID;
  int frame_count;
  long buf_time;
};

/* define secondary science data structure */
struct Secondary_science_data {
  int vcdu;
  int sec;
  short year;
  short day;
  short msec;
  unsigned short tevt_rate_1;
  unsigned short tevt_rate_2;
  unsigned short vevt_rate_1;
  unsigned short vevt_rate_2;
  unsigned short shield_rate_1;
  unsigned short shield_rate_2;
};

struct Event_data {
  double time;
  double qest0;
  double qest1;
  double qest2;
  double qest3;
  int vcdu;
  int x;
  int y;
  int uraw;
  int vraw;
  int upos;
  int vpos;
  int hrc_time;
  unsigned int sec;
  unsigned short year;
  unsigned short day;
  unsigned short msec;
  short av0;
  short av1;
  short av2;
  short au0;
  short au1;
  short au2;
  short pha;
  short sumamps;
  unsigned char cx;
  unsigned char cy;
  unsigned char crsv;
  unsigned char crsu;
  unsigned char amp_sf;
  unsigned char segment;
  unsigned char det_id;
  unsigned char veto_status;
  unsigned char event_status;
  unsigned char process_status;
  unsigned char spare_status;
};

struct Short_data {
  double time;
  int vcdu;
  int x;
  int y;
  int uraw;
  int vraw;
  int upos;
  int vpos;
  int hrc_time;
  short pha;
  short sumamps;
  unsigned char cx;
  unsigned char cy;
  unsigned char amp_sf;
  unsigned char segment;
  unsigned char det_id;
  unsigned char veto_status;
  unsigned char event_status;
  unsigned char process_status;
  unsigned char spare_status;
};

struct Aspect_data {
  double qest[4];
  double qpnom[4];
  double ra_nom;
  double dec_nom;
  double roll_nom;
  double prev_time;
  double prev_q0;
  double prev_q1;
  double prev_q2;
  double prev_q3;
  double prev_dy;
  double prev_dz;
  double prev_dtheta;
  int instr;
  int a_flag;
  char asp_file[64];
};

struct Process_parm {
  /* use dimensioned variables where appropriate */
  /* Quantity[detector][axis][term] */
  double cf[2][2][2];
  double pha_ratio;
  double grid_ratio;
  double finh[2][2];
  double finhd[2][2];
  double fina[2][2];
  double finb[2][2];
  double blow[2][2];
  double bhigh[2][2];
  double fptol;
  double blura[2][2];
  double blurb[2][2];
  double blurc[2][2];
  double blurd[2][2];
  double blurl[2][2];
  double amp_gain;
  double plate_scale;
  double pixel;
  double rot;
  double crot;
  double srot;
  int proc_all;
  int flip;
  int t_flag;
  int h_flag;
  int b_flag;
  int degap_sel;
  int spill;
  int wire_charge;
  int uvmax[2][2];
  int rcent[2][2];
  char degap_file[64];
  char hot_file[64];
};

struct SFparm{
  double ufinh, ufinhd, ufina, ufinb, ublow, ubhigh;
  double vfinh, vfinhd, vfina, vfinb, vblow, vbhigh;
  double gstart, gstop, sum_amps, flat_test, amp_gain, delta;
  int gti_got, ngti;
  int pha_cnt, amp_test, ampsf_cnt, fixampsf_cnt;
  int gti_cnt, amp_cnt, flat_cnt;
  int phal, phau, pha_tol1, pha_tol2, pha_tol3, amp_min, amp_max;
  int finposu_cnt, finposv_cnt;
  int finposu_only, finposv_only, finposu_and_v, finpos_total;
};


struct epr_sel_input_parameters {
  int debug;
  int uposl;
  int uposu;
  int vposl;
  int vposu;
  int lsmu;
  int usmu;
  int lsmv;
  int usmv;
  int phal;
  int phau;
  unsigned char veto;
  unsigned char event;
  unsigned char process;
  short saturated;
  long estart;
  long estop;
};
typedef struct epr_sel_input_parameters EprSelIPRec, *EprSelIP;


struct epr2epr_input_parameters {
  int debug;
  int d;
  int degap_sel;
  int spill;
  int wire_charge;
  double cf[2][2];
  double pha_ratio;
  double grid_ratio;
  double amp_gain;
  char file_name[64];
  char degap_file[64];
  char hot_file[64];
};
typedef struct epr2epr_input_parameters Epr2EprIPRec, *Epr2EprIP;

struct det_cell {
  int u;
  int v;
  int cts;
  double cu;
  double cv;
};
typedef struct det_cell DetCell, *Cell;

struct fdet_cell {
  int u;
  int v;
  double cts;
  double cu;
  double cv;
};
typedef struct fdet_cell FDetCell, *FCell;

struct fine_pos {
  double fu;
  double usig;
  double fv;
  double vsig;
  int sum;
  double pha;
  double psig;
  double period;
  double persig;
};
typedef struct fine_pos FinePos, *Fine;

struct Degap_data {
  double la;
  double lb;
  double ra;
  double rb;

};
typedef struct degap DeGap, *Degap;

struct Hotspot_map {
  short spot;
  unsigned short ul;
  unsigned short vl;
  unsigned short uu;
  unsigned short vu;
};




