Often,, when moving code between UNIX platforms, the biggest obstacles are a few, commonly used, system dependent operations. Among the most common are the call to get the current time and date, the call to get a random number, call to the system, and IO.
My KBB libraries solve many common problems, including the first. On all UNIX platforms in common use at TJNAF, my libraries provide a platform independent call by using the system C routines. Refer to the main KBB page for linking instructions, the "FORTRAN calls to KBB C library" page for examples, and the FTP site for binaries and source.
For the current date and time, the routine kbb_time_now will return a string of the format
"Day Mon dd hh:mm:ss yyyy"for example
"Mon Jul 22 18:51:18 2002"
Other string formats can be had using the now_format_date and now_time_and_date routines.
To send a message to the system, use the SEND_TO_SYSTEM routine.
C has intrinsic random number generators used by the UNIX operating system; I've written FORTRAN callable routines (KBB_SEED_I4, KBB_SEED_I8, KBB_RANDOM_R4, KBB_RANDOM_R8) to allow one to set the seed and to get a random number between 0. and 1.:
These are typical intrinsics; the compiler automatically will adapt to give same kind of output as the input unless otherwise listed:
| function | real*Nx complex*2N z |
if not automatic for N=8 |
|---|---|---|
| maximum: max(x,y) | MAX(x,y) | |
| sine of radians: sin(xradians) | SIN(x) | |
| sine of degrees: sin(xdegrees) | SIND(x) | |
| arcsine in radians: asin(x) | ASIN(x) | |
| arcsine in degrees: asin(x) | ASIND(x) | |
| hyperbolic sine: sinh(x) | SINH(x) | |
| complex: z(a,b) | CMPLX(a,b) | DCMPLX(a,b) |
| imaginary component: Im(z) | IMAG(z) | DIMAG(z) |
| real component: Re(z) | REAL(z) | DREAL(z) |
| natural log: ln(x) | LOG(x) | |
| base10 log: log10(x) | LOG10(x) |
The NEW_FILE, OLD_FILE, and APPEND_FILE routines have the correct OPEN specifiers for each platform supported by KBB/F77; the HP-UX OPEN statment has the following commonly used specifiers:
| specifier | example | notes |
|---|---|---|
| UNIT=iochannel | UNIT=7 | |
| FILE=filename | FILE="input.dat" | |
| ERR=statement_number | ERR=999 | |
| FORM=formattype | FORM="formatted" | "formatted" or "unformatted" |
| STATUS=newORold | STATUS="new" | "old", "new", "scratch", or "unknown" |
| IOSTAT=ioflag | IOSTAT=ioproblem | ok if ioproblem.EQ.0 |