//===================================================== file = clktod.c =====
//=  Program to convert a cumulative stamp file into delta time             =
//===========================================================================
//=  Notes:                                                                 =
//=    1) Input from input file "in.dat" to stdin (see example below)       =
//=        * Comments are bounded by "&" characters at the beginning and    =
//=          end of the comment block                                       =
//=    2) Output is to stdout                                               =
//=-------------------------------------------------------------------------=
//= Example "in.dat" file:                                                  =
//=                                                                         =
//=   & --- Sample input file of cummulative time stamps --- &              =
//=   0.090000                                                              =
//=   0.200000                                                              =
//=   0.660000                                                              =
//=   1.140000                                                              =
//=   1.650000                                                              =
//=   2.170000                                                              =
//=   2.790000                                                              =
//=   3.412000                                                              =
//=   4.034200                                                              =
//=   4.834200                                                              =
//=   5.635200                                                              =
//=-------------------------------------------------------------------------=
//= Example output (for above "in.dat"):                                    =
//=                                                                         =
//=   & ------------------------------------------- clktod.c ----- &        =
//=   0.090000                                                              =
//=   0.110000                                                              =
//=   0.460000                                                              =
//=   0.480000                                                              =
//=   0.510000                                                              =
//=   0.520000                                                              =
//=   0.620000                                                              =
//=   0.622000                                                              =
//=   0.622200                                                              =
//=   0.800000                                                              =
//=   0.801000                                                              =
//=   & ---------------------------------------------------------- &        =
//=-------------------------------------------------------------------------=
//=  Build:  gcc clktod.c, bcc32 clktod.c, cl clktod.c                      =
//=-------------------------------------------------------------------------=
//=  Execute: clktod < in.dat                                               =
//=-------------------------------------------------------------------------=
//=  Author: Kenneth J. Christensen                                         =
//=          University of South Florida                                    =
//=          WWW: http://www.csee.usf.edu/~christen                         =
//=          Email: christen@csee.usf.edu                                   =
//=-------------------------------------------------------------------------=
//=  History: KJC (10/02/98) - Genesis                                      =
//===========================================================================

//----- Include files -------------------------------------------------------
#include <stdio.h>                 // Needed for printf() and feof()
#include <stdlib.h>                // Needed for atof()
#include <string.h>                // Needed for strcmp()

//===========================================================================
//=  Main program                                                           =
//===========================================================================
void main(void)
{
  double    clk_time;              // Current cumulative (clock) time stamp
  double    clk_time_last;         // Last cumulative time stamp
  double    delta_time;            // Delta time stamp value
  char      temp_string[256];      // Temporary string variable

  // Output banner
  printf("& ------------------------------------------- clktod.c ----- & \n");

  // Loop for entire input file
  clk_time_last = delta_time = 0.0;
  while(1)
  {
    // Input a value
    scanf("%s", temp_string);

    // This handles a comment bounded by "&" symbols
    if (strcmp(temp_string, "&") == 0)
    {
      do
      {
        scanf("%s", temp_string);
      } while (strcmp(temp_string, "&") != 0);
      scanf("%s", temp_string);
    }

    // Check if end-of-file
    if (feof(stdin)) break;

    // Set clk_time
    clk_time = atof(temp_string);

    // Compute delta time and output
    delta_time = clk_time - clk_time_last;
    clk_time_last = clk_time;
    printf("%f \n", delta_time);
  }

  // Output closing message
  printf("& ---------------------------------------------------------- & \n");
}
