- Some Intrinsic functions in Fortran 95, 2003, 2008 are shown in this page.
- Functions introduced in this page are chosen based on webmaster's liking.
- Explanation of functions are made following gfortran manual.
Outline of this page
Some functions in Fortran 95, 2003, 2008
CPU_TIME : CPU elapsed time in seconds (Fortran 95)
Description:
- Returns a REAL value representing the elapsed CPU time in seconds.
- This is useful for testing segments of code to determine execution time.
- If a time source is available, time will be reported with microsecond resolution.
- If no time source is available, TIME is set to -1.0.
- Note that TIME may contain a, system dependent, arbitrary offset and may not start with 0.0.
- For CPU_TIME, the absolute value is meaningless, only differences between subsequent calls to this subroutine, as shown in the example below, should be used.
Class:
Subroutine
Syntax:
CALL CPU_TIME(TIME) |
Arguments:
TIME : The type shall be REAL with INTENT(OUT).
Return value:
None
Example:
program test_cpu_time real :: start, finish call cpu_time(start) ! put code to test here call cpu_time(finish) print '("Time = ",f6.3," seconds.")',finish-start end program test_cpu_time |
COMMAND_ARGUMENT_COUNT : Get number of command line arguments (Fortran 2003)
Description:
COMMAND_ARGUMENT_COUNT returns the number of arguments passed on the command line when the containing program was invoked.
Class:
Inquiry function
Syntax:
RESULT = COMMAND_ARGUMENT_COUNT() |
Arguments:
None
Return value:
The return value is an INTEGER of default kind.
Example:
program test_command_argument_count integer :: count count = command_argument_count() print *, count end program test_command_argument_count |
GET_COMMAND_ARGUMENT : Get command line arguments (Fortran 2003)
Description:
Retrieve the NUMBER-th argument that was passed on the command line when the containing program was invoked.
Class:
Subroutine
Syntax:
CALL GET_COMMAND_ARGUMENT(NUMBER [, VALUE, LENGTH, STATUS]) |
Arguments:
- NUMBER : Shall be a scalar of type INTEGER and of default kind, NUMBER >= 0
- VALUE : (Optional) Shall be a scalar of type CHARACTER and of default kind.
- LENGTH : (Optional) Shall be a scalar of type INTEGER and of default kind.
- STATUS : (Optional) Shall be a scalar of type INTEGER and of default kind.
Return value:
- After GET_COMMAND_ARGUMENT returns, the VALUE argument holds the NUMBER-th command line argument.
- If VALUE can not hold the argument, it is truncated to fit the length of VALUE.
- If there are less than NUMBER arguments specified at the command line, VALUE will be filled with blanks.
- If NUMBER = 0, VALUE is set to the name of the program (on systems that support this feature).
- The LENGTH argument contains the length of the NUMBER-th command line argument.
- If the argument retrieval fails, STATUS is a positive number; if VALUE contains a truncated command line argument, STATUS is -1; and otherwise the STATUS is zero.
Example:
PROGRAM test_get_command_argument INTEGER :: i CHARACTER(len=32) :: arg i = 0 DO CALL get_command_argument(i, arg) IF (LEN_TRIM(arg) == 0) EXIT WRITE (*,*) TRIM(arg) i = i+1 END DO END PROGRAM |
EXECUTE_COMMAND_LINE : Execute a shell command (Fortran 2008)
Description:
- EXECUTE_COMMAND_LINE runs a shell command, synchronously or asynchronously.
- The COMMAND argument is passed to the shell and executed, using the C library's system call. (The shell is sh on Unix systems, and cmd.exe on Windows.)
- If WAIT is present and has the value false, the execution of the command is asynchronous if the system supports it; otherwise, the command is executed synchronously.
- The three last arguments allow the user to get status information.
- After synchronous execution, EXITSTAT contains the integer exit code of the command, as returned by system.
- CMDSTAT is set to zero if the command line was executed (whatever its exit status was).
- CMDMSG is assigned an error message if an error has occurred.
- Note that the system function need not be thread-safe.
- It is the responsibility of the user to ensure that system is not called concurrently.
Class:
Subroutine
Syntax:
CALL EXECUTE_COMMAND_LINE(COMMAND [, WAIT, EXITSTAT, CMDSTAT,CMDMSG ]) |
Arguments:
- COMMAND : Shall be a default CHARACTER scalar.
- WAIT : (Optional) Shall be a default LOGICAL scalar.
- EXITSTAT : (Optional) Shall be an INTEGER of the default kind.
- CMDSTAT : (Optional) Shall be an INTEGER of the default kind.
- CMDMSG : (Optional) Shall be an CHARACTER scalar of the default kind.
Example:
program test_exec integer :: i call execute_command_line ("external_prog.exe", exitstat=i) print *, "Exit status of external_prog.exe was ", i call execute_command_line ("reindex_files.exe", wait=.false.) print *, "Now reindexing files in the background" end program test_exec |
Note:
- Because this intrinsic is implemented in terms of the system function call, its behavior with respect to signaling is processor dependent.
- In particular, on POSIX-compliant systems, the SIGINT and SIGQUIT signals will be ignored, and the SIGCHLD will be blocked.
- As such, if the parent process is terminated, the child process might not be terminated alongside.
ACOSH : Inverse hyperbolic cosine function (Fortran 2008)
Description:
ACOSH(X) computes the inverse hyperbolic cosine of X.
Class:
Elemental function
Syntax:
RESULT = ACOSH(X) |
Arguments:
X The type shall be REAL or COMPLEX.
Return value:
- The return value has the same type and kind as X.
- If X is complex, the imaginary part of the result is in radians and lies between 0 <= acosh(x) <= pi.
Example:
PROGRAM test_acosh REAL(8), DIMENSION(3) :: x = (/ 1.0, 2.0, 3.0 /) WRITE (*,*) ACOSH(x) END PROGRAM |
ASINH : Inverse hyperbolic sine function (Fortran 2008)
Description:
ASINH(X) computes the inverse hyperbolic sine of X.
Class:
Elemental function
Syntax:
RESULT = ASINH(X) |
Arguments:
X The type shall be REAL or COMPLEX.
Return value:
- The return value is of the same type and kind as X.
- If X is complex, the imaginary part of the result is in radians and lies between -pi/2 <= asinh(x) <=pi/2.
Example:
PROGRAM test_asinh REAL(8), DIMENSION(3) :: x = (/ -1.0, 0.0, 1.0 /) WRITE (*,*) ASINH(x) END PROGRAM |
ATANH : Inverse hyperbolic tangent function (Fortran 2008)
Description:
ATANH(X) computes the inverse hyperbolic tangent of X.
Class:
Elemental function
Syntax:
RESULT = ATANH(X) |
Arguments:
X : The type shall be REAL or COMPLEX.
Return value:
- The return value has same type and kind as X.
- If X is complex, the imaginary part of the result is in radians and lies between -pi/2 <= atanh(x) <=pi/2.
Example:
PROGRAM test_atanh REAL, DIMENSION(3) :: x = (/ -1.0, 0.0, 1.0 /) WRITE (*,*) ATANH(x) END PROGRAM |
BESSEL_J0 : Bessel function of the first kind of order 0 (Fortran 2008)
Description:
BESSEL_J0(X) computes the Bessel function of the first kind of order 0 of X.
Class:
Elemental function
Syntax:
RESULT = BESSEL_J0(X) |
Arguments:
X : The type shall be REAL, and it shall be scalar.
Return value:
The return value is of type REAL and lies in the range -0.4027... <= Bessel(0, x) <= 1. It has the same kind as X.
Example:
program test_besj0 real(8) :: x = 0.0_8 x = bessel_j0(x) end program test_besj0 |
BESSEL_J1 : Bessel function of the first kind of order 1 (Fortran 2008)
Description:
BESSEL_J1(X) computes the Bessel function of the first kind of order 1 of X.
Class:
Elemental function
Syntax:
RESULT = BESSEL_J1(X) |
Arguments:
X : The type shall be REAL, and it shall be scalar.
Return value:
The return value is of type REAL and it lies in the range -0.5818... <= Bessel(0, x) <= 0.5818. It has the same kind as X.
Example:
program test_besj1 real(8) :: x = 1.0_8 x = bessel_j1(x) end program test_besj1 |
BESSEL_JN : Bessel function of the first kind (Fortran 2008)
Description:
- BESSEL_JN(N, X) computes the Bessel function of the first kind of order N of X.
- If N and X are arrays, their ranks and shapes shall conform.
- BESSEL_JN(N1, N2, X) returns an array with the Bessel functions of the first kind of the orders N1 to N2.
Class:
Elemental function, except for the transformational function BESSEL_JN(N1,N2, X)
Syntax:
RESULT = BESSEL_JN(N, X) RESULT = BESSEL_JN(N1, N2, X) |
Arguments:
- N : Shall be a scalar or an array of type INTEGER.
- N1 : Shall be a non-negative scalar of type INTEGER.
- N2 : Shall be a non-negative scalar of type INTEGER.
- X : Shall be a scalar or an array of type REAL; for BESSEL_JN(N1,N2, X) it shall be scalar.
Return value:
The return value is a scalar of type REAL. It has the same kind as X.
Note: The transformational function uses a recurrence algorithm which might, for some values of X, lead to different results than calls to the elemental function.
Example:
program test_besjn real(8) :: x = 1.0_8 x = bessel_jn(5,x) end program test_besjn |
BESSEL_Y0 : Bessel function of the second kind of order 0 (Fortran 2008)
Description:
BESSEL_Y0(X) computes the Bessel function of the second kind of order 0 of X.
Class:
Elemental function
Syntax:
RESULT = BESSEL_Y0(X) |
Arguments:
X The type shall be REAL, and it shall be scalar.
Return value:
The return value is a scalar of type REAL. It has the same kind as X.
Example:
program test_besy0 real(8) :: x = 0.0_8 x = bessel_y0(x) end program test_besy0 |
BESSEL_Y1 : Bessel function of the second kind of order 1 (Fortran 2008)
Description:
BESSEL_Y1(X) computes the Bessel function of the second kind of order 1 of X.
Class:
Elemental functionSyntax:
RESULT = BESSEL_Y1(X) |
Arguments:
X The type shall be REAL, and it shall be scalar.
Return value:
The return value is a scalar of type REAL. It has the same kind as X.
Example:
program test_besy1 real(8) :: x = 1.0_8 x = bessel_y1(x) end program test_besy1 |
BESSEL_YN : Bessel function of the second kind (Fortran 2008)
Description:
- BESSEL_YN(N, X) computes the Bessel function of the second kind of order N of X.
- If N and X are arrays, their ranks and shapes shall conform.
- BESSEL_YN(N1, N2, X) returns an array with the Bessel functions of the first kind of the orders N1 to N2.
Class:
Elemental function, except for the transformational function BESSEL_YN(N1,N2, X)
Syntax:
RESULT = BESSEL_YN(N, X) RESULT = BESSEL_YN(N1, N2, X) |
Arguments:
- N : Shall be a scalar or an array of type INTEGER .
- N1 : Shall be a non-negative scalar of type INTEGER.
- N2 : Shall be a non-negative scalar of type INTEGER.
- X : Shall be a scalar or an array of type REAL; for BESSEL_YN(N1,N2, X) it shall be scalar.
Return value:
The return value is a scalar of type REAL. It has the same kind as X. Note: The transformational function uses a recurrence algorithm which might, for some values of X, lead to different results than calls to the elemental function.Example:
program test_besyn real(8) :: x = 1.0_8 x = bessel_yn(5,x) end program test_besyn |
GAMMA : Gamma function (Fortran 2008)
Description:
- GAMMA(X) computes Gamma (Γ) of X.
- For positive, integer values of X the Gamma function simplifies to the factorial function Γ(x) = (x - 1)!.
Γ(x)=∫tx-1e-tdt (t=0 → ∞)
Class:
Elemental function
Syntax:
X = GAMMA(X) |
Arguments:
X : Shall be of type REAL and neither zero nor a negative integer.
Return value:
The return value is of type REAL of the same kind as X.
Example:
program test_gamma real :: x = 1.0 x = gamma(x) ! returns 1.0 end program test_gamma |
LOG_GAMMA : Logarithm of the Gamma function (Fortran 2008)
Description:
LOG_GAMMA(X) computes the natural logarithm of the absolute value of the Gamma (Γ) function.
Class:
Elemental function
Syntax:
X = LOG_GAMMA(X) |
Arguments:
X : Shall be of type REAL and neither zero nor a negative integer.
Return value:
The return value is of type REAL of the same kind as X.
Example:
program test_log_gamma real :: x = 1.0 x = lgamma(x) ! returns 0.0 end program test_log_gamma |