C+
C	NAME:
C		BCS_STRUCT
C	PURPOSE:
C		Define the following BCS specific database structures
C			* BCS_QS_Instr_Rec          
C			* BCS_QS_ModeInit_Rec          
C			* BCS_QS_Conv_Rec          
C			* BCS_QS_Group_Rec         
C			* BCS_Index_Rec            
C			* BCS_DP_Sync_Rec          
C			* BCS_DPs_Head_Rec         
C			* BCS_Roadmap_Rec          
C
C	CALLING SEQUENCE:
C		BCS_STRUCT
C	HISTORY:
C		written by Mons Morrison, Fall 90.
C
C-
C	---------------------------------------------------------------

	integer*4	BCS_BuffSiz
	parameter	(BCS_BuffSiz = 4096*2)		!BCS-OUT = 4096 per major frame * factor of 2
	integer*4	MaxBCS_DPSync
	parameter	(MaxBCS_DPSync = 1280)


	STRUCTURE	/BCS_QS_Instr_Rec/
	  integer*2	entry_type /'2011'x/
					! 00- Structure/Entry type

	  integer*4	st_time		! 02- Start time (millisec of day) of valid data
	  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)

					!     _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
	  byte		SCAval(2,4)	! 14- Upper and lower channel SCA settings			W49 F32n+0,2,4,6,8,
					!	(Channel, 0=lower)						10,12,14
					!	(channel, 1=upper)
	  byte		hv_control	! 22- HV control (commanded)					W49 F32n+16
					!	b0:2 = trim for HVA
					!	b4:6 = trim for HVB
					!	NOTE: Changes in one orbit during a cal
	  BYTE		stim_control	! 24- Stimulus on/off						W49 F32n+26
					!	b0   = Detector A internal stim generator (set=off)
					!	b1   = Detector A stim source (set=internal)
					!	b2   = Detector A multiplexor (set=disable)
					!	b4   = Detector B internal stim generator (set=off)
					!	b5   = Detector B stim source (set=internal)
					!	b6   = Detector B multiplexor (set=disable)
					!     _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
	  byte		Fe26_thresh	! xx- Fe XXVI threshold						W66 F28 SF4n+2
					!	value*16 = actual threshold counts
	  byte		chan_mfd	! xx- Channels selected and min flare duration			W66 F28 SF4n+3
					!	LSB = b0
					!	b5:7 = SAA Algorithm channel
					!	b4:5 = Flare algorithm channel
					!	b0:3 = Mininum flare duration
	  byte		SAA_Thresh	! xx- SAA Threshold						W66 F29 SF4n+3
					!	value*16 = actual threshold counts
	  byte		Flr_RiseThresh	! xx- Flare rise threshold					W66 F30 SF4n+3
					!	value*16 = actual threshold counts
	  byte		Flr_DecayThresh	! xx- Flare decay threshold					W66 F31 SF4n+3
					!	value*16 = actual threshold counts
	  byte		Flr_OptionID	! xx- Flare Option ID						W66 F63 SF4n+3
					!     _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

	  BYTE		sensitivity(4)	! 26- Det. Sensitivity (Nominal Val= 200)			Ground Defined
	  INTEGER*4	posGain(4)	! 30- Position Gain for det (Angstrom/Bin)			Ground Defined
	  INTEGER*4	posOffset(4)	! 46- Position Offsets. (micro-Angstrom)			Ground Defined
					!	NOTE that the Gain and offset are the 
					!	slope and intercept of the line giving 
					!	the conversion between bin numbers and 
					!	wavelength.

	  integer*2	bcs2dp_ver	! 62- Algorithm and parameters used to convert			Ground Defined
					!	between BCS timer and DP timer
	  byte		spare(12)	! 64-
	END STRUCTURE			! 80- Total 

	integer*4	nBCS_QS_Instr_Rec
	parameter	(nBCS_QS_Instr_Rec=80)

	STRUCTURE	/BCS_QS_ModeInit_REC/
	  integer*2	entry_type /'2021'x/
					! 00- Structure/Entry type

	  byte		SequenceDef(15)	! 02- Definition of current sequence				Mode Block +4:18
					!	 (0) = Sequence ID
					!	 (1) = Mode A Grouper List ID
	  byte		Flr_Option(6)	! 17- Definition of flare option being used			Mode Block +19:24
	  byte		GFlr_SeqID	! 23- Great Flare sequence ID					Mode Block +25
	  byte		Fe26_Thresh	! 24- Fe XXVI Threshold						Mode Block +26
          byte          Fe26_SeqID      ! 25- Fe XXVI Sequence ID                                       Mode Block +27
          byte          Fe26_FlareOpt   ! 26- Fe XXVI Flare Option                                      Mode Block +28

	  byte		spare(5)	! 27- Spare
	END STRUCTURE			! 32- Total

        integer*4       nBCS_QS_ModeInit_Rec
        parameter       (nBCS_QS_ModeInit_Rec=32)

	STRUCTURE	/BCS_QS_Conv_Rec/
	  integer*2	entry_type /'2031'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	hv_conv(2)	! 14- Conversion for high voltage in 0.01 KeV
					!	(0) = intercept; (1) = slope
					!	NOT IMPLEMENTED AS OF 25-Mar-92]
	  integer*4	temp_conv(2)	! 22- Conversion for temperature in 0.01 deg.
					!	NOT IMPLEMENTED AS OF 25-Mar-92]

	  integer*2	solution_ver	! 30- Solution version
					!	NOT IMPLEMENTED AS OF 25-Mar-92]

	  byte		spare(32)	! 32-
	END STRUCTURE			! 64- Total

	integer*4	nBCS_QS_Conv_Rec
	parameter	(nBCS_QS_Conv_Rec=64)

	STRUCTURE	/BCS_QS_Group_Rec/
	  integer*2	entry_type /'2041'x/
					! 00- Structure/Entry type

					!   - No starting and ending times are needed for the
					!     grouper plan.
	  integer*4	time		! 02- Creation time in msod
	  integer*2	day		! 06- Creation date in days since 1-Jan-1979

	  integer*2	length		! 08- Total No of bytes of data created by the plan
	  integer*2	ModeID		! 10- The modeID that is described
	  byte		ngrp(4)		! 12- Number of groups for each channel
	  integer*2	groups(10,4)	! 16- The Grouper plan for each channel
					!	groups(*,ichan) = [nout1,nbin1, nout2,nbin2, nout3,nbin3, ...]
					!               where ichan is then channel in question
					!                       nout1 is the number of output values
					!                       nbin1 is the number of raw input values binned
	  byte		spare(32)	! 96- Spare
	END STRUCTURE			!128- Total

	integer*4	nBCS_QS_Group_Rec
	parameter	(nBCS_QS_Group_Rec=128)


	STRUCTURE	/BCS_Index_Rec/
	  integer*2	index_version /'2011'x/
					! 00- Index structure version

	  byte		dp_time_out(4)	! 02- DP time (timer1,2,3 and FI) for when
					!     the data is read out
					!     Use this time to check the state of the
					!     Spacecraft during readout - see 
					!     BCS_DP_Sync_Rec structure

					!     _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
	  BYTE		blockID		! 06- BCS Block ID						Derived
					!      =0: Normal Queue Data Block
					!      =1: Fast Queue Data Block
					!      =2: Micro Dump Block (fixed extraction)
					!	   Reformatter forces this mode whenever the
					!	   CPU is disabled
					!      =3: Cal Data Block (fixed extraction)
					!      =4: Queue data where the modeID in the
					!	   header is not recognized.
					!      =5: Normal or fast queue data which have fill
					!	   data (garabage).  Avoid this value to avoid
					!	   these datasets when making light curves.

	  BYTE		ModeID		! 09- Mode ID (Grouper Plan)					Mode Header(8)
					!	For "Normal" and "Fast" queue data
					!	(BlockID = 0 or 1) this value is the
					!	ModeID used in conjunction with the
					!	grouper plan.
					!
					!	If the mode ID is not recognized, then
					!	it is set to 255, and the mode header
					!	is put out with the beginning of the 
					!	data.
					!
					!	For "Cal Mode" (BlockID = 3)
					!	this holds the channel number as
					!	derived from PHA_CONTROL with a
					!	1.5 major frame delay
					!		b4:7 = first 256 bytes
					!		b0:3 = last 256 bytes
					!	Value = 1,2,3,4
					!	Value = 0 if unknown (data dropouts)
	  BYTE		ModeRepNum	! 10- Mode Repeat Number					Mode Header(6)
	  BYTE		ControlTally	! 11- Control Byte Tally					Mode Header(7)
					!     
	  BYTE		ControlByte	! 12- Control Byte						Mode Header(12)

	  BYTE		dgi		! 13- Data Gather Interval (125 msec units)			Mode Header(9)
					!	For "Cal Mode" (BlockID = 3)
					!	this value comes from					W49 F22
	  INTEGER*2	nSampPChan(4)	! 14- Number of data samples per channel			(From Grouper Plan)

	  INTEGER*2	total_cnts(4)	! 22- Total counts in each channel for the mode			Derived
					!     Saved counts have been divided by 10 to
					!     to avoid overflow problems

	  BYTE		DP_Flags	! 30- DP Flags received by BCS					Mode Header(4)
					!	b0	= Radiation Belt monitor (set = yes)
					!	b1,2	= 0,0: No flare
					!		= 1,0: Normal Flare
					!		= 1,1: Great Flare
					!		= 0,1: BCS MEM Mode
					!	b3,4	= 0,0: Low (1 kps)
					!		= 1,0: Med (4 kps)
					!		= 0,1: Hi (32 kps)
					!		= 1,1: Hi (32 kps)
					!	b5	= BCS-OUT after flare (set = enable)
					!	b6	= BCS-OUT after night (set = enable)
					!	b7	= Currently BCS-OUT mode 
	  BYTE		BCS_Status	! 31- BCS Status						Mode Header(5)
					!	b0 = SAA Threshold exceeded (set = yes)
					!	b1 = Flare threshold exceeded (set = yes)
					!	b2 = HVU's turned off by BVS SAA algorithm
					!	b3 = Fe XXVI thershold exceeded
					!	b4 = BCS is in night state
					!	b5 = BCS is in SAA state
					!	b6 = Status of data in queue (set = hi)
					!	b7 = Status of BCS flare flag (set = hi)

	  byte		MissBasicData	! 32- Flag to mark if the DP major frames			Derived
					!     for the period when the data was taken
					!     were telemetered down (set = got the data)
					!	(ie: got the basic part data for
					!	the period when the data was taken)
	  byte		MissModeID	! 33- Missing the beginning of the data which			Derived
					!     has the mode ID so all information is
					!     guessed.

	  INTEGER*2	length		! 35- Total No of bytes of data created by the plan
					!     This is the array length of the output vector
					!     which holds all of the channels.  This is the
					!     true length, where INDEX.GEN.NDATABYTES is the
					!     number of bytes written to the disk, which could
					!     have padded zeros.
	  BYTE		spare(14)	! 34- Spare bytes
	END STRUCTURE			! 48- Total

	integer*4	nBCS_Index_Rec
	parameter	(nBCS_Index_Rec=48)


	STRUCTURE	/BCS_DP_Sync_Rec/
	  integer*2	index_version /'2022'x/
					! 00- Index structure version

	  INTEGER*4	time		! 02- Time (ms of day) of major frame during readout
	  INTEGER*2	day		! 06- Day since 1-Jan-79 or major frame during readout

	  byte		dp_time(4)	! 08- DP time (timer1,2,3 and FI) for when
					!     the data is read out
					!     (see Gen_Index for an explanation of the values)
	  byte		DP_mode		! 12- DP Mode during the readout 
					!     (see Gen_Index for an explanation of the values)
	  byte		DP_rate		! 13- DP Rate during readout 
					!     (see Gen_Index for an explanation of the values)
	  byte		Flare_Control	! 14- Flare flag control during readout 
					!     (see Gen_Index for an explanation of the values)
	  byte		Flare_Status(4)	! 15- Flare flag status during readout 
					!     (see Gen_Index for an explanation of the values)
          byte          RBM_Status      ! 19- Radiation Belt Montitor Status
					!     (see Gen_Index for an explanation of the values)
          byte          Telemetry_mode  ! 20- Telemetry mode                   
					!     (see Gen_Index for an explanation of the values)
          byte          cal_status      ! 21- CAL status                       
					!     (see Gen_Index for an explanation of the values)
 
					!     _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

	  INTEGER*2	All_Cnts(4,2)	! 22- All counts for the 4 channels				W66 F00/01,F06/07,...
					!								W66 F32/33,F38/39,...
					!     Units = counts per "Acc_Interval" (see below)
	  INTEGER*2	Lim_Cnts(4,2)	! 38- Limited for the 4 channels				W66 F02/03,F08/09
					!								W66 F34/35,F40/41,...
					!     Units = counts per "Acc_Interval" (see below)
	  INTEGER*2	Acc_Cnts(4,2)	! 54- Accepted for the 4 channels				W66 F04/05,F10/11
					!								W66 F36/37,F42/43,...
					!   NOTE: For All_Cnts, Lim_Cnts, and Acc_cnts
					!	the following applies
					!     Units = counts per "Acc_Interval" (see below)
					!	Cnts(n,m) 	n = channel
					!			m = 2 per major frame
					!	The onboard counter is an unsigned 16-bit counter
					!	The reformatted data is saved as a signed 16-bit value
					!	If the value is negative, then 65536 (which is 2^16)
					!	needs to be added to the value.
	  integer*2	Acc_interval(2)	! 70- Accumulation interval (sec)				Derived
					!     This value is only relevant for the differences
					!     made to the PREVIOUS major frame for all_cnts(*,0)
					!     Since there are two values dumped each major frame, 
					!     the delta within the single major frame all_cnts(*,1)
					!     is defined by the DP_RATE for that major frame.
					!	Valid values are:
					!		0 = Raw number (not counts/sec)
					!		    Implies dropout for previous major frame
					!		8 sec = 1/2 * 16 sec (med rate)
					!		1 sec = 1/2 * 2 sec (high rate)
					!		? sec = transition high to med- TODO
					!		? sec = transition med to high - TODO
					!     _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

	  byte		pha_counts(8)	! 74- PHA Data							W66 F24,25,26,27
					!								    F56,57,58,59
	  BYTE		PHA_Control(2)	! 82- PHA Control						W49 F32n+18
					!     _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
	  BYTE		SpecStatus(2)	! 84- Spectrometer status					W112 F32n+3
					!	b0 = Calibibration-B (set=enabled)
					!	b1 = HVB logical flag (set=enabled)
					!	b2 = HVB power (set=on)
					!	b3 = Spectrometer B (set=on)
					!	b4 = Calibibration-A (set=enabled)
					!	b5 = HVA logical flag (set=enabled)
					!	b6 = HVA power (set=on)
					!	b7 = Spectrometer A (set=on)
	  byte		CommandStat(2)	! 86- Command Status						W112 F32n+4
					!	b0 = Command decode (set=disabled)
					!	b1 = Program address set (set=disabled)
					!	b2 = Program load (set=disabled)
					!	b3 = CPU processor (set=disabled)
					!	b4 = Low RAM (set=enable)
					!	b5 = Watchdog Timer (set=disabled)
					!	b6 = Block Command (BC) (set=enable)
					!	b7 = Digital Electronics (set=on)

	  byte		cpu(4,2)	! 88- Microprocessor information/diagnostics			W66 F28,29,30,31
					!								    F60,61,62,63
					!     Has the clock value to tie the DP clock
					!     to the BCS clock.

					!     _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
	  BYTE		HV_mon(2)	! 96- HV monitor voltage (0-255)				W32 F32,33 SF2n
					!	SF2n ==> changes every 2 MF!!?!?!
					!     (See quasi-static section for conversions)
	  byte		crytemp(2)	! 98- Crystal Bank Temperatures (milli-Celsius)			W32 F31,32 SF2n+1
					!     (See quasi-static section for conversions)
	  BYTE		Elec_Temp	!100- Electronics temperature					W32 F33    SF2n+1
					!     (See quasi-static section for conversions)
	  byte		spare(11)	!101
	END STRUCTURE			!112- Total

	integer*4	nBCS_DP_Sync_Rec
	parameter	(nBCS_DP_Sync_Rec=112)


	STRUCTURE	/BCS_DPs_Head_Rec/
	  integer*2	index_version /'2031'x/
					! 00- Index structure version

	  INTEGER*2	nEntries	!  2- Number of BCS_DP_Sync_Rec to follow

	  byte		spare(12)	!  4- Spares
	END STRUCTURE			! 16- Total

	integer*4	nBCS_DPs_Head_Rec
	parameter	(nBCS_DPs_Head_Rec=16)


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

	  integer*4	ByteSkip	! 00- Offset in bytes from the beginning of
					!     of the data file for the beginning
					!     of the data set index structure.
	
	  integer*4	time		! 04- Time of data (millisec of day)
	  integer*2	day		! 08- Day of data (since 1-Jan-79)

	  BYTE		blockID		! 10- BCS Block ID						Derived
	  BYTE		seqID		! 11- Observation Sequence ID
	  BYTE		ModeID		! 12- Mode ID (Grouper Plan)
	  BYTE		moderepnum	! 13- Mode Repeat Number
	  BYTE		dgi		! 14- Data Gather Interval (125 msec units)
	  BYTE		DP_Flags	! 15- DP Flags received by BCS					(From Mode Header)
	  BYTE		BCS_Status	! 16- BCS Status						(From Mode Header)

	  INTEGER*2	total_cnts(4)	! 17- Total counts in each channel for the mode

	  INTEGER*2	length		! 25- Total No of bytes of data created by the plan
	  BYTE		ControlTally	! 27- Control Byte Tally

	  byte		spare(4)	! 28- Spares
	END STRUCTURE			! 32- Total

	integer*4	nBCS_Roadmap_Rec
	parameter	(nBCS_Roadmap_Rec=32)

	STRUCTURE       /BCS_Version_Rec/
          integer*2     roadmap /'20F1'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 "File Header Record"

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

