/**---------------------------------------------------------------------------
 ** 
 ** misc.c -- Miscellaneous NBR utilities
 ** 
 ** Author          : Pierre Jaccard
 ** Created On      : 1999/07/15 11:10:54
 ** Last Modified By: Pierre Jaccard
 ** Last Modified On: 1999/07/16 21:13:05
 ** Update Count    : 2
 ** Directory       : /home/pego/pcd1/codas3c/gfi/src/libs/nbr/
 ** Version         : 0.0
 ** Status          : Unknown
 ** ---------------------------------------------------------------------- ** 
 ** DESCRIPTION: 
 ** 
 **    This file provides miscellaneous functions for working with NBR data.
 ** 
 ** ---------------------------------------------------------------------- ** 
 ** REVISIONS: 
 ** ---------------------------------------------------------------------- ** 
 ** CHANGES: 
 **------------------------------------------------------------------------**/

#include "misc.h"

/* ------------------------------------------------------------------
	 This function defines how bottom tracking is selected. 

   RETURNS: 1 if bottom tracking may considered as good, or 0 if not.
	 ------------------------------------------------------------------ */	                                                                   
#if PROTOTYPE_ALLOWED
int get_bottom_track_status(/* Pointer to an ensemble ping */
                            NBR_ENSEMBLE_TYPE *ping)
#else
int get_bottom_track_status(ping)
#endif
{

	NBR_LEADER_TYPE *l;

	SHORT *btvel;
	UBYTE *btpcg;

	int i, nvel, npcg, btm;

	/* Assign pointers */
	l = &(ping->leader);

	nvel = 0;
	npcg = 0;
	btvel = ping->bottom_track_velocity;
	btpcg = ping->bottom_track_percent_good;
	/* Check bt velocities and percent good */
	for(i=0; i<4; i++){
		if(*(btvel+i) != BADSHORT) 
			nvel++;
		if(cnv_bt_pcg(*(btpcg+i)) 
			 > cnv_pcg_threshold(l->percent_good_threshold)) 
			npcg++;
	}
	/* Determine state of bottom tracking */
	btm = ((nvel>=NB_BT_VEL_MIN) && (npcg>=NB_BT_PCG_MIN)) ? 1 : 0;

	return(btm);

}



