2 Copyright (C) 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 This is part of the GNU Fortran manual.
5 For copying conditions, see the file gfortran.texi.
7 Permission is granted to copy, distribute and/or modify this document
8 under the terms of the GNU Free Documentation License, Version 1.2 or
9 any later version published by the Free Software Foundation; with the
10 Invariant Sections being ``GNU General Public License'' and ``Funding
11 Free Software'', the Front-Cover texts being (a) (see below), and with
12 the Back-Cover Texts being (b) (see below). A copy of the license is
13 included in the gfdl(7) man page.
16 Some basic guidelines for editing this document:
18 (1) The intrinsic procedures are to be listed in alphabetical order.
19 (2) The generic name is to be used.
20 (3) The specific names are included in the function index and in a
21 table at the end of the node (See ABS entry).
22 (4) Try to maintain the same style for each entry.
28 \gdef\acos{\mathop{\rm acos}\nolimits}
29 \gdef\asin{\mathop{\rm asin}\nolimits}
30 \gdef\atan{\mathop{\rm atan}\nolimits}
31 \gdef\acosh{\mathop{\rm acosh}\nolimits}
32 \gdef\asinh{\mathop{\rm asinh}\nolimits}
33 \gdef\atanh{\mathop{\rm atanh}\nolimits}
37 @node Intrinsic Procedures
38 @chapter Intrinsic Procedures
39 @cindex intrinsic procedures
42 * Introduction: Introduction to Intrinsics
43 * @code{ABORT}: ABORT, Abort the program
44 * @code{ABS}: ABS, Absolute value
45 * @code{ACCESS}: ACCESS, Checks file access modes
46 * @code{ACHAR}: ACHAR, Character in @acronym{ASCII} collating sequence
47 * @code{ACOS}: ACOS, Arccosine function
48 * @code{ACOSH}: ACOSH, Hyperbolic arccosine function
49 * @code{ADJUSTL}: ADJUSTL, Left adjust a string
50 * @code{ADJUSTR}: ADJUSTR, Right adjust a string
51 * @code{AIMAG}: AIMAG, Imaginary part of complex number
52 * @code{AINT}: AINT, Truncate to a whole number
53 * @code{ALARM}: ALARM, Set an alarm clock
54 * @code{ALL}: ALL, Determine if all values are true
55 * @code{ALLOCATED}: ALLOCATED, Status of allocatable entity
56 * @code{AND}: AND, Bitwise logical AND
57 * @code{ANINT}: ANINT, Nearest whole number
58 * @code{ANY}: ANY, Determine if any values are true
59 * @code{ASIN}: ASIN, Arcsine function
60 * @code{ASINH}: ASINH, Hyperbolic arcsine function
61 * @code{ASSOCIATED}: ASSOCIATED, Status of a pointer or pointer/target pair
62 * @code{ATAN}: ATAN, Arctangent function
63 * @code{ATAN2}: ATAN2, Arctangent function
64 * @code{ATANH}: ATANH, Hyperbolic arctangent function
65 * @code{BESSEL_J0}: BESSEL_J0, Bessel function of the first kind of order 0
66 * @code{BESSEL_J1}: BESSEL_J1, Bessel function of the first kind of order 1
67 * @code{BESSEL_JN}: BESSEL_JN, Bessel function of the first kind
68 * @code{BESSEL_Y0}: BESSEL_Y0, Bessel function of the second kind of order 0
69 * @code{BESSEL_Y1}: BESSEL_Y1, Bessel function of the second kind of order 1
70 * @code{BESSEL_YN}: BESSEL_YN, Bessel function of the second kind
71 * @code{BIT_SIZE}: BIT_SIZE, Bit size inquiry function
72 * @code{BTEST}: BTEST, Bit test function
73 * @code{C_ASSOCIATED}: C_ASSOCIATED, Status of a C pointer
74 * @code{C_F_POINTER}: C_F_POINTER, Convert C into Fortran pointer
75 * @code{C_F_PROCPOINTER}: C_F_PROCPOINTER, Convert C into Fortran procedure pointer
76 * @code{C_FUNLOC}: C_FUNLOC, Obtain the C address of a procedure
77 * @code{C_LOC}: C_LOC, Obtain the C address of an object
78 * @code{CEILING}: CEILING, Integer ceiling function
79 * @code{CHAR}: CHAR, Integer-to-character conversion function
80 * @code{CHDIR}: CHDIR, Change working directory
81 * @code{CHMOD}: CHMOD, Change access permissions of files
82 * @code{CMPLX}: CMPLX, Complex conversion function
83 * @code{COMMAND_ARGUMENT_COUNT}: COMMAND_ARGUMENT_COUNT, Get number of command line arguments
84 * @code{COMPLEX}: COMPLEX, Complex conversion function
85 * @code{CONJG}: CONJG, Complex conjugate function
86 * @code{COS}: COS, Cosine function
87 * @code{COSH}: COSH, Hyperbolic cosine function
88 * @code{COUNT}: COUNT, Count occurrences of TRUE in an array
89 * @code{CPU_TIME}: CPU_TIME, CPU time subroutine
90 * @code{CSHIFT}: CSHIFT, Circular shift elements of an array
91 * @code{CTIME}: CTIME, Subroutine (or function) to convert a time into a string
92 * @code{DATE_AND_TIME}: DATE_AND_TIME, Date and time subroutine
93 * @code{DBLE}: DBLE, Double precision conversion function
94 * @code{DCMPLX}: DCMPLX, Double complex conversion function
95 * @code{DFLOAT}: DFLOAT, Double precision conversion function
96 * @code{DIGITS}: DIGITS, Significant digits function
97 * @code{DIM}: DIM, Positive difference
98 * @code{DOT_PRODUCT}: DOT_PRODUCT, Dot product function
99 * @code{DPROD}: DPROD, Double product function
100 * @code{DREAL}: DREAL, Double real part function
101 * @code{DTIME}: DTIME, Execution time subroutine (or function)
102 * @code{EOSHIFT}: EOSHIFT, End-off shift elements of an array
103 * @code{EPSILON}: EPSILON, Epsilon function
104 * @code{ERF}: ERF, Error function
105 * @code{ERFC}: ERFC, Complementary error function
106 * @code{ERFC_SCALED}: ERFC_SCALED, Exponentially-scaled complementary error function
107 * @code{ETIME}: ETIME, Execution time subroutine (or function)
108 * @code{EXIT}: EXIT, Exit the program with status.
109 * @code{EXP}: EXP, Exponential function
110 * @code{EXPONENT}: EXPONENT, Exponent function
111 * @code{FDATE}: FDATE, Subroutine (or function) to get the current time as a string
112 * @code{FGET}: FGET, Read a single character in stream mode from stdin
113 * @code{FGETC}: FGETC, Read a single character in stream mode
114 * @code{FLOAT}: FLOAT, Convert integer to default real
115 * @code{FLOOR}: FLOOR, Integer floor function
116 * @code{FLUSH}: FLUSH, Flush I/O unit(s)
117 * @code{FNUM}: FNUM, File number function
118 * @code{FPUT}: FPUT, Write a single character in stream mode to stdout
119 * @code{FPUTC}: FPUTC, Write a single character in stream mode
120 * @code{FRACTION}: FRACTION, Fractional part of the model representation
121 * @code{FREE}: FREE, Memory de-allocation subroutine
122 * @code{FSEEK}: FSEEK, Low level file positioning subroutine
123 * @code{FSTAT}: FSTAT, Get file status
124 * @code{FTELL}: FTELL, Current stream position
125 * @code{GAMMA}: GAMMA, Gamma function
126 * @code{GERROR}: GERROR, Get last system error message
127 * @code{GETARG}: GETARG, Get command line arguments
128 * @code{GET_COMMAND}: GET_COMMAND, Get the entire command line
129 * @code{GET_COMMAND_ARGUMENT}: GET_COMMAND_ARGUMENT, Get command line arguments
130 * @code{GETCWD}: GETCWD, Get current working directory
131 * @code{GETENV}: GETENV, Get an environmental variable
132 * @code{GET_ENVIRONMENT_VARIABLE}: GET_ENVIRONMENT_VARIABLE, Get an environmental variable
133 * @code{GETGID}: GETGID, Group ID function
134 * @code{GETLOG}: GETLOG, Get login name
135 * @code{GETPID}: GETPID, Process ID function
136 * @code{GETUID}: GETUID, User ID function
137 * @code{GMTIME}: GMTIME, Convert time to GMT info
138 * @code{HOSTNM}: HOSTNM, Get system host name
139 * @code{HUGE}: HUGE, Largest number of a kind
140 * @code{HYPOT}: HYPOT, Euclidian distance function
141 * @code{IACHAR}: IACHAR, Code in @acronym{ASCII} collating sequence
142 * @code{IAND}: IAND, Bitwise logical and
143 * @code{IARGC}: IARGC, Get the number of command line arguments
144 * @code{IBCLR}: IBCLR, Clear bit
145 * @code{IBITS}: IBITS, Bit extraction
146 * @code{IBSET}: IBSET, Set bit
147 * @code{ICHAR}: ICHAR, Character-to-integer conversion function
148 * @code{IDATE}: IDATE, Current local time (day/month/year)
149 * @code{IEOR}: IEOR, Bitwise logical exclusive or
150 * @code{IERRNO}: IERRNO, Function to get the last system error number
151 * @code{INDEX}: INDEX intrinsic, Position of a substring within a string
152 * @code{INT}: INT, Convert to integer type
153 * @code{INT2}: INT2, Convert to 16-bit integer type
154 * @code{INT8}: INT8, Convert to 64-bit integer type
155 * @code{IOR}: IOR, Bitwise logical or
156 * @code{IRAND}: IRAND, Integer pseudo-random number
157 * @code{IS_IOSTAT_END}: IS_IOSTAT_END, Test for end-of-file value
158 * @code{IS_IOSTAT_EOR}: IS_IOSTAT_EOR, Test for end-of-record value
159 * @code{ISATTY}: ISATTY, Whether a unit is a terminal device
160 * @code{ISHFT}: ISHFT, Shift bits
161 * @code{ISHFTC}: ISHFTC, Shift bits circularly
162 * @code{ISNAN}: ISNAN, Tests for a NaN
163 * @code{ITIME}: ITIME, Current local time (hour/minutes/seconds)
164 * @code{KILL}: KILL, Send a signal to a process
165 * @code{KIND}: KIND, Kind of an entity
166 * @code{LBOUND}: LBOUND, Lower dimension bounds of an array
167 * @code{LEN}: LEN, Length of a character entity
168 * @code{LEN_TRIM}: LEN_TRIM, Length of a character entity without trailing blank characters
169 * @code{LOG_GAMMA}: LOG_GAMMA, Logarithm of the Gamma function
170 * @code{LGE}: LGE, Lexical greater than or equal
171 * @code{LGT}: LGT, Lexical greater than
172 * @code{LINK}: LINK, Create a hard link
173 * @code{LLE}: LLE, Lexical less than or equal
174 * @code{LLT}: LLT, Lexical less than
175 * @code{LNBLNK}: LNBLNK, Index of the last non-blank character in a string
176 * @code{LOC}: LOC, Returns the address of a variable
177 * @code{LOG}: LOG, Logarithm function
178 * @code{LOG10}: LOG10, Base 10 logarithm function
179 * @code{LOGICAL}: LOGICAL, Convert to logical type
180 * @code{LONG}: LONG, Convert to integer type
181 * @code{LSHIFT}: LSHIFT, Left shift bits
182 * @code{LSTAT}: LSTAT, Get file status
183 * @code{LTIME}: LTIME, Convert time to local time info
184 * @code{MALLOC}: MALLOC, Dynamic memory allocation function
185 * @code{MATMUL}: MATMUL, matrix multiplication
186 * @code{MAX}: MAX, Maximum value of an argument list
187 * @code{MAXEXPONENT}: MAXEXPONENT, Maximum exponent of a real kind
188 * @code{MAXLOC}: MAXLOC, Location of the maximum value within an array
189 * @code{MAXVAL}: MAXVAL, Maximum value of an array
190 * @code{MCLOCK}: MCLOCK, Time function
191 * @code{MCLOCK8}: MCLOCK8, Time function (64-bit)
192 * @code{MERGE}: MERGE, Merge arrays
193 * @code{MIN}: MIN, Minimum value of an argument list
194 * @code{MINEXPONENT}: MINEXPONENT, Minimum exponent of a real kind
195 * @code{MINLOC}: MINLOC, Location of the minimum value within an array
196 * @code{MINVAL}: MINVAL, Minimum value of an array
197 * @code{MOD}: MOD, Remainder function
198 * @code{MODULO}: MODULO, Modulo function
199 * @code{MOVE_ALLOC}: MOVE_ALLOC, Move allocation from one object to another
200 * @code{MVBITS}: MVBITS, Move bits from one integer to another
201 * @code{NEAREST}: NEAREST, Nearest representable number
202 * @code{NEW_LINE}: NEW_LINE, New line character
203 * @code{NINT}: NINT, Nearest whole number
204 * @code{NOT}: NOT, Logical negation
205 * @code{NULL}: NULL, Function that returns an disassociated pointer
206 * @code{OR}: OR, Bitwise logical OR
207 * @code{PACK}: PACK, Pack an array into an array of rank one
208 * @code{PERROR}: PERROR, Print system error message
209 * @code{PRECISION}: PRECISION, Decimal precision of a real kind
210 * @code{PRESENT}: PRESENT, Determine whether an optional dummy argument is specified
211 * @code{PRODUCT}: PRODUCT, Product of array elements
212 * @code{RADIX}: RADIX, Base of a data model
213 * @code{RANDOM_NUMBER}: RANDOM_NUMBER, Pseudo-random number
214 * @code{RANDOM_SEED}: RANDOM_SEED, Initialize a pseudo-random number sequence
215 * @code{RAND}: RAND, Real pseudo-random number
216 * @code{RANGE}: RANGE, Decimal exponent range of a real kind
217 * @code{RAN}: RAN, Real pseudo-random number
218 * @code{REAL}: REAL, Convert to real type
219 * @code{RENAME}: RENAME, Rename a file
220 * @code{REPEAT}: REPEAT, Repeated string concatenation
221 * @code{RESHAPE}: RESHAPE, Function to reshape an array
222 * @code{RRSPACING}: RRSPACING, Reciprocal of the relative spacing
223 * @code{RSHIFT}: RSHIFT, Right shift bits
224 * @code{SCALE}: SCALE, Scale a real value
225 * @code{SCAN}: SCAN, Scan a string for the presence of a set of characters
226 * @code{SECNDS}: SECNDS, Time function
227 * @code{SECOND}: SECOND, CPU time function
228 * @code{SELECTED_CHAR_KIND}: SELECTED_CHAR_KIND, Choose character kind
229 * @code{SELECTED_INT_KIND}: SELECTED_INT_KIND, Choose integer kind
230 * @code{SELECTED_REAL_KIND}: SELECTED_REAL_KIND, Choose real kind
231 * @code{SET_EXPONENT}: SET_EXPONENT, Set the exponent of the model
232 * @code{SHAPE}: SHAPE, Determine the shape of an array
233 * @code{SIGN}: SIGN, Sign copying function
234 * @code{SIGNAL}: SIGNAL, Signal handling subroutine (or function)
235 * @code{SIN}: SIN, Sine function
236 * @code{SINH}: SINH, Hyperbolic sine function
237 * @code{SIZE}: SIZE, Function to determine the size of an array
238 * @code{SIZEOF}: SIZEOF, Determine the size in bytes of an expression
239 * @code{SLEEP}: SLEEP, Sleep for the specified number of seconds
240 * @code{SNGL}: SNGL, Convert double precision real to default real
241 * @code{SPACING}: SPACING, Smallest distance between two numbers of a given type
242 * @code{SPREAD}: SPREAD, Add a dimension to an array
243 * @code{SQRT}: SQRT, Square-root function
244 * @code{SRAND}: SRAND, Reinitialize the random number generator
245 * @code{STAT}: STAT, Get file status
246 * @code{SUM}: SUM, Sum of array elements
247 * @code{SYMLNK}: SYMLNK, Create a symbolic link
248 * @code{SYSTEM}: SYSTEM, Execute a shell command
249 * @code{SYSTEM_CLOCK}: SYSTEM_CLOCK, Time function
250 * @code{TAN}: TAN, Tangent function
251 * @code{TANH}: TANH, Hyperbolic tangent function
252 * @code{TIME}: TIME, Time function
253 * @code{TIME8}: TIME8, Time function (64-bit)
254 * @code{TINY}: TINY, Smallest positive number of a real kind
255 * @code{TRANSFER}: TRANSFER, Transfer bit patterns
256 * @code{TRANSPOSE}: TRANSPOSE, Transpose an array of rank two
257 * @code{TRIM}: TRIM, Remove trailing blank characters of a string
258 * @code{TTYNAM}: TTYNAM, Get the name of a terminal device.
259 * @code{UBOUND}: UBOUND, Upper dimension bounds of an array
260 * @code{UMASK}: UMASK, Set the file creation mask
261 * @code{UNLINK}: UNLINK, Remove a file from the file system
262 * @code{UNPACK}: UNPACK, Unpack an array of rank one into an array
263 * @code{VERIFY}: VERIFY, Scan a string for the absence of a set of characters
264 * @code{XOR}: XOR, Bitwise logical exclusive or
267 @node Introduction to Intrinsics
268 @section Introduction to intrinsic procedures
270 The intrinsic procedures provided by GNU Fortran include all of the
271 intrinsic procedures required by the Fortran 95 standard, a set of
272 intrinsic procedures for backwards compatibility with G77, and a
273 selection of intrinsic procedures from the Fortran 2003 and Fortran 2008
274 standards. Any conflict between a description here and a description in
275 either the Fortran 95 standard, the Fortran 2003 standard or the Fortran
276 2008 standard is unintentional, and the standard(s) should be considered
279 The enumeration of the @code{KIND} type parameter is processor defined in
280 the Fortran 95 standard. GNU Fortran defines the default integer type and
281 default real type by @code{INTEGER(KIND=4)} and @code{REAL(KIND=4)},
282 respectively. The standard mandates that both data types shall have
283 another kind, which have more precision. On typical target architectures
284 supported by @command{gfortran}, this kind type parameter is @code{KIND=8}.
285 Hence, @code{REAL(KIND=8)} and @code{DOUBLE PRECISION} are equivalent.
286 In the description of generic intrinsic procedures, the kind type parameter
287 will be specified by @code{KIND=*}, and in the description of specific
288 names for an intrinsic procedure the kind type parameter will be explicitly
289 given (e.g., @code{REAL(KIND=4)} or @code{REAL(KIND=8)}). Finally, for
290 brevity the optional @code{KIND=} syntax will be omitted.
292 Many of the intrinsic procedures take one or more optional arguments.
293 This document follows the convention used in the Fortran 95 standard,
294 and denotes such arguments by square brackets.
296 GNU Fortran offers the @option{-std=f95} and @option{-std=gnu} options,
297 which can be used to restrict the set of intrinsic procedures to a
298 given standard. By default, @command{gfortran} sets the @option{-std=gnu}
299 option, and so all intrinsic procedures described here are accepted. There
300 is one caveat. For a select group of intrinsic procedures, @command{g77}
301 implemented both a function and a subroutine. Both classes
302 have been implemented in @command{gfortran} for backwards compatibility
303 with @command{g77}. It is noted here that these functions and subroutines
304 cannot be intermixed in a given subprogram. In the descriptions that follow,
305 the applicable standard for each intrinsic procedure is noted.
310 @section @code{ABORT} --- Abort the program
312 @cindex program termination, with core dump
313 @cindex terminate program, with core dump
317 @item @emph{Description}:
318 @code{ABORT} causes immediate termination of the program. On operating
319 systems that support a core dump, @code{ABORT} will produce a core dump,
320 which is suitable for debugging purposes.
322 @item @emph{Standard}:
331 @item @emph{Return value}:
334 @item @emph{Example}:
337 integer :: i = 1, j = 2
338 if (i /= j) call abort
339 end program test_abort
342 @item @emph{See also}:
343 @ref{EXIT}, @ref{KILL}
350 @section @code{ABS} --- Absolute value
357 @cindex absolute value
360 @item @emph{Description}:
361 @code{ABS(A)} computes the absolute value of @code{A}.
363 @item @emph{Standard}:
364 Fortran 77 and later, has overloads that are GNU extensions
370 @code{RESULT = ABS(A)}
372 @item @emph{Arguments}:
373 @multitable @columnfractions .15 .70
374 @item @var{A} @tab The type of the argument shall be an @code{INTEGER},
375 @code{REAL}, or @code{COMPLEX}.
378 @item @emph{Return value}:
379 The return value is of the same type and
380 kind as the argument except the return value is @code{REAL} for a
381 @code{COMPLEX} argument.
383 @item @emph{Example}:
388 complex :: z = (-1.e0,0.e0)
395 @item @emph{Specific names}:
396 @multitable @columnfractions .20 .20 .20 .25
397 @item Name @tab Argument @tab Return type @tab Standard
398 @item @code{CABS(A)} @tab @code{COMPLEX(4) Z} @tab @code{REAL(4)} @tab Fortran 77 and later
399 @item @code{DABS(A)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
400 @item @code{IABS(A)} @tab @code{INTEGER(4) I} @tab @code{INTEGER(4)} @tab Fortran 77 and later
401 @item @code{ZABS(A)} @tab @code{COMPLEX(8) Z} @tab @code{COMPLEX(8)} @tab GNU extension
402 @item @code{CDABS(A)} @tab @code{COMPLEX(8) Z} @tab @code{COMPLEX(8)} @tab GNU extension
409 @section @code{ACCESS} --- Checks file access modes
411 @cindex file system, access mode
414 @item @emph{Description}:
415 @code{ACCESS(NAME, MODE)} checks whether the file @var{NAME}
416 exists, is readable, writable or executable. Except for the
417 executable check, @code{ACCESS} can be replaced by
418 Fortran 95's @code{INQUIRE}.
420 @item @emph{Standard}:
427 @code{RESULT = ACCESS(NAME, MODE)}
429 @item @emph{Arguments}:
430 @multitable @columnfractions .15 .70
431 @item @var{NAME} @tab Scalar @code{CHARACTER} of default kind with the
432 file name. Tailing blank are ignored unless the character @code{achar(0)}
433 is present, then all characters up to and excluding @code{achar(0)} are
435 @item @var{MODE} @tab Scalar @code{CHARACTER} of default kind with the
436 file access mode, may be any concatenation of @code{"r"} (readable),
437 @code{"w"} (writable) and @code{"x"} (executable), or @code{" "} to check
441 @item @emph{Return value}:
442 Returns a scalar @code{INTEGER}, which is @code{0} if the file is
443 accessible in the given mode; otherwise or if an invalid argument
444 has been given for @code{MODE} the value @code{1} is returned.
446 @item @emph{Example}:
450 character(len=*), parameter :: file = 'test.dat'
451 character(len=*), parameter :: file2 = 'test.dat '//achar(0)
452 if(access(file,' ') == 0) print *, trim(file),' is exists'
453 if(access(file,'r') == 0) print *, trim(file),' is readable'
454 if(access(file,'w') == 0) print *, trim(file),' is writable'
455 if(access(file,'x') == 0) print *, trim(file),' is executable'
456 if(access(file2,'rwx') == 0) &
457 print *, trim(file2),' is readable, writable and executable'
458 end program access_test
460 @item @emph{Specific names}:
461 @item @emph{See also}:
468 @section @code{ACHAR} --- Character in @acronym{ASCII} collating sequence
470 @cindex @acronym{ASCII} collating sequence
471 @cindex collating sequence, @acronym{ASCII}
474 @item @emph{Description}:
475 @code{ACHAR(I)} returns the character located at position @code{I}
476 in the @acronym{ASCII} collating sequence.
478 @item @emph{Standard}:
479 Fortran 77 and later, with @var{KIND} argument Fortran 2003 and later
485 @code{RESULT = ACHAR(I [, KIND])}
487 @item @emph{Arguments}:
488 @multitable @columnfractions .15 .70
489 @item @var{I} @tab The type shall be @code{INTEGER}.
490 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
491 expression indicating the kind parameter of
495 @item @emph{Return value}:
496 The return value is of type @code{CHARACTER} with a length of one.
497 If the @var{KIND} argument is present, the return value is of the
498 specified kind and of the default kind otherwise.
500 @item @emph{Example}:
505 end program test_achar
509 See @ref{ICHAR} for a discussion of converting between numerical values
510 and formatted string representations.
512 @item @emph{See also}:
513 @ref{CHAR}, @ref{IACHAR}, @ref{ICHAR}
520 @section @code{ACOS} --- Arccosine function
523 @cindex trigonometric function, cosine, inverse
524 @cindex cosine, inverse
527 @item @emph{Description}:
528 @code{ACOS(X)} computes the arccosine of @var{X} (inverse of @code{COS(X)}).
530 @item @emph{Standard}:
537 @code{RESULT = ACOS(X)}
539 @item @emph{Arguments}:
540 @multitable @columnfractions .15 .70
541 @item @var{X} @tab The type shall be @code{REAL} with a magnitude that is
545 @item @emph{Return value}:
546 The return value is of type @code{REAL} and it lies in the
547 range @math{ 0 \leq \acos(x) \leq \pi}. The return value if of the same
550 @item @emph{Example}:
553 real(8) :: x = 0.866_8
555 end program test_acos
558 @item @emph{Specific names}:
559 @multitable @columnfractions .20 .20 .20 .25
560 @item Name @tab Argument @tab Return type @tab Standard
561 @item @code{DACOS(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
564 @item @emph{See also}:
565 Inverse function: @ref{COS}
572 @section @code{ACOSH} --- Hyperbolic arccosine function
575 @cindex area hyperbolic cosine
576 @cindex hyperbolic arccosine
577 @cindex hyperbolic function, cosine, inverse
578 @cindex cosine, hyperbolic, inverse
581 @item @emph{Description}:
582 @code{ACOSH(X)} computes the hyperbolic arccosine of @var{X} (inverse of
585 @item @emph{Standard}:
586 Fortran 2008 and later
592 @code{RESULT = ACOSH(X)}
594 @item @emph{Arguments}:
595 @multitable @columnfractions .15 .70
596 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
599 @item @emph{Return value}:
600 The return value has the same type and kind as @var{X}
602 @item @emph{Example}:
605 REAL(8), DIMENSION(3) :: x = (/ 1.0, 2.0, 3.0 /)
610 @item @emph{Specific names}:
611 @multitable @columnfractions .20 .20 .20 .25
612 @item Name @tab Argument @tab Return type @tab Standard
613 @item @code{DACOSH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
616 @item @emph{See also}:
617 Inverse function: @ref{COSH}
623 @section @code{ADJUSTL} --- Left adjust a string
625 @cindex string, adjust left
626 @cindex adjust string
629 @item @emph{Description}:
630 @code{ADJUSTL(STRING)} will left adjust a string by removing leading spaces.
631 Spaces are inserted at the end of the string as needed.
633 @item @emph{Standard}:
640 @code{RESULT = ADJUSTL(STRING)}
642 @item @emph{Arguments}:
643 @multitable @columnfractions .15 .70
644 @item @var{STRING} @tab The type shall be @code{CHARACTER}.
647 @item @emph{Return value}:
648 The return value is of type @code{CHARACTER} and of the same kind as
649 @var{STRING} where leading spaces are removed and the same number of
650 spaces are inserted on the end of @var{STRING}.
652 @item @emph{Example}:
655 character(len=20) :: str = ' gfortran'
658 end program test_adjustl
661 @item @emph{See also}:
662 @ref{ADJUSTR}, @ref{TRIM}
668 @section @code{ADJUSTR} --- Right adjust a string
670 @cindex string, adjust right
671 @cindex adjust string
674 @item @emph{Description}:
675 @code{ADJUSTR(STRING)} will right adjust a string by removing trailing spaces.
676 Spaces are inserted at the start of the string as needed.
678 @item @emph{Standard}:
685 @code{RESULT = ADJUSTR(STRING)}
687 @item @emph{Arguments}:
688 @multitable @columnfractions .15 .70
689 @item @var{STR} @tab The type shall be @code{CHARACTER}.
692 @item @emph{Return value}:
693 The return value is of type @code{CHARACTER} and of the same kind as
694 @var{STRING} where trailing spaces are removed and the same number of
695 spaces are inserted at the start of @var{STRING}.
697 @item @emph{Example}:
700 character(len=20) :: str = 'gfortran'
703 end program test_adjustr
706 @item @emph{See also}:
707 @ref{ADJUSTL}, @ref{TRIM}
713 @section @code{AIMAG} --- Imaginary part of complex number
718 @cindex complex numbers, imaginary part
721 @item @emph{Description}:
722 @code{AIMAG(Z)} yields the imaginary part of complex argument @code{Z}.
723 The @code{IMAG(Z)} and @code{IMAGPART(Z)} intrinsic functions are provided
724 for compatibility with @command{g77}, and their use in new code is
725 strongly discouraged.
727 @item @emph{Standard}:
728 Fortran 77 and later, has overloads that are GNU extensions
734 @code{RESULT = AIMAG(Z)}
736 @item @emph{Arguments}:
737 @multitable @columnfractions .15 .70
738 @item @var{Z} @tab The type of the argument shall be @code{COMPLEX}.
741 @item @emph{Return value}:
742 The return value is of type @code{REAL} with the
743 kind type parameter of the argument.
745 @item @emph{Example}:
750 z4 = cmplx(1.e0_4, 0.e0_4)
751 z8 = cmplx(0.e0_8, 1.e0_8)
752 print *, aimag(z4), dimag(z8)
753 end program test_aimag
756 @item @emph{Specific names}:
757 @multitable @columnfractions .20 .20 .20 .25
758 @item Name @tab Argument @tab Return type @tab Standard
759 @item @code{DIMAG(Z)} @tab @code{COMPLEX(8) Z} @tab @code{REAL(8)} @tab GNU extension
760 @item @code{IMAG(Z)} @tab @code{COMPLEX Z} @tab @code{REAL} @tab GNU extension
761 @item @code{IMAGPART(Z)} @tab @code{COMPLEX Z} @tab @code{REAL} @tab GNU extension
768 @section @code{AINT} --- Truncate to a whole number
772 @cindex rounding, floor
775 @item @emph{Description}:
776 @code{AINT(A [, KIND])} truncates its argument to a whole number.
778 @item @emph{Standard}:
785 @code{RESULT = AINT(A [, KIND])}
787 @item @emph{Arguments}:
788 @multitable @columnfractions .15 .70
789 @item @var{A} @tab The type of the argument shall be @code{REAL}.
790 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
791 expression indicating the kind parameter of
795 @item @emph{Return value}:
796 The return value is of type @code{REAL} with the kind type parameter of the
797 argument if the optional @var{KIND} is absent; otherwise, the kind
798 type parameter will be given by @var{KIND}. If the magnitude of
799 @var{X} is less than one, @code{AINT(X)} returns zero. If the
800 magnitude is equal to or greater than one then it returns the largest
801 whole number that does not exceed its magnitude. The sign is the same
802 as the sign of @var{X}.
804 @item @emph{Example}:
811 print *, aint(x4), dint(x8)
813 end program test_aint
816 @item @emph{Specific names}:
817 @multitable @columnfractions .20 .20 .20 .25
818 @item Name @tab Argument @tab Return type @tab Standard
819 @item @code{DINT(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
826 @section @code{ALARM} --- Execute a routine after a given delay
828 @cindex delayed execution
831 @item @emph{Description}:
832 @code{ALARM(SECONDS, HANDLER [, STATUS])} causes external subroutine @var{HANDLER}
833 to be executed after a delay of @var{SECONDS} by using @code{alarm(2)} to
834 set up a signal and @code{signal(2)} to catch it. If @var{STATUS} is
835 supplied, it will be returned with the number of seconds remaining until
836 any previously scheduled alarm was due to be delivered, or zero if there
837 was no previously scheduled alarm.
839 @item @emph{Standard}:
846 @code{CALL ALARM(SECONDS, HANDLER [, STATUS])}
848 @item @emph{Arguments}:
849 @multitable @columnfractions .15 .70
850 @item @var{SECONDS} @tab The type of the argument shall be a scalar
851 @code{INTEGER}. It is @code{INTENT(IN)}.
852 @item @var{HANDLER} @tab Signal handler (@code{INTEGER FUNCTION} or
853 @code{SUBROUTINE}) or dummy/global @code{INTEGER} scalar. The scalar
854 values may be either @code{SIG_IGN=1} to ignore the alarm generated
855 or @code{SIG_DFL=0} to set the default action. It is @code{INTENT(IN)}.
856 @item @var{STATUS} @tab (Optional) @var{STATUS} shall be a scalar
857 variable of the default @code{INTEGER} kind. It is @code{INTENT(OUT)}.
860 @item @emph{Example}:
863 external handler_print
865 call alarm (3, handler_print, i)
868 end program test_alarm
870 This will cause the external routine @var{handler_print} to be called
877 @section @code{ALL} --- All values in @var{MASK} along @var{DIM} are true
879 @cindex array, apply condition
880 @cindex array, condition testing
883 @item @emph{Description}:
884 @code{ALL(MASK [, DIM])} determines if all the values are true in @var{MASK}
885 in the array along dimension @var{DIM}.
887 @item @emph{Standard}:
891 Transformational function
894 @code{RESULT = ALL(MASK [, DIM])}
896 @item @emph{Arguments}:
897 @multitable @columnfractions .15 .70
898 @item @var{MASK} @tab The type of the argument shall be @code{LOGICAL} and
899 it shall not be scalar.
900 @item @var{DIM} @tab (Optional) @var{DIM} shall be a scalar integer
901 with a value that lies between one and the rank of @var{MASK}.
904 @item @emph{Return value}:
905 @code{ALL(MASK)} returns a scalar value of type @code{LOGICAL} where
906 the kind type parameter is the same as the kind type parameter of
907 @var{MASK}. If @var{DIM} is present, then @code{ALL(MASK, DIM)} returns
908 an array with the rank of @var{MASK} minus 1. The shape is determined from
909 the shape of @var{MASK} where the @var{DIM} dimension is elided.
913 @code{ALL(MASK)} is true if all elements of @var{MASK} are true.
914 It also is true if @var{MASK} has zero size; otherwise, it is false.
916 If the rank of @var{MASK} is one, then @code{ALL(MASK,DIM)} is equivalent
917 to @code{ALL(MASK)}. If the rank is greater than one, then @code{ALL(MASK,DIM)}
918 is determined by applying @code{ALL} to the array sections.
921 @item @emph{Example}:
925 l = all((/.true., .true., .true./))
930 integer a(2,3), b(2,3)
934 print *, all(a .eq. b, 1)
935 print *, all(a .eq. b, 2)
936 end subroutine section
944 @section @code{ALLOCATED} --- Status of an allocatable entity
946 @cindex allocation, status
949 @item @emph{Description}:
950 @code{ALLOCATED(ARRAY)} checks the status of whether @var{X} is allocated.
952 @item @emph{Standard}:
959 @code{RESULT = ALLOCATED(ARRAY)}
961 @item @emph{Arguments}:
962 @multitable @columnfractions .15 .70
963 @item @var{ARRAY} @tab The argument shall be an @code{ALLOCATABLE} array.
966 @item @emph{Return value}:
967 The return value is a scalar @code{LOGICAL} with the default logical
968 kind type parameter. If @var{ARRAY} is allocated, @code{ALLOCATED(ARRAY)}
969 is @code{.TRUE.}; otherwise, it returns @code{.FALSE.}
971 @item @emph{Example}:
973 program test_allocated
975 real(4), allocatable :: x(:)
976 if (allocated(x) .eqv. .false.) allocate(x(i))
977 end program test_allocated
984 @section @code{AND} --- Bitwise logical AND
986 @cindex bitwise logical and
987 @cindex logical and, bitwise
990 @item @emph{Description}:
991 Bitwise logical @code{AND}.
993 This intrinsic routine is provided for backwards compatibility with
994 GNU Fortran 77. For integer arguments, programmers should consider
995 the use of the @ref{IAND} intrinsic defined by the Fortran standard.
997 @item @emph{Standard}:
1003 @item @emph{Syntax}:
1004 @code{RESULT = AND(I, J)}
1006 @item @emph{Arguments}:
1007 @multitable @columnfractions .15 .70
1008 @item @var{I} @tab The type shall be either a scalar @code{INTEGER}
1009 type or a scalar @code{LOGICAL} type.
1010 @item @var{J} @tab The type shall be the same as the type of @var{I}.
1013 @item @emph{Return value}:
1014 The return type is either a scalar @code{INTEGER} or a scalar
1015 @code{LOGICAL}. If the kind type parameters differ, then the
1016 smaller kind type is implicitly converted to larger kind, and the
1017 return has the larger kind.
1019 @item @emph{Example}:
1022 LOGICAL :: T = .TRUE., F = .FALSE.
1024 DATA a / Z'F' /, b / Z'3' /
1026 WRITE (*,*) AND(T, T), AND(T, F), AND(F, T), AND(F, F)
1027 WRITE (*,*) AND(a, b)
1031 @item @emph{See also}:
1032 Fortran 95 elemental function: @ref{IAND}
1038 @section @code{ANINT} --- Nearest whole number
1042 @cindex rounding, ceiling
1045 @item @emph{Description}:
1046 @code{ANINT(A [, KIND])} rounds its argument to the nearest whole number.
1048 @item @emph{Standard}:
1049 Fortran 77 and later
1054 @item @emph{Syntax}:
1055 @code{RESULT = ANINT(A [, KIND])}
1057 @item @emph{Arguments}:
1058 @multitable @columnfractions .15 .70
1059 @item @var{A} @tab The type of the argument shall be @code{REAL}.
1060 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
1061 expression indicating the kind parameter of
1065 @item @emph{Return value}:
1066 The return value is of type real with the kind type parameter of the
1067 argument if the optional @var{KIND} is absent; otherwise, the kind
1068 type parameter will be given by @var{KIND}. If @var{A} is greater than
1069 zero, @code{ANINT(A)} returns @code{AINT(X+0.5)}. If @var{A} is
1070 less than or equal to zero then it returns @code{AINT(X-0.5)}.
1072 @item @emph{Example}:
1079 print *, anint(x4), dnint(x8)
1081 end program test_anint
1084 @item @emph{Specific names}:
1085 @multitable @columnfractions .20 .20 .20 .25
1086 @item Name @tab Argument @tab Return type @tab Standard
1087 @item @code{DNINT(A)} @tab @code{REAL(8) A} @tab @code{REAL(8)} @tab Fortran 77 and later
1094 @section @code{ANY} --- Any value in @var{MASK} along @var{DIM} is true
1096 @cindex array, apply condition
1097 @cindex array, condition testing
1100 @item @emph{Description}:
1101 @code{ANY(MASK [, DIM])} determines if any of the values in the logical array
1102 @var{MASK} along dimension @var{DIM} are @code{.TRUE.}.
1104 @item @emph{Standard}:
1105 Fortran 95 and later
1108 Transformational function
1110 @item @emph{Syntax}:
1111 @code{RESULT = ANY(MASK [, DIM])}
1113 @item @emph{Arguments}:
1114 @multitable @columnfractions .15 .70
1115 @item @var{MASK} @tab The type of the argument shall be @code{LOGICAL} and
1116 it shall not be scalar.
1117 @item @var{DIM} @tab (Optional) @var{DIM} shall be a scalar integer
1118 with a value that lies between one and the rank of @var{MASK}.
1121 @item @emph{Return value}:
1122 @code{ANY(MASK)} returns a scalar value of type @code{LOGICAL} where
1123 the kind type parameter is the same as the kind type parameter of
1124 @var{MASK}. If @var{DIM} is present, then @code{ANY(MASK, DIM)} returns
1125 an array with the rank of @var{MASK} minus 1. The shape is determined from
1126 the shape of @var{MASK} where the @var{DIM} dimension is elided.
1130 @code{ANY(MASK)} is true if any element of @var{MASK} is true;
1131 otherwise, it is false. It also is false if @var{MASK} has zero size.
1133 If the rank of @var{MASK} is one, then @code{ANY(MASK,DIM)} is equivalent
1134 to @code{ANY(MASK)}. If the rank is greater than one, then @code{ANY(MASK,DIM)}
1135 is determined by applying @code{ANY} to the array sections.
1138 @item @emph{Example}:
1142 l = any((/.true., .true., .true./))
1147 integer a(2,3), b(2,3)
1151 print *, any(a .eq. b, 1)
1152 print *, any(a .eq. b, 2)
1153 end subroutine section
1154 end program test_any
1161 @section @code{ASIN} --- Arcsine function
1164 @cindex trigonometric function, sine, inverse
1165 @cindex sine, inverse
1168 @item @emph{Description}:
1169 @code{ASIN(X)} computes the arcsine of its @var{X} (inverse of @code{SIN(X)}).
1171 @item @emph{Standard}:
1172 Fortran 77 and later
1177 @item @emph{Syntax}:
1178 @code{RESULT = ASIN(X)}
1180 @item @emph{Arguments}:
1181 @multitable @columnfractions .15 .70
1182 @item @var{X} @tab The type shall be @code{REAL}, and a magnitude that is
1186 @item @emph{Return value}:
1187 The return value is of type @code{REAL} and it lies in the
1188 range @math{-\pi / 2 \leq \asin (x) \leq \pi / 2}. The kind type
1189 parameter is the same as @var{X}.
1191 @item @emph{Example}:
1194 real(8) :: x = 0.866_8
1196 end program test_asin
1199 @item @emph{Specific names}:
1200 @multitable @columnfractions .20 .20 .20 .25
1201 @item Name @tab Argument @tab Return type @tab Standard
1202 @item @code{DASIN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
1205 @item @emph{See also}:
1206 Inverse function: @ref{SIN}
1213 @section @code{ASINH} --- Hyperbolic arcsine function
1216 @cindex area hyperbolic sine
1217 @cindex hyperbolic arcsine
1218 @cindex hyperbolic function, sine, inverse
1219 @cindex sine, hyperbolic, inverse
1222 @item @emph{Description}:
1223 @code{ASINH(X)} computes the hyperbolic arcsine of @var{X} (inverse of @code{SINH(X)}).
1225 @item @emph{Standard}:
1226 Fortran 2008 and later
1231 @item @emph{Syntax}:
1232 @code{RESULT = ASINH(X)}
1234 @item @emph{Arguments}:
1235 @multitable @columnfractions .15 .70
1236 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
1239 @item @emph{Return value}:
1240 The return value is of the same type and kind as @var{X}.
1242 @item @emph{Example}:
1245 REAL(8), DIMENSION(3) :: x = (/ -1.0, 0.0, 1.0 /)
1246 WRITE (*,*) ASINH(x)
1250 @item @emph{Specific names}:
1251 @multitable @columnfractions .20 .20 .20 .25
1252 @item Name @tab Argument @tab Return type @tab Standard
1253 @item @code{DASINH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension.
1256 @item @emph{See also}:
1257 Inverse function: @ref{SINH}
1263 @section @code{ASSOCIATED} --- Status of a pointer or pointer/target pair
1265 @cindex pointer, status
1266 @cindex association status
1269 @item @emph{Description}:
1270 @code{ASSOCIATED(POINTER [, TARGET])} determines the status of the pointer
1271 @var{POINTER} or if @var{POINTER} is associated with the target @var{TARGET}.
1273 @item @emph{Standard}:
1274 Fortran 95 and later
1279 @item @emph{Syntax}:
1280 @code{RESULT = ASSOCIATED(POINTER [, TARGET])}
1282 @item @emph{Arguments}:
1283 @multitable @columnfractions .15 .70
1284 @item @var{POINTER} @tab @var{POINTER} shall have the @code{POINTER} attribute
1285 and it can be of any type.
1286 @item @var{TARGET} @tab (Optional) @var{TARGET} shall be a pointer or
1287 a target. It must have the same type, kind type parameter, and
1288 array rank as @var{POINTER}.
1290 The association status of neither @var{POINTER} nor @var{TARGET} shall be
1293 @item @emph{Return value}:
1294 @code{ASSOCIATED(POINTER)} returns a scalar value of type @code{LOGICAL(4)}.
1295 There are several cases:
1297 @item (A) When the optional @var{TARGET} is not present then
1298 @code{ASSOCIATED(POINTER)} is true if @var{POINTER} is associated with a target; otherwise, it returns false.
1299 @item (B) If @var{TARGET} is present and a scalar target, the result is true if
1300 @var{TARGET} is not a zero-sized storage sequence and the target associated with @var{POINTER} occupies the same storage units. If @var{POINTER} is
1301 disassociated, the result is false.
1302 @item (C) If @var{TARGET} is present and an array target, the result is true if
1303 @var{TARGET} and @var{POINTER} have the same shape, are not zero-sized arrays,
1304 are arrays whose elements are not zero-sized storage sequences, and
1305 @var{TARGET} and @var{POINTER} occupy the same storage units in array element
1307 As in case(B), the result is false, if @var{POINTER} is disassociated.
1308 @item (D) If @var{TARGET} is present and an scalar pointer, the result is true
1309 if @var{TARGET} is associated with @var{POINTER}, the target associated with
1310 @var{TARGET} are not zero-sized storage sequences and occupy the same storage
1312 The result is false, if either @var{TARGET} or @var{POINTER} is disassociated.
1313 @item (E) If @var{TARGET} is present and an array pointer, the result is true if
1314 target associated with @var{POINTER} and the target associated with @var{TARGET}
1315 have the same shape, are not zero-sized arrays, are arrays whose elements are
1316 not zero-sized storage sequences, and @var{TARGET} and @var{POINTER} occupy
1317 the same storage units in array element order.
1318 The result is false, if either @var{TARGET} or @var{POINTER} is disassociated.
1321 @item @emph{Example}:
1323 program test_associated
1325 real, target :: tgt(2) = (/1., 2./)
1326 real, pointer :: ptr(:)
1328 if (associated(ptr) .eqv. .false.) call abort
1329 if (associated(ptr,tgt) .eqv. .false.) call abort
1330 end program test_associated
1333 @item @emph{See also}:
1340 @section @code{ATAN} --- Arctangent function
1343 @cindex trigonometric function, tangent, inverse
1344 @cindex tangent, inverse
1347 @item @emph{Description}:
1348 @code{ATAN(X)} computes the arctangent of @var{X}.
1350 @item @emph{Standard}:
1351 Fortran 77 and later
1356 @item @emph{Syntax}:
1357 @code{RESULT = ATAN(X)}
1359 @item @emph{Arguments}:
1360 @multitable @columnfractions .15 .70
1361 @item @var{X} @tab The type shall be @code{REAL}.
1364 @item @emph{Return value}:
1365 The return value is of type @code{REAL} and it lies in the
1366 range @math{ - \pi / 2 \leq \atan (x) \leq \pi / 2}.
1368 @item @emph{Example}:
1371 real(8) :: x = 2.866_8
1373 end program test_atan
1376 @item @emph{Specific names}:
1377 @multitable @columnfractions .20 .20 .20 .25
1378 @item Name @tab Argument @tab Return type @tab Standard
1379 @item @code{DATAN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
1382 @item @emph{See also}:
1383 Inverse function: @ref{TAN}
1390 @section @code{ATAN2} --- Arctangent function
1393 @cindex trigonometric function, tangent, inverse
1394 @cindex tangent, inverse
1397 @item @emph{Description}:
1398 @code{ATAN2(Y, X)} computes the arctangent of the complex number
1401 @item @emph{Standard}:
1402 Fortran 77 and later
1407 @item @emph{Syntax}:
1408 @code{RESULT = ATAN2(Y, X)}
1410 @item @emph{Arguments}:
1411 @multitable @columnfractions .15 .70
1412 @item @var{Y} @tab The type shall be @code{REAL}.
1413 @item @var{X} @tab The type and kind type parameter shall be the same as @var{Y}.
1414 If @var{Y} is zero, then @var{X} must be nonzero.
1417 @item @emph{Return value}:
1418 The return value has the same type and kind type parameter as @var{Y}.
1419 It is the principal value of the complex number @math{X + i Y}. If
1420 @var{X} is nonzero, then it lies in the range @math{-\pi \le \atan (x) \leq \pi}.
1421 The sign is positive if @var{Y} is positive. If @var{Y} is zero, then
1422 the return value is zero if @var{X} is positive and @math{\pi} if @var{X}
1423 is negative. Finally, if @var{X} is zero, then the magnitude of the result
1426 @item @emph{Example}:
1429 real(4) :: x = 1.e0_4, y = 0.5e0_4
1431 end program test_atan2
1434 @item @emph{Specific names}:
1435 @multitable @columnfractions .20 .20 .20 .25
1436 @item Name @tab Argument @tab Return type @tab Standard
1437 @item @code{DATAN2(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
1444 @section @code{ATANH} --- Hyperbolic arctangent function
1447 @cindex area hyperbolic tangent
1448 @cindex hyperbolic arctangent
1449 @cindex hyperbolic function, tangent, inverse
1450 @cindex tangent, hyperbolic, inverse
1453 @item @emph{Description}:
1454 @code{ATANH(X)} computes the hyperbolic arctangent of @var{X} (inverse
1457 @item @emph{Standard}:
1458 Fortran 2008 and later
1463 @item @emph{Syntax}:
1464 @code{RESULT = ATANH(X)}
1466 @item @emph{Arguments}:
1467 @multitable @columnfractions .15 .70
1468 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
1471 @item @emph{Return value}:
1472 The return value has same type and kind as @var{X}.
1474 @item @emph{Example}:
1477 REAL, DIMENSION(3) :: x = (/ -1.0, 0.0, 1.0 /)
1478 WRITE (*,*) ATANH(x)
1482 @item @emph{Specific names}:
1483 @multitable @columnfractions .20 .20 .20 .25
1484 @item Name @tab Argument @tab Return type @tab Standard
1485 @item @code{DATANH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1488 @item @emph{See also}:
1489 Inverse function: @ref{TANH}
1495 @section @code{BESSEL_J0} --- Bessel function of the first kind of order 0
1499 @cindex Bessel function, first kind
1502 @item @emph{Description}:
1503 @code{BESSEL_J0(X)} computes the Bessel function of the first kind of
1504 order 0 of @var{X}. This function is available under the name
1505 @code{BESJ0} as a GNU extension.
1507 @item @emph{Standard}:
1508 Fortran 2008 and later
1513 @item @emph{Syntax}:
1514 @code{RESULT = BESSEL_J0(X)}
1516 @item @emph{Arguments}:
1517 @multitable @columnfractions .15 .70
1518 @item @var{X} @tab The type shall be @code{REAL}, and it shall be scalar.
1521 @item @emph{Return value}:
1522 The return value is of type @code{REAL} and lies in the
1523 range @math{ - 0.4027... \leq Bessel (0,x) \leq 1}. It has the same
1526 @item @emph{Example}:
1529 real(8) :: x = 0.0_8
1531 end program test_besj0
1534 @item @emph{Specific names}:
1535 @multitable @columnfractions .20 .20 .20 .25
1536 @item Name @tab Argument @tab Return type @tab Standard
1537 @item @code{DBESJ0(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1544 @section @code{BESSEL_J1} --- Bessel function of the first kind of order 1
1548 @cindex Bessel function, first kind
1551 @item @emph{Description}:
1552 @code{BESSEL_J1(X)} computes the Bessel function of the first kind of
1553 order 1 of @var{X}. This function is available under the name
1554 @code{BESJ1} as a GNU extension.
1556 @item @emph{Standard}:
1562 @item @emph{Syntax}:
1563 @code{RESULT = BESSEL_J1(X)}
1565 @item @emph{Arguments}:
1566 @multitable @columnfractions .15 .70
1567 @item @var{X} @tab The type shall be @code{REAL}, and it shall be scalar.
1570 @item @emph{Return value}:
1571 The return value is of type @code{REAL} and it lies in the
1572 range @math{ - 0.5818... \leq Bessel (0,x) \leq 0.5818 }. It has the same
1575 @item @emph{Example}:
1578 real(8) :: x = 1.0_8
1580 end program test_besj1
1583 @item @emph{Specific names}:
1584 @multitable @columnfractions .20 .20 .20 .25
1585 @item Name @tab Argument @tab Return type @tab Standard
1586 @item @code{DBESJ1(X)}@tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1593 @section @code{BESSEL_JN} --- Bessel function of the first kind
1597 @cindex Bessel function, first kind
1600 @item @emph{Description}:
1601 @code{BESSEL_JN(N, X)} computes the Bessel function of the first kind of
1602 order @var{N} of @var{X}. This function is available under the name
1603 @code{BESJN} as a GNU extension.
1605 If both arguments are arrays, their ranks and shapes shall conform.
1607 @item @emph{Standard}:
1608 Fortran 2008 and later
1613 @item @emph{Syntax}:
1614 @code{RESULT = BESSEL_JN(N, X)}
1616 @item @emph{Arguments}:
1617 @multitable @columnfractions .15 .70
1618 @item @var{N} @tab Shall be a scalar or an array of type @code{INTEGER}.
1619 @item @var{X} @tab Shall be a scalar or an array of type @code{REAL}.
1622 @item @emph{Return value}:
1623 The return value is a scalar of type @code{REAL}. It has the same
1626 @item @emph{Example}:
1629 real(8) :: x = 1.0_8
1631 end program test_besjn
1634 @item @emph{Specific names}:
1635 @multitable @columnfractions .20 .20 .20 .25
1636 @item Name @tab Argument @tab Return type @tab Standard
1637 @item @code{DBESJN(X)} @tab @code{INTEGER N} @tab @code{REAL(8)} @tab GNU extension
1638 @item @tab @code{REAL(8) X} @tab @tab
1645 @section @code{BESSEL_Y0} --- Bessel function of the second kind of order 0
1649 @cindex Bessel function, second kind
1652 @item @emph{Description}:
1653 @code{BESSEL_Y0(X)} computes the Bessel function of the second kind of
1654 order 0 of @var{X}. This function is available under the name
1655 @code{BESY0} as a GNU extension.
1657 @item @emph{Standard}:
1658 Fortran 2008 and later
1663 @item @emph{Syntax}:
1664 @code{RESULT = BESSEL_Y0(X)}
1666 @item @emph{Arguments}:
1667 @multitable @columnfractions .15 .70
1668 @item @var{X} @tab The type shall be @code{REAL}, and it shall be scalar.
1671 @item @emph{Return value}:
1672 The return value is a scalar of type @code{REAL}. It has the same
1675 @item @emph{Example}:
1678 real(8) :: x = 0.0_8
1680 end program test_besy0
1683 @item @emph{Specific names}:
1684 @multitable @columnfractions .20 .20 .20 .25
1685 @item Name @tab Argument @tab Return type @tab Standard
1686 @item @code{DBESY0(X)}@tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1693 @section @code{BESSEL_Y1} --- Bessel function of the second kind of order 1
1697 @cindex Bessel function, second kind
1700 @item @emph{Description}:
1701 @code{BESSEL_Y1(X)} computes the Bessel function of the second kind of
1702 order 1 of @var{X}. This function is available under the name
1703 @code{BESY1} as a GNU extension.
1705 @item @emph{Standard}:
1706 Fortran 2008 and later
1711 @item @emph{Syntax}:
1712 @code{RESULT = BESSEL_Y1(X)}
1714 @item @emph{Arguments}:
1715 @multitable @columnfractions .15 .70
1716 @item @var{X} @tab The type shall be @code{REAL}, and it shall be scalar.
1719 @item @emph{Return value}:
1720 The return value is a scalar of type @code{REAL}. It has the same
1723 @item @emph{Example}:
1726 real(8) :: x = 1.0_8
1728 end program test_besy1
1731 @item @emph{Specific names}:
1732 @multitable @columnfractions .20 .20 .20 .25
1733 @item Name @tab Argument @tab Return type @tab Standard
1734 @item @code{DBESY1(X)}@tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1741 @section @code{BESSEL_YN} --- Bessel function of the second kind
1745 @cindex Bessel function, second kind
1748 @item @emph{Description}:
1749 @code{BESSEL_YN(N, X)} computes the Bessel function of the second kind of
1750 order @var{N} of @var{X}. This function is available under the name
1751 @code{BESYN} as a GNU extension.
1753 If both arguments are arrays, their ranks and shapes shall conform.
1755 @item @emph{Standard}:
1756 Fortran 2008 and later
1761 @item @emph{Syntax}:
1762 @code{RESULT = BESSEL_YN(N, X)}
1764 @item @emph{Arguments}:
1765 @multitable @columnfractions .15 .70
1766 @item @var{N} @tab Shall be a scalar or an array of type @code{INTEGER}.
1767 @item @var{X} @tab Shall be a scalar or an array of type @code{REAL}.
1770 @item @emph{Return value}:
1771 The return value is a scalar of type @code{REAL}. It has the same
1774 @item @emph{Example}:
1777 real(8) :: x = 1.0_8
1779 end program test_besyn
1782 @item @emph{Specific names}:
1783 @multitable @columnfractions .20 .20 .20 .25
1784 @item Name @tab Argument @tab Return type @tab Standard
1785 @item @code{DBESYN(N,X)} @tab @code{INTEGER N} @tab @code{REAL(8)} @tab GNU extension
1786 @item @tab @code{REAL(8) X} @tab @tab
1793 @section @code{BIT_SIZE} --- Bit size inquiry function
1795 @cindex bits, number of
1796 @cindex size of a variable, in bits
1799 @item @emph{Description}:
1800 @code{BIT_SIZE(I)} returns the number of bits (integer precision plus sign bit)
1801 represented by the type of @var{I}.
1803 @item @emph{Standard}:
1804 Fortran 95 and later
1809 @item @emph{Syntax}:
1810 @code{RESULT = BIT_SIZE(I)}
1812 @item @emph{Arguments}:
1813 @multitable @columnfractions .15 .70
1814 @item @var{I} @tab The type shall be @code{INTEGER}.
1817 @item @emph{Return value}:
1818 The return value is of type @code{INTEGER}
1820 @item @emph{Example}:
1822 program test_bit_size
1827 end program test_bit_size
1834 @section @code{BTEST} --- Bit test function
1836 @cindex bits, testing
1839 @item @emph{Description}:
1840 @code{BTEST(I,POS)} returns logical @code{.TRUE.} if the bit at @var{POS}
1843 @item @emph{Standard}:
1844 Fortran 95 and later
1849 @item @emph{Syntax}:
1850 @code{RESULT = BTEST(I, POS)}
1852 @item @emph{Arguments}:
1853 @multitable @columnfractions .15 .70
1854 @item @var{I} @tab The type shall be @code{INTEGER}.
1855 @item @var{POS} @tab The type shall be @code{INTEGER}.
1858 @item @emph{Return value}:
1859 The return value is of type @code{LOGICAL}
1861 @item @emph{Example}:
1864 integer :: i = 32768 + 1024 + 64
1868 bool = btest(i, pos)
1871 end program test_btest
1877 @section @code{C_ASSOCIATED} --- Status of a C pointer
1878 @fnindex C_ASSOCIATED
1879 @cindex association status, C pointer
1880 @cindex pointer, C association status
1883 @item @emph{Description}:
1884 @code{C_ASSOCIATED(c_prt_1[, c_ptr_2])} determines the status of the C pointer
1885 @var{c_ptr_1} or if @var{c_ptr_1} is associated with the target @var{c_ptr_2}.
1887 @item @emph{Standard}:
1888 Fortran 2003 and later
1893 @item @emph{Syntax}:
1894 @code{RESULT = C_ASSOCIATED(c_prt_1[, c_ptr_2])}
1896 @item @emph{Arguments}:
1897 @multitable @columnfractions .15 .70
1898 @item @var{c_ptr_1} @tab Scalar of the type @code{C_PTR} or @code{C_FUNPTR}.
1899 @item @var{c_ptr_2} @tab (Optional) Scalar of the same type as @var{c_ptr_1}.
1902 @item @emph{Return value}:
1903 The return value is of type @code{LOGICAL}; it is @code{.false.} if either
1904 @var{c_ptr_1} is a C NULL pointer or if @var{c_ptr1} and @var{c_ptr_2}
1905 point to different addresses.
1907 @item @emph{Example}:
1909 subroutine association_test(a,b)
1910 use iso_c_binding, only: c_associated, c_loc, c_ptr
1914 if(c_associated(b, c_loc(a))) &
1915 stop 'b and a do not point to same target'
1916 end subroutine association_test
1919 @item @emph{See also}:
1920 @ref{C_LOC}, @ref{C_FUNLOC}
1925 @section @code{C_FUNLOC} --- Obtain the C address of a procedure
1927 @cindex pointer, C address of procedures
1930 @item @emph{Description}:
1931 @code{C_FUNLOC(x)} determines the C address of the argument.
1933 @item @emph{Standard}:
1934 Fortran 2003 and later
1939 @item @emph{Syntax}:
1940 @code{RESULT = C_FUNLOC(x)}
1942 @item @emph{Arguments}:
1943 @multitable @columnfractions .15 .70
1944 @item @var{x} @tab Interoperable function or pointer to such function.
1947 @item @emph{Return value}:
1948 The return value is of type @code{C_FUNPTR} and contains the C address
1951 @item @emph{Example}:
1957 subroutine sub(a) bind(c)
1967 subroutine my_routine(p) bind(c,name='myC_func')
1969 type(c_funptr), intent(in) :: p
1972 call my_routine(c_funloc(sub))
1976 @item @emph{See also}:
1977 @ref{C_ASSOCIATED}, @ref{C_LOC}, @ref{C_F_POINTER}, @ref{C_F_PROCPOINTER}
1981 @node C_F_PROCPOINTER
1982 @section @code{C_F_PROCPOINTER} --- Convert C into Fortran procedure pointer
1983 @fnindex C_F_PROCPOINTER
1984 @cindex pointer, C address of pointers
1987 @item @emph{Description}:
1988 @code{C_F_PROCPOINTER(CPTR, FPTR)} Assign the target of the C function pointer
1989 @var{CPTR} to the Fortran procedure pointer @var{FPTR}.
1991 Note: Due to the currently lacking support of procedure pointers in GNU Fortran
1992 this function is not fully operable.
1994 @item @emph{Standard}:
1995 Fortran 2003 and later
2000 @item @emph{Syntax}:
2001 @code{CALL C_F_PROCPOINTER(cptr, fptr)}
2003 @item @emph{Arguments}:
2004 @multitable @columnfractions .15 .70
2005 @item @var{CPTR} @tab scalar of the type @code{C_FUNPTR}. It is
2007 @item @var{FPTR} @tab procedure pointer interoperable with @var{cptr}. It is
2011 @item @emph{Example}:
2019 real(c_float), intent(in) :: a
2020 real(c_float) :: func
2024 function getIterFunc() bind(c,name="getIterFunc")
2026 type(c_funptr) :: getIterFunc
2029 type(c_funptr) :: cfunptr
2030 procedure(func), pointer :: myFunc
2031 cfunptr = getIterFunc()
2032 call c_f_procpointer(cfunptr, myFunc)
2036 @item @emph{See also}:
2037 @ref{C_LOC}, @ref{C_F_POINTER}
2042 @section @code{C_F_POINTER} --- Convert C into Fortran pointer
2043 @fnindex C_F_POINTER
2044 @cindex pointer, convert C to Fortran
2047 @item @emph{Description}:
2048 @code{C_F_POINTER(CPTR, FPTR[, SHAPE])} Assign the target the C pointer
2049 @var{CPTR} to the Fortran pointer @var{FPTR} and specify its
2052 @item @emph{Standard}:
2053 Fortran 2003 and later
2058 @item @emph{Syntax}:
2059 @code{CALL C_F_POINTER(CPTR, FPTR[, SHAPE])}
2061 @item @emph{Arguments}:
2062 @multitable @columnfractions .15 .70
2063 @item @var{CPTR} @tab scalar of the type @code{C_PTR}. It is
2065 @item @var{FPTR} @tab pointer interoperable with @var{cptr}. It is
2067 @item @var{SHAPE} @tab (Optional) Rank-one array of type @code{INTEGER}
2068 with @code{INTENT(IN)}. It shall be present
2069 if and only if @var{fptr} is an array. The size
2070 must be equal to the rank of @var{fptr}.
2073 @item @emph{Example}:
2079 subroutine my_routine(p) bind(c,name='myC_func')
2081 type(c_ptr), intent(out) :: p
2085 real,pointer :: a(:)
2086 call my_routine(cptr)
2087 call c_f_pointer(cptr, a, [12])
2091 @item @emph{See also}:
2092 @ref{C_LOC}, @ref{C_F_PROCPOINTER}
2097 @section @code{C_LOC} --- Obtain the C address of an object
2099 @cindex procedure pointer, convert C to Fortran
2102 @item @emph{Description}:
2103 @code{C_LOC(X)} determines the C address of the argument.
2105 @item @emph{Standard}:
2106 Fortran 2003 and later
2111 @item @emph{Syntax}:
2112 @code{RESULT = C_LOC(X)}
2114 @item @emph{Arguments}:
2115 @multitable @columnfractions .15 .70
2116 @item @var{X} @tab Associated scalar pointer or interoperable scalar
2117 or allocated allocatable variable with @code{TARGET}
2121 @item @emph{Return value}:
2122 The return value is of type @code{C_PTR} and contains the C address
2125 @item @emph{Example}:
2127 subroutine association_test(a,b)
2128 use iso_c_binding, only: c_associated, c_loc, c_ptr
2132 if(c_associated(b, c_loc(a))) &
2133 stop 'b and a do not point to same target'
2134 end subroutine association_test
2137 @item @emph{See also}:
2138 @ref{C_ASSOCIATED}, @ref{C_FUNLOC}, @ref{C_F_POINTER}, @ref{C_F_PROCPOINTER}
2143 @section @code{CEILING} --- Integer ceiling function
2146 @cindex rounding, ceiling
2149 @item @emph{Description}:
2150 @code{CEILING(A)} returns the least integer greater than or equal to @var{A}.
2152 @item @emph{Standard}:
2153 Fortran 95 and later
2158 @item @emph{Syntax}:
2159 @code{RESULT = CEILING(A [, KIND])}
2161 @item @emph{Arguments}:
2162 @multitable @columnfractions .15 .70
2163 @item @var{A} @tab The type shall be @code{REAL}.
2164 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
2165 expression indicating the kind parameter of
2169 @item @emph{Return value}:
2170 The return value is of type @code{INTEGER(KIND)} if @var{KIND} is present
2171 and a default-kind @code{INTEGER} otherwise.
2173 @item @emph{Example}:
2175 program test_ceiling
2178 print *, ceiling(x) ! returns 64
2179 print *, ceiling(y) ! returns -63
2180 end program test_ceiling
2183 @item @emph{See also}:
2184 @ref{FLOOR}, @ref{NINT}
2191 @section @code{CHAR} --- Character conversion function
2193 @cindex conversion, to character
2196 @item @emph{Description}:
2197 @code{CHAR(I [, KIND])} returns the character represented by the integer @var{I}.
2199 @item @emph{Standard}:
2200 Fortran 77 and later
2205 @item @emph{Syntax}:
2206 @code{RESULT = CHAR(I [, KIND])}
2208 @item @emph{Arguments}:
2209 @multitable @columnfractions .15 .70
2210 @item @var{I} @tab The type shall be @code{INTEGER}.
2211 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
2212 expression indicating the kind parameter of
2216 @item @emph{Return value}:
2217 The return value is of type @code{CHARACTER(1)}
2219 @item @emph{Example}:
2225 print *, i, c ! returns 'J'
2226 end program test_char
2230 See @ref{ICHAR} for a discussion of converting between numerical values
2231 and formatted string representations.
2233 @item @emph{See also}:
2234 @ref{ACHAR}, @ref{IACHAR}, @ref{ICHAR}
2241 @section @code{CHDIR} --- Change working directory
2243 @cindex system, working directory
2246 @item @emph{Description}:
2247 Change current working directory to a specified path.
2249 This intrinsic is provided in both subroutine and function forms; however,
2250 only one form can be used in any given program unit.
2252 @item @emph{Standard}:
2256 Subroutine, function
2258 @item @emph{Syntax}:
2259 @multitable @columnfractions .80
2260 @item @code{CALL CHDIR(NAME [, STATUS])}
2261 @item @code{STATUS = CHDIR(NAME)}
2264 @item @emph{Arguments}:
2265 @multitable @columnfractions .15 .70
2266 @item @var{NAME} @tab The type shall be @code{CHARACTER} of default
2267 kind and shall specify a valid path within the
2269 @item @var{STATUS} @tab (Optional) @code{INTEGER} status flag of the default
2270 kind. Returns 0 on success, and a system specific
2271 and nonzero error code otherwise.
2274 @item @emph{Example}:
2277 CHARACTER(len=255) :: path
2279 WRITE(*,*) TRIM(path)
2282 WRITE(*,*) TRIM(path)
2286 @item @emph{See also}:
2293 @section @code{CHMOD} --- Change access permissions of files
2295 @cindex file system, change access mode
2298 @item @emph{Description}:
2299 @code{CHMOD} changes the permissions of a file. This function invokes
2300 @code{/bin/chmod} and might therefore not work on all platforms.
2302 This intrinsic is provided in both subroutine and function forms; however,
2303 only one form can be used in any given program unit.
2305 @item @emph{Standard}:
2309 Subroutine, function
2311 @item @emph{Syntax}:
2312 @multitable @columnfractions .80
2313 @item @code{CALL CHMOD(NAME, MODE[, STATUS])}
2314 @item @code{STATUS = CHMOD(NAME, MODE)}
2317 @item @emph{Arguments}:
2318 @multitable @columnfractions .15 .70
2320 @item @var{NAME} @tab Scalar @code{CHARACTER} of default kind with the
2321 file name. Trailing blanks are ignored unless the character
2322 @code{achar(0)} is present, then all characters up to and excluding
2323 @code{achar(0)} are used as the file name.
2325 @item @var{MODE} @tab Scalar @code{CHARACTER} of default kind giving the
2326 file permission. @var{MODE} uses the same syntax as the @var{MODE}
2327 argument of @code{/bin/chmod}.
2329 @item @var{STATUS} @tab (optional) scalar @code{INTEGER}, which is
2330 @code{0} on success and nonzero otherwise.
2333 @item @emph{Return value}:
2334 In either syntax, @var{STATUS} is set to @code{0} on success and nonzero
2337 @item @emph{Example}:
2338 @code{CHMOD} as subroutine
2343 call chmod('test.dat','u+x',status)
2344 print *, 'Status: ', status
2345 end program chmod_test
2347 @code{CHMOD} as function:
2352 status = chmod('test.dat','u+x')
2353 print *, 'Status: ', status
2354 end program chmod_test
2362 @section @code{CMPLX} --- Complex conversion function
2364 @cindex complex numbers, conversion to
2365 @cindex conversion, to complex
2368 @item @emph{Description}:
2369 @code{CMPLX(X [, Y [, KIND]])} returns a complex number where @var{X} is converted to
2370 the real component. If @var{Y} is present it is converted to the imaginary
2371 component. If @var{Y} is not present then the imaginary component is set to
2372 0.0. If @var{X} is complex then @var{Y} must not be present.
2374 @item @emph{Standard}:
2375 Fortran 77 and later
2380 @item @emph{Syntax}:
2381 @code{RESULT = CMPLX(X [, Y [, KIND]])}
2383 @item @emph{Arguments}:
2384 @multitable @columnfractions .15 .70
2385 @item @var{X} @tab The type may be @code{INTEGER}, @code{REAL},
2387 @item @var{Y} @tab (Optional; only allowed if @var{X} is not
2388 @code{COMPLEX}.) May be @code{INTEGER}
2390 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
2391 expression indicating the kind parameter of
2395 @item @emph{Return value}:
2396 The return value is of @code{COMPLEX} type, with a kind equal to
2397 @var{KIND} if it is specified. If @var{KIND} is not specified, the
2398 result is of the default @code{COMPLEX} kind, regardless of the kinds of
2399 @var{X} and @var{Y}.
2401 @item @emph{Example}:
2408 print *, z, cmplx(x)
2409 end program test_cmplx
2412 @item @emph{See also}:
2418 @node COMMAND_ARGUMENT_COUNT
2419 @section @code{COMMAND_ARGUMENT_COUNT} --- Get number of command line arguments
2420 @fnindex COMMAND_ARGUMENT_COUNT
2421 @cindex command-line arguments
2422 @cindex command-line arguments, number of
2423 @cindex arguments, to program
2426 @item @emph{Description}:
2427 @code{COMMAND_ARGUMENT_COUNT()} returns the number of arguments passed on the
2428 command line when the containing program was invoked.
2430 @item @emph{Standard}:
2431 Fortran 2003 and later
2436 @item @emph{Syntax}:
2437 @code{RESULT = COMMAND_ARGUMENT_COUNT()}
2439 @item @emph{Arguments}:
2440 @multitable @columnfractions .15 .70
2444 @item @emph{Return value}:
2445 The return value is of type @code{INTEGER(4)}
2447 @item @emph{Example}:
2449 program test_command_argument_count
2451 count = command_argument_count()
2453 end program test_command_argument_count
2456 @item @emph{See also}:
2457 @ref{GET_COMMAND}, @ref{GET_COMMAND_ARGUMENT}
2463 @section @code{COMPLEX} --- Complex conversion function
2465 @cindex complex numbers, conversion to
2466 @cindex conversion, to complex
2469 @item @emph{Description}:
2470 @code{COMPLEX(X, Y)} returns a complex number where @var{X} is converted
2471 to the real component and @var{Y} is converted to the imaginary
2474 @item @emph{Standard}:
2480 @item @emph{Syntax}:
2481 @code{RESULT = COMPLEX(X, Y)}
2483 @item @emph{Arguments}:
2484 @multitable @columnfractions .15 .70
2485 @item @var{X} @tab The type may be @code{INTEGER} or @code{REAL}.
2486 @item @var{Y} @tab The type may be @code{INTEGER} or @code{REAL}.
2489 @item @emph{Return value}:
2490 If @var{X} and @var{Y} are both of @code{INTEGER} type, then the return
2491 value is of default @code{COMPLEX} type.
2493 If @var{X} and @var{Y} are of @code{REAL} type, or one is of @code{REAL}
2494 type and one is of @code{INTEGER} type, then the return value is of
2495 @code{COMPLEX} type with a kind equal to that of the @code{REAL}
2496 argument with the highest precision.
2498 @item @emph{Example}:
2500 program test_complex
2503 print *, complex(i, x)
2504 end program test_complex
2507 @item @emph{See also}:
2514 @section @code{CONJG} --- Complex conjugate function
2517 @cindex complex conjugate
2520 @item @emph{Description}:
2521 @code{CONJG(Z)} returns the conjugate of @var{Z}. If @var{Z} is @code{(x, y)}
2522 then the result is @code{(x, -y)}
2524 @item @emph{Standard}:
2525 Fortran 77 and later, has overloads that are GNU extensions
2530 @item @emph{Syntax}:
2533 @item @emph{Arguments}:
2534 @multitable @columnfractions .15 .70
2535 @item @var{Z} @tab The type shall be @code{COMPLEX}.
2538 @item @emph{Return value}:
2539 The return value is of type @code{COMPLEX}.
2541 @item @emph{Example}:
2544 complex :: z = (2.0, 3.0)
2545 complex(8) :: dz = (2.71_8, -3.14_8)
2550 end program test_conjg
2553 @item @emph{Specific names}:
2554 @multitable @columnfractions .20 .20 .20 .25
2555 @item Name @tab Argument @tab Return type @tab Standard
2556 @item @code{DCONJG(Z)} @tab @code{COMPLEX(8) Z} @tab @code{COMPLEX(8)} @tab GNU extension
2563 @section @code{COS} --- Cosine function
2569 @cindex trigonometric function, cosine
2573 @item @emph{Description}:
2574 @code{COS(X)} computes the cosine of @var{X}.
2576 @item @emph{Standard}:
2577 Fortran 77 and later, has overloads that are GNU extensions
2582 @item @emph{Syntax}:
2583 @code{RESULT = COS(X)}
2585 @item @emph{Arguments}:
2586 @multitable @columnfractions .15 .70
2587 @item @var{X} @tab The type shall be @code{REAL} or
2591 @item @emph{Return value}:
2592 The return value is of type @code{REAL} and it lies in the
2593 range @math{ -1 \leq \cos (x) \leq 1}. The kind type
2594 parameter is the same as @var{X}.
2596 @item @emph{Example}:
2601 end program test_cos
2604 @item @emph{Specific names}:
2605 @multitable @columnfractions .20 .20 .20 .25
2606 @item Name @tab Argument @tab Return type @tab Standard
2607 @item @code{DCOS(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
2608 @item @code{CCOS(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab Fortran 77 and later
2609 @item @code{ZCOS(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
2610 @item @code{CDCOS(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
2613 @item @emph{See also}:
2614 Inverse function: @ref{ACOS}
2621 @section @code{COSH} --- Hyperbolic cosine function
2624 @cindex hyperbolic cosine
2625 @cindex hyperbolic function, cosine
2626 @cindex cosine, hyperbolic
2629 @item @emph{Description}:
2630 @code{COSH(X)} computes the hyperbolic cosine of @var{X}.
2632 @item @emph{Standard}:
2633 Fortran 77 and later
2638 @item @emph{Syntax}:
2641 @item @emph{Arguments}:
2642 @multitable @columnfractions .15 .70
2643 @item @var{X} @tab The type shall be @code{REAL}.
2646 @item @emph{Return value}:
2647 The return value is of type @code{REAL} and it is positive
2648 (@math{ \cosh (x) \geq 0 }. The return value is of the same
2651 @item @emph{Example}:
2654 real(8) :: x = 1.0_8
2656 end program test_cosh
2659 @item @emph{Specific names}:
2660 @multitable @columnfractions .20 .20 .20 .25
2661 @item Name @tab Argument @tab Return type @tab Standard
2662 @item @code{DCOSH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
2665 @item @emph{See also}:
2666 Inverse function: @ref{ACOSH}
2673 @section @code{COUNT} --- Count function
2675 @cindex array, conditionally count elements
2676 @cindex array, element counting
2677 @cindex array, number of elements
2680 @item @emph{Description}:
2682 @code{COUNT(MASK [, DIM [, KIND]])} counts the number of @code{.TRUE.}
2683 elements of @var{MASK} along the dimension of @var{DIM}. If @var{DIM} is
2684 omitted it is taken to be @code{1}. @var{DIM} is a scaler of type
2685 @code{INTEGER} in the range of @math{1 /leq DIM /leq n)} where @math{n}
2686 is the rank of @var{MASK}.
2688 @item @emph{Standard}:
2689 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
2692 Transformational function
2694 @item @emph{Syntax}:
2695 @code{RESULT = COUNT(MASK [, DIM [, KIND]])}
2697 @item @emph{Arguments}:
2698 @multitable @columnfractions .15 .70
2699 @item @var{MASK} @tab The type shall be @code{LOGICAL}.
2700 @item @var{DIM} @tab (Optional) The type shall be @code{INTEGER}.
2701 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
2702 expression indicating the kind parameter of
2706 @item @emph{Return value}:
2707 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
2708 @var{KIND} is absent, the return value is of default integer kind.
2709 The result has a rank equal to that of @var{MASK}.
2711 @item @emph{Example}:
2714 integer, dimension(2,3) :: a, b
2715 logical, dimension(2,3) :: mask
2716 a = reshape( (/ 1, 2, 3, 4, 5, 6 /), (/ 2, 3 /))
2717 b = reshape( (/ 0, 7, 3, 4, 5, 8 /), (/ 2, 3 /))
2718 print '(3i3)', a(1,:)
2719 print '(3i3)', a(2,:)
2721 print '(3i3)', b(1,:)
2722 print '(3i3)', b(2,:)
2725 print '(3l3)', mask(1,:)
2726 print '(3l3)', mask(2,:)
2728 print '(3i3)', count(mask)
2730 print '(3i3)', count(mask, 1)
2732 print '(3i3)', count(mask, 2)
2733 end program test_count
2740 @section @code{CPU_TIME} --- CPU elapsed time in seconds
2742 @cindex time, elapsed
2745 @item @emph{Description}:
2746 Returns a @code{REAL} value representing the elapsed CPU time in
2747 seconds. This is useful for testing segments of code to determine
2750 If a time source is available, time will be reported with microsecond
2751 resolution. If no time source is available, @var{TIME} is set to
2754 Note that @var{TIME} may contain a, system dependent, arbitrary offset
2755 and may not start with @code{0.0}. For @code{CPU_TIME}, the absolute
2756 value is meaningless, only differences between subsequent calls to
2757 this subroutine, as shown in the example below, should be used.
2760 @item @emph{Standard}:
2761 Fortran 95 and later
2766 @item @emph{Syntax}:
2767 @code{CALL CPU_TIME(TIME)}
2769 @item @emph{Arguments}:
2770 @multitable @columnfractions .15 .70
2771 @item @var{TIME} @tab The type shall be @code{REAL} with @code{INTENT(OUT)}.
2774 @item @emph{Return value}:
2777 @item @emph{Example}:
2779 program test_cpu_time
2780 real :: start, finish
2781 call cpu_time(start)
2782 ! put code to test here
2783 call cpu_time(finish)
2784 print '("Time = ",f6.3," seconds.")',finish-start
2785 end program test_cpu_time
2788 @item @emph{See also}:
2789 @ref{SYSTEM_CLOCK}, @ref{DATE_AND_TIME}
2795 @section @code{CSHIFT} --- Circular shift elements of an array
2797 @cindex array, shift circularly
2798 @cindex array, permutation
2799 @cindex array, rotate
2802 @item @emph{Description}:
2803 @code{CSHIFT(ARRAY, SHIFT [, DIM])} performs a circular shift on elements of
2804 @var{ARRAY} along the dimension of @var{DIM}. If @var{DIM} is omitted it is
2805 taken to be @code{1}. @var{DIM} is a scaler of type @code{INTEGER} in the
2806 range of @math{1 /leq DIM /leq n)} where @math{n} is the rank of @var{ARRAY}.
2807 If the rank of @var{ARRAY} is one, then all elements of @var{ARRAY} are shifted
2808 by @var{SHIFT} places. If rank is greater than one, then all complete rank one
2809 sections of @var{ARRAY} along the given dimension are shifted. Elements
2810 shifted out one end of each rank one section are shifted back in the other end.
2812 @item @emph{Standard}:
2813 Fortran 95 and later
2816 Transformational function
2818 @item @emph{Syntax}:
2819 @code{RESULT = CSHIFT(ARRAY, SHIFT [, DIM])}
2821 @item @emph{Arguments}:
2822 @multitable @columnfractions .15 .70
2823 @item @var{ARRAY} @tab Shall be an array of any type.
2824 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
2825 @item @var{DIM} @tab The type shall be @code{INTEGER}.
2828 @item @emph{Return value}:
2829 Returns an array of same type and rank as the @var{ARRAY} argument.
2831 @item @emph{Example}:
2834 integer, dimension(3,3) :: a
2835 a = reshape( (/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /), (/ 3, 3 /))
2836 print '(3i3)', a(1,:)
2837 print '(3i3)', a(2,:)
2838 print '(3i3)', a(3,:)
2839 a = cshift(a, SHIFT=(/1, 2, -1/), DIM=2)
2841 print '(3i3)', a(1,:)
2842 print '(3i3)', a(2,:)
2843 print '(3i3)', a(3,:)
2844 end program test_cshift
2851 @section @code{CTIME} --- Convert a time into a string
2853 @cindex time, conversion to string
2854 @cindex conversion, to string
2857 @item @emph{Description}:
2858 @code{CTIME} converts a system time value, such as returned by
2859 @code{TIME8()}, to a string of the form @samp{Sat Aug 19 18:13:14 1995}.
2861 This intrinsic is provided in both subroutine and function forms; however,
2862 only one form can be used in any given program unit.
2864 @item @emph{Standard}:
2868 Subroutine, function
2870 @item @emph{Syntax}:
2871 @multitable @columnfractions .80
2872 @item @code{CALL CTIME(TIME, RESULT)}.
2873 @item @code{RESULT = CTIME(TIME)}, (not recommended).
2876 @item @emph{Arguments}:
2877 @multitable @columnfractions .15 .70
2878 @item @var{TIME} @tab The type shall be of type @code{INTEGER(KIND=8)}.
2879 @item @var{RESULT} @tab The type shall be of type @code{CHARACTER} and
2883 @item @emph{Return value}:
2884 The converted date and time as a string.
2886 @item @emph{Example}:
2890 character(len=30) :: date
2893 ! Do something, main part of the program
2896 print *, 'Program was started on ', date
2897 end program test_ctime
2900 @item @emph{See Also}:
2901 @ref{GMTIME}, @ref{LTIME}, @ref{TIME}, @ref{TIME8}
2907 @section @code{DATE_AND_TIME} --- Date and time subroutine
2908 @fnindex DATE_AND_TIME
2909 @cindex date, current
2910 @cindex current date
2911 @cindex time, current
2912 @cindex current time
2915 @item @emph{Description}:
2916 @code{DATE_AND_TIME(DATE, TIME, ZONE, VALUES)} gets the corresponding date and
2917 time information from the real-time system clock. @var{DATE} is
2918 @code{INTENT(OUT)} and has form ccyymmdd. @var{TIME} is @code{INTENT(OUT)} and
2919 has form hhmmss.sss. @var{ZONE} is @code{INTENT(OUT)} and has form (+-)hhmm,
2920 representing the difference with respect to Coordinated Universal Time (UTC).
2921 Unavailable time and date parameters return blanks.
2923 @var{VALUES} is @code{INTENT(OUT)} and provides the following:
2925 @multitable @columnfractions .15 .30 .40
2926 @item @tab @code{VALUE(1)}: @tab The year
2927 @item @tab @code{VALUE(2)}: @tab The month
2928 @item @tab @code{VALUE(3)}: @tab The day of the month
2929 @item @tab @code{VALUE(4)}: @tab Time difference with UTC in minutes
2930 @item @tab @code{VALUE(5)}: @tab The hour of the day
2931 @item @tab @code{VALUE(6)}: @tab The minutes of the hour
2932 @item @tab @code{VALUE(7)}: @tab The seconds of the minute
2933 @item @tab @code{VALUE(8)}: @tab The milliseconds of the second
2936 @item @emph{Standard}:
2937 Fortran 95 and later
2942 @item @emph{Syntax}:
2943 @code{CALL DATE_AND_TIME([DATE, TIME, ZONE, VALUES])}
2945 @item @emph{Arguments}:
2946 @multitable @columnfractions .15 .70
2947 @item @var{DATE} @tab (Optional) The type shall be @code{CHARACTER(LEN=8)}
2948 or larger, and of default kind.
2949 @item @var{TIME} @tab (Optional) The type shall be @code{CHARACTER(LEN=10)}
2950 or larger, and of default kind.
2951 @item @var{ZONE} @tab (Optional) The type shall be @code{CHARACTER(LEN=5)}
2952 or larger, and of default kind.
2953 @item @var{VALUES}@tab (Optional) The type shall be @code{INTEGER(8)}.
2956 @item @emph{Return value}:
2959 @item @emph{Example}:
2961 program test_time_and_date
2962 character(8) :: date
2963 character(10) :: time
2964 character(5) :: zone
2965 integer,dimension(8) :: values
2966 ! using keyword arguments
2967 call date_and_time(date,time,zone,values)
2968 call date_and_time(DATE=date,ZONE=zone)
2969 call date_and_time(TIME=time)
2970 call date_and_time(VALUES=values)
2971 print '(a,2x,a,2x,a)', date, time, zone
2972 print '(8i5))', values
2973 end program test_time_and_date
2976 @item @emph{See also}:
2977 @ref{CPU_TIME}, @ref{SYSTEM_CLOCK}
2983 @section @code{DBLE} --- Double conversion function
2985 @cindex conversion, to real
2988 @item @emph{Description}:
2989 @code{DBLE(A)} Converts @var{A} to double precision real type.
2991 @item @emph{Standard}:
2992 Fortran 77 and later
2997 @item @emph{Syntax}:
2998 @code{RESULT = DBLE(A)}
3000 @item @emph{Arguments}:
3001 @multitable @columnfractions .15 .70
3002 @item @var{A} @tab The type shall be @code{INTEGER}, @code{REAL},
3006 @item @emph{Return value}:
3007 The return value is of type double precision real.
3009 @item @emph{Example}:
3014 complex :: z = (2.3,1.14)
3015 print *, dble(x), dble(i), dble(z)
3016 end program test_dble
3019 @item @emph{See also}:
3020 @ref{DFLOAT}, @ref{FLOAT}, @ref{REAL}
3026 @section @code{DCMPLX} --- Double complex conversion function
3028 @cindex complex numbers, conversion to
3029 @cindex conversion, to complex
3032 @item @emph{Description}:
3033 @code{DCMPLX(X [,Y])} returns a double complex number where @var{X} is
3034 converted to the real component. If @var{Y} is present it is converted to the
3035 imaginary component. If @var{Y} is not present then the imaginary component is
3036 set to 0.0. If @var{X} is complex then @var{Y} must not be present.
3038 @item @emph{Standard}:
3044 @item @emph{Syntax}:
3045 @code{RESULT = DCMPLX(X [, Y])}
3047 @item @emph{Arguments}:
3048 @multitable @columnfractions .15 .70
3049 @item @var{X} @tab The type may be @code{INTEGER}, @code{REAL},
3051 @item @var{Y} @tab (Optional if @var{X} is not @code{COMPLEX}.) May be
3052 @code{INTEGER} or @code{REAL}.
3055 @item @emph{Return value}:
3056 The return value is of type @code{COMPLEX(8)}
3058 @item @emph{Example}:
3068 print *, dcmplx(x,i)
3069 end program test_dcmplx
3076 @section @code{DFLOAT} --- Double conversion function
3078 @cindex conversion, to real
3081 @item @emph{Description}:
3082 @code{DFLOAT(A)} Converts @var{A} to double precision real type.
3084 @item @emph{Standard}:
3090 @item @emph{Syntax}:
3091 @code{RESULT = DFLOAT(A)}
3093 @item @emph{Arguments}:
3094 @multitable @columnfractions .15 .70
3095 @item @var{A} @tab The type shall be @code{INTEGER}.
3098 @item @emph{Return value}:
3099 The return value is of type double precision real.
3101 @item @emph{Example}:
3106 end program test_dfloat
3109 @item @emph{See also}:
3110 @ref{DBLE}, @ref{FLOAT}, @ref{REAL}
3116 @section @code{DIGITS} --- Significant digits function
3118 @cindex model representation, significant digits
3121 @item @emph{Description}:
3122 @code{DIGITS(X)} returns the number of significant digits of the internal model
3123 representation of @var{X}. For example, on a system using a 32-bit
3124 floating point representation, a default real number would likely return 24.
3126 @item @emph{Standard}:
3127 Fortran 95 and later
3132 @item @emph{Syntax}:
3133 @code{RESULT = DIGITS(X)}
3135 @item @emph{Arguments}:
3136 @multitable @columnfractions .15 .70
3137 @item @var{X} @tab The type may be @code{INTEGER} or @code{REAL}.
3140 @item @emph{Return value}:
3141 The return value is of type @code{INTEGER}.
3143 @item @emph{Example}:
3146 integer :: i = 12345
3152 end program test_digits
3159 @section @code{DIM} --- Positive difference
3163 @cindex positive difference
3166 @item @emph{Description}:
3167 @code{DIM(X,Y)} returns the difference @code{X-Y} if the result is positive;
3168 otherwise returns zero.
3170 @item @emph{Standard}:
3171 Fortran 77 and later
3176 @item @emph{Syntax}:
3177 @code{RESULT = DIM(X, Y)}
3179 @item @emph{Arguments}:
3180 @multitable @columnfractions .15 .70
3181 @item @var{X} @tab The type shall be @code{INTEGER} or @code{REAL}
3182 @item @var{Y} @tab The type shall be the same type and kind as @var{X}.
3185 @item @emph{Return value}:
3186 The return value is of type @code{INTEGER} or @code{REAL}.
3188 @item @emph{Example}:
3194 x = dim(4.345_8, 2.111_8)
3197 end program test_dim
3200 @item @emph{Specific names}:
3201 @multitable @columnfractions .20 .20 .20 .25
3202 @item Name @tab Argument @tab Return type @tab Standard
3203 @item @code{IDIM(X,Y)} @tab @code{INTEGER(4) X,Y} @tab @code{INTEGER(4)} @tab Fortran 77 and later
3204 @item @code{DDIM(X,Y)} @tab @code{REAL(8) X,Y} @tab @code{REAL(8)} @tab Fortran 77 and later
3211 @section @code{DOT_PRODUCT} --- Dot product function
3212 @fnindex DOT_PRODUCT
3214 @cindex vector product
3215 @cindex product, vector
3218 @item @emph{Description}:
3219 @code{DOT_PRODUCT(VECTOR_A, VECTOR_B)} computes the dot product multiplication
3220 of two vectors @var{VECTOR_A} and @var{VECTOR_B}. The two vectors may be
3221 either numeric or logical and must be arrays of rank one and of equal size. If
3222 the vectors are @code{INTEGER} or @code{REAL}, the result is
3223 @code{SUM(VECTOR_A*VECTOR_B)}. If the vectors are @code{COMPLEX}, the result
3224 is @code{SUM(CONJG(VECTOR_A)*VECTOR_B)}. If the vectors are @code{LOGICAL},
3225 the result is @code{ANY(VECTOR_A .AND. VECTOR_B)}.
3227 @item @emph{Standard}:
3228 Fortran 95 and later
3231 Transformational function
3233 @item @emph{Syntax}:
3234 @code{RESULT = DOT_PRODUCT(VECTOR_A, VECTOR_B)}
3236 @item @emph{Arguments}:
3237 @multitable @columnfractions .15 .70
3238 @item @var{VECTOR_A} @tab The type shall be numeric or @code{LOGICAL}, rank 1.
3239 @item @var{VECTOR_B} @tab The type shall be numeric if @var{VECTOR_A} is of numeric type or @code{LOGICAL} if @var{VECTOR_A} is of type @code{LOGICAL}. @var{VECTOR_B} shall be a rank-one array.
3242 @item @emph{Return value}:
3243 If the arguments are numeric, the return value is a scaler of numeric type,
3244 @code{INTEGER}, @code{REAL}, or @code{COMPLEX}. If the arguments are
3245 @code{LOGICAL}, the return value is @code{.TRUE.} or @code{.FALSE.}.
3247 @item @emph{Example}:
3249 program test_dot_prod
3250 integer, dimension(3) :: a, b
3257 print *, dot_product(a,b)
3258 end program test_dot_prod
3265 @section @code{DPROD} --- Double product function
3267 @cindex product, double-precision
3270 @item @emph{Description}:
3271 @code{DPROD(X,Y)} returns the product @code{X*Y}.
3273 @item @emph{Standard}:
3274 Fortran 77 and later
3279 @item @emph{Syntax}:
3280 @code{RESULT = DPROD(X, Y)}
3282 @item @emph{Arguments}:
3283 @multitable @columnfractions .15 .70
3284 @item @var{X} @tab The type shall be @code{REAL}.
3285 @item @var{Y} @tab The type shall be @code{REAL}.
3288 @item @emph{Return value}:
3289 The return value is of type @code{REAL(8)}.
3291 @item @emph{Example}:
3299 end program test_dprod
3306 @section @code{DREAL} --- Double real part function
3308 @cindex complex numbers, real part
3311 @item @emph{Description}:
3312 @code{DREAL(Z)} returns the real part of complex variable @var{Z}.
3314 @item @emph{Standard}:
3320 @item @emph{Syntax}:
3321 @code{RESULT = DREAL(A)}
3323 @item @emph{Arguments}:
3324 @multitable @columnfractions .15 .70
3325 @item @var{A} @tab The type shall be @code{COMPLEX(8)}.
3328 @item @emph{Return value}:
3329 The return value is of type @code{REAL(8)}.
3331 @item @emph{Example}:
3334 complex(8) :: z = (1.3_8,7.2_8)
3336 end program test_dreal
3339 @item @emph{See also}:
3347 @section @code{DTIME} --- Execution time subroutine (or function)
3349 @cindex time, elapsed
3350 @cindex elapsed time
3353 @item @emph{Description}:
3354 @code{DTIME(TARRAY, RESULT)} initially returns the number of seconds of runtime
3355 since the start of the process's execution in @var{RESULT}. @var{TARRAY}
3356 returns the user and system components of this time in @code{TARRAY(1)} and
3357 @code{TARRAY(2)} respectively. @var{RESULT} is equal to @code{TARRAY(1) +
3360 Subsequent invocations of @code{DTIME} return values accumulated since the
3361 previous invocation.
3363 On some systems, the underlying timings are represented using types with
3364 sufficiently small limits that overflows (wrap around) are possible, such as
3365 32-bit types. Therefore, the values returned by this intrinsic might be, or
3366 become, negative, or numerically less than previous values, during a single
3367 run of the compiled program.
3369 Please note, that this implementation is thread safe if used within OpenMP
3370 directives, i.e., its state will be consistent while called from multiple
3371 threads. However, if @code{DTIME} is called from multiple threads, the result
3372 is still the time since the last invocation. This may not give the intended
3373 results. If possible, use @code{CPU_TIME} instead.
3375 This intrinsic is provided in both subroutine and function forms; however,
3376 only one form can be used in any given program unit.
3378 @var{TARRAY} and @var{RESULT} are @code{INTENT(OUT)} and provide the following:
3380 @multitable @columnfractions .15 .30 .40
3381 @item @tab @code{TARRAY(1)}: @tab User time in seconds.
3382 @item @tab @code{TARRAY(2)}: @tab System time in seconds.
3383 @item @tab @code{RESULT}: @tab Run time since start in seconds.
3386 @item @emph{Standard}:
3390 Subroutine, function
3392 @item @emph{Syntax}:
3393 @multitable @columnfractions .80
3394 @item @code{CALL DTIME(TARRAY, RESULT)}.
3395 @item @code{RESULT = DTIME(TARRAY)}, (not recommended).
3398 @item @emph{Arguments}:
3399 @multitable @columnfractions .15 .70
3400 @item @var{TARRAY}@tab The type shall be @code{REAL, DIMENSION(2)}.
3401 @item @var{RESULT}@tab The type shall be @code{REAL}.
3404 @item @emph{Return value}:
3405 Elapsed time in seconds since the last invocation or since the start of program
3406 execution if not called before.
3408 @item @emph{Example}:
3412 real, dimension(2) :: tarray
3414 call dtime(tarray, result)
3418 do i=1,100000000 ! Just a delay
3421 call dtime(tarray, result)
3425 end program test_dtime
3428 @item @emph{See also}:
3436 @section @code{EOSHIFT} --- End-off shift elements of an array
3438 @cindex array, shift
3441 @item @emph{Description}:
3442 @code{EOSHIFT(ARRAY, SHIFT[, BOUNDARY, DIM])} performs an end-off shift on
3443 elements of @var{ARRAY} along the dimension of @var{DIM}. If @var{DIM} is
3444 omitted it is taken to be @code{1}. @var{DIM} is a scaler of type
3445 @code{INTEGER} in the range of @math{1 /leq DIM /leq n)} where @math{n} is the
3446 rank of @var{ARRAY}. If the rank of @var{ARRAY} is one, then all elements of
3447 @var{ARRAY} are shifted by @var{SHIFT} places. If rank is greater than one,
3448 then all complete rank one sections of @var{ARRAY} along the given dimension are
3449 shifted. Elements shifted out one end of each rank one section are dropped. If
3450 @var{BOUNDARY} is present then the corresponding value of from @var{BOUNDARY}
3451 is copied back in the other end. If @var{BOUNDARY} is not present then the
3452 following are copied in depending on the type of @var{ARRAY}.
3454 @multitable @columnfractions .15 .80
3455 @item @emph{Array Type} @tab @emph{Boundary Value}
3456 @item Numeric @tab 0 of the type and kind of @var{ARRAY}.
3457 @item Logical @tab @code{.FALSE.}.
3458 @item Character(@var{len}) @tab @var{len} blanks.
3461 @item @emph{Standard}:
3462 Fortran 95 and later
3465 Transformational function
3467 @item @emph{Syntax}:
3468 @code{RESULT = EOSHIFT(ARRAY, SHIFT [, BOUNDARY, DIM])}
3470 @item @emph{Arguments}:
3471 @multitable @columnfractions .15 .70
3472 @item @var{ARRAY} @tab May be any type, not scaler.
3473 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
3474 @item @var{BOUNDARY} @tab Same type as @var{ARRAY}.
3475 @item @var{DIM} @tab The type shall be @code{INTEGER}.
3478 @item @emph{Return value}:
3479 Returns an array of same type and rank as the @var{ARRAY} argument.
3481 @item @emph{Example}:
3483 program test_eoshift
3484 integer, dimension(3,3) :: a
3485 a = reshape( (/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /), (/ 3, 3 /))
3486 print '(3i3)', a(1,:)
3487 print '(3i3)', a(2,:)
3488 print '(3i3)', a(3,:)
3489 a = EOSHIFT(a, SHIFT=(/1, 2, 1/), BOUNDARY=-5, DIM=2)
3491 print '(3i3)', a(1,:)
3492 print '(3i3)', a(2,:)
3493 print '(3i3)', a(3,:)
3494 end program test_eoshift
3501 @section @code{EPSILON} --- Epsilon function
3503 @cindex model representation, epsilon
3506 @item @emph{Description}:
3507 @code{EPSILON(X)} returns a nearly negligible number relative to @code{1}.
3509 @item @emph{Standard}:
3510 Fortran 95 and later
3515 @item @emph{Syntax}:
3516 @code{RESULT = EPSILON(X)}
3518 @item @emph{Arguments}:
3519 @multitable @columnfractions .15 .70
3520 @item @var{X} @tab The type shall be @code{REAL}.
3523 @item @emph{Return value}:
3524 The return value is of same type as the argument.
3526 @item @emph{Example}:
3528 program test_epsilon
3533 end program test_epsilon
3540 @section @code{ERF} --- Error function
3542 @cindex error function
3545 @item @emph{Description}:
3546 @code{ERF(X)} computes the error function of @var{X}.
3548 @item @emph{Standard}:
3549 Fortran 2008 and later
3554 @item @emph{Syntax}:
3555 @code{RESULT = ERF(X)}
3557 @item @emph{Arguments}:
3558 @multitable @columnfractions .15 .70
3559 @item @var{X} @tab The type shall be @code{REAL}.
3562 @item @emph{Return value}:
3563 The return value is of type @code{REAL}, of the same kind as
3564 @var{X} and lies in the range @math{-1 \leq erf (x) \leq 1 }.
3566 @item @emph{Example}:
3569 real(8) :: x = 0.17_8
3571 end program test_erf
3574 @item @emph{Specific names}:
3575 @multitable @columnfractions .20 .20 .20 .25
3576 @item Name @tab Argument @tab Return type @tab Standard
3577 @item @code{DERF(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
3584 @section @code{ERFC} --- Error function
3586 @cindex error function, complementary
3589 @item @emph{Description}:
3590 @code{ERFC(X)} computes the complementary error function of @var{X}.
3592 @item @emph{Standard}:
3593 Fortran 2008 and later
3598 @item @emph{Syntax}:
3599 @code{RESULT = ERFC(X)}
3601 @item @emph{Arguments}:
3602 @multitable @columnfractions .15 .70
3603 @item @var{X} @tab The type shall be @code{REAL}.
3606 @item @emph{Return value}:
3607 The return value is of type @code{REAL} and of the same kind as @var{X}.
3608 It lies in the range @math{ 0 \leq erfc (x) \leq 2 }.
3610 @item @emph{Example}:
3613 real(8) :: x = 0.17_8
3615 end program test_erfc
3618 @item @emph{Specific names}:
3619 @multitable @columnfractions .20 .20 .20 .25
3620 @item Name @tab Argument @tab Return type @tab Standard
3621 @item @code{DERFC(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
3628 @section @code{ERFC_SCALED} --- Error function
3629 @fnindex ERFC_SCALED
3630 @cindex error function, complementary, exponentially-scaled
3633 @item @emph{Description}:
3634 @code{ERFC_SCALED(X)} computes the exponentially-scaled complementary
3635 error function of @var{X}.
3637 @item @emph{Standard}:
3638 Fortran 2008 and later
3643 @item @emph{Syntax}:
3644 @code{RESULT = ERFC_SCALED(X)}
3646 @item @emph{Arguments}:
3647 @multitable @columnfractions .15 .70
3648 @item @var{X} @tab The type shall be @code{REAL}.
3651 @item @emph{Return value}:
3652 The return value is of type @code{REAL} and of the same kind as @var{X}.
3654 @item @emph{Example}:
3656 program test_erfc_scaled
3657 real(8) :: x = 0.17_8
3659 end program test_erfc_scaled
3666 @section @code{ETIME} --- Execution time subroutine (or function)
3668 @cindex time, elapsed
3671 @item @emph{Description}:
3672 @code{ETIME(TARRAY, RESULT)} returns the number of seconds of runtime
3673 since the start of the process's execution in @var{RESULT}. @var{TARRAY}
3674 returns the user and system components of this time in @code{TARRAY(1)} and
3675 @code{TARRAY(2)} respectively. @var{RESULT} is equal to @code{TARRAY(1) + TARRAY(2)}.
3677 On some systems, the underlying timings are represented using types with
3678 sufficiently small limits that overflows (wrap around) are possible, such as
3679 32-bit types. Therefore, the values returned by this intrinsic might be, or
3680 become, negative, or numerically less than previous values, during a single
3681 run of the compiled program.
3683 This intrinsic is provided in both subroutine and function forms; however,
3684 only one form can be used in any given program unit.
3686 @var{TARRAY} and @var{RESULT} are @code{INTENT(OUT)} and provide the following:
3688 @multitable @columnfractions .15 .30 .60
3689 @item @tab @code{TARRAY(1)}: @tab User time in seconds.
3690 @item @tab @code{TARRAY(2)}: @tab System time in seconds.
3691 @item @tab @code{RESULT}: @tab Run time since start in seconds.
3694 @item @emph{Standard}:
3698 Subroutine, function
3700 @item @emph{Syntax}:
3701 @multitable @columnfractions .80
3702 @item @code{CALL ETIME(TARRAY, RESULT)}.
3703 @item @code{RESULT = ETIME(TARRAY)}, (not recommended).
3706 @item @emph{Arguments}:
3707 @multitable @columnfractions .15 .70
3708 @item @var{TARRAY}@tab The type shall be @code{REAL, DIMENSION(2)}.
3709 @item @var{RESULT}@tab The type shall be @code{REAL}.
3712 @item @emph{Return value}:
3713 Elapsed time in seconds since the start of program execution.
3715 @item @emph{Example}:
3719 real, dimension(2) :: tarray
3721 call ETIME(tarray, result)
3725 do i=1,100000000 ! Just a delay
3728 call ETIME(tarray, result)
3732 end program test_etime
3735 @item @emph{See also}:
3743 @section @code{EXIT} --- Exit the program with status.
3745 @cindex program termination
3746 @cindex terminate program
3749 @item @emph{Description}:
3750 @code{EXIT} causes immediate termination of the program with status. If status
3751 is omitted it returns the canonical @emph{success} for the system. All Fortran
3752 I/O units are closed.
3754 @item @emph{Standard}:
3760 @item @emph{Syntax}:
3761 @code{CALL EXIT([STATUS])}
3763 @item @emph{Arguments}:
3764 @multitable @columnfractions .15 .70
3765 @item @var{STATUS} @tab Shall be an @code{INTEGER} of the default kind.
3768 @item @emph{Return value}:
3769 @code{STATUS} is passed to the parent process on exit.
3771 @item @emph{Example}:
3774 integer :: STATUS = 0
3775 print *, 'This program is going to exit.'
3777 end program test_exit
3780 @item @emph{See also}:
3781 @ref{ABORT}, @ref{KILL}
3787 @section @code{EXP} --- Exponential function
3793 @cindex exponential function
3794 @cindex logarithmic function, inverse
3797 @item @emph{Description}:
3798 @code{EXP(X)} computes the base @math{e} exponential of @var{X}.
3800 @item @emph{Standard}:
3801 Fortran 77 and later, has overloads that are GNU extensions
3806 @item @emph{Syntax}:
3807 @code{RESULT = EXP(X)}
3809 @item @emph{Arguments}:
3810 @multitable @columnfractions .15 .70
3811 @item @var{X} @tab The type shall be @code{REAL} or
3815 @item @emph{Return value}:
3816 The return value has same type and kind as @var{X}.
3818 @item @emph{Example}:
3823 end program test_exp
3826 @item @emph{Specific names}:
3827 @multitable @columnfractions .20 .20 .20 .25
3828 @item Name @tab Argument @tab Return type @tab Standard
3829 @item @code{DEXP(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
3830 @item @code{CEXP(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab Fortran 77 and later
3831 @item @code{ZEXP(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
3832 @item @code{CDEXP(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
3839 @section @code{EXPONENT} --- Exponent function
3841 @cindex real number, exponent
3842 @cindex floating point, exponent
3845 @item @emph{Description}:
3846 @code{EXPONENT(X)} returns the value of the exponent part of @var{X}. If @var{X}
3847 is zero the value returned is zero.
3849 @item @emph{Standard}:
3850 Fortran 95 and later
3855 @item @emph{Syntax}:
3856 @code{RESULT = EXPONENT(X)}
3858 @item @emph{Arguments}:
3859 @multitable @columnfractions .15 .70
3860 @item @var{X} @tab The type shall be @code{REAL}.
3863 @item @emph{Return value}:
3864 The return value is of type default @code{INTEGER}.
3866 @item @emph{Example}:
3868 program test_exponent
3873 print *, exponent(0.0)
3874 end program test_exponent
3881 @section @code{FDATE} --- Get the current time as a string
3883 @cindex time, current
3884 @cindex current time
3885 @cindex date, current
3886 @cindex current date
3889 @item @emph{Description}:
3890 @code{FDATE(DATE)} returns the current date (using the same format as
3891 @code{CTIME}) in @var{DATE}. It is equivalent to @code{CALL CTIME(DATE,
3894 This intrinsic is provided in both subroutine and function forms; however,
3895 only one form can be used in any given program unit.
3897 @var{DATE} is an @code{INTENT(OUT)} @code{CHARACTER} variable of the
3900 @item @emph{Standard}:
3904 Subroutine, function
3906 @item @emph{Syntax}:
3907 @multitable @columnfractions .80
3908 @item @code{CALL FDATE(DATE)}.
3909 @item @code{DATE = FDATE()}, (not recommended).
3912 @item @emph{Arguments}:
3913 @multitable @columnfractions .15 .70
3914 @item @var{DATE}@tab The type shall be of type @code{CHARACTER} of the
3918 @item @emph{Return value}:
3919 The current date as a string.
3921 @item @emph{Example}:
3925 character(len=30) :: date
3927 print *, 'Program started on ', date
3928 do i = 1, 100000000 ! Just a delay
3932 print *, 'Program ended on ', date
3933 end program test_fdate
3940 @section @code{FLOAT} --- Convert integer to default real
3942 @cindex conversion, to real
3945 @item @emph{Description}:
3946 @code{FLOAT(A)} converts the integer @var{A} to a default real value.
3948 @item @emph{Standard}:
3949 Fortran 77 and later
3954 @item @emph{Syntax}:
3955 @code{RESULT = FLOAT(A)}
3957 @item @emph{Arguments}:
3958 @multitable @columnfractions .15 .70
3959 @item @var{A} @tab The type shall be @code{INTEGER}.
3962 @item @emph{Return value}:
3963 The return value is of type default @code{REAL}.
3965 @item @emph{Example}:
3969 if (float(i) /= 1.) call abort
3970 end program test_float
3973 @item @emph{See also}:
3974 @ref{DBLE}, @ref{DFLOAT}, @ref{REAL}
3980 @section @code{FGET} --- Read a single character in stream mode from stdin
3982 @cindex read character, stream mode
3983 @cindex stream mode, read character
3984 @cindex file operation, read character
3987 @item @emph{Description}:
3988 Read a single character in stream mode from stdin by bypassing normal
3989 formatted output. Stream I/O should not be mixed with normal record-oriented
3990 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
3992 This intrinsic is provided in both subroutine and function forms; however,
3993 only one form can be used in any given program unit.
3995 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
3996 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
3997 Programmers should consider the use of new stream IO feature in new code
3998 for future portability. See also @ref{Fortran 2003 status}.
4000 @item @emph{Standard}:
4004 Subroutine, function
4006 @item @emph{Syntax}:
4007 @code{CALL FGET(C [, STATUS])}
4009 @item @emph{Arguments}:
4010 @multitable @columnfractions .15 .70
4011 @item @var{C} @tab The type shall be @code{CHARACTER} and of default
4013 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
4014 Returns 0 on success, -1 on end-of-file, and a
4015 system specific positive error code otherwise.
4018 @item @emph{Example}:
4021 INTEGER, PARAMETER :: strlen = 100
4022 INTEGER :: status, i = 1
4023 CHARACTER(len=strlen) :: str = ""
4025 WRITE (*,*) 'Enter text:'
4027 CALL fget(str(i:i), status)
4028 if (status /= 0 .OR. i > strlen) exit
4031 WRITE (*,*) TRIM(str)
4035 @item @emph{See also}:
4036 @ref{FGETC}, @ref{FPUT}, @ref{FPUTC}
4042 @section @code{FGETC} --- Read a single character in stream mode
4044 @cindex read character, stream mode
4045 @cindex stream mode, read character
4046 @cindex file operation, read character
4049 @item @emph{Description}:
4050 Read a single character in stream mode by bypassing normal formatted output.
4051 Stream I/O should not be mixed with normal record-oriented (formatted or
4052 unformatted) I/O on the same unit; the results are unpredictable.
4054 This intrinsic is provided in both subroutine and function forms; however,
4055 only one form can be used in any given program unit.
4057 Note that the @code{FGET} intrinsic is provided for backwards compatibility
4058 with @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
4059 Programmers should consider the use of new stream IO feature in new code
4060 for future portability. See also @ref{Fortran 2003 status}.
4062 @item @emph{Standard}:
4066 Subroutine, function
4068 @item @emph{Syntax}:
4069 @code{CALL FGETC(UNIT, C [, STATUS])}
4071 @item @emph{Arguments}:
4072 @multitable @columnfractions .15 .70
4073 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
4074 @item @var{C} @tab The type shall be @code{CHARACTER} and of default
4076 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
4077 Returns 0 on success, -1 on end-of-file and a
4078 system specific positive error code otherwise.
4081 @item @emph{Example}:
4084 INTEGER :: fd = 42, status
4087 OPEN(UNIT=fd, FILE="/etc/passwd", ACTION="READ", STATUS = "OLD")
4089 CALL fgetc(fd, c, status)
4090 IF (status /= 0) EXIT
4097 @item @emph{See also}:
4098 @ref{FGET}, @ref{FPUT}, @ref{FPUTC}
4104 @section @code{FLOOR} --- Integer floor function
4107 @cindex rounding, floor
4110 @item @emph{Description}:
4111 @code{FLOOR(A)} returns the greatest integer less than or equal to @var{X}.
4113 @item @emph{Standard}:
4114 Fortran 95 and later
4119 @item @emph{Syntax}:
4120 @code{RESULT = FLOOR(A [, KIND])}
4122 @item @emph{Arguments}:
4123 @multitable @columnfractions .15 .70
4124 @item @var{A} @tab The type shall be @code{REAL}.
4125 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
4126 expression indicating the kind parameter of
4130 @item @emph{Return value}:
4131 The return value is of type @code{INTEGER(KIND)} if @var{KIND} is present
4132 and of default-kind @code{INTEGER} otherwise.
4134 @item @emph{Example}:
4139 print *, floor(x) ! returns 63
4140 print *, floor(y) ! returns -64
4141 end program test_floor
4144 @item @emph{See also}:
4145 @ref{CEILING}, @ref{NINT}
4152 @section @code{FLUSH} --- Flush I/O unit(s)
4154 @cindex file operation, flush
4157 @item @emph{Description}:
4158 Flushes Fortran unit(s) currently open for output. Without the optional
4159 argument, all units are flushed, otherwise just the unit specified.
4161 @item @emph{Standard}:
4167 @item @emph{Syntax}:
4168 @code{CALL FLUSH(UNIT)}
4170 @item @emph{Arguments}:
4171 @multitable @columnfractions .15 .70
4172 @item @var{UNIT} @tab (Optional) The type shall be @code{INTEGER}.
4176 Beginning with the Fortran 2003 standard, there is a @code{FLUSH}
4177 statement that should be preferred over the @code{FLUSH} intrinsic.
4184 @section @code{FNUM} --- File number function
4186 @cindex file operation, file number
4189 @item @emph{Description}:
4190 @code{FNUM(UNIT)} returns the POSIX file descriptor number corresponding to the
4191 open Fortran I/O unit @code{UNIT}.
4193 @item @emph{Standard}:
4199 @item @emph{Syntax}:
4200 @code{RESULT = FNUM(UNIT)}
4202 @item @emph{Arguments}:
4203 @multitable @columnfractions .15 .70
4204 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
4207 @item @emph{Return value}:
4208 The return value is of type @code{INTEGER}
4210 @item @emph{Example}:
4214 open (unit=10, status = "scratch")
4218 end program test_fnum
4225 @section @code{FPUT} --- Write a single character in stream mode to stdout
4227 @cindex write character, stream mode
4228 @cindex stream mode, write character
4229 @cindex file operation, write character
4232 @item @emph{Description}:
4233 Write a single character in stream mode to stdout by bypassing normal
4234 formatted output. Stream I/O should not be mixed with normal record-oriented
4235 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
4237 This intrinsic is provided in both subroutine and function forms; however,
4238 only one form can be used in any given program unit.
4240 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
4241 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
4242 Programmers should consider the use of new stream IO feature in new code
4243 for future portability. See also @ref{Fortran 2003 status}.
4245 @item @emph{Standard}:
4249 Subroutine, function
4251 @item @emph{Syntax}:
4252 @code{CALL FPUT(C [, STATUS])}
4254 @item @emph{Arguments}:
4255 @multitable @columnfractions .15 .70
4256 @item @var{C} @tab The type shall be @code{CHARACTER} and of default
4258 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
4259 Returns 0 on success, -1 on end-of-file and a
4260 system specific positive error code otherwise.
4263 @item @emph{Example}:
4266 CHARACTER(len=10) :: str = "gfortran"
4268 DO i = 1, len_trim(str)
4274 @item @emph{See also}:
4275 @ref{FPUTC}, @ref{FGET}, @ref{FGETC}
4281 @section @code{FPUTC} --- Write a single character in stream mode
4283 @cindex write character, stream mode
4284 @cindex stream mode, write character
4285 @cindex file operation, write character
4288 @item @emph{Description}:
4289 Write a single character in stream mode by bypassing normal formatted
4290 output. Stream I/O should not be mixed with normal record-oriented
4291 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
4293 This intrinsic is provided in both subroutine and function forms; however,
4294 only one form can be used in any given program unit.
4296 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
4297 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
4298 Programmers should consider the use of new stream IO feature in new code
4299 for future portability. See also @ref{Fortran 2003 status}.
4301 @item @emph{Standard}:
4305 Subroutine, function
4307 @item @emph{Syntax}:
4308 @code{CALL FPUTC(UNIT, C [, STATUS])}
4310 @item @emph{Arguments}:
4311 @multitable @columnfractions .15 .70
4312 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
4313 @item @var{C} @tab The type shall be @code{CHARACTER} and of default
4315 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
4316 Returns 0 on success, -1 on end-of-file and a
4317 system specific positive error code otherwise.
4320 @item @emph{Example}:
4323 CHARACTER(len=10) :: str = "gfortran"
4324 INTEGER :: fd = 42, i
4326 OPEN(UNIT = fd, FILE = "out", ACTION = "WRITE", STATUS="NEW")
4327 DO i = 1, len_trim(str)
4328 CALL fputc(fd, str(i:i))
4334 @item @emph{See also}:
4335 @ref{FPUT}, @ref{FGET}, @ref{FGETC}
4341 @section @code{FRACTION} --- Fractional part of the model representation
4343 @cindex real number, fraction
4344 @cindex floating point, fraction
4347 @item @emph{Description}:
4348 @code{FRACTION(X)} returns the fractional part of the model
4349 representation of @code{X}.
4351 @item @emph{Standard}:
4352 Fortran 95 and later
4357 @item @emph{Syntax}:
4358 @code{Y = FRACTION(X)}
4360 @item @emph{Arguments}:
4361 @multitable @columnfractions .15 .70
4362 @item @var{X} @tab The type of the argument shall be a @code{REAL}.
4365 @item @emph{Return value}:
4366 The return value is of the same type and kind as the argument.
4367 The fractional part of the model representation of @code{X} is returned;
4368 it is @code{X * RADIX(X)**(-EXPONENT(X))}.
4370 @item @emph{Example}:
4372 program test_fraction
4375 print *, fraction(x), x * radix(x)**(-exponent(x))
4376 end program test_fraction
4384 @section @code{FREE} --- Frees memory
4386 @cindex pointer, cray
4389 @item @emph{Description}:
4390 Frees memory previously allocated by @code{MALLOC()}. The @code{FREE}
4391 intrinsic is an extension intended to be used with Cray pointers, and is
4392 provided in GNU Fortran to allow user to compile legacy code. For
4393 new code using Fortran 95 pointers, the memory de-allocation intrinsic is
4396 @item @emph{Standard}:
4402 @item @emph{Syntax}:
4403 @code{CALL FREE(PTR)}
4405 @item @emph{Arguments}:
4406 @multitable @columnfractions .15 .70
4407 @item @var{PTR} @tab The type shall be @code{INTEGER}. It represents the
4408 location of the memory that should be de-allocated.
4411 @item @emph{Return value}:
4414 @item @emph{Example}:
4415 See @code{MALLOC} for an example.
4417 @item @emph{See also}:
4424 @section @code{FSEEK} --- Low level file positioning subroutine
4426 @cindex file operation, seek
4427 @cindex file operation, position
4430 @item @emph{Description}:
4431 Moves @var{UNIT} to the specified @var{OFFSET}. If @var{WHENCE}
4432 is set to 0, the @var{OFFSET} is taken as an absolute value @code{SEEK_SET},
4433 if set to 1, @var{OFFSET} is taken to be relative to the current position
4434 @code{SEEK_CUR}, and if set to 2 relative to the end of the file @code{SEEK_END}.
4435 On error, @var{STATUS} is set to a nonzero value. If @var{STATUS} the seek
4438 This intrinsic routine is not fully backwards compatible with @command{g77}.
4439 In @command{g77}, the @code{FSEEK} takes a statement label instead of a
4440 @var{STATUS} variable. If FSEEK is used in old code, change
4442 CALL FSEEK(UNIT, OFFSET, WHENCE, *label)
4447 CALL FSEEK(UNIT, OFFSET, WHENCE, status)
4448 IF (status /= 0) GOTO label
4451 Please note that GNU Fortran provides the Fortran 2003 Stream facility.
4452 Programmers should consider the use of new stream IO feature in new code
4453 for future portability. See also @ref{Fortran 2003 status}.
4455 @item @emph{Standard}:
4461 @item @emph{Syntax}:
4462 @code{CALL FSEEK(UNIT, OFFSET, WHENCE[, STATUS])}
4464 @item @emph{Arguments}:
4465 @multitable @columnfractions .15 .70
4466 @item @var{UNIT} @tab Shall be a scalar of type @code{INTEGER}.
4467 @item @var{OFFSET} @tab Shall be a scalar of type @code{INTEGER}.
4468 @item @var{WHENCE} @tab Shall be a scalar of type @code{INTEGER}.
4469 Its value shall be either 0, 1 or 2.
4470 @item @var{STATUS} @tab (Optional) shall be a scalar of type
4474 @item @emph{Example}:
4477 INTEGER, PARAMETER :: SEEK_SET = 0, SEEK_CUR = 1, SEEK_END = 2
4478 INTEGER :: fd, offset, ierr
4484 OPEN(UNIT=fd, FILE="fseek.test")
4485 CALL FSEEK(fd, offset, SEEK_SET, ierr) ! move to OFFSET
4486 print *, FTELL(fd), ierr
4488 CALL FSEEK(fd, 0, SEEK_END, ierr) ! move to end
4489 print *, FTELL(fd), ierr
4491 CALL FSEEK(fd, 0, SEEK_SET, ierr) ! move to beginning
4492 print *, FTELL(fd), ierr
4498 @item @emph{See also}:
4505 @section @code{FSTAT} --- Get file status
4507 @cindex file system, file status
4510 @item @emph{Description}:
4511 @code{FSTAT} is identical to @ref{STAT}, except that information about an
4512 already opened file is obtained.
4514 The elements in @code{BUFF} are the same as described by @ref{STAT}.
4516 This intrinsic is provided in both subroutine and function forms; however,
4517 only one form can be used in any given program unit.
4519 @item @emph{Standard}:
4523 Subroutine, function
4525 @item @emph{Syntax}:
4526 @code{CALL FSTAT(UNIT, BUFF [, STATUS])}
4528 @item @emph{Arguments}:
4529 @multitable @columnfractions .15 .70
4530 @item @var{UNIT} @tab An open I/O unit number of type @code{INTEGER}.
4531 @item @var{BUFF} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
4532 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}. Returns 0
4533 on success and a system specific error code otherwise.
4536 @item @emph{Example}:
4537 See @ref{STAT} for an example.
4539 @item @emph{See also}:
4540 To stat a link: @ref{LSTAT}, to stat a file: @ref{STAT}
4546 @section @code{FTELL} --- Current stream position
4548 @cindex file operation, position
4551 @item @emph{Description}:
4552 Retrieves the current position within an open file.
4554 This intrinsic is provided in both subroutine and function forms; however,
4555 only one form can be used in any given program unit.
4557 @item @emph{Standard}:
4561 Subroutine, function
4563 @item @emph{Syntax}:
4564 @multitable @columnfractions .80
4565 @item @code{CALL FTELL(UNIT, OFFSET)}
4566 @item @code{OFFSET = FTELL(UNIT)}
4569 @item @emph{Arguments}:
4570 @multitable @columnfractions .15 .70
4571 @item @var{OFFSET} @tab Shall of type @code{INTEGER}.
4572 @item @var{UNIT} @tab Shall of type @code{INTEGER}.
4575 @item @emph{Return value}:
4576 In either syntax, @var{OFFSET} is set to the current offset of unit
4577 number @var{UNIT}, or to @math{-1} if the unit is not currently open.
4579 @item @emph{Example}:
4583 OPEN(10, FILE="temp.dat")
4589 @item @emph{See also}:
4596 @section @code{GAMMA} --- Gamma function
4599 @cindex Gamma function
4600 @cindex Factorial function
4603 @item @emph{Description}:
4604 @code{GAMMA(X)} computes Gamma (@math{\Gamma}) of @var{X}. For positive,
4605 integer values of @var{X} the Gamma function simplifies to the factorial
4606 function @math{\Gamma(x)=(x-1)!}.
4610 \Gamma(x) = \int_0^\infty t^{x-1}{\rm e}^{-t}\,{\rm d}t
4614 @item @emph{Standard}:
4615 Fortran 2008 and later
4620 @item @emph{Syntax}:
4623 @item @emph{Arguments}:
4624 @multitable @columnfractions .15 .70
4625 @item @var{X} @tab Shall be of type @code{REAL} and neither zero
4626 nor a negative integer.
4629 @item @emph{Return value}:
4630 The return value is of type @code{REAL} of the same kind as @var{X}.
4632 @item @emph{Example}:
4636 x = gamma(x) ! returns 1.0
4637 end program test_gamma
4640 @item @emph{Specific names}:
4641 @multitable @columnfractions .20 .20 .20 .25
4642 @item Name @tab Argument @tab Return type @tab Standard
4643 @item @code{GAMMA(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab GNU Extension
4644 @item @code{DGAMMA(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU Extension
4647 @item @emph{See also}:
4648 Logarithm of the Gamma function: @ref{LOG_GAMMA}
4655 @section @code{GERROR} --- Get last system error message
4657 @cindex system, error handling
4660 @item @emph{Description}:
4661 Returns the system error message corresponding to the last system error.
4662 This resembles the functionality of @code{strerror(3)} in C.
4664 @item @emph{Standard}:
4670 @item @emph{Syntax}:
4671 @code{CALL GERROR(RESULT)}
4673 @item @emph{Arguments}:
4674 @multitable @columnfractions .15 .70
4675 @item @var{RESULT} @tab Shall of type @code{CHARACTER} and of default
4678 @item @emph{Example}:
4681 CHARACTER(len=100) :: msg
4687 @item @emph{See also}:
4688 @ref{IERRNO}, @ref{PERROR}
4694 @section @code{GETARG} --- Get command line arguments
4696 @cindex command-line arguments
4697 @cindex arguments, to program
4700 @item @emph{Description}:
4701 Retrieve the @var{POS}-th argument that was passed on the
4702 command line when the containing program was invoked.
4704 This intrinsic routine is provided for backwards compatibility with
4705 GNU Fortran 77. In new code, programmers should consider the use of
4706 the @ref{GET_COMMAND_ARGUMENT} intrinsic defined by the Fortran 2003
4709 @item @emph{Standard}:
4715 @item @emph{Syntax}:
4716 @code{CALL GETARG(POS, VALUE)}
4718 @item @emph{Arguments}:
4719 @multitable @columnfractions .15 .70
4720 @item @var{POS} @tab Shall be of type @code{INTEGER} and not wider than
4721 the default integer kind; @math{@var{POS} \geq 0}
4722 @item @var{VALUE} @tab Shall be of type @code{CHARACTER} and of default
4724 @item @var{VALUE} @tab Shall be of type @code{CHARACTER}.
4727 @item @emph{Return value}:
4728 After @code{GETARG} returns, the @var{VALUE} argument holds the
4729 @var{POS}th command line argument. If @var{VALUE} can not hold the
4730 argument, it is truncated to fit the length of @var{VALUE}. If there are
4731 less than @var{POS} arguments specified at the command line, @var{VALUE}
4732 will be filled with blanks. If @math{@var{POS} = 0}, @var{VALUE} is set
4733 to the name of the program (on systems that support this feature).
4735 @item @emph{Example}:
4739 CHARACTER(len=32) :: arg
4748 @item @emph{See also}:
4749 GNU Fortran 77 compatibility function: @ref{IARGC}
4751 Fortran 2003 functions and subroutines: @ref{GET_COMMAND},
4752 @ref{GET_COMMAND_ARGUMENT}, @ref{COMMAND_ARGUMENT_COUNT}
4758 @section @code{GET_COMMAND} --- Get the entire command line
4759 @fnindex GET_COMMAND
4760 @cindex command-line arguments
4761 @cindex arguments, to program
4764 @item @emph{Description}:
4765 Retrieve the entire command line that was used to invoke the program.
4767 @item @emph{Standard}:
4768 Fortran 2003 and later
4773 @item @emph{Syntax}:
4774 @code{CALL GET_COMMAND(COMMAND)}
4776 @item @emph{Arguments}:
4777 @multitable @columnfractions .15 .70
4778 @item @var{COMMAND} @tab Shall be of type @code{CHARACTER} and of default
4782 @item @emph{Return value}:
4783 Stores the entire command line that was used to invoke the program in
4784 @var{COMMAND}. If @var{COMMAND} is not large enough, the command will be
4787 @item @emph{Example}:
4789 PROGRAM test_get_command
4790 CHARACTER(len=255) :: cmd
4791 CALL get_command(cmd)
4792 WRITE (*,*) TRIM(cmd)
4796 @item @emph{See also}:
4797 @ref{GET_COMMAND_ARGUMENT}, @ref{COMMAND_ARGUMENT_COUNT}
4802 @node GET_COMMAND_ARGUMENT
4803 @section @code{GET_COMMAND_ARGUMENT} --- Get command line arguments
4804 @fnindex GET_COMMAND_ARGUMENT
4805 @cindex command-line arguments
4806 @cindex arguments, to program
4809 @item @emph{Description}:
4810 Retrieve the @var{NUMBER}-th argument that was passed on the
4811 command line when the containing program was invoked.
4813 @item @emph{Standard}:
4814 Fortran 2003 and later
4819 @item @emph{Syntax}:
4820 @code{CALL GET_COMMAND_ARGUMENT(NUMBER [, VALUE, LENGTH, STATUS])}
4822 @item @emph{Arguments}:
4823 @multitable @columnfractions .15 .70
4824 @item @var{NUMBER} @tab Shall be a scalar of type @code{INTEGER(4)},
4825 @math{@var{NUMBER} \geq 0}
4826 @item @var{VALUE} @tab Shall be a scalar of type @code{CHARACTER}
4827 and of default kind.
4828 @item @var{LENGTH} @tab (Option) Shall be a scalar of type @code{INTEGER(4)}.
4829 @item @var{STATUS} @tab (Option) Shall be a scalar of type @code{INTEGER(4)}.
4832 @item @emph{Return value}:
4833 After @code{GET_COMMAND_ARGUMENT} returns, the @var{VALUE} argument holds the
4834 @var{NUMBER}-th command line argument. If @var{VALUE} can not hold the argument, it is
4835 truncated to fit the length of @var{VALUE}. If there are less than @var{NUMBER}
4836 arguments specified at the command line, @var{VALUE} will be filled with blanks.
4837 If @math{@var{NUMBER} = 0}, @var{VALUE} is set to the name of the program (on systems
4838 that support this feature). The @var{LENGTH} argument contains the length of the
4839 @var{NUMBER}-th command line argument. If the argument retrival fails, @var{STATUS}
4840 is a positiv number; if @var{VALUE} contains a truncated command line argument,
4841 @var{STATUS} is -1; and otherwise the @var{STATUS} is zero.
4843 @item @emph{Example}:
4845 PROGRAM test_get_command_argument
4847 CHARACTER(len=32) :: arg
4851 CALL get_command_argument(i, arg)
4852 IF (LEN_TRIM(arg) == 0) EXIT
4854 WRITE (*,*) TRIM(arg)
4860 @item @emph{See also}:
4861 @ref{GET_COMMAND}, @ref{COMMAND_ARGUMENT_COUNT}
4867 @section @code{GETCWD} --- Get current working directory
4869 @cindex system, working directory
4872 @item @emph{Description}:
4873 Get current working directory.
4875 This intrinsic is provided in both subroutine and function forms; however,
4876 only one form can be used in any given program unit.
4878 @item @emph{Standard}:
4882 Subroutine, function
4884 @item @emph{Syntax}:
4885 @code{CALL GETCWD(C [, STATUS])}
4887 @item @emph{Arguments}:
4888 @multitable @columnfractions .15 .70
4889 @item @var{C} @tab The type shall be @code{CHARACTER} and of default kind.
4890 @item @var{STATUS} @tab (Optional) status flag. Returns 0 on success,
4891 a system specific and nonzero error code otherwise.
4894 @item @emph{Example}:
4897 CHARACTER(len=255) :: cwd
4899 WRITE(*,*) TRIM(cwd)
4903 @item @emph{See also}:
4910 @section @code{GETENV} --- Get an environmental variable
4912 @cindex environment variable
4915 @item @emph{Description}:
4916 Get the @var{VALUE} of the environmental variable @var{NAME}.
4918 This intrinsic routine is provided for backwards compatibility with
4919 GNU Fortran 77. In new code, programmers should consider the use of
4920 the @ref{GET_ENVIRONMENT_VARIABLE} intrinsic defined by the Fortran
4923 @item @emph{Standard}:
4929 @item @emph{Syntax}:
4930 @code{CALL GETENV(NAME, VALUE)}
4932 @item @emph{Arguments}:
4933 @multitable @columnfractions .15 .70
4934 @item @var{NAME} @tab Shall be of type @code{CHARACTER} and of default kind.
4935 @item @var{VALUE} @tab Shall be of type @code{CHARACTER} and of default kind.
4938 @item @emph{Return value}:
4939 Stores the value of @var{NAME} in @var{VALUE}. If @var{VALUE} is
4940 not large enough to hold the data, it is truncated. If @var{NAME}
4941 is not set, @var{VALUE} will be filled with blanks.
4943 @item @emph{Example}:
4946 CHARACTER(len=255) :: homedir
4947 CALL getenv("HOME", homedir)
4948 WRITE (*,*) TRIM(homedir)
4952 @item @emph{See also}:
4953 @ref{GET_ENVIRONMENT_VARIABLE}
4958 @node GET_ENVIRONMENT_VARIABLE
4959 @section @code{GET_ENVIRONMENT_VARIABLE} --- Get an environmental variable
4960 @fnindex GET_ENVIRONMENT_VARIABLE
4961 @cindex environment variable
4964 @item @emph{Description}:
4965 Get the @var{VALUE} of the environmental variable @var{NAME}.
4967 @item @emph{Standard}:
4968 Fortran 2003 and later
4973 @item @emph{Syntax}:
4974 @code{CALL GET_ENVIRONMENT_VARIABLE(NAME[, VALUE, LENGTH, STATUS, TRIM_NAME)}
4976 @item @emph{Arguments}:
4977 @multitable @columnfractions .15 .70
4978 @item @var{NAME} @tab Shall be a scalar of type @code{CHARACTER(1)}.
4979 @item @var{VALUE} @tab Shall be a scalar of type @code{CHARACTER(1)}.
4980 @item @var{LENGTH} @tab Shall be a scalar of type @code{INTEGER(4)}.
4981 @item @var{STATUS} @tab Shall be a scalar of type @code{INTEGER(4)}.
4982 @item @var{TRIM_NAME} @tab Shall be a scalar of type @code{LOGICAL(4)}.
4985 @item @emph{Return value}:
4986 Stores the value of @var{NAME} in @var{VALUE}. If @var{VALUE} is
4987 not large enough to hold the data, it is truncated. If @var{NAME}
4988 is not set, @var{VALUE} will be filled with blanks. Argument @var{LENGTH}
4989 contains the length needed for storing the environment variable @var{NAME}
4990 or zero if it is not present. @var{STATUS} is -1 if @var{VALUE} is present
4991 but too short for the environment variable; it is 1 if the environment
4992 variable does not exist and 2 if the processor does not support environment
4993 variables; in all other cases @var{STATUS} is zero. If @var{TRIM_NAME} is
4994 present with the value @code{.FALSE.}, the trailing blanks in @var{NAME}
4995 are significant; otherwise they are not part of the environment variable
4998 @item @emph{Example}:
5001 CHARACTER(len=255) :: homedir
5002 CALL get_environment_variable("HOME", homedir)
5003 WRITE (*,*) TRIM(homedir)
5011 @section @code{GETGID} --- Group ID function
5013 @cindex system, group id
5016 @item @emph{Description}:
5017 Returns the numerical group ID of the current process.
5019 @item @emph{Standard}:
5025 @item @emph{Syntax}:
5026 @code{RESULT = GETGID()}
5028 @item @emph{Return value}:
5029 The return value of @code{GETGID} is an @code{INTEGER} of the default
5033 @item @emph{Example}:
5034 See @code{GETPID} for an example.
5036 @item @emph{See also}:
5037 @ref{GETPID}, @ref{GETUID}
5043 @section @code{GETLOG} --- Get login name
5045 @cindex system, login name
5049 @item @emph{Description}:
5050 Gets the username under which the program is running.
5052 @item @emph{Standard}:
5058 @item @emph{Syntax}:
5059 @code{CALL GETLOG(C)}
5061 @item @emph{Arguments}:
5062 @multitable @columnfractions .15 .70
5063 @item @var{C} @tab Shall be of type @code{CHARACTER} and of default kind.
5066 @item @emph{Return value}:
5067 Stores the current user name in @var{LOGIN}. (On systems where POSIX
5068 functions @code{geteuid} and @code{getpwuid} are not available, and
5069 the @code{getlogin} function is not implemented either, this will
5070 return a blank string.)
5072 @item @emph{Example}:
5075 CHARACTER(32) :: login
5081 @item @emph{See also}:
5088 @section @code{GETPID} --- Process ID function
5090 @cindex system, process id
5094 @item @emph{Description}:
5095 Returns the numerical process identifier of the current process.
5097 @item @emph{Standard}:
5103 @item @emph{Syntax}:
5104 @code{RESULT = GETPID()}
5106 @item @emph{Return value}:
5107 The return value of @code{GETPID} is an @code{INTEGER} of the default
5111 @item @emph{Example}:
5114 print *, "The current process ID is ", getpid()
5115 print *, "Your numerical user ID is ", getuid()
5116 print *, "Your numerical group ID is ", getgid()
5120 @item @emph{See also}:
5121 @ref{GETGID}, @ref{GETUID}
5127 @section @code{GETUID} --- User ID function
5129 @cindex system, user id
5133 @item @emph{Description}:
5134 Returns the numerical user ID of the current process.
5136 @item @emph{Standard}:
5142 @item @emph{Syntax}:
5143 @code{RESULT = GETUID()}
5145 @item @emph{Return value}:
5146 The return value of @code{GETUID} is an @code{INTEGER} of the default
5150 @item @emph{Example}:
5151 See @code{GETPID} for an example.
5153 @item @emph{See also}:
5154 @ref{GETPID}, @ref{GETLOG}
5160 @section @code{GMTIME} --- Convert time to GMT info
5162 @cindex time, conversion to GMT info
5165 @item @emph{Description}:
5166 Given a system time value @var{TIME} (as provided by the @code{TIME8()}
5167 intrinsic), fills @var{VALUES} with values extracted from it appropriate
5168 to the UTC time zone (Universal Coordinated Time, also known in some
5169 countries as GMT, Greenwich Mean Time), using @code{gmtime(3)}.
5171 @item @emph{Standard}:
5177 @item @emph{Syntax}:
5178 @code{CALL GMTIME(TIME, VALUES)}
5180 @item @emph{Arguments}:
5181 @multitable @columnfractions .15 .70
5182 @item @var{TIME} @tab An @code{INTEGER} scalar expression
5183 corresponding to a system time, with
5185 @item @var{VALUES} @tab A default @code{INTEGER} array with 9 elements,
5186 with @code{INTENT(OUT)}.
5189 @item @emph{Return value}:
5190 The elements of @var{VALUES} are assigned as follows:
5192 @item Seconds after the minute, range 0--59 or 0--61 to allow for leap
5194 @item Minutes after the hour, range 0--59
5195 @item Hours past midnight, range 0--23
5196 @item Day of month, range 0--31
5197 @item Number of months since January, range 0--12
5198 @item Years since 1900
5199 @item Number of days since Sunday, range 0--6
5200 @item Days since January 1
5201 @item Daylight savings indicator: positive if daylight savings is in
5202 effect, zero if not, and negative if the information is not
5206 @item @emph{See also}:
5207 @ref{CTIME}, @ref{LTIME}, @ref{TIME}, @ref{TIME8}
5214 @section @code{HOSTNM} --- Get system host name
5216 @cindex system, host name
5219 @item @emph{Description}:
5220 Retrieves the host name of the system on which the program is running.
5222 This intrinsic is provided in both subroutine and function forms; however,
5223 only one form can be used in any given program unit.
5225 @item @emph{Standard}:
5229 Subroutine, function
5231 @item @emph{Syntax}:
5232 @multitable @columnfractions .80
5233 @item @code{CALL HOSTNM(C [, STATUS])}
5234 @item @code{STATUS = HOSTNM(NAME)}
5237 @item @emph{Arguments}:
5238 @multitable @columnfractions .15 .70
5239 @item @var{C} @tab Shall of type @code{CHARACTER} and of default kind.
5240 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
5241 Returns 0 on success, or a system specific error
5245 @item @emph{Return value}:
5246 In either syntax, @var{NAME} is set to the current hostname if it can
5247 be obtained, or to a blank string otherwise.
5254 @section @code{HUGE} --- Largest number of a kind
5256 @cindex limits, largest number
5257 @cindex model representation, largest number
5260 @item @emph{Description}:
5261 @code{HUGE(X)} returns the largest number that is not an infinity in
5262 the model of the type of @code{X}.
5264 @item @emph{Standard}:
5265 Fortran 95 and later
5270 @item @emph{Syntax}:
5271 @code{RESULT = HUGE(X)}
5273 @item @emph{Arguments}:
5274 @multitable @columnfractions .15 .70
5275 @item @var{X} @tab Shall be of type @code{REAL} or @code{INTEGER}.
5278 @item @emph{Return value}:
5279 The return value is of the same type and kind as @var{X}
5281 @item @emph{Example}:
5283 program test_huge_tiny
5284 print *, huge(0), huge(0.0), huge(0.0d0)
5285 print *, tiny(0.0), tiny(0.0d0)
5286 end program test_huge_tiny
5293 @section @code{HYPOT} --- Euclidean distance function
5295 @cindex Euclidean distance
5298 @item @emph{Description}:
5299 @code{HYPOT(X,Y)} is the Euclidean distance function. It is equal to
5300 @math{\sqrt{X^2 + Y^2}}, without undue underflow or overflow.
5302 @item @emph{Standard}:
5303 Fortran 2008 and later
5308 @item @emph{Syntax}:
5309 @code{RESULT = HYPOT(X, Y)}
5311 @item @emph{Arguments}:
5312 @multitable @columnfractions .15 .70
5313 @item @var{X} @tab The type shall be @code{REAL}.
5314 @item @var{Y} @tab The type and kind type parameter shall be the same as
5318 @item @emph{Return value}:
5319 The return value has the same type and kind type parameter as @var{X}.
5321 @item @emph{Example}:
5324 real(4) :: x = 1.e0_4, y = 0.5e0_4
5326 end program test_hypot
5333 @section @code{IACHAR} --- Code in @acronym{ASCII} collating sequence
5335 @cindex @acronym{ASCII} collating sequence
5336 @cindex collating sequence, @acronym{ASCII}
5337 @cindex conversion, to integer
5340 @item @emph{Description}:
5341 @code{IACHAR(C)} returns the code for the @acronym{ASCII} character
5342 in the first character position of @code{C}.
5344 @item @emph{Standard}:
5345 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
5350 @item @emph{Syntax}:
5351 @code{RESULT = IACHAR(C [, KIND])}
5353 @item @emph{Arguments}:
5354 @multitable @columnfractions .15 .70
5355 @item @var{C} @tab Shall be a scalar @code{CHARACTER}, with @code{INTENT(IN)}
5356 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
5357 expression indicating the kind parameter of
5361 @item @emph{Return value}:
5362 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
5363 @var{KIND} is absent, the return value is of default integer kind.
5365 @item @emph{Example}:
5370 end program test_iachar
5374 See @ref{ICHAR} for a discussion of converting between numerical values
5375 and formatted string representations.
5377 @item @emph{See also}:
5378 @ref{ACHAR}, @ref{CHAR}, @ref{ICHAR}
5385 @section @code{IAND} --- Bitwise logical and
5387 @cindex bitwise logical and
5388 @cindex logical and, bitwise
5391 @item @emph{Description}:
5392 Bitwise logical @code{AND}.
5394 @item @emph{Standard}:
5395 Fortran 95 and later
5400 @item @emph{Syntax}:
5401 @code{RESULT = IAND(I, J)}
5403 @item @emph{Arguments}:
5404 @multitable @columnfractions .15 .70
5405 @item @var{I} @tab The type shall be @code{INTEGER}.
5406 @item @var{J} @tab The type shall be @code{INTEGER}, of the same
5407 kind as @var{I}. (As a GNU extension, different kinds are also
5411 @item @emph{Return value}:
5412 The return type is @code{INTEGER}, of the same kind as the
5413 arguments. (If the argument kinds differ, it is of the same kind as
5414 the larger argument.)
5416 @item @emph{Example}:
5420 DATA a / Z'F' /, b / Z'3' /
5421 WRITE (*,*) IAND(a, b)
5425 @item @emph{See also}:
5426 @ref{IOR}, @ref{IEOR}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}, @ref{NOT}
5433 @section @code{IARGC} --- Get the number of command line arguments
5435 @cindex command-line arguments
5436 @cindex command-line arguments, number of
5437 @cindex arguments, to program
5440 @item @emph{Description}:
5441 @code{IARGC()} returns the number of arguments passed on the
5442 command line when the containing program was invoked.
5444 This intrinsic routine is provided for backwards compatibility with
5445 GNU Fortran 77. In new code, programmers should consider the use of
5446 the @ref{COMMAND_ARGUMENT_COUNT} intrinsic defined by the Fortran 2003
5449 @item @emph{Standard}:
5455 @item @emph{Syntax}:
5456 @code{RESULT = IARGC()}
5458 @item @emph{Arguments}:
5461 @item @emph{Return value}:
5462 The number of command line arguments, type @code{INTEGER(4)}.
5464 @item @emph{Example}:
5467 @item @emph{See also}:
5468 GNU Fortran 77 compatibility subroutine: @ref{GETARG}
5470 Fortran 2003 functions and subroutines: @ref{GET_COMMAND},
5471 @ref{GET_COMMAND_ARGUMENT}, @ref{COMMAND_ARGUMENT_COUNT}
5477 @section @code{IBCLR} --- Clear bit
5483 @item @emph{Description}:
5484 @code{IBCLR} returns the value of @var{I} with the bit at position
5485 @var{POS} set to zero.
5487 @item @emph{Standard}:
5488 Fortran 95 and later
5493 @item @emph{Syntax}:
5494 @code{RESULT = IBCLR(I, POS)}
5496 @item @emph{Arguments}:
5497 @multitable @columnfractions .15 .70
5498 @item @var{I} @tab The type shall be @code{INTEGER}.
5499 @item @var{POS} @tab The type shall be @code{INTEGER}.
5502 @item @emph{Return value}:
5503 The return value is of type @code{INTEGER} and of the same kind as
5506 @item @emph{See also}:
5507 @ref{IBITS}, @ref{IBSET}, @ref{IAND}, @ref{IOR}, @ref{IEOR}, @ref{MVBITS}
5514 @section @code{IBITS} --- Bit extraction
5517 @cindex bits, extract
5520 @item @emph{Description}:
5521 @code{IBITS} extracts a field of length @var{LEN} from @var{I},
5522 starting from bit position @var{POS} and extending left for @var{LEN}
5523 bits. The result is right-justified and the remaining bits are
5524 zeroed. The value of @code{POS+LEN} must be less than or equal to the
5525 value @code{BIT_SIZE(I)}.
5527 @item @emph{Standard}:
5528 Fortran 95 and later
5533 @item @emph{Syntax}:
5534 @code{RESULT = IBITS(I, POS, LEN)}
5536 @item @emph{Arguments}:
5537 @multitable @columnfractions .15 .70
5538 @item @var{I} @tab The type shall be @code{INTEGER}.
5539 @item @var{POS} @tab The type shall be @code{INTEGER}.
5540 @item @var{LEN} @tab The type shall be @code{INTEGER}.
5543 @item @emph{Return value}:
5544 The return value is of type @code{INTEGER} and of the same kind as
5547 @item @emph{See also}:
5548 @ref{BIT_SIZE}, @ref{IBCLR}, @ref{IBSET}, @ref{IAND}, @ref{IOR}, @ref{IEOR}
5554 @section @code{IBSET} --- Set bit
5559 @item @emph{Description}:
5560 @code{IBSET} returns the value of @var{I} with the bit at position
5561 @var{POS} set to one.
5563 @item @emph{Standard}:
5564 Fortran 95 and later
5569 @item @emph{Syntax}:
5570 @code{RESULT = IBSET(I, POS)}
5572 @item @emph{Arguments}:
5573 @multitable @columnfractions .15 .70
5574 @item @var{I} @tab The type shall be @code{INTEGER}.
5575 @item @var{POS} @tab The type shall be @code{INTEGER}.
5578 @item @emph{Return value}:
5579 The return value is of type @code{INTEGER} and of the same kind as
5582 @item @emph{See also}:
5583 @ref{IBCLR}, @ref{IBITS}, @ref{IAND}, @ref{IOR}, @ref{IEOR}, @ref{MVBITS}
5590 @section @code{ICHAR} --- Character-to-integer conversion function
5592 @cindex conversion, to integer
5595 @item @emph{Description}:
5596 @code{ICHAR(C)} returns the code for the character in the first character
5597 position of @code{C} in the system's native character set.
5598 The correspondence between characters and their codes is not necessarily
5599 the same across different GNU Fortran implementations.
5601 @item @emph{Standard}:
5602 Fortan 95 and later, with @var{KIND} argument Fortran 2003 and later
5607 @item @emph{Syntax}:
5608 @code{RESULT = ICHAR(C [, KIND])}
5610 @item @emph{Arguments}:
5611 @multitable @columnfractions .15 .70
5612 @item @var{C} @tab Shall be a scalar @code{CHARACTER}, with @code{INTENT(IN)}
5613 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
5614 expression indicating the kind parameter of
5618 @item @emph{Return value}:
5619 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
5620 @var{KIND} is absent, the return value is of default integer kind.
5622 @item @emph{Example}:
5627 end program test_ichar
5631 No intrinsic exists to convert between a numeric value and a formatted
5632 character string representation -- for instance, given the
5633 @code{CHARACTER} value @code{'154'}, obtaining an @code{INTEGER} or
5634 @code{REAL} value with the value 154, or vice versa. Instead, this
5635 functionality is provided by internal-file I/O, as in the following
5640 character(len=10) string, string2
5643 ! Convert a string to a numeric value
5644 read (string,'(I10)') value
5647 ! Convert a value to a formatted string
5648 write (string2,'(I10)') value
5650 end program read_val
5653 @item @emph{See also}:
5654 @ref{ACHAR}, @ref{CHAR}, @ref{IACHAR}
5661 @section @code{IDATE} --- Get current local time subroutine (day/month/year)
5663 @cindex date, current
5664 @cindex current date
5667 @item @emph{Description}:
5668 @code{IDATE(TARRAY)} Fills @var{TARRAY} with the numerical values at the
5669 current local time. The day (in the range 1-31), month (in the range 1-12),
5670 and year appear in elements 1, 2, and 3 of @var{TARRAY}, respectively.
5671 The year has four significant digits.
5673 @item @emph{Standard}:
5679 @item @emph{Syntax}:
5680 @code{CALL IDATE(VALUES)}
5682 @item @emph{Arguments}:
5683 @multitable @columnfractions .15 .70
5684 @item @var{VALUES} @tab The type shall be @code{INTEGER, DIMENSION(3)} and
5685 the kind shall be the default integer kind.
5688 @item @emph{Return value}:
5691 @item @emph{Example}:
5694 integer, dimension(3) :: tarray
5699 end program test_idate
5706 @section @code{IEOR} --- Bitwise logical exclusive or
5708 @cindex bitwise logical exclusive or
5709 @cindex logical exclusive or, bitwise
5712 @item @emph{Description}:
5713 @code{IEOR} returns the bitwise boolean exclusive-OR of @var{I} and
5716 @item @emph{Standard}:
5717 Fortran 95 and later
5722 @item @emph{Syntax}:
5723 @code{RESULT = IEOR(I, J)}
5725 @item @emph{Arguments}:
5726 @multitable @columnfractions .15 .70
5727 @item @var{I} @tab The type shall be @code{INTEGER}.
5728 @item @var{J} @tab The type shall be @code{INTEGER}, of the same
5729 kind as @var{I}. (As a GNU extension, different kinds are also
5733 @item @emph{Return value}:
5734 The return type is @code{INTEGER}, of the same kind as the
5735 arguments. (If the argument kinds differ, it is of the same kind as
5736 the larger argument.)
5738 @item @emph{See also}:
5739 @ref{IOR}, @ref{IAND}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}, @ref{NOT}
5745 @section @code{IERRNO} --- Get the last system error number
5747 @cindex system, error handling
5750 @item @emph{Description}:
5751 Returns the last system error number, as given by the C @code{errno()}
5754 @item @emph{Standard}:
5760 @item @emph{Syntax}:
5761 @code{RESULT = IERRNO()}
5763 @item @emph{Arguments}:
5766 @item @emph{Return value}:
5767 The return value is of type @code{INTEGER} and of the default integer
5770 @item @emph{See also}:
5776 @node INDEX intrinsic
5777 @section @code{INDEX} --- Position of a substring within a string
5779 @cindex substring position
5780 @cindex string, find substring
5783 @item @emph{Description}:
5784 Returns the position of the start of the first occurrence of string
5785 @var{SUBSTRING} as a substring in @var{STRING}, counting from one. If
5786 @var{SUBSTRING} is not present in @var{STRING}, zero is returned. If
5787 the @var{BACK} argument is present and true, the return value is the
5788 start of the last occurrence rather than the first.
5790 @item @emph{Standard}:
5791 Fortran 77 and later, with @var{KIND} argument Fortran 2003 and later
5796 @item @emph{Syntax}:
5797 @code{RESULT = INDEX(STRING, SUBSTRING [, BACK [, KIND]])}
5799 @item @emph{Arguments}:
5800 @multitable @columnfractions .15 .70
5801 @item @var{STRING} @tab Shall be a scalar @code{CHARACTER}, with
5803 @item @var{SUBSTRING} @tab Shall be a scalar @code{CHARACTER}, with
5805 @item @var{BACK} @tab (Optional) Shall be a scalar @code{LOGICAL}, with
5807 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
5808 expression indicating the kind parameter of
5812 @item @emph{Return value}:
5813 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
5814 @var{KIND} is absent, the return value is of default integer kind.
5816 @item @emph{See also}:
5817 @ref{SCAN}, @ref{VERIFY}
5823 @section @code{INT} --- Convert to integer type
5827 @cindex conversion, to integer
5830 @item @emph{Description}:
5831 Convert to integer type
5833 @item @emph{Standard}:
5834 Fortran 77 and later
5839 @item @emph{Syntax}:
5840 @code{RESULT = INT(A [, KIND))}
5842 @item @emph{Arguments}:
5843 @multitable @columnfractions .15 .70
5844 @item @var{A} @tab Shall be of type @code{INTEGER},
5845 @code{REAL}, or @code{COMPLEX}.
5846 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
5847 expression indicating the kind parameter of
5851 @item @emph{Return value}:
5852 These functions return a @code{INTEGER} variable or array under
5853 the following rules:
5857 If @var{A} is of type @code{INTEGER}, @code{INT(A) = A}
5859 If @var{A} is of type @code{REAL} and @math{|A| < 1}, @code{INT(A)} equals @code{0}.
5860 If @math{|A| \geq 1}, then @code{INT(A)} equals the largest integer that does not exceed
5861 the range of @var{A} and whose sign is the same as the sign of @var{A}.
5863 If @var{A} is of type @code{COMPLEX}, rule B is applied to the real part of @var{A}.
5866 @item @emph{Example}:
5870 complex :: z = (-3.7, 1.0)
5872 print *, int(z), int(z,8)
5876 @item @emph{Specific names}:
5877 @multitable @columnfractions .20 .20 .20 .25
5878 @item Name @tab Argument @tab Return type @tab Standard
5879 @item @code{IFIX(A)} @tab @code{REAL(4) A} @tab @code{INTEGER} @tab Fortran 77 and later
5880 @item @code{IDINT(A)} @tab @code{REAL(8) A} @tab @code{INTEGER} @tab Fortran 77 and later
5888 @section @code{INT2} --- Convert to 16-bit integer type
5891 @cindex conversion, to integer
5894 @item @emph{Description}:
5895 Convert to a @code{KIND=2} integer type. This is equivalent to the
5896 standard @code{INT} intrinsic with an optional argument of
5897 @code{KIND=2}, and is only included for backwards compatibility.
5899 The @code{SHORT} intrinsic is equivalent to @code{INT2}.
5901 @item @emph{Standard}:
5907 @item @emph{Syntax}:
5908 @code{RESULT = INT2(A)}
5910 @item @emph{Arguments}:
5911 @multitable @columnfractions .15 .70
5912 @item @var{A} @tab Shall be of type @code{INTEGER},
5913 @code{REAL}, or @code{COMPLEX}.
5916 @item @emph{Return value}:
5917 The return value is a @code{INTEGER(2)} variable.
5919 @item @emph{See also}:
5920 @ref{INT}, @ref{INT8}, @ref{LONG}
5926 @section @code{INT8} --- Convert to 64-bit integer type
5928 @cindex conversion, to integer
5931 @item @emph{Description}:
5932 Convert to a @code{KIND=8} integer type. This is equivalent to the
5933 standard @code{INT} intrinsic with an optional argument of
5934 @code{KIND=8}, and is only included for backwards compatibility.
5936 @item @emph{Standard}:
5942 @item @emph{Syntax}:
5943 @code{RESULT = INT8(A)}
5945 @item @emph{Arguments}:
5946 @multitable @columnfractions .15 .70
5947 @item @var{A} @tab Shall be of type @code{INTEGER},
5948 @code{REAL}, or @code{COMPLEX}.
5951 @item @emph{Return value}:
5952 The return value is a @code{INTEGER(8)} variable.
5954 @item @emph{See also}:
5955 @ref{INT}, @ref{INT2}, @ref{LONG}
5961 @section @code{IOR} --- Bitwise logical or
5963 @cindex bitwise logical or
5964 @cindex logical or, bitwise
5967 @item @emph{Description}:
5968 @code{IOR} returns the bitwise boolean inclusive-OR of @var{I} and
5971 @item @emph{Standard}:
5972 Fortran 95 and later
5977 @item @emph{Syntax}:
5978 @code{RESULT = IOR(I, J)}
5980 @item @emph{Arguments}:
5981 @multitable @columnfractions .15 .70
5982 @item @var{I} @tab The type shall be @code{INTEGER}.
5983 @item @var{J} @tab The type shall be @code{INTEGER}, of the same
5984 kind as @var{I}. (As a GNU extension, different kinds are also
5988 @item @emph{Return value}:
5989 The return type is @code{INTEGER}, of the same kind as the
5990 arguments. (If the argument kinds differ, it is of the same kind as
5991 the larger argument.)
5993 @item @emph{See also}:
5994 @ref{IEOR}, @ref{IAND}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}, @ref{NOT}
6000 @section @code{IRAND} --- Integer pseudo-random number
6002 @cindex random number generation
6005 @item @emph{Description}:
6006 @code{IRAND(FLAG)} returns a pseudo-random number from a uniform
6007 distribution between 0 and a system-dependent limit (which is in most
6008 cases 2147483647). If @var{FLAG} is 0, the next number
6009 in the current sequence is returned; if @var{FLAG} is 1, the generator
6010 is restarted by @code{CALL SRAND(0)}; if @var{FLAG} has any other value,
6011 it is used as a new seed with @code{SRAND}.
6013 This intrinsic routine is provided for backwards compatibility with
6014 GNU Fortran 77. It implements a simple modulo generator as provided
6015 by @command{g77}. For new code, one should consider the use of
6016 @ref{RANDOM_NUMBER} as it implements a superior algorithm.
6018 @item @emph{Standard}:
6024 @item @emph{Syntax}:
6025 @code{RESULT = IRAND(I)}
6027 @item @emph{Arguments}:
6028 @multitable @columnfractions .15 .70
6029 @item @var{I} @tab Shall be a scalar @code{INTEGER} of kind 4.
6032 @item @emph{Return value}:
6033 The return value is of @code{INTEGER(kind=4)} type.
6035 @item @emph{Example}:
6038 integer,parameter :: seed = 86456
6041 print *, irand(), irand(), irand(), irand()
6042 print *, irand(seed), irand(), irand(), irand()
6043 end program test_irand
6051 @section @code{IS_IOSTAT_END} --- Test for end-of-file value
6052 @fnindex IS_IOSTAT_END
6053 @cindex IOSTAT, end of file
6056 @item @emph{Description}:
6057 @code{IS_IOSTAT_END} tests whether an variable has the value of the I/O
6058 status ``end of file''. The function is equivalent to comparing the variable
6059 with the @code{IOSTAT_END} parameter of the intrinsic module
6060 @code{ISO_FORTRAN_ENV}.
6062 @item @emph{Standard}:
6063 Fortran 2003 and later
6068 @item @emph{Syntax}:
6069 @code{RESULT = IS_IOSTAT_END(I)}
6071 @item @emph{Arguments}:
6072 @multitable @columnfractions .15 .70
6073 @item @var{I} @tab Shall be of the type @code{INTEGER}.
6076 @item @emph{Return value}:
6077 Returns a @code{LOGICAL} of the default kind, which @code{.TRUE.} if
6078 @var{I} has the value which indicates an end of file condition for
6079 IOSTAT= specifiers, and is @code{.FALSE.} otherwise.
6081 @item @emph{Example}:
6086 OPEN(88, FILE='test.dat')
6087 READ(88, *, IOSTAT=stat) i
6088 IF(IS_IOSTAT_END(stat)) STOP 'END OF FILE'
6096 @section @code{IS_IOSTAT_EOR} --- Test for end-of-record value
6097 @fnindex IS_IOSTAT_EOR
6098 @cindex IOSTAT, end of record
6101 @item @emph{Description}:
6102 @code{IS_IOSTAT_EOR} tests whether an variable has the value of the I/O
6103 status ``end of record''. The function is equivalent to comparing the
6104 variable with the @code{IOSTAT_EOR} parameter of the intrinsic module
6105 @code{ISO_FORTRAN_ENV}.
6107 @item @emph{Standard}:
6108 Fortran 2003 and later
6113 @item @emph{Syntax}:
6114 @code{RESULT = IS_IOSTAT_EOR(I)}
6116 @item @emph{Arguments}:
6117 @multitable @columnfractions .15 .70
6118 @item @var{I} @tab Shall be of the type @code{INTEGER}.
6121 @item @emph{Return value}:
6122 Returns a @code{LOGICAL} of the default kind, which @code{.TRUE.} if
6123 @var{I} has the value which indicates an end of file condition for
6124 IOSTAT= specifiers, and is @code{.FALSE.} otherwise.
6126 @item @emph{Example}:
6130 INTEGER :: stat, i(50)
6131 OPEN(88, FILE='test.dat', FORM='UNFORMATTED')
6132 READ(88, IOSTAT=stat) i
6133 IF(IS_IOSTAT_EOR(stat)) STOP 'END OF RECORD'
6141 @section @code{ISATTY} --- Whether a unit is a terminal device.
6143 @cindex system, terminal
6146 @item @emph{Description}:
6147 Determine whether a unit is connected to a terminal device.
6149 @item @emph{Standard}:
6155 @item @emph{Syntax}:
6156 @code{RESULT = ISATTY(UNIT)}
6158 @item @emph{Arguments}:
6159 @multitable @columnfractions .15 .70
6160 @item @var{UNIT} @tab Shall be a scalar @code{INTEGER}.
6163 @item @emph{Return value}:
6164 Returns @code{.TRUE.} if the @var{UNIT} is connected to a terminal
6165 device, @code{.FALSE.} otherwise.
6167 @item @emph{Example}:
6170 INTEGER(kind=1) :: unit
6172 write(*,*) isatty(unit=unit)
6176 @item @emph{See also}:
6183 @section @code{ISHFT} --- Shift bits
6188 @item @emph{Description}:
6189 @code{ISHFT} returns a value corresponding to @var{I} with all of the
6190 bits shifted @var{SHIFT} places. A value of @var{SHIFT} greater than
6191 zero corresponds to a left shift, a value of zero corresponds to no
6192 shift, and a value less than zero corresponds to a right shift. If the
6193 absolute value of @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the
6194 value is undefined. Bits shifted out from the left end or right end are
6195 lost; zeros are shifted in from the opposite end.
6197 @item @emph{Standard}:
6198 Fortran 95 and later
6203 @item @emph{Syntax}:
6204 @code{RESULT = ISHFT(I, SHIFT)}
6206 @item @emph{Arguments}:
6207 @multitable @columnfractions .15 .70
6208 @item @var{I} @tab The type shall be @code{INTEGER}.
6209 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
6212 @item @emph{Return value}:
6213 The return value is of type @code{INTEGER} and of the same kind as
6216 @item @emph{See also}:
6223 @section @code{ISHFTC} --- Shift bits circularly
6225 @cindex bits, shift circular
6228 @item @emph{Description}:
6229 @code{ISHFTC} returns a value corresponding to @var{I} with the
6230 rightmost @var{SIZE} bits shifted circularly @var{SHIFT} places; that
6231 is, bits shifted out one end are shifted into the opposite end. A value
6232 of @var{SHIFT} greater than zero corresponds to a left shift, a value of
6233 zero corresponds to no shift, and a value less than zero corresponds to
6234 a right shift. The absolute value of @var{SHIFT} must be less than
6235 @var{SIZE}. If the @var{SIZE} argument is omitted, it is taken to be
6236 equivalent to @code{BIT_SIZE(I)}.
6238 @item @emph{Standard}:
6239 Fortran 95 and later
6244 @item @emph{Syntax}:
6245 @code{RESULT = ISHFTC(I, SHIFT [, SIZE])}
6247 @item @emph{Arguments}:
6248 @multitable @columnfractions .15 .70
6249 @item @var{I} @tab The type shall be @code{INTEGER}.
6250 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
6251 @item @var{SIZE} @tab (Optional) The type shall be @code{INTEGER};
6252 the value must be greater than zero and less than or equal to
6256 @item @emph{Return value}:
6257 The return value is of type @code{INTEGER} and of the same kind as
6260 @item @emph{See also}:
6267 @section @code{ISNAN} --- Test for a NaN
6272 @item @emph{Description}:
6273 @code{ISNAN} tests whether a floating-point value is an IEEE
6275 @item @emph{Standard}:
6281 @item @emph{Syntax}:
6284 @item @emph{Arguments}:
6285 @multitable @columnfractions .15 .70
6286 @item @var{X} @tab Variable of the type @code{REAL}.
6290 @item @emph{Return value}:
6291 Returns a default-kind @code{LOGICAL}. The returned value is @code{TRUE}
6292 if @var{X} is a NaN and @code{FALSE} otherwise.
6294 @item @emph{Example}:
6301 if (isnan(x)) stop '"x" is a NaN'
6302 end program test_nan
6309 @section @code{ITIME} --- Get current local time subroutine (hour/minutes/seconds)
6311 @cindex time, current
6312 @cindex current time
6315 @item @emph{Description}:
6316 @code{IDATE(VALUES)} Fills @var{VALUES} with the numerical values at the
6317 current local time. The hour (in the range 1-24), minute (in the range 1-60),
6318 and seconds (in the range 1-60) appear in elements 1, 2, and 3 of @var{VALUES},
6321 @item @emph{Standard}:
6327 @item @emph{Syntax}:
6328 @code{CALL ITIME(VALUES)}
6330 @item @emph{Arguments}:
6331 @multitable @columnfractions .15 .70
6332 @item @var{VALUES} @tab The type shall be @code{INTEGER, DIMENSION(3)}
6333 and the kind shall be the default integer kind.
6336 @item @emph{Return value}:
6340 @item @emph{Example}:
6343 integer, dimension(3) :: tarray
6348 end program test_itime
6355 @section @code{KILL} --- Send a signal to a process
6359 @item @emph{Description}:
6360 @item @emph{Standard}:
6361 Sends the signal specified by @var{SIGNAL} to the process @var{PID}.
6364 This intrinsic is provided in both subroutine and function forms; however,
6365 only one form can be used in any given program unit.
6368 Subroutine, function
6370 @item @emph{Syntax}:
6371 @code{CALL KILL(C, VALUE [, STATUS])}
6373 @item @emph{Arguments}:
6374 @multitable @columnfractions .15 .70
6375 @item @var{C} @tab Shall be a scalar @code{INTEGER}, with
6377 @item @var{VALUE} @tab Shall be a scalar @code{INTEGER}, with
6379 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)} or
6380 @code{INTEGER(8)}. Returns 0 on success, or a
6381 system-specific error code otherwise.
6384 @item @emph{See also}:
6385 @ref{ABORT}, @ref{EXIT}
6391 @section @code{KIND} --- Kind of an entity
6396 @item @emph{Description}:
6397 @code{KIND(X)} returns the kind value of the entity @var{X}.
6399 @item @emph{Standard}:
6400 Fortran 95 and later
6405 @item @emph{Syntax}:
6408 @item @emph{Arguments}:
6409 @multitable @columnfractions .15 .70
6410 @item @var{X} @tab Shall be of type @code{LOGICAL}, @code{INTEGER},
6411 @code{REAL}, @code{COMPLEX} or @code{CHARACTER}.
6414 @item @emph{Return value}:
6415 The return value is a scalar of type @code{INTEGER} and of the default
6418 @item @emph{Example}:
6421 integer,parameter :: kc = kind(' ')
6422 integer,parameter :: kl = kind(.true.)
6424 print *, "The default character kind is ", kc
6425 print *, "The default logical kind is ", kl
6426 end program test_kind
6434 @section @code{LBOUND} --- Lower dimension bounds of an array
6436 @cindex array, lower bound
6439 @item @emph{Description}:
6440 Returns the lower bounds of an array, or a single lower bound
6441 along the @var{DIM} dimension.
6442 @item @emph{Standard}:
6443 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
6448 @item @emph{Syntax}:
6449 @code{RESULT = LBOUND(ARRAY [, DIM [, KIND]])}
6451 @item @emph{Arguments}:
6452 @multitable @columnfractions .15 .70
6453 @item @var{ARRAY} @tab Shall be an array, of any type.
6454 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER}.
6455 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
6456 expression indicating the kind parameter of
6460 @item @emph{Return value}:
6461 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
6462 @var{KIND} is absent, the return value is of default integer kind.
6463 If @var{DIM} is absent, the result is an array of the lower bounds of
6464 @var{ARRAY}. If @var{DIM} is present, the result is a scalar
6465 corresponding to the lower bound of the array along that dimension. If
6466 @var{ARRAY} is an expression rather than a whole array or array
6467 structure component, or if it has a zero extent along the relevant
6468 dimension, the lower bound is taken to be 1.
6470 @item @emph{See also}:
6477 @section @code{LEN} --- Length of a character entity
6479 @cindex string, length
6482 @item @emph{Description}:
6483 Returns the length of a character string. If @var{STRING} is an array,
6484 the length of an element of @var{STRING} is returned. Note that
6485 @var{STRING} need not be defined when this intrinsic is invoked, since
6486 only the length, not the content, of @var{STRING} is needed.
6488 @item @emph{Standard}:
6489 Fortran 77 and later, with @var{KIND} argument Fortran 2003 and later
6494 @item @emph{Syntax}:
6495 @code{L = LEN(STRING [, KIND])}
6497 @item @emph{Arguments}:
6498 @multitable @columnfractions .15 .70
6499 @item @var{STRING} @tab Shall be a scalar or array of type
6500 @code{CHARACTER}, with @code{INTENT(IN)}
6501 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
6502 expression indicating the kind parameter of
6506 @item @emph{Return value}:
6507 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
6508 @var{KIND} is absent, the return value is of default integer kind.
6510 @item @emph{See also}:
6511 @ref{LEN_TRIM}, @ref{ADJUSTL}, @ref{ADJUSTR}
6517 @section @code{LEN_TRIM} --- Length of a character entity without trailing blank characters
6519 @cindex string, length, without trailing whitespace
6522 @item @emph{Description}:
6523 Returns the length of a character string, ignoring any trailing blanks.
6525 @item @emph{Standard}:
6526 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
6531 @item @emph{Syntax}:
6532 @code{RESULT = LEN_TRIM(STRING [, KIND])}
6534 @item @emph{Arguments}:
6535 @multitable @columnfractions .15 .70
6536 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER},
6537 with @code{INTENT(IN)}
6538 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
6539 expression indicating the kind parameter of
6543 @item @emph{Return value}:
6544 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
6545 @var{KIND} is absent, the return value is of default integer kind.
6547 @item @emph{See also}:
6548 @ref{LEN}, @ref{ADJUSTL}, @ref{ADJUSTR}
6554 @section @code{LGE} --- Lexical greater than or equal
6556 @cindex lexical comparison of strings
6557 @cindex string, comparison
6560 @item @emph{Description}:
6561 Determines whether one string is lexically greater than or equal to
6562 another string, where the two strings are interpreted as containing
6563 ASCII character codes. If the String A and String B are not the same
6564 length, the shorter is compared as if spaces were appended to it to form
6565 a value that has the same length as the longer.
6567 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
6568 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
6569 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
6570 that the latter use the processor's character ordering (which is not
6571 ASCII on some targets), whereas the former always use the ASCII
6574 @item @emph{Standard}:
6575 Fortran 77 and later
6580 @item @emph{Syntax}:
6581 @code{RESULT = LGE(STRING_A, STRING_B)}
6583 @item @emph{Arguments}:
6584 @multitable @columnfractions .15 .70
6585 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
6586 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
6589 @item @emph{Return value}:
6590 Returns @code{.TRUE.} if @code{STRING_A >= STRING_B}, and @code{.FALSE.}
6591 otherwise, based on the ASCII ordering.
6593 @item @emph{See also}:
6594 @ref{LGT}, @ref{LLE}, @ref{LLT}
6600 @section @code{LGT} --- Lexical greater than
6602 @cindex lexical comparison of strings
6603 @cindex string, comparison
6606 @item @emph{Description}:
6607 Determines whether one string is lexically greater than another string,
6608 where the two strings are interpreted as containing ASCII character
6609 codes. If the String A and String B are not the same length, the
6610 shorter is compared as if spaces were appended to it to form a value
6611 that has the same length as the longer.
6613 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
6614 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
6615 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
6616 that the latter use the processor's character ordering (which is not
6617 ASCII on some targets), whereas the former always use the ASCII
6620 @item @emph{Standard}:
6621 Fortran 77 and later
6626 @item @emph{Syntax}:
6627 @code{RESULT = LGT(STRING_A, STRING_B)}
6629 @item @emph{Arguments}:
6630 @multitable @columnfractions .15 .70
6631 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
6632 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
6635 @item @emph{Return value}:
6636 Returns @code{.TRUE.} if @code{STRING_A > STRING_B}, and @code{.FALSE.}
6637 otherwise, based on the ASCII ordering.
6639 @item @emph{See also}:
6640 @ref{LGE}, @ref{LLE}, @ref{LLT}
6646 @section @code{LINK} --- Create a hard link
6648 @cindex file system, create link
6649 @cindex file system, hard link
6652 @item @emph{Description}:
6653 Makes a (hard) link from file @var{PATH1} to @var{PATH2}. A null
6654 character (@code{CHAR(0)}) can be used to mark the end of the names in
6655 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
6656 names are ignored. If the @var{STATUS} argument is supplied, it
6657 contains 0 on success or a nonzero error code upon return; see
6660 This intrinsic is provided in both subroutine and function forms;
6661 however, only one form can be used in any given program unit.
6663 @item @emph{Standard}:
6667 Subroutine, function
6669 @item @emph{Syntax}:
6670 @multitable @columnfractions .80
6671 @item @code{CALL LINK(PATH1, PATH2 [, STATUS])}
6672 @item @code{STATUS = LINK(PATH1, PATH2)}
6675 @item @emph{Arguments}:
6676 @multitable @columnfractions .15 .70
6677 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
6678 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
6679 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
6682 @item @emph{See also}:
6683 @ref{SYMLNK}, @ref{UNLINK}
6689 @section @code{LLE} --- Lexical less than or equal
6691 @cindex lexical comparison of strings
6692 @cindex string, comparison
6695 @item @emph{Description}:
6696 Determines whether one string is lexically less than or equal to another
6697 string, where the two strings are interpreted as containing ASCII
6698 character codes. If the String A and String B are not the same length,
6699 the shorter is compared as if spaces were appended to it to form a value
6700 that has the same length as the longer.
6702 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
6703 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
6704 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
6705 that the latter use the processor's character ordering (which is not
6706 ASCII on some targets), whereas the former always use the ASCII
6709 @item @emph{Standard}:
6710 Fortran 77 and later
6715 @item @emph{Syntax}:
6716 @code{RESULT = LLE(STRING_A, STRING_B)}
6718 @item @emph{Arguments}:
6719 @multitable @columnfractions .15 .70
6720 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
6721 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
6724 @item @emph{Return value}:
6725 Returns @code{.TRUE.} if @code{STRING_A <= STRING_B}, and @code{.FALSE.}
6726 otherwise, based on the ASCII ordering.
6728 @item @emph{See also}:
6729 @ref{LGE}, @ref{LGT}, @ref{LLT}
6735 @section @code{LLT} --- Lexical less than
6737 @cindex lexical comparison of strings
6738 @cindex string, comparison
6741 @item @emph{Description}:
6742 Determines whether one string is lexically less than another string,
6743 where the two strings are interpreted as containing ASCII character
6744 codes. If the String A and String B are not the same length, the
6745 shorter is compared as if spaces were appended to it to form a value
6746 that has the same length as the longer.
6748 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
6749 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
6750 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
6751 that the latter use the processor's character ordering (which is not
6752 ASCII on some targets), whereas the former always use the ASCII
6755 @item @emph{Standard}:
6756 Fortran 77 and later
6761 @item @emph{Syntax}:
6762 @code{RESULT = LLT(STRING_A, STRING_B)}
6764 @item @emph{Arguments}:
6765 @multitable @columnfractions .15 .70
6766 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
6767 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
6770 @item @emph{Return value}:
6771 Returns @code{.TRUE.} if @code{STRING_A < STRING_B}, and @code{.FALSE.}
6772 otherwise, based on the ASCII ordering.
6774 @item @emph{See also}:
6775 @ref{LGE}, @ref{LGT}, @ref{LLE}
6781 @section @code{LNBLNK} --- Index of the last non-blank character in a string
6783 @cindex string, find non-blank character
6786 @item @emph{Description}:
6787 Returns the length of a character string, ignoring any trailing blanks.
6788 This is identical to the standard @code{LEN_TRIM} intrinsic, and is only
6789 included for backwards compatibility.
6791 @item @emph{Standard}:
6797 @item @emph{Syntax}:
6798 @code{RESULT = LNBLNK(STRING)}
6800 @item @emph{Arguments}:
6801 @multitable @columnfractions .15 .70
6802 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER},
6803 with @code{INTENT(IN)}
6806 @item @emph{Return value}:
6807 The return value is of @code{INTEGER(kind=4)} type.
6809 @item @emph{See also}:
6810 @ref{INDEX intrinsic}, @ref{LEN_TRIM}
6816 @section @code{LOC} --- Returns the address of a variable
6818 @cindex location of a variable in memory
6821 @item @emph{Description}:
6822 @code{LOC(X)} returns the address of @var{X} as an integer.
6824 @item @emph{Standard}:
6830 @item @emph{Syntax}:
6831 @code{RESULT = LOC(X)}
6833 @item @emph{Arguments}:
6834 @multitable @columnfractions .15 .70
6835 @item @var{X} @tab Variable of any type.
6838 @item @emph{Return value}:
6839 The return value is of type @code{INTEGER}, with a @code{KIND}
6840 corresponding to the size (in bytes) of a memory address on the target
6843 @item @emph{Example}:
6850 end program test_loc
6857 @section @code{LOG} --- Logarithm function
6864 @cindex exponential function, inverse
6865 @cindex logarithmic function
6868 @item @emph{Description}:
6869 @code{LOG(X)} computes the logarithm of @var{X}.
6871 @item @emph{Standard}:
6872 Fortran 77 and later
6877 @item @emph{Syntax}:
6878 @code{RESULT = LOG(X)}
6880 @item @emph{Arguments}:
6881 @multitable @columnfractions .15 .70
6882 @item @var{X} @tab The type shall be @code{REAL} or
6886 @item @emph{Return value}:
6887 The return value is of type @code{REAL} or @code{COMPLEX}.
6888 The kind type parameter is the same as @var{X}.
6890 @item @emph{Example}:
6893 real(8) :: x = 1.0_8
6894 complex :: z = (1.0, 2.0)
6897 end program test_log
6900 @item @emph{Specific names}:
6901 @multitable @columnfractions .20 .20 .20 .25
6902 @item Name @tab Argument @tab Return type @tab Standard
6903 @item @code{ALOG(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab f95, gnu
6904 @item @code{DLOG(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab f95, gnu
6905 @item @code{CLOG(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab f95, gnu
6906 @item @code{ZLOG(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
6907 @item @code{CDLOG(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
6914 @section @code{LOG10} --- Base 10 logarithm function
6918 @cindex exponential function, inverse
6919 @cindex logarithmic function
6922 @item @emph{Description}:
6923 @code{LOG10(X)} computes the base 10 logarithm of @var{X}.
6925 @item @emph{Standard}:
6926 Fortran 77 and later
6931 @item @emph{Syntax}:
6932 @code{RESULT = LOG10(X)}
6934 @item @emph{Arguments}:
6935 @multitable @columnfractions .15 .70
6936 @item @var{X} @tab The type shall be @code{REAL}.
6939 @item @emph{Return value}:
6940 The return value is of type @code{REAL} or @code{COMPLEX}.
6941 The kind type parameter is the same as @var{X}.
6943 @item @emph{Example}:
6946 real(8) :: x = 10.0_8
6948 end program test_log10
6951 @item @emph{Specific names}:
6952 @multitable @columnfractions .20 .20 .20 .25
6953 @item Name @tab Argument @tab Return type @tab Standard
6954 @item @code{ALOG10(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 95 and later
6955 @item @code{DLOG10(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 95 and later
6962 @section @code{LOG_GAMMA} --- Logarithm of the Gamma function
6967 @cindex Gamma function, logarithm of
6970 @item @emph{Description}:
6971 @code{LOG_GAMMA(X)} computes the natural logarithm of the absolute value
6972 of the Gamma (@math{\Gamma}) function.
6974 @item @emph{Standard}:
6975 Fortran 2008 and later
6980 @item @emph{Syntax}:
6981 @code{X = LOG_GAMMA(X)}
6983 @item @emph{Arguments}:
6984 @multitable @columnfractions .15 .70
6985 @item @var{X} @tab Shall be of type @code{REAL} and neither zero
6986 nor a negative integer.
6989 @item @emph{Return value}:
6990 The return value is of type @code{REAL} of the same kind as @var{X}.
6992 @item @emph{Example}:
6994 program test_log_gamma
6996 x = lgamma(x) ! returns 0.0
6997 end program test_log_gamma
7000 @item @emph{Specific names}:
7001 @multitable @columnfractions .20 .20 .20 .25
7002 @item Name @tab Argument @tab Return type @tab Standard
7003 @item @code{LGAMMA(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab GNU Extension
7004 @item @code{ALGAMA(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab GNU Extension
7005 @item @code{DLGAMA(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU Extension
7008 @item @emph{See also}:
7009 Gamma function: @ref{GAMMA}
7016 @section @code{LOGICAL} --- Convert to logical type
7018 @cindex conversion, to logical
7021 @item @emph{Description}:
7022 Converts one kind of @code{LOGICAL} variable to another.
7024 @item @emph{Standard}:
7025 Fortran 95 and later
7030 @item @emph{Syntax}:
7031 @code{RESULT = LOGICAL(L [, KIND])}
7033 @item @emph{Arguments}:
7034 @multitable @columnfractions .15 .70
7035 @item @var{L} @tab The type shall be @code{LOGICAL}.
7036 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
7037 expression indicating the kind parameter of
7041 @item @emph{Return value}:
7042 The return value is a @code{LOGICAL} value equal to @var{L}, with a
7043 kind corresponding to @var{KIND}, or of the default logical kind if
7044 @var{KIND} is not given.
7046 @item @emph{See also}:
7047 @ref{INT}, @ref{REAL}, @ref{CMPLX}
7053 @section @code{LONG} --- Convert to integer type
7055 @cindex conversion, to integer
7058 @item @emph{Description}:
7059 Convert to a @code{KIND=4} integer type, which is the same size as a C
7060 @code{long} integer. This is equivalent to the standard @code{INT}
7061 intrinsic with an optional argument of @code{KIND=4}, and is only
7062 included for backwards compatibility.
7064 @item @emph{Standard}:
7070 @item @emph{Syntax}:
7071 @code{RESULT = LONG(A)}
7073 @item @emph{Arguments}:
7074 @multitable @columnfractions .15 .70
7075 @item @var{A} @tab Shall be of type @code{INTEGER},
7076 @code{REAL}, or @code{COMPLEX}.
7079 @item @emph{Return value}:
7080 The return value is a @code{INTEGER(4)} variable.
7082 @item @emph{See also}:
7083 @ref{INT}, @ref{INT2}, @ref{INT8}
7089 @section @code{LSHIFT} --- Left shift bits
7091 @cindex bits, shift left
7094 @item @emph{Description}:
7095 @code{LSHIFT} returns a value corresponding to @var{I} with all of the
7096 bits shifted left by @var{SHIFT} places. If the absolute value of
7097 @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the value is undefined.
7098 Bits shifted out from the left end are lost; zeros are shifted in from
7101 This function has been superseded by the @code{ISHFT} intrinsic, which
7102 is standard in Fortran 95 and later.
7104 @item @emph{Standard}:
7110 @item @emph{Syntax}:
7111 @code{RESULT = LSHIFT(I, SHIFT)}
7113 @item @emph{Arguments}:
7114 @multitable @columnfractions .15 .70
7115 @item @var{I} @tab The type shall be @code{INTEGER}.
7116 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
7119 @item @emph{Return value}:
7120 The return value is of type @code{INTEGER} and of the same kind as
7123 @item @emph{See also}:
7124 @ref{ISHFT}, @ref{ISHFTC}, @ref{RSHIFT}
7131 @section @code{LSTAT} --- Get file status
7133 @cindex file system, file status
7136 @item @emph{Description}:
7137 @code{LSTAT} is identical to @ref{STAT}, except that if path is a symbolic link,
7138 then the link itself is statted, not the file that it refers to.
7140 The elements in @code{BUFF} are the same as described by @ref{STAT}.
7142 This intrinsic is provided in both subroutine and function forms; however,
7143 only one form can be used in any given program unit.
7145 @item @emph{Standard}:
7149 Subroutine, function
7151 @item @emph{Syntax}:
7152 @code{CALL LSTAT(FILE, BUFF [, STATUS])}
7154 @item @emph{Arguments}:
7155 @multitable @columnfractions .15 .70
7156 @item @var{FILE} @tab The type shall be @code{CHARACTER} of the default
7157 kind, a valid path within the file system.
7158 @item @var{BUFF} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
7159 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}.
7160 Returns 0 on success and a system specific error code otherwise.
7163 @item @emph{Example}:
7164 See @ref{STAT} for an example.
7166 @item @emph{See also}:
7167 To stat an open file: @ref{FSTAT}, to stat a file: @ref{STAT}
7173 @section @code{LTIME} --- Convert time to local time info
7175 @cindex time, conversion to local time info
7178 @item @emph{Description}:
7179 Given a system time value @var{STIME} (as provided by the @code{TIME8()}
7180 intrinsic), fills @var{TARRAY} with values extracted from it appropriate
7181 to the local time zone using @code{localtime(3)}.
7183 @item @emph{Standard}:
7189 @item @emph{Syntax}:
7190 @code{CALL LTIME(STIME, TARRAY)}
7192 @item @emph{Arguments}:
7193 @multitable @columnfractions .15 .70
7194 @item @var{STIME} @tab An @code{INTEGER} scalar expression
7195 corresponding to a system time, with
7197 @item @var{TARRAY} @tab A default @code{INTEGER} array with 9 elements,
7198 with @code{INTENT(OUT)}.
7201 @item @emph{Return value}:
7202 The elements of @var{TARRAY} are assigned as follows:
7204 @item Seconds after the minute, range 0--59 or 0--61 to allow for leap
7206 @item Minutes after the hour, range 0--59
7207 @item Hours past midnight, range 0--23
7208 @item Day of month, range 0--31
7209 @item Number of months since January, range 0--12
7210 @item Years since 1900
7211 @item Number of days since Sunday, range 0--6
7212 @item Days since January 1
7213 @item Daylight savings indicator: positive if daylight savings is in
7214 effect, zero if not, and negative if the information is not
7218 @item @emph{See also}:
7219 @ref{CTIME}, @ref{GMTIME}, @ref{TIME}, @ref{TIME8}
7226 @section @code{MALLOC} --- Allocate dynamic memory
7228 @cindex pointer, cray
7231 @item @emph{Description}:
7232 @code{MALLOC(SIZE)} allocates @var{SIZE} bytes of dynamic memory and
7233 returns the address of the allocated memory. The @code{MALLOC} intrinsic
7234 is an extension intended to be used with Cray pointers, and is provided
7235 in GNU Fortran to allow the user to compile legacy code. For new code
7236 using Fortran 95 pointers, the memory allocation intrinsic is
7239 @item @emph{Standard}:
7245 @item @emph{Syntax}:
7246 @code{PTR = MALLOC(SIZE)}
7248 @item @emph{Arguments}:
7249 @multitable @columnfractions .15 .70
7250 @item @var{SIZE} @tab The type shall be @code{INTEGER}.
7253 @item @emph{Return value}:
7254 The return value is of type @code{INTEGER(K)}, with @var{K} such that
7255 variables of type @code{INTEGER(K)} have the same size as
7256 C pointers (@code{sizeof(void *)}).
7258 @item @emph{Example}:
7259 The following example demonstrates the use of @code{MALLOC} and
7260 @code{FREE} with Cray pointers. This example is intended to run on
7261 32-bit systems, where the default integer kind is suitable to store
7262 pointers; on 64-bit systems, ptr_x would need to be declared as
7263 @code{integer(kind=8)}.
7272 ptr_x = malloc(20*8)
7274 x(i) = sqrt(1.0d0 / i)
7282 end program test_malloc
7285 @item @emph{See also}:
7292 @section @code{MATMUL} --- matrix multiplication
7294 @cindex matrix multiplication
7295 @cindex product, matrix
7298 @item @emph{Description}:
7299 Performs a matrix multiplication on numeric or logical arguments.
7301 @item @emph{Standard}:
7302 Fortran 95 and later
7305 Transformational function
7307 @item @emph{Syntax}:
7308 @code{RESULT = MATMUL(MATRIX_A, MATRIX_B)}
7310 @item @emph{Arguments}:
7311 @multitable @columnfractions .15 .70
7312 @item @var{MATRIX_A} @tab An array of @code{INTEGER},
7313 @code{REAL}, @code{COMPLEX}, or
7314 @code{LOGICAL} type, with a rank of
7316 @item @var{MATRIX_B} @tab An array of @code{INTEGER},
7317 @code{REAL}, or @code{COMPLEX} type if
7318 @var{MATRIX_A} is of a numeric type;
7319 otherwise, an array of @code{LOGICAL}
7320 type. The rank shall be one or two, and the
7321 first (or only) dimension of @var{MATRIX_B}
7322 shall be equal to the last (or only)
7323 dimension of @var{MATRIX_A}.
7326 @item @emph{Return value}:
7327 The matrix product of @var{MATRIX_A} and @var{MATRIX_B}. The type and
7328 kind of the result follow the usual type and kind promotion rules, as
7329 for the @code{*} or @code{.AND.} operators.
7331 @item @emph{See also}:
7337 @section @code{MAX} --- Maximum value of an argument list
7344 @cindex maximum value
7347 @item @emph{Description}:
7348 Returns the argument with the largest (most positive) value.
7350 @item @emph{Standard}:
7351 Fortran 77 and later
7356 @item @emph{Syntax}:
7357 @code{RESULT = MAX(A1, A2 [, A3 [, ...]])}
7359 @item @emph{Arguments}:
7360 @multitable @columnfractions .15 .70
7361 @item @var{A1} @tab The type shall be @code{INTEGER} or
7363 @item @var{A2}, @var{A3}, ... @tab An expression of the same type and kind
7364 as @var{A1}. (As a GNU extension,
7365 arguments of different kinds are
7369 @item @emph{Return value}:
7370 The return value corresponds to the maximum value among the arguments,
7371 and has the same type and kind as the first argument.
7373 @item @emph{Specific names}:
7374 @multitable @columnfractions .20 .20 .20 .25
7375 @item Name @tab Argument @tab Return type @tab Standard
7376 @item @code{MAX0(I)} @tab @code{INTEGER(4) I} @tab @code{INTEGER(4)} @tab Fortran 77 and later
7377 @item @code{AMAX0(I)} @tab @code{INTEGER(4) I} @tab @code{REAL(MAX(X))} @tab Fortran 77 and later
7378 @item @code{MAX1(X)} @tab @code{REAL X} @tab @code{INT(MAX(X))} @tab Fortran 77 and later
7379 @item @code{AMAX1(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
7380 @item @code{DMAX1(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
7383 @item @emph{See also}:
7384 @ref{MAXLOC} @ref{MAXVAL}, @ref{MIN}
7391 @section @code{MAXEXPONENT} --- Maximum exponent of a real kind
7392 @fnindex MAXEXPONENT
7393 @cindex model representation, maximum exponent
7396 @item @emph{Description}:
7397 @code{MAXEXPONENT(X)} returns the maximum exponent in the model of the
7400 @item @emph{Standard}:
7401 Fortran 95 and later
7406 @item @emph{Syntax}:
7407 @code{RESULT = MAXEXPONENT(X)}
7409 @item @emph{Arguments}:
7410 @multitable @columnfractions .15 .70
7411 @item @var{X} @tab Shall be of type @code{REAL}.
7414 @item @emph{Return value}:
7415 The return value is of type @code{INTEGER} and of the default integer
7418 @item @emph{Example}:
7424 print *, minexponent(x), maxexponent(x)
7425 print *, minexponent(y), maxexponent(y)
7426 end program exponents
7433 @section @code{MAXLOC} --- Location of the maximum value within an array
7435 @cindex array, location of maximum element
7438 @item @emph{Description}:
7439 Determines the location of the element in the array with the maximum
7440 value, or, if the @var{DIM} argument is supplied, determines the
7441 locations of the maximum element along each row of the array in the
7442 @var{DIM} direction. If @var{MASK} is present, only the elements for
7443 which @var{MASK} is @code{.TRUE.} are considered. If more than one
7444 element in the array has the maximum value, the location returned is
7445 that of the first such element in array element order. If the array has
7446 zero size, or all of the elements of @var{MASK} are @code{.FALSE.}, then
7447 the result is an array of zeroes. Similarly, if @var{DIM} is supplied
7448 and all of the elements of @var{MASK} along a given row are zero, the
7449 result value for that row is zero.
7451 @item @emph{Standard}:
7452 Fortran 95 and later
7455 Transformational function
7457 @item @emph{Syntax}:
7458 @multitable @columnfractions .80
7459 @item @code{RESULT = MAXLOC(ARRAY, DIM [, MASK])}
7460 @item @code{RESULT = MAXLOC(ARRAY [, MASK])}
7463 @item @emph{Arguments}:
7464 @multitable @columnfractions .15 .70
7465 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER},
7466 @code{REAL}, or @code{CHARACTER}.
7467 @item @var{DIM} @tab (Optional) Shall be a scalar of type
7468 @code{INTEGER}, with a value between one
7469 and the rank of @var{ARRAY}, inclusive. It
7470 may not be an optional dummy argument.
7471 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL},
7472 and conformable with @var{ARRAY}.
7475 @item @emph{Return value}:
7476 If @var{DIM} is absent, the result is a rank-one array with a length
7477 equal to the rank of @var{ARRAY}. If @var{DIM} is present, the result
7478 is an array with a rank one less than the rank of @var{ARRAY}, and a
7479 size corresponding to the size of @var{ARRAY} with the @var{DIM}
7480 dimension removed. If @var{DIM} is present and @var{ARRAY} has a rank
7481 of one, the result is a scalar. In all cases, the result is of default
7482 @code{INTEGER} type.
7484 @item @emph{See also}:
7485 @ref{MAX}, @ref{MAXVAL}
7492 @section @code{MAXVAL} --- Maximum value of an array
7494 @cindex array, maximum value
7495 @cindex maximum value
7498 @item @emph{Description}:
7499 Determines the maximum value of the elements in an array value, or, if
7500 the @var{DIM} argument is supplied, determines the maximum value along
7501 each row of the array in the @var{DIM} direction. If @var{MASK} is
7502 present, only the elements for which @var{MASK} is @code{.TRUE.} are
7503 considered. If the array has zero size, or all of the elements of
7504 @var{MASK} are @code{.FALSE.}, then the result is the most negative
7505 number of the type and kind of @var{ARRAY} if @var{ARRAY} is numeric, or
7506 a string of nulls if @var{ARRAY} is of character type.
7508 @item @emph{Standard}:
7509 Fortran 95 and later
7512 Transformational function
7514 @item @emph{Syntax}:
7515 @multitable @columnfractions .80
7516 @item @code{RESULT = MAXVAL(ARRAY, DIM [, MASK])}
7517 @item @code{RESULT = MAXVAL(ARRAY [, MASK])}
7520 @item @emph{Arguments}:
7521 @multitable @columnfractions .15 .70
7522 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER},
7523 @code{REAL}, or @code{CHARACTER}.
7524 @item @var{DIM} @tab (Optional) Shall be a scalar of type
7525 @code{INTEGER}, with a value between one
7526 and the rank of @var{ARRAY}, inclusive. It
7527 may not be an optional dummy argument.
7528 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL},
7529 and conformable with @var{ARRAY}.
7532 @item @emph{Return value}:
7533 If @var{DIM} is absent, or if @var{ARRAY} has a rank of one, the result
7534 is a scalar. If @var{DIM} is present, the result is an array with a
7535 rank one less than the rank of @var{ARRAY}, and a size corresponding to
7536 the size of @var{ARRAY} with the @var{DIM} dimension removed. In all
7537 cases, the result is of the same type and kind as @var{ARRAY}.
7539 @item @emph{See also}:
7540 @ref{MAX}, @ref{MAXLOC}
7546 @section @code{MCLOCK} --- Time function
7548 @cindex time, clock ticks
7552 @item @emph{Description}:
7553 Returns the number of clock ticks since the start of the process, based
7554 on the UNIX function @code{clock(3)}.
7556 This intrinsic is not fully portable, such as to systems with 32-bit
7557 @code{INTEGER} types but supporting times wider than 32 bits. Therefore,
7558 the values returned by this intrinsic might be, or become, negative, or
7559 numerically less than previous values, during a single run of the
7562 @item @emph{Standard}:
7568 @item @emph{Syntax}:
7569 @code{RESULT = MCLOCK()}
7571 @item @emph{Return value}:
7572 The return value is a scalar of type @code{INTEGER(4)}, equal to the
7573 number of clock ticks since the start of the process, or @code{-1} if
7574 the system does not support @code{clock(3)}.
7576 @item @emph{See also}:
7577 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK}, @ref{TIME}
7584 @section @code{MCLOCK8} --- Time function (64-bit)
7586 @cindex time, clock ticks
7590 @item @emph{Description}:
7591 Returns the number of clock ticks since the start of the process, based
7592 on the UNIX function @code{clock(3)}.
7594 @emph{Warning:} this intrinsic does not increase the range of the timing
7595 values over that returned by @code{clock(3)}. On a system with a 32-bit
7596 @code{clock(3)}, @code{MCLOCK8()} will return a 32-bit value, even though
7597 it is converted to a 64-bit @code{INTEGER(8)} value. That means
7598 overflows of the 32-bit value can still occur. Therefore, the values
7599 returned by this intrinsic might be or become negative or numerically
7600 less than previous values during a single run of the compiled program.
7602 @item @emph{Standard}:
7608 @item @emph{Syntax}:
7609 @code{RESULT = MCLOCK8()}
7611 @item @emph{Return value}:
7612 The return value is a scalar of type @code{INTEGER(8)}, equal to the
7613 number of clock ticks since the start of the process, or @code{-1} if
7614 the system does not support @code{clock(3)}.
7616 @item @emph{See also}:
7617 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK}, @ref{TIME8}
7624 @section @code{MERGE} --- Merge variables
7626 @cindex array, merge arrays
7627 @cindex array, combine arrays
7630 @item @emph{Description}:
7631 Select values from two arrays according to a logical mask. The result
7632 is equal to @var{TSOURCE} if @var{MASK} is @code{.TRUE.}, or equal to
7633 @var{FSOURCE} if it is @code{.FALSE.}.
7635 @item @emph{Standard}:
7636 Fortran 95 and later
7641 @item @emph{Syntax}:
7642 @code{RESULT = MERGE(TSOURCE, FSOURCE, MASK)}
7644 @item @emph{Arguments}:
7645 @multitable @columnfractions .15 .70
7646 @item @var{TSOURCE} @tab May be of any type.
7647 @item @var{FSOURCE} @tab Shall be of the same type and type parameters
7649 @item @var{MASK} @tab Shall be of type @code{LOGICAL}.
7652 @item @emph{Return value}:
7653 The result is of the same type and type parameters as @var{TSOURCE}.
7660 @section @code{MIN} --- Minimum value of an argument list
7667 @cindex minimum value
7670 @item @emph{Description}:
7671 Returns the argument with the smallest (most negative) value.
7673 @item @emph{Standard}:
7674 Fortran 77 and later
7679 @item @emph{Syntax}:
7680 @code{RESULT = MIN(A1, A2 [, A3, ...])}
7682 @item @emph{Arguments}:
7683 @multitable @columnfractions .15 .70
7684 @item @var{A1} @tab The type shall be @code{INTEGER} or
7686 @item @var{A2}, @var{A3}, ... @tab An expression of the same type and kind
7687 as @var{A1}. (As a GNU extension,
7688 arguments of different kinds are
7692 @item @emph{Return value}:
7693 The return value corresponds to the maximum value among the arguments,
7694 and has the same type and kind as the first argument.
7696 @item @emph{Specific names}:
7697 @multitable @columnfractions .20 .20 .20 .25
7698 @item Name @tab Argument @tab Return type @tab Standard
7699 @item @code{MIN0(I)} @tab @code{INTEGER(4) I} @tab @code{INTEGER(4)} @tab Fortran 77 and later
7700 @item @code{AMIN0(I)} @tab @code{INTEGER(4) I} @tab @code{REAL(MIN(X))} @tab Fortran 77 and later
7701 @item @code{MIN1(X)} @tab @code{REAL X} @tab @code{INT(MIN(X))} @tab Fortran 77 and later
7702 @item @code{AMIN1(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
7703 @item @code{DMIN1(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
7706 @item @emph{See also}:
7707 @ref{MAX}, @ref{MINLOC}, @ref{MINVAL}
7713 @section @code{MINEXPONENT} --- Minimum exponent of a real kind
7714 @fnindex MINEXPONENT
7715 @cindex model representation, minimum exponent
7718 @item @emph{Description}:
7719 @code{MINEXPONENT(X)} returns the minimum exponent in the model of the
7722 @item @emph{Standard}:
7723 Fortran 95 and later
7728 @item @emph{Syntax}:
7729 @code{RESULT = MINEXPONENT(X)}
7731 @item @emph{Arguments}:
7732 @multitable @columnfractions .15 .70
7733 @item @var{X} @tab Shall be of type @code{REAL}.
7736 @item @emph{Return value}:
7737 The return value is of type @code{INTEGER} and of the default integer
7740 @item @emph{Example}:
7741 See @code{MAXEXPONENT} for an example.
7747 @section @code{MINLOC} --- Location of the minimum value within an array
7749 @cindex array, location of minimum element
7752 @item @emph{Description}:
7753 Determines the location of the element in the array with the minimum
7754 value, or, if the @var{DIM} argument is supplied, determines the
7755 locations of the minimum element along each row of the array in the
7756 @var{DIM} direction. If @var{MASK} is present, only the elements for
7757 which @var{MASK} is @code{.TRUE.} are considered. If more than one
7758 element in the array has the minimum value, the location returned is
7759 that of the first such element in array element order. If the array has
7760 zero size, or all of the elements of @var{MASK} are @code{.FALSE.}, then
7761 the result is an array of zeroes. Similarly, if @var{DIM} is supplied
7762 and all of the elements of @var{MASK} along a given row are zero, the
7763 result value for that row is zero.
7765 @item @emph{Standard}:
7766 Fortran 95 and later
7769 Transformational function
7771 @item @emph{Syntax}:
7772 @multitable @columnfractions .80
7773 @item @code{RESULT = MINLOC(ARRAY, DIM [, MASK])}
7774 @item @code{RESULT = MINLOC(ARRAY [, MASK])}
7777 @item @emph{Arguments}:
7778 @multitable @columnfractions .15 .70
7779 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER},
7780 @code{REAL}, or @code{CHARACTER}.
7781 @item @var{DIM} @tab (Optional) Shall be a scalar of type
7782 @code{INTEGER}, with a value between one
7783 and the rank of @var{ARRAY}, inclusive. It
7784 may not be an optional dummy argument.
7785 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL},
7786 and conformable with @var{ARRAY}.
7789 @item @emph{Return value}:
7790 If @var{DIM} is absent, the result is a rank-one array with a length
7791 equal to the rank of @var{ARRAY}. If @var{DIM} is present, the result
7792 is an array with a rank one less than the rank of @var{ARRAY}, and a
7793 size corresponding to the size of @var{ARRAY} with the @var{DIM}
7794 dimension removed. If @var{DIM} is present and @var{ARRAY} has a rank
7795 of one, the result is a scalar. In all cases, the result is of default
7796 @code{INTEGER} type.
7798 @item @emph{See also}:
7799 @ref{MIN}, @ref{MINVAL}
7806 @section @code{MINVAL} --- Minimum value of an array
7808 @cindex array, minimum value
7809 @cindex minimum value
7812 @item @emph{Description}:
7813 Determines the minimum value of the elements in an array value, or, if
7814 the @var{DIM} argument is supplied, determines the minimum value along
7815 each row of the array in the @var{DIM} direction. If @var{MASK} is
7816 present, only the elements for which @var{MASK} is @code{.TRUE.} are
7817 considered. If the array has zero size, or all of the elements of
7818 @var{MASK} are @code{.FALSE.}, then the result is @code{HUGE(ARRAY)} if
7819 @var{ARRAY} is numeric, or a string of @code{CHAR(255)} characters if
7820 @var{ARRAY} is of character type.
7822 @item @emph{Standard}:
7823 Fortran 95 and later
7826 Transformational function
7828 @item @emph{Syntax}:
7829 @multitable @columnfractions .80
7830 @item @code{RESULT = MINVAL(ARRAY, DIM [, MASK])}
7831 @item @code{RESULT = MINVAL(ARRAY [, MASK])}
7834 @item @emph{Arguments}:
7835 @multitable @columnfractions .15 .70
7836 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER},
7837 @code{REAL}, or @code{CHARACTER}.
7838 @item @var{DIM} @tab (Optional) Shall be a scalar of type
7839 @code{INTEGER}, with a value between one
7840 and the rank of @var{ARRAY}, inclusive. It
7841 may not be an optional dummy argument.
7842 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL},
7843 and conformable with @var{ARRAY}.
7846 @item @emph{Return value}:
7847 If @var{DIM} is absent, or if @var{ARRAY} has a rank of one, the result
7848 is a scalar. If @var{DIM} is present, the result is an array with a
7849 rank one less than the rank of @var{ARRAY}, and a size corresponding to
7850 the size of @var{ARRAY} with the @var{DIM} dimension removed. In all
7851 cases, the result is of the same type and kind as @var{ARRAY}.
7853 @item @emph{See also}:
7854 @ref{MIN}, @ref{MINLOC}
7861 @section @code{MOD} --- Remainder function
7866 @cindex division, remainder
7869 @item @emph{Description}:
7870 @code{MOD(A,P)} computes the remainder of the division of A by P@. It is
7871 calculated as @code{A - (INT(A/P) * P)}.
7873 @item @emph{Standard}:
7874 Fortran 77 and later
7879 @item @emph{Syntax}:
7880 @code{RESULT = MOD(A, P)}
7882 @item @emph{Arguments}:
7883 @multitable @columnfractions .15 .70
7884 @item @var{A} @tab Shall be a scalar of type @code{INTEGER} or @code{REAL}
7885 @item @var{P} @tab Shall be a scalar of the same type as @var{A} and not
7889 @item @emph{Return value}:
7890 The kind of the return value is the result of cross-promoting
7891 the kinds of the arguments.
7893 @item @emph{Example}:
7897 print *, mod(17.5,5.5)
7898 print *, mod(17.5d0,5.5)
7899 print *, mod(17.5,5.5d0)
7902 print *, mod(-17.5,5.5)
7903 print *, mod(-17.5d0,5.5)
7904 print *, mod(-17.5,5.5d0)
7907 print *, mod(17.5,-5.5)
7908 print *, mod(17.5d0,-5.5)
7909 print *, mod(17.5,-5.5d0)
7910 end program test_mod
7913 @item @emph{Specific names}:
7914 @multitable @columnfractions .20 .20 .20 .25
7915 @item Name @tab Arguments @tab Return type @tab Standard
7916 @item @code{AMOD(A,P)} @tab @code{REAL(4)} @tab @code{REAL(4)} @tab Fortran 95 and later
7917 @item @code{DMOD(A,P)} @tab @code{REAL(8)} @tab @code{REAL(8)} @tab Fortran 95 and later
7924 @section @code{MODULO} --- Modulo function
7927 @cindex division, modulo
7930 @item @emph{Description}:
7931 @code{MODULO(A,P)} computes the @var{A} modulo @var{P}.
7933 @item @emph{Standard}:
7934 Fortran 95 and later
7939 @item @emph{Syntax}:
7940 @code{RESULT = MODULO(A, P)}
7942 @item @emph{Arguments}:
7943 @multitable @columnfractions .15 .70
7944 @item @var{A} @tab Shall be a scalar of type @code{INTEGER} or @code{REAL}
7945 @item @var{P} @tab Shall be a scalar of the same type and kind as @var{A}
7948 @item @emph{Return value}:
7949 The type and kind of the result are those of the arguments.
7951 @item If @var{A} and @var{P} are of type @code{INTEGER}:
7952 @code{MODULO(A,P)} has the value @var{R} such that @code{A=Q*P+R}, where
7953 @var{Q} is an integer and @var{R} is between 0 (inclusive) and @var{P}
7955 @item If @var{A} and @var{P} are of type @code{REAL}:
7956 @code{MODULO(A,P)} has the value of @code{A - FLOOR (A / P) * P}.
7958 In all cases, if @var{P} is zero the result is processor-dependent.
7960 @item @emph{Example}:
7963 print *, modulo(17,3)
7964 print *, modulo(17.5,5.5)
7966 print *, modulo(-17,3)
7967 print *, modulo(-17.5,5.5)
7969 print *, modulo(17,-3)
7970 print *, modulo(17.5,-5.5)
7979 @section @code{MOVE_ALLOC} --- Move allocation from one object to another
7981 @cindex moving allocation
7982 @cindex allocation, moving
7985 @item @emph{Description}:
7986 @code{MOVE_ALLOC(SRC, DEST)} moves the allocation from @var{SRC} to
7987 @var{DEST}. @var{SRC} will become deallocated in the process.
7989 @item @emph{Standard}:
7990 Fortran 2003 and later
7995 @item @emph{Syntax}:
7996 @code{CALL MOVE_ALLOC(SRC, DEST)}
7998 @item @emph{Arguments}:
7999 @multitable @columnfractions .15 .70
8000 @item @var{SRC} @tab @code{ALLOCATABLE}, @code{INTENT(INOUT)}, may be
8001 of any type and kind.
8002 @item @var{DEST} @tab @code{ALLOCATABLE}, @code{INTENT(OUT)}, shall be
8003 of the same type, kind and rank as @var{SRC}
8006 @item @emph{Return value}:
8009 @item @emph{Example}:
8011 program test_move_alloc
8012 integer, allocatable :: a(:), b(:)
8016 call move_alloc(a, b)
8017 print *, allocated(a), allocated(b)
8019 end program test_move_alloc
8026 @section @code{MVBITS} --- Move bits from one integer to another
8031 @item @emph{Description}:
8032 Moves @var{LEN} bits from positions @var{FROMPOS} through
8033 @code{FROMPOS+LEN-1} of @var{FROM} to positions @var{TOPOS} through
8034 @code{TOPOS+LEN-1} of @var{TO}. The portion of argument @var{TO} not
8035 affected by the movement of bits is unchanged. The values of
8036 @code{FROMPOS+LEN-1} and @code{TOPOS+LEN-1} must be less than
8037 @code{BIT_SIZE(FROM)}.
8039 @item @emph{Standard}:
8040 Fortran 95 and later
8043 Elemental subroutine
8045 @item @emph{Syntax}:
8046 @code{CALL MVBITS(FROM, FROMPOS, LEN, TO, TOPOS)}
8048 @item @emph{Arguments}:
8049 @multitable @columnfractions .15 .70
8050 @item @var{FROM} @tab The type shall be @code{INTEGER}.
8051 @item @var{FROMPOS} @tab The type shall be @code{INTEGER}.
8052 @item @var{LEN} @tab The type shall be @code{INTEGER}.
8053 @item @var{TO} @tab The type shall be @code{INTEGER}, of the
8054 same kind as @var{FROM}.
8055 @item @var{TOPOS} @tab The type shall be @code{INTEGER}.
8058 @item @emph{See also}:
8059 @ref{IBCLR}, @ref{IBSET}, @ref{IBITS}, @ref{IAND}, @ref{IOR}, @ref{IEOR}
8065 @section @code{NEAREST} --- Nearest representable number
8067 @cindex real number, nearest different
8068 @cindex floating point, nearest different
8071 @item @emph{Description}:
8072 @code{NEAREST(X, S)} returns the processor-representable number nearest
8073 to @code{X} in the direction indicated by the sign of @code{S}.
8075 @item @emph{Standard}:
8076 Fortran 95 and later
8081 @item @emph{Syntax}:
8082 @code{RESULT = NEAREST(X, S)}
8084 @item @emph{Arguments}:
8085 @multitable @columnfractions .15 .70
8086 @item @var{X} @tab Shall be of type @code{REAL}.
8087 @item @var{S} @tab (Optional) shall be of type @code{REAL} and
8091 @item @emph{Return value}:
8092 The return value is of the same type as @code{X}. If @code{S} is
8093 positive, @code{NEAREST} returns the processor-representable number
8094 greater than @code{X} and nearest to it. If @code{S} is negative,
8095 @code{NEAREST} returns the processor-representable number smaller than
8096 @code{X} and nearest to it.
8098 @item @emph{Example}:
8100 program test_nearest
8102 x = nearest(42.0, 1.0)
8103 y = nearest(42.0, -1.0)
8104 write (*,"(3(G20.15))") x, y, x - y
8105 end program test_nearest
8112 @section @code{NEW_LINE} --- New line character
8115 @cindex output, newline
8118 @item @emph{Description}:
8119 @code{NEW_LINE(C)} returns the new-line character.
8121 @item @emph{Standard}:
8122 Fortran 2003 and later
8127 @item @emph{Syntax}:
8128 @code{RESULT = NEW_LINE(C)}
8130 @item @emph{Arguments}:
8131 @multitable @columnfractions .15 .70
8132 @item @var{C} @tab The argument shall be a scalar or array of the
8133 type @code{CHARACTER}.
8136 @item @emph{Return value}:
8137 Returns a @var{CHARACTER} scalar of length one with the new-line character of
8138 the same kind as parameter @var{C}.
8140 @item @emph{Example}:
8144 write(*,'(A)') 'This is record 1.'//NEW_LINE('A')//'This is record 2.'
8152 @section @code{NINT} --- Nearest whole number
8155 @cindex rounding, nearest whole number
8158 @item @emph{Description}:
8159 @code{NINT(X)} rounds its argument to the nearest whole number.
8161 @item @emph{Standard}:
8162 Fortran 77 and later, with @var{KIND} argument Fortran 90 and later
8167 @item @emph{Syntax}:
8168 @code{RESULT = NINT(X [, KIND])}
8170 @item @emph{Arguments}:
8171 @multitable @columnfractions .15 .70
8172 @item @var{X} @tab The type of the argument shall be @code{REAL}.
8173 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
8174 expression indicating the kind parameter of
8178 @item @emph{Return value}:
8179 Returns @var{A} with the fractional portion of its magnitude eliminated by
8180 rounding to the nearest whole number and with its sign preserved,
8181 converted to an @code{INTEGER} of the default kind.
8183 @item @emph{Example}:
8190 print *, nint(x4), idnint(x8)
8191 end program test_nint
8194 @item @emph{Specific names}:
8195 @multitable @columnfractions .25 .25 .25
8196 @item Name @tab Argument @tab Standard
8197 @item @code{IDNINT(X)} @tab @code{REAL(8)} @tab Fortran 95 and later
8200 @item @emph{See also}:
8201 @ref{CEILING}, @ref{FLOOR}
8208 @section @code{NOT} --- Logical negation
8210 @cindex bits, negate
8211 @cindex bitwise logical not
8212 @cindex logical not, bitwise
8215 @item @emph{Description}:
8216 @code{NOT} returns the bitwise boolean inverse of @var{I}.
8218 @item @emph{Standard}:
8219 Fortran 95 and later
8224 @item @emph{Syntax}:
8225 @code{RESULT = NOT(I)}
8227 @item @emph{Arguments}:
8228 @multitable @columnfractions .15 .70
8229 @item @var{I} @tab The type shall be @code{INTEGER}.
8232 @item @emph{Return value}:
8233 The return type is @code{INTEGER}, of the same kind as the
8236 @item @emph{See also}:
8237 @ref{IAND}, @ref{IEOR}, @ref{IOR}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}
8244 @section @code{NULL} --- Function that returns an disassociated pointer
8246 @cindex pointer, status
8247 @cindex pointer, disassociated
8250 @item @emph{Description}:
8251 Returns a disassociated pointer.
8253 If @var{MOLD} is present, a dissassociated pointer of the same type is
8254 returned, otherwise the type is determined by context.
8256 In Fortran 95, @var{MOLD} is optional. Please note that Fortran 2003
8257 includes cases where it is required.
8259 @item @emph{Standard}:
8260 Fortran 95 and later
8263 Transformational function
8265 @item @emph{Syntax}:
8266 @code{PTR => NULL([MOLD])}
8268 @item @emph{Arguments}:
8269 @multitable @columnfractions .15 .70
8270 @item @var{MOLD} @tab (Optional) shall be a pointer of any association
8271 status and of any type.
8274 @item @emph{Return value}:
8275 A disassociated pointer.
8277 @item @emph{Example}:
8279 REAL, POINTER, DIMENSION(:) :: VEC => NULL ()
8282 @item @emph{See also}:
8289 @section @code{OR} --- Bitwise logical OR
8291 @cindex bitwise logical or
8292 @cindex logical or, bitwise
8295 @item @emph{Description}:
8296 Bitwise logical @code{OR}.
8298 This intrinsic routine is provided for backwards compatibility with
8299 GNU Fortran 77. For integer arguments, programmers should consider
8300 the use of the @ref{IOR} intrinsic defined by the Fortran standard.
8302 @item @emph{Standard}:
8308 @item @emph{Syntax}:
8309 @code{RESULT = OR(X, Y)}
8311 @item @emph{Arguments}:
8312 @multitable @columnfractions .15 .70
8313 @item @var{X} @tab The type shall be either a scalar @code{INTEGER}
8314 type or a scalar @code{LOGICAL} type.
8315 @item @var{Y} @tab The type shall be the same as the type of @var{X}.
8318 @item @emph{Return value}:
8319 The return type is either a scalar @code{INTEGER} or a scalar
8320 @code{LOGICAL}. If the kind type parameters differ, then the
8321 smaller kind type is implicitly converted to larger kind, and the
8322 return has the larger kind.
8324 @item @emph{Example}:
8327 LOGICAL :: T = .TRUE., F = .FALSE.
8329 DATA a / Z'F' /, b / Z'3' /
8331 WRITE (*,*) OR(T, T), OR(T, F), OR(F, T), OR(F, F)
8332 WRITE (*,*) OR(a, b)
8336 @item @emph{See also}:
8337 Fortran 95 elemental function: @ref{IOR}
8343 @section @code{PACK} --- Pack an array into an array of rank one
8345 @cindex array, packing
8346 @cindex array, reduce dimension
8347 @cindex array, gather elements
8350 @item @emph{Description}:
8351 Stores the elements of @var{ARRAY} in an array of rank one.
8353 The beginning of the resulting array is made up of elements whose @var{MASK}
8354 equals @code{TRUE}. Afterwards, positions are filled with elements taken from
8357 @item @emph{Standard}:
8358 Fortran 95 and later
8361 Transformational function
8363 @item @emph{Syntax}:
8364 @code{RESULT = PACK(ARRAY, MASK[,VECTOR]}
8366 @item @emph{Arguments}:
8367 @multitable @columnfractions .15 .70
8368 @item @var{ARRAY} @tab Shall be an array of any type.
8369 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL} and
8370 of the same size as @var{ARRAY}. Alternatively, it may be a @code{LOGICAL}
8372 @item @var{VECTOR} @tab (Optional) shall be an array of the same type
8373 as @var{ARRAY} and of rank one. If present, the number of elements in
8374 @var{VECTOR} shall be equal to or greater than the number of true elements
8375 in @var{MASK}. If @var{MASK} is scalar, the number of elements in
8376 @var{VECTOR} shall be equal to or greater than the number of elements in
8380 @item @emph{Return value}:
8381 The result is an array of rank one and the same type as that of @var{ARRAY}.
8382 If @var{VECTOR} is present, the result size is that of @var{VECTOR}, the
8383 number of @code{TRUE} values in @var{MASK} otherwise.
8385 @item @emph{Example}:
8386 Gathering nonzero elements from an array:
8390 m = (/ 1, 0, 0, 0, 5, 0 /)
8391 WRITE(*, FMT="(6(I0, ' '))") pack(m, m /= 0) ! "1 5"
8395 Gathering nonzero elements from an array and appending elements from @var{VECTOR}:
8399 m = (/ 1, 0, 0, 2 /)
8400 WRITE(*, FMT="(4(I0, ' '))") pack(m, m /= 0, (/ 0, 0, 3, 4 /)) ! "1 2 3 4"
8404 @item @emph{See also}:
8411 @section @code{PERROR} --- Print system error message
8413 @cindex system, error handling
8416 @item @emph{Description}:
8417 Prints (on the C @code{stderr} stream) a newline-terminated error
8418 message corresponding to the last system error. This is prefixed by
8419 @var{STRING}, a colon and a space. See @code{perror(3)}.
8421 @item @emph{Standard}:
8427 @item @emph{Syntax}:
8428 @code{CALL PERROR(STRING)}
8430 @item @emph{Arguments}:
8431 @multitable @columnfractions .15 .70
8432 @item @var{STRING} @tab A scalar of type @code{CHARACTER} and of the
8436 @item @emph{See also}:
8443 @section @code{PRECISION} --- Decimal precision of a real kind
8445 @cindex model representation, precision
8448 @item @emph{Description}:
8449 @code{PRECISION(X)} returns the decimal precision in the model of the
8452 @item @emph{Standard}:
8453 Fortran 95 and later
8458 @item @emph{Syntax}:
8459 @code{RESULT = PRECISION(X)}
8461 @item @emph{Arguments}:
8462 @multitable @columnfractions .15 .70
8463 @item @var{X} @tab Shall be of type @code{REAL} or @code{COMPLEX}.
8466 @item @emph{Return value}:
8467 The return value is of type @code{INTEGER} and of the default integer
8470 @item @emph{Example}:
8472 program prec_and_range
8473 real(kind=4) :: x(2)
8474 complex(kind=8) :: y
8476 print *, precision(x), range(x)
8477 print *, precision(y), range(y)
8478 end program prec_and_range
8485 @section @code{PRESENT} --- Determine whether an optional dummy argument is specified
8489 @item @emph{Description}:
8490 Determines whether an optional dummy argument is present.
8492 @item @emph{Standard}:
8493 Fortran 95 and later
8498 @item @emph{Syntax}:
8499 @code{RESULT = PRESENT(A)}
8501 @item @emph{Arguments}:
8502 @multitable @columnfractions .15 .70
8503 @item @var{A} @tab May be of any type and may be a pointer, scalar or array
8504 value, or a dummy procedure. It shall be the name of an optional dummy argument
8505 accessible within the current subroutine or function.
8508 @item @emph{Return value}:
8509 Returns either @code{TRUE} if the optional argument @var{A} is present, or
8510 @code{FALSE} otherwise.
8512 @item @emph{Example}:
8514 PROGRAM test_present
8515 WRITE(*,*) f(), f(42) ! "F T"
8517 LOGICAL FUNCTION f(x)
8518 INTEGER, INTENT(IN), OPTIONAL :: x
8528 @section @code{PRODUCT} --- Product of array elements
8530 @cindex array, product
8531 @cindex array, multiply elements
8532 @cindex array, conditionally multiply elements
8533 @cindex multiply array elements
8536 @item @emph{Description}:
8537 Multiplies the elements of @var{ARRAY} along dimension @var{DIM} if
8538 the corresponding element in @var{MASK} is @code{TRUE}.
8540 @item @emph{Standard}:
8541 Fortran 95 and later
8544 Transformational function
8546 @item @emph{Syntax}:
8547 @code{RESULT = PRODUCT(ARRAY[, MASK])}
8548 @code{RESULT = PRODUCT(ARRAY, DIM[, MASK])}
8550 @item @emph{Arguments}:
8551 @multitable @columnfractions .15 .70
8552 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER},
8553 @code{REAL} or @code{COMPLEX}.
8554 @item @var{DIM} @tab (Optional) shall be a scalar of type
8555 @code{INTEGER} with a value in the range from 1 to n, where n
8556 equals the rank of @var{ARRAY}.
8557 @item @var{MASK} @tab (Optional) shall be of type @code{LOGICAL}
8558 and either be a scalar or an array of the same shape as @var{ARRAY}.
8561 @item @emph{Return value}:
8562 The result is of the same type as @var{ARRAY}.
8564 If @var{DIM} is absent, a scalar with the product of all elements in
8565 @var{ARRAY} is returned. Otherwise, an array of rank n-1, where n equals
8566 the rank of @var{ARRAY}, and a shape similar to that of @var{ARRAY} with
8567 dimension @var{DIM} dropped is returned.
8570 @item @emph{Example}:
8572 PROGRAM test_product
8573 INTEGER :: x(5) = (/ 1, 2, 3, 4 ,5 /)
8574 print *, PRODUCT(x) ! all elements, product = 120
8575 print *, PRODUCT(x, MASK=MOD(x, 2)==1) ! odd elements, product = 15
8579 @item @emph{See also}:
8586 @section @code{RADIX} --- Base of a model number
8588 @cindex model representation, base
8589 @cindex model representation, radix
8592 @item @emph{Description}:
8593 @code{RADIX(X)} returns the base of the model representing the entity @var{X}.
8595 @item @emph{Standard}:
8596 Fortran 95 and later
8601 @item @emph{Syntax}:
8602 @code{RESULT = RADIX(X)}
8604 @item @emph{Arguments}:
8605 @multitable @columnfractions .15 .70
8606 @item @var{X} @tab Shall be of type @code{INTEGER} or @code{REAL}
8609 @item @emph{Return value}:
8610 The return value is a scalar of type @code{INTEGER} and of the default
8613 @item @emph{Example}:
8616 print *, "The radix for the default integer kind is", radix(0)
8617 print *, "The radix for the default real kind is", radix(0.0)
8618 end program test_radix
8626 @section @code{RAN} --- Real pseudo-random number
8628 @cindex random number generation
8631 @item @emph{Description}:
8632 For compatibility with HP FORTRAN 77/iX, the @code{RAN} intrinsic is
8633 provided as an alias for @code{RAND}. See @ref{RAND} for complete
8636 @item @emph{Standard}:
8642 @item @emph{See also}:
8643 @ref{RAND}, @ref{RANDOM_NUMBER}
8649 @section @code{RAND} --- Real pseudo-random number
8651 @cindex random number generation
8654 @item @emph{Description}:
8655 @code{RAND(FLAG)} returns a pseudo-random number from a uniform
8656 distribution between 0 and 1. If @var{FLAG} is 0, the next number
8657 in the current sequence is returned; if @var{FLAG} is 1, the generator
8658 is restarted by @code{CALL SRAND(0)}; if @var{FLAG} has any other value,
8659 it is used as a new seed with @code{SRAND}.
8661 This intrinsic routine is provided for backwards compatibility with
8662 GNU Fortran 77. It implements a simple modulo generator as provided
8663 by @command{g77}. For new code, one should consider the use of
8664 @ref{RANDOM_NUMBER} as it implements a superior algorithm.
8666 @item @emph{Standard}:
8672 @item @emph{Syntax}:
8673 @code{RESULT = RAND(FLAG)}
8675 @item @emph{Arguments}:
8676 @multitable @columnfractions .15 .70
8677 @item @var{FLAG} @tab Shall be a scalar @code{INTEGER} of kind 4.
8680 @item @emph{Return value}:
8681 The return value is of @code{REAL} type and the default kind.
8683 @item @emph{Example}:
8686 integer,parameter :: seed = 86456
8689 print *, rand(), rand(), rand(), rand()
8690 print *, rand(seed), rand(), rand(), rand()
8691 end program test_rand
8694 @item @emph{See also}:
8695 @ref{SRAND}, @ref{RANDOM_NUMBER}
8702 @section @code{RANDOM_NUMBER} --- Pseudo-random number
8703 @fnindex RANDOM_NUMBER
8704 @cindex random number generation
8707 @item @emph{Description}:
8708 Returns a single pseudorandom number or an array of pseudorandom numbers
8709 from the uniform distribution over the range @math{ 0 \leq x < 1}.
8711 The runtime-library implements George Marsaglia's KISS (Keep It Simple
8712 Stupid) random number generator (RNG). This RNG combines:
8714 @item The congruential generator @math{x(n) = 69069 \cdot x(n-1) + 1327217885}
8715 with a period of @math{2^{32}},
8716 @item A 3-shift shift-register generator with a period of @math{2^{32} - 1},
8717 @item Two 16-bit multiply-with-carry generators with a period of
8718 @math{597273182964842497 > 2^{59}}.
8720 The overall period exceeds @math{2^{123}}.
8722 Please note, this RNG is thread safe if used within OpenMP directives,
8723 i.e., its state will be consistent while called from multiple threads.
8724 However, the KISS generator does not create random numbers in parallel
8725 from multiple sources, but in sequence from a single source. If an
8726 OpenMP-enabled application heavily relies on random numbers, one should
8727 consider employing a dedicated parallel random number generator instead.
8729 @item @emph{Standard}:
8730 Fortran 95 and later
8735 @item @emph{Syntax}:
8736 @code{RANDOM_NUMBER(HARVEST)}
8738 @item @emph{Arguments}:
8739 @multitable @columnfractions .15 .70
8740 @item @var{HARVEST} @tab Shall be a scalar or an array of type @code{REAL}.
8743 @item @emph{Example}:
8745 program test_random_number
8747 CALL init_random_seed() ! see example of RANDOM_SEED
8748 CALL RANDOM_NUMBER(r)
8752 @item @emph{See also}:
8759 @section @code{RANDOM_SEED} --- Initialize a pseudo-random number sequence
8760 @fnindex RANDOM_SEED
8761 @cindex random number generation, seeding
8762 @cindex seeding a random number generator
8765 @item @emph{Description}:
8766 Restarts or queries the state of the pseudorandom number generator used by
8767 @code{RANDOM_NUMBER}.
8769 If @code{RANDOM_SEED} is called without arguments, it is initialized to
8770 a default state. The example below shows how to initialize the random
8771 seed based on the system's time.
8773 @item @emph{Standard}:
8774 Fortran 95 and later
8779 @item @emph{Syntax}:
8780 @code{CALL RANDOM_SEED(SIZE, PUT, GET)}
8782 @item @emph{Arguments}:
8783 @multitable @columnfractions .15 .70
8784 @item @var{SIZE} @tab (Optional) Shall be a scalar and of type default
8785 @code{INTEGER}, with @code{INTENT(OUT)}. It specifies the minimum size
8786 of the arrays used with the @var{PUT} and @var{GET} arguments.
8787 @item @var{PUT} @tab (Optional) Shall be an array of type default
8788 @code{INTEGER} and rank one. It is @code{INTENT(IN)} and the size of
8789 the array must be larger than or equal to the number returned by the
8790 @var{SIZE} argument.
8791 @item @var{GET} @tab (Optional) Shall be an array of type default
8792 @code{INTEGER} and rank one. It is @code{INTENT(OUT)} and the size
8793 of the array must be larger than or equal to the number returned by
8794 the @var{SIZE} argument.
8797 @item @emph{Example}:
8799 SUBROUTINE init_random_seed()
8800 INTEGER :: i, n, clock
8801 INTEGER, DIMENSION(:), ALLOCATABLE :: seed
8803 CALL RANDOM_SEED(size = n)
8806 CALL SYSTEM_CLOCK(COUNT=clock)
8808 seed = clock + 37 * (/ (i - 1, i = 1, n) /)
8809 CALL RANDOM_SEED(PUT = seed)
8815 @item @emph{See also}:
8822 @section @code{RANGE} --- Decimal exponent range of a real kind
8824 @cindex model representation, range
8827 @item @emph{Description}:
8828 @code{RANGE(X)} returns the decimal exponent range in the model of the
8831 @item @emph{Standard}:
8832 Fortran 95 and later
8837 @item @emph{Syntax}:
8838 @code{RESULT = RANGE(X)}
8840 @item @emph{Arguments}:
8841 @multitable @columnfractions .15 .70
8842 @item @var{X} @tab Shall be of type @code{REAL} or @code{COMPLEX}.
8845 @item @emph{Return value}:
8846 The return value is of type @code{INTEGER} and of the default integer
8849 @item @emph{Example}:
8850 See @code{PRECISION} for an example.
8856 @section @code{REAL} --- Convert to real type
8859 @cindex conversion, to real
8860 @cindex complex numbers, real part
8863 @item @emph{Description}:
8864 @code{REAL(X [, KIND])} converts its argument @var{X} to a real type. The
8865 @code{REALPART(X)} function is provided for compatibility with @command{g77},
8866 and its use is strongly discouraged.
8868 @item @emph{Standard}:
8869 Fortran 77 and later
8874 @item @emph{Syntax}:
8875 @multitable @columnfractions .80
8876 @item @code{RESULT = REAL(X [, KIND])}
8877 @item @code{RESULT = REALPART(Z)}
8880 @item @emph{Arguments}:
8881 @multitable @columnfractions .15 .70
8882 @item @var{X} @tab Shall be @code{INTEGER}, @code{REAL}, or
8884 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
8885 expression indicating the kind parameter of
8889 @item @emph{Return value}:
8890 These functions return a @code{REAL} variable or array under
8891 the following rules:
8895 @code{REAL(X)} is converted to a default real type if @var{X} is an
8896 integer or real variable.
8898 @code{REAL(X)} is converted to a real type with the kind type parameter
8899 of @var{X} if @var{X} is a complex variable.
8901 @code{REAL(X, KIND)} is converted to a real type with kind type
8902 parameter @var{KIND} if @var{X} is a complex, integer, or real
8906 @item @emph{Example}:
8909 complex :: x = (1.0, 2.0)
8910 print *, real(x), real(x,8), realpart(x)
8911 end program test_real
8914 @item @emph{See also}:
8915 @ref{DBLE}, @ref{DFLOAT}, @ref{FLOAT}
8922 @section @code{RENAME} --- Rename a file
8924 @cindex file system, rename file
8927 @item @emph{Description}:
8928 Renames a file from file @var{PATH1} to @var{PATH2}. A null
8929 character (@code{CHAR(0)}) can be used to mark the end of the names in
8930 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
8931 names are ignored. If the @var{STATUS} argument is supplied, it
8932 contains 0 on success or a nonzero error code upon return; see
8935 This intrinsic is provided in both subroutine and function forms;
8936 however, only one form can be used in any given program unit.
8938 @item @emph{Standard}:
8942 Subroutine, function
8944 @item @emph{Syntax}:
8945 @multitable @columnfractions .80
8946 @item @code{CALL RENAME(PATH1, PATH2 [, STATUS])}
8947 @item @code{STATUS = RENAME(PATH1, PATH2)}
8950 @item @emph{Arguments}:
8951 @multitable @columnfractions .15 .70
8952 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
8953 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
8954 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
8957 @item @emph{See also}:
8965 @section @code{REPEAT} --- Repeated string concatenation
8967 @cindex string, repeat
8968 @cindex string, concatenate
8971 @item @emph{Description}:
8972 Concatenates @var{NCOPIES} copies of a string.
8974 @item @emph{Standard}:
8975 Fortran 95 and later
8978 Transformational function
8980 @item @emph{Syntax}:
8981 @code{RESULT = REPEAT(STRING, NCOPIES)}
8983 @item @emph{Arguments}:
8984 @multitable @columnfractions .15 .70
8985 @item @var{STRING} @tab Shall be scalar and of type @code{CHARACTER}.
8986 @item @var{NCOPIES} @tab Shall be scalar and of type @code{INTEGER}.
8989 @item @emph{Return value}:
8990 A new scalar of type @code{CHARACTER} built up from @var{NCOPIES} copies
8993 @item @emph{Example}:
8996 write(*,*) repeat("x", 5) ! "xxxxx"
9004 @section @code{RESHAPE} --- Function to reshape an array
9006 @cindex array, change dimensions
9007 @cindex array, transmogrify
9010 @item @emph{Description}:
9011 Reshapes @var{SOURCE} to correspond to @var{SHAPE}. If necessary,
9012 the new array may be padded with elements from @var{PAD} or permuted
9013 as defined by @var{ORDER}.
9015 @item @emph{Standard}:
9016 Fortran 95 and later
9019 Transformational function
9021 @item @emph{Syntax}:
9022 @code{RESULT = RESHAPE(SOURCE, SHAPE[, PAD, ORDER])}
9024 @item @emph{Arguments}:
9025 @multitable @columnfractions .15 .70
9026 @item @var{SOURCE} @tab Shall be an array of any type.
9027 @item @var{SHAPE} @tab Shall be of type @code{INTEGER} and an
9028 array of rank one. Its values must be positive or zero.
9029 @item @var{PAD} @tab (Optional) shall be an array of the same
9030 type as @var{SOURCE}.
9031 @item @var{ORDER} @tab (Optional) shall be of type @code{INTEGER}
9032 and an array of the same shape as @var{SHAPE}. Its values shall
9033 be a permutation of the numbers from 1 to n, where n is the size of
9034 @var{SHAPE}. If @var{ORDER} is absent, the natural ordering shall
9038 @item @emph{Return value}:
9039 The result is an array of shape @var{SHAPE} with the same type as
9042 @item @emph{Example}:
9044 PROGRAM test_reshape
9045 INTEGER, DIMENSION(4) :: x
9046 WRITE(*,*) SHAPE(x) ! prints "4"
9047 WRITE(*,*) SHAPE(RESHAPE(x, (/2, 2/))) ! prints "2 2"
9051 @item @emph{See also}:
9058 @section @code{RRSPACING} --- Reciprocal of the relative spacing
9060 @cindex real number, relative spacing
9061 @cindex floating point, relative spacing
9065 @item @emph{Description}:
9066 @code{RRSPACING(X)} returns the reciprocal of the relative spacing of
9067 model numbers near @var{X}.
9069 @item @emph{Standard}:
9070 Fortran 95 and later
9075 @item @emph{Syntax}:
9076 @code{RESULT = RRSPACING(X)}
9078 @item @emph{Arguments}:
9079 @multitable @columnfractions .15 .70
9080 @item @var{X} @tab Shall be of type @code{REAL}.
9083 @item @emph{Return value}:
9084 The return value is of the same type and kind as @var{X}.
9085 The value returned is equal to
9086 @code{ABS(FRACTION(X)) * FLOAT(RADIX(X))**DIGITS(X)}.
9088 @item @emph{See also}:
9095 @section @code{RSHIFT} --- Right shift bits
9097 @cindex bits, shift right
9100 @item @emph{Description}:
9101 @code{RSHIFT} returns a value corresponding to @var{I} with all of the
9102 bits shifted right by @var{SHIFT} places. If the absolute value of
9103 @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the value is undefined.
9104 Bits shifted out from the left end are lost; zeros are shifted in from
9107 This function has been superseded by the @code{ISHFT} intrinsic, which
9108 is standard in Fortran 95 and later.
9110 @item @emph{Standard}:
9116 @item @emph{Syntax}:
9117 @code{RESULT = RSHIFT(I, SHIFT)}
9119 @item @emph{Arguments}:
9120 @multitable @columnfractions .15 .70
9121 @item @var{I} @tab The type shall be @code{INTEGER}.
9122 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
9125 @item @emph{Return value}:
9126 The return value is of type @code{INTEGER} and of the same kind as
9129 @item @emph{See also}:
9130 @ref{ISHFT}, @ref{ISHFTC}, @ref{LSHIFT}
9137 @section @code{SCALE} --- Scale a real value
9139 @cindex real number, scale
9140 @cindex floating point, scale
9143 @item @emph{Description}:
9144 @code{SCALE(X,I)} returns @code{X * RADIX(X)**I}.
9146 @item @emph{Standard}:
9147 Fortran 95 and later
9152 @item @emph{Syntax}:
9153 @code{RESULT = SCALE(X, I)}
9155 @item @emph{Arguments}:
9156 @multitable @columnfractions .15 .70
9157 @item @var{X} @tab The type of the argument shall be a @code{REAL}.
9158 @item @var{I} @tab The type of the argument shall be a @code{INTEGER}.
9161 @item @emph{Return value}:
9162 The return value is of the same type and kind as @var{X}.
9163 Its value is @code{X * RADIX(X)**I}.
9165 @item @emph{Example}:
9168 real :: x = 178.1387e-4
9170 print *, scale(x,i), x*radix(x)**i
9171 end program test_scale
9179 @section @code{SCAN} --- Scan a string for the presence of a set of characters
9181 @cindex string, find subset
9184 @item @emph{Description}:
9185 Scans a @var{STRING} for any of the characters in a @var{SET}
9188 If @var{BACK} is either absent or equals @code{FALSE}, this function
9189 returns the position of the leftmost character of @var{STRING} that is
9190 in @var{SET}. If @var{BACK} equals @code{TRUE}, the rightmost position
9191 is returned. If no character of @var{SET} is found in @var{STRING}, the
9194 @item @emph{Standard}:
9195 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
9200 @item @emph{Syntax}:
9201 @code{RESULT = SCAN(STRING, SET[, BACK [, KIND]])}
9203 @item @emph{Arguments}:
9204 @multitable @columnfractions .15 .70
9205 @item @var{STRING} @tab Shall be of type @code{CHARACTER}.
9206 @item @var{SET} @tab Shall be of type @code{CHARACTER}.
9207 @item @var{BACK} @tab (Optional) shall be of type @code{LOGICAL}.
9208 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
9209 expression indicating the kind parameter of
9213 @item @emph{Return value}:
9214 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
9215 @var{KIND} is absent, the return value is of default integer kind.
9217 @item @emph{Example}:
9220 WRITE(*,*) SCAN("FORTRAN", "AO") ! 2, found 'O'
9221 WRITE(*,*) SCAN("FORTRAN", "AO", .TRUE.) ! 6, found 'A'
9222 WRITE(*,*) SCAN("FORTRAN", "C++") ! 0, found none
9226 @item @emph{See also}:
9227 @ref{INDEX intrinsic}, @ref{VERIFY}
9233 @section @code{SECNDS} --- Time function
9235 @cindex time, elapsed
9236 @cindex elapsed time
9239 @item @emph{Description}:
9240 @code{SECNDS(X)} gets the time in seconds from the real-time system clock.
9241 @var{X} is a reference time, also in seconds. If this is zero, the time in
9242 seconds from midnight is returned. This function is non-standard and its
9245 @item @emph{Standard}:
9251 @item @emph{Syntax}:
9252 @code{RESULT = SECNDS (X)}
9254 @item @emph{Arguments}:
9255 @multitable @columnfractions .15 .70
9256 @item @var{T} @tab Shall be of type @code{REAL(4)}.
9257 @item @var{X} @tab Shall be of type @code{REAL(4)}.
9260 @item @emph{Return value}:
9263 @item @emph{Example}:
9268 print *, secnds (0.0) ! seconds since midnight
9269 t1 = secnds (0.0) ! reference time
9270 do i = 1, 10000000 ! do something
9272 t2 = secnds (t1) ! elapsed time
9273 print *, "Something took ", t2, " seconds."
9274 end program test_secnds
9281 @section @code{SECOND} --- CPU time function
9283 @cindex time, elapsed
9284 @cindex elapsed time
9287 @item @emph{Description}:
9288 Returns a @code{REAL(4)} value representing the elapsed CPU time in
9289 seconds. This provides the same functionality as the standard
9290 @code{CPU_TIME} intrinsic, and is only included for backwards
9293 This intrinsic is provided in both subroutine and function forms;
9294 however, only one form can be used in any given program unit.
9296 @item @emph{Standard}:
9300 Subroutine, function
9302 @item @emph{Syntax}:
9303 @multitable @columnfractions .80
9304 @item @code{CALL SECOND(TIME)}
9305 @item @code{TIME = SECOND()}
9308 @item @emph{Arguments}:
9309 @multitable @columnfractions .15 .70
9310 @item @var{TIME} @tab Shall be of type @code{REAL(4)}.
9313 @item @emph{Return value}:
9314 In either syntax, @var{TIME} is set to the process's current runtime in
9317 @item @emph{See also}:
9324 @node SELECTED_CHAR_KIND
9325 @section @code{SELECTED_CHAR_KIND} --- Choose character kind
9326 @fnindex SELECTED_CHAR_KIND
9327 @cindex character kind
9328 @cindex kind, character
9331 @item @emph{Description}:
9333 @code{SELECTED_CHAR_KIND(NAME)} returns the kind value for the character
9334 set named @var{NAME}, if a character set with such a name is supported,
9335 or @math{-1} otherwise. Currently, supported character sets include
9336 ``ASCII'' and ``DEFAULT'', which are equivalent.
9338 @item @emph{Standard}:
9339 Fortran 2003 and later
9342 Transformational function
9344 @item @emph{Syntax}:
9345 @code{RESULT = SELECTED_CHAR_KIND(NAME)}
9347 @item @emph{Arguments}:
9348 @multitable @columnfractions .15 .70
9349 @item @var{NAME} @tab Shall be a scalar and of the default character type.
9352 @item @emph{Example}:
9355 integer,parameter :: ascii = selected_char_kind("ascii")
9356 character(kind=ascii, len=26) :: s
9358 s = ascii_"abcdefghijklmnopqrstuvwxyz"
9360 end program ascii_kind
9366 @node SELECTED_INT_KIND
9367 @section @code{SELECTED_INT_KIND} --- Choose integer kind
9368 @fnindex SELECTED_INT_KIND
9369 @cindex integer kind
9370 @cindex kind, integer
9373 @item @emph{Description}:
9374 @code{SELECTED_INT_KIND(I)} return the kind value of the smallest integer
9375 type that can represent all values ranging from @math{-10^I} (exclusive)
9376 to @math{10^I} (exclusive). If there is no integer kind that accommodates
9377 this range, @code{SELECTED_INT_KIND} returns @math{-1}.
9379 @item @emph{Standard}:
9380 Fortran 95 and later
9383 Transformational function
9385 @item @emph{Syntax}:
9386 @code{RESULT = SELECTED_INT_KIND(I)}
9388 @item @emph{Arguments}:
9389 @multitable @columnfractions .15 .70
9390 @item @var{I} @tab Shall be a scalar and of type @code{INTEGER}.
9393 @item @emph{Example}:
9395 program large_integers
9396 integer,parameter :: k5 = selected_int_kind(5)
9397 integer,parameter :: k15 = selected_int_kind(15)
9398 integer(kind=k5) :: i5
9399 integer(kind=k15) :: i15
9401 print *, huge(i5), huge(i15)
9403 ! The following inequalities are always true
9404 print *, huge(i5) >= 10_k5**5-1
9405 print *, huge(i15) >= 10_k15**15-1
9406 end program large_integers
9412 @node SELECTED_REAL_KIND
9413 @section @code{SELECTED_REAL_KIND} --- Choose real kind
9414 @fnindex SELECTED_REAL_KIND
9419 @item @emph{Description}:
9420 @code{SELECTED_REAL_KIND(P,R)} return the kind value of a real data type
9421 with decimal precision greater of at least @code{P} digits and exponent
9422 range greater at least @code{R}.
9424 @item @emph{Standard}:
9425 Fortran 95 and later
9428 Transformational function
9430 @item @emph{Syntax}:
9431 @code{RESULT = SELECTED_REAL_KIND(P, R)}
9433 @item @emph{Arguments}:
9434 @multitable @columnfractions .15 .70
9435 @item @var{P} @tab (Optional) shall be a scalar and of type @code{INTEGER}.
9436 @item @var{R} @tab (Optional) shall be a scalar and of type @code{INTEGER}.
9438 At least one argument shall be present.
9440 @item @emph{Return value}:
9442 @code{SELECTED_REAL_KIND} returns the value of the kind type parameter of
9443 a real data type with decimal precision of at least @code{P} digits and a
9444 decimal exponent range of at least @code{R}. If more than one real data
9445 type meet the criteria, the kind of the data type with the smallest
9446 decimal precision is returned. If no real data type matches the criteria,
9449 @item -1 if the processor does not support a real data type with a
9450 precision greater than or equal to @code{P}
9451 @item -2 if the processor does not support a real type with an exponent
9452 range greater than or equal to @code{R}
9453 @item -3 if neither is supported.
9456 @item @emph{Example}:
9459 integer,parameter :: p6 = selected_real_kind(6)
9460 integer,parameter :: p10r100 = selected_real_kind(10,100)
9461 integer,parameter :: r400 = selected_real_kind(r=400)
9463 real(kind=p10r100) :: y
9464 real(kind=r400) :: z
9466 print *, precision(x), range(x)
9467 print *, precision(y), range(y)
9468 print *, precision(z), range(z)
9469 end program real_kinds
9476 @section @code{SET_EXPONENT} --- Set the exponent of the model
9477 @fnindex SET_EXPONENT
9478 @cindex real number, set exponent
9479 @cindex floating point, set exponent
9482 @item @emph{Description}:
9483 @code{SET_EXPONENT(X, I)} returns the real number whose fractional part
9484 is that that of @var{X} and whose exponent part is @var{I}.
9486 @item @emph{Standard}:
9487 Fortran 95 and later
9492 @item @emph{Syntax}:
9493 @code{RESULT = SET_EXPONENT(X, I)}
9495 @item @emph{Arguments}:
9496 @multitable @columnfractions .15 .70
9497 @item @var{X} @tab Shall be of type @code{REAL}.
9498 @item @var{I} @tab Shall be of type @code{INTEGER}.
9501 @item @emph{Return value}:
9502 The return value is of the same type and kind as @var{X}.
9503 The real number whose fractional part
9504 is that that of @var{X} and whose exponent part if @var{I} is returned;
9505 it is @code{FRACTION(X) * RADIX(X)**I}.
9507 @item @emph{Example}:
9510 REAL :: x = 178.1387e-4
9512 PRINT *, SET_EXPONENT(x, i), FRACTION(x) * RADIX(x)**i
9521 @section @code{SHAPE} --- Determine the shape of an array
9523 @cindex array, shape
9526 @item @emph{Description}:
9527 Determines the shape of an array.
9529 @item @emph{Standard}:
9530 Fortran 95 and later
9535 @item @emph{Syntax}:
9536 @code{RESULT = SHAPE(SOURCE)}
9538 @item @emph{Arguments}:
9539 @multitable @columnfractions .15 .70
9540 @item @var{SOURCE} @tab Shall be an array or scalar of any type.
9541 If @var{SOURCE} is a pointer it must be associated and allocatable
9542 arrays must be allocated.
9545 @item @emph{Return value}:
9546 An @code{INTEGER} array of rank one with as many elements as @var{SOURCE}
9547 has dimensions. The elements of the resulting array correspond to the extend
9548 of @var{SOURCE} along the respective dimensions. If @var{SOURCE} is a scalar,
9549 the result is the rank one array of size zero.
9551 @item @emph{Example}:
9554 INTEGER, DIMENSION(-1:1, -1:2) :: A
9555 WRITE(*,*) SHAPE(A) ! (/ 3, 4 /)
9556 WRITE(*,*) SIZE(SHAPE(42)) ! (/ /)
9560 @item @emph{See also}:
9561 @ref{RESHAPE}, @ref{SIZE}
9567 @section @code{SIGN} --- Sign copying function
9571 @cindex sign copying
9574 @item @emph{Description}:
9575 @code{SIGN(A,B)} returns the value of @var{A} with the sign of @var{B}.
9577 @item @emph{Standard}:
9578 Fortran 77 and later
9583 @item @emph{Syntax}:
9584 @code{RESULT = SIGN(A, B)}
9586 @item @emph{Arguments}:
9587 @multitable @columnfractions .15 .70
9588 @item @var{A} @tab Shall be of type @code{INTEGER} or @code{REAL}
9589 @item @var{B} @tab Shall be of the same type and kind as @var{A}
9592 @item @emph{Return value}:
9593 The kind of the return value is that of @var{A} and @var{B}.
9594 If @math{B\ge 0} then the result is @code{ABS(A)}, else
9595 it is @code{-ABS(A)}.
9597 @item @emph{Example}:
9600 print *, sign(-12,1)
9601 print *, sign(-12,0)
9602 print *, sign(-12,-1)
9604 print *, sign(-12.,1.)
9605 print *, sign(-12.,0.)
9606 print *, sign(-12.,-1.)
9607 end program test_sign
9610 @item @emph{Specific names}:
9611 @multitable @columnfractions .20 .20 .20 .25
9612 @item Name @tab Arguments @tab Return type @tab Standard
9613 @item @code{ISIGN(A,P)} @tab @code{INTEGER(4)} @tab @code{INTEGER(4)} @tab f95, gnu
9614 @item @code{DSIGN(A,P)} @tab @code{REAL(8)} @tab @code{REAL(8)} @tab f95, gnu
9621 @section @code{SIGNAL} --- Signal handling subroutine (or function)
9623 @cindex system, signal handling
9626 @item @emph{Description}:
9627 @code{SIGNAL(NUMBER, HANDLER [, STATUS])} causes external subroutine
9628 @var{HANDLER} to be executed with a single integer argument when signal
9629 @var{NUMBER} occurs. If @var{HANDLER} is an integer, it can be used to
9630 turn off handling of signal @var{NUMBER} or revert to its default
9631 action. See @code{signal(2)}.
9633 If @code{SIGNAL} is called as a subroutine and the @var{STATUS} argument
9634 is supplied, it is set to the value returned by @code{signal(2)}.
9636 @item @emph{Standard}:
9640 Subroutine, function
9642 @item @emph{Syntax}:
9643 @multitable @columnfractions .80
9644 @item @code{CALL SIGNAL(NUMBER, HANDLER [, STATUS])}
9645 @item @code{STATUS = SIGNAL(NUMBER, HANDLER)}
9648 @item @emph{Arguments}:
9649 @multitable @columnfractions .15 .70
9650 @item @var{NUMBER} @tab Shall be a scalar integer, with @code{INTENT(IN)}
9651 @item @var{HANDLER}@tab Signal handler (@code{INTEGER FUNCTION} or
9652 @code{SUBROUTINE}) or dummy/global @code{INTEGER} scalar.
9653 @code{INTEGER}. It is @code{INTENT(IN)}.
9654 @item @var{STATUS} @tab (Optional) @var{STATUS} shall be a scalar
9655 integer. It has @code{INTENT(OUT)}.
9658 @item @emph{Return value}:
9659 The @code{SIGNAL} function returns the value returned by @code{signal(2)}.
9661 @item @emph{Example}:
9665 external handler_print
9667 call signal (12, handler_print)
9671 end program test_signal
9678 @section @code{SIN} --- Sine function
9684 @cindex trigonometric function, sine
9688 @item @emph{Description}:
9689 @code{SIN(X)} computes the sine of @var{X}.
9691 @item @emph{Standard}:
9692 Fortran 77 and later
9697 @item @emph{Syntax}:
9698 @code{RESULT = SIN(X)}
9700 @item @emph{Arguments}:
9701 @multitable @columnfractions .15 .70
9702 @item @var{X} @tab The type shall be @code{REAL} or
9706 @item @emph{Return value}:
9707 The return value has same type and kind as @var{X}.
9709 @item @emph{Example}:
9714 end program test_sin
9717 @item @emph{Specific names}:
9718 @multitable @columnfractions .20 .20 .20 .25
9719 @item Name @tab Argument @tab Return type @tab Standard
9720 @item @code{DSIN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab f95, gnu
9721 @item @code{CSIN(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab f95, gnu
9722 @item @code{ZSIN(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
9723 @item @code{CDSIN(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
9726 @item @emph{See also}:
9733 @section @code{SINH} --- Hyperbolic sine function
9736 @cindex hyperbolic sine
9737 @cindex hyperbolic function, sine
9738 @cindex sine, hyperbolic
9741 @item @emph{Description}:
9742 @code{SINH(X)} computes the hyperbolic sine of @var{X}.
9744 @item @emph{Standard}:
9745 Fortran 95 and later
9750 @item @emph{Syntax}:
9751 @code{RESULT = SINH(X)}
9753 @item @emph{Arguments}:
9754 @multitable @columnfractions .15 .70
9755 @item @var{X} @tab The type shall be @code{REAL}.
9758 @item @emph{Return value}:
9759 The return value is of type @code{REAL}.
9761 @item @emph{Example}:
9764 real(8) :: x = - 1.0_8
9766 end program test_sinh
9769 @item @emph{Specific names}:
9770 @multitable @columnfractions .20 .20 .20 .25
9771 @item Name @tab Argument @tab Return type @tab Standard
9772 @item @code{DSINH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 95 and later
9775 @item @emph{See also}:
9782 @section @code{SIZE} --- Determine the size of an array
9785 @cindex array, number of elements
9786 @cindex array, count elements
9789 @item @emph{Description}:
9790 Determine the extent of @var{ARRAY} along a specified dimension @var{DIM},
9791 or the total number of elements in @var{ARRAY} if @var{DIM} is absent.
9793 @item @emph{Standard}:
9794 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
9799 @item @emph{Syntax}:
9800 @code{RESULT = SIZE(ARRAY[, DIM [, KIND]])}
9802 @item @emph{Arguments}:
9803 @multitable @columnfractions .15 .70
9804 @item @var{ARRAY} @tab Shall be an array of any type. If @var{ARRAY} is
9805 a pointer it must be associated and allocatable arrays must be allocated.
9806 @item @var{DIM} @tab (Optional) shall be a scalar of type @code{INTEGER}
9807 and its value shall be in the range from 1 to n, where n equals the rank
9809 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
9810 expression indicating the kind parameter of
9814 @item @emph{Return value}:
9815 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
9816 @var{KIND} is absent, the return value is of default integer kind.
9818 @item @emph{Example}:
9821 WRITE(*,*) SIZE((/ 1, 2 /)) ! 2
9825 @item @emph{See also}:
9826 @ref{SHAPE}, @ref{RESHAPE}
9831 @section @code{SIZEOF} --- Size in bytes of an expression
9833 @cindex expression size
9834 @cindex size of an expression
9837 @item @emph{Description}:
9838 @code{SIZEOF(X)} calculates the number of bytes of storage the
9839 expression @code{X} occupies.
9841 @item @emph{Standard}:
9847 @item @emph{Syntax}:
9848 @code{N = SIZEOF(X)}
9850 @item @emph{Arguments}:
9851 @multitable @columnfractions .15 .70
9852 @item @var{X} @tab The argument shall be of any type, rank or shape.
9855 @item @emph{Return value}:
9856 The return value is of type integer and of the system-dependent kind
9857 @var{C_SIZE_T} (from the @var{ISO_C_BINDING} module). Its value is the
9858 number of bytes occupied by the argument. If the argument has the
9859 @code{POINTER} attribute, the number of bytes of the storage area pointed
9860 to is returned. If the argument is of a derived type with @code{POINTER}
9861 or @code{ALLOCATABLE} components, the return value doesn't account for
9862 the sizes of the data pointed to by these components.
9864 @item @emph{Example}:
9868 print *, (sizeof(s)/sizeof(r) == 5)
9871 The example will print @code{.TRUE.} unless you are using a platform
9872 where default @code{REAL} variables are unusually padded.
9876 @section @code{SLEEP} --- Sleep for the specified number of seconds
9878 @cindex delayed execution
9881 @item @emph{Description}:
9882 Calling this subroutine causes the process to pause for @var{SECONDS} seconds.
9884 @item @emph{Standard}:
9890 @item @emph{Syntax}:
9891 @code{CALL SLEEP(SECONDS)}
9893 @item @emph{Arguments}:
9894 @multitable @columnfractions .15 .70
9895 @item @var{SECONDS} @tab The type shall be of default @code{INTEGER}.
9898 @item @emph{Example}:
9909 @section @code{SNGL} --- Convert double precision real to default real
9911 @cindex conversion, to real
9914 @item @emph{Description}:
9915 @code{SNGL(A)} converts the double precision real @var{A}
9916 to a default real value. This is an archaic form of @code{REAL}
9917 that is specific to one type for @var{A}.
9919 @item @emph{Standard}:
9920 Fortran 77 and later
9925 @item @emph{Syntax}:
9926 @code{RESULT = SNGL(A)}
9928 @item @emph{Arguments}:
9929 @multitable @columnfractions .15 .70
9930 @item @var{A} @tab The type shall be a double precision @code{REAL}.
9933 @item @emph{Return value}:
9934 The return value is of type default @code{REAL}.
9936 @item @emph{See also}:
9943 @section @code{SPACING} --- Smallest distance between two numbers of a given type
9945 @cindex real number, relative spacing
9946 @cindex floating point, relative spacing
9949 @item @emph{Description}:
9950 Determines the distance between the argument @var{X} and the nearest
9951 adjacent number of the same type.
9953 @item @emph{Standard}:
9954 Fortran 95 and later
9959 @item @emph{Syntax}:
9960 @code{RESULT = SPACING(X)}
9962 @item @emph{Arguments}:
9963 @multitable @columnfractions .15 .70
9964 @item @var{X} @tab Shall be of type @code{REAL}.
9967 @item @emph{Return value}:
9968 The result is of the same type as the input argument @var{X}.
9970 @item @emph{Example}:
9972 PROGRAM test_spacing
9973 INTEGER, PARAMETER :: SGL = SELECTED_REAL_KIND(p=6, r=37)
9974 INTEGER, PARAMETER :: DBL = SELECTED_REAL_KIND(p=13, r=200)
9976 WRITE(*,*) spacing(1.0_SGL) ! "1.1920929E-07" on i686
9977 WRITE(*,*) spacing(1.0_DBL) ! "2.220446049250313E-016" on i686
9981 @item @emph{See also}:
9988 @section @code{SPREAD} --- Add a dimension to an array
9990 @cindex array, increase dimension
9991 @cindex array, duplicate elements
9992 @cindex array, duplicate dimensions
9995 @item @emph{Description}:
9996 Replicates a @var{SOURCE} array @var{NCOPIES} times along a specified
9997 dimension @var{DIM}.
9999 @item @emph{Standard}:
10000 Fortran 95 and later
10002 @item @emph{Class}:
10003 Transformational function
10005 @item @emph{Syntax}:
10006 @code{RESULT = SPREAD(SOURCE, DIM, NCOPIES)}
10008 @item @emph{Arguments}:
10009 @multitable @columnfractions .15 .70
10010 @item @var{SOURCE} @tab Shall be a scalar or an array of any type and
10011 a rank less than seven.
10012 @item @var{DIM} @tab Shall be a scalar of type @code{INTEGER} with a
10013 value in the range from 1 to n+1, where n equals the rank of @var{SOURCE}.
10014 @item @var{NCOPIES} @tab Shall be a scalar of type @code{INTEGER}.
10017 @item @emph{Return value}:
10018 The result is an array of the same type as @var{SOURCE} and has rank n+1
10019 where n equals the rank of @var{SOURCE}.
10021 @item @emph{Example}:
10023 PROGRAM test_spread
10024 INTEGER :: a = 1, b(2) = (/ 1, 2 /)
10025 WRITE(*,*) SPREAD(A, 1, 2) ! "1 1"
10026 WRITE(*,*) SPREAD(B, 1, 2) ! "1 1 2 2"
10030 @item @emph{See also}:
10037 @section @code{SQRT} --- Square-root function
10044 @cindex square-root
10047 @item @emph{Description}:
10048 @code{SQRT(X)} computes the square root of @var{X}.
10050 @item @emph{Standard}:
10051 Fortran 77 and later
10053 @item @emph{Class}:
10056 @item @emph{Syntax}:
10057 @code{RESULT = SQRT(X)}
10059 @item @emph{Arguments}:
10060 @multitable @columnfractions .15 .70
10061 @item @var{X} @tab The type shall be @code{REAL} or
10065 @item @emph{Return value}:
10066 The return value is of type @code{REAL} or @code{COMPLEX}.
10067 The kind type parameter is the same as @var{X}.
10069 @item @emph{Example}:
10072 real(8) :: x = 2.0_8
10073 complex :: z = (1.0, 2.0)
10076 end program test_sqrt
10079 @item @emph{Specific names}:
10080 @multitable @columnfractions .20 .20 .20 .25
10081 @item Name @tab Argument @tab Return type @tab Standard
10082 @item @code{DSQRT(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 95 and later
10083 @item @code{CSQRT(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab Fortran 95 and later
10084 @item @code{ZSQRT(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
10085 @item @code{CDSQRT(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
10092 @section @code{SRAND} --- Reinitialize the random number generator
10094 @cindex random number generation, seeding
10095 @cindex seeding a random number generator
10098 @item @emph{Description}:
10099 @code{SRAND} reinitializes the pseudo-random number generator
10100 called by @code{RAND} and @code{IRAND}. The new seed used by the
10101 generator is specified by the required argument @var{SEED}.
10103 @item @emph{Standard}:
10106 @item @emph{Class}:
10109 @item @emph{Syntax}:
10110 @code{CALL SRAND(SEED)}
10112 @item @emph{Arguments}:
10113 @multitable @columnfractions .15 .70
10114 @item @var{SEED} @tab Shall be a scalar @code{INTEGER(kind=4)}.
10117 @item @emph{Return value}:
10120 @item @emph{Example}:
10121 See @code{RAND} and @code{IRAND} for examples.
10123 @item @emph{Notes}:
10124 The Fortran 2003 standard specifies the intrinsic @code{RANDOM_SEED} to
10125 initialize the pseudo-random numbers generator and @code{RANDOM_NUMBER}
10126 to generate pseudo-random numbers. Please note that in
10127 GNU Fortran, these two sets of intrinsics (@code{RAND},
10128 @code{IRAND} and @code{SRAND} on the one hand, @code{RANDOM_NUMBER} and
10129 @code{RANDOM_SEED} on the other hand) access two independent
10130 pseudo-random number generators.
10132 @item @emph{See also}:
10133 @ref{RAND}, @ref{RANDOM_SEED}, @ref{RANDOM_NUMBER}
10140 @section @code{STAT} --- Get file status
10142 @cindex file system, file status
10145 @item @emph{Description}:
10146 This function returns information about a file. No permissions are required on
10147 the file itself, but execute (search) permission is required on all of the
10148 directories in path that lead to the file.
10150 The elements that are obtained and stored in the array @code{BUFF}:
10151 @multitable @columnfractions .15 .70
10152 @item @code{buff(1)} @tab Device ID
10153 @item @code{buff(2)} @tab Inode number
10154 @item @code{buff(3)} @tab File mode
10155 @item @code{buff(4)} @tab Number of links
10156 @item @code{buff(5)} @tab Owner's uid
10157 @item @code{buff(6)} @tab Owner's gid
10158 @item @code{buff(7)} @tab ID of device containing directory entry for file (0 if not available)
10159 @item @code{buff(8)} @tab File size (bytes)
10160 @item @code{buff(9)} @tab Last access time
10161 @item @code{buff(10)} @tab Last modification time
10162 @item @code{buff(11)} @tab Last file status change time
10163 @item @code{buff(12)} @tab Preferred I/O block size (-1 if not available)
10164 @item @code{buff(13)} @tab Number of blocks allocated (-1 if not available)
10167 Not all these elements are relevant on all systems.
10168 If an element is not relevant, it is returned as 0.
10170 This intrinsic is provided in both subroutine and function forms; however,
10171 only one form can be used in any given program unit.
10173 @item @emph{Standard}:
10176 @item @emph{Class}:
10177 Subroutine, function
10179 @item @emph{Syntax}:
10180 @code{CALL STAT(FILE,BUFF[,STATUS])}
10182 @item @emph{Arguments}:
10183 @multitable @columnfractions .15 .70
10184 @item @var{FILE} @tab The type shall be @code{CHARACTER}, of the
10185 default kind and a valid path within the file system.
10186 @item @var{BUFF} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
10187 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}. Returns 0
10188 on success and a system specific error code otherwise.
10191 @item @emph{Example}:
10194 INTEGER, DIMENSION(13) :: buff
10197 CALL STAT("/etc/passwd", buff, status)
10199 IF (status == 0) THEN
10200 WRITE (*, FMT="('Device ID:', T30, I19)") buff(1)
10201 WRITE (*, FMT="('Inode number:', T30, I19)") buff(2)
10202 WRITE (*, FMT="('File mode (octal):', T30, O19)") buff(3)
10203 WRITE (*, FMT="('Number of links:', T30, I19)") buff(4)
10204 WRITE (*, FMT="('Owner''s uid:', T30, I19)") buff(5)
10205 WRITE (*, FMT="('Owner''s gid:', T30, I19)") buff(6)
10206 WRITE (*, FMT="('Device where located:', T30, I19)") buff(7)
10207 WRITE (*, FMT="('File size:', T30, I19)") buff(8)
10208 WRITE (*, FMT="('Last access time:', T30, A19)") CTIME(buff(9))
10209 WRITE (*, FMT="('Last modification time', T30, A19)") CTIME(buff(10))
10210 WRITE (*, FMT="('Last status change time:', T30, A19)") CTIME(buff(11))
10211 WRITE (*, FMT="('Preferred block size:', T30, I19)") buff(12)
10212 WRITE (*, FMT="('No. of blocks allocated:', T30, I19)") buff(13)
10217 @item @emph{See also}:
10218 To stat an open file: @ref{FSTAT}, to stat a link: @ref{LSTAT}
10224 @section @code{SUM} --- Sum of array elements
10227 @cindex array, add elements
10228 @cindex array, conditionally add elements
10229 @cindex sum array elements
10232 @item @emph{Description}:
10233 Adds the elements of @var{ARRAY} along dimension @var{DIM} if
10234 the corresponding element in @var{MASK} is @code{TRUE}.
10236 @item @emph{Standard}:
10237 Fortran 95 and later
10239 @item @emph{Class}:
10240 Transformational function
10242 @item @emph{Syntax}:
10243 @code{RESULT = SUM(ARRAY[, MASK])}
10244 @code{RESULT = SUM(ARRAY, DIM[, MASK])}
10246 @item @emph{Arguments}:
10247 @multitable @columnfractions .15 .70
10248 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER},
10249 @code{REAL} or @code{COMPLEX}.
10250 @item @var{DIM} @tab (Optional) shall be a scalar of type
10251 @code{INTEGER} with a value in the range from 1 to n, where n
10252 equals the rank of @var{ARRAY}.
10253 @item @var{MASK} @tab (Optional) shall be of type @code{LOGICAL}
10254 and either be a scalar or an array of the same shape as @var{ARRAY}.
10257 @item @emph{Return value}:
10258 The result is of the same type as @var{ARRAY}.
10260 If @var{DIM} is absent, a scalar with the sum of all elements in @var{ARRAY}
10261 is returned. Otherwise, an array of rank n-1, where n equals the rank of
10262 @var{ARRAY},and a shape similar to that of @var{ARRAY} with dimension @var{DIM}
10263 dropped is returned.
10265 @item @emph{Example}:
10268 INTEGER :: x(5) = (/ 1, 2, 3, 4 ,5 /)
10269 print *, SUM(x) ! all elements, sum = 15
10270 print *, SUM(x, MASK=MOD(x, 2)==1) ! odd elements, sum = 9
10274 @item @emph{See also}:
10281 @section @code{SYMLNK} --- Create a symbolic link
10283 @cindex file system, create link
10284 @cindex file system, soft link
10287 @item @emph{Description}:
10288 Makes a symbolic link from file @var{PATH1} to @var{PATH2}. A null
10289 character (@code{CHAR(0)}) can be used to mark the end of the names in
10290 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
10291 names are ignored. If the @var{STATUS} argument is supplied, it
10292 contains 0 on success or a nonzero error code upon return; see
10293 @code{symlink(2)}. If the system does not supply @code{symlink(2)},
10294 @code{ENOSYS} is returned.
10296 This intrinsic is provided in both subroutine and function forms;
10297 however, only one form can be used in any given program unit.
10299 @item @emph{Standard}:
10302 @item @emph{Class}:
10303 Subroutine, function
10305 @item @emph{Syntax}:
10306 @multitable @columnfractions .80
10307 @item @code{CALL SYMLNK(PATH1, PATH2 [, STATUS])}
10308 @item @code{STATUS = SYMLNK(PATH1, PATH2)}
10311 @item @emph{Arguments}:
10312 @multitable @columnfractions .15 .70
10313 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
10314 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
10315 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
10318 @item @emph{See also}:
10319 @ref{LINK}, @ref{UNLINK}
10326 @section @code{SYSTEM} --- Execute a shell command
10328 @cindex system, system call
10331 @item @emph{Description}:
10332 Passes the command @var{COMMAND} to a shell (see @code{system(3)}). If
10333 argument @var{STATUS} is present, it contains the value returned by
10334 @code{system(3)}, which is presumably 0 if the shell command succeeded.
10335 Note that which shell is used to invoke the command is system-dependent
10336 and environment-dependent.
10338 This intrinsic is provided in both subroutine and function forms;
10339 however, only one form can be used in any given program unit.
10341 @item @emph{Standard}:
10344 @item @emph{Class}:
10345 Subroutine, function
10347 @item @emph{Syntax}:
10348 @multitable @columnfractions .80
10349 @item @code{CALL SYSTEM(COMMAND [, STATUS])}
10350 @item @code{STATUS = SYSTEM(COMMAND)}
10353 @item @emph{Arguments}:
10354 @multitable @columnfractions .15 .70
10355 @item @var{COMMAND} @tab Shall be of default @code{CHARACTER} type.
10356 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
10359 @item @emph{See also}:
10365 @section @code{SYSTEM_CLOCK} --- Time function
10366 @fnindex SYSTEM_CLOCK
10367 @cindex time, clock ticks
10368 @cindex clock ticks
10371 @item @emph{Description}:
10372 Determines the @var{COUNT} of milliseconds of wall clock time since
10373 the Epoch (00:00:00 UTC, January 1, 1970) modulo @var{COUNT_MAX},
10374 @var{COUNT_RATE} determines the number of clock ticks per second.
10375 @var{COUNT_RATE} and @var{COUNT_MAX} are constant and specific to
10376 @command{gfortran}.
10378 If there is no clock, @var{COUNT} is set to @code{-HUGE(COUNT)}, and
10379 @var{COUNT_RATE} and @var{COUNT_MAX} are set to zero
10381 @item @emph{Standard}:
10382 Fortran 95 and later
10384 @item @emph{Class}:
10387 @item @emph{Syntax}:
10388 @code{CALL SYSTEM_CLOCK([COUNT, COUNT_RATE, COUNT_MAX])}
10390 @item @emph{Arguments}:
10391 @item @emph{Arguments}:
10392 @multitable @columnfractions .15 .70
10393 @item @var{COUNT} @tab (Optional) shall be a scalar of type default
10394 @code{INTEGER} with @code{INTENT(OUT)}.
10395 @item @var{COUNT_RATE} @tab (Optional) shall be a scalar of type default
10396 @code{INTEGER} with @code{INTENT(OUT)}.
10397 @item @var{COUNT_MAX} @tab (Optional) shall be a scalar of type default
10398 @code{INTEGER} with @code{INTENT(OUT)}.
10401 @item @emph{Example}:
10403 PROGRAM test_system_clock
10404 INTEGER :: count, count_rate, count_max
10405 CALL SYSTEM_CLOCK(count, count_rate, count_max)
10406 WRITE(*,*) count, count_rate, count_max
10410 @item @emph{See also}:
10411 @ref{DATE_AND_TIME}, @ref{CPU_TIME}
10417 @section @code{TAN} --- Tangent function
10420 @cindex trigonometric function, tangent
10424 @item @emph{Description}:
10425 @code{TAN(X)} computes the tangent of @var{X}.
10427 @item @emph{Standard}:
10428 Fortran 77 and later
10430 @item @emph{Class}:
10433 @item @emph{Syntax}:
10434 @code{RESULT = TAN(X)}
10436 @item @emph{Arguments}:
10437 @multitable @columnfractions .15 .70
10438 @item @var{X} @tab The type shall be @code{REAL}.
10441 @item @emph{Return value}:
10442 The return value is of type @code{REAL}. The kind type parameter is
10443 the same as @var{X}.
10445 @item @emph{Example}:
10448 real(8) :: x = 0.165_8
10450 end program test_tan
10453 @item @emph{Specific names}:
10454 @multitable @columnfractions .20 .20 .20 .25
10455 @item Name @tab Argument @tab Return type @tab Standard
10456 @item @code{DTAN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 95 and later
10459 @item @emph{See also}:
10466 @section @code{TANH} --- Hyperbolic tangent function
10469 @cindex hyperbolic tangent
10470 @cindex hyperbolic function, tangent
10471 @cindex tangent, hyperbolic
10474 @item @emph{Description}:
10475 @code{TANH(X)} computes the hyperbolic tangent of @var{X}.
10477 @item @emph{Standard}:
10478 Fortran 77 and later
10480 @item @emph{Class}:
10483 @item @emph{Syntax}:
10486 @item @emph{Arguments}:
10487 @multitable @columnfractions .15 .70
10488 @item @var{X} @tab The type shall be @code{REAL}.
10491 @item @emph{Return value}:
10492 The return value is of type @code{REAL} and lies in the range
10493 @math{ - 1 \leq tanh(x) \leq 1 }.
10495 @item @emph{Example}:
10498 real(8) :: x = 2.1_8
10500 end program test_tanh
10503 @item @emph{Specific names}:
10504 @multitable @columnfractions .20 .20 .20 .25
10505 @item Name @tab Argument @tab Return type @tab Standard
10506 @item @code{DTANH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 95 and later
10509 @item @emph{See also}:
10516 @section @code{TIME} --- Time function
10518 @cindex time, current
10519 @cindex current time
10522 @item @emph{Description}:
10523 Returns the current time encoded as an integer (in the manner of the
10524 UNIX function @code{time(3)}). This value is suitable for passing to
10525 @code{CTIME()}, @code{GMTIME()}, and @code{LTIME()}.
10527 This intrinsic is not fully portable, such as to systems with 32-bit
10528 @code{INTEGER} types but supporting times wider than 32 bits. Therefore,
10529 the values returned by this intrinsic might be, or become, negative, or
10530 numerically less than previous values, during a single run of the
10533 See @ref{TIME8}, for information on a similar intrinsic that might be
10534 portable to more GNU Fortran implementations, though to fewer Fortran
10537 @item @emph{Standard}:
10540 @item @emph{Class}:
10543 @item @emph{Syntax}:
10544 @code{RESULT = TIME()}
10546 @item @emph{Return value}:
10547 The return value is a scalar of type @code{INTEGER(4)}.
10549 @item @emph{See also}:
10550 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK}, @ref{TIME8}
10557 @section @code{TIME8} --- Time function (64-bit)
10559 @cindex time, current
10560 @cindex current time
10563 @item @emph{Description}:
10564 Returns the current time encoded as an integer (in the manner of the
10565 UNIX function @code{time(3)}). This value is suitable for passing to
10566 @code{CTIME()}, @code{GMTIME()}, and @code{LTIME()}.
10568 @emph{Warning:} this intrinsic does not increase the range of the timing
10569 values over that returned by @code{time(3)}. On a system with a 32-bit
10570 @code{time(3)}, @code{TIME8()} will return a 32-bit value, even though
10571 it is converted to a 64-bit @code{INTEGER(8)} value. That means
10572 overflows of the 32-bit value can still occur. Therefore, the values
10573 returned by this intrinsic might be or become negative or numerically
10574 less than previous values during a single run of the compiled program.
10576 @item @emph{Standard}:
10579 @item @emph{Class}:
10582 @item @emph{Syntax}:
10583 @code{RESULT = TIME8()}
10585 @item @emph{Return value}:
10586 The return value is a scalar of type @code{INTEGER(8)}.
10588 @item @emph{See also}:
10589 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK8}, @ref{TIME}
10596 @section @code{TINY} --- Smallest positive number of a real kind
10598 @cindex limits, smallest number
10599 @cindex model representation, smallest number
10602 @item @emph{Description}:
10603 @code{TINY(X)} returns the smallest positive (non zero) number
10604 in the model of the type of @code{X}.
10606 @item @emph{Standard}:
10607 Fortran 95 and later
10609 @item @emph{Class}:
10612 @item @emph{Syntax}:
10613 @code{RESULT = TINY(X)}
10615 @item @emph{Arguments}:
10616 @multitable @columnfractions .15 .70
10617 @item @var{X} @tab Shall be of type @code{REAL}.
10620 @item @emph{Return value}:
10621 The return value is of the same type and kind as @var{X}
10623 @item @emph{Example}:
10624 See @code{HUGE} for an example.
10630 @section @code{TRANSFER} --- Transfer bit patterns
10636 @item @emph{Description}:
10637 Interprets the bitwise representation of @var{SOURCE} in memory as if it
10638 is the representation of a variable or array of the same type and type
10639 parameters as @var{MOLD}.
10641 This is approximately equivalent to the C concept of @emph{casting} one
10644 @item @emph{Standard}:
10645 Fortran 95 and later
10647 @item @emph{Class}:
10648 Transformational function
10650 @item @emph{Syntax}:
10651 @code{RESULT = TRANSFER(SOURCE, MOLD[, SIZE])}
10653 @item @emph{Arguments}:
10654 @multitable @columnfractions .15 .70
10655 @item @var{SOURCE} @tab Shall be a scalar or an array of any type.
10656 @item @var{MOLD} @tab Shall be a scalar or an array of any type.
10657 @item @var{SIZE} @tab (Optional) shall be a scalar of type
10661 @item @emph{Return value}:
10662 The result has the same type as @var{MOLD}, with the bit level
10663 representation of @var{SOURCE}. If @var{SIZE} is present, the result is
10664 a one-dimensional array of length @var{SIZE}. If @var{SIZE} is absent
10665 but @var{MOLD} is an array (of any size or shape), the result is a one-
10666 dimensional array of the minimum length needed to contain the entirety
10667 of the bitwise representation of @var{SOURCE}. If @var{SIZE} is absent
10668 and @var{MOLD} is a scalar, the result is a scalar.
10670 If the bitwise representation of the result is longer than that of
10671 @var{SOURCE}, then the leading bits of the result correspond to those of
10672 @var{SOURCE} and any trailing bits are filled arbitrarily.
10674 When the resulting bit representation does not correspond to a valid
10675 representation of a variable of the same type as @var{MOLD}, the results
10676 are undefined, and subsequent operations on the result cannot be
10677 guaranteed to produce sensible behavior. For example, it is possible to
10678 create @code{LOGICAL} variables for which @code{@var{VAR}} and
10679 @code{.NOT.@var{VAR}} both appear to be true.
10681 @item @emph{Example}:
10683 PROGRAM test_transfer
10684 integer :: x = 2143289344
10685 print *, transfer(x, 1.0) ! prints "NaN" on i686
10693 @section @code{TRANSPOSE} --- Transpose an array of rank two
10695 @cindex array, transpose
10696 @cindex matrix, transpose
10700 @item @emph{Description}:
10701 Transpose an array of rank two. Element (i, j) of the result has the value
10702 @code{MATRIX(j, i)}, for all i, j.
10704 @item @emph{Standard}:
10705 Fortran 95 and later
10707 @item @emph{Class}:
10708 Transformational function
10710 @item @emph{Syntax}:
10711 @code{RESULT = TRANSPOSE(MATRIX)}
10713 @item @emph{Arguments}:
10714 @multitable @columnfractions .15 .70
10715 @item @var{MATRIX} @tab Shall be an array of any type and have a rank of two.
10718 @item @emph{Return value}:
10719 The result has the same type as @var{MATRIX}, and has shape
10720 @code{(/ m, n /)} if @var{MATRIX} has shape @code{(/ n, m /)}.
10726 @section @code{TRIM} --- Remove trailing blank characters of a string
10728 @cindex string, remove trailing whitespace
10731 @item @emph{Description}:
10732 Removes trailing blank characters of a string.
10734 @item @emph{Standard}:
10735 Fortran 95 and later
10737 @item @emph{Class}:
10738 Transformational function
10740 @item @emph{Syntax}:
10741 @code{RESULT = TRIM(STRING)}
10743 @item @emph{Arguments}:
10744 @multitable @columnfractions .15 .70
10745 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER}.
10748 @item @emph{Return value}:
10749 A scalar of type @code{CHARACTER} which length is that of @var{STRING}
10750 less the number of trailing blanks.
10752 @item @emph{Example}:
10755 CHARACTER(len=10), PARAMETER :: s = "GFORTRAN "
10756 WRITE(*,*) LEN(s), LEN(TRIM(s)) ! "10 8", with/without trailing blanks
10760 @item @emph{See also}:
10761 @ref{ADJUSTL}, @ref{ADJUSTR}
10767 @section @code{TTYNAM} --- Get the name of a terminal device.
10769 @cindex system, terminal
10772 @item @emph{Description}:
10773 Get the name of a terminal device. For more information,
10774 see @code{ttyname(3)}.
10776 This intrinsic is provided in both subroutine and function forms;
10777 however, only one form can be used in any given program unit.
10779 @item @emph{Standard}:
10782 @item @emph{Class}:
10783 Subroutine, function
10785 @item @emph{Syntax}:
10786 @multitable @columnfractions .80
10787 @item @code{CALL TTYNAM(UNIT, NAME)}
10788 @item @code{NAME = TTYNAM(UNIT)}
10791 @item @emph{Arguments}:
10792 @multitable @columnfractions .15 .70
10793 @item @var{UNIT} @tab Shall be a scalar @code{INTEGER}.
10794 @item @var{NAME} @tab Shall be of type @code{CHARACTER}.
10797 @item @emph{Example}:
10799 PROGRAM test_ttynam
10802 IF (isatty(unit=unit)) write(*,*) ttynam(unit)
10807 @item @emph{See also}:
10814 @section @code{UBOUND} --- Upper dimension bounds of an array
10816 @cindex array, upper bound
10819 @item @emph{Description}:
10820 Returns the upper bounds of an array, or a single upper bound
10821 along the @var{DIM} dimension.
10822 @item @emph{Standard}:
10823 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
10825 @item @emph{Class}:
10828 @item @emph{Syntax}:
10829 @code{RESULT = UBOUND(ARRAY [, DIM [, KIND]])}
10831 @item @emph{Arguments}:
10832 @multitable @columnfractions .15 .70
10833 @item @var{ARRAY} @tab Shall be an array, of any type.
10834 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER}.
10835 @item @var{KIND}@tab (Optional) An @code{INTEGER} initialization
10836 expression indicating the kind parameter of
10840 @item @emph{Return value}:
10841 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
10842 @var{KIND} is absent, the return value is of default integer kind.
10843 If @var{DIM} is absent, the result is an array of the upper bounds of
10844 @var{ARRAY}. If @var{DIM} is present, the result is a scalar
10845 corresponding to the upper bound of the array along that dimension. If
10846 @var{ARRAY} is an expression rather than a whole array or array
10847 structure component, or if it has a zero extent along the relevant
10848 dimension, the upper bound is taken to be the number of elements along
10849 the relevant dimension.
10851 @item @emph{See also}:
10858 @section @code{UMASK} --- Set the file creation mask
10860 @cindex file system, file creation mask
10863 @item @emph{Description}:
10864 Sets the file creation mask to @var{MASK} and returns the old value in
10865 argument @var{OLD} if it is supplied. See @code{umask(2)}.
10867 @item @emph{Standard}:
10870 @item @emph{Class}:
10873 @item @emph{Syntax}:
10874 @code{CALL UMASK(MASK [, OLD])}
10876 @item @emph{Arguments}:
10877 @multitable @columnfractions .15 .70
10878 @item @var{MASK} @tab Shall be a scalar of type @code{INTEGER}.
10879 @item @var{MASK} @tab (Optional) Shall be a scalar of type
10888 @section @code{UNLINK} --- Remove a file from the file system
10890 @cindex file system, remove file
10893 @item @emph{Description}:
10894 Unlinks the file @var{PATH}. A null character (@code{CHAR(0)}) can be
10895 used to mark the end of the name in @var{PATH}; otherwise, trailing
10896 blanks in the file name are ignored. If the @var{STATUS} argument is
10897 supplied, it contains 0 on success or a nonzero error code upon return;
10898 see @code{unlink(2)}.
10900 This intrinsic is provided in both subroutine and function forms;
10901 however, only one form can be used in any given program unit.
10903 @item @emph{Standard}:
10906 @item @emph{Class}:
10907 Subroutine, function
10909 @item @emph{Syntax}:
10910 @multitable @columnfractions .80
10911 @item @code{CALL UNLINK(PATH [, STATUS])}
10912 @item @code{STATUS = UNLINK(PATH)}
10915 @item @emph{Arguments}:
10916 @multitable @columnfractions .15 .70
10917 @item @var{PATH} @tab Shall be of default @code{CHARACTER} type.
10918 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
10921 @item @emph{See also}:
10922 @ref{LINK}, @ref{SYMLNK}
10928 @section @code{UNPACK} --- Unpack an array of rank one into an array
10930 @cindex array, unpacking
10931 @cindex array, increase dimension
10932 @cindex array, scatter elements
10935 @item @emph{Description}:
10936 Store the elements of @var{VECTOR} in an array of higher rank.
10938 @item @emph{Standard}:
10939 Fortran 95 and later
10941 @item @emph{Class}:
10942 Transformational function
10944 @item @emph{Syntax}:
10945 @code{RESULT = UNPACK(VECTOR, MASK, FIELD)}
10947 @item @emph{Arguments}:
10948 @multitable @columnfractions .15 .70
10949 @item @var{VECTOR} @tab Shall be an array of any type and rank one. It
10950 shall have at least as many elements as @var{MASK} has @code{TRUE} values.
10951 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL}.
10952 @item @var{FIELD} @tab Shall be of the same type as @var{VECTOR} and have
10953 the same shape as @var{MASK}.
10956 @item @emph{Return value}:
10957 The resulting array corresponds to @var{FIELD} with @code{TRUE} elements
10958 of @var{MASK} replaced by values from @var{VECTOR} in array element order.
10960 @item @emph{Example}:
10962 PROGRAM test_unpack
10963 integer :: vector(2) = (/1,1/)
10964 logical :: mask(4) = (/ .TRUE., .FALSE., .FALSE., .TRUE. /)
10965 integer :: field(2,2) = 0, unity(2,2)
10967 ! result: unity matrix
10968 unity = unpack(vector, reshape(mask, (/2,2/)), field)
10972 @item @emph{See also}:
10973 @ref{PACK}, @ref{SPREAD}
10979 @section @code{VERIFY} --- Scan a string for the absence of a set of characters
10981 @cindex string, find missing set
10984 @item @emph{Description}:
10985 Verifies that all the characters in a @var{SET} are present in a @var{STRING}.
10987 If @var{BACK} is either absent or equals @code{FALSE}, this function
10988 returns the position of the leftmost character of @var{STRING} that is
10989 not in @var{SET}. If @var{BACK} equals @code{TRUE}, the rightmost position
10990 is returned. If all characters of @var{SET} are found in @var{STRING}, the
10993 @item @emph{Standard}:
10994 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
10996 @item @emph{Class}:
10999 @item @emph{Syntax}:
11000 @code{RESULT = VERIFY(STRING, SET[, BACK [, KIND]])}
11002 @item @emph{Arguments}:
11003 @multitable @columnfractions .15 .70
11004 @item @var{STRING} @tab Shall be of type @code{CHARACTER}.
11005 @item @var{SET} @tab Shall be of type @code{CHARACTER}.
11006 @item @var{BACK} @tab (Optional) shall be of type @code{LOGICAL}.
11007 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
11008 expression indicating the kind parameter of
11012 @item @emph{Return value}:
11013 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
11014 @var{KIND} is absent, the return value is of default integer kind.
11016 @item @emph{Example}:
11018 PROGRAM test_verify
11019 WRITE(*,*) VERIFY("FORTRAN", "AO") ! 1, found 'F'
11020 WRITE(*,*) VERIFY("FORTRAN", "FOO") ! 3, found 'R'
11021 WRITE(*,*) VERIFY("FORTRAN", "C++") ! 1, found 'F'
11022 WRITE(*,*) VERIFY("FORTRAN", "C++", .TRUE.) ! 7, found 'N'
11023 WRITE(*,*) VERIFY("FORTRAN", "FORTRAN") ! 0' found none
11027 @item @emph{See also}:
11028 @ref{SCAN}, @ref{INDEX intrinsic}
11034 @section @code{XOR} --- Bitwise logical exclusive OR
11036 @cindex bitwise logical exclusive or
11037 @cindex logical exclusive or, bitwise
11040 @item @emph{Description}:
11041 Bitwise logical exclusive or.
11043 This intrinsic routine is provided for backwards compatibility with
11044 GNU Fortran 77. For integer arguments, programmers should consider
11045 the use of the @ref{IEOR} intrinsic defined by the Fortran standard.
11047 @item @emph{Standard}:
11050 @item @emph{Class}:
11053 @item @emph{Syntax}:
11054 @code{RESULT = XOR(X, Y)}
11056 @item @emph{Arguments}:
11057 @multitable @columnfractions .15 .70
11058 @item @var{X} @tab The type shall be either a scalar @code{INTEGER}
11059 type or a scalar @code{LOGICAL} type.
11060 @item @var{Y} @tab The type shall be the same as the type of @var{I}.
11063 @item @emph{Return value}:
11064 The return type is either a scalar @code{INTEGER} or a scalar
11065 @code{LOGICAL}. If the kind type parameters differ, then the
11066 smaller kind type is implicitly converted to larger kind, and the
11067 return has the larger kind.
11069 @item @emph{Example}:
11072 LOGICAL :: T = .TRUE., F = .FALSE.
11074 DATA a / Z'F' /, b / Z'3' /
11076 WRITE (*,*) XOR(T, T), XOR(T, F), XOR(F, T), XOR(F, F)
11077 WRITE (*,*) XOR(a, b)
11081 @item @emph{See also}:
11082 Fortran 95 elemental function: @ref{IEOR}
11087 @node Intrinsic Modules
11088 @chapter Intrinsic Modules
11089 @cindex intrinsic Modules
11091 @c @node ISO_FORTRAN_ENV
11092 @section @code{ISO_FORTRAN_ENV}
11094 @item @emph{Standard}:
11095 Fortran 2003 and later
11098 The @code{ISO_FORTRAN_ENV} module provides the following scalar default-integer
11102 @item @code{CHARACTER_STORAGE_SIZE}:
11103 Size in bits of the character storage unit.
11105 @item @code{ERROR_UNIT}:
11106 Identifies the preconnected unit used for error reporting.
11108 @item @code{FILE_STORAGE_SIZE}:
11109 Size in bits of the file-storage unit.
11111 @item @code{INPUT_UNIT}:
11112 Identifies the preconnected unit identified by the asterisk
11113 (@code{*}) in @code{READ} statement.
11115 @item @code{IOSTAT_END}:
11116 The value assigned to the variable passed to the IOSTAT= specifier of
11117 an input/output statement if an end-of-file condition occurred.
11119 @item @code{IOSTAT_EOR}:
11120 The value assigned to the variable passed to the IOSTAT= specifier of
11121 an input/output statement if an end-of-record condition occurred.
11123 @item @code{NUMERIC_STORAGE_SIZE}:
11124 The size in bits of the numeric storage unit.
11126 @item @code{OUTPUT_UNIT}:
11127 Identifies the preconnected unit identified by the asterisk
11128 (@code{*}) in @code{WRITE} statement.
11131 @c @node ISO_C_BINDING
11132 @section @code{ISO_C_BINDING}
11134 @item @emph{Standard}:
11135 Fortran 2003 and later, GNU extensions
11138 The following intrinsic procedures are provided by the module; their
11139 definition can be found in the section Intrinsic Procedures of this
11143 @item @code{C_ASSOCIATED}
11144 @item @code{C_F_POINTER}
11145 @item @code{C_F_PROCPOINTER}
11146 @item @code{C_FUNLOC}
11150 The @code{ISO_C_BINDING} module provides the following named constants of the
11151 type integer, which can be used as KIND type parameter. Note that GNU
11152 Fortran currently does not support the @code{C_INT_FAST...} KIND type
11153 parameters (marked by an asterisk (@code{*}) in the list below).
11154 The @code{C_INT_FAST...} parameters have therefore the value @math{-2}
11155 and cannot be used as KIND type parameter of the @code{INTEGER} type.
11157 In addition to the integer named constants required by the Fortran 2003
11158 standard, GNU Fortran provides as an extension named constants for the
11159 128-bit integer types supported by the C compiler: @code{C_INT128_T,
11160 C_INT_LEAST128_T, C_INT_FAST128_T}.
11162 @multitable @columnfractions .15 .35 .35 .35
11163 @item Fortran Type @tab Named constant @tab C type @tab Extension
11164 @item @code{INTEGER}@tab @code{C_INT} @tab @code{int}
11165 @item @code{INTEGER}@tab @code{C_SHORT} @tab @code{short int}
11166 @item @code{INTEGER}@tab @code{C_LONG} @tab @code{long int}
11167 @item @code{INTEGER}@tab @code{C_LONG_LONG} @tab @code{long long int}
11168 @item @code{INTEGER}@tab @code{C_SIGNED_CHAR} @tab @code{signed char}/@code{unsigned char}
11169 @item @code{INTEGER}@tab @code{C_SIZE_T} @tab @code{size_t}
11170 @item @code{INTEGER}@tab @code{C_INT8_T} @tab @code{int8_t}
11171 @item @code{INTEGER}@tab @code{C_INT16_T} @tab @code{int16_t}
11172 @item @code{INTEGER}@tab @code{C_INT32_T} @tab @code{int32_t}
11173 @item @code{INTEGER}@tab @code{C_INT64_T} @tab @code{int64_t}
11174 @item @code{INTEGER}@tab @code{C_INT128_T} @tab @code{int128_t} @tab Ext.
11175 @item @code{INTEGER}@tab @code{C_INT_LEAST8_T} @tab @code{int_least8_t}
11176 @item @code{INTEGER}@tab @code{C_INT_LEAST16_T} @tab @code{int_least16_t}
11177 @item @code{INTEGER}@tab @code{C_INT_LEAST32_T} @tab @code{int_least32_t}
11178 @item @code{INTEGER}@tab @code{C_INT_LEAST64_T} @tab @code{int_least64_t}
11179 @item @code{INTEGER}@tab @code{C_INT_LEAST128_T} @tab @code{int_least128_t} @tab Ext.
11180 @item @code{INTEGER}@tab @code{C_INT_FAST8_T}* @tab @code{int_fast8_t}
11181 @item @code{INTEGER}@tab @code{C_INT_FAST16_T}* @tab @code{int_fast16_t}
11182 @item @code{INTEGER}@tab @code{C_INT_FAST32_T}* @tab @code{int_fast32_t}
11183 @item @code{INTEGER}@tab @code{C_INT_FAST64_T}* @tab @code{int_fast64_t}
11184 @item @code{INTEGER}@tab @code{C_INT_FAST128_T}* @tab @code{int_fast128_t} @tab Ext.
11185 @item @code{INTEGER}@tab @code{C_INTMAX_T} @tab @code{intmax_t}
11186 @item @code{INTEGER}@tab @code{C_INTPTR_T} @tab @code{intptr_t}
11187 @item @code{REAL} @tab @code{C_FLOAT} @tab @code{float}
11188 @item @code{REAL} @tab @code{C_DOUBLE} @tab @code{double}
11189 @item @code{REAL} @tab @code{C_LONG_DOUBLE} @tab @code{long double}
11190 @item @code{COMPLEX}@tab @code{C_FLOAT_COMPLEX} @tab @code{float _Complex}
11191 @item @code{COMPLEX}@tab @code{C_DOUBLE_COMPLEX}@tab @code{double _Complex}
11192 @item @code{COMPLEX}@tab @code{C_LONG_DOUBLE_COMPLEX}@tab @code{long double _Complex}
11193 @item @code{LOGICAL}@tab @code{C_BOOL} @tab @code{_Bool}
11194 @item @code{CHARACTER}@tab @code{C_CHAR} @tab @code{char}
11197 Additionally, the following @code{(CHARACTER(KIND=C_CHAR)} are
11200 @multitable @columnfractions .20 .45 .15
11201 @item Name @tab C definition @tab Value
11202 @item @code{C_NULL_CHAR} @tab null character @tab @code{'\0'}
11203 @item @code{C_ALERT} @tab alert @tab @code{'\a'}
11204 @item @code{C_BACKSPACE} @tab backspace @tab @code{'\b'}
11205 @item @code{C_FORM_FEED} @tab form feed @tab @code{'\f'}
11206 @item @code{C_NEW_LINE} @tab new line @tab @code{'\n'}
11207 @item @code{C_CARRIAGE_RETURN} @tab carriage return @tab @code{'\r'}
11208 @item @code{C_HORIZONTAL_TAB} @tab horizontal tab @tab @code{'\t'}
11209 @item @code{C_VERTICAL_TAB} @tab vertical tab @tab @code{'\v'}
11212 @c @node OpenMP Modules OMP_LIB and OMP_LIB_KINDS
11213 @section OpenMP Modules @code{OMP_LIB} and @code{OMP_LIB_KINDS}
11215 @item @emph{Standard}:
11216 OpenMP Application Program Interface v2.5
11220 The OpenMP Fortran runtime library routines are provided both in
11221 a form of two Fortran 90 modules, named @code{OMP_LIB} and
11222 @code{OMP_LIB_KINDS}, and in a form of a Fortran @code{include} file named
11223 @file{omp_lib.h}. The procedures provided by @code{OMP_LIB} can be found
11224 in the @ref{Top,,Introduction,libgomp,GNU OpenMP runtime library} manual,
11225 the named constants defined in the @code{OMP_LIB_KINDS} module are listed
11228 For details refer to the actual
11229 @uref{http://www.openmp.org/drupal/mp-documents/spec25.pdf,
11230 OpenMP Application Program Interface v2.5}.
11232 @code{OMP_LIB_KINDS} provides the following scalar default-integer
11236 @item @code{omp_integer_kind}
11237 @item @code{omp_logical_kind}
11238 @item @code{omp_lock_kind}
11239 @item @code{omp_nest_lock_kind}