1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <time.h>
#include <string.h>
/**GRDATE -- get date and time as character string (Cray)
*+
* SUBROUTINE GRDATE(STRING, L)
* CHARACTER*(*) STRING
* INTEGER L
*
* Return the current date and time, in format 'dd-Mmm-yyyy hh:mm'.
* To receive the whole string, the STRING should be declared
* CHARACTER*17.
*
* Arguments:
* STRING : receives date and time, truncated or extended with
* blanks as necessary.
* SLEN : receives the number of characters in STRING, excluding
* trailing blanks. This will always be 17, unless the length
* of the string supplied is shorter.
*--
* 13-Nov-1994 - [mcs] Abosft FORTRAN callable C version for NeXT.
*-----------------------------------------------------------------------
*/
void GRDATE(string, slen, maxlen, w_slen)
char *string; int *slen;
int maxlen, w_slen;
{
char vtime[18]; /* Output string compilation buffer */
char *utime; /* Returned string from ctime() */
time_t x; /* Time returned by time() */
int i;
/*
* Get the standard C time string.
*/
time(&x);
utime = ctime(&x);
/*
* Copy a re-organised version of the time string into vtime[].
*/
vtime[0] = utime[8];
vtime[1] = utime[9];
vtime[2] = '-';
vtime[3] = utime[4];
vtime[4] = utime[5];
vtime[5] = utime[6];
vtime[6] = '-';
vtime[7] = utime[20];
vtime[8] = utime[21];
vtime[9] = utime[22];
vtime[10] = utime[23];
vtime[11] = ' ';
strncpy(vtime+12, utime+11, 5);
vtime[17]='\0';
/*
* Copy up to maxlen characters of vtime into the output FORTRAN string.
*/
strncpy(string, vtime, maxlen);
*slen = (maxlen < 17) ? maxlen : 17;
/*
* Pad the FORTRAN string with spaces.
*/
for(i=17; i<maxlen; i++)
string[i] = ' ';
return;
}
|