#include "common.h"
#include "prtspecl.h"  /* print_ymdhms_time */
#include "time_.h"      /* yd_to_ymdhmh_time */
#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
{
   double day;
   YMDHMS_TIME_TYPE dt;
   int year_base;
   int n;

   if (argc == 2 && *argv[1] == '-')
   {
      while (1)
      {
         n = scanf("%d %lf\n", &year_base, &day);
         if (n != 2) return;  /* Exit: no more input. */
         year_base = yr4digit(year_base);
         yd_to_ymdhmh_time(day, year_base, &dt);
         write_ymdhms_time(stdout, &dt);
         puts("");
      }
   }
   
   if (argc !=3)
   {
      printf("\ncommand line: year_base day");
      printf("\nyear_base is 2- or 4-digit, day is the decimal year day.\n");
      return;  /* Exit: inadequate input. */
   }

   if (sscanf(argv[1], " %d", &year_base) != 1)
   {
      printf("\n error reading year_base\n");
      exit(-1);
   }
   year_base = yr4digit(year_base);
   if (sscanf(argv[2], " %lf", &day) != 1)
   {
      printf("\n error reading day\n");
      exit(-1);
   }
   yd_to_ymdhmh_time(day, year_base, &dt);
   write_ymdhms_time(stdout, &dt);
   puts("");
   return;    /* Exit: command line input used. */
}


