/*--------------------------------------------------------------------
 *    The MB-system:	mb_lgpl.h	9/13/2004
 *    $Id:  $
 *
 *    Copyright (c) 2004 by
 *    David W. Caress (caress@mbari.org)
 *      Monterey Bay Aquarium Research Institute
 *      Moss Landing, CA 95039
 *    and Dale N. Chayes (dale@ldeo.columbia.edu)
 *      Lamont-Doherty Earth Observatory
 *      Palisades, NY 10964
 *
 *    This file contains source code modified from source files
 *    distributed as part of MB-System. In contrast to the GPL-licensed
 *    MB-System distributions, the code contained here is licensed
 *    under the Lesser GNU Public license, or LGPL. This means that
 *    compiled versions of these functions, or functions derived from
 *    modifications to this code, may be linked with commercial
 *    applications without imposing any restriction on the sale and
 *    and distribution of those applications.
 *
 *    The full LGPL text may be accessed at http://www.gnu.org/
 *
 *    The release of this code under the LGPL does not change the
 *    the GPL licensing of any code contained in the regular
 *    MB-System distribution.
 *
 *    The source code provided here does not come with any warranties, 
 *    nor is it guarenteed to work on your computer or to do 
 *    anything useful. The user assumes full responsibility for 
 *    the use of this software. In particular, David W. Caress, 
 *    Dale N. Chayes, the Lamont-Doherty Earth Observatory of 
 *    Columbia University, the Monterey Bay Aquarium Research Institute, 
 *    or any other individuals or organizations involved in the 
 *    design and maintenance of the MB-System software package 
 *    and derived distributions are NOT responsible for any 
 *    damage that may follow from correct or incorrect use of this 
 *    source code. Moreover, it should be noted that the source
 *    code provided here has NOT been tested after modification
 *    from the related functions that are part of MB-System.
 *
 *    To access MB-System documentation or source code releases see:
 *         http://www.mbari.org/data/mbsystem
 *         http://www.ldeo.columbia.edu/MB-System
 *
 *--------------------------------------------------------------------*/
/*
 * Author:	D. W. Caress
 * Date:	September 13, 2004
 *
 * $Log:  $
 *
 *--------------------------------------------------------------------*/
/*
 *    This header file mb_lgpl.h includes structure and macro definitions
 *    required for the source provided in the file mb_lgpl.c to compile.
 *
 */

/* include this code only once */
#ifndef MBLGPL_HEADER_DEF
#define MBLGPL_HEADER_DEF

/* MBLGPL function boolean convention */
#define	MBLGPL_YES	1
#define	MBLGPL_NO	0

/* MBIO function status convention */
#define	MBLGPL_SUCCESS			1
#define	MBLGPL_FAILURE			0

/* MBIO function fatal error values */
#define	MBLGPL_ERROR_NO_ERROR		0
#define	MBLGPL_ERROR_MEMORY_FAIL	1
#define	MBLGPL_ERROR_EOF		4
#define	MBLGPL_ERROR_UNINTELLIGIBLE	-8

/* MBLGPL data type ("kind") convention */
#define	MBLGPL_DATA_NONE			0
#define	MBLGPL_DATA_DATA			1	/* general survey data */
#define	MBLGPL_DATA_COMMENT			2	/* general comment */

/* define some important sizes */
#define	MBLGPL_FBT_OLDHEADERSIZE	38
#define	MBLGPL_FBT_NEWHEADERSIZE	44
#define	MBLGPL_FBT_COMMENTSIZE		128

/* define byte swapping macros */
#define mblgpl_swap_short(a) ( ((a & 0xff) << 8) | ((unsigned short)(a) >> 8) )
#define mblgpl_swap_int(a) ( ((a) << 24) | \
                       (((a) << 8) & 0x00ff0000) | \
                       (((a) >> 8) & 0x0000ff00) | \
                        ((unsigned int)(a) >>24) )

#define mblgpl_swap_long(a) ( ((a) << 56) | \
                       (((a) << 40) & 0x00ff000000000000) | \
                       (((a) << 24) & 0x0000ff0000000000) | \
                       (((a) <<  8) & 0x000000ff00000000) | \
                       (((a) >>  8) & 0x00000000ff000000) | \
                       (((a) >> 24) & 0x0000000000ff0000) | \
                       (((a) >> 40) & 0x000000000000ff00) | \
                        ((unsigned long)(a) >> 56)) 

/* data storage structure for fbt swath bathymetry data */
struct mblgpl_fbt_struct
	{
	/* type of data record */
	int	kind;

	/* time stamp */
	short	year;		/* year (4 digits) */
	short	day;		/* julian day (1-366) */
	short	min;		/* minutes from beginning of day (0-1439) */
	short	sec;		/* seconds from beginning of minute (0-59) */
	short	msec;		/* milliseconds from beginning of minute (0-59) */

	/* position */
	unsigned short	lon2u;	/* minutes east of prime meridian */
	unsigned short	lon2b;	/* fraction of minute times 10000 */
	unsigned short	lat2u;	/* number of minutes north of 90S */
	unsigned short	lat2b;	/* fraction of minute times 10000 */

	/* heading and speed */
	unsigned short	heading;/* heading:
					0 = 0 degrees
					1 = 0.0055 degrees
					16384 = 90 degrees
					65535 = 359.9945 degrees
					0 = 360 degrees */
	unsigned short	speed;	/* km/s X100 */

	/* numbers of beams */
	short	beams_bath;	/* number of depth values */
	short	beams_amp;	/* number of amplitude values */
	short	pixels_ss;	/* number of sidescan pixels */
	short	beams_bath_alloc;	/* number of depth values allocated */
	short	beams_amp_alloc;	/* number of amplitude values allocated */
	short	pixels_ss_alloc;	/* number of sidescan pixels allocated */
	short	depth_scale;	/* 1000 X scale where depth = bath X scale */
	short	distance_scale;	/* 1000 X scale where distance = dist X scale */
	short	transducer_depth; /* scaled by depth_scale */
	short	altitude;	/* scaled by depth_scale */
	short	beam_xwidth;	/* 0.01 degrees */
	short	beam_lwidth;	/* 0.01 degrees */
	short	spare;		/* spare */

	/* pointers to arrays */
	unsigned char *beamflag;
	short	*bath;
	short	*amp;
	short	*bath_acrosstrack;
	short	*bath_alongtrack;
	short	*ss;
	short	*ss_acrosstrack;
	short	*ss_alongtrack;

	/* comment */
	char	comment[MBLGPL_FBT_COMMENTSIZE];
	};

#endif
