/**---------------------------------------------------------------------------
 ** 
 ** fix_nbr.h -- 
 ** 
 ** Author          : Pierre Jaccard
 ** Created On      : 1999/07/30 19:36:06
 ** Last Modified By: Pierre Jaccard
 ** Last Modified On: 1999/07/30 21:08:53
 ** Update Count    : 10
 ** Directory       : /home/pego/pcd1/codas3c/gfi/src/apps/nbr/
 ** Version         : 0.0
 ** Status          : Unknown
 ** ---------------------------------------------------------------------- ** 
 ** DESCRIPTION: 
 ** 
 **    Undocumented.
 ** 
 ** ---------------------------------------------------------------------- ** 
 ** REVISIONS: 
 ** ---------------------------------------------------------------------- ** 
 ** CHANGES: 
 **------------------------------------------------------------------------**/

/* ##################################################################
	This programme has been tested as follows:

	   +Byte by byte comparison of non-fixed with fixed raw files.

		 +Reading fixed files with "LISTADCP" or "TRANSECT", or with [[view_nbr]]
		  does work, although the checksum is not always accepted by RDI's
			software. 

	################################################################## */

#include "geninc.h"
#include "ioserv.h"
#include "dbsource.h"
#include "use_db.h"
#include "gfimisc.h"
#include "gfinbr.h"
#include "gfinav.h"

/* ##################################################################
	 -Parameters:
	 ################################################################## */

static int year_base;
static FILE_NAME_TYPE file_list, log_file;
static char out_dir[100];
	
static PARAMETER_LIST_ENTRY_TYPE fix_nbr_params[]=
{
	{" year_base:", "%d", &year_base, TYPE_INT},
	{" file_list:", "%79s", file_list, TYPE_STRING},
	{" log_file:", "%79s", log_file, TYPE_STRING},
	{" out_dir:", "%79s", out_dir, TYPE_STRING},
	{ NULL, NULL, NULL, 0}
};

/* ------------------------------------------------------------------
	 --Options:

	 Options are saved in a long bits variable. The meaning of each bit is the
	 following:

		scan_nav bits:

			BIT16: use scan_nav output
			BIT17: scan_nav heading
			BIT18: scan_nav pitch
			BIT19: scan_nav roll
			BIT20: scan_nav time

		Output bits:

			BIT24: output ship's navigation
   ------------------------------------------------------------------ */

#define USE_SCAN_NAV_BIT				 BIT16
#define SCAN_NAV_HEADING_BIT		 BIT17
#define SCAN_NAV_PITCH_BIT			 BIT18
#define SCAN_NAV_ROLL_BIT				 BIT19
#define SCAN_NAV_TIME_BIT				 BIT20

#define OUTPUT_NAVIGATION_BIT    BIT24

static FILE_NAME_TYPE scan_nav_file;
static ULONG fix_nbr_bits=0;

static OPTION_TYPE scan_nav_options[]=
{
	{"end", 0, NULL, (char *) NULL},
	{"file_name:", TYPE_STRING, op_get_param, (char *) scan_nav_file},
	{"heading", 17, set_long_bit, (char *) &fix_nbr_bits},
	{"pitch",   18, set_long_bit, (char *) &fix_nbr_bits},
	{"roll",    19, set_long_bit, (char *) &fix_nbr_bits},
	{"time",    20, set_long_bit, (char *) &fix_nbr_bits},
	{NULL, 0, NULL, (char *) NULL}
};

static TRANSDUCER_MISALIGNMENT_TYPE tr_mis;

static OPTION_TYPE tr_mis_opts[]=
{
	{"end", 0, NULL, (char *) NULL},
	{"heading=", TYPE_DOUBLE, op_get_param, (char *) &(tr_mis.heading)},
	{"pitch=",   TYPE_DOUBLE, op_get_param, (char *) &(tr_mis.pitch)},
	{"roll=",    TYPE_DOUBLE, op_get_param, (char *) &(tr_mis.roll)},
	{NULL, 0, NULL, (char *) NULL}
};

static OPTION_TYPE fix_nbr_options[]=
{
	{"end", 0, NULL, (char *) NULL},
	{"OPTIONS:", 0, NULL, (char *) NULL},
	{"use_scan_nav_output:", 1, execute_sub_options, (char *) scan_nav_options},
	{"transducer_misalignment:", 1, execute_sub_options, (char *) tr_mis_opts},
	{NULL, 0, NULL, (char *) NULL}
};

/* ##################################################################
	 -Type Definitions:
	 ################################################################## */

/* ------------------------------------------------------------------
	--File Pointers:

	File pointers are grouped into a single structure.
	------------------------------------------------------------------ */

typedef struct
{
	FILE *lst;						 /* list of adcp raw files	*/
	FILE *log;						 /* fix_nbr log file				*/
	FILE *nav;			       /* scan_nav file						*/ 
	FILE *out;
} FIX_NBR_FILES_TYPE; 
	
/* ------------------------------------------------------------------
	 --Input Data:

	 Input consists of different structures, depending from which file data has
	 been read. All of these structure is stored in a single record, in order to
	 simplify calls to functions.

	 An additional field is reserved for the estimated start time of the
	 ensemble.
	 ------------------------------------------------------------------ */

typedef struct
{
	FILE_NAME_TYPE out_file_name;
	DATA_FILE_INFO_TYPE fi;
	SCAN_NAV_LINE_TYPE nav;
	NBR_ENSEMBLE_TYPE ping;
	SCAN_NAV_TIME_TYPE ens_time;
	SCAN_NAV_TIME_TYPE time;
	USHORT number;
} FIX_NBR_TYPE;

