Chapter 4. System Functions and Subroutines

This chapter describes extensions to FORTRAN 77 that are related to the IRIX compiler and operating system.

Library Functions

The Fortran library functions provide an interface from Fortran programs to the IRIX system functions. System functions are facilities that are provided by the IRIX system kernel directly, as opposed to functions that are supplied by library code linked with your program.

Table 4-1 summarizes the functions in the Fortran run-time library. In general, the name of the interface routine is the same as the name of the system function that would be called from a C program. For details on a system interface routine use the following command:

man 2 name_of_function


Note: You must declare the time function as EXTERNAL; if you do not, the compiler will assume you mean the VMS-compatible intrinsic time function rather than the IRIX system function. It is a usually a good idea to declare any library function in an EXTERNAL statement as documentation.


Table 4-1. Summary of System Interface Library Routines

Function

Purpose

abort(3f)

abnormal termination

access(2)

determine accessibility of a file

acct(2)

enable/disable process accounting

alarm(3f)

execute a subroutine after a specified time

barrier

perform barrier operations

blockproc(2)

block processes

brk(2)

change data segment space allocation

close

close a file descriptor

creat

create or rewrite a file

ctime(3f)

return system time

dtime(3f)

return elapsed execution time

dup

duplicate an open file descriptor

etime(3f)

return elapsed execution time

exit(2)

terminate process with status

fcntl(2)

file control

fdate(3f)

return date and time in an ASCII string

fgetc(3f)

get a character from a logical unit

flush(3f)

flush output to a logical unit

fork(2)

create a copy of this process

fputc(3f)

write a character to a Fortran logical unit

free_barrier

free barrier

fseek(3f)

reposition a file on a logical unit

fseek64(3f)

reposition a file on a logical unit for 64-bit architecture

fstat(2)

get file status

ftell(3f)

reposition a file on a logical unit

ftell64(3f)

reposition a file on a logical unit for 64-bit architecture

gerror(3f)

get system error messages

getarg(3f)

return command line arguments

getc(3f)

get a character from a logical unit

getcwd

get pathname of current working directory

getdents(2)

read directory entries

getegid(2)

get effective group ID

gethostid(2)

get unique identifier of current host

getenv(3f)

get value of environment variables

geteuid(2)

get effective user ID

getgid(2)

get user or group ID of the caller

gethostname(2)

get current host ID

getlog(3f)

get user's login name

getpgrp

get process group ID

getpid

get process ID

getppid

get parent process ID

getsockopt(2)

get options on sockets

getuid(2)

get user or group ID of caller

gmtime(3f)

return system time

iargc(3f)

return command line arguments

idate(3f)

return date or time in numerical form

ierrno(3f)

get system error messages

ioctl(2)

control device

isatty(3f)

determine if unit is associated with tty

itime(3f)

return date or time in numerical form

kill(2)

send a signal to a process

link(2)

make a link to an existing file

loc(3f)

return the address of an object

lseek(2)

move read/write file pointer

lseek64(2)

move read/write file pointer for 64-bit architecture

lstat(2)

get file status

ltime(3f)

return system time

m_fork

create parallel processes

m_get_myid

get task ID

m_get_numprocs

get number of subtasks

m_kill_procs

kill process

m_lock

set global lock

m_next

return value of counter

m_park_procs

suspend child processes

m_rele_procs

resume child processes

m_set_procs

set number of subtasks

m_sync

synchronize all threads

m_unlock

unset a global lock

mkdir(2)

make a directory

mknod(2)

make a directory/file

mount(2)

mount a filesystem

new_barrier

initialize a barrier structure

nice

lower priority of a process

open(2)

open a file

oserror(3f)

get/set system error

pause(2)

suspend process until signal

perror(3f)

get system error messages

pipe(2)

create an interprocess channel

plock(2)

lock process, test, or data in memory

prctl(2)

control processes

profil(2)

execution-time profile

ptrace

process trace

putc(3f)

write a character to a Fortran logical unit

putenv(3f)

set environment variable

qsort(3f)

quick sort

read

read from a file descriptor

readlink

read value of symbolic link

rename(3f)

change the name of a file

rmdir(2)

remove a directory

sbrk(2)

change data segment space allocation

schedctl(2)

call to scheduler control

send(2)

send a message to a socket

setblockproccnt(2)

set semaphore count

setgid

set group ID

sethostid(2)

set current host ID

setoserror(3f)

set system error

setpgrp(2)

set process group ID

setsockopt(2)

set options on sockets

setuid

set user ID

sginap(2)

put process to sleep

sginap64(2)

put process to sleep in 64-bit environment

shmat(2)

attach shared memory

shmdt(2)

detach shared memory

sighold(2)

raise priority and hold signal

sigignore(2)

ignore signal

signal(2)

change the action for a signal

sigpause(2)

suspend until receive signal

sigrelse(2)

release signal and lower priority

sigset(2)

specify system signal handling

sleep(3f)

suspend execution for an interval

socket(2)

create an endpoint for communication TCP

sproc(2)

create a new share group process

stat(2)

get file status

stime(2)

set time

symlink(2)

make symbolic link

sync

update superblock

sysmp(2)

control multiprocessing

sysmp64(2)

control multiprocessing in 64-bit environment

system(3f)

issue a shell command

taskblock

block tasks

taskcreate

create a new task

taskctl

control task

taskdestroy

kill task

tasksetblockcnt

set task semaphore count

taskunblock

unblock task

time(3f)

return system time (must be declared EXTERNAL)

ttynam(3f)

find name of terminal port

uadmin

administrative control

ulimit(2)

get and set user limits

ulimit64(2)

get and set user limits in 64-bit architecture

umask

get and set file creation mask

umount(2)

dismount a file system

unblockproc(2)

unblock processes

unlink(2)

remove a directory entry

uscalloc

shared memory allocator

uscalloc64

shared memory allocator in 64-bit environment

uscas

compare and swap operator

usclosepollsema

detach file descriptor from a pollable semaphore

usconfig

semaphore and lock configuration operations

uscpsema

acquire a semaphore

uscsetlock

unconditionally set lock

usctlsema

semaphore control operations

usdumplock

dump lock information

usdumpsema

dump semaphore information

usfree

user shared memory allocation

usfreelock

free a lock

usfreepollsema

free a pollable semaphore

usfreesema

free a semaphore

usgetinfo

exchange information through an arena

usinit

semaphore and lock initialize routine

usinitlock

initialize a lock

usinitsema

initialize a semaphore

usmalloc

allocate shared memory

usmalloc64

allocate shared memory in 64-bit environment

usmallopt

control allocation algorithm

usnewlock

allocate and initialize a lock

usnewpollsema

allocate and initialize a pollable semaphore

usnewsema

allocate and initialize a semaphore

usopenpollsema

attach a file descriptor to a pollable semaphore

uspsema

acquire a semaphore

usputinfo

exchange information through an arena

usrealloc

user share memory allocation

usrealloc64

user share memory allocation in 64-bit environment

ussetlock

set lock

ustestlock

test lock

ustestsema

return value of semaphore

usunsetlock

unset lock

usvsema

free a resource to a semaphore

uswsetlock

set lock

wait(2)

wait for a process to terminate

write

write to a file

You can use the statement to cause Fortran interprocess data sharing. However, this is a nonstandard statement. The datapool statement is a way that different processes can use to access the same pool of common symbols. Any processes can access the shared datapool by linking with the datapool DSO. For more information see the datapool(5) reference page.

Extended Intrinsic Subroutines

This section describes the intrinsic subroutines that are extensions to FORTRAN 77. The intrinsic functions that are standard to FORTRAN 77 are documented in Appendix A of the MIPSPro Fortran 77 Language Reference Manual. The rules for using the names of intrinsic subroutines are also discussed in that appendix.

DATE

The DATE routine returns the current date as set by the system; the format is as follows:

CALL DATE (buf)

The buf argument is a variable, array, array element, or character substring nine bytes long. After the call, buf contains an ASCII variable in the format dd-mmm-yy, where dd is the date in digits, mmm is the month in alphabetic characters, and yy is the year in digits.

IDATE

The IDATE routine returns the current date as three integer values representing the month, date, and year; the format is as follows:

CALL IDATE (m, d,y)

The m, d, and y arguments are either INTEGER*4 or INTEGER*2 values representing the current month, day and year. For example, the values of m, d, and y on August 10, 1989, are the following:

m = 8
d = 10
y = 89

ERRSNS

The ERRSNS routine returns information about the most recent program error; the format is as follows:

CALL ERRSNS (arg1, arg2, arg3, arg4, arg5)

The arguments (arg1, arg2, and so on) can be either INTEGER*4 or INTEGER*2 variables. On return from ERRSNS, the arguments contain the information shown in the following table.

Argument

Contents

arg1

IRIX global variable errno, which is then reset to zero after the call

arg2

Zero

arg3

Zero

arg4

Logical unit number of the file that was being processed when the error occurred

arg5

Zero

Although only arg1 and arg4 return relevant information, arg2, arg3, and arg5 are always required.

EXIT

The EXIT routine causes normal program termination and optionally returns an exit-status code; the format is as follows:

CALL EXIT (status)

The status argument is an INTEGER*4 or INTEGER*2 argument containing a status code.

TIME

The TIME routine returns the current time in hours, minutes, and seconds; the format is as follows:

CALL TIME (clock)

The clock argument is a variable, array, array element, or character substring; it must be eight bytes long. After execution, clock contains the time in the format hh:mm:ss, where hh, mm, and ss are numerical values representing the hour, the minute, and the second.

MVBITS

The MVBITS routine transfers a bit field from one storage location to another; the format is as follows:

CALL MVBITS (source,sbit,length,destination,dbit)

Arguments can be declared as INTEGER*2, INTEGER*4, or INTEGER*8. The following list describes each argument:

Argument

Description

source

Integer variable or array element. Source location of bit field to be transferred.

sbit

Integer expression. First bit position in the field to be transferred from source.

length

Integer expression. Length of the field to be transferred from source.

destination

Integer variable or array element. Destination location of the bit field.

dbit

Integer expression. First bit in destination to which the field is transferred.

Extended Intrinsic Functions

The following sections provide an overview of the intrinsic functions added as extensions to FORTRAN 77.

SECNDS

SECNDS is an intrinsic routine that returns the number of seconds since midnight, minus the value of the passed argument; the format is as follows:

s = SECNDS(n)

After execution, s contains the number of seconds past midnight less the value specified by n. Both s and n are single-precision, floating point values.

RAN

RAN generates a pseudo-random number. The format is as follows:

v = RAN(s)

The argument s is an INTEGER*4 variable or array element. This variable serves as a seed in determining the next random number. It should initially be set to a large, odd integer value. You can compute multiple random number series by supplying different variables or array elements as the seed argument to different calls of RAN.


Caution: Because RAN modifies the s argument, calling the function with a constant value can cause a core dump.

The algorithm used in RAN is the linear congruential method. The code is similar to the following fragment:

S = S * 1103515245L + 12345
RAN = FLOAT(IAND(RSHIFT(S,16),32767))/32768.0

RAN is supplied for compatibility with VMS. For demanding applications, use the functions described on the random reference page. These can all be called using techniques described under “Using %VAL” in Chapter 3.