//--base_raw2 header file
//--common definitions for reading in a raw2 file

// definitions -------------------------------------------
#define NLINE 512  		// max # char per each line
#define ND_MAX 3000  	// max # dives expected
#define NP_MAX 4000  	// max # of points in one dive
#define N_GPS    15     // #variables on a flash GPS line
#define MAX_PDAT 10		// max # columns in one Pdat line; includes DOX
#define MAX_EDAT 13 	// max # columns in one Edat line
#define N_ENG     35    // #variables in the flash engineering line
#define PGAIN 0.04; 	// SBE pressure gain
#define DTMIN 0.002   	// 0.002 day = 2.9 minutes: dt match for .satI w/flash
//default ADP definitions
#define MAX_ADP_H 11	// max columns for adp header line
#define MAX_ADP_LINE 42 // max #integers on one line of data
#define NADP_MAX 150 	// max # ADP ensembles expected per each dive
#define NBEAM 3   	// # of beams in the system
#define MAXCELL 5 	// max # of cells
#define BD0 4.0 	// default blanking distance


//--- structures --------------------------------------------------

//*** global declarations, used by some of the functions below
	extern int UxSrf[ ND_MAX ]; // CF_DIVE profile index->surf index array
	extern unsigned long UxTm1[ ND_MAX ], UxTm2[ ND_MAX ]; //CF_DIVE dive start, profile start times
	//extern int 		Pid, Dive_Set, Ncyc, Npro;
	//extern long 	Uxti0, Uxti1;
	extern int Pdat[ NP_MAX ][  MAX_PDAT ]; // One dive profile data
	extern int Edat[ NP_MAX ][  MAX_EDAT ]; // One dive engineering data
	extern int Eng [ ND_MAX ][  N_ENG    ]; // One eng packet per dive
	extern float WLat[ND_MAX], WLon[ND_MAX]; // waypoint lat & lon arrays
	extern float GPS[4][ ND_MAX][ N_GPS   ]; // all of the GPS info
	
	extern int K_adp; // output index: next open spot
	extern int Hadp [ MAX_ADP_H ]; //last read ADP info
	extern int Dadp [ NADP_MAX][ MAX_ADP_LINE ]; //integer inputs for one profile

//*** prototypes *****************************************************
void  init_global0     ( void );
void  init_pro_global  ( void );
int   get_dive_mark    ( FILE *fp );
int   get_dive         ( FILE *fp, int *npts, int *jEng );
int   store_flash_GPS  ( char s[] );
int   store_flash_eng  ( char s[] );
void  store_flash_Edat ( int j, char s[] );
void  store_flash_Pdat ( int j, char s[] );
void  store_flash_adp_h( char s[]  );
void  store_flash_adp  ( char s[]  );
int   store_flash_CF_DIVE (  char s[]  );
//*********************************************************************

//define indices for the GPS scan
//GPS[id][surf][k]: id=0,1.2,3 = usual dive phase, surf=surface#
#define GPS_KSRF  0 // surface #
#define GPS_VALID 1 // valid flag: 0=bad, 1=good
#define GPS_YEAR  2 // year
#define GPS_YDAY  3 // xx.xxxx year-day
#define GPS_LAT   4 // latitude
#define GPS_LON   5 // longitude
#define GPS_HDOP  6 // HDOP
#define GPS_ACQT  7 // acquire-time
#define GPS_NSAT  8 // # of satellites
#define GPS_SMIN  9 // min SNR
#define GPS_SAVG 10 // avg SNR
#define GPS_SMAX 11 // max SNR
#define GPS_HR   12 // UTC hr
#define GPS_MN   13 // UTC minutes
#define GPS_SEC  14 // UTC seconds

//define indices for Pdat
#define Pdat_KSRF  0 // surface #
#define Pdat_KCYC  1 // cycle #
#define Pdat_KPRO  2 // profile # 
#define Pdat_TM    3 // index to time counts
#define Pdat_PR    4 // index to pressure counts
#define Pdat_TEMP  5 // temperature
#define Pdat_SAL   6 // salinity
#define Pdat_OPT   7 // optical
#define Pdat_SBE   8 // SBE_ON if=1
#define Pdat_DOX   9 // Dissolved Oxygen, if available

//define indices for Edat
#define Edat_KSRF  0 // surface #
#define Edat_KCYC  1 // cycle # for profile within surfacing
#define Edat_KPRO  2 // profile #
#define Edat_HEAD  3 // compass heading
#define Edat_PITCH 4 // compass pitch
#define Edat_ROLL  5 // compass roll
#define Edat_ADPI  6 // pitch counts
#define Edat_ADRO  7 // roll counts
#define Edat_V14   8 // 14V battery
#define Edat_AMP   9 // pump current
#define Edat_OIL  10 // pump oil sensor
#define Edat_V07  11 // 7V battery
#define Edat_ALT  12 // altimeter
#define Edat_ERR  13 // error flags

//define indices for Eng = Engineering packet
#define Eng_ZMX  3 // index of max depth
#define Eng_ALT  5 // index to altimeter
#define Eng_AMP  7 // index to pump amps
#define Eng_PSURF 8// index to the surface pressure counts

//define indices for the ADP header info
// 0=surface#, 1=cycle#, 2=profile#
#define ADP_BD      3 // Blanking distance
#define ADP_ALPHA   4 // attenuation
#define ADP_BIN0    5 // center of 1st bin [m*10]
#define ADP_NCELL   6 // # of cells
#define ADP_CSIZE   7 // cell size [m]
#define ADP_PULSE   8 // pulse length [m]
#define ADP_SNR     9 // minimum snr
#define ADP_PSURF  10 // surface counts @ last surfacing

//define data ADP indices
#define DADP_PR     3 // pressure counts
#define DADP_HE     4 // heading [deg*10]
#define DADP_PI     5 // pitch ( deg = val*0.4; )
#define DADP_RO     6 // roll  ( deg = val*0.4; )
#define DADP_NO     7 // points to beam 1 noise
#define DADP_AMP   10 // points to first amplitude point