/*

-Procedure tictoc ( UTC and ET time conversion. )


-Abstract

   This `cookbook' example program demonstrates use of the
   following two CSPICE time conversion routines:

                  str2et_c
                  et2utc_c

-Disclaimer

   THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE
   CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.
   GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE
   ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE
   PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS"
   TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY
   WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A
   PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC
   SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE
   SOFTWARE AND RELATED MATERIALS, HOWEVER USED.

   IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA
   BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT
   LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,
   INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,
   REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE
   REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.

   RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF
   THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY
   CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE
   ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.

-Input

   The user will be prompted for:

      - The name of a leapseconds Kernel file.

-Output

   This program will output to the terminal, several
   examples of valid UTC time strings and their corresponding ET
   (ephemeris time) values.

-Particulars

   This program uses the CSPICE routines str2et_c and et2utc_c.
   These routines convert between UTC and ET representations of
   time:

      UTC    is a character string representation of Universal
             Time Coordinated.  which may be in calendar, day
             of year, or Julian date format.  UTC time strings
             are human-readable and thus suitable as user input.

      ET     which stands for Ephemeris Time, is a double precision
             number of ephemeris seconds past Julian year 2000,
             also called Barycentric Dynamical Time.  ET time is
             used internally in CSPICE routines for reading
             ephemeris files.

   For the sake of brevity, this program does NO error checking
   on its inputs. Mistakes will cause the program to crash.

-References

   Refer to Time Required Reading and the str22et_c and et2utc_c
   module headers for additional information.

-Version

   -CSPICE Version 2.0.0, 11-NOV-2002   (EDW)

      Modified program to reproduce, as precisely as possible,
      output of the FORTRAN version of the TICTOC cookbook.
      Programing style and brevity are secondary to this goal.

   -CSPICE Version 1.0.0, 17-OCT-1999   (EDW)

-&
*/

   /* Include needed headers. */

   #include <stdio.h>
   #include "SpiceUsr.h"



int main()
   {


   /* Local declarations. */

   #define                 NCASES      6
   #define                 FILE_SIZE   128
   #define                 STRSIZ      40

   SpiceChar            *  utc        [NCASES];
   SpiceChar            *  format;
   SpiceChar               leap       [FILE_SIZE];
   SpiceChar               answer     [STRSIZ];
   SpiceChar               timestr    [STRSIZ];

   SpiceInt                i;
   SpiceInt                prec;

   SpiceDouble             et;

   SpiceBoolean            cont = SPICETRUE;   

   /*
   Initialize data.  Set the example time strings and the precision
   level for output.
   */

   utc[0] = "9 JAN 1986 03:12:59.22451";
   utc[1] = "1/9/86 3:12:59.22451";
   utc[2] = "86-365//12:00";
   utc[3] = "JD 2451545";
   utc[4] = "77 JUL 1";
   utc[5] = "1 JUL \'29";
   prec   = 3;


   /* Information for the user. */
   puts( "                 Welcome to TICTOC"                       );
   puts( " "                                                        );
   puts( "This program demonstrates the use of the CSPICE  "        );
   puts( "time conversion utility routines: str2et_c and et2utc_c." );
   puts( ""                                                         );


   /* Get and load the leapsecond kernel. */
   prompt_c ( "Enter the name of a leapseconds kernel file: ", 
                                                    FILE_SIZE, leap );
   furnsh_c ( leap );

   puts ( " " );
   puts ( "Working ... Please wait." );
   puts ( " " );


   /* Loop over each example time string. */
   i = 0;
   do
      {

      /* Begin output. */
      puts( " " );
      printf ("      Example UTC time      :  %s\n", utc[i]  );


      /* Convert the time string to ephemeris time J2000. */
      str2et_c ( utc[i], &et );
      puts( " " );
      printf (  "      Corresponding ET      :  %f\n", et      );
      puts( " " );

      /* Convert the ephemeris time to a calendar format. */
      format = "C";
      et2utc_c ( et , format, prec, STRSIZ, timestr );
      printf (  "      UTC calendar format   :  %s\n", timestr );


      /* Convert the ephemeris time to a day-of-year format. */
      format = "D";
      et2utc_c ( et , format, prec, STRSIZ, timestr );
      printf (  "      UTC day of year format:  %s\n", timestr );


      /* Convert the ephemeris time to a Julian Day format. */
      format = "J";
      et2utc_c ( et , format, prec, STRSIZ, timestr );
      printf ( "      UTC Julian date format:  %s\n", timestr );

      ++i;

      /* Does the user intend to continue. */
      puts( " " );
      if( i < NCASES )
         {
         prompt_c ( "Continue? (Enter Y or N): ", STRSIZ, answer );

         if ( eqstr_c( "N", answer ) )
            {
            cont = SPICEFALSE;
            }
         }
 
      }
   while ( (i < NCASES) && cont );

   return ( 0 );

   }
