# Portability Library Routines

The following tables list library routines for portability.

If you have programs that use these routines, it is recommended that they access the portability library with USE IFPORT.

Some routines in this library can be called with different sets of arguments, and some can be used as a function or a subroutine. In these cases, the arguments and calling mechanism determine the meaning of the routine. The IFPORT module contains generic interface blocks that give procedure definitions for these routines.

Fortran contains intrinsic procedures for many of the portability functions. The portability routines are extensions to the Fortran 2018 standard. For portability and performance, you should write code using Fortran standard intrinsic procedures whenever possible.

Information Retrieval
Name | Procedure Type | Description
--- | --- | ---
FOR_IFCORE_VERSION | Function | Returns the version of the Fortran run-time library (ifcore).
FOR_IFPORT_VERSION | Function | Returns the version of the Fortran portability library (ifport).
FSTAT | Function | Returns information about a logical file unit.
GETCWD | Function | Returns the pathname of the current working directory.
GETENV | Subroutine | Searches the environment for a given string and returns its value if found.
GETGID | Function | Returns the group ID of the user.
GETLOG | Subroutine | Returns the user's login name.
GETPID | Function | Returns the process ID of the process.
GETUID | Function | Returns the user ID of the user of the process.
HOSTNAM 1 | Function | Returns the name of the user's host.
ISATTY | Function | Checks whether a logical unit number is a terminal.
LSTAT | Function | Returns information about a named file. STAT is the preferred form of this function.
RENAME | Function | Renames a file.
STAT | Function | Returns information about a named file.
UNLINK | Function | Deletes the file given by path.

Process Control
Name | Procedure Type | Description
--- | --- | ---
ABORT | Subroutine | Stops execution of the current process, clears I/O buffers, and writes a string to external unit 0.
ALARM | Function | Executes an external subroutine after waiting a specified number of seconds.
KILL | Function | Sends a signal code to the process given by ID.
SIGNAL | Function | Changes the action for signal.
SLEEP | Subroutine | Suspends program execution for a specified number of seconds.
SYSTEM | Function | Executes a command in a separate shell.

Numeric Values and Conversion
Name | Procedure Type | Description
--- | --- | ---
BESJ0, BESJ1,BESJN, BESY0,BESY1, BESYN | Functions | Return single-precision values of Bessel functions of the first and second kind of orders 1, 2, and n, respectively.
BIC, BIS | Subroutines | Perform bit level clear, set, and test for integers.
BIT | Function | Performs bit level clear, set, and test for integers.
CDFLOAT | Function | Converts a COMPLEX(4) argument to DOUBLE PRECISION type.
COMPLINT, COMPLREAL, COMPLLOG | Functions | Return a BIT-WISE complement or logical .NOT. of the argument.
CSMG | Function | Performs an effective BIT-WISE store under mask.
DBESJ0, DBESJ1,DBESJN, DBESY0,DBESY1, DBESYN | Functions | Return double-precision values of Bessel functions of the first and second kind of orders 1, 2, and n, respectively.
DFLOATI, DFLOATJ, DFLOATK | Functions | Convert an integer to double-precision real type.
DRAND, DRANDM | Functions | Return random numbers between 0.0 and 1.0.
DRANSET | Subroutine | Sets the seed for the random number generator.
IDFLOAT | Function | Converts an INTEGER(4) argument to double-precision real type.
IFLOATI, IFLOATJ | Functions | Convert an integer to single-precision real type.
INMAX | Function | Returns the maximum positive value for an integer.
INTC | Function | Converts an INTEGER(4) argument to INTEGER(2) type.
IRAND, IRANDM | Functions | Return a positive integer in the range 0 through 2**31-1 or 2**15-1 if called without an argument.
IRANGET | Subroutine | Returns the current seed.
IRANSET | Subroutine | Sets the seed for the random number generator.
JABS | Function | Computes an absolute value.
LONG | Function | Converts an INTEGER(2) argument to INTEGER(4) type.
QRANSET | Subroutine | Sets the seed for a sequence of pseudo-random numbers.
RAND, RANDOM 2 | Functions | Return random values in the range 0 through 1.0.
RANF | Function | Generates a random number between 0.0 and RAND_MAX.
RANGET | Subroutine | Returns the current seed.
RANSET | Subroutine | Sets the seed for the random number generator.
SEED | Subroutine | Changes the starting point of RANDOM.
SHORT | Function | Converts an INTEGER(4) argument to INTEGER(2) type.
SRAND | Subroutine | Seeds the random number generator used with IRAND and RAND.

Input and Output
Name | Procedure Type | Description
--- | --- | ---
ACCESS | Function | Checks a file for accessibility according to mode.
CHMOD | Function | Changes file attributes.
FGETC | Function | Reads a character from an external unit.
FLUSH | Function | Flushes the buffer for an external unit to its associated file.
FPUTC | Function | Writes a character to an external unit.
FSEEK | Subroutine | Repositions a file on an external unit.
FTELL, FTELLI8 | Function | Return the offset, in bytes, from the beginning of the file.
GETC | Function | Reads a character from unit 5.
GETPOS, GETPOSI8 | Functions | Return the offset, in bytes, from the beginning of the file.
PUTC | Function | Writes a character to unit 6.

Date and Time
Name | Procedure Type | Description
--- | --- | ---
CLOCK | Function | Returns current time in HH:MM:SS format using a 24-hour clock.
CLOCKX | Subroutine | Returns the processor clock to the nearest microsecond.
CTIME | Function | Converts system time to a 24-character ASCII string.
DATE 3 | Subroutine or Function | Returns the current system date.
DATE4 | Subroutine | Returns the current system date.
DCLOCK | Function | Returns the elapsed time in seconds since the start of the current process.
DTIME | Function | Returns CPU time since later of (1) start of program, or (2) most recent call to DTIME.
ETIME | Function | Returns elapsed CPU time since the start of program execution.
FDATE | Subroutine or Function | Returns the current date and time as an ASCII string.
GETDAT | Subroutine | Returns the date.
GETTIM | Subroutine | Returns the time.
GMTIME | Subroutine | Returns Greenwich Mean Time as a 9-element integer array.
IDATE 3 | Subroutine | Returns the date either as one 3-element array or three scalar parameters (month, day, year).
IDATE4 | Subroutine | Returns the date either as one 3-element array or three scalar parameters (month, day, year).
ITIME | Subroutine | Returns current time as a 3-element array (hour, minute, second).
JDATE 3 | Function | Returns current date as an 8-character string with the Julian date.
JDATE4 | Function | Returns current date as a 10-character string with the Julian date.
LTIME | Subroutine | Returns local time as a 9-element integer array.
RTC | Function | Returns number of seconds since 00:00:00 GMT, Jan 1, 1970.
SECNDS | Function | Returns number of seconds since midnight, less the value of its argument.
SETDAT | Function | Sets the date.
SETTIM | Function | Sets the time.
TIME | Subroutine or Function | As a subroutine, returns time formatted as HH:MM:SS; as a function, returns time in seconds since 00:00:00 GMT, Jan 1, 1970.
TIMEF | Function | Returns the number of seconds since the first time this function was called (or zero).

Error Handling
Name | Procedure Type | Description
--- | --- | ---
GETLASTERROR | Function | Returns the last error set.
GETLASTERRORQQ | Function | Returns the last error set by a run-time function or subroutine.
IERRNO | Function | Returns the last code error.
SETERRORMODEQQ | Subroutine | Sets the mode for handling critical errors.

Program Control
Name | Procedure Type | Description
--- | --- | ---
RAISEQQ | Function | Sends an interrupt to the executing program, simulating an interrupt from the operating system.
RUNQQ | Function | Calls another program and waits for it to execute.
SIGNALQQ | Function | Controls signal handling.
SLEEPQQ | Subroutine | Delays execution of the program for the specified time.

System, Drive, and Directory
Name | Procedure Type | Description
--- | --- | ---
CHDIR | Function | Changes the current working directory.
CHANGEDIRQQ | Function | Makes the specified directory the current (default) directory.
CHANGEDRIVEQQ | Function | Makes the specified drive the current drive.
DELDIRQQ | Function | Deletes a specified directory.
GETDRIVEDIRQQ | Function | Returns the current drive and directory path.
GETDRIVESIZEQQ | Function | Gets the size of the specified drive.
GETDRIVESQQ | Function | Reports the drives available to the system.
GETENVQQ | Function | Gets a value from the current environment.
MAKEDIRQQ | Function | Makes a directory with the specified directory name.
SETENVQQ | Function | Adds a new environment variable, or sets the value of an existing one.
SYSTEMQQ | Function | Executes a command by passing a command string to the operating system's command interpretor.

Speaker
Name | Procedure Type | Description
--- | --- | ---
BEEPQQ | Subroutine | Sounds the speaker for a specified duration in milliseconds at a specified frequency in Hertz.

File Management
Name | Procedure Type | Description
--- | --- | ---
DELFILESQQ | Function | Deletes the specified files in a specified directory.
FINDFILEQQ | Function | Searches for a file in the directories specified in the PATH environment variable.
FULLPATHQQ | Function | Returns the full path for a specified file or directory.
GETFILEINFOQQ | Function | Returns information about files with names that match a request string.
PACKTIMEQQ | Subroutine | Packs time values for use by SETFILETIMEQQ.
RENAMEFILEQQ | Function | Renames a file.
SETFILEACCESSQQ | Function | Sets file-access mode for the specified file.
SETFILETIMEQQ | Function | Sets modification time for a given file.
SPLITPATHQQ | Function | Breaks a full path into four components.
UNPACKTIMEQQ | Subroutine | Unpacks a file's packed time and date value into its component parts.

Arrays
Name | Procedure Type | Description
--- | --- | ---
BSEARCHQQ | Function | Performs a binary search for a specified element on a sorted one-dimensional array of non-structure data types (derived types are not allowed).
SORTQQ | Subroutine | Sorts a one-dimensional array of non-structure data types (derived types are not allowed).

Floating-Point Inquiry and Control
Name | Procedure Type | Description
--- | --- | ---
CLEARSTATUSFPQQ | Subroutine | Clears the exception flags in the floating-point processor status word.
GETCONTROLFPQQ | Subroutine | Returns the value of the floating-point processor control word.
GETSTATUSFPQQ | Subroutine | Returns the value of the floating-point processor status word.
LCWRQQ | Subroutine | Same as SETCONTROLFPQQ.
SCWRQQ | Subroutine | Same as GETCONTROLFPQQ.
SETCONTROLFPQQ | Subroutine | Sets the value of the floating-point processor control word.
SSWRQQ | Subroutine | Same as GETSTATUSFPQQ.

IEEE Functionality
Name | Procedure Type | Description
--- | --- | ---
IEEE_FLAGS | Function | Sets, gets, or clears IEEE flags.
IEEE_HANDLER | Function | Establishes a handler for IEEE exceptions.

Serial Port I/O4
Name | Procedure Type | Description
--- | --- | ---
SPORT_CANCEL_IO | Function | Cancels any I/O in progress to the specified port.
SPORT_CONNECT | Function | Establishes the connection to a serial port and defines certain usage parameters.
SPORT_CONNECT_EX | Function | Establishes the connection to a serial port, defines certain usage parameters, and defines the size of the internal buffer for data reception.
SPORT_GET_HANDLE | Function | Returns the Windows* handle associated with the communications port.
SPORT_GET_STATE | Function | Returns the baud rate, parity, data bits, and stop bit settings of the communications port.
SPORT_GET_STATE_EX | Function | Returns the baud rate, parity, data bits setting, stop bits, and other settings of the communications port.
SPORT_GET_TIMEOUTS | Function | Returns the user selectable timeouts for the serial port.
SPORT_PEEK_DATA | Function | Returns information about the availability of input data.
SPORT_PEEK_LINE | Function | Returns information about the availability of input records.
SPORT_PURGE | Function | Executes a purge function on the specified port.
SPORT_READ_DATA | Function | Reads available data from the port specified.
SPORT_READ_LINE | Function | Reads a record from the port specified.
SPORT_RELEASE | Function | Releases a serial port that has previously been connected.
SPORT_SET_STATE | Function | Sets the baud rate, parity, data bits and stop bit settings of the communications port.
SPORT_SET_STATE_EX | Function | Sets the baud rate, parity, data bits setting, stop bits, and other settings of the communications port.
SPORT_SET_TIMEOUTS | Function | Sets the user selectable timeouts for the serial port.
SPORT_SHOW_STATE | Function | Displays the state of a port.
SPORT_SPECIAL_FUNC | Function | Executes a communications function on a specified port.
SPORT_WRITE_DATA | Function | Outputs data to a specified port.
SPORT_WRITE_LINE | Function | Outputs data to a specified port and follows it with a record terminator.

Miscellaneous
Name | Procedure Type | Description
--- | --- | ---
LNBLNK | Function | Returns the index of the last non-blank character in a string.
QSORT | Subroutine | Returns a sorted version of a one-dimensional array of a specified number of elements of a named size.
RINDEX | Function | Returns the index of the last occurrence of a substring in a string.
SCANENV | Subroutine | Scans the environment for the value of an environment variable.
TTYNAM | Subroutine | Checks whether a logical unit is a terminal.

1 This routine can also be specified as HOSTNM.

2 There is also a RANDOM subroutine in the portability library.

3 The two-digit year return value of DATE, IDATE, and JDATE may cause problems with the year 2000. Use the intrinsic subroutine DATE_AND_TIME instead.

4 W*S

Parent topic: Language Summary Tables