2 Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
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 ``Funding Free Software'', the Front-Cover
11 Texts being (a) (see below), and with the Back-Cover Texts being (b)
12 (see below). A copy of the license is included in the gfdl(7) man page.
15 Some basic guidelines for editing this document:
17 (1) The intrinsic procedures are to be listed in alphabetical order.
18 (2) The generic name is to be used.
19 (3) The specific names are included in the function index and in a
20 table at the end of the node (See ABS entry).
21 (4) Try to maintain the same style for each entry.
27 \gdef\acos{\mathop{\rm acos}\nolimits}
28 \gdef\asin{\mathop{\rm asin}\nolimits}
29 \gdef\atan{\mathop{\rm atan}\nolimits}
30 \gdef\acosh{\mathop{\rm acosh}\nolimits}
31 \gdef\asinh{\mathop{\rm asinh}\nolimits}
32 \gdef\atanh{\mathop{\rm atanh}\nolimits}
36 @node Intrinsic Procedures
37 @chapter Intrinsic Procedures
38 @cindex intrinsic procedures
41 * Introduction: Introduction to Intrinsics
42 * @code{ABORT}: ABORT, Abort the program
43 * @code{ABS}: ABS, Absolute value
44 * @code{ACCESS}: ACCESS, Checks file access modes
45 * @code{ACHAR}: ACHAR, Character in @acronym{ASCII} collating sequence
46 * @code{ACOS}: ACOS, Arccosine function
47 * @code{ACOSH}: ACOSH, Hyperbolic arccosine function
48 * @code{ADJUSTL}: ADJUSTL, Left adjust a string
49 * @code{ADJUSTR}: ADJUSTR, Right adjust a string
50 * @code{AIMAG}: AIMAG, Imaginary part of complex number
51 * @code{AINT}: AINT, Truncate to a whole number
52 * @code{ALARM}: ALARM, Set an alarm clock
53 * @code{ALL}: ALL, Determine if all values are true
54 * @code{ALLOCATED}: ALLOCATED, Status of allocatable entity
55 * @code{AND}: AND, Bitwise logical AND
56 * @code{ANINT}: ANINT, Nearest whole number
57 * @code{ANY}: ANY, Determine if any values are true
58 * @code{ASIN}: ASIN, Arcsine function
59 * @code{ASINH}: ASINH, Hyperbolic arcsine function
60 * @code{ASSOCIATED}: ASSOCIATED, Status of a pointer or pointer/target pair
61 * @code{ATAN}: ATAN, Arctangent function
62 * @code{ATAN2}: ATAN2, Arctangent function
63 * @code{ATANH}: ATANH, Hyperbolic arctangent function
64 * @code{BESSEL_J0}: BESSEL_J0, Bessel function of the first kind of order 0
65 * @code{BESSEL_J1}: BESSEL_J1, Bessel function of the first kind of order 1
66 * @code{BESSEL_JN}: BESSEL_JN, Bessel function of the first kind
67 * @code{BESSEL_Y0}: BESSEL_Y0, Bessel function of the second kind of order 0
68 * @code{BESSEL_Y1}: BESSEL_Y1, Bessel function of the second kind of order 1
69 * @code{BESSEL_YN}: BESSEL_YN, Bessel function of the second kind
70 * @code{BIT_SIZE}: BIT_SIZE, Bit size inquiry function
71 * @code{BTEST}: BTEST, Bit test function
72 * @code{C_ASSOCIATED}: C_ASSOCIATED, Status of a C pointer
73 * @code{C_F_POINTER}: C_F_POINTER, Convert C into Fortran pointer
74 * @code{C_F_PROCPOINTER}: C_F_PROCPOINTER, Convert C into Fortran procedure pointer
75 * @code{C_FUNLOC}: C_FUNLOC, Obtain the C address of a procedure
76 * @code{C_LOC}: C_LOC, Obtain the C address of an object
77 * @code{C_SIZEOF}: C_SIZEOF, Size in bytes of an expression
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{DIGITS}: DIGITS, Significant digits function
96 * @code{DIM}: DIM, Positive difference
97 * @code{DOT_PRODUCT}: DOT_PRODUCT, Dot product function
98 * @code{DPROD}: DPROD, Double product function
99 * @code{DREAL}: DREAL, Double real part function
100 * @code{DTIME}: DTIME, Execution time subroutine (or function)
101 * @code{EOSHIFT}: EOSHIFT, End-off shift elements of an array
102 * @code{EPSILON}: EPSILON, Epsilon function
103 * @code{ERF}: ERF, Error function
104 * @code{ERFC}: ERFC, Complementary error function
105 * @code{ERFC_SCALED}: ERFC_SCALED, Exponentially-scaled complementary error function
106 * @code{ETIME}: ETIME, Execution time subroutine (or function)
107 * @code{EXIT}: EXIT, Exit the program with status.
108 * @code{EXP}: EXP, Exponential function
109 * @code{EXPONENT}: EXPONENT, Exponent function
110 * @code{FDATE}: FDATE, Subroutine (or function) to get the current time as a string
111 * @code{FGET}: FGET, Read a single character in stream mode from stdin
112 * @code{FGETC}: FGETC, Read a single character in stream mode
113 * @code{FLOOR}: FLOOR, Integer floor function
114 * @code{FLUSH}: FLUSH, Flush I/O unit(s)
115 * @code{FNUM}: FNUM, File number function
116 * @code{FPUT}: FPUT, Write a single character in stream mode to stdout
117 * @code{FPUTC}: FPUTC, Write a single character in stream mode
118 * @code{FRACTION}: FRACTION, Fractional part of the model representation
119 * @code{FREE}: FREE, Memory de-allocation subroutine
120 * @code{FSEEK}: FSEEK, Low level file positioning subroutine
121 * @code{FSTAT}: FSTAT, Get file status
122 * @code{FTELL}: FTELL, Current stream position
123 * @code{GAMMA}: GAMMA, Gamma function
124 * @code{GERROR}: GERROR, Get last system error message
125 * @code{GETARG}: GETARG, Get command line arguments
126 * @code{GET_COMMAND}: GET_COMMAND, Get the entire command line
127 * @code{GET_COMMAND_ARGUMENT}: GET_COMMAND_ARGUMENT, Get command line arguments
128 * @code{GETCWD}: GETCWD, Get current working directory
129 * @code{GETENV}: GETENV, Get an environmental variable
130 * @code{GET_ENVIRONMENT_VARIABLE}: GET_ENVIRONMENT_VARIABLE, Get an environmental variable
131 * @code{GETGID}: GETGID, Group ID function
132 * @code{GETLOG}: GETLOG, Get login name
133 * @code{GETPID}: GETPID, Process ID function
134 * @code{GETUID}: GETUID, User ID function
135 * @code{GMTIME}: GMTIME, Convert time to GMT info
136 * @code{HOSTNM}: HOSTNM, Get system host name
137 * @code{HUGE}: HUGE, Largest number of a kind
138 * @code{HYPOT}: HYPOT, Euclidian distance function
139 * @code{IACHAR}: IACHAR, Code in @acronym{ASCII} collating sequence
140 * @code{IAND}: IAND, Bitwise logical and
141 * @code{IARGC}: IARGC, Get the number of command line arguments
142 * @code{IBCLR}: IBCLR, Clear bit
143 * @code{IBITS}: IBITS, Bit extraction
144 * @code{IBSET}: IBSET, Set bit
145 * @code{ICHAR}: ICHAR, Character-to-integer conversion function
146 * @code{IDATE}: IDATE, Current local time (day/month/year)
147 * @code{IEOR}: IEOR, Bitwise logical exclusive or
148 * @code{IERRNO}: IERRNO, Function to get the last system error number
149 * @code{INDEX}: INDEX intrinsic, Position of a substring within a string
150 * @code{INT}: INT, Convert to integer type
151 * @code{INT2}: INT2, Convert to 16-bit integer type
152 * @code{INT8}: INT8, Convert to 64-bit integer type
153 * @code{IOR}: IOR, Bitwise logical or
154 * @code{IRAND}: IRAND, Integer pseudo-random number
155 * @code{IMAGE_INDEX}: IMAGE_INDEX, Cosubscript to image index convertion
156 * @code{IS_IOSTAT_END}: IS_IOSTAT_END, Test for end-of-file value
157 * @code{IS_IOSTAT_EOR}: IS_IOSTAT_EOR, Test for end-of-record value
158 * @code{ISATTY}: ISATTY, Whether a unit is a terminal device
159 * @code{ISHFT}: ISHFT, Shift bits
160 * @code{ISHFTC}: ISHFTC, Shift bits circularly
161 * @code{ISNAN}: ISNAN, Tests for a NaN
162 * @code{ITIME}: ITIME, Current local time (hour/minutes/seconds)
163 * @code{KILL}: KILL, Send a signal to a process
164 * @code{KIND}: KIND, Kind of an entity
165 * @code{LBOUND}: LBOUND, Lower dimension bounds of an array
166 * @code{LCOBOUND}: LCOBOUND, Lower codimension bounds of an array
167 * @code{LEADZ}: LEADZ, Number of leading zero bits of an integer
168 * @code{LEN}: LEN, Length of a character entity
169 * @code{LEN_TRIM}: LEN_TRIM, Length of a character entity without trailing blank characters
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{LOG_GAMMA}: LOG_GAMMA, Logarithm of the Gamma function
180 * @code{LOGICAL}: LOGICAL, Convert to logical type
181 * @code{LONG}: LONG, Convert to integer type
182 * @code{LSHIFT}: LSHIFT, Left shift bits
183 * @code{LSTAT}: LSTAT, Get file status
184 * @code{LTIME}: LTIME, Convert time to local time info
185 * @code{MALLOC}: MALLOC, Dynamic memory allocation function
186 * @code{MATMUL}: MATMUL, matrix multiplication
187 * @code{MAX}: MAX, Maximum value of an argument list
188 * @code{MAXEXPONENT}: MAXEXPONENT, Maximum exponent of a real kind
189 * @code{MAXLOC}: MAXLOC, Location of the maximum value within an array
190 * @code{MAXVAL}: MAXVAL, Maximum value of an array
191 * @code{MCLOCK}: MCLOCK, Time function
192 * @code{MCLOCK8}: MCLOCK8, Time function (64-bit)
193 * @code{MERGE}: MERGE, Merge arrays
194 * @code{MIN}: MIN, Minimum value of an argument list
195 * @code{MINEXPONENT}: MINEXPONENT, Minimum exponent of a real kind
196 * @code{MINLOC}: MINLOC, Location of the minimum value within an array
197 * @code{MINVAL}: MINVAL, Minimum value of an array
198 * @code{MOD}: MOD, Remainder function
199 * @code{MODULO}: MODULO, Modulo function
200 * @code{MOVE_ALLOC}: MOVE_ALLOC, Move allocation from one object to another
201 * @code{MVBITS}: MVBITS, Move bits from one integer to another
202 * @code{NEAREST}: NEAREST, Nearest representable number
203 * @code{NEW_LINE}: NEW_LINE, New line character
204 * @code{NINT}: NINT, Nearest whole number
205 * @code{NOT}: NOT, Logical negation
206 * @code{NULL}: NULL, Function that returns an disassociated pointer
207 * @code{NUM_IMAGES}: NUM_IMAGES, Number of images
208 * @code{OR}: OR, Bitwise logical OR
209 * @code{PACK}: PACK, Pack an array into an array of rank one
210 * @code{PERROR}: PERROR, Print system error message
211 * @code{PRECISION}: PRECISION, Decimal precision of a real kind
212 * @code{PRESENT}: PRESENT, Determine whether an optional dummy argument is specified
213 * @code{PRODUCT}: PRODUCT, Product of array elements
214 * @code{RADIX}: RADIX, Base of a data model
215 * @code{RANDOM_NUMBER}: RANDOM_NUMBER, Pseudo-random number
216 * @code{RANDOM_SEED}: RANDOM_SEED, Initialize a pseudo-random number sequence
217 * @code{RAND}: RAND, Real pseudo-random number
218 * @code{RANGE}: RANGE, Decimal exponent range
219 * @code{RAN}: RAN, Real pseudo-random number
220 * @code{REAL}: REAL, Convert to real type
221 * @code{RENAME}: RENAME, Rename a file
222 * @code{REPEAT}: REPEAT, Repeated string concatenation
223 * @code{RESHAPE}: RESHAPE, Function to reshape an array
224 * @code{RRSPACING}: RRSPACING, Reciprocal of the relative spacing
225 * @code{RSHIFT}: RSHIFT, Right shift bits
226 * @code{SCALE}: SCALE, Scale a real value
227 * @code{SCAN}: SCAN, Scan a string for the presence of a set of characters
228 * @code{SECNDS}: SECNDS, Time function
229 * @code{SECOND}: SECOND, CPU time function
230 * @code{SELECTED_CHAR_KIND}: SELECTED_CHAR_KIND, Choose character kind
231 * @code{SELECTED_INT_KIND}: SELECTED_INT_KIND, Choose integer kind
232 * @code{SELECTED_REAL_KIND}: SELECTED_REAL_KIND, Choose real kind
233 * @code{SET_EXPONENT}: SET_EXPONENT, Set the exponent of the model
234 * @code{SHAPE}: SHAPE, Determine the shape of an array
235 * @code{SIGN}: SIGN, Sign copying function
236 * @code{SIGNAL}: SIGNAL, Signal handling subroutine (or function)
237 * @code{SIN}: SIN, Sine function
238 * @code{SINH}: SINH, Hyperbolic sine function
239 * @code{SIZE}: SIZE, Function to determine the size of an array
240 * @code{SIZEOF}: SIZEOF, Determine the size in bytes of an expression
241 * @code{SLEEP}: SLEEP, Sleep for the specified number of seconds
242 * @code{SPACING}: SPACING, Smallest distance between two numbers of a given type
243 * @code{SPREAD}: SPREAD, Add a dimension to an array
244 * @code{SQRT}: SQRT, Square-root function
245 * @code{SRAND}: SRAND, Reinitialize the random number generator
246 * @code{STAT}: STAT, Get file status
247 * @code{SUM}: SUM, Sum of array elements
248 * @code{SYMLNK}: SYMLNK, Create a symbolic link
249 * @code{SYSTEM}: SYSTEM, Execute a shell command
250 * @code{SYSTEM_CLOCK}: SYSTEM_CLOCK, Time function
251 * @code{TAN}: TAN, Tangent function
252 * @code{TANH}: TANH, Hyperbolic tangent function
253 * @code{THIS_IMAGE}: THIS_IMAGE, Cosubscript index of this image
254 * @code{TIME}: TIME, Time function
255 * @code{TIME8}: TIME8, Time function (64-bit)
256 * @code{TINY}: TINY, Smallest positive number of a real kind
257 * @code{TRAILZ}: TRAILZ, Number of trailing zero bits of an integer
258 * @code{TRANSFER}: TRANSFER, Transfer bit patterns
259 * @code{TRANSPOSE}: TRANSPOSE, Transpose an array of rank two
260 * @code{TRIM}: TRIM, Remove trailing blank characters of a string
261 * @code{TTYNAM}: TTYNAM, Get the name of a terminal device.
262 * @code{UBOUND}: UBOUND, Upper dimension bounds of an array
263 * @code{UCOBOUND}: UCOBOUND, Upper codimension bounds of an array
264 * @code{UMASK}: UMASK, Set the file creation mask
265 * @code{UNLINK}: UNLINK, Remove a file from the file system
266 * @code{UNPACK}: UNPACK, Unpack an array of rank one into an array
267 * @code{VERIFY}: VERIFY, Scan a string for the absence of a set of characters
268 * @code{XOR}: XOR, Bitwise logical exclusive or
271 @node Introduction to Intrinsics
272 @section Introduction to intrinsic procedures
274 The intrinsic procedures provided by GNU Fortran include all of the
275 intrinsic procedures required by the Fortran 95 standard, a set of
276 intrinsic procedures for backwards compatibility with G77, and a
277 selection of intrinsic procedures from the Fortran 2003 and Fortran 2008
278 standards. Any conflict between a description here and a description in
279 either the Fortran 95 standard, the Fortran 2003 standard or the Fortran
280 2008 standard is unintentional, and the standard(s) should be considered
283 The enumeration of the @code{KIND} type parameter is processor defined in
284 the Fortran 95 standard. GNU Fortran defines the default integer type and
285 default real type by @code{INTEGER(KIND=4)} and @code{REAL(KIND=4)},
286 respectively. The standard mandates that both data types shall have
287 another kind, which have more precision. On typical target architectures
288 supported by @command{gfortran}, this kind type parameter is @code{KIND=8}.
289 Hence, @code{REAL(KIND=8)} and @code{DOUBLE PRECISION} are equivalent.
290 In the description of generic intrinsic procedures, the kind type parameter
291 will be specified by @code{KIND=*}, and in the description of specific
292 names for an intrinsic procedure the kind type parameter will be explicitly
293 given (e.g., @code{REAL(KIND=4)} or @code{REAL(KIND=8)}). Finally, for
294 brevity the optional @code{KIND=} syntax will be omitted.
296 Many of the intrinsic procedures take one or more optional arguments.
297 This document follows the convention used in the Fortran 95 standard,
298 and denotes such arguments by square brackets.
300 GNU Fortran offers the @option{-std=f95} and @option{-std=gnu} options,
301 which can be used to restrict the set of intrinsic procedures to a
302 given standard. By default, @command{gfortran} sets the @option{-std=gnu}
303 option, and so all intrinsic procedures described here are accepted. There
304 is one caveat. For a select group of intrinsic procedures, @command{g77}
305 implemented both a function and a subroutine. Both classes
306 have been implemented in @command{gfortran} for backwards compatibility
307 with @command{g77}. It is noted here that these functions and subroutines
308 cannot be intermixed in a given subprogram. In the descriptions that follow,
309 the applicable standard for each intrinsic procedure is noted.
314 @section @code{ABORT} --- Abort the program
316 @cindex program termination, with core dump
317 @cindex terminate program, with core dump
321 @item @emph{Description}:
322 @code{ABORT} causes immediate termination of the program. On operating
323 systems that support a core dump, @code{ABORT} will produce a core dump even if
324 the option @option{-fno-dump-core} is in effect, which is suitable for debugging
326 @c TODO: Check if this (with -fno-dump-core) is correct.
328 @item @emph{Standard}:
337 @item @emph{Return value}:
340 @item @emph{Example}:
343 integer :: i = 1, j = 2
344 if (i /= j) call abort
345 end program test_abort
348 @item @emph{See also}:
349 @ref{EXIT}, @ref{KILL}
356 @section @code{ABS} --- Absolute value
363 @cindex absolute value
366 @item @emph{Description}:
367 @code{ABS(A)} computes the absolute value of @code{A}.
369 @item @emph{Standard}:
370 Fortran 77 and later, has overloads that are GNU extensions
376 @code{RESULT = ABS(A)}
378 @item @emph{Arguments}:
379 @multitable @columnfractions .15 .70
380 @item @var{A} @tab The type of the argument shall be an @code{INTEGER},
381 @code{REAL}, or @code{COMPLEX}.
384 @item @emph{Return value}:
385 The return value is of the same type and
386 kind as the argument except the return value is @code{REAL} for a
387 @code{COMPLEX} argument.
389 @item @emph{Example}:
394 complex :: z = (-1.e0,0.e0)
401 @item @emph{Specific names}:
402 @multitable @columnfractions .20 .20 .20 .25
403 @item Name @tab Argument @tab Return type @tab Standard
404 @item @code{ABS(A)} @tab @code{REAL(4) A} @tab @code{REAL(4)} @tab Fortran 77 and later
405 @item @code{CABS(A)} @tab @code{COMPLEX(4) A} @tab @code{REAL(4)} @tab Fortran 77 and later
406 @item @code{DABS(A)} @tab @code{REAL(8) A} @tab @code{REAL(8)} @tab Fortran 77 and later
407 @item @code{IABS(A)} @tab @code{INTEGER(4) A} @tab @code{INTEGER(4)} @tab Fortran 77 and later
408 @item @code{ZABS(A)} @tab @code{COMPLEX(8) A} @tab @code{COMPLEX(8)} @tab GNU extension
409 @item @code{CDABS(A)} @tab @code{COMPLEX(8) A} @tab @code{COMPLEX(8)} @tab GNU extension
416 @section @code{ACCESS} --- Checks file access modes
418 @cindex file system, access mode
421 @item @emph{Description}:
422 @code{ACCESS(NAME, MODE)} checks whether the file @var{NAME}
423 exists, is readable, writable or executable. Except for the
424 executable check, @code{ACCESS} can be replaced by
425 Fortran 95's @code{INQUIRE}.
427 @item @emph{Standard}:
434 @code{RESULT = ACCESS(NAME, MODE)}
436 @item @emph{Arguments}:
437 @multitable @columnfractions .15 .70
438 @item @var{NAME} @tab Scalar @code{CHARACTER} of default kind with the
439 file name. Tailing blank are ignored unless the character @code{achar(0)}
440 is present, then all characters up to and excluding @code{achar(0)} are
442 @item @var{MODE} @tab Scalar @code{CHARACTER} of default kind with the
443 file access mode, may be any concatenation of @code{"r"} (readable),
444 @code{"w"} (writable) and @code{"x"} (executable), or @code{" "} to check
448 @item @emph{Return value}:
449 Returns a scalar @code{INTEGER}, which is @code{0} if the file is
450 accessible in the given mode; otherwise or if an invalid argument
451 has been given for @code{MODE} the value @code{1} is returned.
453 @item @emph{Example}:
457 character(len=*), parameter :: file = 'test.dat'
458 character(len=*), parameter :: file2 = 'test.dat '//achar(0)
459 if(access(file,' ') == 0) print *, trim(file),' is exists'
460 if(access(file,'r') == 0) print *, trim(file),' is readable'
461 if(access(file,'w') == 0) print *, trim(file),' is writable'
462 if(access(file,'x') == 0) print *, trim(file),' is executable'
463 if(access(file2,'rwx') == 0) &
464 print *, trim(file2),' is readable, writable and executable'
465 end program access_test
467 @item @emph{Specific names}:
468 @item @emph{See also}:
475 @section @code{ACHAR} --- Character in @acronym{ASCII} collating sequence
477 @cindex @acronym{ASCII} collating sequence
478 @cindex collating sequence, @acronym{ASCII}
481 @item @emph{Description}:
482 @code{ACHAR(I)} returns the character located at position @code{I}
483 in the @acronym{ASCII} collating sequence.
485 @item @emph{Standard}:
486 Fortran 77 and later, with @var{KIND} argument Fortran 2003 and later
492 @code{RESULT = ACHAR(I [, KIND])}
494 @item @emph{Arguments}:
495 @multitable @columnfractions .15 .70
496 @item @var{I} @tab The type shall be @code{INTEGER}.
497 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
498 expression indicating the kind parameter of the result.
501 @item @emph{Return value}:
502 The return value is of type @code{CHARACTER} with a length of one.
503 If the @var{KIND} argument is present, the return value is of the
504 specified kind and of the default kind otherwise.
506 @item @emph{Example}:
511 end program test_achar
515 See @ref{ICHAR} for a discussion of converting between numerical values
516 and formatted string representations.
518 @item @emph{See also}:
519 @ref{CHAR}, @ref{IACHAR}, @ref{ICHAR}
526 @section @code{ACOS} --- Arccosine function
529 @cindex trigonometric function, cosine, inverse
530 @cindex cosine, inverse
533 @item @emph{Description}:
534 @code{ACOS(X)} computes the arccosine of @var{X} (inverse of @code{COS(X)}).
536 @item @emph{Standard}:
537 Fortran 77 and later, for a complex argument Fortran 2008 or later
543 @code{RESULT = ACOS(X)}
545 @item @emph{Arguments}:
546 @multitable @columnfractions .15 .70
547 @item @var{X} @tab The type shall either be @code{REAL} with a magnitude that is
548 less than or equal to one - or the type shall be @code{COMPLEX}.
551 @item @emph{Return value}:
552 The return value is of the same type and kind as @var{X}.
553 The real part of the result is in radians and lies in the range
554 @math{0 \leq \Re \acos(x) \leq \pi}.
556 @item @emph{Example}:
559 real(8) :: x = 0.866_8
561 end program test_acos
564 @item @emph{Specific names}:
565 @multitable @columnfractions .20 .20 .20 .25
566 @item Name @tab Argument @tab Return type @tab Standard
567 @item @code{ACOS(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
568 @item @code{DACOS(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
571 @item @emph{See also}:
572 Inverse function: @ref{COS}
579 @section @code{ACOSH} --- Hyperbolic arccosine function
582 @cindex area hyperbolic cosine
583 @cindex hyperbolic arccosine
584 @cindex hyperbolic function, cosine, inverse
585 @cindex cosine, hyperbolic, inverse
588 @item @emph{Description}:
589 @code{ACOSH(X)} computes the hyperbolic arccosine of @var{X} (inverse of
592 @item @emph{Standard}:
593 Fortran 2008 and later
599 @code{RESULT = ACOSH(X)}
601 @item @emph{Arguments}:
602 @multitable @columnfractions .15 .70
603 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
606 @item @emph{Return value}:
607 The return value has the same type and kind as @var{X}. If @var{X} is
608 complex, the imaginary part of the result is in radians and lies between
609 @math{ 0 \leq \Im \acosh(x) \leq \pi}.
611 @item @emph{Example}:
614 REAL(8), DIMENSION(3) :: x = (/ 1.0, 2.0, 3.0 /)
619 @item @emph{Specific names}:
620 @multitable @columnfractions .20 .20 .20 .25
621 @item Name @tab Argument @tab Return type @tab Standard
622 @item @code{DACOSH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
625 @item @emph{See also}:
626 Inverse function: @ref{COSH}
632 @section @code{ADJUSTL} --- Left adjust a string
634 @cindex string, adjust left
635 @cindex adjust string
638 @item @emph{Description}:
639 @code{ADJUSTL(STRING)} will left adjust a string by removing leading spaces.
640 Spaces are inserted at the end of the string as needed.
642 @item @emph{Standard}:
649 @code{RESULT = ADJUSTL(STRING)}
651 @item @emph{Arguments}:
652 @multitable @columnfractions .15 .70
653 @item @var{STRING} @tab The type shall be @code{CHARACTER}.
656 @item @emph{Return value}:
657 The return value is of type @code{CHARACTER} and of the same kind as
658 @var{STRING} where leading spaces are removed and the same number of
659 spaces are inserted on the end of @var{STRING}.
661 @item @emph{Example}:
664 character(len=20) :: str = ' gfortran'
667 end program test_adjustl
670 @item @emph{See also}:
671 @ref{ADJUSTR}, @ref{TRIM}
677 @section @code{ADJUSTR} --- Right adjust a string
679 @cindex string, adjust right
680 @cindex adjust string
683 @item @emph{Description}:
684 @code{ADJUSTR(STRING)} will right adjust a string by removing trailing spaces.
685 Spaces are inserted at the start of the string as needed.
687 @item @emph{Standard}:
694 @code{RESULT = ADJUSTR(STRING)}
696 @item @emph{Arguments}:
697 @multitable @columnfractions .15 .70
698 @item @var{STR} @tab The type shall be @code{CHARACTER}.
701 @item @emph{Return value}:
702 The return value is of type @code{CHARACTER} and of the same kind as
703 @var{STRING} where trailing spaces are removed and the same number of
704 spaces are inserted at the start of @var{STRING}.
706 @item @emph{Example}:
709 character(len=20) :: str = 'gfortran'
712 end program test_adjustr
715 @item @emph{See also}:
716 @ref{ADJUSTL}, @ref{TRIM}
722 @section @code{AIMAG} --- Imaginary part of complex number
727 @cindex complex numbers, imaginary part
730 @item @emph{Description}:
731 @code{AIMAG(Z)} yields the imaginary part of complex argument @code{Z}.
732 The @code{IMAG(Z)} and @code{IMAGPART(Z)} intrinsic functions are provided
733 for compatibility with @command{g77}, and their use in new code is
734 strongly discouraged.
736 @item @emph{Standard}:
737 Fortran 77 and later, has overloads that are GNU extensions
743 @code{RESULT = AIMAG(Z)}
745 @item @emph{Arguments}:
746 @multitable @columnfractions .15 .70
747 @item @var{Z} @tab The type of the argument shall be @code{COMPLEX}.
750 @item @emph{Return value}:
751 The return value is of type @code{REAL} with the
752 kind type parameter of the argument.
754 @item @emph{Example}:
759 z4 = cmplx(1.e0_4, 0.e0_4)
760 z8 = cmplx(0.e0_8, 1.e0_8)
761 print *, aimag(z4), dimag(z8)
762 end program test_aimag
765 @item @emph{Specific names}:
766 @multitable @columnfractions .20 .20 .20 .25
767 @item Name @tab Argument @tab Return type @tab Standard
768 @item @code{AIMAG(Z)} @tab @code{COMPLEX Z} @tab @code{REAL} @tab GNU extension
769 @item @code{DIMAG(Z)} @tab @code{COMPLEX(8) Z} @tab @code{REAL(8)} @tab GNU extension
770 @item @code{IMAG(Z)} @tab @code{COMPLEX Z} @tab @code{REAL} @tab GNU extension
771 @item @code{IMAGPART(Z)} @tab @code{COMPLEX Z} @tab @code{REAL} @tab GNU extension
778 @section @code{AINT} --- Truncate to a whole number
782 @cindex rounding, floor
785 @item @emph{Description}:
786 @code{AINT(A [, KIND])} truncates its argument to a whole number.
788 @item @emph{Standard}:
795 @code{RESULT = AINT(A [, KIND])}
797 @item @emph{Arguments}:
798 @multitable @columnfractions .15 .70
799 @item @var{A} @tab The type of the argument shall be @code{REAL}.
800 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
801 expression indicating the kind parameter of the result.
804 @item @emph{Return value}:
805 The return value is of type @code{REAL} with the kind type parameter of the
806 argument if the optional @var{KIND} is absent; otherwise, the kind
807 type parameter will be given by @var{KIND}. If the magnitude of
808 @var{X} is less than one, @code{AINT(X)} returns zero. If the
809 magnitude is equal to or greater than one then it returns the largest
810 whole number that does not exceed its magnitude. The sign is the same
811 as the sign of @var{X}.
813 @item @emph{Example}:
820 print *, aint(x4), dint(x8)
822 end program test_aint
825 @item @emph{Specific names}:
826 @multitable @columnfractions .20 .20 .20 .25
827 @item Name @tab Argument @tab Return type @tab Standard
828 @item @code{AINT(A)} @tab @code{REAL(4) A} @tab @code{REAL(4)} @tab Fortran 77 and later
829 @item @code{DINT(A)} @tab @code{REAL(8) A} @tab @code{REAL(8)} @tab Fortran 77 and later
836 @section @code{ALARM} --- Execute a routine after a given delay
838 @cindex delayed execution
841 @item @emph{Description}:
842 @code{ALARM(SECONDS, HANDLER [, STATUS])} causes external subroutine @var{HANDLER}
843 to be executed after a delay of @var{SECONDS} by using @code{alarm(2)} to
844 set up a signal and @code{signal(2)} to catch it. If @var{STATUS} is
845 supplied, it will be returned with the number of seconds remaining until
846 any previously scheduled alarm was due to be delivered, or zero if there
847 was no previously scheduled alarm.
849 @item @emph{Standard}:
856 @code{CALL ALARM(SECONDS, HANDLER [, STATUS])}
858 @item @emph{Arguments}:
859 @multitable @columnfractions .15 .70
860 @item @var{SECONDS} @tab The type of the argument shall be a scalar
861 @code{INTEGER}. It is @code{INTENT(IN)}.
862 @item @var{HANDLER} @tab Signal handler (@code{INTEGER FUNCTION} or
863 @code{SUBROUTINE}) or dummy/global @code{INTEGER} scalar. The scalar
864 values may be either @code{SIG_IGN=1} to ignore the alarm generated
865 or @code{SIG_DFL=0} to set the default action. It is @code{INTENT(IN)}.
866 @item @var{STATUS} @tab (Optional) @var{STATUS} shall be a scalar
867 variable of the default @code{INTEGER} kind. It is @code{INTENT(OUT)}.
870 @item @emph{Example}:
873 external handler_print
875 call alarm (3, handler_print, i)
878 end program test_alarm
880 This will cause the external routine @var{handler_print} to be called
887 @section @code{ALL} --- All values in @var{MASK} along @var{DIM} are true
889 @cindex array, apply condition
890 @cindex array, condition testing
893 @item @emph{Description}:
894 @code{ALL(MASK [, DIM])} determines if all the values are true in @var{MASK}
895 in the array along dimension @var{DIM}.
897 @item @emph{Standard}:
901 Transformational function
904 @code{RESULT = ALL(MASK [, DIM])}
906 @item @emph{Arguments}:
907 @multitable @columnfractions .15 .70
908 @item @var{MASK} @tab The type of the argument shall be @code{LOGICAL} and
909 it shall not be scalar.
910 @item @var{DIM} @tab (Optional) @var{DIM} shall be a scalar integer
911 with a value that lies between one and the rank of @var{MASK}.
914 @item @emph{Return value}:
915 @code{ALL(MASK)} returns a scalar value of type @code{LOGICAL} where
916 the kind type parameter is the same as the kind type parameter of
917 @var{MASK}. If @var{DIM} is present, then @code{ALL(MASK, DIM)} returns
918 an array with the rank of @var{MASK} minus 1. The shape is determined from
919 the shape of @var{MASK} where the @var{DIM} dimension is elided.
923 @code{ALL(MASK)} is true if all elements of @var{MASK} are true.
924 It also is true if @var{MASK} has zero size; otherwise, it is false.
926 If the rank of @var{MASK} is one, then @code{ALL(MASK,DIM)} is equivalent
927 to @code{ALL(MASK)}. If the rank is greater than one, then @code{ALL(MASK,DIM)}
928 is determined by applying @code{ALL} to the array sections.
931 @item @emph{Example}:
935 l = all((/.true., .true., .true./))
940 integer a(2,3), b(2,3)
944 print *, all(a .eq. b, 1)
945 print *, all(a .eq. b, 2)
946 end subroutine section
954 @section @code{ALLOCATED} --- Status of an allocatable entity
956 @cindex allocation, status
959 @item @emph{Description}:
960 @code{ALLOCATED(ARRAY)} and @code{ALLOCATED(SCALAR)} check the allocation
961 status of @var{ARRAY} and @var{SCALAR}, respectively.
963 @item @emph{Standard}:
964 Fortran 95 and later. Note, the @code{SCALAR=} keyword and allocatable
965 scalar entities are available in Fortran 2003 and later.
971 @code{RESULT = ALLOCATED(ARRAY)} or @code{RESULT = ALLOCATED(SCALAR)}
973 @item @emph{Arguments}:
974 @multitable @columnfractions .15 .70
975 @item @var{ARRAY} @tab The argument shall be an @code{ALLOCATABLE} array.
976 @item @var{SCALAR} @tab The argument shall be an @code{ALLOCATABLE} scalar.
979 @item @emph{Return value}:
980 The return value is a scalar @code{LOGICAL} with the default logical
981 kind type parameter. If the argument is allocated, then the result is
982 @code{.TRUE.}; otherwise, it returns @code{.FALSE.}
984 @item @emph{Example}:
986 program test_allocated
988 real(4), allocatable :: x(:)
989 if (.not. allocated(x)) allocate(x(i))
990 end program test_allocated
997 @section @code{AND} --- Bitwise logical AND
999 @cindex bitwise logical and
1000 @cindex logical and, bitwise
1003 @item @emph{Description}:
1004 Bitwise logical @code{AND}.
1006 This intrinsic routine is provided for backwards compatibility with
1007 GNU Fortran 77. For integer arguments, programmers should consider
1008 the use of the @ref{IAND} intrinsic defined by the Fortran standard.
1010 @item @emph{Standard}:
1016 @item @emph{Syntax}:
1017 @code{RESULT = AND(I, J)}
1019 @item @emph{Arguments}:
1020 @multitable @columnfractions .15 .70
1021 @item @var{I} @tab The type shall be either a scalar @code{INTEGER}
1022 type or a scalar @code{LOGICAL} type.
1023 @item @var{J} @tab The type shall be the same as the type of @var{I}.
1026 @item @emph{Return value}:
1027 The return type is either a scalar @code{INTEGER} or a scalar
1028 @code{LOGICAL}. If the kind type parameters differ, then the
1029 smaller kind type is implicitly converted to larger kind, and the
1030 return has the larger kind.
1032 @item @emph{Example}:
1035 LOGICAL :: T = .TRUE., F = .FALSE.
1037 DATA a / Z'F' /, b / Z'3' /
1039 WRITE (*,*) AND(T, T), AND(T, F), AND(F, T), AND(F, F)
1040 WRITE (*,*) AND(a, b)
1044 @item @emph{See also}:
1045 Fortran 95 elemental function: @ref{IAND}
1051 @section @code{ANINT} --- Nearest whole number
1055 @cindex rounding, ceiling
1058 @item @emph{Description}:
1059 @code{ANINT(A [, KIND])} rounds its argument to the nearest whole number.
1061 @item @emph{Standard}:
1062 Fortran 77 and later
1067 @item @emph{Syntax}:
1068 @code{RESULT = ANINT(A [, KIND])}
1070 @item @emph{Arguments}:
1071 @multitable @columnfractions .15 .70
1072 @item @var{A} @tab The type of the argument shall be @code{REAL}.
1073 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
1074 expression indicating the kind parameter of the result.
1077 @item @emph{Return value}:
1078 The return value is of type real with the kind type parameter of the
1079 argument if the optional @var{KIND} is absent; otherwise, the kind
1080 type parameter will be given by @var{KIND}. If @var{A} is greater than
1081 zero, @code{ANINT(A)} returns @code{AINT(X+0.5)}. If @var{A} is
1082 less than or equal to zero then it returns @code{AINT(X-0.5)}.
1084 @item @emph{Example}:
1091 print *, anint(x4), dnint(x8)
1093 end program test_anint
1096 @item @emph{Specific names}:
1097 @multitable @columnfractions .20 .20 .20 .25
1098 @item Name @tab Argument @tab Return type @tab Standard
1099 @item @code{AINT(A)} @tab @code{REAL(4) A} @tab @code{REAL(4)} @tab Fortran 77 and later
1100 @item @code{DNINT(A)} @tab @code{REAL(8) A} @tab @code{REAL(8)} @tab Fortran 77 and later
1107 @section @code{ANY} --- Any value in @var{MASK} along @var{DIM} is true
1109 @cindex array, apply condition
1110 @cindex array, condition testing
1113 @item @emph{Description}:
1114 @code{ANY(MASK [, DIM])} determines if any of the values in the logical array
1115 @var{MASK} along dimension @var{DIM} are @code{.TRUE.}.
1117 @item @emph{Standard}:
1118 Fortran 95 and later
1121 Transformational function
1123 @item @emph{Syntax}:
1124 @code{RESULT = ANY(MASK [, DIM])}
1126 @item @emph{Arguments}:
1127 @multitable @columnfractions .15 .70
1128 @item @var{MASK} @tab The type of the argument shall be @code{LOGICAL} and
1129 it shall not be scalar.
1130 @item @var{DIM} @tab (Optional) @var{DIM} shall be a scalar integer
1131 with a value that lies between one and the rank of @var{MASK}.
1134 @item @emph{Return value}:
1135 @code{ANY(MASK)} returns a scalar value of type @code{LOGICAL} where
1136 the kind type parameter is the same as the kind type parameter of
1137 @var{MASK}. If @var{DIM} is present, then @code{ANY(MASK, DIM)} returns
1138 an array with the rank of @var{MASK} minus 1. The shape is determined from
1139 the shape of @var{MASK} where the @var{DIM} dimension is elided.
1143 @code{ANY(MASK)} is true if any element of @var{MASK} is true;
1144 otherwise, it is false. It also is false if @var{MASK} has zero size.
1146 If the rank of @var{MASK} is one, then @code{ANY(MASK,DIM)} is equivalent
1147 to @code{ANY(MASK)}. If the rank is greater than one, then @code{ANY(MASK,DIM)}
1148 is determined by applying @code{ANY} to the array sections.
1151 @item @emph{Example}:
1155 l = any((/.true., .true., .true./))
1160 integer a(2,3), b(2,3)
1164 print *, any(a .eq. b, 1)
1165 print *, any(a .eq. b, 2)
1166 end subroutine section
1167 end program test_any
1174 @section @code{ASIN} --- Arcsine function
1177 @cindex trigonometric function, sine, inverse
1178 @cindex sine, inverse
1181 @item @emph{Description}:
1182 @code{ASIN(X)} computes the arcsine of its @var{X} (inverse of @code{SIN(X)}).
1184 @item @emph{Standard}:
1185 Fortran 77 and later, for a complex argument Fortran 2008 or later
1190 @item @emph{Syntax}:
1191 @code{RESULT = ASIN(X)}
1193 @item @emph{Arguments}:
1194 @multitable @columnfractions .15 .70
1195 @item @var{X} @tab The type shall be either @code{REAL} and a magnitude that is
1196 less than or equal to one - or be @code{COMPLEX}.
1199 @item @emph{Return value}:
1200 The return value is of the same type and kind as @var{X}.
1201 The real part of the result is in radians and lies in the range
1202 @math{-\pi/2 \leq \Re \asin(x) \leq \pi/2}.
1204 @item @emph{Example}:
1207 real(8) :: x = 0.866_8
1209 end program test_asin
1212 @item @emph{Specific names}:
1213 @multitable @columnfractions .20 .20 .20 .25
1214 @item Name @tab Argument @tab Return type @tab Standard
1215 @item @code{ASIN(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
1216 @item @code{DASIN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
1219 @item @emph{See also}:
1220 Inverse function: @ref{SIN}
1227 @section @code{ASINH} --- Hyperbolic arcsine function
1230 @cindex area hyperbolic sine
1231 @cindex hyperbolic arcsine
1232 @cindex hyperbolic function, sine, inverse
1233 @cindex sine, hyperbolic, inverse
1236 @item @emph{Description}:
1237 @code{ASINH(X)} computes the hyperbolic arcsine of @var{X} (inverse of @code{SINH(X)}).
1239 @item @emph{Standard}:
1240 Fortran 2008 and later
1245 @item @emph{Syntax}:
1246 @code{RESULT = ASINH(X)}
1248 @item @emph{Arguments}:
1249 @multitable @columnfractions .15 .70
1250 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
1253 @item @emph{Return value}:
1254 The return value is of the same type and kind as @var{X}. If @var{X} is
1255 complex, the imaginary part of the result is in radians and lies between
1256 @math{-\pi/2 \leq \Im \asinh(x) \leq \pi/2}.
1258 @item @emph{Example}:
1261 REAL(8), DIMENSION(3) :: x = (/ -1.0, 0.0, 1.0 /)
1262 WRITE (*,*) ASINH(x)
1266 @item @emph{Specific names}:
1267 @multitable @columnfractions .20 .20 .20 .25
1268 @item Name @tab Argument @tab Return type @tab Standard
1269 @item @code{DASINH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension.
1272 @item @emph{See also}:
1273 Inverse function: @ref{SINH}
1279 @section @code{ASSOCIATED} --- Status of a pointer or pointer/target pair
1281 @cindex pointer, status
1282 @cindex association status
1285 @item @emph{Description}:
1286 @code{ASSOCIATED(POINTER [, TARGET])} determines the status of the pointer
1287 @var{POINTER} or if @var{POINTER} is associated with the target @var{TARGET}.
1289 @item @emph{Standard}:
1290 Fortran 95 and later
1295 @item @emph{Syntax}:
1296 @code{RESULT = ASSOCIATED(POINTER [, TARGET])}
1298 @item @emph{Arguments}:
1299 @multitable @columnfractions .15 .70
1300 @item @var{POINTER} @tab @var{POINTER} shall have the @code{POINTER} attribute
1301 and it can be of any type.
1302 @item @var{TARGET} @tab (Optional) @var{TARGET} shall be a pointer or
1303 a target. It must have the same type, kind type parameter, and
1304 array rank as @var{POINTER}.
1306 The association status of neither @var{POINTER} nor @var{TARGET} shall be
1309 @item @emph{Return value}:
1310 @code{ASSOCIATED(POINTER)} returns a scalar value of type @code{LOGICAL(4)}.
1311 There are several cases:
1313 @item (A) When the optional @var{TARGET} is not present then
1314 @code{ASSOCIATED(POINTER)} is true if @var{POINTER} is associated with a target; otherwise, it returns false.
1315 @item (B) If @var{TARGET} is present and a scalar target, the result is true if
1316 @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
1317 disassociated, the result is false.
1318 @item (C) If @var{TARGET} is present and an array target, the result is true if
1319 @var{TARGET} and @var{POINTER} have the same shape, are not zero-sized arrays,
1320 are arrays whose elements are not zero-sized storage sequences, and
1321 @var{TARGET} and @var{POINTER} occupy the same storage units in array element
1323 As in case(B), the result is false, if @var{POINTER} is disassociated.
1324 @item (D) If @var{TARGET} is present and an scalar pointer, the result is true
1325 if @var{TARGET} is associated with @var{POINTER}, the target associated with
1326 @var{TARGET} are not zero-sized storage sequences and occupy the same storage
1328 The result is false, if either @var{TARGET} or @var{POINTER} is disassociated.
1329 @item (E) If @var{TARGET} is present and an array pointer, the result is true if
1330 target associated with @var{POINTER} and the target associated with @var{TARGET}
1331 have the same shape, are not zero-sized arrays, are arrays whose elements are
1332 not zero-sized storage sequences, and @var{TARGET} and @var{POINTER} occupy
1333 the same storage units in array element order.
1334 The result is false, if either @var{TARGET} or @var{POINTER} is disassociated.
1337 @item @emph{Example}:
1339 program test_associated
1341 real, target :: tgt(2) = (/1., 2./)
1342 real, pointer :: ptr(:)
1344 if (associated(ptr) .eqv. .false.) call abort
1345 if (associated(ptr,tgt) .eqv. .false.) call abort
1346 end program test_associated
1349 @item @emph{See also}:
1356 @section @code{ATAN} --- Arctangent function
1359 @cindex trigonometric function, tangent, inverse
1360 @cindex tangent, inverse
1363 @item @emph{Description}:
1364 @code{ATAN(X)} computes the arctangent of @var{X}.
1366 @item @emph{Standard}:
1367 Fortran 77 and later, for a complex argument and for two arguments
1368 Fortran 2008 or later
1373 @item @emph{Syntax}:
1374 @code{RESULT = ATAN(X)}
1375 @code{RESULT = ATAN(Y, X)}
1377 @item @emph{Arguments}:
1378 @multitable @columnfractions .15 .70
1379 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX};
1380 if @var{Y} is present, @var{X} shall be REAL.
1381 @item @var{Y} shall be of the same type and kind as @var{X}.
1384 @item @emph{Return value}:
1385 The return value is of the same type and kind as @var{X}.
1386 If @var{Y} is present, the result is identical to @code{ATAN2(Y,X)}.
1387 Otherwise, it the arcus tangent of @var{X}, where the real part of
1388 the result is in radians and lies in the range
1389 @math{-\pi/2 \leq \Re \atan(x) \leq \pi/2}.
1391 @item @emph{Example}:
1394 real(8) :: x = 2.866_8
1396 end program test_atan
1399 @item @emph{Specific names}:
1400 @multitable @columnfractions .20 .20 .20 .25
1401 @item Name @tab Argument @tab Return type @tab Standard
1402 @item @code{ATAN(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
1403 @item @code{DATAN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
1406 @item @emph{See also}:
1407 Inverse function: @ref{TAN}
1414 @section @code{ATAN2} --- Arctangent function
1417 @cindex trigonometric function, tangent, inverse
1418 @cindex tangent, inverse
1421 @item @emph{Description}:
1422 @code{ATAN2(Y, X)} computes the principal value of the argument
1423 function of the complex number @math{X + i Y}. This function can
1424 be used to transform from carthesian into polar coordinates and
1425 allows to determine the angle in the correct quadrant.
1427 @item @emph{Standard}:
1428 Fortran 77 and later
1433 @item @emph{Syntax}:
1434 @code{RESULT = ATAN2(Y, X)}
1436 @item @emph{Arguments}:
1437 @multitable @columnfractions .15 .70
1438 @item @var{Y} @tab The type shall be @code{REAL}.
1439 @item @var{X} @tab The type and kind type parameter shall be the same as @var{Y}.
1440 If @var{Y} is zero, then @var{X} must be nonzero.
1443 @item @emph{Return value}:
1444 The return value has the same type and kind type parameter as @var{Y}.
1445 It is the principal value of the complex number @math{X + i Y}. If
1446 @var{X} is nonzero, then it lies in the range @math{-\pi \le \atan (x) \leq \pi}.
1447 The sign is positive if @var{Y} is positive. If @var{Y} is zero, then
1448 the return value is zero if @var{X} is positive and @math{\pi} if @var{X}
1449 is negative. Finally, if @var{X} is zero, then the magnitude of the result
1452 @item @emph{Example}:
1455 real(4) :: x = 1.e0_4, y = 0.5e0_4
1457 end program test_atan2
1460 @item @emph{Specific names}:
1461 @multitable @columnfractions .20 .20 .20 .25
1462 @item Name @tab Argument @tab Return type @tab Standard
1463 @item @code{ATAN2(X, Y)} @tab @code{REAL(4) X, Y} @tab @code{REAL(4)} @tab Fortran 77 and later
1464 @item @code{DATAN2(X, Y)} @tab @code{REAL(8) X, Y} @tab @code{REAL(8)} @tab Fortran 77 and later
1471 @section @code{ATANH} --- Hyperbolic arctangent function
1474 @cindex area hyperbolic tangent
1475 @cindex hyperbolic arctangent
1476 @cindex hyperbolic function, tangent, inverse
1477 @cindex tangent, hyperbolic, inverse
1480 @item @emph{Description}:
1481 @code{ATANH(X)} computes the hyperbolic arctangent of @var{X} (inverse
1484 @item @emph{Standard}:
1485 Fortran 2008 and later
1490 @item @emph{Syntax}:
1491 @code{RESULT = ATANH(X)}
1493 @item @emph{Arguments}:
1494 @multitable @columnfractions .15 .70
1495 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
1498 @item @emph{Return value}:
1499 The return value has same type and kind as @var{X}. If @var{X} is
1500 complex, the imaginary part of the result is in radians and lies between
1501 @math{-\pi/2 \leq \Im \atanh(x) \leq \pi/2}.
1503 @item @emph{Example}:
1506 REAL, DIMENSION(3) :: x = (/ -1.0, 0.0, 1.0 /)
1507 WRITE (*,*) ATANH(x)
1511 @item @emph{Specific names}:
1512 @multitable @columnfractions .20 .20 .20 .25
1513 @item Name @tab Argument @tab Return type @tab Standard
1514 @item @code{DATANH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1517 @item @emph{See also}:
1518 Inverse function: @ref{TANH}
1524 @section @code{BESSEL_J0} --- Bessel function of the first kind of order 0
1528 @cindex Bessel function, first kind
1531 @item @emph{Description}:
1532 @code{BESSEL_J0(X)} computes the Bessel function of the first kind of
1533 order 0 of @var{X}. This function is available under the name
1534 @code{BESJ0} as a GNU extension.
1536 @item @emph{Standard}:
1537 Fortran 2008 and later
1542 @item @emph{Syntax}:
1543 @code{RESULT = BESSEL_J0(X)}
1545 @item @emph{Arguments}:
1546 @multitable @columnfractions .15 .70
1547 @item @var{X} @tab The type shall be @code{REAL}, and it shall be scalar.
1550 @item @emph{Return value}:
1551 The return value is of type @code{REAL} and lies in the
1552 range @math{ - 0.4027... \leq Bessel (0,x) \leq 1}. It has the same
1555 @item @emph{Example}:
1558 real(8) :: x = 0.0_8
1560 end program test_besj0
1563 @item @emph{Specific names}:
1564 @multitable @columnfractions .20 .20 .20 .25
1565 @item Name @tab Argument @tab Return type @tab Standard
1566 @item @code{DBESJ0(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1573 @section @code{BESSEL_J1} --- Bessel function of the first kind of order 1
1577 @cindex Bessel function, first kind
1580 @item @emph{Description}:
1581 @code{BESSEL_J1(X)} computes the Bessel function of the first kind of
1582 order 1 of @var{X}. This function is available under the name
1583 @code{BESJ1} as a GNU extension.
1585 @item @emph{Standard}:
1591 @item @emph{Syntax}:
1592 @code{RESULT = BESSEL_J1(X)}
1594 @item @emph{Arguments}:
1595 @multitable @columnfractions .15 .70
1596 @item @var{X} @tab The type shall be @code{REAL}, and it shall be scalar.
1599 @item @emph{Return value}:
1600 The return value is of type @code{REAL} and it lies in the
1601 range @math{ - 0.5818... \leq Bessel (0,x) \leq 0.5818 }. It has the same
1604 @item @emph{Example}:
1607 real(8) :: x = 1.0_8
1609 end program test_besj1
1612 @item @emph{Specific names}:
1613 @multitable @columnfractions .20 .20 .20 .25
1614 @item Name @tab Argument @tab Return type @tab Standard
1615 @item @code{DBESJ1(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1622 @section @code{BESSEL_JN} --- Bessel function of the first kind
1626 @cindex Bessel function, first kind
1629 @item @emph{Description}:
1630 @code{BESSEL_JN(N, X)} computes the Bessel function of the first kind of
1631 order @var{N} of @var{X}. This function is available under the name
1632 @code{BESJN} as a GNU extension.
1634 If both arguments are arrays, their ranks and shapes shall conform.
1636 @item @emph{Standard}:
1637 Fortran 2008 and later
1642 @item @emph{Syntax}:
1643 @code{RESULT = BESSEL_JN(N, X)}
1645 @item @emph{Arguments}:
1646 @multitable @columnfractions .15 .70
1647 @item @var{N} @tab Shall be a scalar or an array of type @code{INTEGER}.
1648 @item @var{X} @tab Shall be a scalar or an array of type @code{REAL}.
1651 @item @emph{Return value}:
1652 The return value is a scalar of type @code{REAL}. It has the same
1655 @item @emph{Example}:
1658 real(8) :: x = 1.0_8
1660 end program test_besjn
1663 @item @emph{Specific names}:
1664 @multitable @columnfractions .20 .20 .20 .25
1665 @item Name @tab Argument @tab Return type @tab Standard
1666 @item @code{DBESJN(N, X)} @tab @code{INTEGER N} @tab @code{REAL(8)} @tab GNU extension
1667 @item @tab @code{REAL(8) X} @tab @tab
1674 @section @code{BESSEL_Y0} --- Bessel function of the second kind of order 0
1678 @cindex Bessel function, second kind
1681 @item @emph{Description}:
1682 @code{BESSEL_Y0(X)} computes the Bessel function of the second kind of
1683 order 0 of @var{X}. This function is available under the name
1684 @code{BESY0} as a GNU extension.
1686 @item @emph{Standard}:
1687 Fortran 2008 and later
1692 @item @emph{Syntax}:
1693 @code{RESULT = BESSEL_Y0(X)}
1695 @item @emph{Arguments}:
1696 @multitable @columnfractions .15 .70
1697 @item @var{X} @tab The type shall be @code{REAL}, and it shall be scalar.
1700 @item @emph{Return value}:
1701 The return value is a scalar of type @code{REAL}. It has the same
1704 @item @emph{Example}:
1707 real(8) :: x = 0.0_8
1709 end program test_besy0
1712 @item @emph{Specific names}:
1713 @multitable @columnfractions .20 .20 .20 .25
1714 @item Name @tab Argument @tab Return type @tab Standard
1715 @item @code{DBESY0(X)}@tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1722 @section @code{BESSEL_Y1} --- Bessel function of the second kind of order 1
1726 @cindex Bessel function, second kind
1729 @item @emph{Description}:
1730 @code{BESSEL_Y1(X)} computes the Bessel function of the second kind of
1731 order 1 of @var{X}. This function is available under the name
1732 @code{BESY1} as a GNU extension.
1734 @item @emph{Standard}:
1735 Fortran 2008 and later
1740 @item @emph{Syntax}:
1741 @code{RESULT = BESSEL_Y1(X)}
1743 @item @emph{Arguments}:
1744 @multitable @columnfractions .15 .70
1745 @item @var{X} @tab The type shall be @code{REAL}, and it shall be scalar.
1748 @item @emph{Return value}:
1749 The return value is a scalar of type @code{REAL}. It has the same
1752 @item @emph{Example}:
1755 real(8) :: x = 1.0_8
1757 end program test_besy1
1760 @item @emph{Specific names}:
1761 @multitable @columnfractions .20 .20 .20 .25
1762 @item Name @tab Argument @tab Return type @tab Standard
1763 @item @code{DBESY1(X)}@tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1770 @section @code{BESSEL_YN} --- Bessel function of the second kind
1774 @cindex Bessel function, second kind
1777 @item @emph{Description}:
1778 @code{BESSEL_YN(N, X)} computes the Bessel function of the second kind of
1779 order @var{N} of @var{X}. This function is available under the name
1780 @code{BESYN} as a GNU extension.
1782 If both arguments are arrays, their ranks and shapes shall conform.
1784 @item @emph{Standard}:
1785 Fortran 2008 and later
1790 @item @emph{Syntax}:
1791 @code{RESULT = BESSEL_YN(N, X)}
1793 @item @emph{Arguments}:
1794 @multitable @columnfractions .15 .70
1795 @item @var{N} @tab Shall be a scalar or an array of type @code{INTEGER}.
1796 @item @var{X} @tab Shall be a scalar or an array of type @code{REAL}.
1799 @item @emph{Return value}:
1800 The return value is a scalar of type @code{REAL}. It has the same
1803 @item @emph{Example}:
1806 real(8) :: x = 1.0_8
1808 end program test_besyn
1811 @item @emph{Specific names}:
1812 @multitable @columnfractions .20 .20 .20 .25
1813 @item Name @tab Argument @tab Return type @tab Standard
1814 @item @code{DBESYN(N,X)} @tab @code{INTEGER N} @tab @code{REAL(8)} @tab GNU extension
1815 @item @tab @code{REAL(8) X} @tab @tab
1822 @section @code{BIT_SIZE} --- Bit size inquiry function
1824 @cindex bits, number of
1825 @cindex size of a variable, in bits
1828 @item @emph{Description}:
1829 @code{BIT_SIZE(I)} returns the number of bits (integer precision plus sign bit)
1830 represented by the type of @var{I}. The result of @code{BIT_SIZE(I)} is
1831 independent of the actual value of @var{I}.
1833 @item @emph{Standard}:
1834 Fortran 95 and later
1839 @item @emph{Syntax}:
1840 @code{RESULT = BIT_SIZE(I)}
1842 @item @emph{Arguments}:
1843 @multitable @columnfractions .15 .70
1844 @item @var{I} @tab The type shall be @code{INTEGER}.
1847 @item @emph{Return value}:
1848 The return value is of type @code{INTEGER}
1850 @item @emph{Example}:
1852 program test_bit_size
1857 end program test_bit_size
1864 @section @code{BTEST} --- Bit test function
1866 @cindex bits, testing
1869 @item @emph{Description}:
1870 @code{BTEST(I,POS)} returns logical @code{.TRUE.} if the bit at @var{POS}
1871 in @var{I} is set. The counting of the bits starts at 0.
1873 @item @emph{Standard}:
1874 Fortran 95 and later
1879 @item @emph{Syntax}:
1880 @code{RESULT = BTEST(I, POS)}
1882 @item @emph{Arguments}:
1883 @multitable @columnfractions .15 .70
1884 @item @var{I} @tab The type shall be @code{INTEGER}.
1885 @item @var{POS} @tab The type shall be @code{INTEGER}.
1888 @item @emph{Return value}:
1889 The return value is of type @code{LOGICAL}
1891 @item @emph{Example}:
1894 integer :: i = 32768 + 1024 + 64
1898 bool = btest(i, pos)
1901 end program test_btest
1907 @section @code{C_ASSOCIATED} --- Status of a C pointer
1908 @fnindex C_ASSOCIATED
1909 @cindex association status, C pointer
1910 @cindex pointer, C association status
1913 @item @emph{Description}:
1914 @code{C_ASSOCIATED(c_prt_1[, c_ptr_2])} determines the status of the C pointer
1915 @var{c_ptr_1} or if @var{c_ptr_1} is associated with the target @var{c_ptr_2}.
1917 @item @emph{Standard}:
1918 Fortran 2003 and later
1923 @item @emph{Syntax}:
1924 @code{RESULT = C_ASSOCIATED(c_prt_1[, c_ptr_2])}
1926 @item @emph{Arguments}:
1927 @multitable @columnfractions .15 .70
1928 @item @var{c_ptr_1} @tab Scalar of the type @code{C_PTR} or @code{C_FUNPTR}.
1929 @item @var{c_ptr_2} @tab (Optional) Scalar of the same type as @var{c_ptr_1}.
1932 @item @emph{Return value}:
1933 The return value is of type @code{LOGICAL}; it is @code{.false.} if either
1934 @var{c_ptr_1} is a C NULL pointer or if @var{c_ptr1} and @var{c_ptr_2}
1935 point to different addresses.
1937 @item @emph{Example}:
1939 subroutine association_test(a,b)
1940 use iso_c_binding, only: c_associated, c_loc, c_ptr
1944 if(c_associated(b, c_loc(a))) &
1945 stop 'b and a do not point to same target'
1946 end subroutine association_test
1949 @item @emph{See also}:
1950 @ref{C_LOC}, @ref{C_FUNLOC}
1955 @section @code{C_FUNLOC} --- Obtain the C address of a procedure
1957 @cindex pointer, C address of procedures
1960 @item @emph{Description}:
1961 @code{C_FUNLOC(x)} determines the C address of the argument.
1963 @item @emph{Standard}:
1964 Fortran 2003 and later
1969 @item @emph{Syntax}:
1970 @code{RESULT = C_FUNLOC(x)}
1972 @item @emph{Arguments}:
1973 @multitable @columnfractions .15 .70
1974 @item @var{x} @tab Interoperable function or pointer to such function.
1977 @item @emph{Return value}:
1978 The return value is of type @code{C_FUNPTR} and contains the C address
1981 @item @emph{Example}:
1987 subroutine sub(a) bind(c)
1997 subroutine my_routine(p) bind(c,name='myC_func')
1999 type(c_funptr), intent(in) :: p
2002 call my_routine(c_funloc(sub))
2006 @item @emph{See also}:
2007 @ref{C_ASSOCIATED}, @ref{C_LOC}, @ref{C_F_POINTER}, @ref{C_F_PROCPOINTER}
2011 @node C_F_PROCPOINTER
2012 @section @code{C_F_PROCPOINTER} --- Convert C into Fortran procedure pointer
2013 @fnindex C_F_PROCPOINTER
2014 @cindex pointer, C address of pointers
2017 @item @emph{Description}:
2018 @code{C_F_PROCPOINTER(CPTR, FPTR)} Assign the target of the C function pointer
2019 @var{CPTR} to the Fortran procedure pointer @var{FPTR}.
2021 @item @emph{Standard}:
2022 Fortran 2003 and later
2027 @item @emph{Syntax}:
2028 @code{CALL C_F_PROCPOINTER(cptr, fptr)}
2030 @item @emph{Arguments}:
2031 @multitable @columnfractions .15 .70
2032 @item @var{CPTR} @tab scalar of the type @code{C_FUNPTR}. It is
2034 @item @var{FPTR} @tab procedure pointer interoperable with @var{cptr}. It is
2038 @item @emph{Example}:
2046 real(c_float), intent(in) :: a
2047 real(c_float) :: func
2051 function getIterFunc() bind(c,name="getIterFunc")
2053 type(c_funptr) :: getIterFunc
2056 type(c_funptr) :: cfunptr
2057 procedure(func), pointer :: myFunc
2058 cfunptr = getIterFunc()
2059 call c_f_procpointer(cfunptr, myFunc)
2063 @item @emph{See also}:
2064 @ref{C_LOC}, @ref{C_F_POINTER}
2069 @section @code{C_F_POINTER} --- Convert C into Fortran pointer
2070 @fnindex C_F_POINTER
2071 @cindex pointer, convert C to Fortran
2074 @item @emph{Description}:
2075 @code{C_F_POINTER(CPTR, FPTR[, SHAPE])} Assign the target the C pointer
2076 @var{CPTR} to the Fortran pointer @var{FPTR} and specify its
2079 @item @emph{Standard}:
2080 Fortran 2003 and later
2085 @item @emph{Syntax}:
2086 @code{CALL C_F_POINTER(CPTR, FPTR[, SHAPE])}
2088 @item @emph{Arguments}:
2089 @multitable @columnfractions .15 .70
2090 @item @var{CPTR} @tab scalar of the type @code{C_PTR}. It is
2092 @item @var{FPTR} @tab pointer interoperable with @var{cptr}. It is
2094 @item @var{SHAPE} @tab (Optional) Rank-one array of type @code{INTEGER}
2095 with @code{INTENT(IN)}. It shall be present
2096 if and only if @var{fptr} is an array. The size
2097 must be equal to the rank of @var{fptr}.
2100 @item @emph{Example}:
2106 subroutine my_routine(p) bind(c,name='myC_func')
2108 type(c_ptr), intent(out) :: p
2112 real,pointer :: a(:)
2113 call my_routine(cptr)
2114 call c_f_pointer(cptr, a, [12])
2118 @item @emph{See also}:
2119 @ref{C_LOC}, @ref{C_F_PROCPOINTER}
2124 @section @code{C_LOC} --- Obtain the C address of an object
2126 @cindex procedure pointer, convert C to Fortran
2129 @item @emph{Description}:
2130 @code{C_LOC(X)} determines the C address of the argument.
2132 @item @emph{Standard}:
2133 Fortran 2003 and later
2138 @item @emph{Syntax}:
2139 @code{RESULT = C_LOC(X)}
2141 @item @emph{Arguments}:
2142 @multitable @columnfractions .15 .70
2143 @item @var{X} @tab Associated scalar pointer or interoperable scalar
2144 or allocated allocatable variable with @code{TARGET} attribute.
2147 @item @emph{Return value}:
2148 The return value is of type @code{C_PTR} and contains the C address
2151 @item @emph{Example}:
2153 subroutine association_test(a,b)
2154 use iso_c_binding, only: c_associated, c_loc, c_ptr
2158 if(c_associated(b, c_loc(a))) &
2159 stop 'b and a do not point to same target'
2160 end subroutine association_test
2163 @item @emph{See also}:
2164 @ref{C_ASSOCIATED}, @ref{C_FUNLOC}, @ref{C_F_POINTER}, @ref{C_F_PROCPOINTER}
2169 @section @code{C_SIZEOF} --- Size in bytes of an expression
2171 @cindex expression size
2172 @cindex size of an expression
2175 @item @emph{Description}:
2176 @code{C_SIZEOF(X)} calculates the number of bytes of storage the
2177 expression @code{X} occupies.
2179 @item @emph{Standard}:
2185 @item @emph{Syntax}:
2186 @code{N = C_SIZEOF(X)}
2188 @item @emph{Arguments}:
2189 @multitable @columnfractions .15 .70
2190 @item @var{X} @tab The argument shall be of any type, rank or shape.
2193 @item @emph{Return value}:
2194 The return value is of type integer and of the system-dependent kind
2195 @var{C_SIZE_T} (from the @var{ISO_C_BINDING} module). Its value is the
2196 number of bytes occupied by the argument. If the argument has the
2197 @code{POINTER} attribute, the number of bytes of the storage area pointed
2198 to is returned. If the argument is of a derived type with @code{POINTER}
2199 or @code{ALLOCATABLE} components, the return value doesn't account for
2200 the sizes of the data pointed to by these components.
2202 @item @emph{Example}:
2206 real(c_float) :: r, s(5)
2207 print *, (c_sizeof(s)/c_sizeof(r) == 5)
2210 The example will print @code{.TRUE.} unless you are using a platform
2211 where default @code{REAL} variables are unusually padded.
2213 @item @emph{See also}:
2219 @section @code{CEILING} --- Integer ceiling function
2222 @cindex rounding, ceiling
2225 @item @emph{Description}:
2226 @code{CEILING(A)} returns the least integer greater than or equal to @var{A}.
2228 @item @emph{Standard}:
2229 Fortran 95 and later
2234 @item @emph{Syntax}:
2235 @code{RESULT = CEILING(A [, KIND])}
2237 @item @emph{Arguments}:
2238 @multitable @columnfractions .15 .70
2239 @item @var{A} @tab The type shall be @code{REAL}.
2240 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
2241 expression indicating the kind parameter of the result.
2244 @item @emph{Return value}:
2245 The return value is of type @code{INTEGER(KIND)} if @var{KIND} is present
2246 and a default-kind @code{INTEGER} otherwise.
2248 @item @emph{Example}:
2250 program test_ceiling
2253 print *, ceiling(x) ! returns 64
2254 print *, ceiling(y) ! returns -63
2255 end program test_ceiling
2258 @item @emph{See also}:
2259 @ref{FLOOR}, @ref{NINT}
2266 @section @code{CHAR} --- Character conversion function
2268 @cindex conversion, to character
2271 @item @emph{Description}:
2272 @code{CHAR(I [, KIND])} returns the character represented by the integer @var{I}.
2274 @item @emph{Standard}:
2275 Fortran 77 and later
2280 @item @emph{Syntax}:
2281 @code{RESULT = CHAR(I [, KIND])}
2283 @item @emph{Arguments}:
2284 @multitable @columnfractions .15 .70
2285 @item @var{I} @tab The type shall be @code{INTEGER}.
2286 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
2287 expression indicating the kind parameter of the result.
2290 @item @emph{Return value}:
2291 The return value is of type @code{CHARACTER(1)}
2293 @item @emph{Example}:
2299 print *, i, c ! returns 'J'
2300 end program test_char
2303 @item @emph{Specific names}:
2304 @multitable @columnfractions .20 .20 .20 .25
2305 @item Name @tab Argument @tab Return type @tab Standard
2306 @item @code{CHAR(I)} @tab @code{INTEGER I} @tab @code{CHARACTER(LEN=1)} @tab F77 and later
2310 See @ref{ICHAR} for a discussion of converting between numerical values
2311 and formatted string representations.
2313 @item @emph{See also}:
2314 @ref{ACHAR}, @ref{IACHAR}, @ref{ICHAR}
2321 @section @code{CHDIR} --- Change working directory
2323 @cindex system, working directory
2326 @item @emph{Description}:
2327 Change current working directory to a specified path.
2329 This intrinsic is provided in both subroutine and function forms; however,
2330 only one form can be used in any given program unit.
2332 @item @emph{Standard}:
2336 Subroutine, function
2338 @item @emph{Syntax}:
2339 @multitable @columnfractions .80
2340 @item @code{CALL CHDIR(NAME [, STATUS])}
2341 @item @code{STATUS = CHDIR(NAME)}
2344 @item @emph{Arguments}:
2345 @multitable @columnfractions .15 .70
2346 @item @var{NAME} @tab The type shall be @code{CHARACTER} of default
2347 kind and shall specify a valid path within the file system.
2348 @item @var{STATUS} @tab (Optional) @code{INTEGER} status flag of the default
2349 kind. Returns 0 on success, and a system specific and nonzero error code
2353 @item @emph{Example}:
2356 CHARACTER(len=255) :: path
2358 WRITE(*,*) TRIM(path)
2361 WRITE(*,*) TRIM(path)
2365 @item @emph{See also}:
2372 @section @code{CHMOD} --- Change access permissions of files
2374 @cindex file system, change access mode
2377 @item @emph{Description}:
2378 @code{CHMOD} changes the permissions of a file. This function invokes
2379 @code{/bin/chmod} and might therefore not work on all platforms.
2381 This intrinsic is provided in both subroutine and function forms; however,
2382 only one form can be used in any given program unit.
2384 @item @emph{Standard}:
2388 Subroutine, function
2390 @item @emph{Syntax}:
2391 @multitable @columnfractions .80
2392 @item @code{CALL CHMOD(NAME, MODE[, STATUS])}
2393 @item @code{STATUS = CHMOD(NAME, MODE)}
2396 @item @emph{Arguments}:
2397 @multitable @columnfractions .15 .70
2399 @item @var{NAME} @tab Scalar @code{CHARACTER} of default kind with the
2400 file name. Trailing blanks are ignored unless the character
2401 @code{achar(0)} is present, then all characters up to and excluding
2402 @code{achar(0)} are used as the file name.
2404 @item @var{MODE} @tab Scalar @code{CHARACTER} of default kind giving the
2405 file permission. @var{MODE} uses the same syntax as the @var{MODE}
2406 argument of @code{/bin/chmod}.
2408 @item @var{STATUS} @tab (optional) scalar @code{INTEGER}, which is
2409 @code{0} on success and nonzero otherwise.
2412 @item @emph{Return value}:
2413 In either syntax, @var{STATUS} is set to @code{0} on success and nonzero
2416 @item @emph{Example}:
2417 @code{CHMOD} as subroutine
2422 call chmod('test.dat','u+x',status)
2423 print *, 'Status: ', status
2424 end program chmod_test
2426 @code{CHMOD} as function:
2431 status = chmod('test.dat','u+x')
2432 print *, 'Status: ', status
2433 end program chmod_test
2441 @section @code{CMPLX} --- Complex conversion function
2443 @cindex complex numbers, conversion to
2444 @cindex conversion, to complex
2447 @item @emph{Description}:
2448 @code{CMPLX(X [, Y [, KIND]])} returns a complex number where @var{X} is converted to
2449 the real component. If @var{Y} is present it is converted to the imaginary
2450 component. If @var{Y} is not present then the imaginary component is set to
2451 0.0. If @var{X} is complex then @var{Y} must not be present.
2453 @item @emph{Standard}:
2454 Fortran 77 and later
2459 @item @emph{Syntax}:
2460 @code{RESULT = CMPLX(X [, Y [, KIND]])}
2462 @item @emph{Arguments}:
2463 @multitable @columnfractions .15 .70
2464 @item @var{X} @tab The type may be @code{INTEGER}, @code{REAL},
2466 @item @var{Y} @tab (Optional; only allowed if @var{X} is not
2467 @code{COMPLEX}.) May be @code{INTEGER} or @code{REAL}.
2468 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
2469 expression indicating the kind parameter of the result.
2472 @item @emph{Return value}:
2473 The return value is of @code{COMPLEX} type, with a kind equal to
2474 @var{KIND} if it is specified. If @var{KIND} is not specified, the
2475 result is of the default @code{COMPLEX} kind, regardless of the kinds of
2476 @var{X} and @var{Y}.
2478 @item @emph{Example}:
2485 print *, z, cmplx(x)
2486 end program test_cmplx
2489 @item @emph{See also}:
2495 @node COMMAND_ARGUMENT_COUNT
2496 @section @code{COMMAND_ARGUMENT_COUNT} --- Get number of command line arguments
2497 @fnindex COMMAND_ARGUMENT_COUNT
2498 @cindex command-line arguments
2499 @cindex command-line arguments, number of
2500 @cindex arguments, to program
2503 @item @emph{Description}:
2504 @code{COMMAND_ARGUMENT_COUNT()} returns the number of arguments passed on the
2505 command line when the containing program was invoked.
2507 @item @emph{Standard}:
2508 Fortran 2003 and later
2513 @item @emph{Syntax}:
2514 @code{RESULT = COMMAND_ARGUMENT_COUNT()}
2516 @item @emph{Arguments}:
2517 @multitable @columnfractions .15 .70
2521 @item @emph{Return value}:
2522 The return value is an @code{INTEGER} of default kind.
2524 @item @emph{Example}:
2526 program test_command_argument_count
2528 count = command_argument_count()
2530 end program test_command_argument_count
2533 @item @emph{See also}:
2534 @ref{GET_COMMAND}, @ref{GET_COMMAND_ARGUMENT}
2540 @section @code{COMPLEX} --- Complex conversion function
2542 @cindex complex numbers, conversion to
2543 @cindex conversion, to complex
2546 @item @emph{Description}:
2547 @code{COMPLEX(X, Y)} returns a complex number where @var{X} is converted
2548 to the real component and @var{Y} is converted to the imaginary
2551 @item @emph{Standard}:
2557 @item @emph{Syntax}:
2558 @code{RESULT = COMPLEX(X, Y)}
2560 @item @emph{Arguments}:
2561 @multitable @columnfractions .15 .70
2562 @item @var{X} @tab The type may be @code{INTEGER} or @code{REAL}.
2563 @item @var{Y} @tab The type may be @code{INTEGER} or @code{REAL}.
2566 @item @emph{Return value}:
2567 If @var{X} and @var{Y} are both of @code{INTEGER} type, then the return
2568 value is of default @code{COMPLEX} type.
2570 If @var{X} and @var{Y} are of @code{REAL} type, or one is of @code{REAL}
2571 type and one is of @code{INTEGER} type, then the return value is of
2572 @code{COMPLEX} type with a kind equal to that of the @code{REAL}
2573 argument with the highest precision.
2575 @item @emph{Example}:
2577 program test_complex
2580 print *, complex(i, x)
2581 end program test_complex
2584 @item @emph{See also}:
2591 @section @code{CONJG} --- Complex conjugate function
2594 @cindex complex conjugate
2597 @item @emph{Description}:
2598 @code{CONJG(Z)} returns the conjugate of @var{Z}. If @var{Z} is @code{(x, y)}
2599 then the result is @code{(x, -y)}
2601 @item @emph{Standard}:
2602 Fortran 77 and later, has overloads that are GNU extensions
2607 @item @emph{Syntax}:
2610 @item @emph{Arguments}:
2611 @multitable @columnfractions .15 .70
2612 @item @var{Z} @tab The type shall be @code{COMPLEX}.
2615 @item @emph{Return value}:
2616 The return value is of type @code{COMPLEX}.
2618 @item @emph{Example}:
2621 complex :: z = (2.0, 3.0)
2622 complex(8) :: dz = (2.71_8, -3.14_8)
2627 end program test_conjg
2630 @item @emph{Specific names}:
2631 @multitable @columnfractions .20 .20 .20 .25
2632 @item Name @tab Argument @tab Return type @tab Standard
2633 @item @code{CONJG(Z)} @tab @code{COMPLEX Z} @tab @code{COMPLEX} @tab GNU extension
2634 @item @code{DCONJG(Z)} @tab @code{COMPLEX(8) Z} @tab @code{COMPLEX(8)} @tab GNU extension
2641 @section @code{COS} --- Cosine function
2647 @cindex trigonometric function, cosine
2651 @item @emph{Description}:
2652 @code{COS(X)} computes the cosine of @var{X}.
2654 @item @emph{Standard}:
2655 Fortran 77 and later, has overloads that are GNU extensions
2660 @item @emph{Syntax}:
2661 @code{RESULT = COS(X)}
2663 @item @emph{Arguments}:
2664 @multitable @columnfractions .15 .70
2665 @item @var{X} @tab The type shall be @code{REAL} or
2669 @item @emph{Return value}:
2670 The return value is of the same type and kind as @var{X}. The real part
2671 of the result is in radians. If @var{X} is of the type @code{REAL},
2672 the return value lies in the range @math{ -1 \leq \cos (x) \leq 1}.
2674 @item @emph{Example}:
2679 end program test_cos
2682 @item @emph{Specific names}:
2683 @multitable @columnfractions .20 .20 .20 .25
2684 @item Name @tab Argument @tab Return type @tab Standard
2685 @item @code{COS(X)} n@tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
2686 @item @code{DCOS(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
2687 @item @code{CCOS(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab Fortran 77 and later
2688 @item @code{ZCOS(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
2689 @item @code{CDCOS(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
2692 @item @emph{See also}:
2693 Inverse function: @ref{ACOS}
2700 @section @code{COSH} --- Hyperbolic cosine function
2703 @cindex hyperbolic cosine
2704 @cindex hyperbolic function, cosine
2705 @cindex cosine, hyperbolic
2708 @item @emph{Description}:
2709 @code{COSH(X)} computes the hyperbolic cosine of @var{X}.
2711 @item @emph{Standard}:
2712 Fortran 77 and later, for a complex argument Fortran 2008 or later
2717 @item @emph{Syntax}:
2720 @item @emph{Arguments}:
2721 @multitable @columnfractions .15 .70
2722 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
2725 @item @emph{Return value}:
2726 The return value has same type and kind as @var{X}. If @var{X} is
2727 complex, the imaginary part of the result is in radians. If @var{X}
2728 is @code{REAL}, the return value has a lower bound of one,
2729 @math{\cosh (x) \geq 1}.
2731 @item @emph{Example}:
2734 real(8) :: x = 1.0_8
2736 end program test_cosh
2739 @item @emph{Specific names}:
2740 @multitable @columnfractions .20 .20 .20 .25
2741 @item Name @tab Argument @tab Return type @tab Standard
2742 @item @code{COSH(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
2743 @item @code{DCOSH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
2746 @item @emph{See also}:
2747 Inverse function: @ref{ACOSH}
2754 @section @code{COUNT} --- Count function
2756 @cindex array, conditionally count elements
2757 @cindex array, element counting
2758 @cindex array, number of elements
2761 @item @emph{Description}:
2763 Counts the number of @code{.TRUE.} elements in a logical @var{MASK},
2764 or, if the @var{DIM} argument is supplied, counts the number of
2765 elements along each row of the array in the @var{DIM} direction.
2766 If the array has zero size, or all of the elements of @var{MASK} are
2767 @code{.FALSE.}, then the result is @code{0}.
2769 @item @emph{Standard}:
2770 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
2773 Transformational function
2775 @item @emph{Syntax}:
2776 @code{RESULT = COUNT(MASK [, DIM, KIND])}
2778 @item @emph{Arguments}:
2779 @multitable @columnfractions .15 .70
2780 @item @var{MASK} @tab The type shall be @code{LOGICAL}.
2781 @item @var{DIM} @tab (Optional) The type shall be @code{INTEGER}.
2782 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
2783 expression indicating the kind parameter of the result.
2786 @item @emph{Return value}:
2787 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
2788 @var{KIND} is absent, the return value is of default integer kind.
2789 If @var{DIM} is present, the result is an array with a rank one less
2790 than the rank of @var{ARRAY}, and a size corresponding to the shape
2791 of @var{ARRAY} with the @var{DIM} dimension removed.
2793 @item @emph{Example}:
2796 integer, dimension(2,3) :: a, b
2797 logical, dimension(2,3) :: mask
2798 a = reshape( (/ 1, 2, 3, 4, 5, 6 /), (/ 2, 3 /))
2799 b = reshape( (/ 0, 7, 3, 4, 5, 8 /), (/ 2, 3 /))
2800 print '(3i3)', a(1,:)
2801 print '(3i3)', a(2,:)
2803 print '(3i3)', b(1,:)
2804 print '(3i3)', b(2,:)
2807 print '(3l3)', mask(1,:)
2808 print '(3l3)', mask(2,:)
2810 print '(3i3)', count(mask)
2812 print '(3i3)', count(mask, 1)
2814 print '(3i3)', count(mask, 2)
2815 end program test_count
2822 @section @code{CPU_TIME} --- CPU elapsed time in seconds
2824 @cindex time, elapsed
2827 @item @emph{Description}:
2828 Returns a @code{REAL} value representing the elapsed CPU time in
2829 seconds. This is useful for testing segments of code to determine
2832 If a time source is available, time will be reported with microsecond
2833 resolution. If no time source is available, @var{TIME} is set to
2836 Note that @var{TIME} may contain a, system dependent, arbitrary offset
2837 and may not start with @code{0.0}. For @code{CPU_TIME}, the absolute
2838 value is meaningless, only differences between subsequent calls to
2839 this subroutine, as shown in the example below, should be used.
2842 @item @emph{Standard}:
2843 Fortran 95 and later
2848 @item @emph{Syntax}:
2849 @code{CALL CPU_TIME(TIME)}
2851 @item @emph{Arguments}:
2852 @multitable @columnfractions .15 .70
2853 @item @var{TIME} @tab The type shall be @code{REAL} with @code{INTENT(OUT)}.
2856 @item @emph{Return value}:
2859 @item @emph{Example}:
2861 program test_cpu_time
2862 real :: start, finish
2863 call cpu_time(start)
2864 ! put code to test here
2865 call cpu_time(finish)
2866 print '("Time = ",f6.3," seconds.")',finish-start
2867 end program test_cpu_time
2870 @item @emph{See also}:
2871 @ref{SYSTEM_CLOCK}, @ref{DATE_AND_TIME}
2877 @section @code{CSHIFT} --- Circular shift elements of an array
2879 @cindex array, shift circularly
2880 @cindex array, permutation
2881 @cindex array, rotate
2884 @item @emph{Description}:
2885 @code{CSHIFT(ARRAY, SHIFT [, DIM])} performs a circular shift on elements of
2886 @var{ARRAY} along the dimension of @var{DIM}. If @var{DIM} is omitted it is
2887 taken to be @code{1}. @var{DIM} is a scalar of type @code{INTEGER} in the
2888 range of @math{1 \leq DIM \leq n)} where @math{n} is the rank of @var{ARRAY}.
2889 If the rank of @var{ARRAY} is one, then all elements of @var{ARRAY} are shifted
2890 by @var{SHIFT} places. If rank is greater than one, then all complete rank one
2891 sections of @var{ARRAY} along the given dimension are shifted. Elements
2892 shifted out one end of each rank one section are shifted back in the other end.
2894 @item @emph{Standard}:
2895 Fortran 95 and later
2898 Transformational function
2900 @item @emph{Syntax}:
2901 @code{RESULT = CSHIFT(ARRAY, SHIFT [, DIM])}
2903 @item @emph{Arguments}:
2904 @multitable @columnfractions .15 .70
2905 @item @var{ARRAY} @tab Shall be an array of any type.
2906 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
2907 @item @var{DIM} @tab The type shall be @code{INTEGER}.
2910 @item @emph{Return value}:
2911 Returns an array of same type and rank as the @var{ARRAY} argument.
2913 @item @emph{Example}:
2916 integer, dimension(3,3) :: a
2917 a = reshape( (/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /), (/ 3, 3 /))
2918 print '(3i3)', a(1,:)
2919 print '(3i3)', a(2,:)
2920 print '(3i3)', a(3,:)
2921 a = cshift(a, SHIFT=(/1, 2, -1/), DIM=2)
2923 print '(3i3)', a(1,:)
2924 print '(3i3)', a(2,:)
2925 print '(3i3)', a(3,:)
2926 end program test_cshift
2933 @section @code{CTIME} --- Convert a time into a string
2935 @cindex time, conversion to string
2936 @cindex conversion, to string
2939 @item @emph{Description}:
2940 @code{CTIME} converts a system time value, such as returned by
2941 @code{TIME8()}, to a string of the form @samp{Sat Aug 19 18:13:14 1995}.
2943 This intrinsic is provided in both subroutine and function forms; however,
2944 only one form can be used in any given program unit.
2946 @item @emph{Standard}:
2950 Subroutine, function
2952 @item @emph{Syntax}:
2953 @multitable @columnfractions .80
2954 @item @code{CALL CTIME(TIME, RESULT)}.
2955 @item @code{RESULT = CTIME(TIME)}, (not recommended).
2958 @item @emph{Arguments}:
2959 @multitable @columnfractions .15 .70
2960 @item @var{TIME} @tab The type shall be of type @code{INTEGER(KIND=8)}.
2961 @item @var{RESULT} @tab The type shall be of type @code{CHARACTER} and
2965 @item @emph{Return value}:
2966 The converted date and time as a string.
2968 @item @emph{Example}:
2972 character(len=30) :: date
2975 ! Do something, main part of the program
2978 print *, 'Program was started on ', date
2979 end program test_ctime
2982 @item @emph{See Also}:
2983 @ref{GMTIME}, @ref{LTIME}, @ref{TIME}, @ref{TIME8}
2989 @section @code{DATE_AND_TIME} --- Date and time subroutine
2990 @fnindex DATE_AND_TIME
2991 @cindex date, current
2992 @cindex current date
2993 @cindex time, current
2994 @cindex current time
2997 @item @emph{Description}:
2998 @code{DATE_AND_TIME(DATE, TIME, ZONE, VALUES)} gets the corresponding date and
2999 time information from the real-time system clock. @var{DATE} is
3000 @code{INTENT(OUT)} and has form ccyymmdd. @var{TIME} is @code{INTENT(OUT)} and
3001 has form hhmmss.sss. @var{ZONE} is @code{INTENT(OUT)} and has form (+-)hhmm,
3002 representing the difference with respect to Coordinated Universal Time (UTC).
3003 Unavailable time and date parameters return blanks.
3005 @var{VALUES} is @code{INTENT(OUT)} and provides the following:
3007 @multitable @columnfractions .15 .30 .40
3008 @item @tab @code{VALUE(1)}: @tab The year
3009 @item @tab @code{VALUE(2)}: @tab The month
3010 @item @tab @code{VALUE(3)}: @tab The day of the month
3011 @item @tab @code{VALUE(4)}: @tab Time difference with UTC in minutes
3012 @item @tab @code{VALUE(5)}: @tab The hour of the day
3013 @item @tab @code{VALUE(6)}: @tab The minutes of the hour
3014 @item @tab @code{VALUE(7)}: @tab The seconds of the minute
3015 @item @tab @code{VALUE(8)}: @tab The milliseconds of the second
3018 @item @emph{Standard}:
3019 Fortran 95 and later
3024 @item @emph{Syntax}:
3025 @code{CALL DATE_AND_TIME([DATE, TIME, ZONE, VALUES])}
3027 @item @emph{Arguments}:
3028 @multitable @columnfractions .15 .70
3029 @item @var{DATE} @tab (Optional) The type shall be @code{CHARACTER(LEN=8)}
3030 or larger, and of default kind.
3031 @item @var{TIME} @tab (Optional) The type shall be @code{CHARACTER(LEN=10)}
3032 or larger, and of default kind.
3033 @item @var{ZONE} @tab (Optional) The type shall be @code{CHARACTER(LEN=5)}
3034 or larger, and of default kind.
3035 @item @var{VALUES}@tab (Optional) The type shall be @code{INTEGER(8)}.
3038 @item @emph{Return value}:
3041 @item @emph{Example}:
3043 program test_time_and_date
3044 character(8) :: date
3045 character(10) :: time
3046 character(5) :: zone
3047 integer,dimension(8) :: values
3048 ! using keyword arguments
3049 call date_and_time(date,time,zone,values)
3050 call date_and_time(DATE=date,ZONE=zone)
3051 call date_and_time(TIME=time)
3052 call date_and_time(VALUES=values)
3053 print '(a,2x,a,2x,a)', date, time, zone
3054 print '(8i5))', values
3055 end program test_time_and_date
3058 @item @emph{See also}:
3059 @ref{CPU_TIME}, @ref{SYSTEM_CLOCK}
3065 @section @code{DBLE} --- Double conversion function
3067 @cindex conversion, to real
3070 @item @emph{Description}:
3071 @code{DBLE(A)} Converts @var{A} to double precision real type.
3073 @item @emph{Standard}:
3074 Fortran 77 and later
3079 @item @emph{Syntax}:
3080 @code{RESULT = DBLE(A)}
3082 @item @emph{Arguments}:
3083 @multitable @columnfractions .15 .70
3084 @item @var{A} @tab The type shall be @code{INTEGER}, @code{REAL},
3088 @item @emph{Return value}:
3089 The return value is of type double precision real.
3091 @item @emph{Example}:
3096 complex :: z = (2.3,1.14)
3097 print *, dble(x), dble(i), dble(z)
3098 end program test_dble
3101 @item @emph{See also}:
3108 @section @code{DCMPLX} --- Double complex conversion function
3110 @cindex complex numbers, conversion to
3111 @cindex conversion, to complex
3114 @item @emph{Description}:
3115 @code{DCMPLX(X [,Y])} returns a double complex number where @var{X} is
3116 converted to the real component. If @var{Y} is present it is converted to the
3117 imaginary component. If @var{Y} is not present then the imaginary component is
3118 set to 0.0. If @var{X} is complex then @var{Y} must not be present.
3120 @item @emph{Standard}:
3126 @item @emph{Syntax}:
3127 @code{RESULT = DCMPLX(X [, Y])}
3129 @item @emph{Arguments}:
3130 @multitable @columnfractions .15 .70
3131 @item @var{X} @tab The type may be @code{INTEGER}, @code{REAL},
3133 @item @var{Y} @tab (Optional if @var{X} is not @code{COMPLEX}.) May be
3134 @code{INTEGER} or @code{REAL}.
3137 @item @emph{Return value}:
3138 The return value is of type @code{COMPLEX(8)}
3140 @item @emph{Example}:
3150 print *, dcmplx(x,i)
3151 end program test_dcmplx
3157 @section @code{DIGITS} --- Significant binary digits function
3159 @cindex model representation, significant digits
3162 @item @emph{Description}:
3163 @code{DIGITS(X)} returns the number of significant binary digits of the internal
3164 model representation of @var{X}. For example, on a system using a 32-bit
3165 floating point representation, a default real number would likely return 24.
3167 @item @emph{Standard}:
3168 Fortran 95 and later
3173 @item @emph{Syntax}:
3174 @code{RESULT = DIGITS(X)}
3176 @item @emph{Arguments}:
3177 @multitable @columnfractions .15 .70
3178 @item @var{X} @tab The type may be @code{INTEGER} or @code{REAL}.
3181 @item @emph{Return value}:
3182 The return value is of type @code{INTEGER}.
3184 @item @emph{Example}:
3187 integer :: i = 12345
3193 end program test_digits
3200 @section @code{DIM} --- Positive difference
3204 @cindex positive difference
3207 @item @emph{Description}:
3208 @code{DIM(X,Y)} returns the difference @code{X-Y} if the result is positive;
3209 otherwise returns zero.
3211 @item @emph{Standard}:
3212 Fortran 77 and later
3217 @item @emph{Syntax}:
3218 @code{RESULT = DIM(X, Y)}
3220 @item @emph{Arguments}:
3221 @multitable @columnfractions .15 .70
3222 @item @var{X} @tab The type shall be @code{INTEGER} or @code{REAL}
3223 @item @var{Y} @tab The type shall be the same type and kind as @var{X}.
3226 @item @emph{Return value}:
3227 The return value is of type @code{INTEGER} or @code{REAL}.
3229 @item @emph{Example}:
3235 x = dim(4.345_8, 2.111_8)
3238 end program test_dim
3241 @item @emph{Specific names}:
3242 @multitable @columnfractions .20 .20 .20 .25
3243 @item Name @tab Argument @tab Return type @tab Standard
3244 @item @code{DIM(X,Y)} @tab @code{REAL(4) X, Y} @tab @code{REAL(4)} @tab Fortran 77 and later
3245 @item @code{IDIM(X,Y)} @tab @code{INTEGER(4) X, Y} @tab @code{INTEGER(4)} @tab Fortran 77 and later
3246 @item @code{DDIM(X,Y)} @tab @code{REAL(8) X, Y} @tab @code{REAL(8)} @tab Fortran 77 and later
3253 @section @code{DOT_PRODUCT} --- Dot product function
3254 @fnindex DOT_PRODUCT
3256 @cindex vector product
3257 @cindex product, vector
3260 @item @emph{Description}:
3261 @code{DOT_PRODUCT(VECTOR_A, VECTOR_B)} computes the dot product multiplication
3262 of two vectors @var{VECTOR_A} and @var{VECTOR_B}. The two vectors may be
3263 either numeric or logical and must be arrays of rank one and of equal size. If
3264 the vectors are @code{INTEGER} or @code{REAL}, the result is
3265 @code{SUM(VECTOR_A*VECTOR_B)}. If the vectors are @code{COMPLEX}, the result
3266 is @code{SUM(CONJG(VECTOR_A)*VECTOR_B)}. If the vectors are @code{LOGICAL},
3267 the result is @code{ANY(VECTOR_A .AND. VECTOR_B)}.
3269 @item @emph{Standard}:
3270 Fortran 95 and later
3273 Transformational function
3275 @item @emph{Syntax}:
3276 @code{RESULT = DOT_PRODUCT(VECTOR_A, VECTOR_B)}
3278 @item @emph{Arguments}:
3279 @multitable @columnfractions .15 .70
3280 @item @var{VECTOR_A} @tab The type shall be numeric or @code{LOGICAL}, rank 1.
3281 @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.
3284 @item @emph{Return value}:
3285 If the arguments are numeric, the return value is a scalar of numeric type,
3286 @code{INTEGER}, @code{REAL}, or @code{COMPLEX}. If the arguments are
3287 @code{LOGICAL}, the return value is @code{.TRUE.} or @code{.FALSE.}.
3289 @item @emph{Example}:
3291 program test_dot_prod
3292 integer, dimension(3) :: a, b
3299 print *, dot_product(a,b)
3300 end program test_dot_prod
3307 @section @code{DPROD} --- Double product function
3309 @cindex product, double-precision
3312 @item @emph{Description}:
3313 @code{DPROD(X,Y)} returns the product @code{X*Y}.
3315 @item @emph{Standard}:
3316 Fortran 77 and later
3321 @item @emph{Syntax}:
3322 @code{RESULT = DPROD(X, Y)}
3324 @item @emph{Arguments}:
3325 @multitable @columnfractions .15 .70
3326 @item @var{X} @tab The type shall be @code{REAL}.
3327 @item @var{Y} @tab The type shall be @code{REAL}.
3330 @item @emph{Return value}:
3331 The return value is of type @code{REAL(8)}.
3333 @item @emph{Example}:
3341 end program test_dprod
3344 @item @emph{Specific names}:
3345 @multitable @columnfractions .20 .20 .20 .25
3346 @item Name @tab Argument @tab Return type @tab Standard
3347 @item @code{DPROD(X,Y)} @tab @code{REAL(4) X, Y} @tab @code{REAL(4)} @tab Fortran 77 and later
3354 @section @code{DREAL} --- Double real part function
3356 @cindex complex numbers, real part
3359 @item @emph{Description}:
3360 @code{DREAL(Z)} returns the real part of complex variable @var{Z}.
3362 @item @emph{Standard}:
3368 @item @emph{Syntax}:
3369 @code{RESULT = DREAL(A)}
3371 @item @emph{Arguments}:
3372 @multitable @columnfractions .15 .70
3373 @item @var{A} @tab The type shall be @code{COMPLEX(8)}.
3376 @item @emph{Return value}:
3377 The return value is of type @code{REAL(8)}.
3379 @item @emph{Example}:
3382 complex(8) :: z = (1.3_8,7.2_8)
3384 end program test_dreal
3387 @item @emph{See also}:
3395 @section @code{DTIME} --- Execution time subroutine (or function)
3397 @cindex time, elapsed
3398 @cindex elapsed time
3401 @item @emph{Description}:
3402 @code{DTIME(VALUES, TIME)} initially returns the number of seconds of runtime
3403 since the start of the process's execution in @var{TIME}. @var{VALUES}
3404 returns the user and system components of this time in @code{VALUES(1)} and
3405 @code{VALUES(2)} respectively. @var{TIME} is equal to @code{VALUES(1) +
3408 Subsequent invocations of @code{DTIME} return values accumulated since the
3409 previous invocation.
3411 On some systems, the underlying timings are represented using types with
3412 sufficiently small limits that overflows (wrap around) are possible, such as
3413 32-bit types. Therefore, the values returned by this intrinsic might be, or
3414 become, negative, or numerically less than previous values, during a single
3415 run of the compiled program.
3417 Please note, that this implementation is thread safe if used within OpenMP
3418 directives, i.e., its state will be consistent while called from multiple
3419 threads. However, if @code{DTIME} is called from multiple threads, the result
3420 is still the time since the last invocation. This may not give the intended
3421 results. If possible, use @code{CPU_TIME} instead.
3423 This intrinsic is provided in both subroutine and function forms; however,
3424 only one form can be used in any given program unit.
3426 @var{VALUES} and @var{TIME} are @code{INTENT(OUT)} and provide the following:
3428 @multitable @columnfractions .15 .30 .40
3429 @item @tab @code{VALUES(1)}: @tab User time in seconds.
3430 @item @tab @code{VALUES(2)}: @tab System time in seconds.
3431 @item @tab @code{TIME}: @tab Run time since start in seconds.
3434 @item @emph{Standard}:
3438 Subroutine, function
3440 @item @emph{Syntax}:
3441 @multitable @columnfractions .80
3442 @item @code{CALL DTIME(VALUES, TIME)}.
3443 @item @code{TIME = DTIME(VALUES)}, (not recommended).
3446 @item @emph{Arguments}:
3447 @multitable @columnfractions .15 .70
3448 @item @var{VALUES}@tab The type shall be @code{REAL(4), DIMENSION(2)}.
3449 @item @var{TIME}@tab The type shall be @code{REAL(4)}.
3452 @item @emph{Return value}:
3453 Elapsed time in seconds since the last invocation or since the start of program
3454 execution if not called before.
3456 @item @emph{Example}:
3460 real, dimension(2) :: tarray
3462 call dtime(tarray, result)
3466 do i=1,100000000 ! Just a delay
3469 call dtime(tarray, result)
3473 end program test_dtime
3476 @item @emph{See also}:
3484 @section @code{EOSHIFT} --- End-off shift elements of an array
3486 @cindex array, shift
3489 @item @emph{Description}:
3490 @code{EOSHIFT(ARRAY, SHIFT[, BOUNDARY, DIM])} performs an end-off shift on
3491 elements of @var{ARRAY} along the dimension of @var{DIM}. If @var{DIM} is
3492 omitted it is taken to be @code{1}. @var{DIM} is a scalar of type
3493 @code{INTEGER} in the range of @math{1 \leq DIM \leq n)} where @math{n} is the
3494 rank of @var{ARRAY}. If the rank of @var{ARRAY} is one, then all elements of
3495 @var{ARRAY} are shifted by @var{SHIFT} places. If rank is greater than one,
3496 then all complete rank one sections of @var{ARRAY} along the given dimension are
3497 shifted. Elements shifted out one end of each rank one section are dropped. If
3498 @var{BOUNDARY} is present then the corresponding value of from @var{BOUNDARY}
3499 is copied back in the other end. If @var{BOUNDARY} is not present then the
3500 following are copied in depending on the type of @var{ARRAY}.
3502 @multitable @columnfractions .15 .80
3503 @item @emph{Array Type} @tab @emph{Boundary Value}
3504 @item Numeric @tab 0 of the type and kind of @var{ARRAY}.
3505 @item Logical @tab @code{.FALSE.}.
3506 @item Character(@var{len}) @tab @var{len} blanks.
3509 @item @emph{Standard}:
3510 Fortran 95 and later
3513 Transformational function
3515 @item @emph{Syntax}:
3516 @code{RESULT = EOSHIFT(ARRAY, SHIFT [, BOUNDARY, DIM])}
3518 @item @emph{Arguments}:
3519 @multitable @columnfractions .15 .70
3520 @item @var{ARRAY} @tab May be any type, not scalar.
3521 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
3522 @item @var{BOUNDARY} @tab Same type as @var{ARRAY}.
3523 @item @var{DIM} @tab The type shall be @code{INTEGER}.
3526 @item @emph{Return value}:
3527 Returns an array of same type and rank as the @var{ARRAY} argument.
3529 @item @emph{Example}:
3531 program test_eoshift
3532 integer, dimension(3,3) :: a
3533 a = reshape( (/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /), (/ 3, 3 /))
3534 print '(3i3)', a(1,:)
3535 print '(3i3)', a(2,:)
3536 print '(3i3)', a(3,:)
3537 a = EOSHIFT(a, SHIFT=(/1, 2, 1/), BOUNDARY=-5, DIM=2)
3539 print '(3i3)', a(1,:)
3540 print '(3i3)', a(2,:)
3541 print '(3i3)', a(3,:)
3542 end program test_eoshift
3549 @section @code{EPSILON} --- Epsilon function
3551 @cindex model representation, epsilon
3554 @item @emph{Description}:
3555 @code{EPSILON(X)} returns the smallest number @var{E} of the same kind
3556 as @var{X} such that @math{1 + E > 1}.
3558 @item @emph{Standard}:
3559 Fortran 95 and later
3564 @item @emph{Syntax}:
3565 @code{RESULT = EPSILON(X)}
3567 @item @emph{Arguments}:
3568 @multitable @columnfractions .15 .70
3569 @item @var{X} @tab The type shall be @code{REAL}.
3572 @item @emph{Return value}:
3573 The return value is of same type as the argument.
3575 @item @emph{Example}:
3577 program test_epsilon
3582 end program test_epsilon
3589 @section @code{ERF} --- Error function
3591 @cindex error function
3594 @item @emph{Description}:
3595 @code{ERF(X)} computes the error function of @var{X}.
3597 @item @emph{Standard}:
3598 Fortran 2008 and later
3603 @item @emph{Syntax}:
3604 @code{RESULT = ERF(X)}
3606 @item @emph{Arguments}:
3607 @multitable @columnfractions .15 .70
3608 @item @var{X} @tab The type shall be @code{REAL}.
3611 @item @emph{Return value}:
3612 The return value is of type @code{REAL}, of the same kind as
3613 @var{X} and lies in the range @math{-1 \leq erf (x) \leq 1 }.
3615 @item @emph{Example}:
3618 real(8) :: x = 0.17_8
3620 end program test_erf
3623 @item @emph{Specific names}:
3624 @multitable @columnfractions .20 .20 .20 .25
3625 @item Name @tab Argument @tab Return type @tab Standard
3626 @item @code{DERF(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
3633 @section @code{ERFC} --- Error function
3635 @cindex error function, complementary
3638 @item @emph{Description}:
3639 @code{ERFC(X)} computes the complementary error function of @var{X}.
3641 @item @emph{Standard}:
3642 Fortran 2008 and later
3647 @item @emph{Syntax}:
3648 @code{RESULT = ERFC(X)}
3650 @item @emph{Arguments}:
3651 @multitable @columnfractions .15 .70
3652 @item @var{X} @tab The type shall be @code{REAL}.
3655 @item @emph{Return value}:
3656 The return value is of type @code{REAL} and of the same kind as @var{X}.
3657 It lies in the range @math{ 0 \leq erfc (x) \leq 2 }.
3659 @item @emph{Example}:
3662 real(8) :: x = 0.17_8
3664 end program test_erfc
3667 @item @emph{Specific names}:
3668 @multitable @columnfractions .20 .20 .20 .25
3669 @item Name @tab Argument @tab Return type @tab Standard
3670 @item @code{DERFC(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
3677 @section @code{ERFC_SCALED} --- Error function
3678 @fnindex ERFC_SCALED
3679 @cindex error function, complementary, exponentially-scaled
3682 @item @emph{Description}:
3683 @code{ERFC_SCALED(X)} computes the exponentially-scaled complementary
3684 error function of @var{X}.
3686 @item @emph{Standard}:
3687 Fortran 2008 and later
3692 @item @emph{Syntax}:
3693 @code{RESULT = ERFC_SCALED(X)}
3695 @item @emph{Arguments}:
3696 @multitable @columnfractions .15 .70
3697 @item @var{X} @tab The type shall be @code{REAL}.
3700 @item @emph{Return value}:
3701 The return value is of type @code{REAL} and of the same kind as @var{X}.
3703 @item @emph{Example}:
3705 program test_erfc_scaled
3706 real(8) :: x = 0.17_8
3708 end program test_erfc_scaled
3715 @section @code{ETIME} --- Execution time subroutine (or function)
3717 @cindex time, elapsed
3720 @item @emph{Description}:
3721 @code{ETIME(VALUES, TIME)} returns the number of seconds of runtime
3722 since the start of the process's execution in @var{TIME}. @var{VALUES}
3723 returns the user and system components of this time in @code{VALUES(1)} and
3724 @code{VALUES(2)} respectively. @var{TIME} is equal to @code{VALUES(1) + VALUES(2)}.
3726 On some systems, the underlying timings are represented using types with
3727 sufficiently small limits that overflows (wrap around) are possible, such as
3728 32-bit types. Therefore, the values returned by this intrinsic might be, or
3729 become, negative, or numerically less than previous values, during a single
3730 run of the compiled program.
3732 This intrinsic is provided in both subroutine and function forms; however,
3733 only one form can be used in any given program unit.
3735 @var{VALUES} and @var{TIME} are @code{INTENT(OUT)} and provide the following:
3737 @multitable @columnfractions .15 .30 .60
3738 @item @tab @code{VALUES(1)}: @tab User time in seconds.
3739 @item @tab @code{VALUES(2)}: @tab System time in seconds.
3740 @item @tab @code{TIME}: @tab Run time since start in seconds.
3743 @item @emph{Standard}:
3747 Subroutine, function
3749 @item @emph{Syntax}:
3750 @multitable @columnfractions .80
3751 @item @code{CALL ETIME(VALUES, TIME)}.
3752 @item @code{TIME = ETIME(VALUES)}, (not recommended).
3755 @item @emph{Arguments}:
3756 @multitable @columnfractions .15 .70
3757 @item @var{VALUES}@tab The type shall be @code{REAL(4), DIMENSION(2)}.
3758 @item @var{TIME}@tab The type shall be @code{REAL(4)}.
3761 @item @emph{Return value}:
3762 Elapsed time in seconds since the start of program execution.
3764 @item @emph{Example}:
3768 real, dimension(2) :: tarray
3770 call ETIME(tarray, result)
3774 do i=1,100000000 ! Just a delay
3777 call ETIME(tarray, result)
3781 end program test_etime
3784 @item @emph{See also}:
3792 @section @code{EXIT} --- Exit the program with status.
3794 @cindex program termination
3795 @cindex terminate program
3798 @item @emph{Description}:
3799 @code{EXIT} causes immediate termination of the program with status. If status
3800 is omitted it returns the canonical @emph{success} for the system. All Fortran
3801 I/O units are closed.
3803 @item @emph{Standard}:
3809 @item @emph{Syntax}:
3810 @code{CALL EXIT([STATUS])}
3812 @item @emph{Arguments}:
3813 @multitable @columnfractions .15 .70
3814 @item @var{STATUS} @tab Shall be an @code{INTEGER} of the default kind.
3817 @item @emph{Return value}:
3818 @code{STATUS} is passed to the parent process on exit.
3820 @item @emph{Example}:
3823 integer :: STATUS = 0
3824 print *, 'This program is going to exit.'
3826 end program test_exit
3829 @item @emph{See also}:
3830 @ref{ABORT}, @ref{KILL}
3836 @section @code{EXP} --- Exponential function
3842 @cindex exponential function
3843 @cindex logarithmic function, inverse
3846 @item @emph{Description}:
3847 @code{EXP(X)} computes the base @math{e} exponential of @var{X}.
3849 @item @emph{Standard}:
3850 Fortran 77 and later, has overloads that are GNU extensions
3855 @item @emph{Syntax}:
3856 @code{RESULT = EXP(X)}
3858 @item @emph{Arguments}:
3859 @multitable @columnfractions .15 .70
3860 @item @var{X} @tab The type shall be @code{REAL} or
3864 @item @emph{Return value}:
3865 The return value has same type and kind as @var{X}.
3867 @item @emph{Example}:
3872 end program test_exp
3875 @item @emph{Specific names}:
3876 @multitable @columnfractions .20 .20 .20 .25
3877 @item Name @tab Argument @tab Return type @tab Standard
3878 @item @code{EXP(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
3879 @item @code{DEXP(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
3880 @item @code{CEXP(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab Fortran 77 and later
3881 @item @code{ZEXP(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
3882 @item @code{CDEXP(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
3889 @section @code{EXPONENT} --- Exponent function
3891 @cindex real number, exponent
3892 @cindex floating point, exponent
3895 @item @emph{Description}:
3896 @code{EXPONENT(X)} returns the value of the exponent part of @var{X}. If @var{X}
3897 is zero the value returned is zero.
3899 @item @emph{Standard}:
3900 Fortran 95 and later
3905 @item @emph{Syntax}:
3906 @code{RESULT = EXPONENT(X)}
3908 @item @emph{Arguments}:
3909 @multitable @columnfractions .15 .70
3910 @item @var{X} @tab The type shall be @code{REAL}.
3913 @item @emph{Return value}:
3914 The return value is of type default @code{INTEGER}.
3916 @item @emph{Example}:
3918 program test_exponent
3923 print *, exponent(0.0)
3924 end program test_exponent
3931 @section @code{FDATE} --- Get the current time as a string
3933 @cindex time, current
3934 @cindex current time
3935 @cindex date, current
3936 @cindex current date
3939 @item @emph{Description}:
3940 @code{FDATE(DATE)} returns the current date (using the same format as
3941 @code{CTIME}) in @var{DATE}. It is equivalent to @code{CALL CTIME(DATE,
3944 This intrinsic is provided in both subroutine and function forms; however,
3945 only one form can be used in any given program unit.
3947 @var{DATE} is an @code{INTENT(OUT)} @code{CHARACTER} variable of the
3950 @item @emph{Standard}:
3954 Subroutine, function
3956 @item @emph{Syntax}:
3957 @multitable @columnfractions .80
3958 @item @code{CALL FDATE(DATE)}.
3959 @item @code{DATE = FDATE()}, (not recommended).
3962 @item @emph{Arguments}:
3963 @multitable @columnfractions .15 .70
3964 @item @var{DATE}@tab The type shall be of type @code{CHARACTER} of the
3968 @item @emph{Return value}:
3969 The current date as a string.
3971 @item @emph{Example}:
3975 character(len=30) :: date
3977 print *, 'Program started on ', date
3978 do i = 1, 100000000 ! Just a delay
3982 print *, 'Program ended on ', date
3983 end program test_fdate
3990 @section @code{FGET} --- Read a single character in stream mode from stdin
3992 @cindex read character, stream mode
3993 @cindex stream mode, read character
3994 @cindex file operation, read character
3997 @item @emph{Description}:
3998 Read a single character in stream mode from stdin by bypassing normal
3999 formatted output. Stream I/O should not be mixed with normal record-oriented
4000 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
4002 This intrinsic is provided in both subroutine and function forms; however,
4003 only one form can be used in any given program unit.
4005 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
4006 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
4007 Programmers should consider the use of new stream IO feature in new code
4008 for future portability. See also @ref{Fortran 2003 status}.
4010 @item @emph{Standard}:
4014 Subroutine, function
4016 @item @emph{Syntax}:
4017 @code{CALL FGET(C [, STATUS])}
4019 @item @emph{Arguments}:
4020 @multitable @columnfractions .15 .70
4021 @item @var{C} @tab The type shall be @code{CHARACTER} and of default
4023 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
4024 Returns 0 on success, -1 on end-of-file, and a system specific positive
4025 error code otherwise.
4028 @item @emph{Example}:
4031 INTEGER, PARAMETER :: strlen = 100
4032 INTEGER :: status, i = 1
4033 CHARACTER(len=strlen) :: str = ""
4035 WRITE (*,*) 'Enter text:'
4037 CALL fget(str(i:i), status)
4038 if (status /= 0 .OR. i > strlen) exit
4041 WRITE (*,*) TRIM(str)
4045 @item @emph{See also}:
4046 @ref{FGETC}, @ref{FPUT}, @ref{FPUTC}
4052 @section @code{FGETC} --- Read a single character in stream mode
4054 @cindex read character, stream mode
4055 @cindex stream mode, read character
4056 @cindex file operation, read character
4059 @item @emph{Description}:
4060 Read a single character in stream mode by bypassing normal formatted output.
4061 Stream I/O should not be mixed with normal record-oriented (formatted or
4062 unformatted) I/O on the same unit; the results are unpredictable.
4064 This intrinsic is provided in both subroutine and function forms; however,
4065 only one form can be used in any given program unit.
4067 Note that the @code{FGET} intrinsic is provided for backwards compatibility
4068 with @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
4069 Programmers should consider the use of new stream IO feature in new code
4070 for future portability. See also @ref{Fortran 2003 status}.
4072 @item @emph{Standard}:
4076 Subroutine, function
4078 @item @emph{Syntax}:
4079 @code{CALL FGETC(UNIT, C [, STATUS])}
4081 @item @emph{Arguments}:
4082 @multitable @columnfractions .15 .70
4083 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
4084 @item @var{C} @tab The type shall be @code{CHARACTER} and of default
4086 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
4087 Returns 0 on success, -1 on end-of-file and a system specific positive
4088 error code otherwise.
4091 @item @emph{Example}:
4094 INTEGER :: fd = 42, status
4097 OPEN(UNIT=fd, FILE="/etc/passwd", ACTION="READ", STATUS = "OLD")
4099 CALL fgetc(fd, c, status)
4100 IF (status /= 0) EXIT
4107 @item @emph{See also}:
4108 @ref{FGET}, @ref{FPUT}, @ref{FPUTC}
4114 @section @code{FLOOR} --- Integer floor function
4117 @cindex rounding, floor
4120 @item @emph{Description}:
4121 @code{FLOOR(A)} returns the greatest integer less than or equal to @var{X}.
4123 @item @emph{Standard}:
4124 Fortran 95 and later
4129 @item @emph{Syntax}:
4130 @code{RESULT = FLOOR(A [, KIND])}
4132 @item @emph{Arguments}:
4133 @multitable @columnfractions .15 .70
4134 @item @var{A} @tab The type shall be @code{REAL}.
4135 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
4136 expression indicating the kind parameter of the result.
4139 @item @emph{Return value}:
4140 The return value is of type @code{INTEGER(KIND)} if @var{KIND} is present
4141 and of default-kind @code{INTEGER} otherwise.
4143 @item @emph{Example}:
4148 print *, floor(x) ! returns 63
4149 print *, floor(y) ! returns -64
4150 end program test_floor
4153 @item @emph{See also}:
4154 @ref{CEILING}, @ref{NINT}
4161 @section @code{FLUSH} --- Flush I/O unit(s)
4163 @cindex file operation, flush
4166 @item @emph{Description}:
4167 Flushes Fortran unit(s) currently open for output. Without the optional
4168 argument, all units are flushed, otherwise just the unit specified.
4170 @item @emph{Standard}:
4176 @item @emph{Syntax}:
4177 @code{CALL FLUSH(UNIT)}
4179 @item @emph{Arguments}:
4180 @multitable @columnfractions .15 .70
4181 @item @var{UNIT} @tab (Optional) The type shall be @code{INTEGER}.
4185 Beginning with the Fortran 2003 standard, there is a @code{FLUSH}
4186 statement that should be preferred over the @code{FLUSH} intrinsic.
4193 @section @code{FNUM} --- File number function
4195 @cindex file operation, file number
4198 @item @emph{Description}:
4199 @code{FNUM(UNIT)} returns the POSIX file descriptor number corresponding to the
4200 open Fortran I/O unit @code{UNIT}.
4202 @item @emph{Standard}:
4208 @item @emph{Syntax}:
4209 @code{RESULT = FNUM(UNIT)}
4211 @item @emph{Arguments}:
4212 @multitable @columnfractions .15 .70
4213 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
4216 @item @emph{Return value}:
4217 The return value is of type @code{INTEGER}
4219 @item @emph{Example}:
4223 open (unit=10, status = "scratch")
4227 end program test_fnum
4234 @section @code{FPUT} --- Write a single character in stream mode to stdout
4236 @cindex write character, stream mode
4237 @cindex stream mode, write character
4238 @cindex file operation, write character
4241 @item @emph{Description}:
4242 Write a single character in stream mode to stdout by bypassing normal
4243 formatted output. Stream I/O should not be mixed with normal record-oriented
4244 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
4246 This intrinsic is provided in both subroutine and function forms; however,
4247 only one form can be used in any given program unit.
4249 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
4250 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
4251 Programmers should consider the use of new stream IO feature in new code
4252 for future portability. See also @ref{Fortran 2003 status}.
4254 @item @emph{Standard}:
4258 Subroutine, function
4260 @item @emph{Syntax}:
4261 @code{CALL FPUT(C [, STATUS])}
4263 @item @emph{Arguments}:
4264 @multitable @columnfractions .15 .70
4265 @item @var{C} @tab The type shall be @code{CHARACTER} and of default
4267 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
4268 Returns 0 on success, -1 on end-of-file and a system specific positive
4269 error code otherwise.
4272 @item @emph{Example}:
4275 CHARACTER(len=10) :: str = "gfortran"
4277 DO i = 1, len_trim(str)
4283 @item @emph{See also}:
4284 @ref{FPUTC}, @ref{FGET}, @ref{FGETC}
4290 @section @code{FPUTC} --- Write a single character in stream mode
4292 @cindex write character, stream mode
4293 @cindex stream mode, write character
4294 @cindex file operation, write character
4297 @item @emph{Description}:
4298 Write a single character in stream mode by bypassing normal formatted
4299 output. Stream I/O should not be mixed with normal record-oriented
4300 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
4302 This intrinsic is provided in both subroutine and function forms; however,
4303 only one form can be used in any given program unit.
4305 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
4306 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
4307 Programmers should consider the use of new stream IO feature in new code
4308 for future portability. See also @ref{Fortran 2003 status}.
4310 @item @emph{Standard}:
4314 Subroutine, function
4316 @item @emph{Syntax}:
4317 @code{CALL FPUTC(UNIT, C [, STATUS])}
4319 @item @emph{Arguments}:
4320 @multitable @columnfractions .15 .70
4321 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
4322 @item @var{C} @tab The type shall be @code{CHARACTER} and of default
4324 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
4325 Returns 0 on success, -1 on end-of-file and a system specific positive
4326 error code otherwise.
4329 @item @emph{Example}:
4332 CHARACTER(len=10) :: str = "gfortran"
4333 INTEGER :: fd = 42, i
4335 OPEN(UNIT = fd, FILE = "out", ACTION = "WRITE", STATUS="NEW")
4336 DO i = 1, len_trim(str)
4337 CALL fputc(fd, str(i:i))
4343 @item @emph{See also}:
4344 @ref{FPUT}, @ref{FGET}, @ref{FGETC}
4350 @section @code{FRACTION} --- Fractional part of the model representation
4352 @cindex real number, fraction
4353 @cindex floating point, fraction
4356 @item @emph{Description}:
4357 @code{FRACTION(X)} returns the fractional part of the model
4358 representation of @code{X}.
4360 @item @emph{Standard}:
4361 Fortran 95 and later
4366 @item @emph{Syntax}:
4367 @code{Y = FRACTION(X)}
4369 @item @emph{Arguments}:
4370 @multitable @columnfractions .15 .70
4371 @item @var{X} @tab The type of the argument shall be a @code{REAL}.
4374 @item @emph{Return value}:
4375 The return value is of the same type and kind as the argument.
4376 The fractional part of the model representation of @code{X} is returned;
4377 it is @code{X * RADIX(X)**(-EXPONENT(X))}.
4379 @item @emph{Example}:
4381 program test_fraction
4384 print *, fraction(x), x * radix(x)**(-exponent(x))
4385 end program test_fraction
4393 @section @code{FREE} --- Frees memory
4395 @cindex pointer, cray
4398 @item @emph{Description}:
4399 Frees memory previously allocated by @code{MALLOC()}. The @code{FREE}
4400 intrinsic is an extension intended to be used with Cray pointers, and is
4401 provided in GNU Fortran to allow user to compile legacy code. For
4402 new code using Fortran 95 pointers, the memory de-allocation intrinsic is
4405 @item @emph{Standard}:
4411 @item @emph{Syntax}:
4412 @code{CALL FREE(PTR)}
4414 @item @emph{Arguments}:
4415 @multitable @columnfractions .15 .70
4416 @item @var{PTR} @tab The type shall be @code{INTEGER}. It represents the
4417 location of the memory that should be de-allocated.
4420 @item @emph{Return value}:
4423 @item @emph{Example}:
4424 See @code{MALLOC} for an example.
4426 @item @emph{See also}:
4433 @section @code{FSEEK} --- Low level file positioning subroutine
4435 @cindex file operation, seek
4436 @cindex file operation, position
4439 @item @emph{Description}:
4440 Moves @var{UNIT} to the specified @var{OFFSET}. If @var{WHENCE}
4441 is set to 0, the @var{OFFSET} is taken as an absolute value @code{SEEK_SET},
4442 if set to 1, @var{OFFSET} is taken to be relative to the current position
4443 @code{SEEK_CUR}, and if set to 2 relative to the end of the file @code{SEEK_END}.
4444 On error, @var{STATUS} is set to a nonzero value. If @var{STATUS} the seek
4447 This intrinsic routine is not fully backwards compatible with @command{g77}.
4448 In @command{g77}, the @code{FSEEK} takes a statement label instead of a
4449 @var{STATUS} variable. If FSEEK is used in old code, change
4451 CALL FSEEK(UNIT, OFFSET, WHENCE, *label)
4456 CALL FSEEK(UNIT, OFFSET, WHENCE, status)
4457 IF (status /= 0) GOTO label
4460 Please note that GNU Fortran provides the Fortran 2003 Stream facility.
4461 Programmers should consider the use of new stream IO feature in new code
4462 for future portability. See also @ref{Fortran 2003 status}.
4464 @item @emph{Standard}:
4470 @item @emph{Syntax}:
4471 @code{CALL FSEEK(UNIT, OFFSET, WHENCE[, STATUS])}
4473 @item @emph{Arguments}:
4474 @multitable @columnfractions .15 .70
4475 @item @var{UNIT} @tab Shall be a scalar of type @code{INTEGER}.
4476 @item @var{OFFSET} @tab Shall be a scalar of type @code{INTEGER}.
4477 @item @var{WHENCE} @tab Shall be a scalar of type @code{INTEGER}.
4478 Its value shall be either 0, 1 or 2.
4479 @item @var{STATUS} @tab (Optional) shall be a scalar of type
4483 @item @emph{Example}:
4486 INTEGER, PARAMETER :: SEEK_SET = 0, SEEK_CUR = 1, SEEK_END = 2
4487 INTEGER :: fd, offset, ierr
4493 OPEN(UNIT=fd, FILE="fseek.test")
4494 CALL FSEEK(fd, offset, SEEK_SET, ierr) ! move to OFFSET
4495 print *, FTELL(fd), ierr
4497 CALL FSEEK(fd, 0, SEEK_END, ierr) ! move to end
4498 print *, FTELL(fd), ierr
4500 CALL FSEEK(fd, 0, SEEK_SET, ierr) ! move to beginning
4501 print *, FTELL(fd), ierr
4507 @item @emph{See also}:
4514 @section @code{FSTAT} --- Get file status
4516 @cindex file system, file status
4519 @item @emph{Description}:
4520 @code{FSTAT} is identical to @ref{STAT}, except that information about an
4521 already opened file is obtained.
4523 The elements in @code{VALUES} are the same as described by @ref{STAT}.
4525 This intrinsic is provided in both subroutine and function forms; however,
4526 only one form can be used in any given program unit.
4528 @item @emph{Standard}:
4532 Subroutine, function
4534 @item @emph{Syntax}:
4535 @code{CALL FSTAT(UNIT, VALUES [, STATUS])}
4537 @item @emph{Arguments}:
4538 @multitable @columnfractions .15 .70
4539 @item @var{UNIT} @tab An open I/O unit number of type @code{INTEGER}.
4540 @item @var{VALUES} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
4541 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}. Returns 0
4542 on success and a system specific error code otherwise.
4545 @item @emph{Example}:
4546 See @ref{STAT} for an example.
4548 @item @emph{See also}:
4549 To stat a link: @ref{LSTAT}, to stat a file: @ref{STAT}
4555 @section @code{FTELL} --- Current stream position
4557 @cindex file operation, position
4560 @item @emph{Description}:
4561 Retrieves the current position within an open file.
4563 This intrinsic is provided in both subroutine and function forms; however,
4564 only one form can be used in any given program unit.
4566 @item @emph{Standard}:
4570 Subroutine, function
4572 @item @emph{Syntax}:
4573 @multitable @columnfractions .80
4574 @item @code{CALL FTELL(UNIT, OFFSET)}
4575 @item @code{OFFSET = FTELL(UNIT)}
4578 @item @emph{Arguments}:
4579 @multitable @columnfractions .15 .70
4580 @item @var{OFFSET} @tab Shall of type @code{INTEGER}.
4581 @item @var{UNIT} @tab Shall of type @code{INTEGER}.
4584 @item @emph{Return value}:
4585 In either syntax, @var{OFFSET} is set to the current offset of unit
4586 number @var{UNIT}, or to @math{-1} if the unit is not currently open.
4588 @item @emph{Example}:
4592 OPEN(10, FILE="temp.dat")
4598 @item @emph{See also}:
4605 @section @code{GAMMA} --- Gamma function
4608 @cindex Gamma function
4609 @cindex Factorial function
4612 @item @emph{Description}:
4613 @code{GAMMA(X)} computes Gamma (@math{\Gamma}) of @var{X}. For positive,
4614 integer values of @var{X} the Gamma function simplifies to the factorial
4615 function @math{\Gamma(x)=(x-1)!}.
4619 \Gamma(x) = \int_0^\infty t^{x-1}{\rm e}^{-t}\,{\rm d}t
4623 @item @emph{Standard}:
4624 Fortran 2008 and later
4629 @item @emph{Syntax}:
4632 @item @emph{Arguments}:
4633 @multitable @columnfractions .15 .70
4634 @item @var{X} @tab Shall be of type @code{REAL} and neither zero
4635 nor a negative integer.
4638 @item @emph{Return value}:
4639 The return value is of type @code{REAL} of the same kind as @var{X}.
4641 @item @emph{Example}:
4645 x = gamma(x) ! returns 1.0
4646 end program test_gamma
4649 @item @emph{Specific names}:
4650 @multitable @columnfractions .20 .20 .20 .25
4651 @item Name @tab Argument @tab Return type @tab Standard
4652 @item @code{GAMMA(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab GNU Extension
4653 @item @code{DGAMMA(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU Extension
4656 @item @emph{See also}:
4657 Logarithm of the Gamma function: @ref{LOG_GAMMA}
4664 @section @code{GERROR} --- Get last system error message
4666 @cindex system, error handling
4669 @item @emph{Description}:
4670 Returns the system error message corresponding to the last system error.
4671 This resembles the functionality of @code{strerror(3)} in C.
4673 @item @emph{Standard}:
4679 @item @emph{Syntax}:
4680 @code{CALL GERROR(RESULT)}
4682 @item @emph{Arguments}:
4683 @multitable @columnfractions .15 .70
4684 @item @var{RESULT} @tab Shall of type @code{CHARACTER} and of default
4687 @item @emph{Example}:
4690 CHARACTER(len=100) :: msg
4696 @item @emph{See also}:
4697 @ref{IERRNO}, @ref{PERROR}
4703 @section @code{GETARG} --- Get command line arguments
4705 @cindex command-line arguments
4706 @cindex arguments, to program
4709 @item @emph{Description}:
4710 Retrieve the @var{POS}-th argument that was passed on the
4711 command line when the containing program was invoked.
4713 This intrinsic routine is provided for backwards compatibility with
4714 GNU Fortran 77. In new code, programmers should consider the use of
4715 the @ref{GET_COMMAND_ARGUMENT} intrinsic defined by the Fortran 2003
4718 @item @emph{Standard}:
4724 @item @emph{Syntax}:
4725 @code{CALL GETARG(POS, VALUE)}
4727 @item @emph{Arguments}:
4728 @multitable @columnfractions .15 .70
4729 @item @var{POS} @tab Shall be of type @code{INTEGER} and not wider than
4730 the default integer kind; @math{@var{POS} \geq 0}
4731 @item @var{VALUE} @tab Shall be of type @code{CHARACTER} and of default
4733 @item @var{VALUE} @tab Shall be of type @code{CHARACTER}.
4736 @item @emph{Return value}:
4737 After @code{GETARG} returns, the @var{VALUE} argument holds the
4738 @var{POS}th command line argument. If @var{VALUE} can not hold the
4739 argument, it is truncated to fit the length of @var{VALUE}. If there are
4740 less than @var{POS} arguments specified at the command line, @var{VALUE}
4741 will be filled with blanks. If @math{@var{POS} = 0}, @var{VALUE} is set
4742 to the name of the program (on systems that support this feature).
4744 @item @emph{Example}:
4748 CHARACTER(len=32) :: arg
4757 @item @emph{See also}:
4758 GNU Fortran 77 compatibility function: @ref{IARGC}
4760 Fortran 2003 functions and subroutines: @ref{GET_COMMAND},
4761 @ref{GET_COMMAND_ARGUMENT}, @ref{COMMAND_ARGUMENT_COUNT}
4767 @section @code{GET_COMMAND} --- Get the entire command line
4768 @fnindex GET_COMMAND
4769 @cindex command-line arguments
4770 @cindex arguments, to program
4773 @item @emph{Description}:
4774 Retrieve the entire command line that was used to invoke the program.
4776 @item @emph{Standard}:
4777 Fortran 2003 and later
4782 @item @emph{Syntax}:
4783 @code{CALL GET_COMMAND([COMMAND, LENGTH, STATUS])}
4785 @item @emph{Arguments}:
4786 @multitable @columnfractions .15 .70
4787 @item @var{COMMAND} @tab (Optional) shall be of type @code{CHARACTER} and
4789 @item @var{LENGTH} @tab (Optional) Shall be of type @code{INTEGER} and of
4791 @item @var{STATUS} @tab (Optional) Shall be of type @code{INTEGER} and of
4795 @item @emph{Return value}:
4796 If @var{COMMAND} is present, stores the entire command line that was used
4797 to invoke the program in @var{COMMAND}. If @var{LENGTH} is present, it is
4798 assigned the length of the command line. If @var{STATUS} is present, it
4799 is assigned 0 upon success of the command, -1 if @var{COMMAND} is too
4800 short to store the command line, or a positive value in case of an error.
4802 @item @emph{Example}:
4804 PROGRAM test_get_command
4805 CHARACTER(len=255) :: cmd
4806 CALL get_command(cmd)
4807 WRITE (*,*) TRIM(cmd)
4811 @item @emph{See also}:
4812 @ref{GET_COMMAND_ARGUMENT}, @ref{COMMAND_ARGUMENT_COUNT}
4817 @node GET_COMMAND_ARGUMENT
4818 @section @code{GET_COMMAND_ARGUMENT} --- Get command line arguments
4819 @fnindex GET_COMMAND_ARGUMENT
4820 @cindex command-line arguments
4821 @cindex arguments, to program
4824 @item @emph{Description}:
4825 Retrieve the @var{NUMBER}-th argument that was passed on the
4826 command line when the containing program was invoked.
4828 @item @emph{Standard}:
4829 Fortran 2003 and later
4834 @item @emph{Syntax}:
4835 @code{CALL GET_COMMAND_ARGUMENT(NUMBER [, VALUE, LENGTH, STATUS])}
4837 @item @emph{Arguments}:
4838 @multitable @columnfractions .15 .70
4839 @item @var{NUMBER} @tab Shall be a scalar of type @code{INTEGER} and of
4840 default kind, @math{@var{NUMBER} \geq 0}
4841 @item @var{VALUE} @tab Shall be a scalar of type @code{CHARACTER}
4842 and of default kind.
4843 @item @var{LENGTH} @tab (Option) Shall be a scalar of type @code{INTEGER}
4844 and of default kind.
4845 @item @var{STATUS} @tab (Option) Shall be a scalar of type @code{INTEGER}
4846 and of default kind.
4849 @item @emph{Return value}:
4850 After @code{GET_COMMAND_ARGUMENT} returns, the @var{VALUE} argument holds the
4851 @var{NUMBER}-th command line argument. If @var{VALUE} can not hold the argument, it is
4852 truncated to fit the length of @var{VALUE}. If there are less than @var{NUMBER}
4853 arguments specified at the command line, @var{VALUE} will be filled with blanks.
4854 If @math{@var{NUMBER} = 0}, @var{VALUE} is set to the name of the program (on
4855 systems that support this feature). The @var{LENGTH} argument contains the
4856 length of the @var{NUMBER}-th command line argument. If the argument retrieval
4857 fails, @var{STATUS} is a positive number; if @var{VALUE} contains a truncated
4858 command line argument, @var{STATUS} is -1; and otherwise the @var{STATUS} is
4861 @item @emph{Example}:
4863 PROGRAM test_get_command_argument
4865 CHARACTER(len=32) :: arg
4869 CALL get_command_argument(i, arg)
4870 IF (LEN_TRIM(arg) == 0) EXIT
4872 WRITE (*,*) TRIM(arg)
4878 @item @emph{See also}:
4879 @ref{GET_COMMAND}, @ref{COMMAND_ARGUMENT_COUNT}
4885 @section @code{GETCWD} --- Get current working directory
4887 @cindex system, working directory
4890 @item @emph{Description}:
4891 Get current working directory.
4893 This intrinsic is provided in both subroutine and function forms; however,
4894 only one form can be used in any given program unit.
4896 @item @emph{Standard}:
4900 Subroutine, function
4902 @item @emph{Syntax}:
4903 @code{CALL GETCWD(C [, STATUS])}
4905 @item @emph{Arguments}:
4906 @multitable @columnfractions .15 .70
4907 @item @var{C} @tab The type shall be @code{CHARACTER} and of default kind.
4908 @item @var{STATUS} @tab (Optional) status flag. Returns 0 on success,
4909 a system specific and nonzero error code otherwise.
4912 @item @emph{Example}:
4915 CHARACTER(len=255) :: cwd
4917 WRITE(*,*) TRIM(cwd)
4921 @item @emph{See also}:
4928 @section @code{GETENV} --- Get an environmental variable
4930 @cindex environment variable
4933 @item @emph{Description}:
4934 Get the @var{VALUE} of the environmental variable @var{NAME}.
4936 This intrinsic routine is provided for backwards compatibility with
4937 GNU Fortran 77. In new code, programmers should consider the use of
4938 the @ref{GET_ENVIRONMENT_VARIABLE} intrinsic defined by the Fortran
4941 @item @emph{Standard}:
4947 @item @emph{Syntax}:
4948 @code{CALL GETENV(NAME, VALUE)}
4950 @item @emph{Arguments}:
4951 @multitable @columnfractions .15 .70
4952 @item @var{NAME} @tab Shall be of type @code{CHARACTER} and of default kind.
4953 @item @var{VALUE} @tab Shall be of type @code{CHARACTER} and of default kind.
4956 @item @emph{Return value}:
4957 Stores the value of @var{NAME} in @var{VALUE}. If @var{VALUE} is
4958 not large enough to hold the data, it is truncated. If @var{NAME}
4959 is not set, @var{VALUE} will be filled with blanks.
4961 @item @emph{Example}:
4964 CHARACTER(len=255) :: homedir
4965 CALL getenv("HOME", homedir)
4966 WRITE (*,*) TRIM(homedir)
4970 @item @emph{See also}:
4971 @ref{GET_ENVIRONMENT_VARIABLE}
4976 @node GET_ENVIRONMENT_VARIABLE
4977 @section @code{GET_ENVIRONMENT_VARIABLE} --- Get an environmental variable
4978 @fnindex GET_ENVIRONMENT_VARIABLE
4979 @cindex environment variable
4982 @item @emph{Description}:
4983 Get the @var{VALUE} of the environmental variable @var{NAME}.
4985 @item @emph{Standard}:
4986 Fortran 2003 and later
4991 @item @emph{Syntax}:
4992 @code{CALL GET_ENVIRONMENT_VARIABLE(NAME[, VALUE, LENGTH, STATUS, TRIM_NAME)}
4994 @item @emph{Arguments}:
4995 @multitable @columnfractions .15 .70
4996 @item @var{NAME} @tab Shall be a scalar of type @code{CHARACTER}
4997 and of default kind.
4998 @item @var{VALUE} @tab Shall be a scalar of type @code{CHARACTER}
4999 and of default kind.
5000 @item @var{LENGTH} @tab Shall be a scalar of type @code{INTEGER}
5001 and of default kind.
5002 @item @var{STATUS} @tab Shall be a scalar of type @code{INTEGER}
5003 and of default kind.
5004 @item @var{TRIM_NAME} @tab Shall be a scalar of type @code{LOGICAL}
5005 and of default kind.
5008 @item @emph{Return value}:
5009 Stores the value of @var{NAME} in @var{VALUE}. If @var{VALUE} is
5010 not large enough to hold the data, it is truncated. If @var{NAME}
5011 is not set, @var{VALUE} will be filled with blanks. Argument @var{LENGTH}
5012 contains the length needed for storing the environment variable @var{NAME}
5013 or zero if it is not present. @var{STATUS} is -1 if @var{VALUE} is present
5014 but too short for the environment variable; it is 1 if the environment
5015 variable does not exist and 2 if the processor does not support environment
5016 variables; in all other cases @var{STATUS} is zero. If @var{TRIM_NAME} is
5017 present with the value @code{.FALSE.}, the trailing blanks in @var{NAME}
5018 are significant; otherwise they are not part of the environment variable
5021 @item @emph{Example}:
5024 CHARACTER(len=255) :: homedir
5025 CALL get_environment_variable("HOME", homedir)
5026 WRITE (*,*) TRIM(homedir)
5034 @section @code{GETGID} --- Group ID function
5036 @cindex system, group id
5039 @item @emph{Description}:
5040 Returns the numerical group ID of the current process.
5042 @item @emph{Standard}:
5048 @item @emph{Syntax}:
5049 @code{RESULT = GETGID()}
5051 @item @emph{Return value}:
5052 The return value of @code{GETGID} is an @code{INTEGER} of the default
5056 @item @emph{Example}:
5057 See @code{GETPID} for an example.
5059 @item @emph{See also}:
5060 @ref{GETPID}, @ref{GETUID}
5066 @section @code{GETLOG} --- Get login name
5068 @cindex system, login name
5072 @item @emph{Description}:
5073 Gets the username under which the program is running.
5075 @item @emph{Standard}:
5081 @item @emph{Syntax}:
5082 @code{CALL GETLOG(C)}
5084 @item @emph{Arguments}:
5085 @multitable @columnfractions .15 .70
5086 @item @var{C} @tab Shall be of type @code{CHARACTER} and of default kind.
5089 @item @emph{Return value}:
5090 Stores the current user name in @var{LOGIN}. (On systems where POSIX
5091 functions @code{geteuid} and @code{getpwuid} are not available, and
5092 the @code{getlogin} function is not implemented either, this will
5093 return a blank string.)
5095 @item @emph{Example}:
5098 CHARACTER(32) :: login
5104 @item @emph{See also}:
5111 @section @code{GETPID} --- Process ID function
5113 @cindex system, process id
5117 @item @emph{Description}:
5118 Returns the numerical process identifier of the current process.
5120 @item @emph{Standard}:
5126 @item @emph{Syntax}:
5127 @code{RESULT = GETPID()}
5129 @item @emph{Return value}:
5130 The return value of @code{GETPID} is an @code{INTEGER} of the default
5134 @item @emph{Example}:
5137 print *, "The current process ID is ", getpid()
5138 print *, "Your numerical user ID is ", getuid()
5139 print *, "Your numerical group ID is ", getgid()
5143 @item @emph{See also}:
5144 @ref{GETGID}, @ref{GETUID}
5150 @section @code{GETUID} --- User ID function
5152 @cindex system, user id
5156 @item @emph{Description}:
5157 Returns the numerical user ID of the current process.
5159 @item @emph{Standard}:
5165 @item @emph{Syntax}:
5166 @code{RESULT = GETUID()}
5168 @item @emph{Return value}:
5169 The return value of @code{GETUID} is an @code{INTEGER} of the default
5173 @item @emph{Example}:
5174 See @code{GETPID} for an example.
5176 @item @emph{See also}:
5177 @ref{GETPID}, @ref{GETLOG}
5183 @section @code{GMTIME} --- Convert time to GMT info
5185 @cindex time, conversion to GMT info
5188 @item @emph{Description}:
5189 Given a system time value @var{TIME} (as provided by the @code{TIME8()}
5190 intrinsic), fills @var{VALUES} with values extracted from it appropriate
5191 to the UTC time zone (Universal Coordinated Time, also known in some
5192 countries as GMT, Greenwich Mean Time), using @code{gmtime(3)}.
5194 @item @emph{Standard}:
5200 @item @emph{Syntax}:
5201 @code{CALL GMTIME(TIME, VALUES)}
5203 @item @emph{Arguments}:
5204 @multitable @columnfractions .15 .70
5205 @item @var{TIME} @tab An @code{INTEGER} scalar expression
5206 corresponding to a system time, with @code{INTENT(IN)}.
5207 @item @var{VALUES} @tab A default @code{INTEGER} array with 9 elements,
5208 with @code{INTENT(OUT)}.
5211 @item @emph{Return value}:
5212 The elements of @var{VALUES} are assigned as follows:
5214 @item Seconds after the minute, range 0--59 or 0--61 to allow for leap
5216 @item Minutes after the hour, range 0--59
5217 @item Hours past midnight, range 0--23
5218 @item Day of month, range 0--31
5219 @item Number of months since January, range 0--12
5220 @item Years since 1900
5221 @item Number of days since Sunday, range 0--6
5222 @item Days since January 1
5223 @item Daylight savings indicator: positive if daylight savings is in
5224 effect, zero if not, and negative if the information is not available.
5227 @item @emph{See also}:
5228 @ref{CTIME}, @ref{LTIME}, @ref{TIME}, @ref{TIME8}
5235 @section @code{HOSTNM} --- Get system host name
5237 @cindex system, host name
5240 @item @emph{Description}:
5241 Retrieves the host name of the system on which the program is running.
5243 This intrinsic is provided in both subroutine and function forms; however,
5244 only one form can be used in any given program unit.
5246 @item @emph{Standard}:
5250 Subroutine, function
5252 @item @emph{Syntax}:
5253 @multitable @columnfractions .80
5254 @item @code{CALL HOSTNM(C [, STATUS])}
5255 @item @code{STATUS = HOSTNM(NAME)}
5258 @item @emph{Arguments}:
5259 @multitable @columnfractions .15 .70
5260 @item @var{C} @tab Shall of type @code{CHARACTER} and of default kind.
5261 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
5262 Returns 0 on success, or a system specific error code otherwise.
5265 @item @emph{Return value}:
5266 In either syntax, @var{NAME} is set to the current hostname if it can
5267 be obtained, or to a blank string otherwise.
5274 @section @code{HUGE} --- Largest number of a kind
5276 @cindex limits, largest number
5277 @cindex model representation, largest number
5280 @item @emph{Description}:
5281 @code{HUGE(X)} returns the largest number that is not an infinity in
5282 the model of the type of @code{X}.
5284 @item @emph{Standard}:
5285 Fortran 95 and later
5290 @item @emph{Syntax}:
5291 @code{RESULT = HUGE(X)}
5293 @item @emph{Arguments}:
5294 @multitable @columnfractions .15 .70
5295 @item @var{X} @tab Shall be of type @code{REAL} or @code{INTEGER}.
5298 @item @emph{Return value}:
5299 The return value is of the same type and kind as @var{X}
5301 @item @emph{Example}:
5303 program test_huge_tiny
5304 print *, huge(0), huge(0.0), huge(0.0d0)
5305 print *, tiny(0.0), tiny(0.0d0)
5306 end program test_huge_tiny
5313 @section @code{HYPOT} --- Euclidean distance function
5315 @cindex Euclidean distance
5318 @item @emph{Description}:
5319 @code{HYPOT(X,Y)} is the Euclidean distance function. It is equal to
5320 @math{\sqrt{X^2 + Y^2}}, without undue underflow or overflow.
5322 @item @emph{Standard}:
5323 Fortran 2008 and later
5328 @item @emph{Syntax}:
5329 @code{RESULT = HYPOT(X, Y)}
5331 @item @emph{Arguments}:
5332 @multitable @columnfractions .15 .70
5333 @item @var{X} @tab The type shall be @code{REAL}.
5334 @item @var{Y} @tab The type and kind type parameter shall be the same as
5338 @item @emph{Return value}:
5339 The return value has the same type and kind type parameter as @var{X}.
5341 @item @emph{Example}:
5344 real(4) :: x = 1.e0_4, y = 0.5e0_4
5346 end program test_hypot
5353 @section @code{IACHAR} --- Code in @acronym{ASCII} collating sequence
5355 @cindex @acronym{ASCII} collating sequence
5356 @cindex collating sequence, @acronym{ASCII}
5357 @cindex conversion, to integer
5360 @item @emph{Description}:
5361 @code{IACHAR(C)} returns the code for the @acronym{ASCII} character
5362 in the first character position of @code{C}.
5364 @item @emph{Standard}:
5365 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
5370 @item @emph{Syntax}:
5371 @code{RESULT = IACHAR(C [, KIND])}
5373 @item @emph{Arguments}:
5374 @multitable @columnfractions .15 .70
5375 @item @var{C} @tab Shall be a scalar @code{CHARACTER}, with @code{INTENT(IN)}
5376 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
5377 expression indicating the kind parameter of the result.
5380 @item @emph{Return value}:
5381 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
5382 @var{KIND} is absent, the return value is of default integer kind.
5384 @item @emph{Example}:
5389 end program test_iachar
5393 See @ref{ICHAR} for a discussion of converting between numerical values
5394 and formatted string representations.
5396 @item @emph{See also}:
5397 @ref{ACHAR}, @ref{CHAR}, @ref{ICHAR}
5404 @section @code{IAND} --- Bitwise logical and
5406 @cindex bitwise logical and
5407 @cindex logical and, bitwise
5410 @item @emph{Description}:
5411 Bitwise logical @code{AND}.
5413 @item @emph{Standard}:
5414 Fortran 95 and later
5419 @item @emph{Syntax}:
5420 @code{RESULT = IAND(I, J)}
5422 @item @emph{Arguments}:
5423 @multitable @columnfractions .15 .70
5424 @item @var{I} @tab The type shall be @code{INTEGER}.
5425 @item @var{J} @tab The type shall be @code{INTEGER}, of the same
5426 kind as @var{I}. (As a GNU extension, different kinds are also
5430 @item @emph{Return value}:
5431 The return type is @code{INTEGER}, of the same kind as the
5432 arguments. (If the argument kinds differ, it is of the same kind as
5433 the larger argument.)
5435 @item @emph{Example}:
5439 DATA a / Z'F' /, b / Z'3' /
5440 WRITE (*,*) IAND(a, b)
5444 @item @emph{See also}:
5445 @ref{IOR}, @ref{IEOR}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}, @ref{NOT}
5452 @section @code{IARGC} --- Get the number of command line arguments
5454 @cindex command-line arguments
5455 @cindex command-line arguments, number of
5456 @cindex arguments, to program
5459 @item @emph{Description}:
5460 @code{IARGC()} returns the number of arguments passed on the
5461 command line when the containing program was invoked.
5463 This intrinsic routine is provided for backwards compatibility with
5464 GNU Fortran 77. In new code, programmers should consider the use of
5465 the @ref{COMMAND_ARGUMENT_COUNT} intrinsic defined by the Fortran 2003
5468 @item @emph{Standard}:
5474 @item @emph{Syntax}:
5475 @code{RESULT = IARGC()}
5477 @item @emph{Arguments}:
5480 @item @emph{Return value}:
5481 The number of command line arguments, type @code{INTEGER(4)}.
5483 @item @emph{Example}:
5486 @item @emph{See also}:
5487 GNU Fortran 77 compatibility subroutine: @ref{GETARG}
5489 Fortran 2003 functions and subroutines: @ref{GET_COMMAND},
5490 @ref{GET_COMMAND_ARGUMENT}, @ref{COMMAND_ARGUMENT_COUNT}
5496 @section @code{IBCLR} --- Clear bit
5502 @item @emph{Description}:
5503 @code{IBCLR} returns the value of @var{I} with the bit at position
5504 @var{POS} set to zero.
5506 @item @emph{Standard}:
5507 Fortran 95 and later
5512 @item @emph{Syntax}:
5513 @code{RESULT = IBCLR(I, POS)}
5515 @item @emph{Arguments}:
5516 @multitable @columnfractions .15 .70
5517 @item @var{I} @tab The type shall be @code{INTEGER}.
5518 @item @var{POS} @tab The type shall be @code{INTEGER}.
5521 @item @emph{Return value}:
5522 The return value is of type @code{INTEGER} and of the same kind as
5525 @item @emph{See also}:
5526 @ref{IBITS}, @ref{IBSET}, @ref{IAND}, @ref{IOR}, @ref{IEOR}, @ref{MVBITS}
5533 @section @code{IBITS} --- Bit extraction
5536 @cindex bits, extract
5539 @item @emph{Description}:
5540 @code{IBITS} extracts a field of length @var{LEN} from @var{I},
5541 starting from bit position @var{POS} and extending left for @var{LEN}
5542 bits. The result is right-justified and the remaining bits are
5543 zeroed. The value of @code{POS+LEN} must be less than or equal to the
5544 value @code{BIT_SIZE(I)}.
5546 @item @emph{Standard}:
5547 Fortran 95 and later
5552 @item @emph{Syntax}:
5553 @code{RESULT = IBITS(I, POS, LEN)}
5555 @item @emph{Arguments}:
5556 @multitable @columnfractions .15 .70
5557 @item @var{I} @tab The type shall be @code{INTEGER}.
5558 @item @var{POS} @tab The type shall be @code{INTEGER}.
5559 @item @var{LEN} @tab The type shall be @code{INTEGER}.
5562 @item @emph{Return value}:
5563 The return value is of type @code{INTEGER} and of the same kind as
5566 @item @emph{See also}:
5567 @ref{BIT_SIZE}, @ref{IBCLR}, @ref{IBSET}, @ref{IAND}, @ref{IOR}, @ref{IEOR}
5573 @section @code{IBSET} --- Set bit
5578 @item @emph{Description}:
5579 @code{IBSET} returns the value of @var{I} with the bit at position
5580 @var{POS} set to one.
5582 @item @emph{Standard}:
5583 Fortran 95 and later
5588 @item @emph{Syntax}:
5589 @code{RESULT = IBSET(I, POS)}
5591 @item @emph{Arguments}:
5592 @multitable @columnfractions .15 .70
5593 @item @var{I} @tab The type shall be @code{INTEGER}.
5594 @item @var{POS} @tab The type shall be @code{INTEGER}.
5597 @item @emph{Return value}:
5598 The return value is of type @code{INTEGER} and of the same kind as
5601 @item @emph{See also}:
5602 @ref{IBCLR}, @ref{IBITS}, @ref{IAND}, @ref{IOR}, @ref{IEOR}, @ref{MVBITS}
5609 @section @code{ICHAR} --- Character-to-integer conversion function
5611 @cindex conversion, to integer
5614 @item @emph{Description}:
5615 @code{ICHAR(C)} returns the code for the character in the first character
5616 position of @code{C} in the system's native character set.
5617 The correspondence between characters and their codes is not necessarily
5618 the same across different GNU Fortran implementations.
5620 @item @emph{Standard}:
5621 Fortan 95 and later, with @var{KIND} argument Fortran 2003 and later
5626 @item @emph{Syntax}:
5627 @code{RESULT = ICHAR(C [, KIND])}
5629 @item @emph{Arguments}:
5630 @multitable @columnfractions .15 .70
5631 @item @var{C} @tab Shall be a scalar @code{CHARACTER}, with @code{INTENT(IN)}
5632 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
5633 expression indicating the kind parameter of the result.
5636 @item @emph{Return value}:
5637 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
5638 @var{KIND} is absent, the return value is of default integer kind.
5640 @item @emph{Example}:
5645 end program test_ichar
5648 @item @emph{Specific names}:
5649 @multitable @columnfractions .20 .20 .20 .25
5650 @item Name @tab Argument @tab Return type @tab Standard
5651 @item @code{ICHAR(C)} @tab @code{CHARACTER C} @tab @code{INTEGER(4)} @tab Fortran 77 and later
5655 No intrinsic exists to convert between a numeric value and a formatted
5656 character string representation -- for instance, given the
5657 @code{CHARACTER} value @code{'154'}, obtaining an @code{INTEGER} or
5658 @code{REAL} value with the value 154, or vice versa. Instead, this
5659 functionality is provided by internal-file I/O, as in the following
5664 character(len=10) string, string2
5667 ! Convert a string to a numeric value
5668 read (string,'(I10)') value
5671 ! Convert a value to a formatted string
5672 write (string2,'(I10)') value
5674 end program read_val
5677 @item @emph{See also}:
5678 @ref{ACHAR}, @ref{CHAR}, @ref{IACHAR}
5685 @section @code{IDATE} --- Get current local time subroutine (day/month/year)
5687 @cindex date, current
5688 @cindex current date
5691 @item @emph{Description}:
5692 @code{IDATE(VALUES)} Fills @var{VALUES} with the numerical values at the
5693 current local time. The day (in the range 1-31), month (in the range 1-12),
5694 and year appear in elements 1, 2, and 3 of @var{VALUES}, respectively.
5695 The year has four significant digits.
5697 @item @emph{Standard}:
5703 @item @emph{Syntax}:
5704 @code{CALL IDATE(VALUES)}
5706 @item @emph{Arguments}:
5707 @multitable @columnfractions .15 .70
5708 @item @var{VALUES} @tab The type shall be @code{INTEGER, DIMENSION(3)} and
5709 the kind shall be the default integer kind.
5712 @item @emph{Return value}:
5713 Does not return anything.
5715 @item @emph{Example}:
5718 integer, dimension(3) :: tarray
5723 end program test_idate
5730 @section @code{IEOR} --- Bitwise logical exclusive or
5732 @cindex bitwise logical exclusive or
5733 @cindex logical exclusive or, bitwise
5736 @item @emph{Description}:
5737 @code{IEOR} returns the bitwise boolean exclusive-OR of @var{I} and
5740 @item @emph{Standard}:
5741 Fortran 95 and later
5746 @item @emph{Syntax}:
5747 @code{RESULT = IEOR(I, J)}
5749 @item @emph{Arguments}:
5750 @multitable @columnfractions .15 .70
5751 @item @var{I} @tab The type shall be @code{INTEGER}.
5752 @item @var{J} @tab The type shall be @code{INTEGER}, of the same
5753 kind as @var{I}. (As a GNU extension, different kinds are also
5757 @item @emph{Return value}:
5758 The return type is @code{INTEGER}, of the same kind as the
5759 arguments. (If the argument kinds differ, it is of the same kind as
5760 the larger argument.)
5762 @item @emph{See also}:
5763 @ref{IOR}, @ref{IAND}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}, @ref{NOT}
5769 @section @code{IERRNO} --- Get the last system error number
5771 @cindex system, error handling
5774 @item @emph{Description}:
5775 Returns the last system error number, as given by the C @code{errno()}
5778 @item @emph{Standard}:
5784 @item @emph{Syntax}:
5785 @code{RESULT = IERRNO()}
5787 @item @emph{Arguments}:
5790 @item @emph{Return value}:
5791 The return value is of type @code{INTEGER} and of the default integer
5794 @item @emph{See also}:
5800 @node INDEX intrinsic
5801 @section @code{INDEX} --- Position of a substring within a string
5803 @cindex substring position
5804 @cindex string, find substring
5807 @item @emph{Description}:
5808 Returns the position of the start of the first occurrence of string
5809 @var{SUBSTRING} as a substring in @var{STRING}, counting from one. If
5810 @var{SUBSTRING} is not present in @var{STRING}, zero is returned. If
5811 the @var{BACK} argument is present and true, the return value is the
5812 start of the last occurrence rather than the first.
5814 @item @emph{Standard}:
5815 Fortran 77 and later, with @var{KIND} argument Fortran 2003 and later
5820 @item @emph{Syntax}:
5821 @code{RESULT = INDEX(STRING, SUBSTRING [, BACK [, KIND]])}
5823 @item @emph{Arguments}:
5824 @multitable @columnfractions .15 .70
5825 @item @var{STRING} @tab Shall be a scalar @code{CHARACTER}, with
5827 @item @var{SUBSTRING} @tab Shall be a scalar @code{CHARACTER}, with
5829 @item @var{BACK} @tab (Optional) Shall be a scalar @code{LOGICAL}, with
5831 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
5832 expression indicating the kind parameter of the result.
5835 @item @emph{Return value}:
5836 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
5837 @var{KIND} is absent, the return value is of default integer kind.
5839 @item @emph{Specific names}:
5840 @multitable @columnfractions .20 .20 .20 .25
5841 @item Name @tab Argument @tab Return type @tab Standard
5842 @item @code{INDEX(STRING, SUBSTRING)} @tab @code{CHARACTER} @tab @code{INTEGER(4)} @tab Fortran 77 and later
5845 @item @emph{See also}:
5846 @ref{SCAN}, @ref{VERIFY}
5852 @section @code{INT} --- Convert to integer type
5856 @cindex conversion, to integer
5859 @item @emph{Description}:
5860 Convert to integer type
5862 @item @emph{Standard}:
5863 Fortran 77 and later
5868 @item @emph{Syntax}:
5869 @code{RESULT = INT(A [, KIND))}
5871 @item @emph{Arguments}:
5872 @multitable @columnfractions .15 .70
5873 @item @var{A} @tab Shall be of type @code{INTEGER},
5874 @code{REAL}, or @code{COMPLEX}.
5875 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
5876 expression indicating the kind parameter of the result.
5879 @item @emph{Return value}:
5880 These functions return a @code{INTEGER} variable or array under
5881 the following rules:
5885 If @var{A} is of type @code{INTEGER}, @code{INT(A) = A}
5887 If @var{A} is of type @code{REAL} and @math{|A| < 1}, @code{INT(A)} equals @code{0}.
5888 If @math{|A| \geq 1}, then @code{INT(A)} equals the largest integer that does not exceed
5889 the range of @var{A} and whose sign is the same as the sign of @var{A}.
5891 If @var{A} is of type @code{COMPLEX}, rule B is applied to the real part of @var{A}.
5894 @item @emph{Example}:
5898 complex :: z = (-3.7, 1.0)
5900 print *, int(z), int(z,8)
5904 @item @emph{Specific names}:
5905 @multitable @columnfractions .20 .20 .20 .25
5906 @item Name @tab Argument @tab Return type @tab Standard
5907 @item @code{INT(A)} @tab @code{REAL(4) A} @tab @code{INTEGER} @tab Fortran 77 and later
5908 @item @code{IFIX(A)} @tab @code{REAL(4) A} @tab @code{INTEGER} @tab Fortran 77 and later
5909 @item @code{IDINT(A)} @tab @code{REAL(8) A} @tab @code{INTEGER} @tab Fortran 77 and later
5916 @section @code{INT2} --- Convert to 16-bit integer type
5919 @cindex conversion, to integer
5922 @item @emph{Description}:
5923 Convert to a @code{KIND=2} integer type. This is equivalent to the
5924 standard @code{INT} intrinsic with an optional argument of
5925 @code{KIND=2}, and is only included for backwards compatibility.
5927 The @code{SHORT} intrinsic is equivalent to @code{INT2}.
5929 @item @emph{Standard}:
5935 @item @emph{Syntax}:
5936 @code{RESULT = INT2(A)}
5938 @item @emph{Arguments}:
5939 @multitable @columnfractions .15 .70
5940 @item @var{A} @tab Shall be of type @code{INTEGER},
5941 @code{REAL}, or @code{COMPLEX}.
5944 @item @emph{Return value}:
5945 The return value is a @code{INTEGER(2)} variable.
5947 @item @emph{See also}:
5948 @ref{INT}, @ref{INT8}, @ref{LONG}
5954 @section @code{INT8} --- Convert to 64-bit integer type
5956 @cindex conversion, to integer
5959 @item @emph{Description}:
5960 Convert to a @code{KIND=8} integer type. This is equivalent to the
5961 standard @code{INT} intrinsic with an optional argument of
5962 @code{KIND=8}, and is only included for backwards compatibility.
5964 @item @emph{Standard}:
5970 @item @emph{Syntax}:
5971 @code{RESULT = INT8(A)}
5973 @item @emph{Arguments}:
5974 @multitable @columnfractions .15 .70
5975 @item @var{A} @tab Shall be of type @code{INTEGER},
5976 @code{REAL}, or @code{COMPLEX}.
5979 @item @emph{Return value}:
5980 The return value is a @code{INTEGER(8)} variable.
5982 @item @emph{See also}:
5983 @ref{INT}, @ref{INT2}, @ref{LONG}
5989 @section @code{IOR} --- Bitwise logical or
5991 @cindex bitwise logical or
5992 @cindex logical or, bitwise
5995 @item @emph{Description}:
5996 @code{IOR} returns the bitwise boolean inclusive-OR of @var{I} and
5999 @item @emph{Standard}:
6000 Fortran 95 and later
6005 @item @emph{Syntax}:
6006 @code{RESULT = IOR(I, J)}
6008 @item @emph{Arguments}:
6009 @multitable @columnfractions .15 .70
6010 @item @var{I} @tab The type shall be @code{INTEGER}.
6011 @item @var{J} @tab The type shall be @code{INTEGER}, of the same
6012 kind as @var{I}. (As a GNU extension, different kinds are also
6016 @item @emph{Return value}:
6017 The return type is @code{INTEGER}, of the same kind as the
6018 arguments. (If the argument kinds differ, it is of the same kind as
6019 the larger argument.)
6021 @item @emph{See also}:
6022 @ref{IEOR}, @ref{IAND}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}, @ref{NOT}
6028 @section @code{IRAND} --- Integer pseudo-random number
6030 @cindex random number generation
6033 @item @emph{Description}:
6034 @code{IRAND(FLAG)} returns a pseudo-random number from a uniform
6035 distribution between 0 and a system-dependent limit (which is in most
6036 cases 2147483647). If @var{FLAG} is 0, the next number
6037 in the current sequence is returned; if @var{FLAG} is 1, the generator
6038 is restarted by @code{CALL SRAND(0)}; if @var{FLAG} has any other value,
6039 it is used as a new seed with @code{SRAND}.
6041 This intrinsic routine is provided for backwards compatibility with
6042 GNU Fortran 77. It implements a simple modulo generator as provided
6043 by @command{g77}. For new code, one should consider the use of
6044 @ref{RANDOM_NUMBER} as it implements a superior algorithm.
6046 @item @emph{Standard}:
6052 @item @emph{Syntax}:
6053 @code{RESULT = IRAND(I)}
6055 @item @emph{Arguments}:
6056 @multitable @columnfractions .15 .70
6057 @item @var{I} @tab Shall be a scalar @code{INTEGER} of kind 4.
6060 @item @emph{Return value}:
6061 The return value is of @code{INTEGER(kind=4)} type.
6063 @item @emph{Example}:
6066 integer,parameter :: seed = 86456
6069 print *, irand(), irand(), irand(), irand()
6070 print *, irand(seed), irand(), irand(), irand()
6071 end program test_irand
6079 @section @code{IMAGE_INDEX} --- Function that converts a cosubscript to an image index
6080 @fnindex IMAGE_INDEX
6081 @cindex coarray, IMAGE_INDEX
6082 @cindex images, cosubscript to image index conversion
6085 @item @emph{Description}:
6086 Returns the image index belonging to a cosubscript.
6088 @item @emph{Standard}:
6089 Fortran 2008 and later
6094 @item @emph{Syntax}:
6095 @code{RESULT = IMAGE_INDEX(COARRAY, SUB)}
6097 @item @emph{Arguments}: None.
6098 @multitable @columnfractions .15 .70
6099 @item @var{COARRAY} @tab Coarray of any type.
6100 @item @var{SUB} @tab default integer rank-1 array of a size equal to
6101 the corank of @var{COARRAY}.
6105 @item @emph{Return value}:
6106 Scalar default integer with the value of the image index which corresponds
6107 to the cosubscripts. For invalid cosubscripts the result is zero.
6109 @item @emph{Example}:
6111 INTEGER :: array[2,-1:4,8,*]
6112 ! Writes 28 (or 0 if there are fewer than 28 images)
6113 WRITE (*,*) IMAGE_INDEX (array, [2,0,3,1])
6116 @item @emph{See also}:
6117 @ref{THIS_IMAGE}, @ref{NUM_IMAGES}
6123 @section @code{IS_IOSTAT_END} --- Test for end-of-file value
6124 @fnindex IS_IOSTAT_END
6125 @cindex IOSTAT, end of file
6128 @item @emph{Description}:
6129 @code{IS_IOSTAT_END} tests whether an variable has the value of the I/O
6130 status ``end of file''. The function is equivalent to comparing the variable
6131 with the @code{IOSTAT_END} parameter of the intrinsic module
6132 @code{ISO_FORTRAN_ENV}.
6134 @item @emph{Standard}:
6135 Fortran 2003 and later
6140 @item @emph{Syntax}:
6141 @code{RESULT = IS_IOSTAT_END(I)}
6143 @item @emph{Arguments}:
6144 @multitable @columnfractions .15 .70
6145 @item @var{I} @tab Shall be of the type @code{INTEGER}.
6148 @item @emph{Return value}:
6149 Returns a @code{LOGICAL} of the default kind, which @code{.TRUE.} if
6150 @var{I} has the value which indicates an end of file condition for
6151 IOSTAT= specifiers, and is @code{.FALSE.} otherwise.
6153 @item @emph{Example}:
6158 OPEN(88, FILE='test.dat')
6159 READ(88, *, IOSTAT=stat) i
6160 IF(IS_IOSTAT_END(stat)) STOP 'END OF FILE'
6168 @section @code{IS_IOSTAT_EOR} --- Test for end-of-record value
6169 @fnindex IS_IOSTAT_EOR
6170 @cindex IOSTAT, end of record
6173 @item @emph{Description}:
6174 @code{IS_IOSTAT_EOR} tests whether an variable has the value of the I/O
6175 status ``end of record''. The function is equivalent to comparing the
6176 variable with the @code{IOSTAT_EOR} parameter of the intrinsic module
6177 @code{ISO_FORTRAN_ENV}.
6179 @item @emph{Standard}:
6180 Fortran 2003 and later
6185 @item @emph{Syntax}:
6186 @code{RESULT = IS_IOSTAT_EOR(I)}
6188 @item @emph{Arguments}:
6189 @multitable @columnfractions .15 .70
6190 @item @var{I} @tab Shall be of the type @code{INTEGER}.
6193 @item @emph{Return value}:
6194 Returns a @code{LOGICAL} of the default kind, which @code{.TRUE.} if
6195 @var{I} has the value which indicates an end of file condition for
6196 IOSTAT= specifiers, and is @code{.FALSE.} otherwise.
6198 @item @emph{Example}:
6202 INTEGER :: stat, i(50)
6203 OPEN(88, FILE='test.dat', FORM='UNFORMATTED')
6204 READ(88, IOSTAT=stat) i
6205 IF(IS_IOSTAT_EOR(stat)) STOP 'END OF RECORD'
6213 @section @code{ISATTY} --- Whether a unit is a terminal device.
6215 @cindex system, terminal
6218 @item @emph{Description}:
6219 Determine whether a unit is connected to a terminal device.
6221 @item @emph{Standard}:
6227 @item @emph{Syntax}:
6228 @code{RESULT = ISATTY(UNIT)}
6230 @item @emph{Arguments}:
6231 @multitable @columnfractions .15 .70
6232 @item @var{UNIT} @tab Shall be a scalar @code{INTEGER}.
6235 @item @emph{Return value}:
6236 Returns @code{.TRUE.} if the @var{UNIT} is connected to a terminal
6237 device, @code{.FALSE.} otherwise.
6239 @item @emph{Example}:
6242 INTEGER(kind=1) :: unit
6244 write(*,*) isatty(unit=unit)
6248 @item @emph{See also}:
6255 @section @code{ISHFT} --- Shift bits
6260 @item @emph{Description}:
6261 @code{ISHFT} returns a value corresponding to @var{I} with all of the
6262 bits shifted @var{SHIFT} places. A value of @var{SHIFT} greater than
6263 zero corresponds to a left shift, a value of zero corresponds to no
6264 shift, and a value less than zero corresponds to a right shift. If the
6265 absolute value of @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the
6266 value is undefined. Bits shifted out from the left end or right end are
6267 lost; zeros are shifted in from the opposite end.
6269 @item @emph{Standard}:
6270 Fortran 95 and later
6275 @item @emph{Syntax}:
6276 @code{RESULT = ISHFT(I, SHIFT)}
6278 @item @emph{Arguments}:
6279 @multitable @columnfractions .15 .70
6280 @item @var{I} @tab The type shall be @code{INTEGER}.
6281 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
6284 @item @emph{Return value}:
6285 The return value is of type @code{INTEGER} and of the same kind as
6288 @item @emph{See also}:
6295 @section @code{ISHFTC} --- Shift bits circularly
6297 @cindex bits, shift circular
6300 @item @emph{Description}:
6301 @code{ISHFTC} returns a value corresponding to @var{I} with the
6302 rightmost @var{SIZE} bits shifted circularly @var{SHIFT} places; that
6303 is, bits shifted out one end are shifted into the opposite end. A value
6304 of @var{SHIFT} greater than zero corresponds to a left shift, a value of
6305 zero corresponds to no shift, and a value less than zero corresponds to
6306 a right shift. The absolute value of @var{SHIFT} must be less than
6307 @var{SIZE}. If the @var{SIZE} argument is omitted, it is taken to be
6308 equivalent to @code{BIT_SIZE(I)}.
6310 @item @emph{Standard}:
6311 Fortran 95 and later
6316 @item @emph{Syntax}:
6317 @code{RESULT = ISHFTC(I, SHIFT [, SIZE])}
6319 @item @emph{Arguments}:
6320 @multitable @columnfractions .15 .70
6321 @item @var{I} @tab The type shall be @code{INTEGER}.
6322 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
6323 @item @var{SIZE} @tab (Optional) The type shall be @code{INTEGER};
6324 the value must be greater than zero and less than or equal to
6328 @item @emph{Return value}:
6329 The return value is of type @code{INTEGER} and of the same kind as
6332 @item @emph{See also}:
6339 @section @code{ISNAN} --- Test for a NaN
6344 @item @emph{Description}:
6345 @code{ISNAN} tests whether a floating-point value is an IEEE
6347 @item @emph{Standard}:
6353 @item @emph{Syntax}:
6356 @item @emph{Arguments}:
6357 @multitable @columnfractions .15 .70
6358 @item @var{X} @tab Variable of the type @code{REAL}.
6362 @item @emph{Return value}:
6363 Returns a default-kind @code{LOGICAL}. The returned value is @code{TRUE}
6364 if @var{X} is a NaN and @code{FALSE} otherwise.
6366 @item @emph{Example}:
6373 if (isnan(x)) stop '"x" is a NaN'
6374 end program test_nan
6381 @section @code{ITIME} --- Get current local time subroutine (hour/minutes/seconds)
6383 @cindex time, current
6384 @cindex current time
6387 @item @emph{Description}:
6388 @code{IDATE(VALUES)} Fills @var{VALUES} with the numerical values at the
6389 current local time. The hour (in the range 1-24), minute (in the range 1-60),
6390 and seconds (in the range 1-60) appear in elements 1, 2, and 3 of @var{VALUES},
6393 @item @emph{Standard}:
6399 @item @emph{Syntax}:
6400 @code{CALL ITIME(VALUES)}
6402 @item @emph{Arguments}:
6403 @multitable @columnfractions .15 .70
6404 @item @var{VALUES} @tab The type shall be @code{INTEGER, DIMENSION(3)}
6405 and the kind shall be the default integer kind.
6408 @item @emph{Return value}:
6409 Does not return anything.
6412 @item @emph{Example}:
6415 integer, dimension(3) :: tarray
6420 end program test_itime
6427 @section @code{KILL} --- Send a signal to a process
6431 @item @emph{Description}:
6432 @item @emph{Standard}:
6433 Sends the signal specified by @var{SIGNAL} to the process @var{PID}.
6436 This intrinsic is provided in both subroutine and function forms; however,
6437 only one form can be used in any given program unit.
6440 Subroutine, function
6442 @item @emph{Syntax}:
6443 @code{CALL KILL(C, VALUE [, STATUS])}
6445 @item @emph{Arguments}:
6446 @multitable @columnfractions .15 .70
6447 @item @var{C} @tab Shall be a scalar @code{INTEGER}, with
6449 @item @var{VALUE} @tab Shall be a scalar @code{INTEGER}, with
6451 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)} or
6452 @code{INTEGER(8)}. Returns 0 on success, or a system-specific error code
6456 @item @emph{See also}:
6457 @ref{ABORT}, @ref{EXIT}
6463 @section @code{KIND} --- Kind of an entity
6468 @item @emph{Description}:
6469 @code{KIND(X)} returns the kind value of the entity @var{X}.
6471 @item @emph{Standard}:
6472 Fortran 95 and later
6477 @item @emph{Syntax}:
6480 @item @emph{Arguments}:
6481 @multitable @columnfractions .15 .70
6482 @item @var{X} @tab Shall be of type @code{LOGICAL}, @code{INTEGER},
6483 @code{REAL}, @code{COMPLEX} or @code{CHARACTER}.
6486 @item @emph{Return value}:
6487 The return value is a scalar of type @code{INTEGER} and of the default
6490 @item @emph{Example}:
6493 integer,parameter :: kc = kind(' ')
6494 integer,parameter :: kl = kind(.true.)
6496 print *, "The default character kind is ", kc
6497 print *, "The default logical kind is ", kl
6498 end program test_kind
6506 @section @code{LBOUND} --- Lower dimension bounds of an array
6508 @cindex array, lower bound
6511 @item @emph{Description}:
6512 Returns the lower bounds of an array, or a single lower bound
6513 along the @var{DIM} dimension.
6514 @item @emph{Standard}:
6515 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
6520 @item @emph{Syntax}:
6521 @code{RESULT = LBOUND(ARRAY [, DIM [, KIND]])}
6523 @item @emph{Arguments}:
6524 @multitable @columnfractions .15 .70
6525 @item @var{ARRAY} @tab Shall be an array, of any type.
6526 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER}.
6527 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
6528 expression indicating the kind parameter of the result.
6531 @item @emph{Return value}:
6532 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
6533 @var{KIND} is absent, the return value is of default integer kind.
6534 If @var{DIM} is absent, the result is an array of the lower bounds of
6535 @var{ARRAY}. If @var{DIM} is present, the result is a scalar
6536 corresponding to the lower bound of the array along that dimension. If
6537 @var{ARRAY} is an expression rather than a whole array or array
6538 structure component, or if it has a zero extent along the relevant
6539 dimension, the lower bound is taken to be 1.
6541 @item @emph{See also}:
6542 @ref{UBOUND}, @ref{LCOBOUND}
6548 @section @code{LCOBOUND} --- Lower codimension bounds of an array
6550 @cindex coarray, lower bound
6553 @item @emph{Description}:
6554 Returns the lower bounds of a coarray, or a single lower cobound
6555 along the @var{DIM} codimension.
6556 @item @emph{Standard}:
6557 Fortran 2008 and later
6562 @item @emph{Syntax}:
6563 @code{RESULT = LCOBOUND(COARRAY [, DIM [, KIND]])}
6565 @item @emph{Arguments}:
6566 @multitable @columnfractions .15 .70
6567 @item @var{ARRAY} @tab Shall be an coarray, of any type.
6568 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER}.
6569 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
6570 expression indicating the kind parameter of the result.
6573 @item @emph{Return value}:
6574 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
6575 @var{KIND} is absent, the return value is of default integer kind.
6576 If @var{DIM} is absent, the result is an array of the lower cobounds of
6577 @var{COARRAY}. If @var{DIM} is present, the result is a scalar
6578 corresponding to the lower cobound of the array along that codimension.
6580 @item @emph{See also}:
6581 @ref{UCOBOUND}, @ref{LBOUND}
6587 @section @code{LEADZ} --- Number of leading zero bits of an integer
6592 @item @emph{Description}:
6593 @code{LEADZ} returns the number of leading zero bits of an integer.
6595 @item @emph{Standard}:
6596 Fortran 2008 and later
6601 @item @emph{Syntax}:
6602 @code{RESULT = LEADZ(I)}
6604 @item @emph{Arguments}:
6605 @multitable @columnfractions .15 .70
6606 @item @var{I} @tab Shall be of type @code{INTEGER}.
6609 @item @emph{Return value}:
6610 The type of the return value is the default @code{INTEGER}.
6611 If all the bits of @code{I} are zero, the result value is @code{BIT_SIZE(I)}.
6613 @item @emph{Example}:
6616 WRITE (*,*) LEADZ(1) ! prints 8 if BITSIZE(I) has the value 32
6620 @item @emph{See also}:
6621 @ref{BIT_SIZE}, @ref{TRAILZ}
6627 @section @code{LEN} --- Length of a character entity
6629 @cindex string, length
6632 @item @emph{Description}:
6633 Returns the length of a character string. If @var{STRING} is an array,
6634 the length of an element of @var{STRING} is returned. Note that
6635 @var{STRING} need not be defined when this intrinsic is invoked, since
6636 only the length, not the content, of @var{STRING} is needed.
6638 @item @emph{Standard}:
6639 Fortran 77 and later, with @var{KIND} argument Fortran 2003 and later
6644 @item @emph{Syntax}:
6645 @code{L = LEN(STRING [, KIND])}
6647 @item @emph{Arguments}:
6648 @multitable @columnfractions .15 .70
6649 @item @var{STRING} @tab Shall be a scalar or array of type
6650 @code{CHARACTER}, with @code{INTENT(IN)}
6651 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
6652 expression indicating the kind parameter of the result.
6655 @item @emph{Return value}:
6656 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
6657 @var{KIND} is absent, the return value is of default integer kind.
6660 @item @emph{Specific names}:
6661 @multitable @columnfractions .20 .20 .20 .25
6662 @item Name @tab Argument @tab Return type @tab Standard
6663 @item @code{LEN(STRING)} @tab @code{CHARACTER} @tab @code{INTEGER} @tab Fortran 77 and later
6667 @item @emph{See also}:
6668 @ref{LEN_TRIM}, @ref{ADJUSTL}, @ref{ADJUSTR}
6674 @section @code{LEN_TRIM} --- Length of a character entity without trailing blank characters
6676 @cindex string, length, without trailing whitespace
6679 @item @emph{Description}:
6680 Returns the length of a character string, ignoring any trailing blanks.
6682 @item @emph{Standard}:
6683 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
6688 @item @emph{Syntax}:
6689 @code{RESULT = LEN_TRIM(STRING [, KIND])}
6691 @item @emph{Arguments}:
6692 @multitable @columnfractions .15 .70
6693 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER},
6694 with @code{INTENT(IN)}
6695 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
6696 expression indicating the kind parameter of the result.
6699 @item @emph{Return value}:
6700 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
6701 @var{KIND} is absent, the return value is of default integer kind.
6703 @item @emph{See also}:
6704 @ref{LEN}, @ref{ADJUSTL}, @ref{ADJUSTR}
6710 @section @code{LGE} --- Lexical greater than or equal
6712 @cindex lexical comparison of strings
6713 @cindex string, comparison
6716 @item @emph{Description}:
6717 Determines whether one string is lexically greater than or equal to
6718 another string, where the two strings are interpreted as containing
6719 ASCII character codes. If the String A and String B are not the same
6720 length, the shorter is compared as if spaces were appended to it to form
6721 a value that has the same length as the longer.
6723 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
6724 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
6725 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
6726 that the latter use the processor's character ordering (which is not
6727 ASCII on some targets), whereas the former always use the ASCII
6730 @item @emph{Standard}:
6731 Fortran 77 and later
6736 @item @emph{Syntax}:
6737 @code{RESULT = LGE(STRING_A, STRING_B)}
6739 @item @emph{Arguments}:
6740 @multitable @columnfractions .15 .70
6741 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
6742 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
6745 @item @emph{Return value}:
6746 Returns @code{.TRUE.} if @code{STRING_A >= STRING_B}, and @code{.FALSE.}
6747 otherwise, based on the ASCII ordering.
6749 @item @emph{Specific names}:
6750 @multitable @columnfractions .20 .20 .20 .25
6751 @item Name @tab Argument @tab Return type @tab Standard
6752 @item @code{LGE(STRING_A, STRING_B)} @tab @code{CHARACTER} @tab @code{LOGICAL} @tab Fortran 77 and later
6755 @item @emph{See also}:
6756 @ref{LGT}, @ref{LLE}, @ref{LLT}
6762 @section @code{LGT} --- Lexical greater than
6764 @cindex lexical comparison of strings
6765 @cindex string, comparison
6768 @item @emph{Description}:
6769 Determines whether one string is lexically greater than another string,
6770 where the two strings are interpreted as containing ASCII character
6771 codes. If the String A and String B are not the same length, the
6772 shorter is compared as if spaces were appended to it to form a value
6773 that has the same length as the longer.
6775 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
6776 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
6777 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
6778 that the latter use the processor's character ordering (which is not
6779 ASCII on some targets), whereas the former always use the ASCII
6782 @item @emph{Standard}:
6783 Fortran 77 and later
6788 @item @emph{Syntax}:
6789 @code{RESULT = LGT(STRING_A, STRING_B)}
6791 @item @emph{Arguments}:
6792 @multitable @columnfractions .15 .70
6793 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
6794 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
6797 @item @emph{Return value}:
6798 Returns @code{.TRUE.} if @code{STRING_A > STRING_B}, and @code{.FALSE.}
6799 otherwise, based on the ASCII ordering.
6801 @item @emph{Specific names}:
6802 @multitable @columnfractions .20 .20 .20 .25
6803 @item Name @tab Argument @tab Return type @tab Standard
6804 @item @code{LGT(STRING_A, STRING_B)} @tab @code{CHARACTER} @tab @code{LOGICAL} @tab Fortran 77 and later
6807 @item @emph{See also}:
6808 @ref{LGE}, @ref{LLE}, @ref{LLT}
6814 @section @code{LINK} --- Create a hard link
6816 @cindex file system, create link
6817 @cindex file system, hard link
6820 @item @emph{Description}:
6821 Makes a (hard) link from file @var{PATH1} to @var{PATH2}. A null
6822 character (@code{CHAR(0)}) can be used to mark the end of the names in
6823 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
6824 names are ignored. If the @var{STATUS} argument is supplied, it
6825 contains 0 on success or a nonzero error code upon return; see
6828 This intrinsic is provided in both subroutine and function forms;
6829 however, only one form can be used in any given program unit.
6831 @item @emph{Standard}:
6835 Subroutine, function
6837 @item @emph{Syntax}:
6838 @multitable @columnfractions .80
6839 @item @code{CALL LINK(PATH1, PATH2 [, STATUS])}
6840 @item @code{STATUS = LINK(PATH1, PATH2)}
6843 @item @emph{Arguments}:
6844 @multitable @columnfractions .15 .70
6845 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
6846 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
6847 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
6850 @item @emph{See also}:
6851 @ref{SYMLNK}, @ref{UNLINK}
6857 @section @code{LLE} --- Lexical less than or equal
6859 @cindex lexical comparison of strings
6860 @cindex string, comparison
6863 @item @emph{Description}:
6864 Determines whether one string is lexically less than or equal to another
6865 string, where the two strings are interpreted as containing ASCII
6866 character codes. If the String A and String B are not the same length,
6867 the shorter is compared as if spaces were appended to it to form a value
6868 that has the same length as the longer.
6870 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
6871 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
6872 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
6873 that the latter use the processor's character ordering (which is not
6874 ASCII on some targets), whereas the former always use the ASCII
6877 @item @emph{Standard}:
6878 Fortran 77 and later
6883 @item @emph{Syntax}:
6884 @code{RESULT = LLE(STRING_A, STRING_B)}
6886 @item @emph{Arguments}:
6887 @multitable @columnfractions .15 .70
6888 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
6889 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
6892 @item @emph{Return value}:
6893 Returns @code{.TRUE.} if @code{STRING_A <= STRING_B}, and @code{.FALSE.}
6894 otherwise, based on the ASCII ordering.
6896 @item @emph{Specific names}:
6897 @multitable @columnfractions .20 .20 .20 .25
6898 @item Name @tab Argument @tab Return type @tab Standard
6899 @item @code{LLE(STRING_A, STRING_B)} @tab @code{CHARACTER} @tab @code{LOGICAL} @tab Fortran 77 and later
6902 @item @emph{See also}:
6903 @ref{LGE}, @ref{LGT}, @ref{LLT}
6909 @section @code{LLT} --- Lexical less than
6911 @cindex lexical comparison of strings
6912 @cindex string, comparison
6915 @item @emph{Description}:
6916 Determines whether one string is lexically less than another string,
6917 where the two strings are interpreted as containing ASCII character
6918 codes. If the String A and String B are not the same length, the
6919 shorter is compared as if spaces were appended to it to form a value
6920 that has the same length as the longer.
6922 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
6923 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
6924 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
6925 that the latter use the processor's character ordering (which is not
6926 ASCII on some targets), whereas the former always use the ASCII
6929 @item @emph{Standard}:
6930 Fortran 77 and later
6935 @item @emph{Syntax}:
6936 @code{RESULT = LLT(STRING_A, STRING_B)}
6938 @item @emph{Arguments}:
6939 @multitable @columnfractions .15 .70
6940 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
6941 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
6944 @item @emph{Return value}:
6945 Returns @code{.TRUE.} if @code{STRING_A < STRING_B}, and @code{.FALSE.}
6946 otherwise, based on the ASCII ordering.
6948 @item @emph{Specific names}:
6949 @multitable @columnfractions .20 .20 .20 .25
6950 @item Name @tab Argument @tab Return type @tab Standard
6951 @item @code{LLT(STRING_A, STRING_B)} @tab @code{CHARACTER} @tab @code{LOGICAL} @tab Fortran 77 and later
6954 @item @emph{See also}:
6955 @ref{LGE}, @ref{LGT}, @ref{LLE}
6961 @section @code{LNBLNK} --- Index of the last non-blank character in a string
6963 @cindex string, find non-blank character
6966 @item @emph{Description}:
6967 Returns the length of a character string, ignoring any trailing blanks.
6968 This is identical to the standard @code{LEN_TRIM} intrinsic, and is only
6969 included for backwards compatibility.
6971 @item @emph{Standard}:
6977 @item @emph{Syntax}:
6978 @code{RESULT = LNBLNK(STRING)}
6980 @item @emph{Arguments}:
6981 @multitable @columnfractions .15 .70
6982 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER},
6983 with @code{INTENT(IN)}
6986 @item @emph{Return value}:
6987 The return value is of @code{INTEGER(kind=4)} type.
6989 @item @emph{See also}:
6990 @ref{INDEX intrinsic}, @ref{LEN_TRIM}
6996 @section @code{LOC} --- Returns the address of a variable
6998 @cindex location of a variable in memory
7001 @item @emph{Description}:
7002 @code{LOC(X)} returns the address of @var{X} as an integer.
7004 @item @emph{Standard}:
7010 @item @emph{Syntax}:
7011 @code{RESULT = LOC(X)}
7013 @item @emph{Arguments}:
7014 @multitable @columnfractions .15 .70
7015 @item @var{X} @tab Variable of any type.
7018 @item @emph{Return value}:
7019 The return value is of type @code{INTEGER}, with a @code{KIND}
7020 corresponding to the size (in bytes) of a memory address on the target
7023 @item @emph{Example}:
7030 end program test_loc
7037 @section @code{LOG} --- Logarithm function
7044 @cindex exponential function, inverse
7045 @cindex logarithmic function
7048 @item @emph{Description}:
7049 @code{LOG(X)} computes the logarithm of @var{X}.
7051 @item @emph{Standard}:
7052 Fortran 77 and later
7057 @item @emph{Syntax}:
7058 @code{RESULT = LOG(X)}
7060 @item @emph{Arguments}:
7061 @multitable @columnfractions .15 .70
7062 @item @var{X} @tab The type shall be @code{REAL} or
7066 @item @emph{Return value}:
7067 The return value is of type @code{REAL} or @code{COMPLEX}.
7068 The kind type parameter is the same as @var{X}.
7069 If @var{X} is @code{COMPLEX}, the imaginary part @math{\omega} is in the range
7070 @math{-\pi \leq \omega \leq \pi}.
7072 @item @emph{Example}:
7075 real(8) :: x = 1.0_8
7076 complex :: z = (1.0, 2.0)
7079 end program test_log
7082 @item @emph{Specific names}:
7083 @multitable @columnfractions .20 .20 .20 .25
7084 @item Name @tab Argument @tab Return type @tab Standard
7085 @item @code{ALOG(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab f95, gnu
7086 @item @code{DLOG(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab f95, gnu
7087 @item @code{CLOG(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab f95, gnu
7088 @item @code{ZLOG(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
7089 @item @code{CDLOG(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
7096 @section @code{LOG10} --- Base 10 logarithm function
7100 @cindex exponential function, inverse
7101 @cindex logarithmic function
7104 @item @emph{Description}:
7105 @code{LOG10(X)} computes the base 10 logarithm of @var{X}.
7107 @item @emph{Standard}:
7108 Fortran 77 and later
7113 @item @emph{Syntax}:
7114 @code{RESULT = LOG10(X)}
7116 @item @emph{Arguments}:
7117 @multitable @columnfractions .15 .70
7118 @item @var{X} @tab The type shall be @code{REAL}.
7121 @item @emph{Return value}:
7122 The return value is of type @code{REAL} or @code{COMPLEX}.
7123 The kind type parameter is the same as @var{X}.
7125 @item @emph{Example}:
7128 real(8) :: x = 10.0_8
7130 end program test_log10
7133 @item @emph{Specific names}:
7134 @multitable @columnfractions .20 .20 .20 .25
7135 @item Name @tab Argument @tab Return type @tab Standard
7136 @item @code{ALOG10(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 95 and later
7137 @item @code{DLOG10(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 95 and later
7144 @section @code{LOG_GAMMA} --- Logarithm of the Gamma function
7149 @cindex Gamma function, logarithm of
7152 @item @emph{Description}:
7153 @code{LOG_GAMMA(X)} computes the natural logarithm of the absolute value
7154 of the Gamma (@math{\Gamma}) function.
7156 @item @emph{Standard}:
7157 Fortran 2008 and later
7162 @item @emph{Syntax}:
7163 @code{X = LOG_GAMMA(X)}
7165 @item @emph{Arguments}:
7166 @multitable @columnfractions .15 .70
7167 @item @var{X} @tab Shall be of type @code{REAL} and neither zero
7168 nor a negative integer.
7171 @item @emph{Return value}:
7172 The return value is of type @code{REAL} of the same kind as @var{X}.
7174 @item @emph{Example}:
7176 program test_log_gamma
7178 x = lgamma(x) ! returns 0.0
7179 end program test_log_gamma
7182 @item @emph{Specific names}:
7183 @multitable @columnfractions .20 .20 .20 .25
7184 @item Name @tab Argument @tab Return type @tab Standard
7185 @item @code{LGAMMA(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab GNU Extension
7186 @item @code{ALGAMA(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab GNU Extension
7187 @item @code{DLGAMA(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU Extension
7190 @item @emph{See also}:
7191 Gamma function: @ref{GAMMA}
7198 @section @code{LOGICAL} --- Convert to logical type
7200 @cindex conversion, to logical
7203 @item @emph{Description}:
7204 Converts one kind of @code{LOGICAL} variable to another.
7206 @item @emph{Standard}:
7207 Fortran 95 and later
7212 @item @emph{Syntax}:
7213 @code{RESULT = LOGICAL(L [, KIND])}
7215 @item @emph{Arguments}:
7216 @multitable @columnfractions .15 .70
7217 @item @var{L} @tab The type shall be @code{LOGICAL}.
7218 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
7219 expression indicating the kind parameter of the result.
7222 @item @emph{Return value}:
7223 The return value is a @code{LOGICAL} value equal to @var{L}, with a
7224 kind corresponding to @var{KIND}, or of the default logical kind if
7225 @var{KIND} is not given.
7227 @item @emph{See also}:
7228 @ref{INT}, @ref{REAL}, @ref{CMPLX}
7234 @section @code{LONG} --- Convert to integer type
7236 @cindex conversion, to integer
7239 @item @emph{Description}:
7240 Convert to a @code{KIND=4} integer type, which is the same size as a C
7241 @code{long} integer. This is equivalent to the standard @code{INT}
7242 intrinsic with an optional argument of @code{KIND=4}, and is only
7243 included for backwards compatibility.
7245 @item @emph{Standard}:
7251 @item @emph{Syntax}:
7252 @code{RESULT = LONG(A)}
7254 @item @emph{Arguments}:
7255 @multitable @columnfractions .15 .70
7256 @item @var{A} @tab Shall be of type @code{INTEGER},
7257 @code{REAL}, or @code{COMPLEX}.
7260 @item @emph{Return value}:
7261 The return value is a @code{INTEGER(4)} variable.
7263 @item @emph{See also}:
7264 @ref{INT}, @ref{INT2}, @ref{INT8}
7270 @section @code{LSHIFT} --- Left shift bits
7272 @cindex bits, shift left
7275 @item @emph{Description}:
7276 @code{LSHIFT} returns a value corresponding to @var{I} with all of the
7277 bits shifted left by @var{SHIFT} places. If the absolute value of
7278 @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the value is undefined.
7279 Bits shifted out from the left end are lost; zeros are shifted in from
7282 This function has been superseded by the @code{ISHFT} intrinsic, which
7283 is standard in Fortran 95 and later.
7285 @item @emph{Standard}:
7291 @item @emph{Syntax}:
7292 @code{RESULT = LSHIFT(I, SHIFT)}
7294 @item @emph{Arguments}:
7295 @multitable @columnfractions .15 .70
7296 @item @var{I} @tab The type shall be @code{INTEGER}.
7297 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
7300 @item @emph{Return value}:
7301 The return value is of type @code{INTEGER} and of the same kind as
7304 @item @emph{See also}:
7305 @ref{ISHFT}, @ref{ISHFTC}, @ref{RSHIFT}
7312 @section @code{LSTAT} --- Get file status
7314 @cindex file system, file status
7317 @item @emph{Description}:
7318 @code{LSTAT} is identical to @ref{STAT}, except that if path is a
7319 symbolic link, then the link itself is statted, not the file that it
7322 The elements in @code{VALUES} are the same as described by @ref{STAT}.
7324 This intrinsic is provided in both subroutine and function forms;
7325 however, only one form can be used in any given program unit.
7327 @item @emph{Standard}:
7331 Subroutine, function
7333 @item @emph{Syntax}:
7334 @code{CALL LSTAT(NAME, VALUES [, STATUS])}
7336 @item @emph{Arguments}:
7337 @multitable @columnfractions .15 .70
7338 @item @var{NAME} @tab The type shall be @code{CHARACTER} of the default
7339 kind, a valid path within the file system.
7340 @item @var{VALUES} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
7341 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}.
7342 Returns 0 on success and a system specific error code otherwise.
7345 @item @emph{Example}:
7346 See @ref{STAT} for an example.
7348 @item @emph{See also}:
7349 To stat an open file: @ref{FSTAT}, to stat a file: @ref{STAT}
7355 @section @code{LTIME} --- Convert time to local time info
7357 @cindex time, conversion to local time info
7360 @item @emph{Description}:
7361 Given a system time value @var{TIME} (as provided by the @code{TIME8()}
7362 intrinsic), fills @var{VALUES} with values extracted from it appropriate
7363 to the local time zone using @code{localtime(3)}.
7365 @item @emph{Standard}:
7371 @item @emph{Syntax}:
7372 @code{CALL LTIME(TIME, VALUES)}
7374 @item @emph{Arguments}:
7375 @multitable @columnfractions .15 .70
7376 @item @var{TIME} @tab An @code{INTEGER} scalar expression
7377 corresponding to a system time, with @code{INTENT(IN)}.
7378 @item @var{VALUES} @tab A default @code{INTEGER} array with 9 elements,
7379 with @code{INTENT(OUT)}.
7382 @item @emph{Return value}:
7383 The elements of @var{VALUES} are assigned as follows:
7385 @item Seconds after the minute, range 0--59 or 0--61 to allow for leap
7387 @item Minutes after the hour, range 0--59
7388 @item Hours past midnight, range 0--23
7389 @item Day of month, range 0--31
7390 @item Number of months since January, range 0--12
7391 @item Years since 1900
7392 @item Number of days since Sunday, range 0--6
7393 @item Days since January 1
7394 @item Daylight savings indicator: positive if daylight savings is in
7395 effect, zero if not, and negative if the information is not available.
7398 @item @emph{See also}:
7399 @ref{CTIME}, @ref{GMTIME}, @ref{TIME}, @ref{TIME8}
7406 @section @code{MALLOC} --- Allocate dynamic memory
7408 @cindex pointer, cray
7411 @item @emph{Description}:
7412 @code{MALLOC(SIZE)} allocates @var{SIZE} bytes of dynamic memory and
7413 returns the address of the allocated memory. The @code{MALLOC} intrinsic
7414 is an extension intended to be used with Cray pointers, and is provided
7415 in GNU Fortran to allow the user to compile legacy code. For new code
7416 using Fortran 95 pointers, the memory allocation intrinsic is
7419 @item @emph{Standard}:
7425 @item @emph{Syntax}:
7426 @code{PTR = MALLOC(SIZE)}
7428 @item @emph{Arguments}:
7429 @multitable @columnfractions .15 .70
7430 @item @var{SIZE} @tab The type shall be @code{INTEGER}.
7433 @item @emph{Return value}:
7434 The return value is of type @code{INTEGER(K)}, with @var{K} such that
7435 variables of type @code{INTEGER(K)} have the same size as
7436 C pointers (@code{sizeof(void *)}).
7438 @item @emph{Example}:
7439 The following example demonstrates the use of @code{MALLOC} and
7440 @code{FREE} with Cray pointers.
7449 ptr_x = malloc(20*8)
7451 x(i) = sqrt(1.0d0 / i)
7459 end program test_malloc
7462 @item @emph{See also}:
7469 @section @code{MATMUL} --- matrix multiplication
7471 @cindex matrix multiplication
7472 @cindex product, matrix
7475 @item @emph{Description}:
7476 Performs a matrix multiplication on numeric or logical arguments.
7478 @item @emph{Standard}:
7479 Fortran 95 and later
7482 Transformational function
7484 @item @emph{Syntax}:
7485 @code{RESULT = MATMUL(MATRIX_A, MATRIX_B)}
7487 @item @emph{Arguments}:
7488 @multitable @columnfractions .15 .70
7489 @item @var{MATRIX_A} @tab An array of @code{INTEGER},
7490 @code{REAL}, @code{COMPLEX}, or @code{LOGICAL} type, with a rank of
7492 @item @var{MATRIX_B} @tab An array of @code{INTEGER},
7493 @code{REAL}, or @code{COMPLEX} type if @var{MATRIX_A} is of a numeric
7494 type; otherwise, an array of @code{LOGICAL} type. The rank shall be one
7495 or two, and the first (or only) dimension of @var{MATRIX_B} shall be
7496 equal to the last (or only) dimension of @var{MATRIX_A}.
7499 @item @emph{Return value}:
7500 The matrix product of @var{MATRIX_A} and @var{MATRIX_B}. The type and
7501 kind of the result follow the usual type and kind promotion rules, as
7502 for the @code{*} or @code{.AND.} operators.
7504 @item @emph{See also}:
7510 @section @code{MAX} --- Maximum value of an argument list
7517 @cindex maximum value
7520 @item @emph{Description}:
7521 Returns the argument with the largest (most positive) value.
7523 @item @emph{Standard}:
7524 Fortran 77 and later
7529 @item @emph{Syntax}:
7530 @code{RESULT = MAX(A1, A2 [, A3 [, ...]])}
7532 @item @emph{Arguments}:
7533 @multitable @columnfractions .15 .70
7534 @item @var{A1} @tab The type shall be @code{INTEGER} or
7536 @item @var{A2}, @var{A3}, ... @tab An expression of the same type and kind
7537 as @var{A1}. (As a GNU extension, arguments of different kinds are
7541 @item @emph{Return value}:
7542 The return value corresponds to the maximum value among the arguments,
7543 and has the same type and kind as the first argument.
7545 @item @emph{Specific names}:
7546 @multitable @columnfractions .20 .20 .20 .25
7547 @item Name @tab Argument @tab Return type @tab Standard
7548 @item @code{MAX0(A1)} @tab @code{INTEGER(4) A1} @tab @code{INTEGER(4)} @tab Fortran 77 and later
7549 @item @code{AMAX0(A1)} @tab @code{INTEGER(4) A1} @tab @code{REAL(MAX(X))} @tab Fortran 77 and later
7550 @item @code{MAX1(A1)} @tab @code{REAL A1} @tab @code{INT(MAX(X))} @tab Fortran 77 and later
7551 @item @code{AMAX1(A1)} @tab @code{REAL(4) A1} @tab @code{REAL(4)} @tab Fortran 77 and later
7552 @item @code{DMAX1(A1)} @tab @code{REAL(8) A1} @tab @code{REAL(8)} @tab Fortran 77 and later
7555 @item @emph{See also}:
7556 @ref{MAXLOC} @ref{MAXVAL}, @ref{MIN}
7563 @section @code{MAXEXPONENT} --- Maximum exponent of a real kind
7564 @fnindex MAXEXPONENT
7565 @cindex model representation, maximum exponent
7568 @item @emph{Description}:
7569 @code{MAXEXPONENT(X)} returns the maximum exponent in the model of the
7572 @item @emph{Standard}:
7573 Fortran 95 and later
7578 @item @emph{Syntax}:
7579 @code{RESULT = MAXEXPONENT(X)}
7581 @item @emph{Arguments}:
7582 @multitable @columnfractions .15 .70
7583 @item @var{X} @tab Shall be of type @code{REAL}.
7586 @item @emph{Return value}:
7587 The return value is of type @code{INTEGER} and of the default integer
7590 @item @emph{Example}:
7596 print *, minexponent(x), maxexponent(x)
7597 print *, minexponent(y), maxexponent(y)
7598 end program exponents
7605 @section @code{MAXLOC} --- Location of the maximum value within an array
7607 @cindex array, location of maximum element
7610 @item @emph{Description}:
7611 Determines the location of the element in the array with the maximum
7612 value, or, if the @var{DIM} argument is supplied, determines the
7613 locations of the maximum element along each row of the array in the
7614 @var{DIM} direction. If @var{MASK} is present, only the elements for
7615 which @var{MASK} is @code{.TRUE.} are considered. If more than one
7616 element in the array has the maximum value, the location returned is
7617 that of the first such element in array element order. If the array has
7618 zero size, or all of the elements of @var{MASK} are @code{.FALSE.}, then
7619 the result is an array of zeroes. Similarly, if @var{DIM} is supplied
7620 and all of the elements of @var{MASK} along a given row are zero, the
7621 result value for that row is zero.
7623 @item @emph{Standard}:
7624 Fortran 95 and later
7627 Transformational function
7629 @item @emph{Syntax}:
7630 @multitable @columnfractions .80
7631 @item @code{RESULT = MAXLOC(ARRAY, DIM [, MASK])}
7632 @item @code{RESULT = MAXLOC(ARRAY [, MASK])}
7635 @item @emph{Arguments}:
7636 @multitable @columnfractions .15 .70
7637 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER} or
7639 @item @var{DIM} @tab (Optional) Shall be a scalar of type
7640 @code{INTEGER}, with a value between one and the rank of @var{ARRAY},
7641 inclusive. It may not be an optional dummy argument.
7642 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL},
7643 and conformable with @var{ARRAY}.
7646 @item @emph{Return value}:
7647 If @var{DIM} is absent, the result is a rank-one array with a length
7648 equal to the rank of @var{ARRAY}. If @var{DIM} is present, the result
7649 is an array with a rank one less than the rank of @var{ARRAY}, and a
7650 size corresponding to the size of @var{ARRAY} with the @var{DIM}
7651 dimension removed. If @var{DIM} is present and @var{ARRAY} has a rank
7652 of one, the result is a scalar. In all cases, the result is of default
7653 @code{INTEGER} type.
7655 @item @emph{See also}:
7656 @ref{MAX}, @ref{MAXVAL}
7663 @section @code{MAXVAL} --- Maximum value of an array
7665 @cindex array, maximum value
7666 @cindex maximum value
7669 @item @emph{Description}:
7670 Determines the maximum value of the elements in an array value, or, if
7671 the @var{DIM} argument is supplied, determines the maximum value along
7672 each row of the array in the @var{DIM} direction. If @var{MASK} is
7673 present, only the elements for which @var{MASK} is @code{.TRUE.} are
7674 considered. If the array has zero size, or all of the elements of
7675 @var{MASK} are @code{.FALSE.}, then the result is @code{-HUGE(ARRAY)}
7676 if @var{ARRAY} is numeric, or a string of nulls if @var{ARRAY} is of character
7679 @item @emph{Standard}:
7680 Fortran 95 and later
7683 Transformational function
7685 @item @emph{Syntax}:
7686 @multitable @columnfractions .80
7687 @item @code{RESULT = MAXVAL(ARRAY, DIM [, MASK])}
7688 @item @code{RESULT = MAXVAL(ARRAY [, MASK])}
7691 @item @emph{Arguments}:
7692 @multitable @columnfractions .15 .70
7693 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER} or
7695 @item @var{DIM} @tab (Optional) Shall be a scalar of type
7696 @code{INTEGER}, with a value between one and the rank of @var{ARRAY},
7697 inclusive. It may not be an optional dummy argument.
7698 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL},
7699 and conformable with @var{ARRAY}.
7702 @item @emph{Return value}:
7703 If @var{DIM} is absent, or if @var{ARRAY} has a rank of one, the result
7704 is a scalar. If @var{DIM} is present, the result is an array with a
7705 rank one less than the rank of @var{ARRAY}, and a size corresponding to
7706 the size of @var{ARRAY} with the @var{DIM} dimension removed. In all
7707 cases, the result is of the same type and kind as @var{ARRAY}.
7709 @item @emph{See also}:
7710 @ref{MAX}, @ref{MAXLOC}
7716 @section @code{MCLOCK} --- Time function
7718 @cindex time, clock ticks
7722 @item @emph{Description}:
7723 Returns the number of clock ticks since the start of the process, based
7724 on the UNIX function @code{clock(3)}.
7726 This intrinsic is not fully portable, such as to systems with 32-bit
7727 @code{INTEGER} types but supporting times wider than 32 bits. Therefore,
7728 the values returned by this intrinsic might be, or become, negative, or
7729 numerically less than previous values, during a single run of the
7732 @item @emph{Standard}:
7738 @item @emph{Syntax}:
7739 @code{RESULT = MCLOCK()}
7741 @item @emph{Return value}:
7742 The return value is a scalar of type @code{INTEGER(4)}, equal to the
7743 number of clock ticks since the start of the process, or @code{-1} if
7744 the system does not support @code{clock(3)}.
7746 @item @emph{See also}:
7747 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK}, @ref{TIME}
7754 @section @code{MCLOCK8} --- Time function (64-bit)
7756 @cindex time, clock ticks
7760 @item @emph{Description}:
7761 Returns the number of clock ticks since the start of the process, based
7762 on the UNIX function @code{clock(3)}.
7764 @emph{Warning:} this intrinsic does not increase the range of the timing
7765 values over that returned by @code{clock(3)}. On a system with a 32-bit
7766 @code{clock(3)}, @code{MCLOCK8()} will return a 32-bit value, even though
7767 it is converted to a 64-bit @code{INTEGER(8)} value. That means
7768 overflows of the 32-bit value can still occur. Therefore, the values
7769 returned by this intrinsic might be or become negative or numerically
7770 less than previous values during a single run of the compiled program.
7772 @item @emph{Standard}:
7778 @item @emph{Syntax}:
7779 @code{RESULT = MCLOCK8()}
7781 @item @emph{Return value}:
7782 The return value is a scalar of type @code{INTEGER(8)}, equal to the
7783 number of clock ticks since the start of the process, or @code{-1} if
7784 the system does not support @code{clock(3)}.
7786 @item @emph{See also}:
7787 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK}, @ref{TIME8}
7794 @section @code{MERGE} --- Merge variables
7796 @cindex array, merge arrays
7797 @cindex array, combine arrays
7800 @item @emph{Description}:
7801 Select values from two arrays according to a logical mask. The result
7802 is equal to @var{TSOURCE} if @var{MASK} is @code{.TRUE.}, or equal to
7803 @var{FSOURCE} if it is @code{.FALSE.}.
7805 @item @emph{Standard}:
7806 Fortran 95 and later
7811 @item @emph{Syntax}:
7812 @code{RESULT = MERGE(TSOURCE, FSOURCE, MASK)}
7814 @item @emph{Arguments}:
7815 @multitable @columnfractions .15 .70
7816 @item @var{TSOURCE} @tab May be of any type.
7817 @item @var{FSOURCE} @tab Shall be of the same type and type parameters
7819 @item @var{MASK} @tab Shall be of type @code{LOGICAL}.
7822 @item @emph{Return value}:
7823 The result is of the same type and type parameters as @var{TSOURCE}.
7830 @section @code{MIN} --- Minimum value of an argument list
7837 @cindex minimum value
7840 @item @emph{Description}:
7841 Returns the argument with the smallest (most negative) value.
7843 @item @emph{Standard}:
7844 Fortran 77 and later
7849 @item @emph{Syntax}:
7850 @code{RESULT = MIN(A1, A2 [, A3, ...])}
7852 @item @emph{Arguments}:
7853 @multitable @columnfractions .15 .70
7854 @item @var{A1} @tab The type shall be @code{INTEGER} or
7856 @item @var{A2}, @var{A3}, ... @tab An expression of the same type and kind
7857 as @var{A1}. (As a GNU extension, arguments of different kinds are
7861 @item @emph{Return value}:
7862 The return value corresponds to the maximum value among the arguments,
7863 and has the same type and kind as the first argument.
7865 @item @emph{Specific names}:
7866 @multitable @columnfractions .20 .20 .20 .25
7867 @item Name @tab Argument @tab Return type @tab Standard
7868 @item @code{MIN0(A1)} @tab @code{INTEGER(4) A1} @tab @code{INTEGER(4)} @tab Fortran 77 and later
7869 @item @code{AMIN0(A1)} @tab @code{INTEGER(4) A1} @tab @code{REAL(4)} @tab Fortran 77 and later
7870 @item @code{MIN1(A1)} @tab @code{REAL A1} @tab @code{INTEGER(4)} @tab Fortran 77 and later
7871 @item @code{AMIN1(A1)} @tab @code{REAL(4) A1} @tab @code{REAL(4)} @tab Fortran 77 and later
7872 @item @code{DMIN1(A1)} @tab @code{REAL(8) A1} @tab @code{REAL(8)} @tab Fortran 77 and later
7875 @item @emph{See also}:
7876 @ref{MAX}, @ref{MINLOC}, @ref{MINVAL}
7882 @section @code{MINEXPONENT} --- Minimum exponent of a real kind
7883 @fnindex MINEXPONENT
7884 @cindex model representation, minimum exponent
7887 @item @emph{Description}:
7888 @code{MINEXPONENT(X)} returns the minimum exponent in the model of the
7891 @item @emph{Standard}:
7892 Fortran 95 and later
7897 @item @emph{Syntax}:
7898 @code{RESULT = MINEXPONENT(X)}
7900 @item @emph{Arguments}:
7901 @multitable @columnfractions .15 .70
7902 @item @var{X} @tab Shall be of type @code{REAL}.
7905 @item @emph{Return value}:
7906 The return value is of type @code{INTEGER} and of the default integer
7909 @item @emph{Example}:
7910 See @code{MAXEXPONENT} for an example.
7916 @section @code{MINLOC} --- Location of the minimum value within an array
7918 @cindex array, location of minimum element
7921 @item @emph{Description}:
7922 Determines the location of the element in the array with the minimum
7923 value, or, if the @var{DIM} argument is supplied, determines the
7924 locations of the minimum element along each row of the array in the
7925 @var{DIM} direction. If @var{MASK} is present, only the elements for
7926 which @var{MASK} is @code{.TRUE.} are considered. If more than one
7927 element in the array has the minimum value, the location returned is
7928 that of the first such element in array element order. If the array has
7929 zero size, or all of the elements of @var{MASK} are @code{.FALSE.}, then
7930 the result is an array of zeroes. Similarly, if @var{DIM} is supplied
7931 and all of the elements of @var{MASK} along a given row are zero, the
7932 result value for that row is zero.
7934 @item @emph{Standard}:
7935 Fortran 95 and later
7938 Transformational function
7940 @item @emph{Syntax}:
7941 @multitable @columnfractions .80
7942 @item @code{RESULT = MINLOC(ARRAY, DIM [, MASK])}
7943 @item @code{RESULT = MINLOC(ARRAY [, MASK])}
7946 @item @emph{Arguments}:
7947 @multitable @columnfractions .15 .70
7948 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER} or
7950 @item @var{DIM} @tab (Optional) Shall be a scalar of type
7951 @code{INTEGER}, with a value between one and the rank of @var{ARRAY},
7952 inclusive. It may not be an optional dummy argument.
7953 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL},
7954 and conformable with @var{ARRAY}.
7957 @item @emph{Return value}:
7958 If @var{DIM} is absent, the result is a rank-one array with a length
7959 equal to the rank of @var{ARRAY}. If @var{DIM} is present, the result
7960 is an array with a rank one less than the rank of @var{ARRAY}, and a
7961 size corresponding to the size of @var{ARRAY} with the @var{DIM}
7962 dimension removed. If @var{DIM} is present and @var{ARRAY} has a rank
7963 of one, the result is a scalar. In all cases, the result is of default
7964 @code{INTEGER} type.
7966 @item @emph{See also}:
7967 @ref{MIN}, @ref{MINVAL}
7974 @section @code{MINVAL} --- Minimum value of an array
7976 @cindex array, minimum value
7977 @cindex minimum value
7980 @item @emph{Description}:
7981 Determines the minimum value of the elements in an array value, or, if
7982 the @var{DIM} argument is supplied, determines the minimum value along
7983 each row of the array in the @var{DIM} direction. If @var{MASK} is
7984 present, only the elements for which @var{MASK} is @code{.TRUE.} are
7985 considered. If the array has zero size, or all of the elements of
7986 @var{MASK} are @code{.FALSE.}, then the result is @code{HUGE(ARRAY)} if
7987 @var{ARRAY} is numeric, or a string of @code{CHAR(255)} characters if
7988 @var{ARRAY} is of character type.
7990 @item @emph{Standard}:
7991 Fortran 95 and later
7994 Transformational function
7996 @item @emph{Syntax}:
7997 @multitable @columnfractions .80
7998 @item @code{RESULT = MINVAL(ARRAY, DIM [, MASK])}
7999 @item @code{RESULT = MINVAL(ARRAY [, MASK])}
8002 @item @emph{Arguments}:
8003 @multitable @columnfractions .15 .70
8004 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER} or
8006 @item @var{DIM} @tab (Optional) Shall be a scalar of type
8007 @code{INTEGER}, with a value between one and the rank of @var{ARRAY},
8008 inclusive. It may not be an optional dummy argument.
8009 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL},
8010 and conformable with @var{ARRAY}.
8013 @item @emph{Return value}:
8014 If @var{DIM} is absent, or if @var{ARRAY} has a rank of one, the result
8015 is a scalar. If @var{DIM} is present, the result is an array with a
8016 rank one less than the rank of @var{ARRAY}, and a size corresponding to
8017 the size of @var{ARRAY} with the @var{DIM} dimension removed. In all
8018 cases, the result is of the same type and kind as @var{ARRAY}.
8020 @item @emph{See also}:
8021 @ref{MIN}, @ref{MINLOC}
8028 @section @code{MOD} --- Remainder function
8033 @cindex division, remainder
8036 @item @emph{Description}:
8037 @code{MOD(A,P)} computes the remainder of the division of A by P@. It is
8038 calculated as @code{A - (INT(A/P) * P)}.
8040 @item @emph{Standard}:
8041 Fortran 77 and later
8046 @item @emph{Syntax}:
8047 @code{RESULT = MOD(A, P)}
8049 @item @emph{Arguments}:
8050 @multitable @columnfractions .15 .70
8051 @item @var{A} @tab Shall be a scalar of type @code{INTEGER} or @code{REAL}
8052 @item @var{P} @tab Shall be a scalar of the same type as @var{A} and not
8056 @item @emph{Return value}:
8057 The kind of the return value is the result of cross-promoting
8058 the kinds of the arguments.
8060 @item @emph{Example}:
8064 print *, mod(17.5,5.5)
8065 print *, mod(17.5d0,5.5)
8066 print *, mod(17.5,5.5d0)
8069 print *, mod(-17.5,5.5)
8070 print *, mod(-17.5d0,5.5)
8071 print *, mod(-17.5,5.5d0)
8074 print *, mod(17.5,-5.5)
8075 print *, mod(17.5d0,-5.5)
8076 print *, mod(17.5,-5.5d0)
8077 end program test_mod
8080 @item @emph{Specific names}:
8081 @multitable @columnfractions .20 .20 .20 .25
8082 @item Name @tab Arguments @tab Return type @tab Standard
8083 @item @code{MOD(A,P)} @tab @code{INTEGER A,P} @tab @code{INTEGER} @tab Fortran 95 and later
8084 @item @code{AMOD(A,P)} @tab @code{REAL(4) A,P} @tab @code{REAL(4)} @tab Fortran 95 and later
8085 @item @code{DMOD(A,P)} @tab @code{REAL(8) A,P} @tab @code{REAL(8)} @tab Fortran 95 and later
8092 @section @code{MODULO} --- Modulo function
8095 @cindex division, modulo
8098 @item @emph{Description}:
8099 @code{MODULO(A,P)} computes the @var{A} modulo @var{P}.
8101 @item @emph{Standard}:
8102 Fortran 95 and later
8107 @item @emph{Syntax}:
8108 @code{RESULT = MODULO(A, P)}
8110 @item @emph{Arguments}:
8111 @multitable @columnfractions .15 .70
8112 @item @var{A} @tab Shall be a scalar of type @code{INTEGER} or @code{REAL}
8113 @item @var{P} @tab Shall be a scalar of the same type and kind as @var{A}
8116 @item @emph{Return value}:
8117 The type and kind of the result are those of the arguments.
8119 @item If @var{A} and @var{P} are of type @code{INTEGER}:
8120 @code{MODULO(A,P)} has the value @var{R} such that @code{A=Q*P+R}, where
8121 @var{Q} is an integer and @var{R} is between 0 (inclusive) and @var{P}
8123 @item If @var{A} and @var{P} are of type @code{REAL}:
8124 @code{MODULO(A,P)} has the value of @code{A - FLOOR (A / P) * P}.
8126 In all cases, if @var{P} is zero the result is processor-dependent.
8128 @item @emph{Example}:
8131 print *, modulo(17,3)
8132 print *, modulo(17.5,5.5)
8134 print *, modulo(-17,3)
8135 print *, modulo(-17.5,5.5)
8137 print *, modulo(17,-3)
8138 print *, modulo(17.5,-5.5)
8147 @section @code{MOVE_ALLOC} --- Move allocation from one object to another
8149 @cindex moving allocation
8150 @cindex allocation, moving
8153 @item @emph{Description}:
8154 @code{MOVE_ALLOC(FROM, TO)} moves the allocation from @var{FROM} to
8155 @var{TO}. @var{FROM} will become deallocated in the process.
8157 @item @emph{Standard}:
8158 Fortran 2003 and later
8163 @item @emph{Syntax}:
8164 @code{CALL MOVE_ALLOC(FROM, TO)}
8166 @item @emph{Arguments}:
8167 @multitable @columnfractions .15 .70
8168 @item @var{FROM} @tab @code{ALLOCATABLE}, @code{INTENT(INOUT)}, may be
8169 of any type and kind.
8170 @item @var{TO} @tab @code{ALLOCATABLE}, @code{INTENT(OUT)}, shall be
8171 of the same type, kind and rank as @var{FROM}.
8174 @item @emph{Return value}:
8177 @item @emph{Example}:
8179 program test_move_alloc
8180 integer, allocatable :: a(:), b(:)
8184 call move_alloc(a, b)
8185 print *, allocated(a), allocated(b)
8187 end program test_move_alloc
8194 @section @code{MVBITS} --- Move bits from one integer to another
8199 @item @emph{Description}:
8200 Moves @var{LEN} bits from positions @var{FROMPOS} through
8201 @code{FROMPOS+LEN-1} of @var{FROM} to positions @var{TOPOS} through
8202 @code{TOPOS+LEN-1} of @var{TO}. The portion of argument @var{TO} not
8203 affected by the movement of bits is unchanged. The values of
8204 @code{FROMPOS+LEN-1} and @code{TOPOS+LEN-1} must be less than
8205 @code{BIT_SIZE(FROM)}.
8207 @item @emph{Standard}:
8208 Fortran 95 and later
8211 Elemental subroutine
8213 @item @emph{Syntax}:
8214 @code{CALL MVBITS(FROM, FROMPOS, LEN, TO, TOPOS)}
8216 @item @emph{Arguments}:
8217 @multitable @columnfractions .15 .70
8218 @item @var{FROM} @tab The type shall be @code{INTEGER}.
8219 @item @var{FROMPOS} @tab The type shall be @code{INTEGER}.
8220 @item @var{LEN} @tab The type shall be @code{INTEGER}.
8221 @item @var{TO} @tab The type shall be @code{INTEGER}, of the
8222 same kind as @var{FROM}.
8223 @item @var{TOPOS} @tab The type shall be @code{INTEGER}.
8226 @item @emph{See also}:
8227 @ref{IBCLR}, @ref{IBSET}, @ref{IBITS}, @ref{IAND}, @ref{IOR}, @ref{IEOR}
8233 @section @code{NEAREST} --- Nearest representable number
8235 @cindex real number, nearest different
8236 @cindex floating point, nearest different
8239 @item @emph{Description}:
8240 @code{NEAREST(X, S)} returns the processor-representable number nearest
8241 to @code{X} in the direction indicated by the sign of @code{S}.
8243 @item @emph{Standard}:
8244 Fortran 95 and later
8249 @item @emph{Syntax}:
8250 @code{RESULT = NEAREST(X, S)}
8252 @item @emph{Arguments}:
8253 @multitable @columnfractions .15 .70
8254 @item @var{X} @tab Shall be of type @code{REAL}.
8255 @item @var{S} @tab (Optional) shall be of type @code{REAL} and
8259 @item @emph{Return value}:
8260 The return value is of the same type as @code{X}. If @code{S} is
8261 positive, @code{NEAREST} returns the processor-representable number
8262 greater than @code{X} and nearest to it. If @code{S} is negative,
8263 @code{NEAREST} returns the processor-representable number smaller than
8264 @code{X} and nearest to it.
8266 @item @emph{Example}:
8268 program test_nearest
8270 x = nearest(42.0, 1.0)
8271 y = nearest(42.0, -1.0)
8272 write (*,"(3(G20.15))") x, y, x - y
8273 end program test_nearest
8280 @section @code{NEW_LINE} --- New line character
8283 @cindex output, newline
8286 @item @emph{Description}:
8287 @code{NEW_LINE(C)} returns the new-line character.
8289 @item @emph{Standard}:
8290 Fortran 2003 and later
8295 @item @emph{Syntax}:
8296 @code{RESULT = NEW_LINE(C)}
8298 @item @emph{Arguments}:
8299 @multitable @columnfractions .15 .70
8300 @item @var{C} @tab The argument shall be a scalar or array of the
8301 type @code{CHARACTER}.
8304 @item @emph{Return value}:
8305 Returns a @var{CHARACTER} scalar of length one with the new-line character of
8306 the same kind as parameter @var{C}.
8308 @item @emph{Example}:
8312 write(*,'(A)') 'This is record 1.'//NEW_LINE('A')//'This is record 2.'
8320 @section @code{NINT} --- Nearest whole number
8323 @cindex rounding, nearest whole number
8326 @item @emph{Description}:
8327 @code{NINT(A)} rounds its argument to the nearest whole number.
8329 @item @emph{Standard}:
8330 Fortran 77 and later, with @var{KIND} argument Fortran 90 and later
8335 @item @emph{Syntax}:
8336 @code{RESULT = NINT(A [, KIND])}
8338 @item @emph{Arguments}:
8339 @multitable @columnfractions .15 .70
8340 @item @var{A} @tab The type of the argument shall be @code{REAL}.
8341 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
8342 expression indicating the kind parameter of the result.
8345 @item @emph{Return value}:
8346 Returns @var{A} with the fractional portion of its magnitude eliminated by
8347 rounding to the nearest whole number and with its sign preserved,
8348 converted to an @code{INTEGER} of the default kind.
8350 @item @emph{Example}:
8357 print *, nint(x4), idnint(x8)
8358 end program test_nint
8361 @item @emph{Specific names}:
8362 @multitable @columnfractions .20 .20 .20 .25
8363 @item Name @tab Argument @tab Return Type @tab Standard
8364 @item @code{NINT(A)} @tab @code{REAL(4) A} @tab @code{INTEGER} @tab Fortran 95 and later
8365 @item @code{IDNINT(A)} @tab @code{REAL(8) A} @tab @code{INTEGER} @tab Fortran 95 and later
8368 @item @emph{See also}:
8369 @ref{CEILING}, @ref{FLOOR}
8376 @section @code{NOT} --- Logical negation
8378 @cindex bits, negate
8379 @cindex bitwise logical not
8380 @cindex logical not, bitwise
8383 @item @emph{Description}:
8384 @code{NOT} returns the bitwise boolean inverse of @var{I}.
8386 @item @emph{Standard}:
8387 Fortran 95 and later
8392 @item @emph{Syntax}:
8393 @code{RESULT = NOT(I)}
8395 @item @emph{Arguments}:
8396 @multitable @columnfractions .15 .70
8397 @item @var{I} @tab The type shall be @code{INTEGER}.
8400 @item @emph{Return value}:
8401 The return type is @code{INTEGER}, of the same kind as the
8404 @item @emph{See also}:
8405 @ref{IAND}, @ref{IEOR}, @ref{IOR}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}
8412 @section @code{NULL} --- Function that returns an disassociated pointer
8414 @cindex pointer, status
8415 @cindex pointer, disassociated
8418 @item @emph{Description}:
8419 Returns a disassociated pointer.
8421 If @var{MOLD} is present, a dissassociated pointer of the same type is
8422 returned, otherwise the type is determined by context.
8424 In Fortran 95, @var{MOLD} is optional. Please note that Fortran 2003
8425 includes cases where it is required.
8427 @item @emph{Standard}:
8428 Fortran 95 and later
8431 Transformational function
8433 @item @emph{Syntax}:
8434 @code{PTR => NULL([MOLD])}
8436 @item @emph{Arguments}:
8437 @multitable @columnfractions .15 .70
8438 @item @var{MOLD} @tab (Optional) shall be a pointer of any association
8439 status and of any type.
8442 @item @emph{Return value}:
8443 A disassociated pointer.
8445 @item @emph{Example}:
8447 REAL, POINTER, DIMENSION(:) :: VEC => NULL ()
8450 @item @emph{See also}:
8457 @section @code{NUM_IMAGES} --- Function that returns the number of images
8459 @cindex coarray, NUM_IMAGES
8460 @cindex images, number of
8463 @item @emph{Description}:
8464 Returns the number of images.
8466 @item @emph{Standard}:
8467 Fortran 2008 and later
8470 Transformational function
8472 @item @emph{Syntax}:
8473 @code{RESULT = NUM_IMAGES()}
8475 @item @emph{Arguments}: None.
8477 @item @emph{Return value}:
8478 Scalar default-kind integer.
8480 @item @emph{Example}:
8484 value = THIS_IMAGE()
8486 IF (THIS_IMAGE() == 1) THEN
8487 DO i = 1, NUM_IMAGES()
8488 WRITE(*,'(2(a,i0))') 'value[', i, '] is ', value[i]
8493 @item @emph{See also}:
8494 @ref{THIS_IMAGE}, @ref{IMAGE_INDEX}
8500 @section @code{OR} --- Bitwise logical OR
8502 @cindex bitwise logical or
8503 @cindex logical or, bitwise
8506 @item @emph{Description}:
8507 Bitwise logical @code{OR}.
8509 This intrinsic routine is provided for backwards compatibility with
8510 GNU Fortran 77. For integer arguments, programmers should consider
8511 the use of the @ref{IOR} intrinsic defined by the Fortran standard.
8513 @item @emph{Standard}:
8519 @item @emph{Syntax}:
8520 @code{RESULT = OR(I, J)}
8522 @item @emph{Arguments}:
8523 @multitable @columnfractions .15 .70
8524 @item @var{I} @tab The type shall be either a scalar @code{INTEGER}
8525 type or a scalar @code{LOGICAL} type.
8526 @item @var{J} @tab The type shall be the same as the type of @var{J}.
8529 @item @emph{Return value}:
8530 The return type is either a scalar @code{INTEGER} or a scalar
8531 @code{LOGICAL}. If the kind type parameters differ, then the
8532 smaller kind type is implicitly converted to larger kind, and the
8533 return has the larger kind.
8535 @item @emph{Example}:
8538 LOGICAL :: T = .TRUE., F = .FALSE.
8540 DATA a / Z'F' /, b / Z'3' /
8542 WRITE (*,*) OR(T, T), OR(T, F), OR(F, T), OR(F, F)
8543 WRITE (*,*) OR(a, b)
8547 @item @emph{See also}:
8548 Fortran 95 elemental function: @ref{IOR}
8554 @section @code{PACK} --- Pack an array into an array of rank one
8556 @cindex array, packing
8557 @cindex array, reduce dimension
8558 @cindex array, gather elements
8561 @item @emph{Description}:
8562 Stores the elements of @var{ARRAY} in an array of rank one.
8564 The beginning of the resulting array is made up of elements whose @var{MASK}
8565 equals @code{TRUE}. Afterwards, positions are filled with elements taken from
8568 @item @emph{Standard}:
8569 Fortran 95 and later
8572 Transformational function
8574 @item @emph{Syntax}:
8575 @code{RESULT = PACK(ARRAY, MASK[,VECTOR]}
8577 @item @emph{Arguments}:
8578 @multitable @columnfractions .15 .70
8579 @item @var{ARRAY} @tab Shall be an array of any type.
8580 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL} and
8581 of the same size as @var{ARRAY}. Alternatively, it may be a @code{LOGICAL}
8583 @item @var{VECTOR} @tab (Optional) shall be an array of the same type
8584 as @var{ARRAY} and of rank one. If present, the number of elements in
8585 @var{VECTOR} shall be equal to or greater than the number of true elements
8586 in @var{MASK}. If @var{MASK} is scalar, the number of elements in
8587 @var{VECTOR} shall be equal to or greater than the number of elements in
8591 @item @emph{Return value}:
8592 The result is an array of rank one and the same type as that of @var{ARRAY}.
8593 If @var{VECTOR} is present, the result size is that of @var{VECTOR}, the
8594 number of @code{TRUE} values in @var{MASK} otherwise.
8596 @item @emph{Example}:
8597 Gathering nonzero elements from an array:
8601 m = (/ 1, 0, 0, 0, 5, 0 /)
8602 WRITE(*, FMT="(6(I0, ' '))") pack(m, m /= 0) ! "1 5"
8606 Gathering nonzero elements from an array and appending elements from @var{VECTOR}:
8610 m = (/ 1, 0, 0, 2 /)
8611 WRITE(*, FMT="(4(I0, ' '))") pack(m, m /= 0, (/ 0, 0, 3, 4 /)) ! "1 2 3 4"
8615 @item @emph{See also}:
8622 @section @code{PERROR} --- Print system error message
8624 @cindex system, error handling
8627 @item @emph{Description}:
8628 Prints (on the C @code{stderr} stream) a newline-terminated error
8629 message corresponding to the last system error. This is prefixed by
8630 @var{STRING}, a colon and a space. See @code{perror(3)}.
8632 @item @emph{Standard}:
8638 @item @emph{Syntax}:
8639 @code{CALL PERROR(STRING)}
8641 @item @emph{Arguments}:
8642 @multitable @columnfractions .15 .70
8643 @item @var{STRING} @tab A scalar of type @code{CHARACTER} and of the
8647 @item @emph{See also}:
8654 @section @code{PRECISION} --- Decimal precision of a real kind
8656 @cindex model representation, precision
8659 @item @emph{Description}:
8660 @code{PRECISION(X)} returns the decimal precision in the model of the
8663 @item @emph{Standard}:
8664 Fortran 95 and later
8669 @item @emph{Syntax}:
8670 @code{RESULT = PRECISION(X)}
8672 @item @emph{Arguments}:
8673 @multitable @columnfractions .15 .70
8674 @item @var{X} @tab Shall be of type @code{REAL} or @code{COMPLEX}.
8677 @item @emph{Return value}:
8678 The return value is of type @code{INTEGER} and of the default integer
8681 @item @emph{Example}:
8683 program prec_and_range
8684 real(kind=4) :: x(2)
8685 complex(kind=8) :: y
8687 print *, precision(x), range(x)
8688 print *, precision(y), range(y)
8689 end program prec_and_range
8696 @section @code{PRESENT} --- Determine whether an optional dummy argument is specified
8700 @item @emph{Description}:
8701 Determines whether an optional dummy argument is present.
8703 @item @emph{Standard}:
8704 Fortran 95 and later
8709 @item @emph{Syntax}:
8710 @code{RESULT = PRESENT(A)}
8712 @item @emph{Arguments}:
8713 @multitable @columnfractions .15 .70
8714 @item @var{A} @tab May be of any type and may be a pointer, scalar or array
8715 value, or a dummy procedure. It shall be the name of an optional dummy argument
8716 accessible within the current subroutine or function.
8719 @item @emph{Return value}:
8720 Returns either @code{TRUE} if the optional argument @var{A} is present, or
8721 @code{FALSE} otherwise.
8723 @item @emph{Example}:
8725 PROGRAM test_present
8726 WRITE(*,*) f(), f(42) ! "F T"
8728 LOGICAL FUNCTION f(x)
8729 INTEGER, INTENT(IN), OPTIONAL :: x
8739 @section @code{PRODUCT} --- Product of array elements
8741 @cindex array, product
8742 @cindex array, multiply elements
8743 @cindex array, conditionally multiply elements
8744 @cindex multiply array elements
8747 @item @emph{Description}:
8748 Multiplies the elements of @var{ARRAY} along dimension @var{DIM} if
8749 the corresponding element in @var{MASK} is @code{TRUE}.
8751 @item @emph{Standard}:
8752 Fortran 95 and later
8755 Transformational function
8757 @item @emph{Syntax}:
8758 @multitable @columnfractions .80
8759 @item @code{RESULT = PRODUCT(ARRAY[, MASK])}
8760 @item @code{RESULT = PRODUCT(ARRAY, DIM[, MASK])}
8763 @item @emph{Arguments}:
8764 @multitable @columnfractions .15 .70
8765 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER},
8766 @code{REAL} or @code{COMPLEX}.
8767 @item @var{DIM} @tab (Optional) shall be a scalar of type
8768 @code{INTEGER} with a value in the range from 1 to n, where n
8769 equals the rank of @var{ARRAY}.
8770 @item @var{MASK} @tab (Optional) shall be of type @code{LOGICAL}
8771 and either be a scalar or an array of the same shape as @var{ARRAY}.
8774 @item @emph{Return value}:
8775 The result is of the same type as @var{ARRAY}.
8777 If @var{DIM} is absent, a scalar with the product of all elements in
8778 @var{ARRAY} is returned. Otherwise, an array of rank n-1, where n equals
8779 the rank of @var{ARRAY}, and a shape similar to that of @var{ARRAY} with
8780 dimension @var{DIM} dropped is returned.
8783 @item @emph{Example}:
8785 PROGRAM test_product
8786 INTEGER :: x(5) = (/ 1, 2, 3, 4 ,5 /)
8787 print *, PRODUCT(x) ! all elements, product = 120
8788 print *, PRODUCT(x, MASK=MOD(x, 2)==1) ! odd elements, product = 15
8792 @item @emph{See also}:
8799 @section @code{RADIX} --- Base of a model number
8801 @cindex model representation, base
8802 @cindex model representation, radix
8805 @item @emph{Description}:
8806 @code{RADIX(X)} returns the base of the model representing the entity @var{X}.
8808 @item @emph{Standard}:
8809 Fortran 95 and later
8814 @item @emph{Syntax}:
8815 @code{RESULT = RADIX(X)}
8817 @item @emph{Arguments}:
8818 @multitable @columnfractions .15 .70
8819 @item @var{X} @tab Shall be of type @code{INTEGER} or @code{REAL}
8822 @item @emph{Return value}:
8823 The return value is a scalar of type @code{INTEGER} and of the default
8826 @item @emph{Example}:
8829 print *, "The radix for the default integer kind is", radix(0)
8830 print *, "The radix for the default real kind is", radix(0.0)
8831 end program test_radix
8839 @section @code{RAN} --- Real pseudo-random number
8841 @cindex random number generation
8844 @item @emph{Description}:
8845 For compatibility with HP FORTRAN 77/iX, the @code{RAN} intrinsic is
8846 provided as an alias for @code{RAND}. See @ref{RAND} for complete
8849 @item @emph{Standard}:
8855 @item @emph{See also}:
8856 @ref{RAND}, @ref{RANDOM_NUMBER}
8862 @section @code{RAND} --- Real pseudo-random number
8864 @cindex random number generation
8867 @item @emph{Description}:
8868 @code{RAND(FLAG)} returns a pseudo-random number from a uniform
8869 distribution between 0 and 1. If @var{FLAG} is 0, the next number
8870 in the current sequence is returned; if @var{FLAG} is 1, the generator
8871 is restarted by @code{CALL SRAND(0)}; if @var{FLAG} has any other value,
8872 it is used as a new seed with @code{SRAND}.
8874 This intrinsic routine is provided for backwards compatibility with
8875 GNU Fortran 77. It implements a simple modulo generator as provided
8876 by @command{g77}. For new code, one should consider the use of
8877 @ref{RANDOM_NUMBER} as it implements a superior algorithm.
8879 @item @emph{Standard}:
8885 @item @emph{Syntax}:
8886 @code{RESULT = RAND(I)}
8888 @item @emph{Arguments}:
8889 @multitable @columnfractions .15 .70
8890 @item @var{I} @tab Shall be a scalar @code{INTEGER} of kind 4.
8893 @item @emph{Return value}:
8894 The return value is of @code{REAL} type and the default kind.
8896 @item @emph{Example}:
8899 integer,parameter :: seed = 86456
8902 print *, rand(), rand(), rand(), rand()
8903 print *, rand(seed), rand(), rand(), rand()
8904 end program test_rand
8907 @item @emph{See also}:
8908 @ref{SRAND}, @ref{RANDOM_NUMBER}
8915 @section @code{RANDOM_NUMBER} --- Pseudo-random number
8916 @fnindex RANDOM_NUMBER
8917 @cindex random number generation
8920 @item @emph{Description}:
8921 Returns a single pseudorandom number or an array of pseudorandom numbers
8922 from the uniform distribution over the range @math{ 0 \leq x < 1}.
8924 The runtime-library implements George Marsaglia's KISS (Keep It Simple
8925 Stupid) random number generator (RNG). This RNG combines:
8927 @item The congruential generator @math{x(n) = 69069 \cdot x(n-1) + 1327217885}
8928 with a period of @math{2^{32}},
8929 @item A 3-shift shift-register generator with a period of @math{2^{32} - 1},
8930 @item Two 16-bit multiply-with-carry generators with a period of
8931 @math{597273182964842497 > 2^{59}}.
8933 The overall period exceeds @math{2^{123}}.
8935 Please note, this RNG is thread safe if used within OpenMP directives,
8936 i.e., its state will be consistent while called from multiple threads.
8937 However, the KISS generator does not create random numbers in parallel
8938 from multiple sources, but in sequence from a single source. If an
8939 OpenMP-enabled application heavily relies on random numbers, one should
8940 consider employing a dedicated parallel random number generator instead.
8942 @item @emph{Standard}:
8943 Fortran 95 and later
8948 @item @emph{Syntax}:
8949 @code{RANDOM_NUMBER(HARVEST)}
8951 @item @emph{Arguments}:
8952 @multitable @columnfractions .15 .70
8953 @item @var{HARVEST} @tab Shall be a scalar or an array of type @code{REAL}.
8956 @item @emph{Example}:
8958 program test_random_number
8960 CALL init_random_seed() ! see example of RANDOM_SEED
8961 CALL RANDOM_NUMBER(r)
8965 @item @emph{See also}:
8972 @section @code{RANDOM_SEED} --- Initialize a pseudo-random number sequence
8973 @fnindex RANDOM_SEED
8974 @cindex random number generation, seeding
8975 @cindex seeding a random number generator
8978 @item @emph{Description}:
8979 Restarts or queries the state of the pseudorandom number generator used by
8980 @code{RANDOM_NUMBER}.
8982 If @code{RANDOM_SEED} is called without arguments, it is initialized to
8983 a default state. The example below shows how to initialize the random
8984 seed based on the system's time.
8986 @item @emph{Standard}:
8987 Fortran 95 and later
8992 @item @emph{Syntax}:
8993 @code{CALL RANDOM_SEED([SIZE, PUT, GET])}
8995 @item @emph{Arguments}:
8996 @multitable @columnfractions .15 .70
8997 @item @var{SIZE} @tab (Optional) Shall be a scalar and of type default
8998 @code{INTEGER}, with @code{INTENT(OUT)}. It specifies the minimum size
8999 of the arrays used with the @var{PUT} and @var{GET} arguments.
9000 @item @var{PUT} @tab (Optional) Shall be an array of type default
9001 @code{INTEGER} and rank one. It is @code{INTENT(IN)} and the size of
9002 the array must be larger than or equal to the number returned by the
9003 @var{SIZE} argument.
9004 @item @var{GET} @tab (Optional) Shall be an array of type default
9005 @code{INTEGER} and rank one. It is @code{INTENT(OUT)} and the size
9006 of the array must be larger than or equal to the number returned by
9007 the @var{SIZE} argument.
9010 @item @emph{Example}:
9012 SUBROUTINE init_random_seed()
9013 INTEGER :: i, n, clock
9014 INTEGER, DIMENSION(:), ALLOCATABLE :: seed
9016 CALL RANDOM_SEED(size = n)
9019 CALL SYSTEM_CLOCK(COUNT=clock)
9021 seed = clock + 37 * (/ (i - 1, i = 1, n) /)
9022 CALL RANDOM_SEED(PUT = seed)
9028 @item @emph{See also}:
9035 @section @code{RANGE} --- Decimal exponent range
9037 @cindex model representation, range
9040 @item @emph{Description}:
9041 @code{RANGE(X)} returns the decimal exponent range in the model of the
9044 @item @emph{Standard}:
9045 Fortran 95 and later
9050 @item @emph{Syntax}:
9051 @code{RESULT = RANGE(X)}
9053 @item @emph{Arguments}:
9054 @multitable @columnfractions .15 .70
9055 @item @var{X} @tab Shall be of type @code{INTEGER}, @code{REAL}
9059 @item @emph{Return value}:
9060 The return value is of type @code{INTEGER} and of the default integer
9063 @item @emph{Example}:
9064 See @code{PRECISION} for an example.
9070 @section @code{REAL} --- Convert to real type
9076 @cindex conversion, to real
9077 @cindex complex numbers, real part
9080 @item @emph{Description}:
9081 @code{REAL(A [, KIND])} converts its argument @var{A} to a real type. The
9082 @code{REALPART} function is provided for compatibility with @command{g77},
9083 and its use is strongly discouraged.
9085 @item @emph{Standard}:
9086 Fortran 77 and later
9091 @item @emph{Syntax}:
9092 @multitable @columnfractions .80
9093 @item @code{RESULT = REAL(A [, KIND])}
9094 @item @code{RESULT = REALPART(Z)}
9097 @item @emph{Arguments}:
9098 @multitable @columnfractions .15 .70
9099 @item @var{A} @tab Shall be @code{INTEGER}, @code{REAL}, or
9101 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
9102 expression indicating the kind parameter of the result.
9105 @item @emph{Return value}:
9106 These functions return a @code{REAL} variable or array under
9107 the following rules:
9111 @code{REAL(A)} is converted to a default real type if @var{A} is an
9112 integer or real variable.
9114 @code{REAL(A)} is converted to a real type with the kind type parameter
9115 of @var{A} if @var{A} is a complex variable.
9117 @code{REAL(A, KIND)} is converted to a real type with kind type
9118 parameter @var{KIND} if @var{A} is a complex, integer, or real
9122 @item @emph{Example}:
9125 complex :: x = (1.0, 2.0)
9126 print *, real(x), real(x,8), realpart(x)
9127 end program test_real
9130 @item @emph{Specific names}:
9131 @multitable @columnfractions .20 .20 .20 .25
9132 @item Name @tab Argument @tab Return type @tab Standard
9133 @item @code{FLOAT(A)} @tab @code{INTEGER(4)} @tab @code{REAL(4)} @tab Fortran 77 and later
9134 @item @code{DFLOAT(A)} @tab @code{INTEGER(4)} @tab @code{REAL(8)} @tab GNU extension
9135 @item @code{SNGL(A)} @tab @code{INTEGER(8)} @tab @code{REAL(4)} @tab Fortran 77 and later
9139 @item @emph{See also}:
9147 @section @code{RENAME} --- Rename a file
9149 @cindex file system, rename file
9152 @item @emph{Description}:
9153 Renames a file from file @var{PATH1} to @var{PATH2}. A null
9154 character (@code{CHAR(0)}) can be used to mark the end of the names in
9155 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
9156 names are ignored. If the @var{STATUS} argument is supplied, it
9157 contains 0 on success or a nonzero error code upon return; see
9160 This intrinsic is provided in both subroutine and function forms;
9161 however, only one form can be used in any given program unit.
9163 @item @emph{Standard}:
9167 Subroutine, function
9169 @item @emph{Syntax}:
9170 @multitable @columnfractions .80
9171 @item @code{CALL RENAME(PATH1, PATH2 [, STATUS])}
9172 @item @code{STATUS = RENAME(PATH1, PATH2)}
9175 @item @emph{Arguments}:
9176 @multitable @columnfractions .15 .70
9177 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
9178 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
9179 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
9182 @item @emph{See also}:
9190 @section @code{REPEAT} --- Repeated string concatenation
9192 @cindex string, repeat
9193 @cindex string, concatenate
9196 @item @emph{Description}:
9197 Concatenates @var{NCOPIES} copies of a string.
9199 @item @emph{Standard}:
9200 Fortran 95 and later
9203 Transformational function
9205 @item @emph{Syntax}:
9206 @code{RESULT = REPEAT(STRING, NCOPIES)}
9208 @item @emph{Arguments}:
9209 @multitable @columnfractions .15 .70
9210 @item @var{STRING} @tab Shall be scalar and of type @code{CHARACTER}.
9211 @item @var{NCOPIES} @tab Shall be scalar and of type @code{INTEGER}.
9214 @item @emph{Return value}:
9215 A new scalar of type @code{CHARACTER} built up from @var{NCOPIES} copies
9218 @item @emph{Example}:
9221 write(*,*) repeat("x", 5) ! "xxxxx"
9229 @section @code{RESHAPE} --- Function to reshape an array
9231 @cindex array, change dimensions
9232 @cindex array, transmogrify
9235 @item @emph{Description}:
9236 Reshapes @var{SOURCE} to correspond to @var{SHAPE}. If necessary,
9237 the new array may be padded with elements from @var{PAD} or permuted
9238 as defined by @var{ORDER}.
9240 @item @emph{Standard}:
9241 Fortran 95 and later
9244 Transformational function
9246 @item @emph{Syntax}:
9247 @code{RESULT = RESHAPE(SOURCE, SHAPE[, PAD, ORDER])}
9249 @item @emph{Arguments}:
9250 @multitable @columnfractions .15 .70
9251 @item @var{SOURCE} @tab Shall be an array of any type.
9252 @item @var{SHAPE} @tab Shall be of type @code{INTEGER} and an
9253 array of rank one. Its values must be positive or zero.
9254 @item @var{PAD} @tab (Optional) shall be an array of the same
9255 type as @var{SOURCE}.
9256 @item @var{ORDER} @tab (Optional) shall be of type @code{INTEGER}
9257 and an array of the same shape as @var{SHAPE}. Its values shall
9258 be a permutation of the numbers from 1 to n, where n is the size of
9259 @var{SHAPE}. If @var{ORDER} is absent, the natural ordering shall
9263 @item @emph{Return value}:
9264 The result is an array of shape @var{SHAPE} with the same type as
9267 @item @emph{Example}:
9269 PROGRAM test_reshape
9270 INTEGER, DIMENSION(4) :: x
9271 WRITE(*,*) SHAPE(x) ! prints "4"
9272 WRITE(*,*) SHAPE(RESHAPE(x, (/2, 2/))) ! prints "2 2"
9276 @item @emph{See also}:
9283 @section @code{RRSPACING} --- Reciprocal of the relative spacing
9285 @cindex real number, relative spacing
9286 @cindex floating point, relative spacing
9290 @item @emph{Description}:
9291 @code{RRSPACING(X)} returns the reciprocal of the relative spacing of
9292 model numbers near @var{X}.
9294 @item @emph{Standard}:
9295 Fortran 95 and later
9300 @item @emph{Syntax}:
9301 @code{RESULT = RRSPACING(X)}
9303 @item @emph{Arguments}:
9304 @multitable @columnfractions .15 .70
9305 @item @var{X} @tab Shall be of type @code{REAL}.
9308 @item @emph{Return value}:
9309 The return value is of the same type and kind as @var{X}.
9310 The value returned is equal to
9311 @code{ABS(FRACTION(X)) * FLOAT(RADIX(X))**DIGITS(X)}.
9313 @item @emph{See also}:
9320 @section @code{RSHIFT} --- Right shift bits
9322 @cindex bits, shift right
9325 @item @emph{Description}:
9326 @code{RSHIFT} returns a value corresponding to @var{I} with all of the
9327 bits shifted right by @var{SHIFT} places. If the absolute value of
9328 @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the value is undefined.
9329 Bits shifted out from the left end are lost; zeros are shifted in from
9332 This function has been superseded by the @code{ISHFT} intrinsic, which
9333 is standard in Fortran 95 and later.
9335 @item @emph{Standard}:
9341 @item @emph{Syntax}:
9342 @code{RESULT = RSHIFT(I, SHIFT)}
9344 @item @emph{Arguments}:
9345 @multitable @columnfractions .15 .70
9346 @item @var{I} @tab The type shall be @code{INTEGER}.
9347 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
9350 @item @emph{Return value}:
9351 The return value is of type @code{INTEGER} and of the same kind as
9354 @item @emph{See also}:
9355 @ref{ISHFT}, @ref{ISHFTC}, @ref{LSHIFT}
9362 @section @code{SCALE} --- Scale a real value
9364 @cindex real number, scale
9365 @cindex floating point, scale
9368 @item @emph{Description}:
9369 @code{SCALE(X,I)} returns @code{X * RADIX(X)**I}.
9371 @item @emph{Standard}:
9372 Fortran 95 and later
9377 @item @emph{Syntax}:
9378 @code{RESULT = SCALE(X, I)}
9380 @item @emph{Arguments}:
9381 @multitable @columnfractions .15 .70
9382 @item @var{X} @tab The type of the argument shall be a @code{REAL}.
9383 @item @var{I} @tab The type of the argument shall be a @code{INTEGER}.
9386 @item @emph{Return value}:
9387 The return value is of the same type and kind as @var{X}.
9388 Its value is @code{X * RADIX(X)**I}.
9390 @item @emph{Example}:
9393 real :: x = 178.1387e-4
9395 print *, scale(x,i), x*radix(x)**i
9396 end program test_scale
9404 @section @code{SCAN} --- Scan a string for the presence of a set of characters
9406 @cindex string, find subset
9409 @item @emph{Description}:
9410 Scans a @var{STRING} for any of the characters in a @var{SET}
9413 If @var{BACK} is either absent or equals @code{FALSE}, this function
9414 returns the position of the leftmost character of @var{STRING} that is
9415 in @var{SET}. If @var{BACK} equals @code{TRUE}, the rightmost position
9416 is returned. If no character of @var{SET} is found in @var{STRING}, the
9419 @item @emph{Standard}:
9420 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
9425 @item @emph{Syntax}:
9426 @code{RESULT = SCAN(STRING, SET[, BACK [, KIND]])}
9428 @item @emph{Arguments}:
9429 @multitable @columnfractions .15 .70
9430 @item @var{STRING} @tab Shall be of type @code{CHARACTER}.
9431 @item @var{SET} @tab Shall be of type @code{CHARACTER}.
9432 @item @var{BACK} @tab (Optional) shall be of type @code{LOGICAL}.
9433 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
9434 expression indicating the kind parameter of the result.
9437 @item @emph{Return value}:
9438 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
9439 @var{KIND} is absent, the return value is of default integer kind.
9441 @item @emph{Example}:
9444 WRITE(*,*) SCAN("FORTRAN", "AO") ! 2, found 'O'
9445 WRITE(*,*) SCAN("FORTRAN", "AO", .TRUE.) ! 6, found 'A'
9446 WRITE(*,*) SCAN("FORTRAN", "C++") ! 0, found none
9450 @item @emph{See also}:
9451 @ref{INDEX intrinsic}, @ref{VERIFY}
9457 @section @code{SECNDS} --- Time function
9459 @cindex time, elapsed
9460 @cindex elapsed time
9463 @item @emph{Description}:
9464 @code{SECNDS(X)} gets the time in seconds from the real-time system clock.
9465 @var{X} is a reference time, also in seconds. If this is zero, the time in
9466 seconds from midnight is returned. This function is non-standard and its
9469 @item @emph{Standard}:
9475 @item @emph{Syntax}:
9476 @code{RESULT = SECNDS (X)}
9478 @item @emph{Arguments}:
9479 @multitable @columnfractions .15 .70
9480 @item @var{T} @tab Shall be of type @code{REAL(4)}.
9481 @item @var{X} @tab Shall be of type @code{REAL(4)}.
9484 @item @emph{Return value}:
9487 @item @emph{Example}:
9492 print *, secnds (0.0) ! seconds since midnight
9493 t1 = secnds (0.0) ! reference time
9494 do i = 1, 10000000 ! do something
9496 t2 = secnds (t1) ! elapsed time
9497 print *, "Something took ", t2, " seconds."
9498 end program test_secnds
9505 @section @code{SECOND} --- CPU time function
9507 @cindex time, elapsed
9508 @cindex elapsed time
9511 @item @emph{Description}:
9512 Returns a @code{REAL(4)} value representing the elapsed CPU time in
9513 seconds. This provides the same functionality as the standard
9514 @code{CPU_TIME} intrinsic, and is only included for backwards
9517 This intrinsic is provided in both subroutine and function forms;
9518 however, only one form can be used in any given program unit.
9520 @item @emph{Standard}:
9524 Subroutine, function
9526 @item @emph{Syntax}:
9527 @multitable @columnfractions .80
9528 @item @code{CALL SECOND(TIME)}
9529 @item @code{TIME = SECOND()}
9532 @item @emph{Arguments}:
9533 @multitable @columnfractions .15 .70
9534 @item @var{TIME} @tab Shall be of type @code{REAL(4)}.
9537 @item @emph{Return value}:
9538 In either syntax, @var{TIME} is set to the process's current runtime in
9541 @item @emph{See also}:
9548 @node SELECTED_CHAR_KIND
9549 @section @code{SELECTED_CHAR_KIND} --- Choose character kind
9550 @fnindex SELECTED_CHAR_KIND
9551 @cindex character kind
9552 @cindex kind, character
9555 @item @emph{Description}:
9557 @code{SELECTED_CHAR_KIND(NAME)} returns the kind value for the character
9558 set named @var{NAME}, if a character set with such a name is supported,
9559 or @math{-1} otherwise. Currently, supported character sets include
9560 ``ASCII'' and ``DEFAULT'', which are equivalent.
9562 @item @emph{Standard}:
9563 Fortran 2003 and later
9566 Transformational function
9568 @item @emph{Syntax}:
9569 @code{RESULT = SELECTED_CHAR_KIND(NAME)}
9571 @item @emph{Arguments}:
9572 @multitable @columnfractions .15 .70
9573 @item @var{NAME} @tab Shall be a scalar and of the default character type.
9576 @item @emph{Example}:
9579 integer,parameter :: ascii = selected_char_kind("ascii")
9580 character(kind=ascii, len=26) :: s
9582 s = ascii_"abcdefghijklmnopqrstuvwxyz"
9584 end program ascii_kind
9590 @node SELECTED_INT_KIND
9591 @section @code{SELECTED_INT_KIND} --- Choose integer kind
9592 @fnindex SELECTED_INT_KIND
9593 @cindex integer kind
9594 @cindex kind, integer
9597 @item @emph{Description}:
9598 @code{SELECTED_INT_KIND(R)} return the kind value of the smallest integer
9599 type that can represent all values ranging from @math{-10^R} (exclusive)
9600 to @math{10^R} (exclusive). If there is no integer kind that accommodates
9601 this range, @code{SELECTED_INT_KIND} returns @math{-1}.
9603 @item @emph{Standard}:
9604 Fortran 95 and later
9607 Transformational function
9609 @item @emph{Syntax}:
9610 @code{RESULT = SELECTED_INT_KIND(R)}
9612 @item @emph{Arguments}:
9613 @multitable @columnfractions .15 .70
9614 @item @var{R} @tab Shall be a scalar and of type @code{INTEGER}.
9617 @item @emph{Example}:
9619 program large_integers
9620 integer,parameter :: k5 = selected_int_kind(5)
9621 integer,parameter :: k15 = selected_int_kind(15)
9622 integer(kind=k5) :: i5
9623 integer(kind=k15) :: i15
9625 print *, huge(i5), huge(i15)
9627 ! The following inequalities are always true
9628 print *, huge(i5) >= 10_k5**5-1
9629 print *, huge(i15) >= 10_k15**15-1
9630 end program large_integers
9636 @node SELECTED_REAL_KIND
9637 @section @code{SELECTED_REAL_KIND} --- Choose real kind
9638 @fnindex SELECTED_REAL_KIND
9643 @item @emph{Description}:
9644 @code{SELECTED_REAL_KIND(P,R)} returns the kind value of a real data type
9645 with decimal precision of at least @code{P} digits and exponent
9646 range greater at least @code{R}.
9648 @item @emph{Standard}:
9649 Fortran 95 and later
9652 Transformational function
9654 @item @emph{Syntax}:
9655 @code{RESULT = SELECTED_REAL_KIND([P, R])}
9657 @item @emph{Arguments}:
9658 @multitable @columnfractions .15 .70
9659 @item @var{P} @tab (Optional) shall be a scalar and of type @code{INTEGER}.
9660 @item @var{R} @tab (Optional) shall be a scalar and of type @code{INTEGER}.
9662 At least one argument shall be present.
9664 @item @emph{Return value}:
9666 @code{SELECTED_REAL_KIND} returns the value of the kind type parameter of
9667 a real data type with decimal precision of at least @code{P} digits and a
9668 decimal exponent range of at least @code{R}. If more than one real data
9669 type meet the criteria, the kind of the data type with the smallest
9670 decimal precision is returned. If no real data type matches the criteria,
9673 @item -1 if the processor does not support a real data type with a
9674 precision greater than or equal to @code{P}
9675 @item -2 if the processor does not support a real type with an exponent
9676 range greater than or equal to @code{R}
9677 @item -3 if neither is supported.
9680 @item @emph{Example}:
9683 integer,parameter :: p6 = selected_real_kind(6)
9684 integer,parameter :: p10r100 = selected_real_kind(10,100)
9685 integer,parameter :: r400 = selected_real_kind(r=400)
9687 real(kind=p10r100) :: y
9688 real(kind=r400) :: z
9690 print *, precision(x), range(x)
9691 print *, precision(y), range(y)
9692 print *, precision(z), range(z)
9693 end program real_kinds
9700 @section @code{SET_EXPONENT} --- Set the exponent of the model
9701 @fnindex SET_EXPONENT
9702 @cindex real number, set exponent
9703 @cindex floating point, set exponent
9706 @item @emph{Description}:
9707 @code{SET_EXPONENT(X, I)} returns the real number whose fractional part
9708 is that that of @var{X} and whose exponent part is @var{I}.
9710 @item @emph{Standard}:
9711 Fortran 95 and later
9716 @item @emph{Syntax}:
9717 @code{RESULT = SET_EXPONENT(X, I)}
9719 @item @emph{Arguments}:
9720 @multitable @columnfractions .15 .70
9721 @item @var{X} @tab Shall be of type @code{REAL}.
9722 @item @var{I} @tab Shall be of type @code{INTEGER}.
9725 @item @emph{Return value}:
9726 The return value is of the same type and kind as @var{X}.
9727 The real number whose fractional part
9728 is that that of @var{X} and whose exponent part if @var{I} is returned;
9729 it is @code{FRACTION(X) * RADIX(X)**I}.
9731 @item @emph{Example}:
9734 REAL :: x = 178.1387e-4
9736 PRINT *, SET_EXPONENT(x, i), FRACTION(x) * RADIX(x)**i
9745 @section @code{SHAPE} --- Determine the shape of an array
9747 @cindex array, shape
9750 @item @emph{Description}:
9751 Determines the shape of an array.
9753 @item @emph{Standard}:
9754 Fortran 95 and later
9759 @item @emph{Syntax}:
9760 @code{RESULT = SHAPE(SOURCE)}
9762 @item @emph{Arguments}:
9763 @multitable @columnfractions .15 .70
9764 @item @var{SOURCE} @tab Shall be an array or scalar of any type.
9765 If @var{SOURCE} is a pointer it must be associated and allocatable
9766 arrays must be allocated.
9769 @item @emph{Return value}:
9770 An @code{INTEGER} array of rank one with as many elements as @var{SOURCE}
9771 has dimensions. The elements of the resulting array correspond to the extend
9772 of @var{SOURCE} along the respective dimensions. If @var{SOURCE} is a scalar,
9773 the result is the rank one array of size zero.
9775 @item @emph{Example}:
9778 INTEGER, DIMENSION(-1:1, -1:2) :: A
9779 WRITE(*,*) SHAPE(A) ! (/ 3, 4 /)
9780 WRITE(*,*) SIZE(SHAPE(42)) ! (/ /)
9784 @item @emph{See also}:
9785 @ref{RESHAPE}, @ref{SIZE}
9791 @section @code{SIGN} --- Sign copying function
9795 @cindex sign copying
9798 @item @emph{Description}:
9799 @code{SIGN(A,B)} returns the value of @var{A} with the sign of @var{B}.
9801 @item @emph{Standard}:
9802 Fortran 77 and later
9807 @item @emph{Syntax}:
9808 @code{RESULT = SIGN(A, B)}
9810 @item @emph{Arguments}:
9811 @multitable @columnfractions .15 .70
9812 @item @var{A} @tab Shall be of type @code{INTEGER} or @code{REAL}
9813 @item @var{B} @tab Shall be of the same type and kind as @var{A}
9816 @item @emph{Return value}:
9817 The kind of the return value is that of @var{A} and @var{B}.
9818 If @math{B\ge 0} then the result is @code{ABS(A)}, else
9819 it is @code{-ABS(A)}.
9821 @item @emph{Example}:
9824 print *, sign(-12,1)
9825 print *, sign(-12,0)
9826 print *, sign(-12,-1)
9828 print *, sign(-12.,1.)
9829 print *, sign(-12.,0.)
9830 print *, sign(-12.,-1.)
9831 end program test_sign
9834 @item @emph{Specific names}:
9835 @multitable @columnfractions .20 .20 .20 .25
9836 @item Name @tab Arguments @tab Return type @tab Standard
9837 @item @code{SIGN(A,B)} @tab @code{REAL(4) A, B} @tab @code{REAL(4)} @tab f77, gnu
9838 @item @code{ISIGN(A,B)} @tab @code{INTEGER(4) A, B} @tab @code{INTEGER(4)} @tab f77, gnu
9839 @item @code{DSIGN(A,B)} @tab @code{REAL(8) A, B} @tab @code{REAL(8)} @tab f77, gnu
9846 @section @code{SIGNAL} --- Signal handling subroutine (or function)
9848 @cindex system, signal handling
9851 @item @emph{Description}:
9852 @code{SIGNAL(NUMBER, HANDLER [, STATUS])} causes external subroutine
9853 @var{HANDLER} to be executed with a single integer argument when signal
9854 @var{NUMBER} occurs. If @var{HANDLER} is an integer, it can be used to
9855 turn off handling of signal @var{NUMBER} or revert to its default
9856 action. See @code{signal(2)}.
9858 If @code{SIGNAL} is called as a subroutine and the @var{STATUS} argument
9859 is supplied, it is set to the value returned by @code{signal(2)}.
9861 @item @emph{Standard}:
9865 Subroutine, function
9867 @item @emph{Syntax}:
9868 @multitable @columnfractions .80
9869 @item @code{CALL SIGNAL(NUMBER, HANDLER [, STATUS])}
9870 @item @code{STATUS = SIGNAL(NUMBER, HANDLER)}
9873 @item @emph{Arguments}:
9874 @multitable @columnfractions .15 .70
9875 @item @var{NUMBER} @tab Shall be a scalar integer, with @code{INTENT(IN)}
9876 @item @var{HANDLER}@tab Signal handler (@code{INTEGER FUNCTION} or
9877 @code{SUBROUTINE}) or dummy/global @code{INTEGER} scalar.
9878 @code{INTEGER}. It is @code{INTENT(IN)}.
9879 @item @var{STATUS} @tab (Optional) @var{STATUS} shall be a scalar
9880 integer. It has @code{INTENT(OUT)}.
9882 @c TODO: What should the interface of the handler be? Does it take arguments?
9884 @item @emph{Return value}:
9885 The @code{SIGNAL} function returns the value returned by @code{signal(2)}.
9887 @item @emph{Example}:
9891 external handler_print
9893 call signal (12, handler_print)
9897 end program test_signal
9904 @section @code{SIN} --- Sine function
9910 @cindex trigonometric function, sine
9914 @item @emph{Description}:
9915 @code{SIN(X)} computes the sine of @var{X}.
9917 @item @emph{Standard}:
9918 Fortran 77 and later
9923 @item @emph{Syntax}:
9924 @code{RESULT = SIN(X)}
9926 @item @emph{Arguments}:
9927 @multitable @columnfractions .15 .70
9928 @item @var{X} @tab The type shall be @code{REAL} or
9932 @item @emph{Return value}:
9933 The return value has same type and kind as @var{X}.
9935 @item @emph{Example}:
9940 end program test_sin
9943 @item @emph{Specific names}:
9944 @multitable @columnfractions .20 .20 .20 .25
9945 @item Name @tab Argument @tab Return type @tab Standard
9946 @item @code{SIN(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab f77, gnu
9947 @item @code{DSIN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab f95, gnu
9948 @item @code{CSIN(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab f95, gnu
9949 @item @code{ZSIN(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
9950 @item @code{CDSIN(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
9953 @item @emph{See also}:
9960 @section @code{SINH} --- Hyperbolic sine function
9963 @cindex hyperbolic sine
9964 @cindex hyperbolic function, sine
9965 @cindex sine, hyperbolic
9968 @item @emph{Description}:
9969 @code{SINH(X)} computes the hyperbolic sine of @var{X}.
9971 @item @emph{Standard}:
9972 Fortran 95 and later, for a complex argument Fortran 2008 or later
9977 @item @emph{Syntax}:
9978 @code{RESULT = SINH(X)}
9980 @item @emph{Arguments}:
9981 @multitable @columnfractions .15 .70
9982 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
9985 @item @emph{Return value}:
9986 The return value has same type and kind as @var{X}.
9988 @item @emph{Example}:
9991 real(8) :: x = - 1.0_8
9993 end program test_sinh
9996 @item @emph{Specific names}:
9997 @multitable @columnfractions .20 .20 .20 .25
9998 @item Name @tab Argument @tab Return type @tab Standard
9999 @item @code{SINH(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 95 and later
10000 @item @code{DSINH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 95 and later
10003 @item @emph{See also}:
10010 @section @code{SIZE} --- Determine the size of an array
10012 @cindex array, size
10013 @cindex array, number of elements
10014 @cindex array, count elements
10017 @item @emph{Description}:
10018 Determine the extent of @var{ARRAY} along a specified dimension @var{DIM},
10019 or the total number of elements in @var{ARRAY} if @var{DIM} is absent.
10021 @item @emph{Standard}:
10022 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
10024 @item @emph{Class}:
10027 @item @emph{Syntax}:
10028 @code{RESULT = SIZE(ARRAY[, DIM [, KIND]])}
10030 @item @emph{Arguments}:
10031 @multitable @columnfractions .15 .70
10032 @item @var{ARRAY} @tab Shall be an array of any type. If @var{ARRAY} is
10033 a pointer it must be associated and allocatable arrays must be allocated.
10034 @item @var{DIM} @tab (Optional) shall be a scalar of type @code{INTEGER}
10035 and its value shall be in the range from 1 to n, where n equals the rank
10037 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
10038 expression indicating the kind parameter of the result.
10041 @item @emph{Return value}:
10042 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
10043 @var{KIND} is absent, the return value is of default integer kind.
10045 @item @emph{Example}:
10048 WRITE(*,*) SIZE((/ 1, 2 /)) ! 2
10052 @item @emph{See also}:
10053 @ref{SHAPE}, @ref{RESHAPE}
10058 @section @code{SIZEOF} --- Size in bytes of an expression
10060 @cindex expression size
10061 @cindex size of an expression
10064 @item @emph{Description}:
10065 @code{SIZEOF(X)} calculates the number of bytes of storage the
10066 expression @code{X} occupies.
10068 @item @emph{Standard}:
10071 @item @emph{Class}:
10074 @item @emph{Syntax}:
10075 @code{N = SIZEOF(X)}
10077 @item @emph{Arguments}:
10078 @multitable @columnfractions .15 .70
10079 @item @var{X} @tab The argument shall be of any type, rank or shape.
10082 @item @emph{Return value}:
10083 The return value is of type integer and of the system-dependent kind
10084 @var{C_SIZE_T} (from the @var{ISO_C_BINDING} module). Its value is the
10085 number of bytes occupied by the argument. If the argument has the
10086 @code{POINTER} attribute, the number of bytes of the storage area pointed
10087 to is returned. If the argument is of a derived type with @code{POINTER}
10088 or @code{ALLOCATABLE} components, the return value doesn't account for
10089 the sizes of the data pointed to by these components.
10091 @item @emph{Example}:
10095 print *, (sizeof(s)/sizeof(r) == 5)
10098 The example will print @code{.TRUE.} unless you are using a platform
10099 where default @code{REAL} variables are unusually padded.
10101 @item @emph{See also}:
10107 @section @code{SLEEP} --- Sleep for the specified number of seconds
10109 @cindex delayed execution
10112 @item @emph{Description}:
10113 Calling this subroutine causes the process to pause for @var{SECONDS} seconds.
10115 @item @emph{Standard}:
10118 @item @emph{Class}:
10121 @item @emph{Syntax}:
10122 @code{CALL SLEEP(SECONDS)}
10124 @item @emph{Arguments}:
10125 @multitable @columnfractions .15 .70
10126 @item @var{SECONDS} @tab The type shall be of default @code{INTEGER}.
10129 @item @emph{Example}:
10140 @section @code{SPACING} --- Smallest distance between two numbers of a given type
10142 @cindex real number, relative spacing
10143 @cindex floating point, relative spacing
10146 @item @emph{Description}:
10147 Determines the distance between the argument @var{X} and the nearest
10148 adjacent number of the same type.
10150 @item @emph{Standard}:
10151 Fortran 95 and later
10153 @item @emph{Class}:
10156 @item @emph{Syntax}:
10157 @code{RESULT = SPACING(X)}
10159 @item @emph{Arguments}:
10160 @multitable @columnfractions .15 .70
10161 @item @var{X} @tab Shall be of type @code{REAL}.
10164 @item @emph{Return value}:
10165 The result is of the same type as the input argument @var{X}.
10167 @item @emph{Example}:
10169 PROGRAM test_spacing
10170 INTEGER, PARAMETER :: SGL = SELECTED_REAL_KIND(p=6, r=37)
10171 INTEGER, PARAMETER :: DBL = SELECTED_REAL_KIND(p=13, r=200)
10173 WRITE(*,*) spacing(1.0_SGL) ! "1.1920929E-07" on i686
10174 WRITE(*,*) spacing(1.0_DBL) ! "2.220446049250313E-016" on i686
10178 @item @emph{See also}:
10185 @section @code{SPREAD} --- Add a dimension to an array
10187 @cindex array, increase dimension
10188 @cindex array, duplicate elements
10189 @cindex array, duplicate dimensions
10192 @item @emph{Description}:
10193 Replicates a @var{SOURCE} array @var{NCOPIES} times along a specified
10194 dimension @var{DIM}.
10196 @item @emph{Standard}:
10197 Fortran 95 and later
10199 @item @emph{Class}:
10200 Transformational function
10202 @item @emph{Syntax}:
10203 @code{RESULT = SPREAD(SOURCE, DIM, NCOPIES)}
10205 @item @emph{Arguments}:
10206 @multitable @columnfractions .15 .70
10207 @item @var{SOURCE} @tab Shall be a scalar or an array of any type and
10208 a rank less than seven.
10209 @item @var{DIM} @tab Shall be a scalar of type @code{INTEGER} with a
10210 value in the range from 1 to n+1, where n equals the rank of @var{SOURCE}.
10211 @item @var{NCOPIES} @tab Shall be a scalar of type @code{INTEGER}.
10214 @item @emph{Return value}:
10215 The result is an array of the same type as @var{SOURCE} and has rank n+1
10216 where n equals the rank of @var{SOURCE}.
10218 @item @emph{Example}:
10220 PROGRAM test_spread
10221 INTEGER :: a = 1, b(2) = (/ 1, 2 /)
10222 WRITE(*,*) SPREAD(A, 1, 2) ! "1 1"
10223 WRITE(*,*) SPREAD(B, 1, 2) ! "1 1 2 2"
10227 @item @emph{See also}:
10234 @section @code{SQRT} --- Square-root function
10241 @cindex square-root
10244 @item @emph{Description}:
10245 @code{SQRT(X)} computes the square root of @var{X}.
10247 @item @emph{Standard}:
10248 Fortran 77 and later
10250 @item @emph{Class}:
10253 @item @emph{Syntax}:
10254 @code{RESULT = SQRT(X)}
10256 @item @emph{Arguments}:
10257 @multitable @columnfractions .15 .70
10258 @item @var{X} @tab The type shall be @code{REAL} or
10262 @item @emph{Return value}:
10263 The return value is of type @code{REAL} or @code{COMPLEX}.
10264 The kind type parameter is the same as @var{X}.
10266 @item @emph{Example}:
10269 real(8) :: x = 2.0_8
10270 complex :: z = (1.0, 2.0)
10273 end program test_sqrt
10276 @item @emph{Specific names}:
10277 @multitable @columnfractions .20 .20 .20 .25
10278 @item Name @tab Argument @tab Return type @tab Standard
10279 @item @code{SQRT(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 95 and later
10280 @item @code{DSQRT(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 95 and later
10281 @item @code{CSQRT(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab Fortran 95 and later
10282 @item @code{ZSQRT(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
10283 @item @code{CDSQRT(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
10290 @section @code{SRAND} --- Reinitialize the random number generator
10292 @cindex random number generation, seeding
10293 @cindex seeding a random number generator
10296 @item @emph{Description}:
10297 @code{SRAND} reinitializes the pseudo-random number generator
10298 called by @code{RAND} and @code{IRAND}. The new seed used by the
10299 generator is specified by the required argument @var{SEED}.
10301 @item @emph{Standard}:
10304 @item @emph{Class}:
10307 @item @emph{Syntax}:
10308 @code{CALL SRAND(SEED)}
10310 @item @emph{Arguments}:
10311 @multitable @columnfractions .15 .70
10312 @item @var{SEED} @tab Shall be a scalar @code{INTEGER(kind=4)}.
10315 @item @emph{Return value}:
10316 Does not return anything.
10318 @item @emph{Example}:
10319 See @code{RAND} and @code{IRAND} for examples.
10321 @item @emph{Notes}:
10322 The Fortran 2003 standard specifies the intrinsic @code{RANDOM_SEED} to
10323 initialize the pseudo-random numbers generator and @code{RANDOM_NUMBER}
10324 to generate pseudo-random numbers. Please note that in
10325 GNU Fortran, these two sets of intrinsics (@code{RAND},
10326 @code{IRAND} and @code{SRAND} on the one hand, @code{RANDOM_NUMBER} and
10327 @code{RANDOM_SEED} on the other hand) access two independent
10328 pseudo-random number generators.
10330 @item @emph{See also}:
10331 @ref{RAND}, @ref{RANDOM_SEED}, @ref{RANDOM_NUMBER}
10338 @section @code{STAT} --- Get file status
10340 @cindex file system, file status
10343 @item @emph{Description}:
10344 This function returns information about a file. No permissions are required on
10345 the file itself, but execute (search) permission is required on all of the
10346 directories in path that lead to the file.
10348 The elements that are obtained and stored in the array @code{VALUES}:
10349 @multitable @columnfractions .15 .70
10350 @item @code{VALUES(1)} @tab Device ID
10351 @item @code{VALUES(2)} @tab Inode number
10352 @item @code{VALUES(3)} @tab File mode
10353 @item @code{VALUES(4)} @tab Number of links
10354 @item @code{VALUES(5)} @tab Owner's uid
10355 @item @code{VALUES(6)} @tab Owner's gid
10356 @item @code{VALUES(7)} @tab ID of device containing directory entry for file (0 if not available)
10357 @item @code{VALUES(8)} @tab File size (bytes)
10358 @item @code{VALUES(9)} @tab Last access time
10359 @item @code{VALUES(10)} @tab Last modification time
10360 @item @code{VALUES(11)} @tab Last file status change time
10361 @item @code{VALUES(12)} @tab Preferred I/O block size (-1 if not available)
10362 @item @code{VALUES(13)} @tab Number of blocks allocated (-1 if not available)
10365 Not all these elements are relevant on all systems.
10366 If an element is not relevant, it is returned as 0.
10368 This intrinsic is provided in both subroutine and function forms; however,
10369 only one form can be used in any given program unit.
10371 @item @emph{Standard}:
10374 @item @emph{Class}:
10375 Subroutine, function
10377 @item @emph{Syntax}:
10378 @code{CALL STAT(NAME, VALUES [, STATUS])}
10380 @item @emph{Arguments}:
10381 @multitable @columnfractions .15 .70
10382 @item @var{NAME} @tab The type shall be @code{CHARACTER}, of the
10383 default kind and a valid path within the file system.
10384 @item @var{VALUES} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
10385 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}. Returns 0
10386 on success and a system specific error code otherwise.
10389 @item @emph{Example}:
10392 INTEGER, DIMENSION(13) :: buff
10395 CALL STAT("/etc/passwd", buff, status)
10397 IF (status == 0) THEN
10398 WRITE (*, FMT="('Device ID:', T30, I19)") buff(1)
10399 WRITE (*, FMT="('Inode number:', T30, I19)") buff(2)
10400 WRITE (*, FMT="('File mode (octal):', T30, O19)") buff(3)
10401 WRITE (*, FMT="('Number of links:', T30, I19)") buff(4)
10402 WRITE (*, FMT="('Owner''s uid:', T30, I19)") buff(5)
10403 WRITE (*, FMT="('Owner''s gid:', T30, I19)") buff(6)
10404 WRITE (*, FMT="('Device where located:', T30, I19)") buff(7)
10405 WRITE (*, FMT="('File size:', T30, I19)") buff(8)
10406 WRITE (*, FMT="('Last access time:', T30, A19)") CTIME(buff(9))
10407 WRITE (*, FMT="('Last modification time', T30, A19)") CTIME(buff(10))
10408 WRITE (*, FMT="('Last status change time:', T30, A19)") CTIME(buff(11))
10409 WRITE (*, FMT="('Preferred block size:', T30, I19)") buff(12)
10410 WRITE (*, FMT="('No. of blocks allocated:', T30, I19)") buff(13)
10415 @item @emph{See also}:
10416 To stat an open file: @ref{FSTAT}, to stat a link: @ref{LSTAT}
10422 @section @code{SUM} --- Sum of array elements
10425 @cindex array, add elements
10426 @cindex array, conditionally add elements
10427 @cindex sum array elements
10430 @item @emph{Description}:
10431 Adds the elements of @var{ARRAY} along dimension @var{DIM} if
10432 the corresponding element in @var{MASK} is @code{TRUE}.
10434 @item @emph{Standard}:
10435 Fortran 95 and later
10437 @item @emph{Class}:
10438 Transformational function
10440 @item @emph{Syntax}:
10441 @multitable @columnfractions .80
10442 @item @code{RESULT = SUM(ARRAY[, MASK])}
10443 @item @code{RESULT = SUM(ARRAY, DIM[, MASK])}
10446 @item @emph{Arguments}:
10447 @multitable @columnfractions .15 .70
10448 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER},
10449 @code{REAL} or @code{COMPLEX}.
10450 @item @var{DIM} @tab (Optional) shall be a scalar of type
10451 @code{INTEGER} with a value in the range from 1 to n, where n
10452 equals the rank of @var{ARRAY}.
10453 @item @var{MASK} @tab (Optional) shall be of type @code{LOGICAL}
10454 and either be a scalar or an array of the same shape as @var{ARRAY}.
10457 @item @emph{Return value}:
10458 The result is of the same type as @var{ARRAY}.
10460 If @var{DIM} is absent, a scalar with the sum of all elements in @var{ARRAY}
10461 is returned. Otherwise, an array of rank n-1, where n equals the rank of
10462 @var{ARRAY},and a shape similar to that of @var{ARRAY} with dimension @var{DIM}
10463 dropped is returned.
10465 @item @emph{Example}:
10468 INTEGER :: x(5) = (/ 1, 2, 3, 4 ,5 /)
10469 print *, SUM(x) ! all elements, sum = 15
10470 print *, SUM(x, MASK=MOD(x, 2)==1) ! odd elements, sum = 9
10474 @item @emph{See also}:
10481 @section @code{SYMLNK} --- Create a symbolic link
10483 @cindex file system, create link
10484 @cindex file system, soft link
10487 @item @emph{Description}:
10488 Makes a symbolic link from file @var{PATH1} to @var{PATH2}. A null
10489 character (@code{CHAR(0)}) can be used to mark the end of the names in
10490 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
10491 names are ignored. If the @var{STATUS} argument is supplied, it
10492 contains 0 on success or a nonzero error code upon return; see
10493 @code{symlink(2)}. If the system does not supply @code{symlink(2)},
10494 @code{ENOSYS} is returned.
10496 This intrinsic is provided in both subroutine and function forms;
10497 however, only one form can be used in any given program unit.
10499 @item @emph{Standard}:
10502 @item @emph{Class}:
10503 Subroutine, function
10505 @item @emph{Syntax}:
10506 @multitable @columnfractions .80
10507 @item @code{CALL SYMLNK(PATH1, PATH2 [, STATUS])}
10508 @item @code{STATUS = SYMLNK(PATH1, PATH2)}
10511 @item @emph{Arguments}:
10512 @multitable @columnfractions .15 .70
10513 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
10514 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
10515 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
10518 @item @emph{See also}:
10519 @ref{LINK}, @ref{UNLINK}
10526 @section @code{SYSTEM} --- Execute a shell command
10528 @cindex system, system call
10531 @item @emph{Description}:
10532 Passes the command @var{COMMAND} to a shell (see @code{system(3)}). If
10533 argument @var{STATUS} is present, it contains the value returned by
10534 @code{system(3)}, which is presumably 0 if the shell command succeeded.
10535 Note that which shell is used to invoke the command is system-dependent
10536 and environment-dependent.
10538 This intrinsic is provided in both subroutine and function forms;
10539 however, only one form can be used in any given program unit.
10541 @item @emph{Standard}:
10544 @item @emph{Class}:
10545 Subroutine, function
10547 @item @emph{Syntax}:
10548 @multitable @columnfractions .80
10549 @item @code{CALL SYSTEM(COMMAND [, STATUS])}
10550 @item @code{STATUS = SYSTEM(COMMAND)}
10553 @item @emph{Arguments}:
10554 @multitable @columnfractions .15 .70
10555 @item @var{COMMAND} @tab Shall be of default @code{CHARACTER} type.
10556 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
10559 @item @emph{See also}:
10565 @section @code{SYSTEM_CLOCK} --- Time function
10566 @fnindex SYSTEM_CLOCK
10567 @cindex time, clock ticks
10568 @cindex clock ticks
10571 @item @emph{Description}:
10572 Determines the @var{COUNT} of milliseconds of wall clock time since
10573 the Epoch (00:00:00 UTC, January 1, 1970) modulo @var{COUNT_MAX},
10574 @var{COUNT_RATE} determines the number of clock ticks per second.
10575 @var{COUNT_RATE} and @var{COUNT_MAX} are constant and specific to
10576 @command{gfortran}.
10578 If there is no clock, @var{COUNT} is set to @code{-HUGE(COUNT)}, and
10579 @var{COUNT_RATE} and @var{COUNT_MAX} are set to zero
10581 @item @emph{Standard}:
10582 Fortran 95 and later
10584 @item @emph{Class}:
10587 @item @emph{Syntax}:
10588 @code{CALL SYSTEM_CLOCK([COUNT, COUNT_RATE, COUNT_MAX])}
10590 @item @emph{Arguments}:
10591 @item @emph{Arguments}:
10592 @multitable @columnfractions .15 .70
10593 @item @var{COUNT} @tab (Optional) shall be a scalar of type default
10594 @code{INTEGER} with @code{INTENT(OUT)}.
10595 @item @var{COUNT_RATE} @tab (Optional) shall be a scalar of type default
10596 @code{INTEGER} with @code{INTENT(OUT)}.
10597 @item @var{COUNT_MAX} @tab (Optional) shall be a scalar of type default
10598 @code{INTEGER} with @code{INTENT(OUT)}.
10601 @item @emph{Example}:
10603 PROGRAM test_system_clock
10604 INTEGER :: count, count_rate, count_max
10605 CALL SYSTEM_CLOCK(count, count_rate, count_max)
10606 WRITE(*,*) count, count_rate, count_max
10610 @item @emph{See also}:
10611 @ref{DATE_AND_TIME}, @ref{CPU_TIME}
10617 @section @code{TAN} --- Tangent function
10620 @cindex trigonometric function, tangent
10624 @item @emph{Description}:
10625 @code{TAN(X)} computes the tangent of @var{X}.
10627 @item @emph{Standard}:
10628 Fortran 77 and later, for a complex argument Fortran 2008 or later
10630 @item @emph{Class}:
10633 @item @emph{Syntax}:
10634 @code{RESULT = TAN(X)}
10636 @item @emph{Arguments}:
10637 @multitable @columnfractions .15 .70
10638 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
10641 @item @emph{Return value}:
10642 The return value has same type and kind as @var{X}.
10644 @item @emph{Example}:
10647 real(8) :: x = 0.165_8
10649 end program test_tan
10652 @item @emph{Specific names}:
10653 @multitable @columnfractions .20 .20 .20 .25
10654 @item Name @tab Argument @tab Return type @tab Standard
10655 @item @code{TAN(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 95 and later
10656 @item @code{DTAN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 95 and later
10659 @item @emph{See also}:
10666 @section @code{TANH} --- Hyperbolic tangent function
10669 @cindex hyperbolic tangent
10670 @cindex hyperbolic function, tangent
10671 @cindex tangent, hyperbolic
10674 @item @emph{Description}:
10675 @code{TANH(X)} computes the hyperbolic tangent of @var{X}.
10677 @item @emph{Standard}:
10678 Fortran 77 and later, for a complex argument Fortran 2008 or later
10680 @item @emph{Class}:
10683 @item @emph{Syntax}:
10686 @item @emph{Arguments}:
10687 @multitable @columnfractions .15 .70
10688 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
10691 @item @emph{Return value}:
10692 The return value has same type and kind as @var{X}. If @var{X} is
10693 complex, the imaginary part of the result is in radians. If @var{X}
10694 is @code{REAL}, the return value lies in the range
10695 @math{ - 1 \leq tanh(x) \leq 1 }.
10697 @item @emph{Example}:
10700 real(8) :: x = 2.1_8
10702 end program test_tanh
10705 @item @emph{Specific names}:
10706 @multitable @columnfractions .20 .20 .20 .25
10707 @item Name @tab Argument @tab Return type @tab Standard
10708 @item @code{TANH(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 95 and later
10709 @item @code{DTANH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 95 and later
10712 @item @emph{See also}:
10719 @section @code{THIS_IMAGE} --- Function that returns the cosubscript index of this image
10720 @fnindex THIS_IMAGE
10721 @cindex coarray, THIS_IMAGE
10722 @cindex images, index of this image
10725 @item @emph{Description}:
10726 Returns the cosubscript for this image.
10728 @item @emph{Standard}:
10729 Fortran 2008 and later
10731 @item @emph{Class}:
10732 Transformational function
10734 @item @emph{Syntax}:
10735 @multitable @columnfractions .80
10736 @item @code{RESULT = THIS_IMAGE()}
10737 @item @code{RESULT = THIS_IMAGE(COARRAY [, DIM])}
10740 @item @emph{Arguments}:
10741 @multitable @columnfractions .15 .70
10742 @item @var{COARRAY} @tab Coarray of any type (optional; if @var{DIM}
10743 present, required).
10744 @item @var{DIM} @tab default integer scalar (optional). If present,
10745 @var{DIM} shall be between one and the corank of @var{COARRAY}.
10749 @item @emph{Return value}:
10750 Default integer. If @var{COARRAY} is not present, it is scalar and its value
10751 is the index of the invoking image. Otherwise, if @var{DIM} is not present,
10752 a rank-1 array with corank elements is returned, containing the cosubscripts
10753 for @var{COARRAY} specifying the invoking image. If @var{DIM} is present,
10754 a scalar is returned, with the value of the @var{DIM} element of
10755 @code{THIS_IMAGE(COARRAY)}.
10757 @item @emph{Example}:
10759 INTEGER :: value[*]
10761 value = THIS_IMAGE()
10763 IF (THIS_IMAGE() == 1) THEN
10764 DO i = 1, NUM_IMAGES()
10765 WRITE(*,'(2(a,i0))') 'value[', i, '] is ', value[i]
10770 @item @emph{See also}:
10771 @ref{NUM_IMAGES}, @ref{IMAGE_INDEX}
10777 @section @code{TIME} --- Time function
10779 @cindex time, current
10780 @cindex current time
10783 @item @emph{Description}:
10784 Returns the current time encoded as an integer (in the manner of the
10785 UNIX function @code{time(3)}). This value is suitable for passing to
10786 @code{CTIME()}, @code{GMTIME()}, and @code{LTIME()}.
10788 This intrinsic is not fully portable, such as to systems with 32-bit
10789 @code{INTEGER} types but supporting times wider than 32 bits. Therefore,
10790 the values returned by this intrinsic might be, or become, negative, or
10791 numerically less than previous values, during a single run of the
10794 See @ref{TIME8}, for information on a similar intrinsic that might be
10795 portable to more GNU Fortran implementations, though to fewer Fortran
10798 @item @emph{Standard}:
10801 @item @emph{Class}:
10804 @item @emph{Syntax}:
10805 @code{RESULT = TIME()}
10807 @item @emph{Return value}:
10808 The return value is a scalar of type @code{INTEGER(4)}.
10810 @item @emph{See also}:
10811 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK}, @ref{TIME8}
10818 @section @code{TIME8} --- Time function (64-bit)
10820 @cindex time, current
10821 @cindex current time
10824 @item @emph{Description}:
10825 Returns the current time encoded as an integer (in the manner of the
10826 UNIX function @code{time(3)}). This value is suitable for passing to
10827 @code{CTIME()}, @code{GMTIME()}, and @code{LTIME()}.
10829 @emph{Warning:} this intrinsic does not increase the range of the timing
10830 values over that returned by @code{time(3)}. On a system with a 32-bit
10831 @code{time(3)}, @code{TIME8()} will return a 32-bit value, even though
10832 it is converted to a 64-bit @code{INTEGER(8)} value. That means
10833 overflows of the 32-bit value can still occur. Therefore, the values
10834 returned by this intrinsic might be or become negative or numerically
10835 less than previous values during a single run of the compiled program.
10837 @item @emph{Standard}:
10840 @item @emph{Class}:
10843 @item @emph{Syntax}:
10844 @code{RESULT = TIME8()}
10846 @item @emph{Return value}:
10847 The return value is a scalar of type @code{INTEGER(8)}.
10849 @item @emph{See also}:
10850 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK8}, @ref{TIME}
10857 @section @code{TINY} --- Smallest positive number of a real kind
10859 @cindex limits, smallest number
10860 @cindex model representation, smallest number
10863 @item @emph{Description}:
10864 @code{TINY(X)} returns the smallest positive (non zero) number
10865 in the model of the type of @code{X}.
10867 @item @emph{Standard}:
10868 Fortran 95 and later
10870 @item @emph{Class}:
10873 @item @emph{Syntax}:
10874 @code{RESULT = TINY(X)}
10876 @item @emph{Arguments}:
10877 @multitable @columnfractions .15 .70
10878 @item @var{X} @tab Shall be of type @code{REAL}.
10881 @item @emph{Return value}:
10882 The return value is of the same type and kind as @var{X}
10884 @item @emph{Example}:
10885 See @code{HUGE} for an example.
10891 @section @code{TRAILZ} --- Number of trailing zero bits of an integer
10896 @item @emph{Description}:
10897 @code{TRAILZ} returns the number of trailing zero bits of an integer.
10899 @item @emph{Standard}:
10900 Fortran 2008 and later
10902 @item @emph{Class}:
10905 @item @emph{Syntax}:
10906 @code{RESULT = TRAILZ(I)}
10908 @item @emph{Arguments}:
10909 @multitable @columnfractions .15 .70
10910 @item @var{I} @tab Shall be of type @code{INTEGER}.
10913 @item @emph{Return value}:
10914 The type of the return value is the default @code{INTEGER}.
10915 If all the bits of @code{I} are zero, the result value is @code{BIT_SIZE(I)}.
10917 @item @emph{Example}:
10919 PROGRAM test_trailz
10920 WRITE (*,*) TRAILZ(8) ! prints 3
10924 @item @emph{See also}:
10925 @ref{BIT_SIZE}, @ref{LEADZ}
10931 @section @code{TRANSFER} --- Transfer bit patterns
10937 @item @emph{Description}:
10938 Interprets the bitwise representation of @var{SOURCE} in memory as if it
10939 is the representation of a variable or array of the same type and type
10940 parameters as @var{MOLD}.
10942 This is approximately equivalent to the C concept of @emph{casting} one
10945 @item @emph{Standard}:
10946 Fortran 95 and later
10948 @item @emph{Class}:
10949 Transformational function
10951 @item @emph{Syntax}:
10952 @code{RESULT = TRANSFER(SOURCE, MOLD[, SIZE])}
10954 @item @emph{Arguments}:
10955 @multitable @columnfractions .15 .70
10956 @item @var{SOURCE} @tab Shall be a scalar or an array of any type.
10957 @item @var{MOLD} @tab Shall be a scalar or an array of any type.
10958 @item @var{SIZE} @tab (Optional) shall be a scalar of type
10962 @item @emph{Return value}:
10963 The result has the same type as @var{MOLD}, with the bit level
10964 representation of @var{SOURCE}. If @var{SIZE} is present, the result is
10965 a one-dimensional array of length @var{SIZE}. If @var{SIZE} is absent
10966 but @var{MOLD} is an array (of any size or shape), the result is a one-
10967 dimensional array of the minimum length needed to contain the entirety
10968 of the bitwise representation of @var{SOURCE}. If @var{SIZE} is absent
10969 and @var{MOLD} is a scalar, the result is a scalar.
10971 If the bitwise representation of the result is longer than that of
10972 @var{SOURCE}, then the leading bits of the result correspond to those of
10973 @var{SOURCE} and any trailing bits are filled arbitrarily.
10975 When the resulting bit representation does not correspond to a valid
10976 representation of a variable of the same type as @var{MOLD}, the results
10977 are undefined, and subsequent operations on the result cannot be
10978 guaranteed to produce sensible behavior. For example, it is possible to
10979 create @code{LOGICAL} variables for which @code{@var{VAR}} and
10980 @code{.NOT.@var{VAR}} both appear to be true.
10982 @item @emph{Example}:
10984 PROGRAM test_transfer
10985 integer :: x = 2143289344
10986 print *, transfer(x, 1.0) ! prints "NaN" on i686
10994 @section @code{TRANSPOSE} --- Transpose an array of rank two
10996 @cindex array, transpose
10997 @cindex matrix, transpose
11001 @item @emph{Description}:
11002 Transpose an array of rank two. Element (i, j) of the result has the value
11003 @code{MATRIX(j, i)}, for all i, j.
11005 @item @emph{Standard}:
11006 Fortran 95 and later
11008 @item @emph{Class}:
11009 Transformational function
11011 @item @emph{Syntax}:
11012 @code{RESULT = TRANSPOSE(MATRIX)}
11014 @item @emph{Arguments}:
11015 @multitable @columnfractions .15 .70
11016 @item @var{MATRIX} @tab Shall be an array of any type and have a rank of two.
11019 @item @emph{Return value}:
11020 The result has the same type as @var{MATRIX}, and has shape
11021 @code{(/ m, n /)} if @var{MATRIX} has shape @code{(/ n, m /)}.
11027 @section @code{TRIM} --- Remove trailing blank characters of a string
11029 @cindex string, remove trailing whitespace
11032 @item @emph{Description}:
11033 Removes trailing blank characters of a string.
11035 @item @emph{Standard}:
11036 Fortran 95 and later
11038 @item @emph{Class}:
11039 Transformational function
11041 @item @emph{Syntax}:
11042 @code{RESULT = TRIM(STRING)}
11044 @item @emph{Arguments}:
11045 @multitable @columnfractions .15 .70
11046 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER}.
11049 @item @emph{Return value}:
11050 A scalar of type @code{CHARACTER} which length is that of @var{STRING}
11051 less the number of trailing blanks.
11053 @item @emph{Example}:
11056 CHARACTER(len=10), PARAMETER :: s = "GFORTRAN "
11057 WRITE(*,*) LEN(s), LEN(TRIM(s)) ! "10 8", with/without trailing blanks
11061 @item @emph{See also}:
11062 @ref{ADJUSTL}, @ref{ADJUSTR}
11068 @section @code{TTYNAM} --- Get the name of a terminal device.
11070 @cindex system, terminal
11073 @item @emph{Description}:
11074 Get the name of a terminal device. For more information,
11075 see @code{ttyname(3)}.
11077 This intrinsic is provided in both subroutine and function forms;
11078 however, only one form can be used in any given program unit.
11080 @item @emph{Standard}:
11083 @item @emph{Class}:
11084 Subroutine, function
11086 @item @emph{Syntax}:
11087 @multitable @columnfractions .80
11088 @item @code{CALL TTYNAM(UNIT, NAME)}
11089 @item @code{NAME = TTYNAM(UNIT)}
11092 @item @emph{Arguments}:
11093 @multitable @columnfractions .15 .70
11094 @item @var{UNIT} @tab Shall be a scalar @code{INTEGER}.
11095 @item @var{NAME} @tab Shall be of type @code{CHARACTER}.
11098 @item @emph{Example}:
11100 PROGRAM test_ttynam
11103 IF (isatty(unit=unit)) write(*,*) ttynam(unit)
11108 @item @emph{See also}:
11115 @section @code{UBOUND} --- Upper dimension bounds of an array
11117 @cindex array, upper bound
11120 @item @emph{Description}:
11121 Returns the upper bounds of an array, or a single upper bound
11122 along the @var{DIM} dimension.
11123 @item @emph{Standard}:
11124 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
11126 @item @emph{Class}:
11129 @item @emph{Syntax}:
11130 @code{RESULT = UBOUND(ARRAY [, DIM [, KIND]])}
11132 @item @emph{Arguments}:
11133 @multitable @columnfractions .15 .70
11134 @item @var{ARRAY} @tab Shall be an array, of any type.
11135 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER}.
11136 @item @var{KIND}@tab (Optional) An @code{INTEGER} initialization
11137 expression indicating the kind parameter of the result.
11140 @item @emph{Return value}:
11141 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
11142 @var{KIND} is absent, the return value is of default integer kind.
11143 If @var{DIM} is absent, the result is an array of the upper bounds of
11144 @var{ARRAY}. If @var{DIM} is present, the result is a scalar
11145 corresponding to the upper bound of the array along that dimension. If
11146 @var{ARRAY} is an expression rather than a whole array or array
11147 structure component, or if it has a zero extent along the relevant
11148 dimension, the upper bound is taken to be the number of elements along
11149 the relevant dimension.
11151 @item @emph{See also}:
11152 @ref{LBOUND}, @ref{LCOBOUND}
11158 @section @code{UCOBOUND} --- Upper codimension bounds of an array
11160 @cindex coarray, upper bound
11163 @item @emph{Description}:
11164 Returns the upper cobounds of a coarray, or a single upper cobound
11165 along the @var{DIM} codimension.
11166 @item @emph{Standard}:
11167 Fortran 2008 and later
11169 @item @emph{Class}:
11172 @item @emph{Syntax}:
11173 @code{RESULT = UCOBOUND(COARRAY [, DIM [, KIND]])}
11175 @item @emph{Arguments}:
11176 @multitable @columnfractions .15 .70
11177 @item @var{ARRAY} @tab Shall be an coarray, of any type.
11178 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER}.
11179 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
11180 expression indicating the kind parameter of the result.
11183 @item @emph{Return value}:
11184 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
11185 @var{KIND} is absent, the return value is of default integer kind.
11186 If @var{DIM} is absent, the result is an array of the lower cobounds of
11187 @var{COARRAY}. If @var{DIM} is present, the result is a scalar
11188 corresponding to the lower cobound of the array along that codimension.
11190 @item @emph{See also}:
11191 @ref{LCOBOUND}, @ref{LBOUND}
11197 @section @code{UMASK} --- Set the file creation mask
11199 @cindex file system, file creation mask
11202 @item @emph{Description}:
11203 Sets the file creation mask to @var{MASK}. If called as a function, it
11204 returns the old value. If called as a subroutine and argument @var{OLD}
11205 if it is supplied, it is set to the old value. See @code{umask(2)}.
11207 @item @emph{Standard}:
11210 @item @emph{Class}:
11211 Subroutine, function
11213 @item @emph{Syntax}:
11214 @code{CALL UMASK(MASK [, OLD])}
11215 @code{OLD = UMASK(MASK)}
11217 @item @emph{Arguments}:
11218 @multitable @columnfractions .15 .70
11219 @item @var{MASK} @tab Shall be a scalar of type @code{INTEGER}.
11220 @item @var{OLD} @tab (Optional) Shall be a scalar of type
11229 @section @code{UNLINK} --- Remove a file from the file system
11231 @cindex file system, remove file
11234 @item @emph{Description}:
11235 Unlinks the file @var{PATH}. A null character (@code{CHAR(0)}) can be
11236 used to mark the end of the name in @var{PATH}; otherwise, trailing
11237 blanks in the file name are ignored. If the @var{STATUS} argument is
11238 supplied, it contains 0 on success or a nonzero error code upon return;
11239 see @code{unlink(2)}.
11241 This intrinsic is provided in both subroutine and function forms;
11242 however, only one form can be used in any given program unit.
11244 @item @emph{Standard}:
11247 @item @emph{Class}:
11248 Subroutine, function
11250 @item @emph{Syntax}:
11251 @multitable @columnfractions .80
11252 @item @code{CALL UNLINK(PATH [, STATUS])}
11253 @item @code{STATUS = UNLINK(PATH)}
11256 @item @emph{Arguments}:
11257 @multitable @columnfractions .15 .70
11258 @item @var{PATH} @tab Shall be of default @code{CHARACTER} type.
11259 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
11262 @item @emph{See also}:
11263 @ref{LINK}, @ref{SYMLNK}
11269 @section @code{UNPACK} --- Unpack an array of rank one into an array
11271 @cindex array, unpacking
11272 @cindex array, increase dimension
11273 @cindex array, scatter elements
11276 @item @emph{Description}:
11277 Store the elements of @var{VECTOR} in an array of higher rank.
11279 @item @emph{Standard}:
11280 Fortran 95 and later
11282 @item @emph{Class}:
11283 Transformational function
11285 @item @emph{Syntax}:
11286 @code{RESULT = UNPACK(VECTOR, MASK, FIELD)}
11288 @item @emph{Arguments}:
11289 @multitable @columnfractions .15 .70
11290 @item @var{VECTOR} @tab Shall be an array of any type and rank one. It
11291 shall have at least as many elements as @var{MASK} has @code{TRUE} values.
11292 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL}.
11293 @item @var{FIELD} @tab Shall be of the same type as @var{VECTOR} and have
11294 the same shape as @var{MASK}.
11297 @item @emph{Return value}:
11298 The resulting array corresponds to @var{FIELD} with @code{TRUE} elements
11299 of @var{MASK} replaced by values from @var{VECTOR} in array element order.
11301 @item @emph{Example}:
11303 PROGRAM test_unpack
11304 integer :: vector(2) = (/1,1/)
11305 logical :: mask(4) = (/ .TRUE., .FALSE., .FALSE., .TRUE. /)
11306 integer :: field(2,2) = 0, unity(2,2)
11308 ! result: unity matrix
11309 unity = unpack(vector, reshape(mask, (/2,2/)), field)
11313 @item @emph{See also}:
11314 @ref{PACK}, @ref{SPREAD}
11320 @section @code{VERIFY} --- Scan a string for the absence of a set of characters
11322 @cindex string, find missing set
11325 @item @emph{Description}:
11326 Verifies that all the characters in a @var{SET} are present in a @var{STRING}.
11328 If @var{BACK} is either absent or equals @code{FALSE}, this function
11329 returns the position of the leftmost character of @var{STRING} that is
11330 not in @var{SET}. If @var{BACK} equals @code{TRUE}, the rightmost position
11331 is returned. If all characters of @var{SET} are found in @var{STRING}, the
11334 @item @emph{Standard}:
11335 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
11337 @item @emph{Class}:
11340 @item @emph{Syntax}:
11341 @code{RESULT = VERIFY(STRING, SET[, BACK [, KIND]])}
11343 @item @emph{Arguments}:
11344 @multitable @columnfractions .15 .70
11345 @item @var{STRING} @tab Shall be of type @code{CHARACTER}.
11346 @item @var{SET} @tab Shall be of type @code{CHARACTER}.
11347 @item @var{BACK} @tab (Optional) shall be of type @code{LOGICAL}.
11348 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
11349 expression indicating the kind parameter of the result.
11352 @item @emph{Return value}:
11353 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
11354 @var{KIND} is absent, the return value is of default integer kind.
11356 @item @emph{Example}:
11358 PROGRAM test_verify
11359 WRITE(*,*) VERIFY("FORTRAN", "AO") ! 1, found 'F'
11360 WRITE(*,*) VERIFY("FORTRAN", "FOO") ! 3, found 'R'
11361 WRITE(*,*) VERIFY("FORTRAN", "C++") ! 1, found 'F'
11362 WRITE(*,*) VERIFY("FORTRAN", "C++", .TRUE.) ! 7, found 'N'
11363 WRITE(*,*) VERIFY("FORTRAN", "FORTRAN") ! 0' found none
11367 @item @emph{See also}:
11368 @ref{SCAN}, @ref{INDEX intrinsic}
11374 @section @code{XOR} --- Bitwise logical exclusive OR
11376 @cindex bitwise logical exclusive or
11377 @cindex logical exclusive or, bitwise
11380 @item @emph{Description}:
11381 Bitwise logical exclusive or.
11383 This intrinsic routine is provided for backwards compatibility with
11384 GNU Fortran 77. For integer arguments, programmers should consider
11385 the use of the @ref{IEOR} intrinsic and for logical arguments the
11386 @code{.NEQV.} operator, which are both defined by the Fortran standard.
11388 @item @emph{Standard}:
11391 @item @emph{Class}:
11394 @item @emph{Syntax}:
11395 @code{RESULT = XOR(I, J)}
11397 @item @emph{Arguments}:
11398 @multitable @columnfractions .15 .70
11399 @item @var{I} @tab The type shall be either a scalar @code{INTEGER}
11400 type or a scalar @code{LOGICAL} type.
11401 @item @var{J} @tab The type shall be the same as the type of @var{I}.
11404 @item @emph{Return value}:
11405 The return type is either a scalar @code{INTEGER} or a scalar
11406 @code{LOGICAL}. If the kind type parameters differ, then the
11407 smaller kind type is implicitly converted to larger kind, and the
11408 return has the larger kind.
11410 @item @emph{Example}:
11413 LOGICAL :: T = .TRUE., F = .FALSE.
11415 DATA a / Z'F' /, b / Z'3' /
11417 WRITE (*,*) XOR(T, T), XOR(T, F), XOR(F, T), XOR(F, F)
11418 WRITE (*,*) XOR(a, b)
11422 @item @emph{See also}:
11423 Fortran 95 elemental function: @ref{IEOR}
11428 @node Intrinsic Modules
11429 @chapter Intrinsic Modules
11430 @cindex intrinsic Modules
11433 * ISO_FORTRAN_ENV::
11435 * OpenMP Modules OMP_LIB and OMP_LIB_KINDS::
11438 @node ISO_FORTRAN_ENV
11439 @section @code{ISO_FORTRAN_ENV}
11441 @item @emph{Standard}:
11442 Fortran 2003 and later, except when otherwise noted
11445 The @code{ISO_FORTRAN_ENV} module provides the following scalar default-integer
11449 @item @code{ATOMIC_INT_KIND}:
11450 Default-kind integer constant to be used as kind parameter when defining
11451 integer variables used in atomic operations. (Fortran 2008 or later.)
11453 @item @code{ATOMIC_LOGICAL_KIND}:
11454 Default-kind integer constant to be used as kind parameter when defining
11455 logical variables used in atomic operations. (Fortran 2008 or later.)
11457 @item @code{CHARACTER_STORAGE_SIZE}:
11458 Size in bits of the character storage unit.
11460 @item @code{ERROR_UNIT}:
11461 Identifies the preconnected unit used for error reporting.
11463 @item @code{FILE_STORAGE_SIZE}:
11464 Size in bits of the file-storage unit.
11466 @item @code{INPUT_UNIT}:
11467 Identifies the preconnected unit identified by the asterisk
11468 (@code{*}) in @code{READ} statement.
11470 @item @code{INT8}, @code{INT16}, @code{INT32}, @code{INT64}:
11471 Kind type parameters to specify an INTEGER type with a storage
11472 size of 16, 32, and 64 bits. It is negative if a target platform
11473 does not support the particular kind. (Fortran 2008 or later.)
11475 @item @code{IOSTAT_END}:
11476 The value assigned to the variable passed to the IOSTAT= specifier of
11477 an input/output statement if an end-of-file condition occurred.
11479 @item @code{IOSTAT_EOR}:
11480 The value assigned to the variable passed to the IOSTAT= specifier of
11481 an input/output statement if an end-of-record condition occurred.
11483 @item @code{IOSTAT_INQUIRE_INTERNAL_UNIT}:
11484 Scalar default-integer constant, used by @code{INQUIRE} for the
11485 IOSTAT= specifier to denote an that a unit number identifies an
11486 internal unit. (Fortran 2008 or later.)
11488 @item @code{NUMERIC_STORAGE_SIZE}:
11489 The size in bits of the numeric storage unit.
11491 @item @code{OUTPUT_UNIT}:
11492 Identifies the preconnected unit identified by the asterisk
11493 (@code{*}) in @code{WRITE} statement.
11495 @item @code{REAL32}, @code{REAL64}, @code{REAL128}:
11496 Kind type parameters to specify a REAL type with a storage
11497 size of 32, 64, and 128 bits. It is negative if a target platform
11498 does not support the particular kind. (Fortran 2008 or later.)
11500 @item @code{STAT_LOCKED}:
11501 Scalar default-integer constant used as STAT= return value by @code{LOCK} to
11502 denote that the lock variable is locked by the executing image. (Fortran 2008
11505 @item @code{STAT_LOCKED_OTHER_IMAGE}:
11506 Scalar default-integer constant used as STAT= return value by @code{UNLOCK} to
11507 denote that the lock variable is locked by another image. (Fortran 2008 or
11510 @item @code{STAT_STOPPED_IMAGE}:
11511 Positive, scalar default-integer constant used as STAT= return value if the
11512 argument in the statement requires synchronisation with an image, which has
11513 initiated the termination of the execution. (Fortran 2008 or later.)
11515 @item @code{STAT_UNLOCKED}:
11516 Scalar default-integer constant used as STAT= return value by @code{UNLOCK} to
11517 denote that the lock variable is unlocked. (Fortran 2008 or later.)
11522 @node ISO_C_BINDING
11523 @section @code{ISO_C_BINDING}
11525 @item @emph{Standard}:
11526 Fortran 2003 and later, GNU extensions
11529 The following intrinsic procedures are provided by the module; their
11530 definition can be found in the section Intrinsic Procedures of this
11534 @item @code{C_ASSOCIATED}
11535 @item @code{C_F_POINTER}
11536 @item @code{C_F_PROCPOINTER}
11537 @item @code{C_FUNLOC}
11540 @c TODO: Vertical spacing between C_FUNLOC and C_LOC wrong in PDF,
11541 @c don't really know why.
11543 The @code{ISO_C_BINDING} module provides the following named constants of
11544 type default integer, which can be used as KIND type parameters.
11546 In addition to the integer named constants required by the Fortran 2003
11547 standard, GNU Fortran provides as an extension named constants for the
11548 128-bit integer types supported by the C compiler: @code{C_INT128_T,
11549 C_INT_LEAST128_T, C_INT_FAST128_T}.
11551 @multitable @columnfractions .15 .35 .35 .35
11552 @item Fortran Type @tab Named constant @tab C type @tab Extension
11553 @item @code{INTEGER}@tab @code{C_INT} @tab @code{int}
11554 @item @code{INTEGER}@tab @code{C_SHORT} @tab @code{short int}
11555 @item @code{INTEGER}@tab @code{C_LONG} @tab @code{long int}
11556 @item @code{INTEGER}@tab @code{C_LONG_LONG} @tab @code{long long int}
11557 @item @code{INTEGER}@tab @code{C_SIGNED_CHAR} @tab @code{signed char}/@code{unsigned char}
11558 @item @code{INTEGER}@tab @code{C_SIZE_T} @tab @code{size_t}
11559 @item @code{INTEGER}@tab @code{C_INT8_T} @tab @code{int8_t}
11560 @item @code{INTEGER}@tab @code{C_INT16_T} @tab @code{int16_t}
11561 @item @code{INTEGER}@tab @code{C_INT32_T} @tab @code{int32_t}
11562 @item @code{INTEGER}@tab @code{C_INT64_T} @tab @code{int64_t}
11563 @item @code{INTEGER}@tab @code{C_INT128_T} @tab @code{int128_t} @tab Ext.
11564 @item @code{INTEGER}@tab @code{C_INT_LEAST8_T} @tab @code{int_least8_t}
11565 @item @code{INTEGER}@tab @code{C_INT_LEAST16_T} @tab @code{int_least16_t}
11566 @item @code{INTEGER}@tab @code{C_INT_LEAST32_T} @tab @code{int_least32_t}
11567 @item @code{INTEGER}@tab @code{C_INT_LEAST64_T} @tab @code{int_least64_t}
11568 @item @code{INTEGER}@tab @code{C_INT_LEAST128_T}@tab @code{int_least128_t} @tab Ext.
11569 @item @code{INTEGER}@tab @code{C_INT_FAST8_T} @tab @code{int_fast8_t}
11570 @item @code{INTEGER}@tab @code{C_INT_FAST16_T} @tab @code{int_fast16_t}
11571 @item @code{INTEGER}@tab @code{C_INT_FAST32_T} @tab @code{int_fast32_t}
11572 @item @code{INTEGER}@tab @code{C_INT_FAST64_T} @tab @code{int_fast64_t}
11573 @item @code{INTEGER}@tab @code{C_INT_FAST128_T} @tab @code{int_fast128_t} @tab Ext.
11574 @item @code{INTEGER}@tab @code{C_INTMAX_T} @tab @code{intmax_t}
11575 @item @code{INTEGER}@tab @code{C_INTPTR_T} @tab @code{intptr_t}
11576 @item @code{REAL} @tab @code{C_FLOAT} @tab @code{float}
11577 @item @code{REAL} @tab @code{C_DOUBLE} @tab @code{double}
11578 @item @code{REAL} @tab @code{C_LONG_DOUBLE} @tab @code{long double}
11579 @item @code{COMPLEX}@tab @code{C_FLOAT_COMPLEX} @tab @code{float _Complex}
11580 @item @code{COMPLEX}@tab @code{C_DOUBLE_COMPLEX}@tab @code{double _Complex}
11581 @item @code{COMPLEX}@tab @code{C_LONG_DOUBLE_COMPLEX}@tab @code{long double _Complex}
11582 @item @code{LOGICAL}@tab @code{C_BOOL} @tab @code{_Bool}
11583 @item @code{CHARACTER}@tab @code{C_CHAR} @tab @code{char}
11586 Additionally, the following parameters of type @code{CHARACTER(KIND=C_CHAR)}
11589 @multitable @columnfractions .20 .45 .15
11590 @item Name @tab C definition @tab Value
11591 @item @code{C_NULL_CHAR} @tab null character @tab @code{'\0'}
11592 @item @code{C_ALERT} @tab alert @tab @code{'\a'}
11593 @item @code{C_BACKSPACE} @tab backspace @tab @code{'\b'}
11594 @item @code{C_FORM_FEED} @tab form feed @tab @code{'\f'}
11595 @item @code{C_NEW_LINE} @tab new line @tab @code{'\n'}
11596 @item @code{C_CARRIAGE_RETURN} @tab carriage return @tab @code{'\r'}
11597 @item @code{C_HORIZONTAL_TAB} @tab horizontal tab @tab @code{'\t'}
11598 @item @code{C_VERTICAL_TAB} @tab vertical tab @tab @code{'\v'}
11601 @node OpenMP Modules OMP_LIB and OMP_LIB_KINDS
11602 @section OpenMP Modules @code{OMP_LIB} and @code{OMP_LIB_KINDS}
11604 @item @emph{Standard}:
11605 OpenMP Application Program Interface v3.0
11609 The OpenMP Fortran runtime library routines are provided both in
11610 a form of two Fortran 90 modules, named @code{OMP_LIB} and
11611 @code{OMP_LIB_KINDS}, and in a form of a Fortran @code{include} file named
11612 @file{omp_lib.h}. The procedures provided by @code{OMP_LIB} can be found
11613 in the @ref{Top,,Introduction,libgomp,GNU OpenMP runtime library} manual,
11614 the named constants defined in the @code{OMP_LIB_KINDS} module are listed
11617 For details refer to the actual
11618 @uref{http://www.openmp.org/mp-documents/spec30.pdf,
11619 OpenMP Application Program Interface v3.0}.
11621 @code{OMP_LIB_KINDS} provides the following scalar default-integer
11625 @item @code{omp_integer_kind}
11626 @item @code{omp_logical_kind}
11627 @item @code{omp_lock_kind}
11628 @item @code{omp_nest_lock_kind}
11629 @item @code{omp_sched_kind}