#include "common.h"
#include "time_.h"  /* YMDHMS_TIME_TYPE, year_day() */
#include "use_db.h"
#include "ioserv.h"

#if PROTOTYPE_ALLOWED
void main(int argc, char *argv[])
#else
void main(argc, argv)
int argc;
char *argv[];
#endif
{
   YMDHMS_TIME_TYPE dt;
   USHORT *dt_ptr;
   int year_base;
   int i;
   double s;

   /* defaults: */
   dt.month = dt.day = 1;
   dt.hour = dt.minute = dt.second = 0;

   if (argc <3 || argc > 8)
   {
      printf("\ncommand line: year_base yy mm dd hh mi se");
      printf("\nbase_year, yy are 2 or 4-digit.  All others are optional.\n");
   }
   else
   {
      if (sscanf(argv[1], " %d", &year_base) != 1)
      {
         printf("\n error reading year_base\n");
         exit(-1);
      }
      year_base = yr4digit(year_base);

      dt_ptr = (USHORT *) &dt;
      for (i=2; i<argc; i++)
      {
         if (sscanf(argv[i], " %hd", dt_ptr++) != 1)
         {
            printf("\n error reading command line\n");
            exit(-1);
         }
      }
      if (argc == 8)     /* re-scan seconds arg as double just in case */
      {
         sscanf(argv[7], " %lf", &s);
         dt.second = set_hs(s);
      }
      dt.year = (USHORT) yr4digit( (int)dt.year);
      printf("%0.8f\n", year_day(&dt, year_base));
   }
}


