/***************************************************************

   POS_IO.C

      functions for working with geographic positions

      header and library: use_db

***************************************************************/

#include "geninc.h"  /* POSITION, BADFLOAT */
#include "use_db.h"  /* DMSH_LL_TYPE, DOUBLE_LL_TYPE */

#if PROTOTYPE_ALLOWED
void get_latlon(DOUBLE_LL_TYPE *pos)
#else
void get_latlon(pos)
DOUBLE_LL_TYPE *pos;
#endif
{
   DMSH_LL_TYPE ll;
   int          type = POSITION, ierr;
   unsigned int n = sizeof(DMSH_LL_TYPE);

   DBGET(&type, (char *) &ll, &n, &ierr);
   if (DBERROR(&ierr, "DBGET, position")) exit(-1);

   if (ll.lon.degree == BADSHORT)
      pos->lon = pos->lat = BADFLOAT;
   else
   {
      /* convert hundredths of a second to degrees */
      pos->lat = POSHUN(&(ll.lat)) / 360000.0;
      pos->lon = POSHUN(&(ll.lon)) / 360000.0;
   }
}                       /* get_position */

#if PROTOTYPE_ALLOWED
void get_hun_latlon(HUN_LL_TYPE *pos)
#else
void get_hun_latlon(pos)
HUN_LL_TYPE *pos;
#endif
{
   DMSH_LL_TYPE ll;
   int type = POSITION, ierr;
   unsigned int n = sizeof(DMSH_LL_TYPE);

   DBGET(&type, (char *) &ll, &n, &ierr);
   if (DBERROR(&ierr, "DBGET, position")) exit(-1);

   pos->lat = POSHUN(&(ll.lat));
   pos->lon = POSHUN(&(ll.lon));
}                       /* get_hun_latlon */

#if PROTOTYPE_ALLOWED
void copy_latlon(DOUBLE_LL_TYPE *dest, DOUBLE_LL_TYPE *source)
#else
void copy_latlon(dest, source)
DOUBLE_LL_TYPE *dest, *source;
#endif
{
   dest->lat = source->lat;
   dest->lon = source->lon;
}                       /* copy_latlong */

#if PROTOTYPE_ALLOWED
void copy_hun_latlon(HUN_LL_TYPE *dest, HUN_LL_TYPE *source)
#else
void copy_hun_latlon(dest, source)
HUN_LL_TYPE *dest, *source;
#endif
{
   dest->lat = source->lat;
   dest->lon = source->lon;
}                       /* copy_latlong */


