Actual source code: fdate.c

  1: /* $Id: fdate.c,v 1.41 2001/03/23 23:20:44 balay Exp $*/

 3:  #include petsc.h
 4:  #include petscsys.h
  5: #include "petscfix.h"
  6: #if defined(PETSC_HAVE_SYS_TIME_H)
  7: #include <sys/types.h>
  8: #include <sys/time.h>
  9: #endif
 10: #include <time.h>
 11: #if defined(PETSC_NEEDS_GETTIMEOFDAY_PROTO)
 12: EXTERN_C_BEGIN
 13: EXTERN int gettimeofday(struct timeval *,struct timezone *);
 14: EXTERN_C_END
 15: #endif

 17: static char starttime[64];
 18: 
 19: /*
 20:   This function is called once during the initialize stage.
 21:   It stashes the timestamp, and uses it when needed. This is so that 
 22:   error handlers may report the date without generating possible
 23:   additional system errors during the call to get the date.

 25: */
 26: /*@C
 27:     PetscGetDate - Gets the current date.

 29:    Not collective

 31:   Input Parameter:
 32: .  len - length of string to hold date

 34:   Output Parameter:
 35: .  date - the date

 37:   Level: beginner

 39:   Notes:
 40:     This is Y2K compliant.

 42:     This function DOES make a system call and thus SHOULD NOT be called
 43:     from an error handler. Use PetscGetInitialDate() instead.

 45: .seealso: PetscGetInitialDate()

 47: @*/
 48: int PetscGetDate(char date[],int len)
 49: {
 50:   char           *str=0;
 51: #if defined (PARCH_win32)
 52:   time_t         aclock;
 53:   int            ierr;
 54: #else
 55:   struct timeval tp;
 56:   int            ierr;
 57: #endif

 60: #if defined (PARCH_win32)
 61:   time(&aclock);
 62:   PetscStrncpy(date,asctime(localtime(&aclock)),len);
 63: #else
 64:   gettimeofday(&tp,(struct timezone *)0);
 65:   PetscStrncpy(date,asctime(localtime((time_t*)&tp.tv_sec)),len);
 66: #endif
 67:   /* now strip out the new-line chars at the end of the string */
 68:   PetscStrstr(date,"n",&str);
 69:   if (str) str[0] = 0;
 70:   return(0);
 71: }

 73: int PetscSetInitialDate(void)
 74: {
 77:   PetscGetDate(starttime,64);
 78:   return(0);
 79: }

 81: /*@C
 82:     PetscGetInitialDate - Gets the date the program was started 
 83:       on.

 85:    Not collective

 87:   Input Parameter:
 88: .  len - length of string to hold date

 90:   Output Parameter:
 91: .  date - the date

 93:   Level: beginner

 95:   Notes:
 96:     This is Y2K compliant.

 98:     This function does not make a system call and thus may be called
 99:     from an error handler.

101: .seealso: PetscGetDate()

103: @*/
104: int PetscGetInitialDate(char date[],int len)
105: {

109:   PetscStrncpy(date,starttime,len);
110:   return(0);
111: }