/**---------------------------------------------------------------------------
 ** 
 ** adcp.h -- Main ADCP NBR definitions
 ** 
 ** Author          : Pierre Jaccard
 ** Created On      : 1999/07/16 17:50:44
 ** Last Modified By: Pierre Jaccard
 ** Last Modified On: 1999/07/16 21:29:15
 ** Update Count    : 2
 ** Directory       : /home/pego/pcd1/codas3c/gfi/src/libs/nbr/
 ** Version         : 0.0
 ** Status          : Unknown
 ** ---------------------------------------------------------------------- ** 
 ** DESCRIPTION: 
 ** 
 **    This file provides main definitions and macros for reading and
 **    processing ADCP NBR files.
 ** 
 ** ---------------------------------------------------------------------- ** 
 ** REVISIONS: 
 ** ---------------------------------------------------------------------- ** 
 ** CHANGES: 
 **------------------------------------------------------------------------**/

#ifndef gfilib_nbr_adcp_already_included
#define gfilib_nbr_adcp_already_included

/* 
   Sizes of NBR buffers
*/
#define NBR_LEADER_FIXED_SIZE 63					/* Size of leader buffer	 */
#define NBR_HEADER_FIXED_SIZE 14					/* Size of header buffer	 */
#define NBR_ENSEMBLE_SIZE_MAX 5000        /* Max size required for
																						 an ensemble             */

#define MAX_BINS 128											/* Max number of bins			 */

/*
  These bits are used to signal if the associated buffer is present in an NBR
  ensemble 
*/
#define HEADER_PRESENT					 BIT0
#define LEADER_PRESENT					 BIT1
#define VELOCITY_PRESENT				 BIT2
#define SPECTRAL_WIDTH_PRESENT	 BIT3
#define ECHO_INTENSITY_PRESENT	 BIT4
#define PERCENT_GOOD_PRESENT		 BIT5
#define STATUS_PRESENT					 BIT6
#define ENSEMBLE_PRESENT				 BIT7

/*
  This structure is used to store ADCP RTC time
*/
typedef struct
{
  UBYTE month;
  UBYTE day;
  UBYTE hour;
  UBYTE minute;
  UBYTE second;
} NBR_RTC_TYPE;

/* 
	 This structure is used to store ADCP time between pings.
*/
typedef struct
{
  UBYTE minutes;
  UBYTE seconds;
  UBYTE hundredths;
} NBR_TBP_TYPE;

/*
  Header data groups all buffer sizes
*/
typedef struct
{
  USHORT output_buffer_size;
  USHORT leader_buffer_size;
  USHORT velocity_buffer_size;
  USHORT spectral_width_buffer_size;
  USHORT echo_intensity_buffer_size;
  USHORT percent_good_buffer_size;
  USHORT status_buffer_size;
} NBR_HEADER_TYPE;

/*
  Structure for leader data
*/
typedef struct
{
  NBR_RTC_TYPE ensemble_start_time;
  NBR_TBP_TYPE time_between_pings;
  USHORT pings_per_ensemble;
  UBYTE number_of_bins;
  UBYTE raw_bin_length;
  UBYTE xmt_pulse_length;
  UBYTE blank_after_xmt;
  UBYTE delay_after_blank;
  USHORT ensemble_number;
  UBYTE bit_status;
  UBYTE adcp_config;
  UBYTE signal_noise_threshold;
  UBYTE percent_good_threshold;
  SHORT pitch_tilt;
  SHORT roll_tilt;
  USHORT heading;
  USHORT adcp_temp;
  UBYTE high_voltage_in;
  UBYTE xmt_current;
  UBYTE low_voltage_in;
  UBYTE raw_ctd_conductivity_count[3];
  UBYTE raw_ctd_temperature_count[3];
  UBYTE raw_ctd_depth_count[3];
  UBYTE raw_bottom_track_velocities[6];
  USHORT bottom_track_range[4];
  UBYTE pitch_std_dev;
  UBYTE roll_std_dev;
  UBYTE heading_std_dev;
  UBYTE raw_ctd_measurement_interval[3];
  UBYTE raw_bottom_track_percent_good[2];   
} NBR_LEADER_TYPE;

/* 
	 Structure for ensemble data is composed of raw ADCP data at its beginning,
	 followed by different additionnal variables, such as converted data and
	 buffer presence føaggs.
*/
typedef struct
{
  /* Raw data from file */
  NBR_HEADER_TYPE header;
  NBR_LEADER_TYPE leader;
  UBYTE  raw_velocity[MAX_BINS][6];
	UBYTE  spectral_width[MAX_BINS][4];
	UBYTE  echo_intensity[MAX_BINS][4];
	UBYTE  percent_good[MAX_BINS][4];
	UBYTE  raw_status[MAX_BINS][2];
	USHORT checksum;
         
  /* Converted raw data */
  UBYTE bin_length;
  SHORT bottom_track_velocity[4];
  UBYTE bottom_track_percent_good[4];
	ULONG ctd_conductivity_count;
	ULONG ctd_temperature_count;
	ULONG ctd_depth_count;
	ULONG ctd_measurement_interval;
  SHORT velocity[MAX_BINS][4];
	UBYTE status[MAX_BINS][4];

  /* Check flags */
	ULONG presence_bits;

} NBR_ENSEMBLE_TYPE;

/* 
	 The next structure is for transducer misalignment. Angles values should be
	 entered so that
   
	 <real angle> + <misalignment> = <adcp angle>
*/
typedef struct
{
	double heading;
	double pitch;
	double roll;
} TRANSDUCER_MISALIGNMENT_TYPE;

#endif /* gfilib_nbr_adcp_already_included */
