/* timeofday.c CrayMPP code for using gettimeofday C function in another code */
/* compile with "cc -c timeofday.c"; load "timeofday.o" with other *.o files */
/* reference as "[variable] = timeofday()" getting microsecond wall time */
/* Caution:  function name must be in caps, since Fortran auto-capitalizes*/
int TIMEOFDAY()
{
   long int tmicro,t1[2],t2[2];
   int gtod;
   float tod;
   gtod=gettimeofday(t1,t2);
/* gettimeofday returns gotod = 0 if successful; t2 gives the timezone;
   t1[0] in secs since 1/1/70, t1[1]in added microseconds */
/* cut t1[0] down to trailing  4 digits for Cray 8 byte float answer return */
   tmicro=(t1[0]-(t1[0]/10000)*10000)*1000000+t1[1];
   tod=tmicro/1000000.; /* big loss of microsec accuracy=> don't return */
/* testing print: remove comments for checking  */
/* printf("tsecs,tmicrosecs,tmicro,TOD= %d secs %d microsec %d %16.6f sec\n" 
                                 ,t1[0],t1[1],tmicro,tod) ;  */
/* return answer in microseconds integer accuracy; avoiding division truncation;
   with 5 leading digits truncated, OK if time < hour, BUT subject to integer
   OverFlow as are most integer clocks, check of time < 0 in application code */
   return(tmicro);
}

