[net.lang.f77] Need help on date, time, errors msgs.

jme@wdl1.UUCP (Joseph M. Earley) (01/03/84)

	We would like to stamp our reports with the current date and time.
	How do we get that information into our FORTRAN program?  We are
	currently using the 4.1 BSD Unix release.

	Also, where do I find out the meaning of an IOSTAT run time error?
	We were trying to track down an IOSTAT ERROR 115 and I couldn't find
	any manuals or on-line documentation that explained any of the run
	time or compile time errors.  Either our site is missing some
	documentation or I've been looking in the wrong place.  The FORTRAN
	user community is a very small minority on our Unix system so the 
	systems people never bothered to learn the ins and outs of using it,
	and I would prefer not to waste their or my time in digging through
	the compiler's source code to find out that I've made a stupid mistake.

	Thanks in advance for any help.

	Joe Earley
	Ford Aerospace & Communications Corporation

chris@umcp-cs.UUCP (01/06/84)

The F77 error codes (100-?) are in /usr/src/lib/libI77uc/f_errno.h,
at least in the latest release of 4.1BSD.  The number returned in
the iostat= variable is either < 0 => EOF, 0-sys_nerr => Unix error
code, or 100-f_nerr => F77 I/O library error message.  You have to
write C code to access these.  Something like

C	error routine
100	call errmsg (iostat)
	...

and

	_errmsg_ (e)
	int e;
	{
		extern int errno, sys_nerr, f_nerr;
		extern char *sys_errlist[], *f_errlist[];

		if (e < 0)
			printf ("EOF\n");
		else if (e < sys_nerr)
			printf ("%s\n", sys_errlist[e]);
		else if (e < 100)
			printf ("Unknown system error %d\n", e);
		else if (e - 100 < f_nerr)
			printf ("%s\n", f_errlist[e - 100]);
		else
			printf ("Unknown f77 error %d\n", e);
	}

should work.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris@umcp-cs		ARPA:	chris.umcp-cs@CSNet-Relay

shprentz@proper.UUCP (Joel Shprentz) (01/13/84)

The following two C functions provide the time and date
in F77 character string form. They appear similar to the
time and date subroutines found on VAX VMS and CDC systems.

Note that I am primarily a Fortran programmer trying to move
an existing program to Unix with the minimum of fuss. I am
sure their are better ways to write this, but, after all, what
percent of total execution time is spent in the time and date
subroutines?


# Time subroutine for F77 programs

# use:   character*8 string
#        call time (string)

# returns time string such as '12:34:56'.
# strings less than 8 characters will be truncated.
# strings longer than 8 characters will be padded with blanks.

time_ (string, length)
char *string;
long int length;
{
	char *ctime(), *ascii;
	int i;
	long clock, time();

	/* get current time in ascii string. */
	clock = time (0);
	ascii = ctime (&clock);

	/* move formatted time to user's string */
	for (i=0; i<8 && i<length; i++)
		string [i] = ascii [i+11];
	while (i<length)
		string [i++] = ' ';
}
# Date subroutine for F77 programs

# use:   character*10 string
#        call date (string)

# returns date string such as '15 Jan 1983'.
# strings less than 10 characters will be truncated.
# strings longer than 10 characters will be padded with blanks.

date_ (string, length)
char *string;
long int length;
{
	char *ctime(), buffer [11], *ascii;
	int i;
	long clock, time();

	/* get current time in ascii string. */
	clock = time (0);
	ascii = ctime (&clock);

	/* construct date string in work buffer. */
	buffer [0] = ascii [8];		/* day */
	buffer [1] = ascii [9];
	buffer [2] = ' ';
	buffer [3] = ascii [4];		/* month */
	buffer [4] = ascii [5];
	buffer [5] = ascii [6];
	buffer [6] = ' ';
	buffer [7] = ascii [20];	/* year */
	buffer [8] = ascii [21];
	buffer [9] = ascii [22];
	buffer [10] = ascii [23];

	/* move formatted date to user's string */
	for (i=0; i<11 && i<length; i++)
		string [i] = buffer [i];
	while (i<length)
		string [i++] = ' ';
}