#include <stdio.h>
#include "dbext.h"         /* SHORT, ... */
#include "adcp.h"          /* ACCESS_VARIABLES_TYPE */
#include "data_id.h"       /* ACCESS_VARIABLES */
#include "use_db.h"        /* db*_cnf() */
/*-----------------------------------------------------------------------------

   FUNCTION: update_acc_var

      Updates the last_good_bin field of the ACCESS_VARIABLES structure if
      the parameter is smaller than the current setting.  (This field is
      supposed to mark the last good bin estimate based on all considerations.)

   PARAMETER:

      last_good_bin = new estimate for last_good_bin

   RETURNS:

      0 if okay
      1 if database error

*/
#if PROTOTYPE_ALLOWED
int update_acc_var(SHORT last_good_bin)
#else
int update_acc_var(last_good_bin)
SHORT last_good_bin;
#endif
{
   ACCESS_VARIABLES_TYPE acc;
   unsigned int n = sizeof(ACCESS_VARIABLES_TYPE);

   if (dbget_cnf(ACCESS_VARIABLES, (char *) &acc, &n, "getting access variables"))
      return(1);
   if ( acc.last_good_bin != -1 )
   {
      acc.last_good_bin = last_good_bin;
      if (dbput_cnf(ACCESS_VARIABLES, (char *) &acc, &n, "storing access variables"))
         return(1);
   }
   return(0);
}

#if PROTOTYPE_ALLOWED
int comment(char *x)
#else
int comment(x)
char *x;
#endif
{
   return ( (x == NULL) || (*(x) == '%') );
}
