1e5c89e4eSSatish Balay 2*c6db04a5SJed Brown #include <petscsys.h> 3e5c89e4eSSatish Balay #if defined(PETSC_HAVE_SYS_TIME_H) 4e5c89e4eSSatish Balay #include <sys/types.h> 5e5c89e4eSSatish Balay #include <sys/time.h> 6e5c89e4eSSatish Balay #endif 7e5c89e4eSSatish Balay #include <time.h> 8e5c89e4eSSatish Balay #if defined(PETSC_NEEDS_GETTIMEOFDAY_PROTO) 9e5c89e4eSSatish Balay EXTERN_C_BEGIN 1009573ac7SBarry Smith extern int gettimeofday(struct timeval *,struct timezone *); 11e5c89e4eSSatish Balay EXTERN_C_END 12e5c89e4eSSatish Balay #endif 13e5c89e4eSSatish Balay 14e5c89e4eSSatish Balay /* 15e5c89e4eSSatish Balay This function is called once during the initialize stage. 16e5c89e4eSSatish Balay It stashes the timestamp, and uses it when needed. This is so that 17e5c89e4eSSatish Balay error handlers may report the date without generating possible 18e5c89e4eSSatish Balay additional system errors during the call to get the date. 19e5c89e4eSSatish Balay 20e5c89e4eSSatish Balay */ 21e5c89e4eSSatish Balay #undef __FUNCT__ 22e5c89e4eSSatish Balay #define __FUNCT__ "PetscGetDate" 23e5c89e4eSSatish Balay /*@C 24e5c89e4eSSatish Balay PetscGetDate - Gets the current date. 25e5c89e4eSSatish Balay 26e5c89e4eSSatish Balay Not collective 27e5c89e4eSSatish Balay 28e5c89e4eSSatish Balay Input Parameter: 29e5c89e4eSSatish Balay . len - length of string to hold date 30e5c89e4eSSatish Balay 31e5c89e4eSSatish Balay Output Parameter: 32e5c89e4eSSatish Balay . date - the date 33e5c89e4eSSatish Balay 34e5c89e4eSSatish Balay Level: beginner 35e5c89e4eSSatish Balay 36e5c89e4eSSatish Balay This function DOES make a system call and thus SHOULD NOT be called 37e5c89e4eSSatish Balay from an error handler. 38e5c89e4eSSatish Balay 39e5c89e4eSSatish Balay @*/ 407087cfbeSBarry Smith PetscErrorCode PetscGetDate(char date[],size_t len) 41e5c89e4eSSatish Balay { 42e5c89e4eSSatish Balay char *str=PETSC_NULL; 43e5c89e4eSSatish Balay #if defined(PETSC_HAVE_TIME) 44e5c89e4eSSatish Balay time_t aclock; 45e5c89e4eSSatish Balay #else 46e5c89e4eSSatish Balay struct timeval tp; 47e5c89e4eSSatish Balay #endif 48e5c89e4eSSatish Balay PetscErrorCode ierr; 49e5c89e4eSSatish Balay 50e5c89e4eSSatish Balay PetscFunctionBegin; 51e5c89e4eSSatish Balay #if defined(PETSC_HAVE_TIME) 52e5c89e4eSSatish Balay time(&aclock); 53e5c89e4eSSatish Balay ierr = PetscStrncpy(date,asctime(localtime(&aclock)),len);CHKERRQ(ierr); 54e5c89e4eSSatish Balay #else 55e5c89e4eSSatish Balay gettimeofday(&tp,(struct timezone *)0); 56e5c89e4eSSatish Balay ierr = PetscStrncpy(date,asctime(localtime((time_t*)&tp.tv_sec)),len);CHKERRQ(ierr); 57e5c89e4eSSatish Balay #endif 58e5c89e4eSSatish Balay /* now strip out the new-line chars at the end of the string */ 59e5c89e4eSSatish Balay ierr = PetscStrstr(date,"\n",&str);CHKERRQ(ierr); 60e5c89e4eSSatish Balay if (str) str[0] = 0; 61e5c89e4eSSatish Balay PetscFunctionReturn(0); 62e5c89e4eSSatish Balay } 63e5c89e4eSSatish Balay 64