C+
C	NAME:
C		BSC_STRUCT
C	PURPOSE:
C		Define the following BSC specific database structures
C			* BSC_Index_Rec            
C			* BSC_Roadmap_Rec          
C			* FIT_BSC_Rec
C
C	CALLING SEQUENCE:
C		BSC_STRUCT
C	HISTORY:
C		written by Mons Morrison, R. Bentley, J. Mariska and D. Zarro, Fall 92
C       11-sep-93, JRL + DMZ, Added .valid_ans, .nstart and .nend fields (see **)
C	 2-Oct-93 (MDM) - Changed the FIT structure a fair amount
C	13-Oct-93 (MDM) - Changed the FIT field from Num_inter to Num_iter
C	 8-Nov-93 (MDM) - Changed comments
C	 3-Feb-94 (MDM) - Added .SPACECRAFT to .BSC structure
C			- Made a new FIT structure with .ION_MULT
C			- Archived FIT_2041_BSC_Rec to BSC_OLD_STRUCT.INC
C	 3-Feb-94 (MDM) - Added .DENSITY to .FIT
C	 8-Aug-94 (MDM) - Added .DISPC and .U_DISPC to .FIT
C
C-
C	---------------------------------------------------------------

	STRUCTURE	/BSC_Index_Rec/
	  integer*2	index_version /'2022'x/
					! 00- Index structure version
	  byte		spare1(2)	! 02 -Padding byte
	  byte		blockID		! 10- BCS Block ID						From BDA
					!      =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		! 11- Mode ID (Grouper Plan)					From BDA
					!	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		DP_Flags	! 12- DP Flags received by BCS					From BDA
					!	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	! 13- BCS Status						From BDA
					!	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		chan		! 14- channel number						User Input
					!	1 = Fe XXVI
					!	2 = Fe XXV
					!	3 = Ca XIX
					!	4 = S XV
	  byte		spare2		! 15 -Padding byte
	  integer*4	actim		! 16- Accumulation time in ms					User Input
	  integer*4	interval	! 20- End time - start time in ms 				Derived
					!     (matches "actim" if no missing data)
	  integer*4	cnt_thresh      ! 24- Count threshold used to control accumulation (millisec)	User Input
                                        !       0 = no threshold set (use actim)

	  byte		dgi		! 28- Data Gather Interval (125 msec units)			From BDA
	  byte		spare3		! 29 -Padding byte
	  integer*2	nBin		! 30- Number of bins for selected channel			Defined by ModeID
	  integer*2	nSpec		! 32- Number of spectra in accumulation				Derived


	  byte		spare4(2)	! 34 -Padding byte
	  real*4	total_cnts	! 36- Total counts in the selected channel for actim		Derived
	  real*4	max_cps		! 40- Maximum counts per second of limited counts from 		Derived
					!     dp_sync for the channel
	  byte		dp_sync_dpf	! 44- DP_SYNC data presence flag				Derived
					!	0 = did not check, unknown
					!	1 = full data over accumulation interval
					!	2 = partial data over accumulation interval
					!	3 = interpolated
					!	4 = derived by fitting
	  byte		spare5(3)	! 45 -Padding byte
	  integer*4	sc_pntg(3)	! 48- Average spacecraft pointing offset from Sun center? 	From PNT
					!     (copy of ADS value from PNT file, 0.1 arc sec per unit)
					!	(0) = E/W (W is positive?)
					!	(1) = N/S (N is positive)
					!	(2) = roll
	  real*4	sc_pntg_dev(3)	! 60- RMS deviation of above over the accumulation interval	Derived
	  byte		sc_pntg_dpf	! 72- Pointing data availability flag				Derived
					!	0 = did not check, unknown
					!	1 = full data over accumulation interval
					!	2 = partial data over accumulation interval
					!	3 = ?
	  byte		spare6		! 73 -Padding byte
	  integer*2	offset(2)	! 74- Source location in heliocentric coordinates 		User Input
					!     (arc second units)
					!	(0) = E/W (W is positive?)
					!	(1) = N/S (N is positive)
	  byte 		offset_dpf	! 78- Offset data presence flag					User Input
					!	0 = none
					!	1 = SXT PFI
					!	2 = SCT FFI manual pointing
					!	3 = H alpha manual pointing
					!	4 = HXI
					!	5 = ...

	  byte		despike_ans	! 79-								User Input	
	  byte		deadtime_ans	! 80- deadtime correction answer				User Input
					!	0 = no correction done
					!	1 = using ?? routine
					!	2 = ...
	  byte		curve_ans	! 81-								User Input	
	  byte		linearity_ans	! 82-								User Input	
	  byte		waveDisp_ans	! 83-								User Input	
	  byte		narrowLine_ans	! 84-								User Input	
	  byte		pntg_ans	! 85-								User Input	
	  byte		offset_ans	! 86-								User Input	
	  byte		rebin_ans	! 87-								User Input	
	  byte		physUnits_ans	! 88-								User Input	
					!
					!
	  byte		valid_ans	! 89 -1 means valid bins have been extracted. 0 is raw data     User Input
	  byte		nstart		! 90 -First Valid Bin in raw data      (if changed, then update FIT_RANGE)
	  byte		nend		! 91 -Last Valid Bin in raw data                                       
C	  byte		spare7(3)	! 89 -Padding byte							
					!
	  integer*2	length		! 92- The number of points in the spectra.  It might not
					!     match the "nbin" field for the cases where the spectra
					!     is "stretched" and new bins are created
	  integer*2	dataRecTypes	! 94- Type of data the is included in the data portion
					!	b0 = counts (spectra)				.COUNTS
					!	b1 = bin address				.BIN
					!	b2 = uncertainty of counts (units?)		.ERROR
					!	b3 = Unused (shuffled .fit to .flux_fit)	.JUNK
					!	b4 = wavelength array				.WAVE (start values for BIN)
					!	b5 = flux calibrated data			.FLUX
					!	b6 = Actual wavelength array (from FIT_BSC)	.WAVE_FIT
					!	b7 = fitted spectra				.FLUX_FIT
					!	b8 = fitted spectrum for a secondary component	.FLUX_FIT2
                                        !
          byte          calfil_vers     !102- version number of BCS CALFIL used to correct spectra
	  byte		spare7(1)	!103 -Padding byte							

          character*3   spacecraft      !104- Identification of the spacecraft from
					!	which the data originated
					!	Valid Options are:
					!		SMM, P78, HIN, YOH (Yohkoh, Solar-A),
					!		Gnd (Ground testing)
	  BYTE		spare(17)	!107- Spare bytes
	END STRUCTURE			!128- Total

	integer*4	nBSC_Index_Rec
	parameter	(nBSC_Index_Rec=48)

	STRUCTURE	/FIT_BSC_Rec/
	  integer*2	index_version /'2042'x/

	  integer*2	z		!  2- Atomic Number
	  character*16	elem		!  4- Element (string)
	  byte		chan		! 20- channel number	
					!	1 = Fe XXVI
					!	2 = Fe XXV
					!	3 = Ca XIX
					!	4 = S XV
          character*3   spacecraft      ! 21- Identification of the spacecraft from
					!	which the data originated
					!	Valid Options are:
					!		SMM, P78, HIN, YOH (Yohkoh, Solar-A),
					!		Gnd (Ground testing)

					!-------------------- Fitting Specific parameters --------------------

	  integer*2	Fit_level	! 24- Level of Fitting (0=No fit, 1=First guess)
	  integer*2	Fit_attempt	! 26- Next highest level attempted (if fit_attempt gt fit_level, fitting failed)
	  real*4	Chi2		! 28- Total Chi^2
	  integer*2	NFree		! 32- Number of degrees of freedom
	  integer*2	Nparams		! 34- Number of parameters allowed to vary
	  integer*2	Num_iter	! 36- Number of iterations
	  integer*2	Ncomp_req /1/	! 38- Number of components requested in fit (1 or 2)
	  integer*2	Ncomp_fit 	! 40- Number of components actually fit (1 or 2)
	  integer*2	Fit_model	! 42- Fit model (0=no contraints or links)
          integer*2	Fit_flags(10)   ! 44- Fit flags (e.g. fit_flag(i) = -1 ---> i'th parameter was not varied 
                                        !                                =  0 ---> i'th parameter was fit
                                        !                                =  j ---> i'th parameter was linked to j'th parameter  
          integer*2	Fit_range(2,3)/-1/ ! 64- Fit range = indicies of wavelength ranges used in fit and chi2 calculation
                                        !    (up to 3 ranges for each of 2 components)
	  byte		spare1(4)	! 76- Padding
	 
					!-------------------- Fitting parameters --------------------

	  real*4	Te6		! 80- (1)  Electron Temperature main component (MK)
	  real*4	Td6		! 84- (2)  Doppler  Temperature main component (MK)
	  real*4	EM50		! 88- (3)  Emission measure of main component  (cm-3)
	  real*4	wshift		! 92- (4)  Source position wavelength shift (Ang)
	  real*4	cnorm /1/	! 96- (5)  Continuum normalization factor 
	  real*4	Te6_s		!100- (6)  Electron Temperature of 2nd component (MK)
	  real*4	Td6_s		!104- (7)  Doppler  Temperature of 2nd component (MK)
	  real*4	EM50_s		!108- (8)  Emission measure of 2nd component (cm-3)
	  real*4	Vel		!112- (9)  Velocity 2nd relative to 1st (km/s, negative is blueshift)
	  real*4	spare2		!116-(10) Reserved for future use

					!-------------------- Uncertainties in Fitting parameters --------------------

	  real*4	u_Te6		!120- (1)  Electron Temperature main component (MK)
	  real*4	u_Td6		!124- (2)  Doppler  Temperature main component (MK)
	  real*4	u_EM50		!128- (3)  Emission measure of main component (cm-3)
	  real*4	u_wshift	!132- (4)  Source position wavelength shift (Ang)
	  real*4	u_cnorm /1/	!136- (5)  Continuum normalization factor 
	  real*4	u_Te6_s		!140- (6)  Electron Temperature of 2nd component (MK)
	  real*4	u_Td6_s		!144- (7)  Doppler  Temperature of 2nd component (MK)
	  real*4	u_EM50_s	!148- (8)  Emission measure of 2nd component (cm-3)
	  real*4	u_Vel		!152- (9)  Velocity 2nd relative to 1st (km/s, negative is blue)
	  real*4	spare3		!156-(10) Reserved for future use

					!-------------------- Spectral Calculation parameters --------------------

	  real*4	Ashift		!160- Bulk wavelength shift of spectrum in atomic calculation (A)
	  real*4	elem_num	!164- Number of Abundance table used
	  real*4	abun		!168- Abundance used [N(Z)/N(H)]
	  character*32	abun_info	!172- Text describing abundance
	  real*4	Utdoppw		!204- User supplied Gaussian broadening (A)
	  byte  	ioncal		!208- Number of ionization balance calculation
	  byte  	atocal		!209- Number of atomic parameter file
	  byte		spare4(2)	!210- Pad to end on 4 byte boundary
	  character*32	ion_info	!212- Text describing ionization balance calculation
	  character*20	ion_file	!244- File containing ionization balance calculation
	  character*60	ato_info	!264- Text describing atomic data calculation
	  character*20	ato_file	!324- File containing atomic data parameters
	  byte		nocont		!344- 1 if No continuum calculation
	  byte		noline		!345- 1 if No line calculation

	  byte		spare5(2)	!346- Pad to end on 4 byte boundary
	  real*4	ion_mult(10) /1/!348- Multiplier factor applied to the ionization balance
					!	ion_mult(0) applies to H+
					!	        (1) applies to H
					!		(2) to He
					!		(3) to Li, etc.
					!	(i.e., the subscript = number of electrons of the ion)
	  real*4	density		!388- Density used to compute the theory spectrum
					!     Units are cm-3

	  real*4	dispc		!392- Multiplicative correction factor
                                        !     applied to nominal wavelength 
                                        !     dispersion in BCS detector 
                                        !     CAL FILE
	  real*4	u_dispc		!396- Uncertainty on DISPC
	END STRUCTURE			!400- Total

	STRUCTURE	/BSC_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- Start time (millisec of day)
	  integer*2	day		! 08- Start day (since 1-jan-1979)
	  byte		chan		! 10- Channel number
	  byte		spare1		! 11 -Padding byte
	  integer*4	actim		! 12-	Accumulation time in ms
	  integer*2	nBin		! 16- Number of bins for selected channel
					!
	  byte		spare2(2)	! 18 -Padding byte
	  real*4	total_cnts	! 20- Total counts in the selected channel for actim
	  real*4	max_cps		! 24- Maximum counts per second of limited counts from dp_sync for
					!	the channel
	  byte		DP_Flags	! 28- DP Flags received by BCS
	  byte		spare3(3)	! 29 -Padding byte

	  integer*2	length		! 32- The number of points in the spectra. 
	  integer*2	dataRecTypes	! 34- Type of data the is included in the data portion
	  BYTE		spare(12)	! 36- Spare bytes
	END STRUCTURE			! 48- Total


	STRUCTURE       /BSC_Version_Rec/
          integer*2     roadmap /'20E1'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"
	  integer*2	data /'20E1'x/	!
                                        !     This structure is not written to any files
          byte          spare(12)       !     (need for automatic conversion to IDL format)
	END STRUCTURE

