C+
C	NAME:
C		HXT_STRUCT
C	PURPOSE:
C		Define the following HXT specific database structures
C			* HXT_QS_Instr_Rec         
C			* HXT_QS_Conv_Rec          
C			* HXT_Index_Rec            
C			* HXT_PC_Data_Rec          
C			* HXT_PH_Data_Rec          
C			* HXT_RoadMap_Rec          
C
C	CALLING SEQUENCE:
C		HXT_STRUCT
C	HISTORY:
C		written by Mons Morrison, Fall 90.
C                1-Sep-94 (MDM) - Clarified the "dataRecTypes" definition
C
C-
C	---------------------------------------------------------------

	STRUCTURE	/HXT_QS_Instr_Rec/
					!	NOT IMPLEMENTED AS OF 25-Mar-92]

	  integer*2	entry_type /'4011'x/
					! 00- Structure/Entry type

	  integer*4	st_time		! 02- Start time (millisec of day) entries are valid
	  integer*2	st_day		! 06- Start day (since 1-Jan-79)
	  integer*4	en_time		! 08- End time (millisec of day)
	  integer*2	en_day		! 12- End day (since 1-Jan-79)

	  !TBD

	  byte		spare(50)	! 14- Spare
	END STRUCTURE			! 64- Total


	STRUCTURE	/HXT_QS_Conv_Rec/
					!	NOT IMPLEMENTED AS OF 25-Mar-92]

	  integer*2	entry_type /'4021'x/
					! 00- Structure/Entry type

	  integer*4	st_time		! 02- Start time (millisec of day) entries are valid
	  integer*2	st_day		! 06- Start day (since 1-Jan-79)
	  integer*4	en_time		! 08- End time (millisec of day)
	  integer*2	en_day		! 12- End day (since 1-Jan-79)

	  integer*4	off_dhk(2)	! 14- Offset time in millisec from MF time for DHK data
	  integer*4	off_pc(2)	! 22- Offset time in millisec from MF time for PC data
	  integer*4	off_ph(2)	! 30- Offset time in millisec from MF time for PHA data
	  integer*4	off_hxa(2)	! 38- Offset time in millisec from MF time for HXA data
					!	(1) = high rate; (2) = medium rate

	  integer*4	energy(5)	! 46- Energy conversion in 0.01 KeV
	  integer*4	hv_conv(2)	! 66- Conversion for high voltage in 0.01 KeV
					!	(1) = intercept; (2) = slope
	  integer*4	temp_conv(2)	! 74- Conversion for temperature in 0.01 deg.
	  integer*2	solution_ver	! 82- Solution version

	  byte		spare(44)	! 84-
	END STRUCTURE			!128- Total


	STRUCTURE	/HXT_Index_Rec/
	  integer*2	index_version /'4011'x/
					!  0- Index structure version					Ground Info
					!	AAAABBBB CCCCDDDD

	  byte		Pow_stat(2)	!  2- Power status 						W48 F32+1
					!	b7 = HXT1 (electronics for 00 to 31)
					!	b6 = HXT2 (electronics for 32 to 63)
					!	b5 = OS memory status 
					!	b4 = HXA on/off
					!	b3 = HXA cal
					!	b2 = HXT cal
					!	b1 = HV reduction fuction on/off (enable SAA HV on/off)
					!	     Usually HV is 900 V, reduced to ~0 V when on
					!	b0 - HV enable (double command safety)
					!	     HV cannot go on until this is enabled
	  byte		HV_stat(2)	!  4- HV Status on/off						W48 F32+17 (+29)
					!	b7 = HV0 on/off for sensor 00 to 07
					!	b6 = HV7 on/off for sensor 56 to 63
	  byte		HXT_Mon(2)	!  6- Memory content of OS-Memory				W49 F32+31
					!	b7 = HXT1 (electronics for 00 to 31)
					!	b6 = HXT2 (electronics for 32 to 63)
					!	b5 = HXA on/off
					!	b4 = Analog part of HXT-E on/off
					!	b3 = HV reduction fuction on/off (enable SAA HV on/off)
					!	     Usually HV is 900 V, reduced to ~0 V when on
					!	b2 = RBM flag (from DP)

	  byte		gain_control(64)!  8- Electronics gain for each sensor				W65
					!	Hopefully changed only once a month
	  byte		HV_control(8)	! 72- HV setting						W49 F32+9,11,13,15
					!	Hopefully changed only once a month

	  byte		HV_values(8)	! 80- High voltage values (HK monitor output)			W32 F19-F26 (even MF #s)
					!     (See quasi-static section for conversions)
	  byte		temps(21)	! 88- HXT Temperatures (HK monitor output)			W32 F61-F63 (even MF #s)
					!     (See quasi-static section for conversions)
					!								W32 F00-F17 (odd MF #s)
	  byte		dhk_data(64)	!109- DHK PC Data (low energies)				W64 F00-F63
					!     In PC mode:
					!	Integrated photon counts in low channel
					!     In PH (cal) mode:
					!	Sensor number (same value for 4 minor frames...)

	  integer*2	sum_L		!173- Summation of all 64 subcollimator
					!	counts (cnts/sec)
					!     Low energy (15-24.4 KeV)
	  integer*2	sum_M1		!175- Medium-1 energy (24.4-35.2 KeV) cnts/sec
	  integer*2	sum_M2		!177- Medium-2 energy (35.2-56.8 KeV) cnts/sec
	  integer*2	sum_H		!179- High energy (56.8-100 KeV) cnts/sec
	  integer*2	sigma_L		!181- Standard deviation of low energy channels
					!     of fan beam elements only.  Not corrected for
					!     integration period.
					!	Sensor #s: (octal)	00,01,04,05
					!				10,11,14,15
					!				60,61,64,65
					!				70,71,74,75
					!     For PH mode .... TODO 

	  byte		dataRecTypes	!183- What data follows (setting bits)				Derived
					!	b0 = PC data follows
					!	b1 = PH (cal) data follows
					!	Derived from (W51 F7 b0:1) - Output from DP
					!		00 = No Data (PC data in index only)  (=0)
					!		01 = PC data                          (=1)
					!		10 = PH data (CAL)                    (=2)
					!		11 = ??

	  byte		spare(8)	!184- Spare
	END STRUCTURE			!192- Total

	STRUCTURE	/HXT_PC_Data_Rec/
					!	hxt_pc(i,j,k)		i=energy band
					!				j=sensor #
					!				k=repetition #
	  byte		pc_data(4,64,4)	!   0- PC data
	END STRUCTURE			!1024- Total


	STRUCTURE	/HXT_PH_Data_Rec/
					!	hxt_ph(i,j)		i=energy channel
					!				j=sensor #
	  byte		ph_data(64,64)	!   0- PH data
	END STRUCTURE			!4096- Total


	STRUCTURE	/HXT_RoadMap_Rec/
                                        !     For a full description of the fields,
                                        !     look at the Index_Rec definition

	  integer*4	ByteSkip	! 00- Start byte of index rec

	  integer*4	time		! 04- Major frame time (millisec of day)
	  integer*2	day		! 08- Major frame day (since 1-Jan-79)
	  byte		Flare_Control	! 14- Flare flag control (active triggers) 
					!     Copied from GEN_INDEX (needed here to put
					!     into the observing log entry)
	  byte		Flare_Status	! 15- Flare flag status	

	  byte		DP_mode		! 10- DP Mode
	  byte		DP_rate		! 11- DP Rate

	  byte		Pow_stat	! 12- Power status 
	  byte		HV_stat		! 13- HV Status 

	  integer*2	sum_L		! 14- Summation of Low energy counts (cnts/sec)
	  integer*2	sum_M1		! 16- Medium-1 energy
	  integer*2	sum_M2		! 18- Medium-2 energy
	  integer*2	sum_H		! 20- High energy
	  integer*2	sigma_L		! 22- Standard deviation of low energy channels

	  byte		dataRecTypes	! 24- What data follows
					!TODO - Flag to show start of PH data ??

	  byte		spare(5)	! 25-
	END STRUCTURE			! 32

	STRUCTURE       /HXT_Version_Rec/
          integer*2     roadmap /'40F2'x/
                                        ! 00- The version number of the Roadmap
                                        !     This value is not contained in the
                                        !     roadmap structure to save space.  It is
                                        !     saved in the "Pointer Record"
	  integer*2	hxi_roadmap /'40F3'x/
					!   - The HXI data file roadmap version number

                                        !     This structure is not written to any files
          byte          spare(12)       !     (need for automatic conversion to IDL format)
	END STRUCTURE


	STRUCTURE	/HXI_Index_Rec/
	  integer*2	index_version /'4021'x/
					!  0- Index structure version					Ground Info
					!	AAAABBBB CCCCDDDD

					!    --------------- Selection of Data -----------------------
	  byte		chan		!   - Channel that was converted to an image
					!	0 = Low energy (15-24.4 KeV)
					!	1 = Medium-1 energy (24.4-35.2 KeV) cnts/sec
					!	2 = Medium-2 energy (35.2-56.8 KeV) cnts/sec
					!	3 = High energy (56.8-100 KeV) cnts/sec
	  real*4	cnts_p_cm2	!   - Counts per CM^2 for the selected channel (not per sec)
					!	16 coarsest collomators (fan beam)
	  integer*2	actim		!   - accumulation time in 0.1 sec units (cannot be less than 0.5 sec)
	  integer*2	interval	!   - end time minus start time (should equal "actim" if no data is missing)
					!     (0.1 sec units)
					!   - The time/day of the start time of the data is in the GEN structure

	  integer*4	bkg_time	!   - Time of start of background data used (millisec of day)
	  integer*2	bkg_day		!   - Days of start of background data used (days since 1-Jan-79)
					!	bkg_day = 0 means no background subtracted
					!	bkg_day = -1 means user defined background was used
	  integer*2	bkg_actim	!   - accumulation time in 0.1 sec units for background
					!	bkg_actim = 0 means no background subtracted
	  integer*2	bkg_interval	!   - end time minus start time (should equal "actim" if no data is missing)
					!     (0.1 sec units)

					!    --------------- Input Parameters to Synthesis Routine -----------------------

	  byte		grause(8)	!   - Grid assembly usage (set = used)
					!	(0) = coarsest spatial resolution (single pitch angle)
					!	      (top of grouse.1 file)
					!		b0 = largest position angle
					!		b7 = smallest position angle
					!			  1 1 1 1 1 1 1 1
					!			smallest     largest
					!	(7) = finest spatial resolution
	  real*4	x0		!   - FOV X Center position in HXT units of 126 arcsec
	  real*4	y0		!   - FOV Y Center position in HXT units of 126 arcsec
	  real*4	alpha		!   - Amplitude of phase correction factor
	  integer*2	iway		!   - Patter to use
					!		=0 for triangular mo. patterns
					!		=1 for sine wave patterns
	  byte		syserr_tech	!   - Technique used for handling "syserr"
					!		0 = ??
	  byte		he_mod_adj	!   - Model used for adjusting the high energy modulation pattern
					!		0 = ??
	  real*4	syserr		!   - systematic error term to be added to Poisson Uncertainty
	  real*4	gamma0		!   - initial value of iteration gain
	  integer*2	laminc		!   - initial value for lambda increment
	  real*4	chilim		!   - minimum value of chi^2 needed
	  real*4	area		!   - total area in cm^2 of scintillators

	  integer*2	resolution	!   - In milli arc seconds

					!    --------------- Results of Synthesis -----------------------

	  integer*2	lambda		!
	  integer*2	iteration	!
	  real*4	chi2		!
	  real*4	delta		!

	  real*4	max_bright	!   - Maximum brightness
	  integer*2	x_max		!   - Column of maximum (starting at 0)
	  integer*2	y_max		!   - Line of maximum (starting at 0)

	  integer*2	shape_sav(2)	!   - Size of image 
					!	(0) = number of columns (ie: 64)
					!	(1) = number of lines (ie: 64)

	  byte		spare(7)	!   - Spare
	END STRUCTURE			! 96- Total

	STRUCTURE	/HXI_RoadMap_Rec/
                                        !     For a full description of the fields,
                                        !     look at the Index_Rec definition

	  integer*4	ByteSkip	! 00- Start byte of index rec

	  integer*4	time		! 04- Major frame time (millisec of day)
	  integer*2	day		! 08- Major frame day (since 1-Jan-79)

	  byte		chan		! 10- Channel that was converted to an image
	  integer*2	actim		! 11- accumulation time in millisec (cannot be less than 0.5 sec)
	  real*4	cnts_p_cm2	! 13- Counts per CM^2 for the selected channel (not per sec)

	  integer*2	lambda		! 17-
	  integer*2	iteration	! 19
	  real*4	chi2		! 21
	  real*4	max_bright	! 25- Maximum brightness

	  byte		spare(3)	! 29-
	END STRUCTURE			! 32

	STRUCTURE	/HXI_QS_SCPara_Rec/
	  integer*2	entry_type /'4031'x/
					! 00- Structure/Entry type

	  integer*4	st_time		! 02- Start time (millisec of day) entries are valid
	  integer*2	st_day		! 06- Start day (since 1-Jan-79)
	  integer*4	en_time		! 08- End time (millisec of day)
	  integer*2	en_day		! 12- End day (since 1-Jan-79)

	  integer*2	sensor(64)	! 14- Sensor # (0-63)
					!	( 0-15 are fan beam elements)
					!	(16-63 are sine/cosine)
	  integer*2	spat_freq(64)	!   - Spatial frequency (1-8)
	  integer*2	pos_angle(64)	!   - Position angle in degrees (0,45,90,135,30,60,120,150)
	  character*64	id		!   - Identification
					!	1-4 = fan beam sub-element
					!	C   = cosine element
					!	S   = sine element
	  real*4	dc(64)		!   - DC offset of modulation pattern
	  real*4	amp(64)		!   - Amplitiude of modulation pattern
	  real*4	phase(64)	!   - Phase of modulation pattern
	  real*4	phase_corr(64)	!   - Phase correction factor of modulation pattern

	  character*10	para_filnam	!   - The parameter file name used to load the above parameters

	  byte		spare(40)	! 14- Spare
	END STRUCTURE			! 64- Total

	STRUCTURE	/HXI_QS_Bkg_Rec/
	  integer*2	entry_type /'4041'x/
					! 00- Structure/Entry type

	  integer*4	st_time		! 02- Start time (millisec of day) entries are valid
	  integer*2	st_day		! 06- Start day (since 1-Jan-79)
	  integer*4	en_time		! 08- End time (millisec of day)
	  integer*2	en_day		! 12- End day (since 1-Jan-79)

	  real*4	bkg(64,4)	! 14- The background counts used
					!	(i,j)
					!		(i) = sensor #
					!		(j) = channel
	  character*20	comments	!526-

	  byte		spare(46)	!546- Spare
	END STRUCTURE			! 64- Total




