/*
********************************************************************************
*                                                                              *
*  2DHF version 1-2003                                                         *
*  Copyright (C) 1995 Leif Laaksonen                                           *
*                                                                              *
*  This software may be used and distributed according to the terms            *
*  of the GNU General Public License, see README and COPYING.                  *
*                                                                              *
********************************************************************************

  Two small c-routines to return the used cpu-time (both parent and child)
  and the time and date.

  This small FORTAN program:

c-------------------------------------
      character*80 text

      call getdatetime(text)

      do i = 1,1000000
      c = sqrt(c * 10000.)
      enddo

      call getusedcpu(a , b)

      write(6,*) a,b

      write(6,*) text

      end
c-------------------------------------

     returns the following:

azalea 121> time ./junk
   0.8200000      0.0000000E+00
 Tue Nov 21 21:41:03 1995

0.813u 0.012s 0:00.84 97.6% 0+0k 0+0io 0pf+0w

  (1) The first number 0.8200000 is the used cpu-time in seconds
  (2) The second number 0.0000000E+00 is the cpu-time used by sub-processes
      or children. In this case it is (of course zero)
  (3) The text 'Tue Nov 21 21:41:03 1995' is the date and time stamp
      returned. The FORTRAN string returning the time stamp has to be
      defined as 80 characters long!!!!!
  (4) The retuned cpu-time is the total used cpu-time (including system 
      services 0.813 + 0.012).

  The c-routine can be compiled as:

  cc -c util.c

  and the combined FORTRAN/C routines can be compiled/linked as:

  f77 -o junk test.f util.o

  and run the program:

  ./junk

*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>


#include <sys/types.h>
#include <sys/times.h>
#include <sys/param.h>

#if defined(dec)
#include <sys/acct.h>
#endif

#if defined(ymp)
#include <time.h>
#endif

#define STRING_LENGTH 80

/************************************************************************/
#if defined(AIX)
void getdatetime(char *datetime)
#endif
#if defined(ymp)
void GETDATETIME(char *datetime)
#else
void getdatetime_(char *datetime)       
#endif
/************************************************************************/
{
    time_t  t;

    time(&t);
    if(t == -1) {
    strcpy(datetime,"?Sorry, can't get the time ");
    return;}

    strncpy(datetime,(char *)ctime(&t), STRING_LENGTH);

}


