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.3 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, Inverse hyperbolic cosine 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, Inverse hyperbolic sine 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, Inverse hyperbolic tangent 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{BGE}: BGE, Bitwise greater than or equal to
71 * @code{BGT}: BGT, Bitwise greater than
72 * @code{BIT_SIZE}: BIT_SIZE, Bit size inquiry function
73 * @code{BLE}: BLE, Bitwise less than or equal to
74 * @code{BLT}: BLT, Bitwise less than
75 * @code{BTEST}: BTEST, Bit test function
76 * @code{C_ASSOCIATED}: C_ASSOCIATED, Status of a C pointer
77 * @code{C_F_POINTER}: C_F_POINTER, Convert C into Fortran pointer
78 * @code{C_F_PROCPOINTER}: C_F_PROCPOINTER, Convert C into Fortran procedure pointer
79 * @code{C_FUNLOC}: C_FUNLOC, Obtain the C address of a procedure
80 * @code{C_LOC}: C_LOC, Obtain the C address of an object
81 * @code{C_SIZEOF}: C_SIZEOF, Size in bytes of an expression
82 * @code{CEILING}: CEILING, Integer ceiling function
83 * @code{CHAR}: CHAR, Integer-to-character conversion function
84 * @code{CHDIR}: CHDIR, Change working directory
85 * @code{CHMOD}: CHMOD, Change access permissions of files
86 * @code{CMPLX}: CMPLX, Complex conversion function
87 * @code{COMMAND_ARGUMENT_COUNT}: COMMAND_ARGUMENT_COUNT, Get number of command line arguments
88 * @code{COMPLEX}: COMPLEX, Complex conversion function
89 * @code{COMPILER_VERSION}: COMPILER_VERSION, Compiler version string
90 * @code{COMPILER_OPTIONS}: COMPILER_OPTIONS, Options passed to the compiler
91 * @code{CONJG}: CONJG, Complex conjugate function
92 * @code{COS}: COS, Cosine function
93 * @code{COSH}: COSH, Hyperbolic cosine function
94 * @code{COUNT}: COUNT, Count occurrences of TRUE in an array
95 * @code{CPU_TIME}: CPU_TIME, CPU time subroutine
96 * @code{CSHIFT}: CSHIFT, Circular shift elements of an array
97 * @code{CTIME}: CTIME, Subroutine (or function) to convert a time into a string
98 * @code{DATE_AND_TIME}: DATE_AND_TIME, Date and time subroutine
99 * @code{DBLE}: DBLE, Double precision conversion function
100 * @code{DCMPLX}: DCMPLX, Double complex conversion function
101 * @code{DIGITS}: DIGITS, Significant digits function
102 * @code{DIM}: DIM, Positive difference
103 * @code{DOT_PRODUCT}: DOT_PRODUCT, Dot product function
104 * @code{DPROD}: DPROD, Double product function
105 * @code{DREAL}: DREAL, Double real part function
106 * @code{DSHIFTL}: DSHIFTL, Combined left shift
107 * @code{DSHIFTR}: DSHIFTR, Combined right shift
108 * @code{DTIME}: DTIME, Execution time subroutine (or function)
109 * @code{EOSHIFT}: EOSHIFT, End-off shift elements of an array
110 * @code{EPSILON}: EPSILON, Epsilon function
111 * @code{ERF}: ERF, Error function
112 * @code{ERFC}: ERFC, Complementary error function
113 * @code{ERFC_SCALED}: ERFC_SCALED, Exponentially-scaled complementary error function
114 * @code{ETIME}: ETIME, Execution time subroutine (or function)
115 * @code{EXECUTE_COMMAND_LINE}: EXECUTE_COMMAND_LINE, Execute a shell command
116 * @code{EXIT}: EXIT, Exit the program with status.
117 * @code{EXP}: EXP, Exponential function
118 * @code{EXPONENT}: EXPONENT, Exponent function
119 * @code{EXTENDS_TYPE_OF}: EXTENDS_TYPE_OF, Query dynamic type for extension
120 * @code{FDATE}: FDATE, Subroutine (or function) to get the current time as a string
121 * @code{FGET}: FGET, Read a single character in stream mode from stdin
122 * @code{FGETC}: FGETC, Read a single character in stream mode
123 * @code{FLOOR}: FLOOR, Integer floor function
124 * @code{FLUSH}: FLUSH, Flush I/O unit(s)
125 * @code{FNUM}: FNUM, File number function
126 * @code{FPUT}: FPUT, Write a single character in stream mode to stdout
127 * @code{FPUTC}: FPUTC, Write a single character in stream mode
128 * @code{FRACTION}: FRACTION, Fractional part of the model representation
129 * @code{FREE}: FREE, Memory de-allocation subroutine
130 * @code{FSEEK}: FSEEK, Low level file positioning subroutine
131 * @code{FSTAT}: FSTAT, Get file status
132 * @code{FTELL}: FTELL, Current stream position
133 * @code{GAMMA}: GAMMA, Gamma function
134 * @code{GERROR}: GERROR, Get last system error message
135 * @code{GETARG}: GETARG, Get command line arguments
136 * @code{GET_COMMAND}: GET_COMMAND, Get the entire command line
137 * @code{GET_COMMAND_ARGUMENT}: GET_COMMAND_ARGUMENT, Get command line arguments
138 * @code{GETCWD}: GETCWD, Get current working directory
139 * @code{GETENV}: GETENV, Get an environmental variable
140 * @code{GET_ENVIRONMENT_VARIABLE}: GET_ENVIRONMENT_VARIABLE, Get an environmental variable
141 * @code{GETGID}: GETGID, Group ID function
142 * @code{GETLOG}: GETLOG, Get login name
143 * @code{GETPID}: GETPID, Process ID function
144 * @code{GETUID}: GETUID, User ID function
145 * @code{GMTIME}: GMTIME, Convert time to GMT info
146 * @code{HOSTNM}: HOSTNM, Get system host name
147 * @code{HUGE}: HUGE, Largest number of a kind
148 * @code{HYPOT}: HYPOT, Euclidean distance function
149 * @code{IACHAR}: IACHAR, Code in @acronym{ASCII} collating sequence
150 * @code{IALL}: IALL, Bitwise AND of array elements
151 * @code{IAND}: IAND, Bitwise logical and
152 * @code{IANY}: IANY, Bitwise OR of array elements
153 * @code{IARGC}: IARGC, Get the number of command line arguments
154 * @code{IBCLR}: IBCLR, Clear bit
155 * @code{IBITS}: IBITS, Bit extraction
156 * @code{IBSET}: IBSET, Set bit
157 * @code{ICHAR}: ICHAR, Character-to-integer conversion function
158 * @code{IDATE}: IDATE, Current local time (day/month/year)
159 * @code{IEOR}: IEOR, Bitwise logical exclusive or
160 * @code{IERRNO}: IERRNO, Function to get the last system error number
161 * @code{IMAGE_INDEX}: IMAGE_INDEX, Cosubscript to image index conversion
162 * @code{INDEX}: INDEX intrinsic, Position of a substring within a string
163 * @code{INT}: INT, Convert to integer type
164 * @code{INT2}: INT2, Convert to 16-bit integer type
165 * @code{INT8}: INT8, Convert to 64-bit integer type
166 * @code{IOR}: IOR, Bitwise logical or
167 * @code{IPARITY}: IPARITY, Bitwise XOR of array elements
168 * @code{IRAND}: IRAND, Integer pseudo-random number
169 * @code{IS_IOSTAT_END}: IS_IOSTAT_END, Test for end-of-file value
170 * @code{IS_IOSTAT_EOR}: IS_IOSTAT_EOR, Test for end-of-record value
171 * @code{ISATTY}: ISATTY, Whether a unit is a terminal device
172 * @code{ISHFT}: ISHFT, Shift bits
173 * @code{ISHFTC}: ISHFTC, Shift bits circularly
174 * @code{ISNAN}: ISNAN, Tests for a NaN
175 * @code{ITIME}: ITIME, Current local time (hour/minutes/seconds)
176 * @code{KILL}: KILL, Send a signal to a process
177 * @code{KIND}: KIND, Kind of an entity
178 * @code{LBOUND}: LBOUND, Lower dimension bounds of an array
179 * @code{LCOBOUND}: LCOBOUND, Lower codimension bounds of an array
180 * @code{LEADZ}: LEADZ, Number of leading zero bits of an integer
181 * @code{LEN}: LEN, Length of a character entity
182 * @code{LEN_TRIM}: LEN_TRIM, Length of a character entity without trailing blank characters
183 * @code{LGE}: LGE, Lexical greater than or equal
184 * @code{LGT}: LGT, Lexical greater than
185 * @code{LINK}: LINK, Create a hard link
186 * @code{LLE}: LLE, Lexical less than or equal
187 * @code{LLT}: LLT, Lexical less than
188 * @code{LNBLNK}: LNBLNK, Index of the last non-blank character in a string
189 * @code{LOC}: LOC, Returns the address of a variable
190 * @code{LOG}: LOG, Logarithm function
191 * @code{LOG10}: LOG10, Base 10 logarithm function
192 * @code{LOG_GAMMA}: LOG_GAMMA, Logarithm of the Gamma function
193 * @code{LOGICAL}: LOGICAL, Convert to logical type
194 * @code{LONG}: LONG, Convert to integer type
195 * @code{LSHIFT}: LSHIFT, Left shift bits
196 * @code{LSTAT}: LSTAT, Get file status
197 * @code{LTIME}: LTIME, Convert time to local time info
198 * @code{MALLOC}: MALLOC, Dynamic memory allocation function
199 * @code{MASKL}: MASKL, Left justified mask
200 * @code{MASKR}: MASKR, Right justified mask
201 * @code{MATMUL}: MATMUL, matrix multiplication
202 * @code{MAX}: MAX, Maximum value of an argument list
203 * @code{MAXEXPONENT}: MAXEXPONENT, Maximum exponent of a real kind
204 * @code{MAXLOC}: MAXLOC, Location of the maximum value within an array
205 * @code{MAXVAL}: MAXVAL, Maximum value of an array
206 * @code{MCLOCK}: MCLOCK, Time function
207 * @code{MCLOCK8}: MCLOCK8, Time function (64-bit)
208 * @code{MERGE}: MERGE, Merge arrays
209 * @code{MERGE_BITS}: MERGE_BITS, Merge of bits under mask
210 * @code{MIN}: MIN, Minimum value of an argument list
211 * @code{MINEXPONENT}: MINEXPONENT, Minimum exponent of a real kind
212 * @code{MINLOC}: MINLOC, Location of the minimum value within an array
213 * @code{MINVAL}: MINVAL, Minimum value of an array
214 * @code{MOD}: MOD, Remainder function
215 * @code{MODULO}: MODULO, Modulo function
216 * @code{MOVE_ALLOC}: MOVE_ALLOC, Move allocation from one object to another
217 * @code{MVBITS}: MVBITS, Move bits from one integer to another
218 * @code{NEAREST}: NEAREST, Nearest representable number
219 * @code{NEW_LINE}: NEW_LINE, New line character
220 * @code{NINT}: NINT, Nearest whole number
221 * @code{NORM2}: NORM2, Euclidean vector norm
222 * @code{NOT}: NOT, Logical negation
223 * @code{NULL}: NULL, Function that returns an disassociated pointer
224 * @code{NUM_IMAGES}: NUM_IMAGES, Number of images
225 * @code{OR}: OR, Bitwise logical OR
226 * @code{PACK}: PACK, Pack an array into an array of rank one
227 * @code{PARITY}: PARITY, Reduction with exclusive OR
228 * @code{PERROR}: PERROR, Print system error message
229 * @code{POPCNT}: POPCNT, Number of bits set
230 * @code{POPPAR}: POPPAR, Parity of the number of bits set
231 * @code{PRECISION}: PRECISION, Decimal precision of a real kind
232 * @code{PRESENT}: PRESENT, Determine whether an optional dummy argument is specified
233 * @code{PRODUCT}: PRODUCT, Product of array elements
234 * @code{RADIX}: RADIX, Base of a data model
235 * @code{RANDOM_NUMBER}: RANDOM_NUMBER, Pseudo-random number
236 * @code{RANDOM_SEED}: RANDOM_SEED, Initialize a pseudo-random number sequence
237 * @code{RAND}: RAND, Real pseudo-random number
238 * @code{RANGE}: RANGE, Decimal exponent range
239 * @code{RAN}: RAN, Real pseudo-random number
240 * @code{REAL}: REAL, Convert to real type
241 * @code{RENAME}: RENAME, Rename a file
242 * @code{REPEAT}: REPEAT, Repeated string concatenation
243 * @code{RESHAPE}: RESHAPE, Function to reshape an array
244 * @code{RRSPACING}: RRSPACING, Reciprocal of the relative spacing
245 * @code{RSHIFT}: RSHIFT, Right shift bits
246 * @code{SAME_TYPE_AS}: SAME_TYPE_AS, Query dynamic types for equality
247 * @code{SCALE}: SCALE, Scale a real value
248 * @code{SCAN}: SCAN, Scan a string for the presence of a set of characters
249 * @code{SECNDS}: SECNDS, Time function
250 * @code{SECOND}: SECOND, CPU time function
251 * @code{SELECTED_CHAR_KIND}: SELECTED_CHAR_KIND, Choose character kind
252 * @code{SELECTED_INT_KIND}: SELECTED_INT_KIND, Choose integer kind
253 * @code{SELECTED_REAL_KIND}: SELECTED_REAL_KIND, Choose real kind
254 * @code{SET_EXPONENT}: SET_EXPONENT, Set the exponent of the model
255 * @code{SHAPE}: SHAPE, Determine the shape of an array
256 * @code{SHIFTA}: SHIFTA, Right shift with fill
257 * @code{SHIFTL}: SHIFTL, Left shift
258 * @code{SHIFTR}: SHIFTR, Right shift
259 * @code{SIGN}: SIGN, Sign copying function
260 * @code{SIGNAL}: SIGNAL, Signal handling subroutine (or function)
261 * @code{SIN}: SIN, Sine function
262 * @code{SINH}: SINH, Hyperbolic sine function
263 * @code{SIZE}: SIZE, Function to determine the size of an array
264 * @code{SIZEOF}: SIZEOF, Determine the size in bytes of an expression
265 * @code{SLEEP}: SLEEP, Sleep for the specified number of seconds
266 * @code{SPACING}: SPACING, Smallest distance between two numbers of a given type
267 * @code{SPREAD}: SPREAD, Add a dimension to an array
268 * @code{SQRT}: SQRT, Square-root function
269 * @code{SRAND}: SRAND, Reinitialize the random number generator
270 * @code{STAT}: STAT, Get file status
271 * @code{STORAGE_SIZE}: STORAGE_SIZE, Storage size in bits
272 * @code{SUM}: SUM, Sum of array elements
273 * @code{SYMLNK}: SYMLNK, Create a symbolic link
274 * @code{SYSTEM}: SYSTEM, Execute a shell command
275 * @code{SYSTEM_CLOCK}: SYSTEM_CLOCK, Time function
276 * @code{TAN}: TAN, Tangent function
277 * @code{TANH}: TANH, Hyperbolic tangent function
278 * @code{THIS_IMAGE}: THIS_IMAGE, Cosubscript index of this image
279 * @code{TIME}: TIME, Time function
280 * @code{TIME8}: TIME8, Time function (64-bit)
281 * @code{TINY}: TINY, Smallest positive number of a real kind
282 * @code{TRAILZ}: TRAILZ, Number of trailing zero bits of an integer
283 * @code{TRANSFER}: TRANSFER, Transfer bit patterns
284 * @code{TRANSPOSE}: TRANSPOSE, Transpose an array of rank two
285 * @code{TRIM}: TRIM, Remove trailing blank characters of a string
286 * @code{TTYNAM}: TTYNAM, Get the name of a terminal device.
287 * @code{UBOUND}: UBOUND, Upper dimension bounds of an array
288 * @code{UCOBOUND}: UCOBOUND, Upper codimension bounds of an array
289 * @code{UMASK}: UMASK, Set the file creation mask
290 * @code{UNLINK}: UNLINK, Remove a file from the file system
291 * @code{UNPACK}: UNPACK, Unpack an array of rank one into an array
292 * @code{VERIFY}: VERIFY, Scan a string for the absence of a set of characters
293 * @code{XOR}: XOR, Bitwise logical exclusive or
296 @node Introduction to Intrinsics
297 @section Introduction to intrinsic procedures
299 The intrinsic procedures provided by GNU Fortran include all of the
300 intrinsic procedures required by the Fortran 95 standard, a set of
301 intrinsic procedures for backwards compatibility with G77, and a
302 selection of intrinsic procedures from the Fortran 2003 and Fortran 2008
303 standards. Any conflict between a description here and a description in
304 either the Fortran 95 standard, the Fortran 2003 standard or the Fortran
305 2008 standard is unintentional, and the standard(s) should be considered
308 The enumeration of the @code{KIND} type parameter is processor defined in
309 the Fortran 95 standard. GNU Fortran defines the default integer type and
310 default real type by @code{INTEGER(KIND=4)} and @code{REAL(KIND=4)},
311 respectively. The standard mandates that both data types shall have
312 another kind, which have more precision. On typical target architectures
313 supported by @command{gfortran}, this kind type parameter is @code{KIND=8}.
314 Hence, @code{REAL(KIND=8)} and @code{DOUBLE PRECISION} are equivalent.
315 In the description of generic intrinsic procedures, the kind type parameter
316 will be specified by @code{KIND=*}, and in the description of specific
317 names for an intrinsic procedure the kind type parameter will be explicitly
318 given (e.g., @code{REAL(KIND=4)} or @code{REAL(KIND=8)}). Finally, for
319 brevity the optional @code{KIND=} syntax will be omitted.
321 Many of the intrinsic procedures take one or more optional arguments.
322 This document follows the convention used in the Fortran 95 standard,
323 and denotes such arguments by square brackets.
325 GNU Fortran offers the @option{-std=f95} and @option{-std=gnu} options,
326 which can be used to restrict the set of intrinsic procedures to a
327 given standard. By default, @command{gfortran} sets the @option{-std=gnu}
328 option, and so all intrinsic procedures described here are accepted. There
329 is one caveat. For a select group of intrinsic procedures, @command{g77}
330 implemented both a function and a subroutine. Both classes
331 have been implemented in @command{gfortran} for backwards compatibility
332 with @command{g77}. It is noted here that these functions and subroutines
333 cannot be intermixed in a given subprogram. In the descriptions that follow,
334 the applicable standard for each intrinsic procedure is noted.
339 @section @code{ABORT} --- Abort the program
341 @cindex program termination, with core dump
342 @cindex terminate program, with core dump
346 @item @emph{Description}:
347 @code{ABORT} causes immediate termination of the program. On operating
348 systems that support a core dump, @code{ABORT} will produce a core dump even if
349 the option @option{-fno-dump-core} is in effect, which is suitable for debugging
351 @c TODO: Check if this (with -fno-dump-core) is correct.
353 @item @emph{Standard}:
362 @item @emph{Return value}:
365 @item @emph{Example}:
368 integer :: i = 1, j = 2
369 if (i /= j) call abort
370 end program test_abort
373 @item @emph{See also}:
374 @ref{EXIT}, @ref{KILL}
381 @section @code{ABS} --- Absolute value
388 @cindex absolute value
391 @item @emph{Description}:
392 @code{ABS(A)} computes the absolute value of @code{A}.
394 @item @emph{Standard}:
395 Fortran 77 and later, has overloads that are GNU extensions
401 @code{RESULT = ABS(A)}
403 @item @emph{Arguments}:
404 @multitable @columnfractions .15 .70
405 @item @var{A} @tab The type of the argument shall be an @code{INTEGER},
406 @code{REAL}, or @code{COMPLEX}.
409 @item @emph{Return value}:
410 The return value is of the same type and
411 kind as the argument except the return value is @code{REAL} for a
412 @code{COMPLEX} argument.
414 @item @emph{Example}:
419 complex :: z = (-1.e0,0.e0)
426 @item @emph{Specific names}:
427 @multitable @columnfractions .20 .20 .20 .25
428 @item Name @tab Argument @tab Return type @tab Standard
429 @item @code{ABS(A)} @tab @code{REAL(4) A} @tab @code{REAL(4)} @tab Fortran 77 and later
430 @item @code{CABS(A)} @tab @code{COMPLEX(4) A} @tab @code{REAL(4)} @tab Fortran 77 and later
431 @item @code{DABS(A)} @tab @code{REAL(8) A} @tab @code{REAL(8)} @tab Fortran 77 and later
432 @item @code{IABS(A)} @tab @code{INTEGER(4) A} @tab @code{INTEGER(4)} @tab Fortran 77 and later
433 @item @code{ZABS(A)} @tab @code{COMPLEX(8) A} @tab @code{COMPLEX(8)} @tab GNU extension
434 @item @code{CDABS(A)} @tab @code{COMPLEX(8) A} @tab @code{COMPLEX(8)} @tab GNU extension
441 @section @code{ACCESS} --- Checks file access modes
443 @cindex file system, access mode
446 @item @emph{Description}:
447 @code{ACCESS(NAME, MODE)} checks whether the file @var{NAME}
448 exists, is readable, writable or executable. Except for the
449 executable check, @code{ACCESS} can be replaced by
450 Fortran 95's @code{INQUIRE}.
452 @item @emph{Standard}:
459 @code{RESULT = ACCESS(NAME, MODE)}
461 @item @emph{Arguments}:
462 @multitable @columnfractions .15 .70
463 @item @var{NAME} @tab Scalar @code{CHARACTER} of default kind with the
464 file name. Tailing blank are ignored unless the character @code{achar(0)}
465 is present, then all characters up to and excluding @code{achar(0)} are
467 @item @var{MODE} @tab Scalar @code{CHARACTER} of default kind with the
468 file access mode, may be any concatenation of @code{"r"} (readable),
469 @code{"w"} (writable) and @code{"x"} (executable), or @code{" "} to check
473 @item @emph{Return value}:
474 Returns a scalar @code{INTEGER}, which is @code{0} if the file is
475 accessible in the given mode; otherwise or if an invalid argument
476 has been given for @code{MODE} the value @code{1} is returned.
478 @item @emph{Example}:
482 character(len=*), parameter :: file = 'test.dat'
483 character(len=*), parameter :: file2 = 'test.dat '//achar(0)
484 if(access(file,' ') == 0) print *, trim(file),' is exists'
485 if(access(file,'r') == 0) print *, trim(file),' is readable'
486 if(access(file,'w') == 0) print *, trim(file),' is writable'
487 if(access(file,'x') == 0) print *, trim(file),' is executable'
488 if(access(file2,'rwx') == 0) &
489 print *, trim(file2),' is readable, writable and executable'
490 end program access_test
492 @item @emph{Specific names}:
493 @item @emph{See also}:
500 @section @code{ACHAR} --- Character in @acronym{ASCII} collating sequence
502 @cindex @acronym{ASCII} collating sequence
503 @cindex collating sequence, @acronym{ASCII}
506 @item @emph{Description}:
507 @code{ACHAR(I)} returns the character located at position @code{I}
508 in the @acronym{ASCII} collating sequence.
510 @item @emph{Standard}:
511 Fortran 77 and later, with @var{KIND} argument Fortran 2003 and later
517 @code{RESULT = ACHAR(I [, KIND])}
519 @item @emph{Arguments}:
520 @multitable @columnfractions .15 .70
521 @item @var{I} @tab The type shall be @code{INTEGER}.
522 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
523 expression indicating the kind parameter of the result.
526 @item @emph{Return value}:
527 The return value is of type @code{CHARACTER} with a length of one.
528 If the @var{KIND} argument is present, the return value is of the
529 specified kind and of the default kind otherwise.
531 @item @emph{Example}:
536 end program test_achar
540 See @ref{ICHAR} for a discussion of converting between numerical values
541 and formatted string representations.
543 @item @emph{See also}:
544 @ref{CHAR}, @ref{IACHAR}, @ref{ICHAR}
551 @section @code{ACOS} --- Arccosine function
554 @cindex trigonometric function, cosine, inverse
555 @cindex cosine, inverse
558 @item @emph{Description}:
559 @code{ACOS(X)} computes the arccosine of @var{X} (inverse of @code{COS(X)}).
561 @item @emph{Standard}:
562 Fortran 77 and later, for a complex argument Fortran 2008 or later
568 @code{RESULT = ACOS(X)}
570 @item @emph{Arguments}:
571 @multitable @columnfractions .15 .70
572 @item @var{X} @tab The type shall either be @code{REAL} with a magnitude that is
573 less than or equal to one - or the type shall be @code{COMPLEX}.
576 @item @emph{Return value}:
577 The return value is of the same type and kind as @var{X}.
578 The real part of the result is in radians and lies in the range
579 @math{0 \leq \Re \acos(x) \leq \pi}.
581 @item @emph{Example}:
584 real(8) :: x = 0.866_8
586 end program test_acos
589 @item @emph{Specific names}:
590 @multitable @columnfractions .20 .20 .20 .25
591 @item Name @tab Argument @tab Return type @tab Standard
592 @item @code{ACOS(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
593 @item @code{DACOS(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
596 @item @emph{See also}:
597 Inverse function: @ref{COS}
604 @section @code{ACOSH} --- Inverse hyperbolic cosine function
607 @cindex area hyperbolic cosine
608 @cindex inverse hyperbolic cosine
609 @cindex hyperbolic function, cosine, inverse
610 @cindex cosine, hyperbolic, inverse
613 @item @emph{Description}:
614 @code{ACOSH(X)} computes the inverse hyperbolic cosine of @var{X}.
616 @item @emph{Standard}:
617 Fortran 2008 and later
623 @code{RESULT = ACOSH(X)}
625 @item @emph{Arguments}:
626 @multitable @columnfractions .15 .70
627 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
630 @item @emph{Return value}:
631 The return value has the same type and kind as @var{X}. If @var{X} is
632 complex, the imaginary part of the result is in radians and lies between
633 @math{ 0 \leq \Im \acosh(x) \leq \pi}.
635 @item @emph{Example}:
638 REAL(8), DIMENSION(3) :: x = (/ 1.0, 2.0, 3.0 /)
643 @item @emph{Specific names}:
644 @multitable @columnfractions .20 .20 .20 .25
645 @item Name @tab Argument @tab Return type @tab Standard
646 @item @code{DACOSH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
649 @item @emph{See also}:
650 Inverse function: @ref{COSH}
656 @section @code{ADJUSTL} --- Left adjust a string
658 @cindex string, adjust left
659 @cindex adjust string
662 @item @emph{Description}:
663 @code{ADJUSTL(STRING)} will left adjust a string by removing leading spaces.
664 Spaces are inserted at the end of the string as needed.
666 @item @emph{Standard}:
673 @code{RESULT = ADJUSTL(STRING)}
675 @item @emph{Arguments}:
676 @multitable @columnfractions .15 .70
677 @item @var{STRING} @tab The type shall be @code{CHARACTER}.
680 @item @emph{Return value}:
681 The return value is of type @code{CHARACTER} and of the same kind as
682 @var{STRING} where leading spaces are removed and the same number of
683 spaces are inserted on the end of @var{STRING}.
685 @item @emph{Example}:
688 character(len=20) :: str = ' gfortran'
691 end program test_adjustl
694 @item @emph{See also}:
695 @ref{ADJUSTR}, @ref{TRIM}
701 @section @code{ADJUSTR} --- Right adjust a string
703 @cindex string, adjust right
704 @cindex adjust string
707 @item @emph{Description}:
708 @code{ADJUSTR(STRING)} will right adjust a string by removing trailing spaces.
709 Spaces are inserted at the start of the string as needed.
711 @item @emph{Standard}:
718 @code{RESULT = ADJUSTR(STRING)}
720 @item @emph{Arguments}:
721 @multitable @columnfractions .15 .70
722 @item @var{STR} @tab The type shall be @code{CHARACTER}.
725 @item @emph{Return value}:
726 The return value is of type @code{CHARACTER} and of the same kind as
727 @var{STRING} where trailing spaces are removed and the same number of
728 spaces are inserted at the start of @var{STRING}.
730 @item @emph{Example}:
733 character(len=20) :: str = 'gfortran'
736 end program test_adjustr
739 @item @emph{See also}:
740 @ref{ADJUSTL}, @ref{TRIM}
746 @section @code{AIMAG} --- Imaginary part of complex number
751 @cindex complex numbers, imaginary part
754 @item @emph{Description}:
755 @code{AIMAG(Z)} yields the imaginary part of complex argument @code{Z}.
756 The @code{IMAG(Z)} and @code{IMAGPART(Z)} intrinsic functions are provided
757 for compatibility with @command{g77}, and their use in new code is
758 strongly discouraged.
760 @item @emph{Standard}:
761 Fortran 77 and later, has overloads that are GNU extensions
767 @code{RESULT = AIMAG(Z)}
769 @item @emph{Arguments}:
770 @multitable @columnfractions .15 .70
771 @item @var{Z} @tab The type of the argument shall be @code{COMPLEX}.
774 @item @emph{Return value}:
775 The return value is of type @code{REAL} with the
776 kind type parameter of the argument.
778 @item @emph{Example}:
783 z4 = cmplx(1.e0_4, 0.e0_4)
784 z8 = cmplx(0.e0_8, 1.e0_8)
785 print *, aimag(z4), dimag(z8)
786 end program test_aimag
789 @item @emph{Specific names}:
790 @multitable @columnfractions .20 .20 .20 .25
791 @item Name @tab Argument @tab Return type @tab Standard
792 @item @code{AIMAG(Z)} @tab @code{COMPLEX Z} @tab @code{REAL} @tab GNU extension
793 @item @code{DIMAG(Z)} @tab @code{COMPLEX(8) Z} @tab @code{REAL(8)} @tab GNU extension
794 @item @code{IMAG(Z)} @tab @code{COMPLEX Z} @tab @code{REAL} @tab GNU extension
795 @item @code{IMAGPART(Z)} @tab @code{COMPLEX Z} @tab @code{REAL} @tab GNU extension
802 @section @code{AINT} --- Truncate to a whole number
806 @cindex rounding, floor
809 @item @emph{Description}:
810 @code{AINT(A [, KIND])} truncates its argument to a whole number.
812 @item @emph{Standard}:
819 @code{RESULT = AINT(A [, KIND])}
821 @item @emph{Arguments}:
822 @multitable @columnfractions .15 .70
823 @item @var{A} @tab The type of the argument shall be @code{REAL}.
824 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
825 expression indicating the kind parameter of the result.
828 @item @emph{Return value}:
829 The return value is of type @code{REAL} with the kind type parameter of the
830 argument if the optional @var{KIND} is absent; otherwise, the kind
831 type parameter will be given by @var{KIND}. If the magnitude of
832 @var{X} is less than one, @code{AINT(X)} returns zero. If the
833 magnitude is equal to or greater than one then it returns the largest
834 whole number that does not exceed its magnitude. The sign is the same
835 as the sign of @var{X}.
837 @item @emph{Example}:
844 print *, aint(x4), dint(x8)
846 end program test_aint
849 @item @emph{Specific names}:
850 @multitable @columnfractions .20 .20 .20 .25
851 @item Name @tab Argument @tab Return type @tab Standard
852 @item @code{AINT(A)} @tab @code{REAL(4) A} @tab @code{REAL(4)} @tab Fortran 77 and later
853 @item @code{DINT(A)} @tab @code{REAL(8) A} @tab @code{REAL(8)} @tab Fortran 77 and later
860 @section @code{ALARM} --- Execute a routine after a given delay
862 @cindex delayed execution
865 @item @emph{Description}:
866 @code{ALARM(SECONDS, HANDLER [, STATUS])} causes external subroutine @var{HANDLER}
867 to be executed after a delay of @var{SECONDS} by using @code{alarm(2)} to
868 set up a signal and @code{signal(2)} to catch it. If @var{STATUS} is
869 supplied, it will be returned with the number of seconds remaining until
870 any previously scheduled alarm was due to be delivered, or zero if there
871 was no previously scheduled alarm.
873 @item @emph{Standard}:
880 @code{CALL ALARM(SECONDS, HANDLER [, STATUS])}
882 @item @emph{Arguments}:
883 @multitable @columnfractions .15 .70
884 @item @var{SECONDS} @tab The type of the argument shall be a scalar
885 @code{INTEGER}. It is @code{INTENT(IN)}.
886 @item @var{HANDLER} @tab Signal handler (@code{INTEGER FUNCTION} or
887 @code{SUBROUTINE}) or dummy/global @code{INTEGER} scalar. The scalar
888 values may be either @code{SIG_IGN=1} to ignore the alarm generated
889 or @code{SIG_DFL=0} to set the default action. It is @code{INTENT(IN)}.
890 @item @var{STATUS} @tab (Optional) @var{STATUS} shall be a scalar
891 variable of the default @code{INTEGER} kind. It is @code{INTENT(OUT)}.
894 @item @emph{Example}:
897 external handler_print
899 call alarm (3, handler_print, i)
902 end program test_alarm
904 This will cause the external routine @var{handler_print} to be called
911 @section @code{ALL} --- All values in @var{MASK} along @var{DIM} are true
913 @cindex array, apply condition
914 @cindex array, condition testing
917 @item @emph{Description}:
918 @code{ALL(MASK [, DIM])} determines if all the values are true in @var{MASK}
919 in the array along dimension @var{DIM}.
921 @item @emph{Standard}:
925 Transformational function
928 @code{RESULT = ALL(MASK [, DIM])}
930 @item @emph{Arguments}:
931 @multitable @columnfractions .15 .70
932 @item @var{MASK} @tab The type of the argument shall be @code{LOGICAL} and
933 it shall not be scalar.
934 @item @var{DIM} @tab (Optional) @var{DIM} shall be a scalar integer
935 with a value that lies between one and the rank of @var{MASK}.
938 @item @emph{Return value}:
939 @code{ALL(MASK)} returns a scalar value of type @code{LOGICAL} where
940 the kind type parameter is the same as the kind type parameter of
941 @var{MASK}. If @var{DIM} is present, then @code{ALL(MASK, DIM)} returns
942 an array with the rank of @var{MASK} minus 1. The shape is determined from
943 the shape of @var{MASK} where the @var{DIM} dimension is elided.
947 @code{ALL(MASK)} is true if all elements of @var{MASK} are true.
948 It also is true if @var{MASK} has zero size; otherwise, it is false.
950 If the rank of @var{MASK} is one, then @code{ALL(MASK,DIM)} is equivalent
951 to @code{ALL(MASK)}. If the rank is greater than one, then @code{ALL(MASK,DIM)}
952 is determined by applying @code{ALL} to the array sections.
955 @item @emph{Example}:
959 l = all((/.true., .true., .true./))
964 integer a(2,3), b(2,3)
968 print *, all(a .eq. b, 1)
969 print *, all(a .eq. b, 2)
970 end subroutine section
978 @section @code{ALLOCATED} --- Status of an allocatable entity
980 @cindex allocation, status
983 @item @emph{Description}:
984 @code{ALLOCATED(ARRAY)} and @code{ALLOCATED(SCALAR)} check the allocation
985 status of @var{ARRAY} and @var{SCALAR}, respectively.
987 @item @emph{Standard}:
988 Fortran 95 and later. Note, the @code{SCALAR=} keyword and allocatable
989 scalar entities are available in Fortran 2003 and later.
995 @multitable @columnfractions .80
996 @item @code{RESULT = ALLOCATED(ARRAY)}
997 @item @code{RESULT = ALLOCATED(SCALAR)}
1000 @item @emph{Arguments}:
1001 @multitable @columnfractions .15 .70
1002 @item @var{ARRAY} @tab The argument shall be an @code{ALLOCATABLE} array.
1003 @item @var{SCALAR} @tab The argument shall be an @code{ALLOCATABLE} scalar.
1006 @item @emph{Return value}:
1007 The return value is a scalar @code{LOGICAL} with the default logical
1008 kind type parameter. If the argument is allocated, then the result is
1009 @code{.TRUE.}; otherwise, it returns @code{.FALSE.}
1011 @item @emph{Example}:
1013 program test_allocated
1015 real(4), allocatable :: x(:)
1016 if (.not. allocated(x)) allocate(x(i))
1017 end program test_allocated
1024 @section @code{AND} --- Bitwise logical AND
1026 @cindex bitwise logical and
1027 @cindex logical and, bitwise
1030 @item @emph{Description}:
1031 Bitwise logical @code{AND}.
1033 This intrinsic routine is provided for backwards compatibility with
1034 GNU Fortran 77. For integer arguments, programmers should consider
1035 the use of the @ref{IAND} intrinsic defined by the Fortran standard.
1037 @item @emph{Standard}:
1043 @item @emph{Syntax}:
1044 @code{RESULT = AND(I, J)}
1046 @item @emph{Arguments}:
1047 @multitable @columnfractions .15 .70
1048 @item @var{I} @tab The type shall be either a scalar @code{INTEGER}
1049 type or a scalar @code{LOGICAL} type.
1050 @item @var{J} @tab The type shall be the same as the type of @var{I}.
1053 @item @emph{Return value}:
1054 The return type is either a scalar @code{INTEGER} or a scalar
1055 @code{LOGICAL}. If the kind type parameters differ, then the
1056 smaller kind type is implicitly converted to larger kind, and the
1057 return has the larger kind.
1059 @item @emph{Example}:
1062 LOGICAL :: T = .TRUE., F = .FALSE.
1064 DATA a / Z'F' /, b / Z'3' /
1066 WRITE (*,*) AND(T, T), AND(T, F), AND(F, T), AND(F, F)
1067 WRITE (*,*) AND(a, b)
1071 @item @emph{See also}:
1072 Fortran 95 elemental function: @ref{IAND}
1078 @section @code{ANINT} --- Nearest whole number
1082 @cindex rounding, ceiling
1085 @item @emph{Description}:
1086 @code{ANINT(A [, KIND])} rounds its argument to the nearest whole number.
1088 @item @emph{Standard}:
1089 Fortran 77 and later
1094 @item @emph{Syntax}:
1095 @code{RESULT = ANINT(A [, KIND])}
1097 @item @emph{Arguments}:
1098 @multitable @columnfractions .15 .70
1099 @item @var{A} @tab The type of the argument shall be @code{REAL}.
1100 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
1101 expression indicating the kind parameter of the result.
1104 @item @emph{Return value}:
1105 The return value is of type real with the kind type parameter of the
1106 argument if the optional @var{KIND} is absent; otherwise, the kind
1107 type parameter will be given by @var{KIND}. If @var{A} is greater than
1108 zero, @code{ANINT(A)} returns @code{AINT(X+0.5)}. If @var{A} is
1109 less than or equal to zero then it returns @code{AINT(X-0.5)}.
1111 @item @emph{Example}:
1118 print *, anint(x4), dnint(x8)
1120 end program test_anint
1123 @item @emph{Specific names}:
1124 @multitable @columnfractions .20 .20 .20 .25
1125 @item Name @tab Argument @tab Return type @tab Standard
1126 @item @code{AINT(A)} @tab @code{REAL(4) A} @tab @code{REAL(4)} @tab Fortran 77 and later
1127 @item @code{DNINT(A)} @tab @code{REAL(8) A} @tab @code{REAL(8)} @tab Fortran 77 and later
1134 @section @code{ANY} --- Any value in @var{MASK} along @var{DIM} is true
1136 @cindex array, apply condition
1137 @cindex array, condition testing
1140 @item @emph{Description}:
1141 @code{ANY(MASK [, DIM])} determines if any of the values in the logical array
1142 @var{MASK} along dimension @var{DIM} are @code{.TRUE.}.
1144 @item @emph{Standard}:
1145 Fortran 95 and later
1148 Transformational function
1150 @item @emph{Syntax}:
1151 @code{RESULT = ANY(MASK [, DIM])}
1153 @item @emph{Arguments}:
1154 @multitable @columnfractions .15 .70
1155 @item @var{MASK} @tab The type of the argument shall be @code{LOGICAL} and
1156 it shall not be scalar.
1157 @item @var{DIM} @tab (Optional) @var{DIM} shall be a scalar integer
1158 with a value that lies between one and the rank of @var{MASK}.
1161 @item @emph{Return value}:
1162 @code{ANY(MASK)} returns a scalar value of type @code{LOGICAL} where
1163 the kind type parameter is the same as the kind type parameter of
1164 @var{MASK}. If @var{DIM} is present, then @code{ANY(MASK, DIM)} returns
1165 an array with the rank of @var{MASK} minus 1. The shape is determined from
1166 the shape of @var{MASK} where the @var{DIM} dimension is elided.
1170 @code{ANY(MASK)} is true if any element of @var{MASK} is true;
1171 otherwise, it is false. It also is false if @var{MASK} has zero size.
1173 If the rank of @var{MASK} is one, then @code{ANY(MASK,DIM)} is equivalent
1174 to @code{ANY(MASK)}. If the rank is greater than one, then @code{ANY(MASK,DIM)}
1175 is determined by applying @code{ANY} to the array sections.
1178 @item @emph{Example}:
1182 l = any((/.true., .true., .true./))
1187 integer a(2,3), b(2,3)
1191 print *, any(a .eq. b, 1)
1192 print *, any(a .eq. b, 2)
1193 end subroutine section
1194 end program test_any
1201 @section @code{ASIN} --- Arcsine function
1204 @cindex trigonometric function, sine, inverse
1205 @cindex sine, inverse
1208 @item @emph{Description}:
1209 @code{ASIN(X)} computes the arcsine of its @var{X} (inverse of @code{SIN(X)}).
1211 @item @emph{Standard}:
1212 Fortran 77 and later, for a complex argument Fortran 2008 or later
1217 @item @emph{Syntax}:
1218 @code{RESULT = ASIN(X)}
1220 @item @emph{Arguments}:
1221 @multitable @columnfractions .15 .70
1222 @item @var{X} @tab The type shall be either @code{REAL} and a magnitude that is
1223 less than or equal to one - or be @code{COMPLEX}.
1226 @item @emph{Return value}:
1227 The return value is of the same type and kind as @var{X}.
1228 The real part of the result is in radians and lies in the range
1229 @math{-\pi/2 \leq \Re \asin(x) \leq \pi/2}.
1231 @item @emph{Example}:
1234 real(8) :: x = 0.866_8
1236 end program test_asin
1239 @item @emph{Specific names}:
1240 @multitable @columnfractions .20 .20 .20 .25
1241 @item Name @tab Argument @tab Return type @tab Standard
1242 @item @code{ASIN(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
1243 @item @code{DASIN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
1246 @item @emph{See also}:
1247 Inverse function: @ref{SIN}
1254 @section @code{ASINH} --- Inverse hyperbolic sine function
1257 @cindex area hyperbolic sine
1258 @cindex inverse hyperbolic sine
1259 @cindex hyperbolic function, sine, inverse
1260 @cindex sine, hyperbolic, inverse
1263 @item @emph{Description}:
1264 @code{ASINH(X)} computes the inverse hyperbolic sine of @var{X}.
1266 @item @emph{Standard}:
1267 Fortran 2008 and later
1272 @item @emph{Syntax}:
1273 @code{RESULT = ASINH(X)}
1275 @item @emph{Arguments}:
1276 @multitable @columnfractions .15 .70
1277 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
1280 @item @emph{Return value}:
1281 The return value is of the same type and kind as @var{X}. If @var{X} is
1282 complex, the imaginary part of the result is in radians and lies between
1283 @math{-\pi/2 \leq \Im \asinh(x) \leq \pi/2}.
1285 @item @emph{Example}:
1288 REAL(8), DIMENSION(3) :: x = (/ -1.0, 0.0, 1.0 /)
1289 WRITE (*,*) ASINH(x)
1293 @item @emph{Specific names}:
1294 @multitable @columnfractions .20 .20 .20 .25
1295 @item Name @tab Argument @tab Return type @tab Standard
1296 @item @code{DASINH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension.
1299 @item @emph{See also}:
1300 Inverse function: @ref{SINH}
1306 @section @code{ASSOCIATED} --- Status of a pointer or pointer/target pair
1308 @cindex pointer, status
1309 @cindex association status
1312 @item @emph{Description}:
1313 @code{ASSOCIATED(POINTER [, TARGET])} determines the status of the pointer
1314 @var{POINTER} or if @var{POINTER} is associated with the target @var{TARGET}.
1316 @item @emph{Standard}:
1317 Fortran 95 and later
1322 @item @emph{Syntax}:
1323 @code{RESULT = ASSOCIATED(POINTER [, TARGET])}
1325 @item @emph{Arguments}:
1326 @multitable @columnfractions .15 .70
1327 @item @var{POINTER} @tab @var{POINTER} shall have the @code{POINTER} attribute
1328 and it can be of any type.
1329 @item @var{TARGET} @tab (Optional) @var{TARGET} shall be a pointer or
1330 a target. It must have the same type, kind type parameter, and
1331 array rank as @var{POINTER}.
1333 The association status of neither @var{POINTER} nor @var{TARGET} shall be
1336 @item @emph{Return value}:
1337 @code{ASSOCIATED(POINTER)} returns a scalar value of type @code{LOGICAL(4)}.
1338 There are several cases:
1340 @item (A) When the optional @var{TARGET} is not present then
1341 @code{ASSOCIATED(POINTER)} is true if @var{POINTER} is associated with a target; otherwise, it returns false.
1342 @item (B) If @var{TARGET} is present and a scalar target, the result is true if
1343 @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
1344 disassociated, the result is false.
1345 @item (C) If @var{TARGET} is present and an array target, the result is true if
1346 @var{TARGET} and @var{POINTER} have the same shape, are not zero-sized arrays,
1347 are arrays whose elements are not zero-sized storage sequences, and
1348 @var{TARGET} and @var{POINTER} occupy the same storage units in array element
1350 As in case(B), the result is false, if @var{POINTER} is disassociated.
1351 @item (D) If @var{TARGET} is present and an scalar pointer, the result is true
1352 if @var{TARGET} is associated with @var{POINTER}, the target associated with
1353 @var{TARGET} are not zero-sized storage sequences and occupy the same storage
1355 The result is false, if either @var{TARGET} or @var{POINTER} is disassociated.
1356 @item (E) If @var{TARGET} is present and an array pointer, the result is true if
1357 target associated with @var{POINTER} and the target associated with @var{TARGET}
1358 have the same shape, are not zero-sized arrays, are arrays whose elements are
1359 not zero-sized storage sequences, and @var{TARGET} and @var{POINTER} occupy
1360 the same storage units in array element order.
1361 The result is false, if either @var{TARGET} or @var{POINTER} is disassociated.
1364 @item @emph{Example}:
1366 program test_associated
1368 real, target :: tgt(2) = (/1., 2./)
1369 real, pointer :: ptr(:)
1371 if (associated(ptr) .eqv. .false.) call abort
1372 if (associated(ptr,tgt) .eqv. .false.) call abort
1373 end program test_associated
1376 @item @emph{See also}:
1383 @section @code{ATAN} --- Arctangent function
1386 @cindex trigonometric function, tangent, inverse
1387 @cindex tangent, inverse
1390 @item @emph{Description}:
1391 @code{ATAN(X)} computes the arctangent of @var{X}.
1393 @item @emph{Standard}:
1394 Fortran 77 and later, for a complex argument and for two arguments
1395 Fortran 2008 or later
1400 @item @emph{Syntax}:
1401 @multitable @columnfractions .80
1402 @item @code{RESULT = ATAN(X)}
1403 @item @code{RESULT = ATAN(Y, X)}
1406 @item @emph{Arguments}:
1407 @multitable @columnfractions .15 .70
1408 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX};
1409 if @var{Y} is present, @var{X} shall be REAL.
1410 @item @var{Y} shall be of the same type and kind as @var{X}.
1413 @item @emph{Return value}:
1414 The return value is of the same type and kind as @var{X}.
1415 If @var{Y} is present, the result is identical to @code{ATAN2(Y,X)}.
1416 Otherwise, it the arcus tangent of @var{X}, where the real part of
1417 the result is in radians and lies in the range
1418 @math{-\pi/2 \leq \Re \atan(x) \leq \pi/2}.
1420 @item @emph{Example}:
1423 real(8) :: x = 2.866_8
1425 end program test_atan
1428 @item @emph{Specific names}:
1429 @multitable @columnfractions .20 .20 .20 .25
1430 @item Name @tab Argument @tab Return type @tab Standard
1431 @item @code{ATAN(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
1432 @item @code{DATAN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
1435 @item @emph{See also}:
1436 Inverse function: @ref{TAN}
1443 @section @code{ATAN2} --- Arctangent function
1446 @cindex trigonometric function, tangent, inverse
1447 @cindex tangent, inverse
1450 @item @emph{Description}:
1451 @code{ATAN2(Y, X)} computes the principal value of the argument
1452 function of the complex number @math{X + i Y}. This function can
1453 be used to transform from Cartesian into polar coordinates and
1454 allows to determine the angle in the correct quadrant.
1456 @item @emph{Standard}:
1457 Fortran 77 and later
1462 @item @emph{Syntax}:
1463 @code{RESULT = ATAN2(Y, X)}
1465 @item @emph{Arguments}:
1466 @multitable @columnfractions .15 .70
1467 @item @var{Y} @tab The type shall be @code{REAL}.
1468 @item @var{X} @tab The type and kind type parameter shall be the same as @var{Y}.
1469 If @var{Y} is zero, then @var{X} must be nonzero.
1472 @item @emph{Return value}:
1473 The return value has the same type and kind type parameter as @var{Y}.
1474 It is the principal value of the complex number @math{X + i Y}. If
1475 @var{X} is nonzero, then it lies in the range @math{-\pi \le \atan (x) \leq \pi}.
1476 The sign is positive if @var{Y} is positive. If @var{Y} is zero, then
1477 the return value is zero if @var{X} is positive and @math{\pi} if @var{X}
1478 is negative. Finally, if @var{X} is zero, then the magnitude of the result
1481 @item @emph{Example}:
1484 real(4) :: x = 1.e0_4, y = 0.5e0_4
1486 end program test_atan2
1489 @item @emph{Specific names}:
1490 @multitable @columnfractions .20 .20 .20 .25
1491 @item Name @tab Argument @tab Return type @tab Standard
1492 @item @code{ATAN2(X, Y)} @tab @code{REAL(4) X, Y} @tab @code{REAL(4)} @tab Fortran 77 and later
1493 @item @code{DATAN2(X, Y)} @tab @code{REAL(8) X, Y} @tab @code{REAL(8)} @tab Fortran 77 and later
1500 @section @code{ATANH} --- Inverse hyperbolic tangent function
1503 @cindex area hyperbolic tangent
1504 @cindex inverse hyperbolic tangent
1505 @cindex hyperbolic function, tangent, inverse
1506 @cindex tangent, hyperbolic, inverse
1509 @item @emph{Description}:
1510 @code{ATANH(X)} computes the inverse hyperbolic tangent of @var{X}.
1512 @item @emph{Standard}:
1513 Fortran 2008 and later
1518 @item @emph{Syntax}:
1519 @code{RESULT = ATANH(X)}
1521 @item @emph{Arguments}:
1522 @multitable @columnfractions .15 .70
1523 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
1526 @item @emph{Return value}:
1527 The return value has same type and kind as @var{X}. If @var{X} is
1528 complex, the imaginary part of the result is in radians and lies between
1529 @math{-\pi/2 \leq \Im \atanh(x) \leq \pi/2}.
1531 @item @emph{Example}:
1534 REAL, DIMENSION(3) :: x = (/ -1.0, 0.0, 1.0 /)
1535 WRITE (*,*) ATANH(x)
1539 @item @emph{Specific names}:
1540 @multitable @columnfractions .20 .20 .20 .25
1541 @item Name @tab Argument @tab Return type @tab Standard
1542 @item @code{DATANH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1545 @item @emph{See also}:
1546 Inverse function: @ref{TANH}
1552 @section @code{BESSEL_J0} --- Bessel function of the first kind of order 0
1556 @cindex Bessel function, first kind
1559 @item @emph{Description}:
1560 @code{BESSEL_J0(X)} computes the Bessel function of the first kind of
1561 order 0 of @var{X}. This function is available under the name
1562 @code{BESJ0} as a GNU extension.
1564 @item @emph{Standard}:
1565 Fortran 2008 and later
1570 @item @emph{Syntax}:
1571 @code{RESULT = BESSEL_J0(X)}
1573 @item @emph{Arguments}:
1574 @multitable @columnfractions .15 .70
1575 @item @var{X} @tab The type shall be @code{REAL}, and it shall be scalar.
1578 @item @emph{Return value}:
1579 The return value is of type @code{REAL} and lies in the
1580 range @math{ - 0.4027... \leq Bessel (0,x) \leq 1}. It has the same
1583 @item @emph{Example}:
1586 real(8) :: x = 0.0_8
1588 end program test_besj0
1591 @item @emph{Specific names}:
1592 @multitable @columnfractions .20 .20 .20 .25
1593 @item Name @tab Argument @tab Return type @tab Standard
1594 @item @code{DBESJ0(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1601 @section @code{BESSEL_J1} --- Bessel function of the first kind of order 1
1605 @cindex Bessel function, first kind
1608 @item @emph{Description}:
1609 @code{BESSEL_J1(X)} computes the Bessel function of the first kind of
1610 order 1 of @var{X}. This function is available under the name
1611 @code{BESJ1} as a GNU extension.
1613 @item @emph{Standard}:
1619 @item @emph{Syntax}:
1620 @code{RESULT = BESSEL_J1(X)}
1622 @item @emph{Arguments}:
1623 @multitable @columnfractions .15 .70
1624 @item @var{X} @tab The type shall be @code{REAL}, and it shall be scalar.
1627 @item @emph{Return value}:
1628 The return value is of type @code{REAL} and it lies in the
1629 range @math{ - 0.5818... \leq Bessel (0,x) \leq 0.5818 }. It has the same
1632 @item @emph{Example}:
1635 real(8) :: x = 1.0_8
1637 end program test_besj1
1640 @item @emph{Specific names}:
1641 @multitable @columnfractions .20 .20 .20 .25
1642 @item Name @tab Argument @tab Return type @tab Standard
1643 @item @code{DBESJ1(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1650 @section @code{BESSEL_JN} --- Bessel function of the first kind
1654 @cindex Bessel function, first kind
1657 @item @emph{Description}:
1658 @code{BESSEL_JN(N, X)} computes the Bessel function of the first kind of
1659 order @var{N} of @var{X}. This function is available under the name
1660 @code{BESJN} as a GNU extension. If @var{N} and @var{X} are arrays,
1661 their ranks and shapes shall conform.
1663 @code{BESSEL_JN(N1, N2, X)} returns an array with the Bessel functions
1664 of the first kind of the orders @var{N1} to @var{N2}.
1666 @item @emph{Standard}:
1667 Fortran 2008 and later, negative @var{N} is allowed as GNU extension
1670 Elemental function, except for the transformational function
1671 @code{BESSEL_JN(N1, N2, X)}
1673 @item @emph{Syntax}:
1674 @multitable @columnfractions .80
1675 @item @code{RESULT = BESSEL_JN(N, X)}
1676 @item @code{RESULT = BESSEL_JN(N1, N2, X)}
1679 @item @emph{Arguments}:
1680 @multitable @columnfractions .15 .70
1681 @item @var{N} @tab Shall be a scalar or an array of type @code{INTEGER}.
1682 @item @var{N1} @tab Shall be a non-negative scalar of type @code{INTEGER}.
1683 @item @var{N2} @tab Shall be a non-negative scalar of type @code{INTEGER}.
1684 @item @var{X} @tab Shall be a scalar or an array of type @code{REAL};
1685 for @code{BESSEL_JN(N1, N2, X)} it shall be scalar.
1688 @item @emph{Return value}:
1689 The return value is a scalar of type @code{REAL}. It has the same
1693 The transformational function uses a recurrence algorithm which might,
1694 for some values of @var{X}, lead to different results than calls to
1695 the elemental function.
1697 @item @emph{Example}:
1700 real(8) :: x = 1.0_8
1702 end program test_besjn
1705 @item @emph{Specific names}:
1706 @multitable @columnfractions .20 .20 .20 .25
1707 @item Name @tab Argument @tab Return type @tab Standard
1708 @item @code{DBESJN(N, X)} @tab @code{INTEGER N} @tab @code{REAL(8)} @tab GNU extension
1709 @item @tab @code{REAL(8) X} @tab @tab
1716 @section @code{BESSEL_Y0} --- Bessel function of the second kind of order 0
1720 @cindex Bessel function, second kind
1723 @item @emph{Description}:
1724 @code{BESSEL_Y0(X)} computes the Bessel function of the second kind of
1725 order 0 of @var{X}. This function is available under the name
1726 @code{BESY0} as a GNU extension.
1728 @item @emph{Standard}:
1729 Fortran 2008 and later
1734 @item @emph{Syntax}:
1735 @code{RESULT = BESSEL_Y0(X)}
1737 @item @emph{Arguments}:
1738 @multitable @columnfractions .15 .70
1739 @item @var{X} @tab The type shall be @code{REAL}, and it shall be scalar.
1742 @item @emph{Return value}:
1743 The return value is a scalar of type @code{REAL}. It has the same
1746 @item @emph{Example}:
1749 real(8) :: x = 0.0_8
1751 end program test_besy0
1754 @item @emph{Specific names}:
1755 @multitable @columnfractions .20 .20 .20 .25
1756 @item Name @tab Argument @tab Return type @tab Standard
1757 @item @code{DBESY0(X)}@tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1764 @section @code{BESSEL_Y1} --- Bessel function of the second kind of order 1
1768 @cindex Bessel function, second kind
1771 @item @emph{Description}:
1772 @code{BESSEL_Y1(X)} computes the Bessel function of the second kind of
1773 order 1 of @var{X}. This function is available under the name
1774 @code{BESY1} as a GNU extension.
1776 @item @emph{Standard}:
1777 Fortran 2008 and later
1782 @item @emph{Syntax}:
1783 @code{RESULT = BESSEL_Y1(X)}
1785 @item @emph{Arguments}:
1786 @multitable @columnfractions .15 .70
1787 @item @var{X} @tab The type shall be @code{REAL}, and it shall be scalar.
1790 @item @emph{Return value}:
1791 The return value is a scalar of type @code{REAL}. It has the same
1794 @item @emph{Example}:
1797 real(8) :: x = 1.0_8
1799 end program test_besy1
1802 @item @emph{Specific names}:
1803 @multitable @columnfractions .20 .20 .20 .25
1804 @item Name @tab Argument @tab Return type @tab Standard
1805 @item @code{DBESY1(X)}@tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1812 @section @code{BESSEL_YN} --- Bessel function of the second kind
1816 @cindex Bessel function, second kind
1819 @item @emph{Description}:
1820 @code{BESSEL_YN(N, X)} computes the Bessel function of the second kind of
1821 order @var{N} of @var{X}. This function is available under the name
1822 @code{BESYN} as a GNU extension. If @var{N} and @var{X} are arrays,
1823 their ranks and shapes shall conform.
1825 @code{BESSEL_YN(N1, N2, X)} returns an array with the Bessel functions
1826 of the first kind of the orders @var{N1} to @var{N2}.
1828 @item @emph{Standard}:
1829 Fortran 2008 and later, negative @var{N} is allowed as GNU extension
1832 Elemental function, except for the transformational function
1833 @code{BESSEL_YN(N1, N2, X)}
1835 @item @emph{Syntax}:
1836 @multitable @columnfractions .80
1837 @item @code{RESULT = BESSEL_YN(N, X)}
1838 @item @code{RESULT = BESSEL_YN(N1, N2, X)}
1841 @item @emph{Arguments}:
1842 @multitable @columnfractions .15 .70
1843 @item @var{N} @tab Shall be a scalar or an array of type @code{INTEGER} .
1844 @item @var{N1} @tab Shall be a non-negative scalar of type @code{INTEGER}.
1845 @item @var{N2} @tab Shall be a non-negative scalar of type @code{INTEGER}.
1846 @item @var{X} @tab Shall be a scalar or an array of type @code{REAL};
1847 for @code{BESSEL_YN(N1, N2, X)} it shall be scalar.
1850 @item @emph{Return value}:
1851 The return value is a scalar of type @code{REAL}. It has the same
1855 The transformational function uses a recurrence algorithm which might,
1856 for some values of @var{X}, lead to different results than calls to
1857 the elemental function.
1859 @item @emph{Example}:
1862 real(8) :: x = 1.0_8
1864 end program test_besyn
1867 @item @emph{Specific names}:
1868 @multitable @columnfractions .20 .20 .20 .25
1869 @item Name @tab Argument @tab Return type @tab Standard
1870 @item @code{DBESYN(N,X)} @tab @code{INTEGER N} @tab @code{REAL(8)} @tab GNU extension
1871 @item @tab @code{REAL(8) X} @tab @tab
1878 @section @code{BGE} --- Bitwise greater than or equal to
1880 @cindex bitwise comparison
1883 @item @emph{Description}:
1884 Determines whether an integral is a bitwise greater than or equal to
1887 @item @emph{Standard}:
1888 Fortran 2008 and later
1893 @item @emph{Syntax}:
1894 @code{RESULT = BGE(I, J)}
1896 @item @emph{Arguments}:
1897 @multitable @columnfractions .15 .70
1898 @item @var{I} @tab Shall be of @code{INTEGER} type.
1899 @item @var{J} @tab Shall be of @code{INTEGER} type, and of the same kind
1903 @item @emph{Return value}:
1904 The return value is of type @code{LOGICAL} and of the default kind.
1906 @item @emph{See also}:
1907 @ref{BGT}, @ref{BLE}, @ref{BLT}
1913 @section @code{BGT} --- Bitwise greater than
1915 @cindex bitwise comparison
1918 @item @emph{Description}:
1919 Determines whether an integral is a bitwise greater than another.
1921 @item @emph{Standard}:
1922 Fortran 2008 and later
1927 @item @emph{Syntax}:
1928 @code{RESULT = BGT(I, J)}
1930 @item @emph{Arguments}:
1931 @multitable @columnfractions .15 .70
1932 @item @var{I} @tab Shall be of @code{INTEGER} type.
1933 @item @var{J} @tab Shall be of @code{INTEGER} type, and of the same kind
1937 @item @emph{Return value}:
1938 The return value is of type @code{LOGICAL} and of the default kind.
1940 @item @emph{See also}:
1941 @ref{BGE}, @ref{BLE}, @ref{BLT}
1947 @section @code{BIT_SIZE} --- Bit size inquiry function
1949 @cindex bits, number of
1950 @cindex size of a variable, in bits
1953 @item @emph{Description}:
1954 @code{BIT_SIZE(I)} returns the number of bits (integer precision plus sign bit)
1955 represented by the type of @var{I}. The result of @code{BIT_SIZE(I)} is
1956 independent of the actual value of @var{I}.
1958 @item @emph{Standard}:
1959 Fortran 95 and later
1964 @item @emph{Syntax}:
1965 @code{RESULT = BIT_SIZE(I)}
1967 @item @emph{Arguments}:
1968 @multitable @columnfractions .15 .70
1969 @item @var{I} @tab The type shall be @code{INTEGER}.
1972 @item @emph{Return value}:
1973 The return value is of type @code{INTEGER}
1975 @item @emph{Example}:
1977 program test_bit_size
1982 end program test_bit_size
1989 @section @code{BLE} --- Bitwise less than or equal to
1991 @cindex bitwise comparison
1994 @item @emph{Description}:
1995 Determines whether an integral is a bitwise less than or equal to
1998 @item @emph{Standard}:
1999 Fortran 2008 and later
2004 @item @emph{Syntax}:
2005 @code{RESULT = BLE(I, J)}
2007 @item @emph{Arguments}:
2008 @multitable @columnfractions .15 .70
2009 @item @var{I} @tab Shall be of @code{INTEGER} type.
2010 @item @var{J} @tab Shall be of @code{INTEGER} type, and of the same kind
2014 @item @emph{Return value}:
2015 The return value is of type @code{LOGICAL} and of the default kind.
2017 @item @emph{See also}:
2018 @ref{BGT}, @ref{BGE}, @ref{BLT}
2024 @section @code{BLT} --- Bitwise less than
2026 @cindex bitwise comparison
2029 @item @emph{Description}:
2030 Determines whether an integral is a bitwise less than another.
2032 @item @emph{Standard}:
2033 Fortran 2008 and later
2038 @item @emph{Syntax}:
2039 @code{RESULT = BLT(I, J)}
2041 @item @emph{Arguments}:
2042 @multitable @columnfractions .15 .70
2043 @item @var{I} @tab Shall be of @code{INTEGER} type.
2044 @item @var{J} @tab Shall be of @code{INTEGER} type, and of the same kind
2048 @item @emph{Return value}:
2049 The return value is of type @code{LOGICAL} and of the default kind.
2051 @item @emph{See also}:
2052 @ref{BGE}, @ref{BGT}, @ref{BLE}
2058 @section @code{BTEST} --- Bit test function
2060 @cindex bits, testing
2063 @item @emph{Description}:
2064 @code{BTEST(I,POS)} returns logical @code{.TRUE.} if the bit at @var{POS}
2065 in @var{I} is set. The counting of the bits starts at 0.
2067 @item @emph{Standard}:
2068 Fortran 95 and later
2073 @item @emph{Syntax}:
2074 @code{RESULT = BTEST(I, POS)}
2076 @item @emph{Arguments}:
2077 @multitable @columnfractions .15 .70
2078 @item @var{I} @tab The type shall be @code{INTEGER}.
2079 @item @var{POS} @tab The type shall be @code{INTEGER}.
2082 @item @emph{Return value}:
2083 The return value is of type @code{LOGICAL}
2085 @item @emph{Example}:
2088 integer :: i = 32768 + 1024 + 64
2092 bool = btest(i, pos)
2095 end program test_btest
2101 @section @code{C_ASSOCIATED} --- Status of a C pointer
2102 @fnindex C_ASSOCIATED
2103 @cindex association status, C pointer
2104 @cindex pointer, C association status
2107 @item @emph{Description}:
2108 @code{C_ASSOCIATED(c_prt_1[, c_ptr_2])} determines the status of the C pointer
2109 @var{c_ptr_1} or if @var{c_ptr_1} is associated with the target @var{c_ptr_2}.
2111 @item @emph{Standard}:
2112 Fortran 2003 and later
2117 @item @emph{Syntax}:
2118 @code{RESULT = C_ASSOCIATED(c_prt_1[, c_ptr_2])}
2120 @item @emph{Arguments}:
2121 @multitable @columnfractions .15 .70
2122 @item @var{c_ptr_1} @tab Scalar of the type @code{C_PTR} or @code{C_FUNPTR}.
2123 @item @var{c_ptr_2} @tab (Optional) Scalar of the same type as @var{c_ptr_1}.
2126 @item @emph{Return value}:
2127 The return value is of type @code{LOGICAL}; it is @code{.false.} if either
2128 @var{c_ptr_1} is a C NULL pointer or if @var{c_ptr1} and @var{c_ptr_2}
2129 point to different addresses.
2131 @item @emph{Example}:
2133 subroutine association_test(a,b)
2134 use iso_c_binding, only: c_associated, c_loc, c_ptr
2138 if(c_associated(b, c_loc(a))) &
2139 stop 'b and a do not point to same target'
2140 end subroutine association_test
2143 @item @emph{See also}:
2144 @ref{C_LOC}, @ref{C_FUNLOC}
2149 @section @code{C_FUNLOC} --- Obtain the C address of a procedure
2151 @cindex pointer, C address of procedures
2154 @item @emph{Description}:
2155 @code{C_FUNLOC(x)} determines the C address of the argument.
2157 @item @emph{Standard}:
2158 Fortran 2003 and later
2163 @item @emph{Syntax}:
2164 @code{RESULT = C_FUNLOC(x)}
2166 @item @emph{Arguments}:
2167 @multitable @columnfractions .15 .70
2168 @item @var{x} @tab Interoperable function or pointer to such function.
2171 @item @emph{Return value}:
2172 The return value is of type @code{C_FUNPTR} and contains the C address
2175 @item @emph{Example}:
2181 subroutine sub(a) bind(c)
2191 subroutine my_routine(p) bind(c,name='myC_func')
2193 type(c_funptr), intent(in) :: p
2196 call my_routine(c_funloc(sub))
2200 @item @emph{See also}:
2201 @ref{C_ASSOCIATED}, @ref{C_LOC}, @ref{C_F_POINTER}, @ref{C_F_PROCPOINTER}
2205 @node C_F_PROCPOINTER
2206 @section @code{C_F_PROCPOINTER} --- Convert C into Fortran procedure pointer
2207 @fnindex C_F_PROCPOINTER
2208 @cindex pointer, C address of pointers
2211 @item @emph{Description}:
2212 @code{C_F_PROCPOINTER(CPTR, FPTR)} Assign the target of the C function pointer
2213 @var{CPTR} to the Fortran procedure pointer @var{FPTR}.
2215 @item @emph{Standard}:
2216 Fortran 2003 and later
2221 @item @emph{Syntax}:
2222 @code{CALL C_F_PROCPOINTER(cptr, fptr)}
2224 @item @emph{Arguments}:
2225 @multitable @columnfractions .15 .70
2226 @item @var{CPTR} @tab scalar of the type @code{C_FUNPTR}. It is
2228 @item @var{FPTR} @tab procedure pointer interoperable with @var{cptr}. It is
2232 @item @emph{Example}:
2240 real(c_float), intent(in) :: a
2241 real(c_float) :: func
2245 function getIterFunc() bind(c,name="getIterFunc")
2247 type(c_funptr) :: getIterFunc
2250 type(c_funptr) :: cfunptr
2251 procedure(func), pointer :: myFunc
2252 cfunptr = getIterFunc()
2253 call c_f_procpointer(cfunptr, myFunc)
2257 @item @emph{See also}:
2258 @ref{C_LOC}, @ref{C_F_POINTER}
2263 @section @code{C_F_POINTER} --- Convert C into Fortran pointer
2264 @fnindex C_F_POINTER
2265 @cindex pointer, convert C to Fortran
2268 @item @emph{Description}:
2269 @code{C_F_POINTER(CPTR, FPTR[, SHAPE])} Assign the target the C pointer
2270 @var{CPTR} to the Fortran pointer @var{FPTR} and specify its
2273 @item @emph{Standard}:
2274 Fortran 2003 and later
2279 @item @emph{Syntax}:
2280 @code{CALL C_F_POINTER(CPTR, FPTR[, SHAPE])}
2282 @item @emph{Arguments}:
2283 @multitable @columnfractions .15 .70
2284 @item @var{CPTR} @tab scalar of the type @code{C_PTR}. It is
2286 @item @var{FPTR} @tab pointer interoperable with @var{cptr}. It is
2288 @item @var{SHAPE} @tab (Optional) Rank-one array of type @code{INTEGER}
2289 with @code{INTENT(IN)}. It shall be present
2290 if and only if @var{fptr} is an array. The size
2291 must be equal to the rank of @var{fptr}.
2294 @item @emph{Example}:
2300 subroutine my_routine(p) bind(c,name='myC_func')
2302 type(c_ptr), intent(out) :: p
2306 real,pointer :: a(:)
2307 call my_routine(cptr)
2308 call c_f_pointer(cptr, a, [12])
2312 @item @emph{See also}:
2313 @ref{C_LOC}, @ref{C_F_PROCPOINTER}
2318 @section @code{C_LOC} --- Obtain the C address of an object
2320 @cindex procedure pointer, convert C to Fortran
2323 @item @emph{Description}:
2324 @code{C_LOC(X)} determines the C address of the argument.
2326 @item @emph{Standard}:
2327 Fortran 2003 and later
2332 @item @emph{Syntax}:
2333 @code{RESULT = C_LOC(X)}
2335 @item @emph{Arguments}:
2336 @multitable @columnfractions .10 .75
2337 @item @var{X} @tab Shall have either the POINTER or TARGET attribute. It shall not be a coindexed object. It shall either be a variable with interoperable type and kind type parameters, or be a scalar, nonpolymorphic variable with no length type parameters.
2341 @item @emph{Return value}:
2342 The return value is of type @code{C_PTR} and contains the C address
2345 @item @emph{Example}:
2347 subroutine association_test(a,b)
2348 use iso_c_binding, only: c_associated, c_loc, c_ptr
2352 if(c_associated(b, c_loc(a))) &
2353 stop 'b and a do not point to same target'
2354 end subroutine association_test
2357 @item @emph{See also}:
2358 @ref{C_ASSOCIATED}, @ref{C_FUNLOC}, @ref{C_F_POINTER}, @ref{C_F_PROCPOINTER}
2363 @section @code{C_SIZEOF} --- Size in bytes of an expression
2365 @cindex expression size
2366 @cindex size of an expression
2369 @item @emph{Description}:
2370 @code{C_SIZEOF(X)} calculates the number of bytes of storage the
2371 expression @code{X} occupies.
2373 @item @emph{Standard}:
2377 Inquiry function of the module @code{ISO_C_BINDING}
2379 @item @emph{Syntax}:
2380 @code{N = C_SIZEOF(X)}
2382 @item @emph{Arguments}:
2383 @multitable @columnfractions .15 .70
2384 @item @var{X} @tab The argument shall be an interoperable data entity.
2387 @item @emph{Return value}:
2388 The return value is of type integer and of the system-dependent kind
2389 @code{C_SIZE_T} (from the @code{ISO_C_BINDING} module). Its value is the
2390 number of bytes occupied by the argument. If the argument has the
2391 @code{POINTER} attribute, the number of bytes of the storage area pointed
2392 to is returned. If the argument is of a derived type with @code{POINTER}
2393 or @code{ALLOCATABLE} components, the return value doesn't account for
2394 the sizes of the data pointed to by these components.
2396 @item @emph{Example}:
2400 real(c_float) :: r, s(5)
2401 print *, (c_sizeof(s)/c_sizeof(r) == 5)
2404 The example will print @code{.TRUE.} unless you are using a platform
2405 where default @code{REAL} variables are unusually padded.
2407 @item @emph{See also}:
2408 @ref{SIZEOF}, @ref{STORAGE_SIZE}
2413 @section @code{CEILING} --- Integer ceiling function
2416 @cindex rounding, ceiling
2419 @item @emph{Description}:
2420 @code{CEILING(A)} returns the least integer greater than or equal to @var{A}.
2422 @item @emph{Standard}:
2423 Fortran 95 and later
2428 @item @emph{Syntax}:
2429 @code{RESULT = CEILING(A [, KIND])}
2431 @item @emph{Arguments}:
2432 @multitable @columnfractions .15 .70
2433 @item @var{A} @tab The type shall be @code{REAL}.
2434 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
2435 expression indicating the kind parameter of the result.
2438 @item @emph{Return value}:
2439 The return value is of type @code{INTEGER(KIND)} if @var{KIND} is present
2440 and a default-kind @code{INTEGER} otherwise.
2442 @item @emph{Example}:
2444 program test_ceiling
2447 print *, ceiling(x) ! returns 64
2448 print *, ceiling(y) ! returns -63
2449 end program test_ceiling
2452 @item @emph{See also}:
2453 @ref{FLOOR}, @ref{NINT}
2460 @section @code{CHAR} --- Character conversion function
2462 @cindex conversion, to character
2465 @item @emph{Description}:
2466 @code{CHAR(I [, KIND])} returns the character represented by the integer @var{I}.
2468 @item @emph{Standard}:
2469 Fortran 77 and later
2474 @item @emph{Syntax}:
2475 @code{RESULT = CHAR(I [, KIND])}
2477 @item @emph{Arguments}:
2478 @multitable @columnfractions .15 .70
2479 @item @var{I} @tab The type shall be @code{INTEGER}.
2480 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
2481 expression indicating the kind parameter of the result.
2484 @item @emph{Return value}:
2485 The return value is of type @code{CHARACTER(1)}
2487 @item @emph{Example}:
2493 print *, i, c ! returns 'J'
2494 end program test_char
2497 @item @emph{Specific names}:
2498 @multitable @columnfractions .20 .20 .20 .25
2499 @item Name @tab Argument @tab Return type @tab Standard
2500 @item @code{CHAR(I)} @tab @code{INTEGER I} @tab @code{CHARACTER(LEN=1)} @tab F77 and later
2504 See @ref{ICHAR} for a discussion of converting between numerical values
2505 and formatted string representations.
2507 @item @emph{See also}:
2508 @ref{ACHAR}, @ref{IACHAR}, @ref{ICHAR}
2515 @section @code{CHDIR} --- Change working directory
2517 @cindex system, working directory
2520 @item @emph{Description}:
2521 Change current working directory to a specified path.
2523 This intrinsic is provided in both subroutine and function forms; however,
2524 only one form can be used in any given program unit.
2526 @item @emph{Standard}:
2530 Subroutine, function
2532 @item @emph{Syntax}:
2533 @multitable @columnfractions .80
2534 @item @code{CALL CHDIR(NAME [, STATUS])}
2535 @item @code{STATUS = CHDIR(NAME)}
2538 @item @emph{Arguments}:
2539 @multitable @columnfractions .15 .70
2540 @item @var{NAME} @tab The type shall be @code{CHARACTER} of default
2541 kind and shall specify a valid path within the file system.
2542 @item @var{STATUS} @tab (Optional) @code{INTEGER} status flag of the default
2543 kind. Returns 0 on success, and a system specific and nonzero error code
2547 @item @emph{Example}:
2550 CHARACTER(len=255) :: path
2552 WRITE(*,*) TRIM(path)
2555 WRITE(*,*) TRIM(path)
2559 @item @emph{See also}:
2566 @section @code{CHMOD} --- Change access permissions of files
2568 @cindex file system, change access mode
2571 @item @emph{Description}:
2572 @code{CHMOD} changes the permissions of a file. This function invokes
2573 @code{/bin/chmod} and might therefore not work on all platforms.
2575 This intrinsic is provided in both subroutine and function forms; however,
2576 only one form can be used in any given program unit.
2578 @item @emph{Standard}:
2582 Subroutine, function
2584 @item @emph{Syntax}:
2585 @multitable @columnfractions .80
2586 @item @code{CALL CHMOD(NAME, MODE[, STATUS])}
2587 @item @code{STATUS = CHMOD(NAME, MODE)}
2590 @item @emph{Arguments}:
2591 @multitable @columnfractions .15 .70
2593 @item @var{NAME} @tab Scalar @code{CHARACTER} of default kind with the
2594 file name. Trailing blanks are ignored unless the character
2595 @code{achar(0)} is present, then all characters up to and excluding
2596 @code{achar(0)} are used as the file name.
2598 @item @var{MODE} @tab Scalar @code{CHARACTER} of default kind giving the
2599 file permission. @var{MODE} uses the same syntax as the @var{MODE}
2600 argument of @code{/bin/chmod}.
2602 @item @var{STATUS} @tab (optional) scalar @code{INTEGER}, which is
2603 @code{0} on success and nonzero otherwise.
2606 @item @emph{Return value}:
2607 In either syntax, @var{STATUS} is set to @code{0} on success and nonzero
2610 @item @emph{Example}:
2611 @code{CHMOD} as subroutine
2616 call chmod('test.dat','u+x',status)
2617 print *, 'Status: ', status
2618 end program chmod_test
2620 @code{CHMOD} as function:
2625 status = chmod('test.dat','u+x')
2626 print *, 'Status: ', status
2627 end program chmod_test
2635 @section @code{CMPLX} --- Complex conversion function
2637 @cindex complex numbers, conversion to
2638 @cindex conversion, to complex
2641 @item @emph{Description}:
2642 @code{CMPLX(X [, Y [, KIND]])} returns a complex number where @var{X} is converted to
2643 the real component. If @var{Y} is present it is converted to the imaginary
2644 component. If @var{Y} is not present then the imaginary component is set to
2645 0.0. If @var{X} is complex then @var{Y} must not be present.
2647 @item @emph{Standard}:
2648 Fortran 77 and later
2653 @item @emph{Syntax}:
2654 @code{RESULT = CMPLX(X [, Y [, KIND]])}
2656 @item @emph{Arguments}:
2657 @multitable @columnfractions .15 .70
2658 @item @var{X} @tab The type may be @code{INTEGER}, @code{REAL},
2660 @item @var{Y} @tab (Optional; only allowed if @var{X} is not
2661 @code{COMPLEX}.) May be @code{INTEGER} or @code{REAL}.
2662 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
2663 expression indicating the kind parameter of the result.
2666 @item @emph{Return value}:
2667 The return value is of @code{COMPLEX} type, with a kind equal to
2668 @var{KIND} if it is specified. If @var{KIND} is not specified, the
2669 result is of the default @code{COMPLEX} kind, regardless of the kinds of
2670 @var{X} and @var{Y}.
2672 @item @emph{Example}:
2679 print *, z, cmplx(x)
2680 end program test_cmplx
2683 @item @emph{See also}:
2689 @node COMMAND_ARGUMENT_COUNT
2690 @section @code{COMMAND_ARGUMENT_COUNT} --- Get number of command line arguments
2691 @fnindex COMMAND_ARGUMENT_COUNT
2692 @cindex command-line arguments
2693 @cindex command-line arguments, number of
2694 @cindex arguments, to program
2697 @item @emph{Description}:
2698 @code{COMMAND_ARGUMENT_COUNT} returns the number of arguments passed on the
2699 command line when the containing program was invoked.
2701 @item @emph{Standard}:
2702 Fortran 2003 and later
2707 @item @emph{Syntax}:
2708 @code{RESULT = COMMAND_ARGUMENT_COUNT()}
2710 @item @emph{Arguments}:
2711 @multitable @columnfractions .15 .70
2715 @item @emph{Return value}:
2716 The return value is an @code{INTEGER} of default kind.
2718 @item @emph{Example}:
2720 program test_command_argument_count
2722 count = command_argument_count()
2724 end program test_command_argument_count
2727 @item @emph{See also}:
2728 @ref{GET_COMMAND}, @ref{GET_COMMAND_ARGUMENT}
2733 @node COMPILER_OPTIONS
2734 @section @code{COMPILER_OPTIONS} --- Options passed to the compiler
2735 @fnindex COMPILER_OPTIONS
2736 @cindex flags inquiry function
2737 @cindex options inquiry function
2738 @cindex compiler flags inquiry function
2741 @item @emph{Description}:
2742 @code{COMPILER_OPTIONS} returns a string with the options used for
2745 @item @emph{Standard}:
2749 Inquiry function of the module @code{ISO_FORTRAN_ENV}
2751 @item @emph{Syntax}:
2752 @code{STR = COMPILER_OPTIONS()}
2754 @item @emph{Arguments}:
2757 @item @emph{Return value}:
2758 The return value is a default-kind string with system-dependent length.
2759 It contains the compiler flags used to compile the file, which called
2760 the @code{COMPILER_OPTIONS} intrinsic.
2762 @item @emph{Example}:
2765 print '(4a)', 'This file was compiled by ', &
2766 compiler_version(), ' using the the options ', &
2771 @item @emph{See also}:
2772 @ref{COMPILER_VERSION}, @ref{ISO_FORTRAN_ENV}
2777 @node COMPILER_VERSION
2778 @section @code{COMPILER_VERSION} --- Compiler version string
2779 @fnindex COMPILER_VERSION
2780 @cindex compiler, name and version
2781 @cindex version of the compiler
2784 @item @emph{Description}:
2785 @code{COMPILER_VERSION} returns a string with the name and the
2786 version of the compiler.
2788 @item @emph{Standard}:
2792 Inquiry function of the module @code{ISO_FORTRAN_ENV}
2794 @item @emph{Syntax}:
2795 @code{STR = COMPILER_VERSION()}
2797 @item @emph{Arguments}:
2800 @item @emph{Return value}:
2801 The return value is a default-kind string with system-dependent length.
2802 It contains the name of the compiler and its version number.
2804 @item @emph{Example}:
2807 print '(4a)', 'This file was compiled by ', &
2808 compiler_version(), ' using the the options ', &
2813 @item @emph{See also}:
2814 @ref{COMPILER_OPTIONS}, @ref{ISO_FORTRAN_ENV}
2820 @section @code{COMPLEX} --- Complex conversion function
2822 @cindex complex numbers, conversion to
2823 @cindex conversion, to complex
2826 @item @emph{Description}:
2827 @code{COMPLEX(X, Y)} returns a complex number where @var{X} is converted
2828 to the real component and @var{Y} is converted to the imaginary
2831 @item @emph{Standard}:
2837 @item @emph{Syntax}:
2838 @code{RESULT = COMPLEX(X, Y)}
2840 @item @emph{Arguments}:
2841 @multitable @columnfractions .15 .70
2842 @item @var{X} @tab The type may be @code{INTEGER} or @code{REAL}.
2843 @item @var{Y} @tab The type may be @code{INTEGER} or @code{REAL}.
2846 @item @emph{Return value}:
2847 If @var{X} and @var{Y} are both of @code{INTEGER} type, then the return
2848 value is of default @code{COMPLEX} type.
2850 If @var{X} and @var{Y} are of @code{REAL} type, or one is of @code{REAL}
2851 type and one is of @code{INTEGER} type, then the return value is of
2852 @code{COMPLEX} type with a kind equal to that of the @code{REAL}
2853 argument with the highest precision.
2855 @item @emph{Example}:
2857 program test_complex
2860 print *, complex(i, x)
2861 end program test_complex
2864 @item @emph{See also}:
2871 @section @code{CONJG} --- Complex conjugate function
2874 @cindex complex conjugate
2877 @item @emph{Description}:
2878 @code{CONJG(Z)} returns the conjugate of @var{Z}. If @var{Z} is @code{(x, y)}
2879 then the result is @code{(x, -y)}
2881 @item @emph{Standard}:
2882 Fortran 77 and later, has overloads that are GNU extensions
2887 @item @emph{Syntax}:
2890 @item @emph{Arguments}:
2891 @multitable @columnfractions .15 .70
2892 @item @var{Z} @tab The type shall be @code{COMPLEX}.
2895 @item @emph{Return value}:
2896 The return value is of type @code{COMPLEX}.
2898 @item @emph{Example}:
2901 complex :: z = (2.0, 3.0)
2902 complex(8) :: dz = (2.71_8, -3.14_8)
2907 end program test_conjg
2910 @item @emph{Specific names}:
2911 @multitable @columnfractions .20 .20 .20 .25
2912 @item Name @tab Argument @tab Return type @tab Standard
2913 @item @code{CONJG(Z)} @tab @code{COMPLEX Z} @tab @code{COMPLEX} @tab GNU extension
2914 @item @code{DCONJG(Z)} @tab @code{COMPLEX(8) Z} @tab @code{COMPLEX(8)} @tab GNU extension
2921 @section @code{COS} --- Cosine function
2927 @cindex trigonometric function, cosine
2931 @item @emph{Description}:
2932 @code{COS(X)} computes the cosine of @var{X}.
2934 @item @emph{Standard}:
2935 Fortran 77 and later, has overloads that are GNU extensions
2940 @item @emph{Syntax}:
2941 @code{RESULT = COS(X)}
2943 @item @emph{Arguments}:
2944 @multitable @columnfractions .15 .70
2945 @item @var{X} @tab The type shall be @code{REAL} or
2949 @item @emph{Return value}:
2950 The return value is of the same type and kind as @var{X}. The real part
2951 of the result is in radians. If @var{X} is of the type @code{REAL},
2952 the return value lies in the range @math{ -1 \leq \cos (x) \leq 1}.
2954 @item @emph{Example}:
2959 end program test_cos
2962 @item @emph{Specific names}:
2963 @multitable @columnfractions .20 .20 .20 .25
2964 @item Name @tab Argument @tab Return type @tab Standard
2965 @item @code{COS(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
2966 @item @code{DCOS(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
2967 @item @code{CCOS(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab Fortran 77 and later
2968 @item @code{ZCOS(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
2969 @item @code{CDCOS(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
2972 @item @emph{See also}:
2973 Inverse function: @ref{ACOS}
2980 @section @code{COSH} --- Hyperbolic cosine function
2983 @cindex hyperbolic cosine
2984 @cindex hyperbolic function, cosine
2985 @cindex cosine, hyperbolic
2988 @item @emph{Description}:
2989 @code{COSH(X)} computes the hyperbolic cosine of @var{X}.
2991 @item @emph{Standard}:
2992 Fortran 77 and later, for a complex argument Fortran 2008 or later
2997 @item @emph{Syntax}:
3000 @item @emph{Arguments}:
3001 @multitable @columnfractions .15 .70
3002 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
3005 @item @emph{Return value}:
3006 The return value has same type and kind as @var{X}. If @var{X} is
3007 complex, the imaginary part of the result is in radians. If @var{X}
3008 is @code{REAL}, the return value has a lower bound of one,
3009 @math{\cosh (x) \geq 1}.
3011 @item @emph{Example}:
3014 real(8) :: x = 1.0_8
3016 end program test_cosh
3019 @item @emph{Specific names}:
3020 @multitable @columnfractions .20 .20 .20 .25
3021 @item Name @tab Argument @tab Return type @tab Standard
3022 @item @code{COSH(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
3023 @item @code{DCOSH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
3026 @item @emph{See also}:
3027 Inverse function: @ref{ACOSH}
3034 @section @code{COUNT} --- Count function
3036 @cindex array, conditionally count elements
3037 @cindex array, element counting
3038 @cindex array, number of elements
3041 @item @emph{Description}:
3043 Counts the number of @code{.TRUE.} elements in a logical @var{MASK},
3044 or, if the @var{DIM} argument is supplied, counts the number of
3045 elements along each row of the array in the @var{DIM} direction.
3046 If the array has zero size, or all of the elements of @var{MASK} are
3047 @code{.FALSE.}, then the result is @code{0}.
3049 @item @emph{Standard}:
3050 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
3053 Transformational function
3055 @item @emph{Syntax}:
3056 @code{RESULT = COUNT(MASK [, DIM, KIND])}
3058 @item @emph{Arguments}:
3059 @multitable @columnfractions .15 .70
3060 @item @var{MASK} @tab The type shall be @code{LOGICAL}.
3061 @item @var{DIM} @tab (Optional) The type shall be @code{INTEGER}.
3062 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
3063 expression indicating the kind parameter of the result.
3066 @item @emph{Return value}:
3067 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
3068 @var{KIND} is absent, the return value is of default integer kind.
3069 If @var{DIM} is present, the result is an array with a rank one less
3070 than the rank of @var{ARRAY}, and a size corresponding to the shape
3071 of @var{ARRAY} with the @var{DIM} dimension removed.
3073 @item @emph{Example}:
3076 integer, dimension(2,3) :: a, b
3077 logical, dimension(2,3) :: mask
3078 a = reshape( (/ 1, 2, 3, 4, 5, 6 /), (/ 2, 3 /))
3079 b = reshape( (/ 0, 7, 3, 4, 5, 8 /), (/ 2, 3 /))
3080 print '(3i3)', a(1,:)
3081 print '(3i3)', a(2,:)
3083 print '(3i3)', b(1,:)
3084 print '(3i3)', b(2,:)
3087 print '(3l3)', mask(1,:)
3088 print '(3l3)', mask(2,:)
3090 print '(3i3)', count(mask)
3092 print '(3i3)', count(mask, 1)
3094 print '(3i3)', count(mask, 2)
3095 end program test_count
3102 @section @code{CPU_TIME} --- CPU elapsed time in seconds
3104 @cindex time, elapsed
3107 @item @emph{Description}:
3108 Returns a @code{REAL} value representing the elapsed CPU time in
3109 seconds. This is useful for testing segments of code to determine
3112 If a time source is available, time will be reported with microsecond
3113 resolution. If no time source is available, @var{TIME} is set to
3116 Note that @var{TIME} may contain a, system dependent, arbitrary offset
3117 and may not start with @code{0.0}. For @code{CPU_TIME}, the absolute
3118 value is meaningless, only differences between subsequent calls to
3119 this subroutine, as shown in the example below, should be used.
3122 @item @emph{Standard}:
3123 Fortran 95 and later
3128 @item @emph{Syntax}:
3129 @code{CALL CPU_TIME(TIME)}
3131 @item @emph{Arguments}:
3132 @multitable @columnfractions .15 .70
3133 @item @var{TIME} @tab The type shall be @code{REAL} with @code{INTENT(OUT)}.
3136 @item @emph{Return value}:
3139 @item @emph{Example}:
3141 program test_cpu_time
3142 real :: start, finish
3143 call cpu_time(start)
3144 ! put code to test here
3145 call cpu_time(finish)
3146 print '("Time = ",f6.3," seconds.")',finish-start
3147 end program test_cpu_time
3150 @item @emph{See also}:
3151 @ref{SYSTEM_CLOCK}, @ref{DATE_AND_TIME}
3157 @section @code{CSHIFT} --- Circular shift elements of an array
3159 @cindex array, shift circularly
3160 @cindex array, permutation
3161 @cindex array, rotate
3164 @item @emph{Description}:
3165 @code{CSHIFT(ARRAY, SHIFT [, DIM])} performs a circular shift on elements of
3166 @var{ARRAY} along the dimension of @var{DIM}. If @var{DIM} is omitted it is
3167 taken to be @code{1}. @var{DIM} is a scalar of type @code{INTEGER} in the
3168 range of @math{1 \leq DIM \leq n)} where @math{n} is the rank of @var{ARRAY}.
3169 If the rank of @var{ARRAY} is one, then all elements of @var{ARRAY} are shifted
3170 by @var{SHIFT} places. If rank is greater than one, then all complete rank one
3171 sections of @var{ARRAY} along the given dimension are shifted. Elements
3172 shifted out one end of each rank one section are shifted back in the other end.
3174 @item @emph{Standard}:
3175 Fortran 95 and later
3178 Transformational function
3180 @item @emph{Syntax}:
3181 @code{RESULT = CSHIFT(ARRAY, SHIFT [, DIM])}
3183 @item @emph{Arguments}:
3184 @multitable @columnfractions .15 .70
3185 @item @var{ARRAY} @tab Shall be an array of any type.
3186 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
3187 @item @var{DIM} @tab The type shall be @code{INTEGER}.
3190 @item @emph{Return value}:
3191 Returns an array of same type and rank as the @var{ARRAY} argument.
3193 @item @emph{Example}:
3196 integer, dimension(3,3) :: a
3197 a = reshape( (/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /), (/ 3, 3 /))
3198 print '(3i3)', a(1,:)
3199 print '(3i3)', a(2,:)
3200 print '(3i3)', a(3,:)
3201 a = cshift(a, SHIFT=(/1, 2, -1/), DIM=2)
3203 print '(3i3)', a(1,:)
3204 print '(3i3)', a(2,:)
3205 print '(3i3)', a(3,:)
3206 end program test_cshift
3213 @section @code{CTIME} --- Convert a time into a string
3215 @cindex time, conversion to string
3216 @cindex conversion, to string
3219 @item @emph{Description}:
3220 @code{CTIME} converts a system time value, such as returned by
3221 @code{TIME8}, to a string of the form @samp{Sat Aug 19 18:13:14 1995}.
3223 This intrinsic is provided in both subroutine and function forms; however,
3224 only one form can be used in any given program unit.
3226 @item @emph{Standard}:
3230 Subroutine, function
3232 @item @emph{Syntax}:
3233 @multitable @columnfractions .80
3234 @item @code{CALL CTIME(TIME, RESULT)}.
3235 @item @code{RESULT = CTIME(TIME)}, (not recommended).
3238 @item @emph{Arguments}:
3239 @multitable @columnfractions .15 .70
3240 @item @var{TIME} @tab The type shall be of type @code{INTEGER(KIND=8)}.
3241 @item @var{RESULT} @tab The type shall be of type @code{CHARACTER} and
3245 @item @emph{Return value}:
3246 The converted date and time as a string.
3248 @item @emph{Example}:
3252 character(len=30) :: date
3255 ! Do something, main part of the program
3258 print *, 'Program was started on ', date
3259 end program test_ctime
3262 @item @emph{See Also}:
3263 @ref{GMTIME}, @ref{LTIME}, @ref{TIME}, @ref{TIME8}
3269 @section @code{DATE_AND_TIME} --- Date and time subroutine
3270 @fnindex DATE_AND_TIME
3271 @cindex date, current
3272 @cindex current date
3273 @cindex time, current
3274 @cindex current time
3277 @item @emph{Description}:
3278 @code{DATE_AND_TIME(DATE, TIME, ZONE, VALUES)} gets the corresponding date and
3279 time information from the real-time system clock. @var{DATE} is
3280 @code{INTENT(OUT)} and has form ccyymmdd. @var{TIME} is @code{INTENT(OUT)} and
3281 has form hhmmss.sss. @var{ZONE} is @code{INTENT(OUT)} and has form (+-)hhmm,
3282 representing the difference with respect to Coordinated Universal Time (UTC).
3283 Unavailable time and date parameters return blanks.
3285 @var{VALUES} is @code{INTENT(OUT)} and provides the following:
3287 @multitable @columnfractions .15 .30 .40
3288 @item @tab @code{VALUE(1)}: @tab The year
3289 @item @tab @code{VALUE(2)}: @tab The month
3290 @item @tab @code{VALUE(3)}: @tab The day of the month
3291 @item @tab @code{VALUE(4)}: @tab Time difference with UTC in minutes
3292 @item @tab @code{VALUE(5)}: @tab The hour of the day
3293 @item @tab @code{VALUE(6)}: @tab The minutes of the hour
3294 @item @tab @code{VALUE(7)}: @tab The seconds of the minute
3295 @item @tab @code{VALUE(8)}: @tab The milliseconds of the second
3298 @item @emph{Standard}:
3299 Fortran 95 and later
3304 @item @emph{Syntax}:
3305 @code{CALL DATE_AND_TIME([DATE, TIME, ZONE, VALUES])}
3307 @item @emph{Arguments}:
3308 @multitable @columnfractions .15 .70
3309 @item @var{DATE} @tab (Optional) The type shall be @code{CHARACTER(LEN=8)}
3310 or larger, and of default kind.
3311 @item @var{TIME} @tab (Optional) The type shall be @code{CHARACTER(LEN=10)}
3312 or larger, and of default kind.
3313 @item @var{ZONE} @tab (Optional) The type shall be @code{CHARACTER(LEN=5)}
3314 or larger, and of default kind.
3315 @item @var{VALUES}@tab (Optional) The type shall be @code{INTEGER(8)}.
3318 @item @emph{Return value}:
3321 @item @emph{Example}:
3323 program test_time_and_date
3324 character(8) :: date
3325 character(10) :: time
3326 character(5) :: zone
3327 integer,dimension(8) :: values
3328 ! using keyword arguments
3329 call date_and_time(date,time,zone,values)
3330 call date_and_time(DATE=date,ZONE=zone)
3331 call date_and_time(TIME=time)
3332 call date_and_time(VALUES=values)
3333 print '(a,2x,a,2x,a)', date, time, zone
3334 print '(8i5))', values
3335 end program test_time_and_date
3338 @item @emph{See also}:
3339 @ref{CPU_TIME}, @ref{SYSTEM_CLOCK}
3345 @section @code{DBLE} --- Double conversion function
3347 @cindex conversion, to real
3350 @item @emph{Description}:
3351 @code{DBLE(A)} Converts @var{A} to double precision real type.
3353 @item @emph{Standard}:
3354 Fortran 77 and later
3359 @item @emph{Syntax}:
3360 @code{RESULT = DBLE(A)}
3362 @item @emph{Arguments}:
3363 @multitable @columnfractions .15 .70
3364 @item @var{A} @tab The type shall be @code{INTEGER}, @code{REAL},
3368 @item @emph{Return value}:
3369 The return value is of type double precision real.
3371 @item @emph{Example}:
3376 complex :: z = (2.3,1.14)
3377 print *, dble(x), dble(i), dble(z)
3378 end program test_dble
3381 @item @emph{See also}:
3388 @section @code{DCMPLX} --- Double complex conversion function
3390 @cindex complex numbers, conversion to
3391 @cindex conversion, to complex
3394 @item @emph{Description}:
3395 @code{DCMPLX(X [,Y])} returns a double complex number where @var{X} is
3396 converted to the real component. If @var{Y} is present it is converted to the
3397 imaginary component. If @var{Y} is not present then the imaginary component is
3398 set to 0.0. If @var{X} is complex then @var{Y} must not be present.
3400 @item @emph{Standard}:
3406 @item @emph{Syntax}:
3407 @code{RESULT = DCMPLX(X [, Y])}
3409 @item @emph{Arguments}:
3410 @multitable @columnfractions .15 .70
3411 @item @var{X} @tab The type may be @code{INTEGER}, @code{REAL},
3413 @item @var{Y} @tab (Optional if @var{X} is not @code{COMPLEX}.) May be
3414 @code{INTEGER} or @code{REAL}.
3417 @item @emph{Return value}:
3418 The return value is of type @code{COMPLEX(8)}
3420 @item @emph{Example}:
3430 print *, dcmplx(x,i)
3431 end program test_dcmplx
3437 @section @code{DIGITS} --- Significant binary digits function
3439 @cindex model representation, significant digits
3442 @item @emph{Description}:
3443 @code{DIGITS(X)} returns the number of significant binary digits of the internal
3444 model representation of @var{X}. For example, on a system using a 32-bit
3445 floating point representation, a default real number would likely return 24.
3447 @item @emph{Standard}:
3448 Fortran 95 and later
3453 @item @emph{Syntax}:
3454 @code{RESULT = DIGITS(X)}
3456 @item @emph{Arguments}:
3457 @multitable @columnfractions .15 .70
3458 @item @var{X} @tab The type may be @code{INTEGER} or @code{REAL}.
3461 @item @emph{Return value}:
3462 The return value is of type @code{INTEGER}.
3464 @item @emph{Example}:
3467 integer :: i = 12345
3473 end program test_digits
3480 @section @code{DIM} --- Positive difference
3484 @cindex positive difference
3487 @item @emph{Description}:
3488 @code{DIM(X,Y)} returns the difference @code{X-Y} if the result is positive;
3489 otherwise returns zero.
3491 @item @emph{Standard}:
3492 Fortran 77 and later
3497 @item @emph{Syntax}:
3498 @code{RESULT = DIM(X, Y)}
3500 @item @emph{Arguments}:
3501 @multitable @columnfractions .15 .70
3502 @item @var{X} @tab The type shall be @code{INTEGER} or @code{REAL}
3503 @item @var{Y} @tab The type shall be the same type and kind as @var{X}.
3506 @item @emph{Return value}:
3507 The return value is of type @code{INTEGER} or @code{REAL}.
3509 @item @emph{Example}:
3515 x = dim(4.345_8, 2.111_8)
3518 end program test_dim
3521 @item @emph{Specific names}:
3522 @multitable @columnfractions .20 .20 .20 .25
3523 @item Name @tab Argument @tab Return type @tab Standard
3524 @item @code{DIM(X,Y)} @tab @code{REAL(4) X, Y} @tab @code{REAL(4)} @tab Fortran 77 and later
3525 @item @code{IDIM(X,Y)} @tab @code{INTEGER(4) X, Y} @tab @code{INTEGER(4)} @tab Fortran 77 and later
3526 @item @code{DDIM(X,Y)} @tab @code{REAL(8) X, Y} @tab @code{REAL(8)} @tab Fortran 77 and later
3533 @section @code{DOT_PRODUCT} --- Dot product function
3534 @fnindex DOT_PRODUCT
3536 @cindex vector product
3537 @cindex product, vector
3540 @item @emph{Description}:
3541 @code{DOT_PRODUCT(VECTOR_A, VECTOR_B)} computes the dot product multiplication
3542 of two vectors @var{VECTOR_A} and @var{VECTOR_B}. The two vectors may be
3543 either numeric or logical and must be arrays of rank one and of equal size. If
3544 the vectors are @code{INTEGER} or @code{REAL}, the result is
3545 @code{SUM(VECTOR_A*VECTOR_B)}. If the vectors are @code{COMPLEX}, the result
3546 is @code{SUM(CONJG(VECTOR_A)*VECTOR_B)}. If the vectors are @code{LOGICAL},
3547 the result is @code{ANY(VECTOR_A .AND. VECTOR_B)}.
3549 @item @emph{Standard}:
3550 Fortran 95 and later
3553 Transformational function
3555 @item @emph{Syntax}:
3556 @code{RESULT = DOT_PRODUCT(VECTOR_A, VECTOR_B)}
3558 @item @emph{Arguments}:
3559 @multitable @columnfractions .15 .70
3560 @item @var{VECTOR_A} @tab The type shall be numeric or @code{LOGICAL}, rank 1.
3561 @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.
3564 @item @emph{Return value}:
3565 If the arguments are numeric, the return value is a scalar of numeric type,
3566 @code{INTEGER}, @code{REAL}, or @code{COMPLEX}. If the arguments are
3567 @code{LOGICAL}, the return value is @code{.TRUE.} or @code{.FALSE.}.
3569 @item @emph{Example}:
3571 program test_dot_prod
3572 integer, dimension(3) :: a, b
3579 print *, dot_product(a,b)
3580 end program test_dot_prod
3587 @section @code{DPROD} --- Double product function
3589 @cindex product, double-precision
3592 @item @emph{Description}:
3593 @code{DPROD(X,Y)} returns the product @code{X*Y}.
3595 @item @emph{Standard}:
3596 Fortran 77 and later
3601 @item @emph{Syntax}:
3602 @code{RESULT = DPROD(X, Y)}
3604 @item @emph{Arguments}:
3605 @multitable @columnfractions .15 .70
3606 @item @var{X} @tab The type shall be @code{REAL}.
3607 @item @var{Y} @tab The type shall be @code{REAL}.
3610 @item @emph{Return value}:
3611 The return value is of type @code{REAL(8)}.
3613 @item @emph{Example}:
3621 end program test_dprod
3624 @item @emph{Specific names}:
3625 @multitable @columnfractions .20 .20 .20 .25
3626 @item Name @tab Argument @tab Return type @tab Standard
3627 @item @code{DPROD(X,Y)} @tab @code{REAL(4) X, Y} @tab @code{REAL(4)} @tab Fortran 77 and later
3634 @section @code{DREAL} --- Double real part function
3636 @cindex complex numbers, real part
3639 @item @emph{Description}:
3640 @code{DREAL(Z)} returns the real part of complex variable @var{Z}.
3642 @item @emph{Standard}:
3648 @item @emph{Syntax}:
3649 @code{RESULT = DREAL(A)}
3651 @item @emph{Arguments}:
3652 @multitable @columnfractions .15 .70
3653 @item @var{A} @tab The type shall be @code{COMPLEX(8)}.
3656 @item @emph{Return value}:
3657 The return value is of type @code{REAL(8)}.
3659 @item @emph{Example}:
3662 complex(8) :: z = (1.3_8,7.2_8)
3664 end program test_dreal
3667 @item @emph{See also}:
3675 @section @code{DSHIFTL} --- Combined left shift
3677 @cindex left shift, combined
3681 @item @emph{Description}:
3682 @code{DSHIFTL(I, J, SHIFT)} combines bits of @var{I} and @var{J}. The
3683 rightmost @var{SHIFT} bits of the result are the leftmost @var{SHIFT}
3684 bits of @var{J}, and the remaining bits are the rightmost bits of
3687 @item @emph{Standard}:
3688 Fortran 2008 and later
3693 @item @emph{Syntax}:
3694 @code{RESULT = DSHIFTL(I, J, SHIFT)}
3696 @item @emph{Arguments}:
3697 @multitable @columnfractions .15 .70
3698 @item @var{I} @tab Shall be of type @code{INTEGER}.
3699 @item @var{J} @tab Shall be of type @code{INTEGER}, and of the same kind
3701 @item @var{SHIFT} @tab Shall be of type @code{INTEGER}.
3704 @item @emph{Return value}:
3705 The return value has same type and kind as @var{I}.
3707 @item @emph{See also}:
3715 @section @code{DSHIFTR} --- Combined right shift
3717 @cindex right shift, combined
3718 @cindex shift, right
3721 @item @emph{Description}:
3722 @code{DSHIFTR(I, J, SHIFT)} combines bits of @var{I} and @var{J}. The
3723 leftmost @var{SHIFT} bits of the result are the rightmost @var{SHIFT}
3724 bits of @var{I}, and the remaining bits are the leftmost bits of
3727 @item @emph{Standard}:
3728 Fortran 2008 and later
3733 @item @emph{Syntax}:
3734 @code{RESULT = DSHIFTR(I, J, SHIFT)}
3736 @item @emph{Arguments}:
3737 @multitable @columnfractions .15 .70
3738 @item @var{I} @tab Shall be of type @code{INTEGER}.
3739 @item @var{J} @tab Shall be of type @code{INTEGER}, and of the same kind
3741 @item @var{SHIFT} @tab Shall be of type @code{INTEGER}.
3744 @item @emph{Return value}:
3745 The return value has same type and kind as @var{I}.
3747 @item @emph{See also}:
3755 @section @code{DTIME} --- Execution time subroutine (or function)
3757 @cindex time, elapsed
3758 @cindex elapsed time
3761 @item @emph{Description}:
3762 @code{DTIME(VALUES, TIME)} initially returns the number of seconds of runtime
3763 since the start of the process's execution in @var{TIME}. @var{VALUES}
3764 returns the user and system components of this time in @code{VALUES(1)} and
3765 @code{VALUES(2)} respectively. @var{TIME} is equal to @code{VALUES(1) +
3768 Subsequent invocations of @code{DTIME} return values accumulated since the
3769 previous invocation.
3771 On some systems, the underlying timings are represented using types with
3772 sufficiently small limits that overflows (wrap around) are possible, such as
3773 32-bit types. Therefore, the values returned by this intrinsic might be, or
3774 become, negative, or numerically less than previous values, during a single
3775 run of the compiled program.
3777 Please note, that this implementation is thread safe if used within OpenMP
3778 directives, i.e., its state will be consistent while called from multiple
3779 threads. However, if @code{DTIME} is called from multiple threads, the result
3780 is still the time since the last invocation. This may not give the intended
3781 results. If possible, use @code{CPU_TIME} instead.
3783 This intrinsic is provided in both subroutine and function forms; however,
3784 only one form can be used in any given program unit.
3786 @var{VALUES} and @var{TIME} are @code{INTENT(OUT)} and provide the following:
3788 @multitable @columnfractions .15 .30 .40
3789 @item @tab @code{VALUES(1)}: @tab User time in seconds.
3790 @item @tab @code{VALUES(2)}: @tab System time in seconds.
3791 @item @tab @code{TIME}: @tab Run time since start in seconds.
3794 @item @emph{Standard}:
3798 Subroutine, function
3800 @item @emph{Syntax}:
3801 @multitable @columnfractions .80
3802 @item @code{CALL DTIME(VALUES, TIME)}.
3803 @item @code{TIME = DTIME(VALUES)}, (not recommended).
3806 @item @emph{Arguments}:
3807 @multitable @columnfractions .15 .70
3808 @item @var{VALUES}@tab The type shall be @code{REAL(4), DIMENSION(2)}.
3809 @item @var{TIME}@tab The type shall be @code{REAL(4)}.
3812 @item @emph{Return value}:
3813 Elapsed time in seconds since the last invocation or since the start of program
3814 execution if not called before.
3816 @item @emph{Example}:
3820 real, dimension(2) :: tarray
3822 call dtime(tarray, result)
3826 do i=1,100000000 ! Just a delay
3829 call dtime(tarray, result)
3833 end program test_dtime
3836 @item @emph{See also}:
3844 @section @code{EOSHIFT} --- End-off shift elements of an array
3846 @cindex array, shift
3849 @item @emph{Description}:
3850 @code{EOSHIFT(ARRAY, SHIFT[, BOUNDARY, DIM])} performs an end-off shift on
3851 elements of @var{ARRAY} along the dimension of @var{DIM}. If @var{DIM} is
3852 omitted it is taken to be @code{1}. @var{DIM} is a scalar of type
3853 @code{INTEGER} in the range of @math{1 \leq DIM \leq n)} where @math{n} is the
3854 rank of @var{ARRAY}. If the rank of @var{ARRAY} is one, then all elements of
3855 @var{ARRAY} are shifted by @var{SHIFT} places. If rank is greater than one,
3856 then all complete rank one sections of @var{ARRAY} along the given dimension are
3857 shifted. Elements shifted out one end of each rank one section are dropped. If
3858 @var{BOUNDARY} is present then the corresponding value of from @var{BOUNDARY}
3859 is copied back in the other end. If @var{BOUNDARY} is not present then the
3860 following are copied in depending on the type of @var{ARRAY}.
3862 @multitable @columnfractions .15 .80
3863 @item @emph{Array Type} @tab @emph{Boundary Value}
3864 @item Numeric @tab 0 of the type and kind of @var{ARRAY}.
3865 @item Logical @tab @code{.FALSE.}.
3866 @item Character(@var{len}) @tab @var{len} blanks.
3869 @item @emph{Standard}:
3870 Fortran 95 and later
3873 Transformational function
3875 @item @emph{Syntax}:
3876 @code{RESULT = EOSHIFT(ARRAY, SHIFT [, BOUNDARY, DIM])}
3878 @item @emph{Arguments}:
3879 @multitable @columnfractions .15 .70
3880 @item @var{ARRAY} @tab May be any type, not scalar.
3881 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
3882 @item @var{BOUNDARY} @tab Same type as @var{ARRAY}.
3883 @item @var{DIM} @tab The type shall be @code{INTEGER}.
3886 @item @emph{Return value}:
3887 Returns an array of same type and rank as the @var{ARRAY} argument.
3889 @item @emph{Example}:
3891 program test_eoshift
3892 integer, dimension(3,3) :: a
3893 a = reshape( (/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /), (/ 3, 3 /))
3894 print '(3i3)', a(1,:)
3895 print '(3i3)', a(2,:)
3896 print '(3i3)', a(3,:)
3897 a = EOSHIFT(a, SHIFT=(/1, 2, 1/), BOUNDARY=-5, DIM=2)
3899 print '(3i3)', a(1,:)
3900 print '(3i3)', a(2,:)
3901 print '(3i3)', a(3,:)
3902 end program test_eoshift
3909 @section @code{EPSILON} --- Epsilon function
3911 @cindex model representation, epsilon
3914 @item @emph{Description}:
3915 @code{EPSILON(X)} returns the smallest number @var{E} of the same kind
3916 as @var{X} such that @math{1 + E > 1}.
3918 @item @emph{Standard}:
3919 Fortran 95 and later
3924 @item @emph{Syntax}:
3925 @code{RESULT = EPSILON(X)}
3927 @item @emph{Arguments}:
3928 @multitable @columnfractions .15 .70
3929 @item @var{X} @tab The type shall be @code{REAL}.
3932 @item @emph{Return value}:
3933 The return value is of same type as the argument.
3935 @item @emph{Example}:
3937 program test_epsilon
3942 end program test_epsilon
3949 @section @code{ERF} --- Error function
3951 @cindex error function
3954 @item @emph{Description}:
3955 @code{ERF(X)} computes the error function of @var{X}.
3957 @item @emph{Standard}:
3958 Fortran 2008 and later
3963 @item @emph{Syntax}:
3964 @code{RESULT = ERF(X)}
3966 @item @emph{Arguments}:
3967 @multitable @columnfractions .15 .70
3968 @item @var{X} @tab The type shall be @code{REAL}.
3971 @item @emph{Return value}:
3972 The return value is of type @code{REAL}, of the same kind as
3973 @var{X} and lies in the range @math{-1 \leq erf (x) \leq 1 }.
3975 @item @emph{Example}:
3978 real(8) :: x = 0.17_8
3980 end program test_erf
3983 @item @emph{Specific names}:
3984 @multitable @columnfractions .20 .20 .20 .25
3985 @item Name @tab Argument @tab Return type @tab Standard
3986 @item @code{DERF(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
3993 @section @code{ERFC} --- Error function
3995 @cindex error function, complementary
3998 @item @emph{Description}:
3999 @code{ERFC(X)} computes the complementary error function of @var{X}.
4001 @item @emph{Standard}:
4002 Fortran 2008 and later
4007 @item @emph{Syntax}:
4008 @code{RESULT = ERFC(X)}
4010 @item @emph{Arguments}:
4011 @multitable @columnfractions .15 .70
4012 @item @var{X} @tab The type shall be @code{REAL}.
4015 @item @emph{Return value}:
4016 The return value is of type @code{REAL} and of the same kind as @var{X}.
4017 It lies in the range @math{ 0 \leq erfc (x) \leq 2 }.
4019 @item @emph{Example}:
4022 real(8) :: x = 0.17_8
4024 end program test_erfc
4027 @item @emph{Specific names}:
4028 @multitable @columnfractions .20 .20 .20 .25
4029 @item Name @tab Argument @tab Return type @tab Standard
4030 @item @code{DERFC(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
4037 @section @code{ERFC_SCALED} --- Error function
4038 @fnindex ERFC_SCALED
4039 @cindex error function, complementary, exponentially-scaled
4042 @item @emph{Description}:
4043 @code{ERFC_SCALED(X)} computes the exponentially-scaled complementary
4044 error function of @var{X}.
4046 @item @emph{Standard}:
4047 Fortran 2008 and later
4052 @item @emph{Syntax}:
4053 @code{RESULT = ERFC_SCALED(X)}
4055 @item @emph{Arguments}:
4056 @multitable @columnfractions .15 .70
4057 @item @var{X} @tab The type shall be @code{REAL}.
4060 @item @emph{Return value}:
4061 The return value is of type @code{REAL} and of the same kind as @var{X}.
4063 @item @emph{Example}:
4065 program test_erfc_scaled
4066 real(8) :: x = 0.17_8
4068 end program test_erfc_scaled
4075 @section @code{ETIME} --- Execution time subroutine (or function)
4077 @cindex time, elapsed
4080 @item @emph{Description}:
4081 @code{ETIME(VALUES, TIME)} returns the number of seconds of runtime
4082 since the start of the process's execution in @var{TIME}. @var{VALUES}
4083 returns the user and system components of this time in @code{VALUES(1)} and
4084 @code{VALUES(2)} respectively. @var{TIME} is equal to @code{VALUES(1) + VALUES(2)}.
4086 On some systems, the underlying timings are represented using types with
4087 sufficiently small limits that overflows (wrap around) are possible, such as
4088 32-bit types. Therefore, the values returned by this intrinsic might be, or
4089 become, negative, or numerically less than previous values, during a single
4090 run of the compiled program.
4092 This intrinsic is provided in both subroutine and function forms; however,
4093 only one form can be used in any given program unit.
4095 @var{VALUES} and @var{TIME} are @code{INTENT(OUT)} and provide the following:
4097 @multitable @columnfractions .15 .30 .60
4098 @item @tab @code{VALUES(1)}: @tab User time in seconds.
4099 @item @tab @code{VALUES(2)}: @tab System time in seconds.
4100 @item @tab @code{TIME}: @tab Run time since start in seconds.
4103 @item @emph{Standard}:
4107 Subroutine, function
4109 @item @emph{Syntax}:
4110 @multitable @columnfractions .80
4111 @item @code{CALL ETIME(VALUES, TIME)}.
4112 @item @code{TIME = ETIME(VALUES)}, (not recommended).
4115 @item @emph{Arguments}:
4116 @multitable @columnfractions .15 .70
4117 @item @var{VALUES}@tab The type shall be @code{REAL(4), DIMENSION(2)}.
4118 @item @var{TIME}@tab The type shall be @code{REAL(4)}.
4121 @item @emph{Return value}:
4122 Elapsed time in seconds since the start of program execution.
4124 @item @emph{Example}:
4128 real, dimension(2) :: tarray
4130 call ETIME(tarray, result)
4134 do i=1,100000000 ! Just a delay
4137 call ETIME(tarray, result)
4141 end program test_etime
4144 @item @emph{See also}:
4151 @node EXECUTE_COMMAND_LINE
4152 @section @code{EXECUTE_COMMAND_LINE} --- Execute a shell command
4153 @fnindex EXECUTE_COMMAND_LINE
4154 @cindex system, system call
4155 @cindex command line
4158 @item @emph{Description}:
4159 @code{EXECUTE_COMMAND_LINE} runs a shell command, synchronously or
4162 The @code{COMMAND} argument is passed to the shell and executed, using
4163 the C library's @code{system} call. (The shell is @code{sh} on Unix
4164 systems, and @code{cmd.exe} on Windows.) If @code{WAIT} is present
4165 and has the value false, the execution of the command is asynchronous
4166 if the system supports it; otherwise, the command is executed
4169 The three last arguments allow the user to get status information. After
4170 synchronous execution, @code{EXITSTAT} contains the integer exit code of
4171 the command, as returned by @code{system}. @code{CMDSTAT} is set to zero
4172 if the command line was executed (whatever its exit status was).
4173 @code{CMDMSG} is assigned an error message if an error has occurred.
4175 Note that the @code{system} function need not be thread-safe. It is
4176 the responsibility of the user to ensure that @code{system} is not
4177 called concurrently.
4179 @item @emph{Standard}:
4180 Fortran 2008 and later
4185 @item @emph{Syntax}:
4186 @code{CALL EXECUTE_COMMAND_LINE(COMMAND [, WAIT, EXITSTAT, CMDSTAT, CMDMSG ])}
4188 @item @emph{Arguments}:
4189 @multitable @columnfractions .15 .70
4190 @item @var{COMMAND} @tab Shall be a default @code{CHARACTER} scalar.
4191 @item @var{WAIT} @tab (Optional) Shall be a default @code{LOGICAL} scalar.
4192 @item @var{EXITSTAT} @tab (Optional) Shall be an @code{INTEGER} of the
4194 @item @var{CMDSTAT} @tab (Optional) Shall be an @code{INTEGER} of the
4196 @item @var{CMDMSG} @tab (Optional) Shall be an @code{CHARACTER} scalar of the
4200 @item @emph{Example}:
4205 call execute_command_line ("external_prog.exe", exitstat=i)
4206 print *, "Exit status of external_prog.exe was ", i
4208 call execute_command_line ("reindex_files.exe", wait=.false.)
4209 print *, "Now reindexing files in the background"
4211 end program test_exec
4217 Because this intrinsic is implemented in terms of the @code{system}
4218 function call, its behavior with respect to signaling is processor
4219 dependent. In particular, on POSIX-compliant systems, the SIGINT and
4220 SIGQUIT signals will be ignored, and the SIGCHLD will be blocked. As
4221 such, if the parent process is terminated, the child process might not be
4222 terminated alongside.
4225 @item @emph{See also}:
4232 @section @code{EXIT} --- Exit the program with status.
4234 @cindex program termination
4235 @cindex terminate program
4238 @item @emph{Description}:
4239 @code{EXIT} causes immediate termination of the program with status. If status
4240 is omitted it returns the canonical @emph{success} for the system. All Fortran
4241 I/O units are closed.
4243 @item @emph{Standard}:
4249 @item @emph{Syntax}:
4250 @code{CALL EXIT([STATUS])}
4252 @item @emph{Arguments}:
4253 @multitable @columnfractions .15 .70
4254 @item @var{STATUS} @tab Shall be an @code{INTEGER} of the default kind.
4257 @item @emph{Return value}:
4258 @code{STATUS} is passed to the parent process on exit.
4260 @item @emph{Example}:
4263 integer :: STATUS = 0
4264 print *, 'This program is going to exit.'
4266 end program test_exit
4269 @item @emph{See also}:
4270 @ref{ABORT}, @ref{KILL}
4276 @section @code{EXP} --- Exponential function
4282 @cindex exponential function
4283 @cindex logarithmic function, inverse
4286 @item @emph{Description}:
4287 @code{EXP(X)} computes the base @math{e} exponential of @var{X}.
4289 @item @emph{Standard}:
4290 Fortran 77 and later, has overloads that are GNU extensions
4295 @item @emph{Syntax}:
4296 @code{RESULT = EXP(X)}
4298 @item @emph{Arguments}:
4299 @multitable @columnfractions .15 .70
4300 @item @var{X} @tab The type shall be @code{REAL} or
4304 @item @emph{Return value}:
4305 The return value has same type and kind as @var{X}.
4307 @item @emph{Example}:
4312 end program test_exp
4315 @item @emph{Specific names}:
4316 @multitable @columnfractions .20 .20 .20 .25
4317 @item Name @tab Argument @tab Return type @tab Standard
4318 @item @code{EXP(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
4319 @item @code{DEXP(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
4320 @item @code{CEXP(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab Fortran 77 and later
4321 @item @code{ZEXP(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
4322 @item @code{CDEXP(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
4329 @section @code{EXPONENT} --- Exponent function
4331 @cindex real number, exponent
4332 @cindex floating point, exponent
4335 @item @emph{Description}:
4336 @code{EXPONENT(X)} returns the value of the exponent part of @var{X}. If @var{X}
4337 is zero the value returned is zero.
4339 @item @emph{Standard}:
4340 Fortran 95 and later
4345 @item @emph{Syntax}:
4346 @code{RESULT = EXPONENT(X)}
4348 @item @emph{Arguments}:
4349 @multitable @columnfractions .15 .70
4350 @item @var{X} @tab The type shall be @code{REAL}.
4353 @item @emph{Return value}:
4354 The return value is of type default @code{INTEGER}.
4356 @item @emph{Example}:
4358 program test_exponent
4363 print *, exponent(0.0)
4364 end program test_exponent
4370 @node EXTENDS_TYPE_OF
4371 @section @code{EXTENDS_TYPE_OF} --- Query dynamic type for extension
4372 @fnindex EXTENDS_TYPE_OF
4375 @item @emph{Description}:
4376 Query dynamic type for extension.
4378 @item @emph{Standard}:
4379 Fortran 2003 and later
4384 @item @emph{Syntax}:
4385 @code{RESULT = EXTENDS_TYPE_OF(A, MOLD)}
4387 @item @emph{Arguments}:
4388 @multitable @columnfractions .15 .70
4389 @item @var{A} @tab Shall be an object of extensible declared type or
4390 unlimited polymorphic.
4391 @item @var{MOLD} @tab Shall be an object of extensible declared type or
4392 unlimited polymorphic.
4395 @item @emph{Return value}:
4396 The return value is a scalar of type default logical. It is true if and only if
4397 the dynamic type of A is an extension type of the dynamic type of MOLD.
4400 @item @emph{See also}:
4407 @section @code{FDATE} --- Get the current time as a string
4409 @cindex time, current
4410 @cindex current time
4411 @cindex date, current
4412 @cindex current date
4415 @item @emph{Description}:
4416 @code{FDATE(DATE)} returns the current date (using the same format as
4417 @code{CTIME}) in @var{DATE}. It is equivalent to @code{CALL CTIME(DATE,
4420 This intrinsic is provided in both subroutine and function forms; however,
4421 only one form can be used in any given program unit.
4423 @var{DATE} is an @code{INTENT(OUT)} @code{CHARACTER} variable of the
4426 @item @emph{Standard}:
4430 Subroutine, function
4432 @item @emph{Syntax}:
4433 @multitable @columnfractions .80
4434 @item @code{CALL FDATE(DATE)}.
4435 @item @code{DATE = FDATE()}, (not recommended).
4438 @item @emph{Arguments}:
4439 @multitable @columnfractions .15 .70
4440 @item @var{DATE}@tab The type shall be of type @code{CHARACTER} of the
4444 @item @emph{Return value}:
4445 The current date as a string.
4447 @item @emph{Example}:
4451 character(len=30) :: date
4453 print *, 'Program started on ', date
4454 do i = 1, 100000000 ! Just a delay
4458 print *, 'Program ended on ', date
4459 end program test_fdate
4466 @section @code{FGET} --- Read a single character in stream mode from stdin
4468 @cindex read character, stream mode
4469 @cindex stream mode, read character
4470 @cindex file operation, read character
4473 @item @emph{Description}:
4474 Read a single character in stream mode from stdin by bypassing normal
4475 formatted output. Stream I/O should not be mixed with normal record-oriented
4476 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
4478 This intrinsic is provided in both subroutine and function forms; however,
4479 only one form can be used in any given program unit.
4481 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
4482 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
4483 Programmers should consider the use of new stream IO feature in new code
4484 for future portability. See also @ref{Fortran 2003 status}.
4486 @item @emph{Standard}:
4490 Subroutine, function
4492 @item @emph{Syntax}:
4493 @multitable @columnfractions .80
4494 @item @code{CALL FGET(C [, STATUS])}
4495 @item @code{STATUS = FGET(C)}
4498 @item @emph{Arguments}:
4499 @multitable @columnfractions .15 .70
4500 @item @var{C} @tab The type shall be @code{CHARACTER} and of default
4502 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
4503 Returns 0 on success, -1 on end-of-file, and a system specific positive
4504 error code otherwise.
4507 @item @emph{Example}:
4510 INTEGER, PARAMETER :: strlen = 100
4511 INTEGER :: status, i = 1
4512 CHARACTER(len=strlen) :: str = ""
4514 WRITE (*,*) 'Enter text:'
4516 CALL fget(str(i:i), status)
4517 if (status /= 0 .OR. i > strlen) exit
4520 WRITE (*,*) TRIM(str)
4524 @item @emph{See also}:
4525 @ref{FGETC}, @ref{FPUT}, @ref{FPUTC}
4531 @section @code{FGETC} --- Read a single character in stream mode
4533 @cindex read character, stream mode
4534 @cindex stream mode, read character
4535 @cindex file operation, read character
4538 @item @emph{Description}:
4539 Read a single character in stream mode by bypassing normal formatted output.
4540 Stream I/O should not be mixed with normal record-oriented (formatted or
4541 unformatted) I/O on the same unit; the results are unpredictable.
4543 This intrinsic is provided in both subroutine and function forms; however,
4544 only one form can be used in any given program unit.
4546 Note that the @code{FGET} intrinsic is provided for backwards compatibility
4547 with @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
4548 Programmers should consider the use of new stream IO feature in new code
4549 for future portability. See also @ref{Fortran 2003 status}.
4551 @item @emph{Standard}:
4555 Subroutine, function
4557 @item @emph{Syntax}:
4558 @multitable @columnfractions .80
4559 @item @code{CALL FGETC(UNIT, C [, STATUS])}
4560 @item @code{STATUS = FGETC(UNIT, C)}
4563 @item @emph{Arguments}:
4564 @multitable @columnfractions .15 .70
4565 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
4566 @item @var{C} @tab The type shall be @code{CHARACTER} and of default
4568 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
4569 Returns 0 on success, -1 on end-of-file and a system specific positive
4570 error code otherwise.
4573 @item @emph{Example}:
4576 INTEGER :: fd = 42, status
4579 OPEN(UNIT=fd, FILE="/etc/passwd", ACTION="READ", STATUS = "OLD")
4581 CALL fgetc(fd, c, status)
4582 IF (status /= 0) EXIT
4589 @item @emph{See also}:
4590 @ref{FGET}, @ref{FPUT}, @ref{FPUTC}
4596 @section @code{FLOOR} --- Integer floor function
4599 @cindex rounding, floor
4602 @item @emph{Description}:
4603 @code{FLOOR(A)} returns the greatest integer less than or equal to @var{X}.
4605 @item @emph{Standard}:
4606 Fortran 95 and later
4611 @item @emph{Syntax}:
4612 @code{RESULT = FLOOR(A [, KIND])}
4614 @item @emph{Arguments}:
4615 @multitable @columnfractions .15 .70
4616 @item @var{A} @tab The type shall be @code{REAL}.
4617 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
4618 expression indicating the kind parameter of the result.
4621 @item @emph{Return value}:
4622 The return value is of type @code{INTEGER(KIND)} if @var{KIND} is present
4623 and of default-kind @code{INTEGER} otherwise.
4625 @item @emph{Example}:
4630 print *, floor(x) ! returns 63
4631 print *, floor(y) ! returns -64
4632 end program test_floor
4635 @item @emph{See also}:
4636 @ref{CEILING}, @ref{NINT}
4643 @section @code{FLUSH} --- Flush I/O unit(s)
4645 @cindex file operation, flush
4648 @item @emph{Description}:
4649 Flushes Fortran unit(s) currently open for output. Without the optional
4650 argument, all units are flushed, otherwise just the unit specified.
4652 @item @emph{Standard}:
4658 @item @emph{Syntax}:
4659 @code{CALL FLUSH(UNIT)}
4661 @item @emph{Arguments}:
4662 @multitable @columnfractions .15 .70
4663 @item @var{UNIT} @tab (Optional) The type shall be @code{INTEGER}.
4667 Beginning with the Fortran 2003 standard, there is a @code{FLUSH}
4668 statement that should be preferred over the @code{FLUSH} intrinsic.
4670 The @code{FLUSH} intrinsic and the Fortran 2003 @code{FLUSH} statement
4671 have identical effect: they flush the runtime library's I/O buffer so
4672 that the data becomes visible to other processes. This does not guarantee
4673 that the data is committed to disk.
4675 On POSIX systems, you can request that all data is transferred to the
4676 storage device by calling the @code{fsync} function, with the POSIX file
4677 descriptor of the I/O unit as argument (retrieved with GNU intrinsic
4678 @code{FNUM}). The following example shows how:
4681 ! Declare the interface for POSIX fsync function
4683 function fsync (fd) bind(c,name="fsync")
4684 use iso_c_binding, only: c_int
4685 integer(c_int), value :: fd
4686 integer(c_int) :: fsync
4690 ! Variable declaration
4694 open (10,file="foo")
4697 ! Perform I/O on unit 10
4702 ret = fsync(fnum(10))
4704 ! Handle possible error
4705 if (ret /= 0) stop "Error calling FSYNC"
4713 @section @code{FNUM} --- File number function
4715 @cindex file operation, file number
4718 @item @emph{Description}:
4719 @code{FNUM(UNIT)} returns the POSIX file descriptor number corresponding to the
4720 open Fortran I/O unit @code{UNIT}.
4722 @item @emph{Standard}:
4728 @item @emph{Syntax}:
4729 @code{RESULT = FNUM(UNIT)}
4731 @item @emph{Arguments}:
4732 @multitable @columnfractions .15 .70
4733 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
4736 @item @emph{Return value}:
4737 The return value is of type @code{INTEGER}
4739 @item @emph{Example}:
4743 open (unit=10, status = "scratch")
4747 end program test_fnum
4754 @section @code{FPUT} --- Write a single character in stream mode to stdout
4756 @cindex write character, stream mode
4757 @cindex stream mode, write character
4758 @cindex file operation, write character
4761 @item @emph{Description}:
4762 Write a single character in stream mode to stdout by bypassing normal
4763 formatted output. Stream I/O should not be mixed with normal record-oriented
4764 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
4766 This intrinsic is provided in both subroutine and function forms; however,
4767 only one form can be used in any given program unit.
4769 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
4770 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
4771 Programmers should consider the use of new stream IO feature in new code
4772 for future portability. See also @ref{Fortran 2003 status}.
4774 @item @emph{Standard}:
4778 Subroutine, function
4780 @item @emph{Syntax}:
4781 @multitable @columnfractions .80
4782 @item @code{CALL FPUT(C [, STATUS])}
4783 @item @code{STATUS = FPUT(C)}
4786 @item @emph{Arguments}:
4787 @multitable @columnfractions .15 .70
4788 @item @var{C} @tab The type shall be @code{CHARACTER} and of default
4790 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
4791 Returns 0 on success, -1 on end-of-file and a system specific positive
4792 error code otherwise.
4795 @item @emph{Example}:
4798 CHARACTER(len=10) :: str = "gfortran"
4800 DO i = 1, len_trim(str)
4806 @item @emph{See also}:
4807 @ref{FPUTC}, @ref{FGET}, @ref{FGETC}
4813 @section @code{FPUTC} --- Write a single character in stream mode
4815 @cindex write character, stream mode
4816 @cindex stream mode, write character
4817 @cindex file operation, write character
4820 @item @emph{Description}:
4821 Write a single character in stream mode by bypassing normal formatted
4822 output. Stream I/O should not be mixed with normal record-oriented
4823 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
4825 This intrinsic is provided in both subroutine and function forms; however,
4826 only one form can be used in any given program unit.
4828 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
4829 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
4830 Programmers should consider the use of new stream IO feature in new code
4831 for future portability. See also @ref{Fortran 2003 status}.
4833 @item @emph{Standard}:
4837 Subroutine, function
4839 @item @emph{Syntax}:
4840 @multitable @columnfractions .80
4841 @item @code{CALL FPUTC(UNIT, C [, STATUS])}
4842 @item @code{STATUS = FPUTC(UNIT, C)}
4845 @item @emph{Arguments}:
4846 @multitable @columnfractions .15 .70
4847 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
4848 @item @var{C} @tab The type shall be @code{CHARACTER} and of default
4850 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
4851 Returns 0 on success, -1 on end-of-file and a system specific positive
4852 error code otherwise.
4855 @item @emph{Example}:
4858 CHARACTER(len=10) :: str = "gfortran"
4859 INTEGER :: fd = 42, i
4861 OPEN(UNIT = fd, FILE = "out", ACTION = "WRITE", STATUS="NEW")
4862 DO i = 1, len_trim(str)
4863 CALL fputc(fd, str(i:i))
4869 @item @emph{See also}:
4870 @ref{FPUT}, @ref{FGET}, @ref{FGETC}
4876 @section @code{FRACTION} --- Fractional part of the model representation
4878 @cindex real number, fraction
4879 @cindex floating point, fraction
4882 @item @emph{Description}:
4883 @code{FRACTION(X)} returns the fractional part of the model
4884 representation of @code{X}.
4886 @item @emph{Standard}:
4887 Fortran 95 and later
4892 @item @emph{Syntax}:
4893 @code{Y = FRACTION(X)}
4895 @item @emph{Arguments}:
4896 @multitable @columnfractions .15 .70
4897 @item @var{X} @tab The type of the argument shall be a @code{REAL}.
4900 @item @emph{Return value}:
4901 The return value is of the same type and kind as the argument.
4902 The fractional part of the model representation of @code{X} is returned;
4903 it is @code{X * RADIX(X)**(-EXPONENT(X))}.
4905 @item @emph{Example}:
4907 program test_fraction
4910 print *, fraction(x), x * radix(x)**(-exponent(x))
4911 end program test_fraction
4919 @section @code{FREE} --- Frees memory
4921 @cindex pointer, cray
4924 @item @emph{Description}:
4925 Frees memory previously allocated by @code{MALLOC}. The @code{FREE}
4926 intrinsic is an extension intended to be used with Cray pointers, and is
4927 provided in GNU Fortran to allow user to compile legacy code. For
4928 new code using Fortran 95 pointers, the memory de-allocation intrinsic is
4931 @item @emph{Standard}:
4937 @item @emph{Syntax}:
4938 @code{CALL FREE(PTR)}
4940 @item @emph{Arguments}:
4941 @multitable @columnfractions .15 .70
4942 @item @var{PTR} @tab The type shall be @code{INTEGER}. It represents the
4943 location of the memory that should be de-allocated.
4946 @item @emph{Return value}:
4949 @item @emph{Example}:
4950 See @code{MALLOC} for an example.
4952 @item @emph{See also}:
4959 @section @code{FSEEK} --- Low level file positioning subroutine
4961 @cindex file operation, seek
4962 @cindex file operation, position
4965 @item @emph{Description}:
4966 Moves @var{UNIT} to the specified @var{OFFSET}. If @var{WHENCE}
4967 is set to 0, the @var{OFFSET} is taken as an absolute value @code{SEEK_SET},
4968 if set to 1, @var{OFFSET} is taken to be relative to the current position
4969 @code{SEEK_CUR}, and if set to 2 relative to the end of the file @code{SEEK_END}.
4970 On error, @var{STATUS} is set to a nonzero value. If @var{STATUS} the seek
4973 This intrinsic routine is not fully backwards compatible with @command{g77}.
4974 In @command{g77}, the @code{FSEEK} takes a statement label instead of a
4975 @var{STATUS} variable. If FSEEK is used in old code, change
4977 CALL FSEEK(UNIT, OFFSET, WHENCE, *label)
4982 CALL FSEEK(UNIT, OFFSET, WHENCE, status)
4983 IF (status /= 0) GOTO label
4986 Please note that GNU Fortran provides the Fortran 2003 Stream facility.
4987 Programmers should consider the use of new stream IO feature in new code
4988 for future portability. See also @ref{Fortran 2003 status}.
4990 @item @emph{Standard}:
4996 @item @emph{Syntax}:
4997 @code{CALL FSEEK(UNIT, OFFSET, WHENCE[, STATUS])}
4999 @item @emph{Arguments}:
5000 @multitable @columnfractions .15 .70
5001 @item @var{UNIT} @tab Shall be a scalar of type @code{INTEGER}.
5002 @item @var{OFFSET} @tab Shall be a scalar of type @code{INTEGER}.
5003 @item @var{WHENCE} @tab Shall be a scalar of type @code{INTEGER}.
5004 Its value shall be either 0, 1 or 2.
5005 @item @var{STATUS} @tab (Optional) shall be a scalar of type
5009 @item @emph{Example}:
5012 INTEGER, PARAMETER :: SEEK_SET = 0, SEEK_CUR = 1, SEEK_END = 2
5013 INTEGER :: fd, offset, ierr
5019 OPEN(UNIT=fd, FILE="fseek.test")
5020 CALL FSEEK(fd, offset, SEEK_SET, ierr) ! move to OFFSET
5021 print *, FTELL(fd), ierr
5023 CALL FSEEK(fd, 0, SEEK_END, ierr) ! move to end
5024 print *, FTELL(fd), ierr
5026 CALL FSEEK(fd, 0, SEEK_SET, ierr) ! move to beginning
5027 print *, FTELL(fd), ierr
5033 @item @emph{See also}:
5040 @section @code{FSTAT} --- Get file status
5042 @cindex file system, file status
5045 @item @emph{Description}:
5046 @code{FSTAT} is identical to @ref{STAT}, except that information about an
5047 already opened file is obtained.
5049 The elements in @code{VALUES} are the same as described by @ref{STAT}.
5051 This intrinsic is provided in both subroutine and function forms; however,
5052 only one form can be used in any given program unit.
5054 @item @emph{Standard}:
5058 Subroutine, function
5060 @item @emph{Syntax}:
5061 @multitable @columnfractions .80
5062 @item @code{CALL FSTAT(UNIT, VALUES [, STATUS])}
5063 @item @code{STATUS = FSTAT(UNIT, VALUES)}
5066 @item @emph{Arguments}:
5067 @multitable @columnfractions .15 .70
5068 @item @var{UNIT} @tab An open I/O unit number of type @code{INTEGER}.
5069 @item @var{VALUES} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
5070 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}. Returns 0
5071 on success and a system specific error code otherwise.
5074 @item @emph{Example}:
5075 See @ref{STAT} for an example.
5077 @item @emph{See also}:
5078 To stat a link: @ref{LSTAT}, to stat a file: @ref{STAT}
5084 @section @code{FTELL} --- Current stream position
5086 @cindex file operation, position
5089 @item @emph{Description}:
5090 Retrieves the current position within an open file.
5092 This intrinsic is provided in both subroutine and function forms; however,
5093 only one form can be used in any given program unit.
5095 @item @emph{Standard}:
5099 Subroutine, function
5101 @item @emph{Syntax}:
5102 @multitable @columnfractions .80
5103 @item @code{CALL FTELL(UNIT, OFFSET)}
5104 @item @code{OFFSET = FTELL(UNIT)}
5107 @item @emph{Arguments}:
5108 @multitable @columnfractions .15 .70
5109 @item @var{OFFSET} @tab Shall of type @code{INTEGER}.
5110 @item @var{UNIT} @tab Shall of type @code{INTEGER}.
5113 @item @emph{Return value}:
5114 In either syntax, @var{OFFSET} is set to the current offset of unit
5115 number @var{UNIT}, or to @math{-1} if the unit is not currently open.
5117 @item @emph{Example}:
5121 OPEN(10, FILE="temp.dat")
5127 @item @emph{See also}:
5134 @section @code{GAMMA} --- Gamma function
5137 @cindex Gamma function
5138 @cindex Factorial function
5141 @item @emph{Description}:
5142 @code{GAMMA(X)} computes Gamma (@math{\Gamma}) of @var{X}. For positive,
5143 integer values of @var{X} the Gamma function simplifies to the factorial
5144 function @math{\Gamma(x)=(x-1)!}.
5148 \Gamma(x) = \int_0^\infty t^{x-1}{\rm e}^{-t}\,{\rm d}t
5152 @item @emph{Standard}:
5153 Fortran 2008 and later
5158 @item @emph{Syntax}:
5161 @item @emph{Arguments}:
5162 @multitable @columnfractions .15 .70
5163 @item @var{X} @tab Shall be of type @code{REAL} and neither zero
5164 nor a negative integer.
5167 @item @emph{Return value}:
5168 The return value is of type @code{REAL} of the same kind as @var{X}.
5170 @item @emph{Example}:
5174 x = gamma(x) ! returns 1.0
5175 end program test_gamma
5178 @item @emph{Specific names}:
5179 @multitable @columnfractions .20 .20 .20 .25
5180 @item Name @tab Argument @tab Return type @tab Standard
5181 @item @code{GAMMA(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab GNU Extension
5182 @item @code{DGAMMA(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU Extension
5185 @item @emph{See also}:
5186 Logarithm of the Gamma function: @ref{LOG_GAMMA}
5193 @section @code{GERROR} --- Get last system error message
5195 @cindex system, error handling
5198 @item @emph{Description}:
5199 Returns the system error message corresponding to the last system error.
5200 This resembles the functionality of @code{strerror(3)} in C.
5202 @item @emph{Standard}:
5208 @item @emph{Syntax}:
5209 @code{CALL GERROR(RESULT)}
5211 @item @emph{Arguments}:
5212 @multitable @columnfractions .15 .70
5213 @item @var{RESULT} @tab Shall of type @code{CHARACTER} and of default
5216 @item @emph{Example}:
5219 CHARACTER(len=100) :: msg
5225 @item @emph{See also}:
5226 @ref{IERRNO}, @ref{PERROR}
5232 @section @code{GETARG} --- Get command line arguments
5234 @cindex command-line arguments
5235 @cindex arguments, to program
5238 @item @emph{Description}:
5239 Retrieve the @var{POS}-th argument that was passed on the
5240 command line when the containing program was invoked.
5242 This intrinsic routine is provided for backwards compatibility with
5243 GNU Fortran 77. In new code, programmers should consider the use of
5244 the @ref{GET_COMMAND_ARGUMENT} intrinsic defined by the Fortran 2003
5247 @item @emph{Standard}:
5253 @item @emph{Syntax}:
5254 @code{CALL GETARG(POS, VALUE)}
5256 @item @emph{Arguments}:
5257 @multitable @columnfractions .15 .70
5258 @item @var{POS} @tab Shall be of type @code{INTEGER} and not wider than
5259 the default integer kind; @math{@var{POS} \geq 0}
5260 @item @var{VALUE} @tab Shall be of type @code{CHARACTER} and of default
5262 @item @var{VALUE} @tab Shall be of type @code{CHARACTER}.
5265 @item @emph{Return value}:
5266 After @code{GETARG} returns, the @var{VALUE} argument holds the
5267 @var{POS}th command line argument. If @var{VALUE} can not hold the
5268 argument, it is truncated to fit the length of @var{VALUE}. If there are
5269 less than @var{POS} arguments specified at the command line, @var{VALUE}
5270 will be filled with blanks. If @math{@var{POS} = 0}, @var{VALUE} is set
5271 to the name of the program (on systems that support this feature).
5273 @item @emph{Example}:
5277 CHARACTER(len=32) :: arg
5286 @item @emph{See also}:
5287 GNU Fortran 77 compatibility function: @ref{IARGC}
5289 Fortran 2003 functions and subroutines: @ref{GET_COMMAND},
5290 @ref{GET_COMMAND_ARGUMENT}, @ref{COMMAND_ARGUMENT_COUNT}
5296 @section @code{GET_COMMAND} --- Get the entire command line
5297 @fnindex GET_COMMAND
5298 @cindex command-line arguments
5299 @cindex arguments, to program
5302 @item @emph{Description}:
5303 Retrieve the entire command line that was used to invoke the program.
5305 @item @emph{Standard}:
5306 Fortran 2003 and later
5311 @item @emph{Syntax}:
5312 @code{CALL GET_COMMAND([COMMAND, LENGTH, STATUS])}
5314 @item @emph{Arguments}:
5315 @multitable @columnfractions .15 .70
5316 @item @var{COMMAND} @tab (Optional) shall be of type @code{CHARACTER} and
5318 @item @var{LENGTH} @tab (Optional) Shall be of type @code{INTEGER} and of
5320 @item @var{STATUS} @tab (Optional) Shall be of type @code{INTEGER} and of
5324 @item @emph{Return value}:
5325 If @var{COMMAND} is present, stores the entire command line that was used
5326 to invoke the program in @var{COMMAND}. If @var{LENGTH} is present, it is
5327 assigned the length of the command line. If @var{STATUS} is present, it
5328 is assigned 0 upon success of the command, -1 if @var{COMMAND} is too
5329 short to store the command line, or a positive value in case of an error.
5331 @item @emph{Example}:
5333 PROGRAM test_get_command
5334 CHARACTER(len=255) :: cmd
5335 CALL get_command(cmd)
5336 WRITE (*,*) TRIM(cmd)
5340 @item @emph{See also}:
5341 @ref{GET_COMMAND_ARGUMENT}, @ref{COMMAND_ARGUMENT_COUNT}
5346 @node GET_COMMAND_ARGUMENT
5347 @section @code{GET_COMMAND_ARGUMENT} --- Get command line arguments
5348 @fnindex GET_COMMAND_ARGUMENT
5349 @cindex command-line arguments
5350 @cindex arguments, to program
5353 @item @emph{Description}:
5354 Retrieve the @var{NUMBER}-th argument that was passed on the
5355 command line when the containing program was invoked.
5357 @item @emph{Standard}:
5358 Fortran 2003 and later
5363 @item @emph{Syntax}:
5364 @code{CALL GET_COMMAND_ARGUMENT(NUMBER [, VALUE, LENGTH, STATUS])}
5366 @item @emph{Arguments}:
5367 @multitable @columnfractions .15 .70
5368 @item @var{NUMBER} @tab Shall be a scalar of type @code{INTEGER} and of
5369 default kind, @math{@var{NUMBER} \geq 0}
5370 @item @var{VALUE} @tab (Optional) Shall be a scalar of type @code{CHARACTER}
5371 and of default kind.
5372 @item @var{LENGTH} @tab (Optional) Shall be a scalar of type @code{INTEGER}
5373 and of default kind.
5374 @item @var{STATUS} @tab (Optional) Shall be a scalar of type @code{INTEGER}
5375 and of default kind.
5378 @item @emph{Return value}:
5379 After @code{GET_COMMAND_ARGUMENT} returns, the @var{VALUE} argument holds the
5380 @var{NUMBER}-th command line argument. If @var{VALUE} can not hold the argument, it is
5381 truncated to fit the length of @var{VALUE}. If there are less than @var{NUMBER}
5382 arguments specified at the command line, @var{VALUE} will be filled with blanks.
5383 If @math{@var{NUMBER} = 0}, @var{VALUE} is set to the name of the program (on
5384 systems that support this feature). The @var{LENGTH} argument contains the
5385 length of the @var{NUMBER}-th command line argument. If the argument retrieval
5386 fails, @var{STATUS} is a positive number; if @var{VALUE} contains a truncated
5387 command line argument, @var{STATUS} is -1; and otherwise the @var{STATUS} is
5390 @item @emph{Example}:
5392 PROGRAM test_get_command_argument
5394 CHARACTER(len=32) :: arg
5398 CALL get_command_argument(i, arg)
5399 IF (LEN_TRIM(arg) == 0) EXIT
5401 WRITE (*,*) TRIM(arg)
5407 @item @emph{See also}:
5408 @ref{GET_COMMAND}, @ref{COMMAND_ARGUMENT_COUNT}
5414 @section @code{GETCWD} --- Get current working directory
5416 @cindex system, working directory
5419 @item @emph{Description}:
5420 Get current working directory.
5422 This intrinsic is provided in both subroutine and function forms; however,
5423 only one form can be used in any given program unit.
5425 @item @emph{Standard}:
5429 Subroutine, function
5431 @item @emph{Syntax}:
5432 @multitable @columnfractions .80
5433 @item @code{CALL GETCWD(C [, STATUS])}
5434 @item @code{STATUS = GETCWD(C)}
5437 @item @emph{Arguments}:
5438 @multitable @columnfractions .15 .70
5439 @item @var{C} @tab The type shall be @code{CHARACTER} and of default kind.
5440 @item @var{STATUS} @tab (Optional) status flag. Returns 0 on success,
5441 a system specific and nonzero error code otherwise.
5444 @item @emph{Example}:
5447 CHARACTER(len=255) :: cwd
5449 WRITE(*,*) TRIM(cwd)
5453 @item @emph{See also}:
5460 @section @code{GETENV} --- Get an environmental variable
5462 @cindex environment variable
5465 @item @emph{Description}:
5466 Get the @var{VALUE} of the environmental variable @var{NAME}.
5468 This intrinsic routine is provided for backwards compatibility with
5469 GNU Fortran 77. In new code, programmers should consider the use of
5470 the @ref{GET_ENVIRONMENT_VARIABLE} intrinsic defined by the Fortran
5473 Note that @code{GETENV} need not be thread-safe. It is the
5474 responsibility of the user to ensure that the environment is not being
5475 updated concurrently with a call to the @code{GETENV} intrinsic.
5477 @item @emph{Standard}:
5483 @item @emph{Syntax}:
5484 @code{CALL GETENV(NAME, VALUE)}
5486 @item @emph{Arguments}:
5487 @multitable @columnfractions .15 .70
5488 @item @var{NAME} @tab Shall be of type @code{CHARACTER} and of default kind.
5489 @item @var{VALUE} @tab Shall be of type @code{CHARACTER} and of default kind.
5492 @item @emph{Return value}:
5493 Stores the value of @var{NAME} in @var{VALUE}. If @var{VALUE} is
5494 not large enough to hold the data, it is truncated. If @var{NAME}
5495 is not set, @var{VALUE} will be filled with blanks.
5497 @item @emph{Example}:
5500 CHARACTER(len=255) :: homedir
5501 CALL getenv("HOME", homedir)
5502 WRITE (*,*) TRIM(homedir)
5506 @item @emph{See also}:
5507 @ref{GET_ENVIRONMENT_VARIABLE}
5512 @node GET_ENVIRONMENT_VARIABLE
5513 @section @code{GET_ENVIRONMENT_VARIABLE} --- Get an environmental variable
5514 @fnindex GET_ENVIRONMENT_VARIABLE
5515 @cindex environment variable
5518 @item @emph{Description}:
5519 Get the @var{VALUE} of the environmental variable @var{NAME}.
5521 Note that @code{GET_ENVIRONMENT_VARIABLE} need not be thread-safe. It
5522 is the responsibility of the user to ensure that the environment is
5523 not being updated concurrently with a call to the
5524 @code{GET_ENVIRONMENT_VARIABLE} intrinsic.
5526 @item @emph{Standard}:
5527 Fortran 2003 and later
5532 @item @emph{Syntax}:
5533 @code{CALL GET_ENVIRONMENT_VARIABLE(NAME[, VALUE, LENGTH, STATUS, TRIM_NAME)}
5535 @item @emph{Arguments}:
5536 @multitable @columnfractions .15 .70
5537 @item @var{NAME} @tab Shall be a scalar of type @code{CHARACTER}
5538 and of default kind.
5539 @item @var{VALUE} @tab (Optional) Shall be a scalar of type @code{CHARACTER}
5540 and of default kind.
5541 @item @var{LENGTH} @tab (Optional) Shall be a scalar of type @code{INTEGER}
5542 and of default kind.
5543 @item @var{STATUS} @tab (Optional) Shall be a scalar of type @code{INTEGER}
5544 and of default kind.
5545 @item @var{TRIM_NAME} @tab (Optional) Shall be a scalar of type @code{LOGICAL}
5546 and of default kind.
5549 @item @emph{Return value}:
5550 Stores the value of @var{NAME} in @var{VALUE}. If @var{VALUE} is
5551 not large enough to hold the data, it is truncated. If @var{NAME}
5552 is not set, @var{VALUE} will be filled with blanks. Argument @var{LENGTH}
5553 contains the length needed for storing the environment variable @var{NAME}
5554 or zero if it is not present. @var{STATUS} is -1 if @var{VALUE} is present
5555 but too short for the environment variable; it is 1 if the environment
5556 variable does not exist and 2 if the processor does not support environment
5557 variables; in all other cases @var{STATUS} is zero. If @var{TRIM_NAME} is
5558 present with the value @code{.FALSE.}, the trailing blanks in @var{NAME}
5559 are significant; otherwise they are not part of the environment variable
5562 @item @emph{Example}:
5565 CHARACTER(len=255) :: homedir
5566 CALL get_environment_variable("HOME", homedir)
5567 WRITE (*,*) TRIM(homedir)
5575 @section @code{GETGID} --- Group ID function
5577 @cindex system, group ID
5580 @item @emph{Description}:
5581 Returns the numerical group ID of the current process.
5583 @item @emph{Standard}:
5589 @item @emph{Syntax}:
5590 @code{RESULT = GETGID()}
5592 @item @emph{Return value}:
5593 The return value of @code{GETGID} is an @code{INTEGER} of the default
5597 @item @emph{Example}:
5598 See @code{GETPID} for an example.
5600 @item @emph{See also}:
5601 @ref{GETPID}, @ref{GETUID}
5607 @section @code{GETLOG} --- Get login name
5609 @cindex system, login name
5613 @item @emph{Description}:
5614 Gets the username under which the program is running.
5616 @item @emph{Standard}:
5622 @item @emph{Syntax}:
5623 @code{CALL GETLOG(C)}
5625 @item @emph{Arguments}:
5626 @multitable @columnfractions .15 .70
5627 @item @var{C} @tab Shall be of type @code{CHARACTER} and of default kind.
5630 @item @emph{Return value}:
5631 Stores the current user name in @var{LOGIN}. (On systems where POSIX
5632 functions @code{geteuid} and @code{getpwuid} are not available, and
5633 the @code{getlogin} function is not implemented either, this will
5634 return a blank string.)
5636 @item @emph{Example}:
5639 CHARACTER(32) :: login
5645 @item @emph{See also}:
5652 @section @code{GETPID} --- Process ID function
5654 @cindex system, process ID
5658 @item @emph{Description}:
5659 Returns the numerical process identifier of the current process.
5661 @item @emph{Standard}:
5667 @item @emph{Syntax}:
5668 @code{RESULT = GETPID()}
5670 @item @emph{Return value}:
5671 The return value of @code{GETPID} is an @code{INTEGER} of the default
5675 @item @emph{Example}:
5678 print *, "The current process ID is ", getpid()
5679 print *, "Your numerical user ID is ", getuid()
5680 print *, "Your numerical group ID is ", getgid()
5684 @item @emph{See also}:
5685 @ref{GETGID}, @ref{GETUID}
5691 @section @code{GETUID} --- User ID function
5693 @cindex system, user ID
5697 @item @emph{Description}:
5698 Returns the numerical user ID of the current process.
5700 @item @emph{Standard}:
5706 @item @emph{Syntax}:
5707 @code{RESULT = GETUID()}
5709 @item @emph{Return value}:
5710 The return value of @code{GETUID} is an @code{INTEGER} of the default
5714 @item @emph{Example}:
5715 See @code{GETPID} for an example.
5717 @item @emph{See also}:
5718 @ref{GETPID}, @ref{GETLOG}
5724 @section @code{GMTIME} --- Convert time to GMT info
5726 @cindex time, conversion to GMT info
5729 @item @emph{Description}:
5730 Given a system time value @var{TIME} (as provided by the @code{TIME8}
5731 intrinsic), fills @var{VALUES} with values extracted from it appropriate
5732 to the UTC time zone (Universal Coordinated Time, also known in some
5733 countries as GMT, Greenwich Mean Time), using @code{gmtime(3)}.
5735 @item @emph{Standard}:
5741 @item @emph{Syntax}:
5742 @code{CALL GMTIME(TIME, VALUES)}
5744 @item @emph{Arguments}:
5745 @multitable @columnfractions .15 .70
5746 @item @var{TIME} @tab An @code{INTEGER} scalar expression
5747 corresponding to a system time, with @code{INTENT(IN)}.
5748 @item @var{VALUES} @tab A default @code{INTEGER} array with 9 elements,
5749 with @code{INTENT(OUT)}.
5752 @item @emph{Return value}:
5753 The elements of @var{VALUES} are assigned as follows:
5755 @item Seconds after the minute, range 0--59 or 0--61 to allow for leap
5757 @item Minutes after the hour, range 0--59
5758 @item Hours past midnight, range 0--23
5759 @item Day of month, range 0--31
5760 @item Number of months since January, range 0--12
5761 @item Years since 1900
5762 @item Number of days since Sunday, range 0--6
5763 @item Days since January 1
5764 @item Daylight savings indicator: positive if daylight savings is in
5765 effect, zero if not, and negative if the information is not available.
5768 @item @emph{See also}:
5769 @ref{CTIME}, @ref{LTIME}, @ref{TIME}, @ref{TIME8}
5776 @section @code{HOSTNM} --- Get system host name
5778 @cindex system, host name
5781 @item @emph{Description}:
5782 Retrieves the host name of the system on which the program is running.
5784 This intrinsic is provided in both subroutine and function forms; however,
5785 only one form can be used in any given program unit.
5787 @item @emph{Standard}:
5791 Subroutine, function
5793 @item @emph{Syntax}:
5794 @multitable @columnfractions .80
5795 @item @code{CALL HOSTNM(C [, STATUS])}
5796 @item @code{STATUS = HOSTNM(NAME)}
5799 @item @emph{Arguments}:
5800 @multitable @columnfractions .15 .70
5801 @item @var{C} @tab Shall of type @code{CHARACTER} and of default kind.
5802 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
5803 Returns 0 on success, or a system specific error code otherwise.
5806 @item @emph{Return value}:
5807 In either syntax, @var{NAME} is set to the current hostname if it can
5808 be obtained, or to a blank string otherwise.
5815 @section @code{HUGE} --- Largest number of a kind
5817 @cindex limits, largest number
5818 @cindex model representation, largest number
5821 @item @emph{Description}:
5822 @code{HUGE(X)} returns the largest number that is not an infinity in
5823 the model of the type of @code{X}.
5825 @item @emph{Standard}:
5826 Fortran 95 and later
5831 @item @emph{Syntax}:
5832 @code{RESULT = HUGE(X)}
5834 @item @emph{Arguments}:
5835 @multitable @columnfractions .15 .70
5836 @item @var{X} @tab Shall be of type @code{REAL} or @code{INTEGER}.
5839 @item @emph{Return value}:
5840 The return value is of the same type and kind as @var{X}
5842 @item @emph{Example}:
5844 program test_huge_tiny
5845 print *, huge(0), huge(0.0), huge(0.0d0)
5846 print *, tiny(0.0), tiny(0.0d0)
5847 end program test_huge_tiny
5854 @section @code{HYPOT} --- Euclidean distance function
5856 @cindex Euclidean distance
5859 @item @emph{Description}:
5860 @code{HYPOT(X,Y)} is the Euclidean distance function. It is equal to
5861 @math{\sqrt{X^2 + Y^2}}, without undue underflow or overflow.
5863 @item @emph{Standard}:
5864 Fortran 2008 and later
5869 @item @emph{Syntax}:
5870 @code{RESULT = HYPOT(X, Y)}
5872 @item @emph{Arguments}:
5873 @multitable @columnfractions .15 .70
5874 @item @var{X} @tab The type shall be @code{REAL}.
5875 @item @var{Y} @tab The type and kind type parameter shall be the same as
5879 @item @emph{Return value}:
5880 The return value has the same type and kind type parameter as @var{X}.
5882 @item @emph{Example}:
5885 real(4) :: x = 1.e0_4, y = 0.5e0_4
5887 end program test_hypot
5894 @section @code{IACHAR} --- Code in @acronym{ASCII} collating sequence
5896 @cindex @acronym{ASCII} collating sequence
5897 @cindex collating sequence, @acronym{ASCII}
5898 @cindex conversion, to integer
5901 @item @emph{Description}:
5902 @code{IACHAR(C)} returns the code for the @acronym{ASCII} character
5903 in the first character position of @code{C}.
5905 @item @emph{Standard}:
5906 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
5911 @item @emph{Syntax}:
5912 @code{RESULT = IACHAR(C [, KIND])}
5914 @item @emph{Arguments}:
5915 @multitable @columnfractions .15 .70
5916 @item @var{C} @tab Shall be a scalar @code{CHARACTER}, with @code{INTENT(IN)}
5917 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
5918 expression indicating the kind parameter of the result.
5921 @item @emph{Return value}:
5922 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
5923 @var{KIND} is absent, the return value is of default integer kind.
5925 @item @emph{Example}:
5930 end program test_iachar
5934 See @ref{ICHAR} for a discussion of converting between numerical values
5935 and formatted string representations.
5937 @item @emph{See also}:
5938 @ref{ACHAR}, @ref{CHAR}, @ref{ICHAR}
5945 @section @code{IALL} --- Bitwise AND of array elements
5948 @cindex bits, AND of array elements
5951 @item @emph{Description}:
5952 Reduces with bitwise AND the elements of @var{ARRAY} along dimension @var{DIM}
5953 if the corresponding element in @var{MASK} is @code{TRUE}.
5955 @item @emph{Standard}:
5956 Fortran 2008 and later
5959 Transformational function
5961 @item @emph{Syntax}:
5962 @multitable @columnfractions .80
5963 @item @code{RESULT = IALL(ARRAY[, MASK])}
5964 @item @code{RESULT = IALL(ARRAY, DIM[, MASK])}
5967 @item @emph{Arguments}:
5968 @multitable @columnfractions .15 .70
5969 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER}
5970 @item @var{DIM} @tab (Optional) shall be a scalar of type
5971 @code{INTEGER} with a value in the range from 1 to n, where n
5972 equals the rank of @var{ARRAY}.
5973 @item @var{MASK} @tab (Optional) shall be of type @code{LOGICAL}
5974 and either be a scalar or an array of the same shape as @var{ARRAY}.
5977 @item @emph{Return value}:
5978 The result is of the same type as @var{ARRAY}.
5980 If @var{DIM} is absent, a scalar with the bitwise ALL of all elements in
5981 @var{ARRAY} is returned. Otherwise, an array of rank n-1, where n equals
5982 the rank of @var{ARRAY}, and a shape similar to that of @var{ARRAY} with
5983 dimension @var{DIM} dropped is returned.
5985 @item @emph{Example}:
5994 PRINT '(b8.8)', IALL(a)
5998 @item @emph{See also}:
5999 @ref{IANY}, @ref{IPARITY}, @ref{IAND}
6005 @section @code{IAND} --- Bitwise logical and
6007 @cindex bitwise logical and
6008 @cindex logical and, bitwise
6011 @item @emph{Description}:
6012 Bitwise logical @code{AND}.
6014 @item @emph{Standard}:
6015 Fortran 95 and later
6020 @item @emph{Syntax}:
6021 @code{RESULT = IAND(I, J)}
6023 @item @emph{Arguments}:
6024 @multitable @columnfractions .15 .70
6025 @item @var{I} @tab The type shall be @code{INTEGER}.
6026 @item @var{J} @tab The type shall be @code{INTEGER}, of the same
6027 kind as @var{I}. (As a GNU extension, different kinds are also
6031 @item @emph{Return value}:
6032 The return type is @code{INTEGER}, of the same kind as the
6033 arguments. (If the argument kinds differ, it is of the same kind as
6034 the larger argument.)
6036 @item @emph{Example}:
6040 DATA a / Z'F' /, b / Z'3' /
6041 WRITE (*,*) IAND(a, b)
6045 @item @emph{See also}:
6046 @ref{IOR}, @ref{IEOR}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}, @ref{NOT}
6053 @section @code{IANY} --- Bitwise OR of array elements
6056 @cindex bits, OR of array elements
6059 @item @emph{Description}:
6060 Reduces with bitwise OR (inclusive or) the elements of @var{ARRAY} along
6061 dimension @var{DIM} if the corresponding element in @var{MASK} is @code{TRUE}.
6063 @item @emph{Standard}:
6064 Fortran 2008 and later
6067 Transformational function
6069 @item @emph{Syntax}:
6070 @multitable @columnfractions .80
6071 @item @code{RESULT = IANY(ARRAY[, MASK])}
6072 @item @code{RESULT = IANY(ARRAY, DIM[, MASK])}
6075 @item @emph{Arguments}:
6076 @multitable @columnfractions .15 .70
6077 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER}
6078 @item @var{DIM} @tab (Optional) shall be a scalar of type
6079 @code{INTEGER} with a value in the range from 1 to n, where n
6080 equals the rank of @var{ARRAY}.
6081 @item @var{MASK} @tab (Optional) shall be of type @code{LOGICAL}
6082 and either be a scalar or an array of the same shape as @var{ARRAY}.
6085 @item @emph{Return value}:
6086 The result is of the same type as @var{ARRAY}.
6088 If @var{DIM} is absent, a scalar with the bitwise OR of all elements in
6089 @var{ARRAY} is returned. Otherwise, an array of rank n-1, where n equals
6090 the rank of @var{ARRAY}, and a shape similar to that of @var{ARRAY} with
6091 dimension @var{DIM} dropped is returned.
6093 @item @emph{Example}:
6102 PRINT '(b8.8)', IANY(a)
6106 @item @emph{See also}:
6107 @ref{IPARITY}, @ref{IALL}, @ref{IOR}
6113 @section @code{IARGC} --- Get the number of command line arguments
6115 @cindex command-line arguments
6116 @cindex command-line arguments, number of
6117 @cindex arguments, to program
6120 @item @emph{Description}:
6121 @code{IARGC} returns the number of arguments passed on the
6122 command line when the containing program was invoked.
6124 This intrinsic routine is provided for backwards compatibility with
6125 GNU Fortran 77. In new code, programmers should consider the use of
6126 the @ref{COMMAND_ARGUMENT_COUNT} intrinsic defined by the Fortran 2003
6129 @item @emph{Standard}:
6135 @item @emph{Syntax}:
6136 @code{RESULT = IARGC()}
6138 @item @emph{Arguments}:
6141 @item @emph{Return value}:
6142 The number of command line arguments, type @code{INTEGER(4)}.
6144 @item @emph{Example}:
6147 @item @emph{See also}:
6148 GNU Fortran 77 compatibility subroutine: @ref{GETARG}
6150 Fortran 2003 functions and subroutines: @ref{GET_COMMAND},
6151 @ref{GET_COMMAND_ARGUMENT}, @ref{COMMAND_ARGUMENT_COUNT}
6157 @section @code{IBCLR} --- Clear bit
6163 @item @emph{Description}:
6164 @code{IBCLR} returns the value of @var{I} with the bit at position
6165 @var{POS} set to zero.
6167 @item @emph{Standard}:
6168 Fortran 95 and later
6173 @item @emph{Syntax}:
6174 @code{RESULT = IBCLR(I, POS)}
6176 @item @emph{Arguments}:
6177 @multitable @columnfractions .15 .70
6178 @item @var{I} @tab The type shall be @code{INTEGER}.
6179 @item @var{POS} @tab The type shall be @code{INTEGER}.
6182 @item @emph{Return value}:
6183 The return value is of type @code{INTEGER} and of the same kind as
6186 @item @emph{See also}:
6187 @ref{IBITS}, @ref{IBSET}, @ref{IAND}, @ref{IOR}, @ref{IEOR}, @ref{MVBITS}
6194 @section @code{IBITS} --- Bit extraction
6197 @cindex bits, extract
6200 @item @emph{Description}:
6201 @code{IBITS} extracts a field of length @var{LEN} from @var{I},
6202 starting from bit position @var{POS} and extending left for @var{LEN}
6203 bits. The result is right-justified and the remaining bits are
6204 zeroed. The value of @code{POS+LEN} must be less than or equal to the
6205 value @code{BIT_SIZE(I)}.
6207 @item @emph{Standard}:
6208 Fortran 95 and later
6213 @item @emph{Syntax}:
6214 @code{RESULT = IBITS(I, POS, LEN)}
6216 @item @emph{Arguments}:
6217 @multitable @columnfractions .15 .70
6218 @item @var{I} @tab The type shall be @code{INTEGER}.
6219 @item @var{POS} @tab The type shall be @code{INTEGER}.
6220 @item @var{LEN} @tab The type shall be @code{INTEGER}.
6223 @item @emph{Return value}:
6224 The return value is of type @code{INTEGER} and of the same kind as
6227 @item @emph{See also}:
6228 @ref{BIT_SIZE}, @ref{IBCLR}, @ref{IBSET}, @ref{IAND}, @ref{IOR}, @ref{IEOR}
6234 @section @code{IBSET} --- Set bit
6239 @item @emph{Description}:
6240 @code{IBSET} returns the value of @var{I} with the bit at position
6241 @var{POS} set to one.
6243 @item @emph{Standard}:
6244 Fortran 95 and later
6249 @item @emph{Syntax}:
6250 @code{RESULT = IBSET(I, POS)}
6252 @item @emph{Arguments}:
6253 @multitable @columnfractions .15 .70
6254 @item @var{I} @tab The type shall be @code{INTEGER}.
6255 @item @var{POS} @tab The type shall be @code{INTEGER}.
6258 @item @emph{Return value}:
6259 The return value is of type @code{INTEGER} and of the same kind as
6262 @item @emph{See also}:
6263 @ref{IBCLR}, @ref{IBITS}, @ref{IAND}, @ref{IOR}, @ref{IEOR}, @ref{MVBITS}
6270 @section @code{ICHAR} --- Character-to-integer conversion function
6272 @cindex conversion, to integer
6275 @item @emph{Description}:
6276 @code{ICHAR(C)} returns the code for the character in the first character
6277 position of @code{C} in the system's native character set.
6278 The correspondence between characters and their codes is not necessarily
6279 the same across different GNU Fortran implementations.
6281 @item @emph{Standard}:
6282 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
6287 @item @emph{Syntax}:
6288 @code{RESULT = ICHAR(C [, KIND])}
6290 @item @emph{Arguments}:
6291 @multitable @columnfractions .15 .70
6292 @item @var{C} @tab Shall be a scalar @code{CHARACTER}, with @code{INTENT(IN)}
6293 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
6294 expression indicating the kind parameter of the result.
6297 @item @emph{Return value}:
6298 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
6299 @var{KIND} is absent, the return value is of default integer kind.
6301 @item @emph{Example}:
6306 end program test_ichar
6309 @item @emph{Specific names}:
6310 @multitable @columnfractions .20 .20 .20 .25
6311 @item Name @tab Argument @tab Return type @tab Standard
6312 @item @code{ICHAR(C)} @tab @code{CHARACTER C} @tab @code{INTEGER(4)} @tab Fortran 77 and later
6316 No intrinsic exists to convert between a numeric value and a formatted
6317 character string representation -- for instance, given the
6318 @code{CHARACTER} value @code{'154'}, obtaining an @code{INTEGER} or
6319 @code{REAL} value with the value 154, or vice versa. Instead, this
6320 functionality is provided by internal-file I/O, as in the following
6325 character(len=10) string, string2
6328 ! Convert a string to a numeric value
6329 read (string,'(I10)') value
6332 ! Convert a value to a formatted string
6333 write (string2,'(I10)') value
6335 end program read_val
6338 @item @emph{See also}:
6339 @ref{ACHAR}, @ref{CHAR}, @ref{IACHAR}
6346 @section @code{IDATE} --- Get current local time subroutine (day/month/year)
6348 @cindex date, current
6349 @cindex current date
6352 @item @emph{Description}:
6353 @code{IDATE(VALUES)} Fills @var{VALUES} with the numerical values at the
6354 current local time. The day (in the range 1-31), month (in the range 1-12),
6355 and year appear in elements 1, 2, and 3 of @var{VALUES}, respectively.
6356 The year has four significant digits.
6358 @item @emph{Standard}:
6364 @item @emph{Syntax}:
6365 @code{CALL IDATE(VALUES)}
6367 @item @emph{Arguments}:
6368 @multitable @columnfractions .15 .70
6369 @item @var{VALUES} @tab The type shall be @code{INTEGER, DIMENSION(3)} and
6370 the kind shall be the default integer kind.
6373 @item @emph{Return value}:
6374 Does not return anything.
6376 @item @emph{Example}:
6379 integer, dimension(3) :: tarray
6384 end program test_idate
6391 @section @code{IEOR} --- Bitwise logical exclusive or
6393 @cindex bitwise logical exclusive or
6394 @cindex logical exclusive or, bitwise
6397 @item @emph{Description}:
6398 @code{IEOR} returns the bitwise Boolean exclusive-OR of @var{I} and
6401 @item @emph{Standard}:
6402 Fortran 95 and later
6407 @item @emph{Syntax}:
6408 @code{RESULT = IEOR(I, J)}
6410 @item @emph{Arguments}:
6411 @multitable @columnfractions .15 .70
6412 @item @var{I} @tab The type shall be @code{INTEGER}.
6413 @item @var{J} @tab The type shall be @code{INTEGER}, of the same
6414 kind as @var{I}. (As a GNU extension, different kinds are also
6418 @item @emph{Return value}:
6419 The return type is @code{INTEGER}, of the same kind as the
6420 arguments. (If the argument kinds differ, it is of the same kind as
6421 the larger argument.)
6423 @item @emph{See also}:
6424 @ref{IOR}, @ref{IAND}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}, @ref{NOT}
6430 @section @code{IERRNO} --- Get the last system error number
6432 @cindex system, error handling
6435 @item @emph{Description}:
6436 Returns the last system error number, as given by the C @code{errno}
6439 @item @emph{Standard}:
6445 @item @emph{Syntax}:
6446 @code{RESULT = IERRNO()}
6448 @item @emph{Arguments}:
6451 @item @emph{Return value}:
6452 The return value is of type @code{INTEGER} and of the default integer
6455 @item @emph{See also}:
6462 @section @code{IMAGE_INDEX} --- Function that converts a cosubscript to an image index
6463 @fnindex IMAGE_INDEX
6464 @cindex coarray, @code{IMAGE_INDEX}
6465 @cindex images, cosubscript to image index conversion
6468 @item @emph{Description}:
6469 Returns the image index belonging to a cosubscript.
6471 @item @emph{Standard}:
6472 Fortran 2008 and later
6477 @item @emph{Syntax}:
6478 @code{RESULT = IMAGE_INDEX(COARRAY, SUB)}
6480 @item @emph{Arguments}: None.
6481 @multitable @columnfractions .15 .70
6482 @item @var{COARRAY} @tab Coarray of any type.
6483 @item @var{SUB} @tab default integer rank-1 array of a size equal to
6484 the corank of @var{COARRAY}.
6488 @item @emph{Return value}:
6489 Scalar default integer with the value of the image index which corresponds
6490 to the cosubscripts. For invalid cosubscripts the result is zero.
6492 @item @emph{Example}:
6494 INTEGER :: array[2,-1:4,8,*]
6495 ! Writes 28 (or 0 if there are fewer than 28 images)
6496 WRITE (*,*) IMAGE_INDEX (array, [2,0,3,1])
6499 @item @emph{See also}:
6500 @ref{THIS_IMAGE}, @ref{NUM_IMAGES}
6505 @node INDEX intrinsic
6506 @section @code{INDEX} --- Position of a substring within a string
6508 @cindex substring position
6509 @cindex string, find substring
6512 @item @emph{Description}:
6513 Returns the position of the start of the first occurrence of string
6514 @var{SUBSTRING} as a substring in @var{STRING}, counting from one. If
6515 @var{SUBSTRING} is not present in @var{STRING}, zero is returned. If
6516 the @var{BACK} argument is present and true, the return value is the
6517 start of the last occurrence rather than the first.
6519 @item @emph{Standard}:
6520 Fortran 77 and later, with @var{KIND} argument Fortran 2003 and later
6525 @item @emph{Syntax}:
6526 @code{RESULT = INDEX(STRING, SUBSTRING [, BACK [, KIND]])}
6528 @item @emph{Arguments}:
6529 @multitable @columnfractions .15 .70
6530 @item @var{STRING} @tab Shall be a scalar @code{CHARACTER}, with
6532 @item @var{SUBSTRING} @tab Shall be a scalar @code{CHARACTER}, with
6534 @item @var{BACK} @tab (Optional) Shall be a scalar @code{LOGICAL}, with
6536 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
6537 expression indicating the kind parameter of the result.
6540 @item @emph{Return value}:
6541 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
6542 @var{KIND} is absent, the return value is of default integer kind.
6544 @item @emph{Specific names}:
6545 @multitable @columnfractions .20 .20 .20 .25
6546 @item Name @tab Argument @tab Return type @tab Standard
6547 @item @code{INDEX(STRING, SUBSTRING)} @tab @code{CHARACTER} @tab @code{INTEGER(4)} @tab Fortran 77 and later
6550 @item @emph{See also}:
6551 @ref{SCAN}, @ref{VERIFY}
6557 @section @code{INT} --- Convert to integer type
6561 @cindex conversion, to integer
6564 @item @emph{Description}:
6565 Convert to integer type
6567 @item @emph{Standard}:
6568 Fortran 77 and later
6573 @item @emph{Syntax}:
6574 @code{RESULT = INT(A [, KIND))}
6576 @item @emph{Arguments}:
6577 @multitable @columnfractions .15 .70
6578 @item @var{A} @tab Shall be of type @code{INTEGER},
6579 @code{REAL}, or @code{COMPLEX}.
6580 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
6581 expression indicating the kind parameter of the result.
6584 @item @emph{Return value}:
6585 These functions return a @code{INTEGER} variable or array under
6586 the following rules:
6590 If @var{A} is of type @code{INTEGER}, @code{INT(A) = A}
6592 If @var{A} is of type @code{REAL} and @math{|A| < 1}, @code{INT(A)} equals @code{0}.
6593 If @math{|A| \geq 1}, then @code{INT(A)} equals the largest integer that does not exceed
6594 the range of @var{A} and whose sign is the same as the sign of @var{A}.
6596 If @var{A} is of type @code{COMPLEX}, rule B is applied to the real part of @var{A}.
6599 @item @emph{Example}:
6603 complex :: z = (-3.7, 1.0)
6605 print *, int(z), int(z,8)
6609 @item @emph{Specific names}:
6610 @multitable @columnfractions .20 .20 .20 .25
6611 @item Name @tab Argument @tab Return type @tab Standard
6612 @item @code{INT(A)} @tab @code{REAL(4) A} @tab @code{INTEGER} @tab Fortran 77 and later
6613 @item @code{IFIX(A)} @tab @code{REAL(4) A} @tab @code{INTEGER} @tab Fortran 77 and later
6614 @item @code{IDINT(A)} @tab @code{REAL(8) A} @tab @code{INTEGER} @tab Fortran 77 and later
6621 @section @code{INT2} --- Convert to 16-bit integer type
6624 @cindex conversion, to integer
6627 @item @emph{Description}:
6628 Convert to a @code{KIND=2} integer type. This is equivalent to the
6629 standard @code{INT} intrinsic with an optional argument of
6630 @code{KIND=2}, and is only included for backwards compatibility.
6632 The @code{SHORT} intrinsic is equivalent to @code{INT2}.
6634 @item @emph{Standard}:
6640 @item @emph{Syntax}:
6641 @code{RESULT = INT2(A)}
6643 @item @emph{Arguments}:
6644 @multitable @columnfractions .15 .70
6645 @item @var{A} @tab Shall be of type @code{INTEGER},
6646 @code{REAL}, or @code{COMPLEX}.
6649 @item @emph{Return value}:
6650 The return value is a @code{INTEGER(2)} variable.
6652 @item @emph{See also}:
6653 @ref{INT}, @ref{INT8}, @ref{LONG}
6659 @section @code{INT8} --- Convert to 64-bit integer type
6661 @cindex conversion, to integer
6664 @item @emph{Description}:
6665 Convert to a @code{KIND=8} integer type. This is equivalent to the
6666 standard @code{INT} intrinsic with an optional argument of
6667 @code{KIND=8}, and is only included for backwards compatibility.
6669 @item @emph{Standard}:
6675 @item @emph{Syntax}:
6676 @code{RESULT = INT8(A)}
6678 @item @emph{Arguments}:
6679 @multitable @columnfractions .15 .70
6680 @item @var{A} @tab Shall be of type @code{INTEGER},
6681 @code{REAL}, or @code{COMPLEX}.
6684 @item @emph{Return value}:
6685 The return value is a @code{INTEGER(8)} variable.
6687 @item @emph{See also}:
6688 @ref{INT}, @ref{INT2}, @ref{LONG}
6694 @section @code{IOR} --- Bitwise logical or
6696 @cindex bitwise logical or
6697 @cindex logical or, bitwise
6700 @item @emph{Description}:
6701 @code{IOR} returns the bitwise Boolean inclusive-OR of @var{I} and
6704 @item @emph{Standard}:
6705 Fortran 95 and later
6710 @item @emph{Syntax}:
6711 @code{RESULT = IOR(I, J)}
6713 @item @emph{Arguments}:
6714 @multitable @columnfractions .15 .70
6715 @item @var{I} @tab The type shall be @code{INTEGER}.
6716 @item @var{J} @tab The type shall be @code{INTEGER}, of the same
6717 kind as @var{I}. (As a GNU extension, different kinds are also
6721 @item @emph{Return value}:
6722 The return type is @code{INTEGER}, of the same kind as the
6723 arguments. (If the argument kinds differ, it is of the same kind as
6724 the larger argument.)
6726 @item @emph{See also}:
6727 @ref{IEOR}, @ref{IAND}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}, @ref{NOT}
6733 @section @code{IPARITY} --- Bitwise XOR of array elements
6735 @cindex array, parity
6737 @cindex bits, XOR of array elements
6740 @item @emph{Description}:
6741 Reduces with bitwise XOR (exclusive or) the elements of @var{ARRAY} along
6742 dimension @var{DIM} if the corresponding element in @var{MASK} is @code{TRUE}.
6744 @item @emph{Standard}:
6745 Fortran 2008 and later
6748 Transformational function
6750 @item @emph{Syntax}:
6751 @multitable @columnfractions .80
6752 @item @code{RESULT = IPARITY(ARRAY[, MASK])}
6753 @item @code{RESULT = IPARITY(ARRAY, DIM[, MASK])}
6756 @item @emph{Arguments}:
6757 @multitable @columnfractions .15 .70
6758 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER}
6759 @item @var{DIM} @tab (Optional) shall be a scalar of type
6760 @code{INTEGER} with a value in the range from 1 to n, where n
6761 equals the rank of @var{ARRAY}.
6762 @item @var{MASK} @tab (Optional) shall be of type @code{LOGICAL}
6763 and either be a scalar or an array of the same shape as @var{ARRAY}.
6766 @item @emph{Return value}:
6767 The result is of the same type as @var{ARRAY}.
6769 If @var{DIM} is absent, a scalar with the bitwise XOR of all elements in
6770 @var{ARRAY} is returned. Otherwise, an array of rank n-1, where n equals
6771 the rank of @var{ARRAY}, and a shape similar to that of @var{ARRAY} with
6772 dimension @var{DIM} dropped is returned.
6774 @item @emph{Example}:
6776 PROGRAM test_iparity
6783 PRINT '(b8.8)', IPARITY(a)
6787 @item @emph{See also}:
6788 @ref{IANY}, @ref{IALL}, @ref{IEOR}, @ref{PARITY}
6794 @section @code{IRAND} --- Integer pseudo-random number
6796 @cindex random number generation
6799 @item @emph{Description}:
6800 @code{IRAND(FLAG)} returns a pseudo-random number from a uniform
6801 distribution between 0 and a system-dependent limit (which is in most
6802 cases 2147483647). If @var{FLAG} is 0, the next number
6803 in the current sequence is returned; if @var{FLAG} is 1, the generator
6804 is restarted by @code{CALL SRAND(0)}; if @var{FLAG} has any other value,
6805 it is used as a new seed with @code{SRAND}.
6807 This intrinsic routine is provided for backwards compatibility with
6808 GNU Fortran 77. It implements a simple modulo generator as provided
6809 by @command{g77}. For new code, one should consider the use of
6810 @ref{RANDOM_NUMBER} as it implements a superior algorithm.
6812 @item @emph{Standard}:
6818 @item @emph{Syntax}:
6819 @code{RESULT = IRAND(I)}
6821 @item @emph{Arguments}:
6822 @multitable @columnfractions .15 .70
6823 @item @var{I} @tab Shall be a scalar @code{INTEGER} of kind 4.
6826 @item @emph{Return value}:
6827 The return value is of @code{INTEGER(kind=4)} type.
6829 @item @emph{Example}:
6832 integer,parameter :: seed = 86456
6835 print *, irand(), irand(), irand(), irand()
6836 print *, irand(seed), irand(), irand(), irand()
6837 end program test_irand
6845 @section @code{IS_IOSTAT_END} --- Test for end-of-file value
6846 @fnindex IS_IOSTAT_END
6847 @cindex @code{IOSTAT}, end of file
6850 @item @emph{Description}:
6851 @code{IS_IOSTAT_END} tests whether an variable has the value of the I/O
6852 status ``end of file''. The function is equivalent to comparing the variable
6853 with the @code{IOSTAT_END} parameter of the intrinsic module
6854 @code{ISO_FORTRAN_ENV}.
6856 @item @emph{Standard}:
6857 Fortran 2003 and later
6862 @item @emph{Syntax}:
6863 @code{RESULT = IS_IOSTAT_END(I)}
6865 @item @emph{Arguments}:
6866 @multitable @columnfractions .15 .70
6867 @item @var{I} @tab Shall be of the type @code{INTEGER}.
6870 @item @emph{Return value}:
6871 Returns a @code{LOGICAL} of the default kind, which @code{.TRUE.} if
6872 @var{I} has the value which indicates an end of file condition for
6873 @code{IOSTAT=} specifiers, and is @code{.FALSE.} otherwise.
6875 @item @emph{Example}:
6880 OPEN(88, FILE='test.dat')
6881 READ(88, *, IOSTAT=stat) i
6882 IF(IS_IOSTAT_END(stat)) STOP 'END OF FILE'
6890 @section @code{IS_IOSTAT_EOR} --- Test for end-of-record value
6891 @fnindex IS_IOSTAT_EOR
6892 @cindex @code{IOSTAT}, end of record
6895 @item @emph{Description}:
6896 @code{IS_IOSTAT_EOR} tests whether an variable has the value of the I/O
6897 status ``end of record''. The function is equivalent to comparing the
6898 variable with the @code{IOSTAT_EOR} parameter of the intrinsic module
6899 @code{ISO_FORTRAN_ENV}.
6901 @item @emph{Standard}:
6902 Fortran 2003 and later
6907 @item @emph{Syntax}:
6908 @code{RESULT = IS_IOSTAT_EOR(I)}
6910 @item @emph{Arguments}:
6911 @multitable @columnfractions .15 .70
6912 @item @var{I} @tab Shall be of the type @code{INTEGER}.
6915 @item @emph{Return value}:
6916 Returns a @code{LOGICAL} of the default kind, which @code{.TRUE.} if
6917 @var{I} has the value which indicates an end of file condition for
6918 @code{IOSTAT=} specifiers, and is @code{.FALSE.} otherwise.
6920 @item @emph{Example}:
6924 INTEGER :: stat, i(50)
6925 OPEN(88, FILE='test.dat', FORM='UNFORMATTED')
6926 READ(88, IOSTAT=stat) i
6927 IF(IS_IOSTAT_EOR(stat)) STOP 'END OF RECORD'
6935 @section @code{ISATTY} --- Whether a unit is a terminal device.
6937 @cindex system, terminal
6940 @item @emph{Description}:
6941 Determine whether a unit is connected to a terminal device.
6943 @item @emph{Standard}:
6949 @item @emph{Syntax}:
6950 @code{RESULT = ISATTY(UNIT)}
6952 @item @emph{Arguments}:
6953 @multitable @columnfractions .15 .70
6954 @item @var{UNIT} @tab Shall be a scalar @code{INTEGER}.
6957 @item @emph{Return value}:
6958 Returns @code{.TRUE.} if the @var{UNIT} is connected to a terminal
6959 device, @code{.FALSE.} otherwise.
6961 @item @emph{Example}:
6964 INTEGER(kind=1) :: unit
6966 write(*,*) isatty(unit=unit)
6970 @item @emph{See also}:
6977 @section @code{ISHFT} --- Shift bits
6982 @item @emph{Description}:
6983 @code{ISHFT} returns a value corresponding to @var{I} with all of the
6984 bits shifted @var{SHIFT} places. A value of @var{SHIFT} greater than
6985 zero corresponds to a left shift, a value of zero corresponds to no
6986 shift, and a value less than zero corresponds to a right shift. If the
6987 absolute value of @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the
6988 value is undefined. Bits shifted out from the left end or right end are
6989 lost; zeros are shifted in from the opposite end.
6991 @item @emph{Standard}:
6992 Fortran 95 and later
6997 @item @emph{Syntax}:
6998 @code{RESULT = ISHFT(I, SHIFT)}
7000 @item @emph{Arguments}:
7001 @multitable @columnfractions .15 .70
7002 @item @var{I} @tab The type shall be @code{INTEGER}.
7003 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
7006 @item @emph{Return value}:
7007 The return value is of type @code{INTEGER} and of the same kind as
7010 @item @emph{See also}:
7017 @section @code{ISHFTC} --- Shift bits circularly
7019 @cindex bits, shift circular
7022 @item @emph{Description}:
7023 @code{ISHFTC} returns a value corresponding to @var{I} with the
7024 rightmost @var{SIZE} bits shifted circularly @var{SHIFT} places; that
7025 is, bits shifted out one end are shifted into the opposite end. A value
7026 of @var{SHIFT} greater than zero corresponds to a left shift, a value of
7027 zero corresponds to no shift, and a value less than zero corresponds to
7028 a right shift. The absolute value of @var{SHIFT} must be less than
7029 @var{SIZE}. If the @var{SIZE} argument is omitted, it is taken to be
7030 equivalent to @code{BIT_SIZE(I)}.
7032 @item @emph{Standard}:
7033 Fortran 95 and later
7038 @item @emph{Syntax}:
7039 @code{RESULT = ISHFTC(I, SHIFT [, SIZE])}
7041 @item @emph{Arguments}:
7042 @multitable @columnfractions .15 .70
7043 @item @var{I} @tab The type shall be @code{INTEGER}.
7044 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
7045 @item @var{SIZE} @tab (Optional) The type shall be @code{INTEGER};
7046 the value must be greater than zero and less than or equal to
7050 @item @emph{Return value}:
7051 The return value is of type @code{INTEGER} and of the same kind as
7054 @item @emph{See also}:
7061 @section @code{ISNAN} --- Test for a NaN
7066 @item @emph{Description}:
7067 @code{ISNAN} tests whether a floating-point value is an IEEE
7069 @item @emph{Standard}:
7075 @item @emph{Syntax}:
7078 @item @emph{Arguments}:
7079 @multitable @columnfractions .15 .70
7080 @item @var{X} @tab Variable of the type @code{REAL}.
7084 @item @emph{Return value}:
7085 Returns a default-kind @code{LOGICAL}. The returned value is @code{TRUE}
7086 if @var{X} is a NaN and @code{FALSE} otherwise.
7088 @item @emph{Example}:
7095 if (isnan(x)) stop '"x" is a NaN'
7096 end program test_nan
7103 @section @code{ITIME} --- Get current local time subroutine (hour/minutes/seconds)
7105 @cindex time, current
7106 @cindex current time
7109 @item @emph{Description}:
7110 @code{IDATE(VALUES)} Fills @var{VALUES} with the numerical values at the
7111 current local time. The hour (in the range 1-24), minute (in the range 1-60),
7112 and seconds (in the range 1-60) appear in elements 1, 2, and 3 of @var{VALUES},
7115 @item @emph{Standard}:
7121 @item @emph{Syntax}:
7122 @code{CALL ITIME(VALUES)}
7124 @item @emph{Arguments}:
7125 @multitable @columnfractions .15 .70
7126 @item @var{VALUES} @tab The type shall be @code{INTEGER, DIMENSION(3)}
7127 and the kind shall be the default integer kind.
7130 @item @emph{Return value}:
7131 Does not return anything.
7134 @item @emph{Example}:
7137 integer, dimension(3) :: tarray
7142 end program test_itime
7149 @section @code{KILL} --- Send a signal to a process
7153 @item @emph{Description}:
7154 @item @emph{Standard}:
7155 Sends the signal specified by @var{SIGNAL} to the process @var{PID}.
7158 This intrinsic is provided in both subroutine and function forms; however,
7159 only one form can be used in any given program unit.
7162 Subroutine, function
7164 @item @emph{Syntax}:
7165 @multitable @columnfractions .80
7166 @item @code{CALL KILL(C, VALUE [, STATUS])}
7167 @item @code{STATUS = KILL(C, VALUE)}
7170 @item @emph{Arguments}:
7171 @multitable @columnfractions .15 .70
7172 @item @var{C} @tab Shall be a scalar @code{INTEGER}, with
7174 @item @var{VALUE} @tab Shall be a scalar @code{INTEGER}, with
7176 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)} or
7177 @code{INTEGER(8)}. Returns 0 on success, or a system-specific error code
7181 @item @emph{See also}:
7182 @ref{ABORT}, @ref{EXIT}
7188 @section @code{KIND} --- Kind of an entity
7193 @item @emph{Description}:
7194 @code{KIND(X)} returns the kind value of the entity @var{X}.
7196 @item @emph{Standard}:
7197 Fortran 95 and later
7202 @item @emph{Syntax}:
7205 @item @emph{Arguments}:
7206 @multitable @columnfractions .15 .70
7207 @item @var{X} @tab Shall be of type @code{LOGICAL}, @code{INTEGER},
7208 @code{REAL}, @code{COMPLEX} or @code{CHARACTER}.
7211 @item @emph{Return value}:
7212 The return value is a scalar of type @code{INTEGER} and of the default
7215 @item @emph{Example}:
7218 integer,parameter :: kc = kind(' ')
7219 integer,parameter :: kl = kind(.true.)
7221 print *, "The default character kind is ", kc
7222 print *, "The default logical kind is ", kl
7223 end program test_kind
7231 @section @code{LBOUND} --- Lower dimension bounds of an array
7233 @cindex array, lower bound
7236 @item @emph{Description}:
7237 Returns the lower bounds of an array, or a single lower bound
7238 along the @var{DIM} dimension.
7239 @item @emph{Standard}:
7240 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
7245 @item @emph{Syntax}:
7246 @code{RESULT = LBOUND(ARRAY [, DIM [, KIND]])}
7248 @item @emph{Arguments}:
7249 @multitable @columnfractions .15 .70
7250 @item @var{ARRAY} @tab Shall be an array, of any type.
7251 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER}.
7252 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
7253 expression indicating the kind parameter of the result.
7256 @item @emph{Return value}:
7257 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
7258 @var{KIND} is absent, the return value is of default integer kind.
7259 If @var{DIM} is absent, the result is an array of the lower bounds of
7260 @var{ARRAY}. If @var{DIM} is present, the result is a scalar
7261 corresponding to the lower bound of the array along that dimension. If
7262 @var{ARRAY} is an expression rather than a whole array or array
7263 structure component, or if it has a zero extent along the relevant
7264 dimension, the lower bound is taken to be 1.
7266 @item @emph{See also}:
7267 @ref{UBOUND}, @ref{LCOBOUND}
7273 @section @code{LCOBOUND} --- Lower codimension bounds of an array
7275 @cindex coarray, lower bound
7278 @item @emph{Description}:
7279 Returns the lower bounds of a coarray, or a single lower cobound
7280 along the @var{DIM} codimension.
7281 @item @emph{Standard}:
7282 Fortran 2008 and later
7287 @item @emph{Syntax}:
7288 @code{RESULT = LCOBOUND(COARRAY [, DIM [, KIND]])}
7290 @item @emph{Arguments}:
7291 @multitable @columnfractions .15 .70
7292 @item @var{ARRAY} @tab Shall be an coarray, of any type.
7293 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER}.
7294 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
7295 expression indicating the kind parameter of the result.
7298 @item @emph{Return value}:
7299 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
7300 @var{KIND} is absent, the return value is of default integer kind.
7301 If @var{DIM} is absent, the result is an array of the lower cobounds of
7302 @var{COARRAY}. If @var{DIM} is present, the result is a scalar
7303 corresponding to the lower cobound of the array along that codimension.
7305 @item @emph{See also}:
7306 @ref{UCOBOUND}, @ref{LBOUND}
7312 @section @code{LEADZ} --- Number of leading zero bits of an integer
7317 @item @emph{Description}:
7318 @code{LEADZ} returns the number of leading zero bits of an integer.
7320 @item @emph{Standard}:
7321 Fortran 2008 and later
7326 @item @emph{Syntax}:
7327 @code{RESULT = LEADZ(I)}
7329 @item @emph{Arguments}:
7330 @multitable @columnfractions .15 .70
7331 @item @var{I} @tab Shall be of type @code{INTEGER}.
7334 @item @emph{Return value}:
7335 The type of the return value is the default @code{INTEGER}.
7336 If all the bits of @code{I} are zero, the result value is @code{BIT_SIZE(I)}.
7338 @item @emph{Example}:
7341 WRITE (*,*) BIT_SIZE(1) ! prints 32
7342 WRITE (*,*) LEADZ(1) ! prints 31
7346 @item @emph{See also}:
7347 @ref{BIT_SIZE}, @ref{TRAILZ}, @ref{POPCNT}, @ref{POPPAR}
7353 @section @code{LEN} --- Length of a character entity
7355 @cindex string, length
7358 @item @emph{Description}:
7359 Returns the length of a character string. If @var{STRING} is an array,
7360 the length of an element of @var{STRING} is returned. Note that
7361 @var{STRING} need not be defined when this intrinsic is invoked, since
7362 only the length, not the content, of @var{STRING} is needed.
7364 @item @emph{Standard}:
7365 Fortran 77 and later, with @var{KIND} argument Fortran 2003 and later
7370 @item @emph{Syntax}:
7371 @code{L = LEN(STRING [, KIND])}
7373 @item @emph{Arguments}:
7374 @multitable @columnfractions .15 .70
7375 @item @var{STRING} @tab Shall be a scalar or array of type
7376 @code{CHARACTER}, with @code{INTENT(IN)}
7377 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
7378 expression indicating the kind parameter of the result.
7381 @item @emph{Return value}:
7382 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
7383 @var{KIND} is absent, the return value is of default integer kind.
7386 @item @emph{Specific names}:
7387 @multitable @columnfractions .20 .20 .20 .25
7388 @item Name @tab Argument @tab Return type @tab Standard
7389 @item @code{LEN(STRING)} @tab @code{CHARACTER} @tab @code{INTEGER} @tab Fortran 77 and later
7393 @item @emph{See also}:
7394 @ref{LEN_TRIM}, @ref{ADJUSTL}, @ref{ADJUSTR}
7400 @section @code{LEN_TRIM} --- Length of a character entity without trailing blank characters
7402 @cindex string, length, without trailing whitespace
7405 @item @emph{Description}:
7406 Returns the length of a character string, ignoring any trailing blanks.
7408 @item @emph{Standard}:
7409 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
7414 @item @emph{Syntax}:
7415 @code{RESULT = LEN_TRIM(STRING [, KIND])}
7417 @item @emph{Arguments}:
7418 @multitable @columnfractions .15 .70
7419 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER},
7420 with @code{INTENT(IN)}
7421 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
7422 expression indicating the kind parameter of the result.
7425 @item @emph{Return value}:
7426 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
7427 @var{KIND} is absent, the return value is of default integer kind.
7429 @item @emph{See also}:
7430 @ref{LEN}, @ref{ADJUSTL}, @ref{ADJUSTR}
7436 @section @code{LGE} --- Lexical greater than or equal
7438 @cindex lexical comparison of strings
7439 @cindex string, comparison
7442 @item @emph{Description}:
7443 Determines whether one string is lexically greater than or equal to
7444 another string, where the two strings are interpreted as containing
7445 ASCII character codes. If the String A and String B are not the same
7446 length, the shorter is compared as if spaces were appended to it to form
7447 a value that has the same length as the longer.
7449 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
7450 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
7451 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
7452 that the latter use the processor's character ordering (which is not
7453 ASCII on some targets), whereas the former always use the ASCII
7456 @item @emph{Standard}:
7457 Fortran 77 and later
7462 @item @emph{Syntax}:
7463 @code{RESULT = LGE(STRING_A, STRING_B)}
7465 @item @emph{Arguments}:
7466 @multitable @columnfractions .15 .70
7467 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
7468 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
7471 @item @emph{Return value}:
7472 Returns @code{.TRUE.} if @code{STRING_A >= STRING_B}, and @code{.FALSE.}
7473 otherwise, based on the ASCII ordering.
7475 @item @emph{Specific names}:
7476 @multitable @columnfractions .20 .20 .20 .25
7477 @item Name @tab Argument @tab Return type @tab Standard
7478 @item @code{LGE(STRING_A, STRING_B)} @tab @code{CHARACTER} @tab @code{LOGICAL} @tab Fortran 77 and later
7481 @item @emph{See also}:
7482 @ref{LGT}, @ref{LLE}, @ref{LLT}
7488 @section @code{LGT} --- Lexical greater than
7490 @cindex lexical comparison of strings
7491 @cindex string, comparison
7494 @item @emph{Description}:
7495 Determines whether one string is lexically greater than another string,
7496 where the two strings are interpreted as containing ASCII character
7497 codes. If the String A and String B are not the same length, the
7498 shorter is compared as if spaces were appended to it to form a value
7499 that has the same length as the longer.
7501 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
7502 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
7503 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
7504 that the latter use the processor's character ordering (which is not
7505 ASCII on some targets), whereas the former always use the ASCII
7508 @item @emph{Standard}:
7509 Fortran 77 and later
7514 @item @emph{Syntax}:
7515 @code{RESULT = LGT(STRING_A, STRING_B)}
7517 @item @emph{Arguments}:
7518 @multitable @columnfractions .15 .70
7519 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
7520 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
7523 @item @emph{Return value}:
7524 Returns @code{.TRUE.} if @code{STRING_A > STRING_B}, and @code{.FALSE.}
7525 otherwise, based on the ASCII ordering.
7527 @item @emph{Specific names}:
7528 @multitable @columnfractions .20 .20 .20 .25
7529 @item Name @tab Argument @tab Return type @tab Standard
7530 @item @code{LGT(STRING_A, STRING_B)} @tab @code{CHARACTER} @tab @code{LOGICAL} @tab Fortran 77 and later
7533 @item @emph{See also}:
7534 @ref{LGE}, @ref{LLE}, @ref{LLT}
7540 @section @code{LINK} --- Create a hard link
7542 @cindex file system, create link
7543 @cindex file system, hard link
7546 @item @emph{Description}:
7547 Makes a (hard) link from file @var{PATH1} to @var{PATH2}. A null
7548 character (@code{CHAR(0)}) can be used to mark the end of the names in
7549 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
7550 names are ignored. If the @var{STATUS} argument is supplied, it
7551 contains 0 on success or a nonzero error code upon return; see
7554 This intrinsic is provided in both subroutine and function forms;
7555 however, only one form can be used in any given program unit.
7557 @item @emph{Standard}:
7561 Subroutine, function
7563 @item @emph{Syntax}:
7564 @multitable @columnfractions .80
7565 @item @code{CALL LINK(PATH1, PATH2 [, STATUS])}
7566 @item @code{STATUS = LINK(PATH1, PATH2)}
7569 @item @emph{Arguments}:
7570 @multitable @columnfractions .15 .70
7571 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
7572 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
7573 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
7576 @item @emph{See also}:
7577 @ref{SYMLNK}, @ref{UNLINK}
7583 @section @code{LLE} --- Lexical less than or equal
7585 @cindex lexical comparison of strings
7586 @cindex string, comparison
7589 @item @emph{Description}:
7590 Determines whether one string is lexically less than or equal to another
7591 string, where the two strings are interpreted as containing ASCII
7592 character codes. If the String A and String B are not the same length,
7593 the shorter is compared as if spaces were appended to it to form a value
7594 that has the same length as the longer.
7596 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
7597 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
7598 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
7599 that the latter use the processor's character ordering (which is not
7600 ASCII on some targets), whereas the former always use the ASCII
7603 @item @emph{Standard}:
7604 Fortran 77 and later
7609 @item @emph{Syntax}:
7610 @code{RESULT = LLE(STRING_A, STRING_B)}
7612 @item @emph{Arguments}:
7613 @multitable @columnfractions .15 .70
7614 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
7615 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
7618 @item @emph{Return value}:
7619 Returns @code{.TRUE.} if @code{STRING_A <= STRING_B}, and @code{.FALSE.}
7620 otherwise, based on the ASCII ordering.
7622 @item @emph{Specific names}:
7623 @multitable @columnfractions .20 .20 .20 .25
7624 @item Name @tab Argument @tab Return type @tab Standard
7625 @item @code{LLE(STRING_A, STRING_B)} @tab @code{CHARACTER} @tab @code{LOGICAL} @tab Fortran 77 and later
7628 @item @emph{See also}:
7629 @ref{LGE}, @ref{LGT}, @ref{LLT}
7635 @section @code{LLT} --- Lexical less than
7637 @cindex lexical comparison of strings
7638 @cindex string, comparison
7641 @item @emph{Description}:
7642 Determines whether one string is lexically less than another string,
7643 where the two strings are interpreted as containing ASCII character
7644 codes. If the String A and String B are not the same length, the
7645 shorter is compared as if spaces were appended to it to form a value
7646 that has the same length as the longer.
7648 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
7649 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
7650 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
7651 that the latter use the processor's character ordering (which is not
7652 ASCII on some targets), whereas the former always use the ASCII
7655 @item @emph{Standard}:
7656 Fortran 77 and later
7661 @item @emph{Syntax}:
7662 @code{RESULT = LLT(STRING_A, STRING_B)}
7664 @item @emph{Arguments}:
7665 @multitable @columnfractions .15 .70
7666 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
7667 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
7670 @item @emph{Return value}:
7671 Returns @code{.TRUE.} if @code{STRING_A < STRING_B}, and @code{.FALSE.}
7672 otherwise, based on the ASCII ordering.
7674 @item @emph{Specific names}:
7675 @multitable @columnfractions .20 .20 .20 .25
7676 @item Name @tab Argument @tab Return type @tab Standard
7677 @item @code{LLT(STRING_A, STRING_B)} @tab @code{CHARACTER} @tab @code{LOGICAL} @tab Fortran 77 and later
7680 @item @emph{See also}:
7681 @ref{LGE}, @ref{LGT}, @ref{LLE}
7687 @section @code{LNBLNK} --- Index of the last non-blank character in a string
7689 @cindex string, find non-blank character
7692 @item @emph{Description}:
7693 Returns the length of a character string, ignoring any trailing blanks.
7694 This is identical to the standard @code{LEN_TRIM} intrinsic, and is only
7695 included for backwards compatibility.
7697 @item @emph{Standard}:
7703 @item @emph{Syntax}:
7704 @code{RESULT = LNBLNK(STRING)}
7706 @item @emph{Arguments}:
7707 @multitable @columnfractions .15 .70
7708 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER},
7709 with @code{INTENT(IN)}
7712 @item @emph{Return value}:
7713 The return value is of @code{INTEGER(kind=4)} type.
7715 @item @emph{See also}:
7716 @ref{INDEX intrinsic}, @ref{LEN_TRIM}
7722 @section @code{LOC} --- Returns the address of a variable
7724 @cindex location of a variable in memory
7727 @item @emph{Description}:
7728 @code{LOC(X)} returns the address of @var{X} as an integer.
7730 @item @emph{Standard}:
7736 @item @emph{Syntax}:
7737 @code{RESULT = LOC(X)}
7739 @item @emph{Arguments}:
7740 @multitable @columnfractions .15 .70
7741 @item @var{X} @tab Variable of any type.
7744 @item @emph{Return value}:
7745 The return value is of type @code{INTEGER}, with a @code{KIND}
7746 corresponding to the size (in bytes) of a memory address on the target
7749 @item @emph{Example}:
7756 end program test_loc
7763 @section @code{LOG} --- Logarithm function
7770 @cindex exponential function, inverse
7771 @cindex logarithmic function
7774 @item @emph{Description}:
7775 @code{LOG(X)} computes the logarithm of @var{X}.
7777 @item @emph{Standard}:
7778 Fortran 77 and later
7783 @item @emph{Syntax}:
7784 @code{RESULT = LOG(X)}
7786 @item @emph{Arguments}:
7787 @multitable @columnfractions .15 .70
7788 @item @var{X} @tab The type shall be @code{REAL} or
7792 @item @emph{Return value}:
7793 The return value is of type @code{REAL} or @code{COMPLEX}.
7794 The kind type parameter is the same as @var{X}.
7795 If @var{X} is @code{COMPLEX}, the imaginary part @math{\omega} is in the range
7796 @math{-\pi \leq \omega \leq \pi}.
7798 @item @emph{Example}:
7801 real(8) :: x = 1.0_8
7802 complex :: z = (1.0, 2.0)
7805 end program test_log
7808 @item @emph{Specific names}:
7809 @multitable @columnfractions .20 .20 .20 .25
7810 @item Name @tab Argument @tab Return type @tab Standard
7811 @item @code{ALOG(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab f95, gnu
7812 @item @code{DLOG(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab f95, gnu
7813 @item @code{CLOG(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab f95, gnu
7814 @item @code{ZLOG(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
7815 @item @code{CDLOG(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
7822 @section @code{LOG10} --- Base 10 logarithm function
7826 @cindex exponential function, inverse
7827 @cindex logarithmic function
7830 @item @emph{Description}:
7831 @code{LOG10(X)} computes the base 10 logarithm of @var{X}.
7833 @item @emph{Standard}:
7834 Fortran 77 and later
7839 @item @emph{Syntax}:
7840 @code{RESULT = LOG10(X)}
7842 @item @emph{Arguments}:
7843 @multitable @columnfractions .15 .70
7844 @item @var{X} @tab The type shall be @code{REAL}.
7847 @item @emph{Return value}:
7848 The return value is of type @code{REAL} or @code{COMPLEX}.
7849 The kind type parameter is the same as @var{X}.
7851 @item @emph{Example}:
7854 real(8) :: x = 10.0_8
7856 end program test_log10
7859 @item @emph{Specific names}:
7860 @multitable @columnfractions .20 .20 .20 .25
7861 @item Name @tab Argument @tab Return type @tab Standard
7862 @item @code{ALOG10(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 95 and later
7863 @item @code{DLOG10(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 95 and later
7870 @section @code{LOG_GAMMA} --- Logarithm of the Gamma function
7875 @cindex Gamma function, logarithm of
7878 @item @emph{Description}:
7879 @code{LOG_GAMMA(X)} computes the natural logarithm of the absolute value
7880 of the Gamma (@math{\Gamma}) function.
7882 @item @emph{Standard}:
7883 Fortran 2008 and later
7888 @item @emph{Syntax}:
7889 @code{X = LOG_GAMMA(X)}
7891 @item @emph{Arguments}:
7892 @multitable @columnfractions .15 .70
7893 @item @var{X} @tab Shall be of type @code{REAL} and neither zero
7894 nor a negative integer.
7897 @item @emph{Return value}:
7898 The return value is of type @code{REAL} of the same kind as @var{X}.
7900 @item @emph{Example}:
7902 program test_log_gamma
7904 x = lgamma(x) ! returns 0.0
7905 end program test_log_gamma
7908 @item @emph{Specific names}:
7909 @multitable @columnfractions .20 .20 .20 .25
7910 @item Name @tab Argument @tab Return type @tab Standard
7911 @item @code{LGAMMA(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab GNU Extension
7912 @item @code{ALGAMA(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab GNU Extension
7913 @item @code{DLGAMA(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU Extension
7916 @item @emph{See also}:
7917 Gamma function: @ref{GAMMA}
7924 @section @code{LOGICAL} --- Convert to logical type
7926 @cindex conversion, to logical
7929 @item @emph{Description}:
7930 Converts one kind of @code{LOGICAL} variable to another.
7932 @item @emph{Standard}:
7933 Fortran 95 and later
7938 @item @emph{Syntax}:
7939 @code{RESULT = LOGICAL(L [, KIND])}
7941 @item @emph{Arguments}:
7942 @multitable @columnfractions .15 .70
7943 @item @var{L} @tab The type shall be @code{LOGICAL}.
7944 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
7945 expression indicating the kind parameter of the result.
7948 @item @emph{Return value}:
7949 The return value is a @code{LOGICAL} value equal to @var{L}, with a
7950 kind corresponding to @var{KIND}, or of the default logical kind if
7951 @var{KIND} is not given.
7953 @item @emph{See also}:
7954 @ref{INT}, @ref{REAL}, @ref{CMPLX}
7960 @section @code{LONG} --- Convert to integer type
7962 @cindex conversion, to integer
7965 @item @emph{Description}:
7966 Convert to a @code{KIND=4} integer type, which is the same size as a C
7967 @code{long} integer. This is equivalent to the standard @code{INT}
7968 intrinsic with an optional argument of @code{KIND=4}, and is only
7969 included for backwards compatibility.
7971 @item @emph{Standard}:
7977 @item @emph{Syntax}:
7978 @code{RESULT = LONG(A)}
7980 @item @emph{Arguments}:
7981 @multitable @columnfractions .15 .70
7982 @item @var{A} @tab Shall be of type @code{INTEGER},
7983 @code{REAL}, or @code{COMPLEX}.
7986 @item @emph{Return value}:
7987 The return value is a @code{INTEGER(4)} variable.
7989 @item @emph{See also}:
7990 @ref{INT}, @ref{INT2}, @ref{INT8}
7996 @section @code{LSHIFT} --- Left shift bits
7998 @cindex bits, shift left
8001 @item @emph{Description}:
8002 @code{LSHIFT} returns a value corresponding to @var{I} with all of the
8003 bits shifted left by @var{SHIFT} places. If the absolute value of
8004 @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the value is undefined.
8005 Bits shifted out from the left end are lost; zeros are shifted in from
8008 This function has been superseded by the @code{ISHFT} intrinsic, which
8009 is standard in Fortran 95 and later, and the @code{SHIFTL} intrinsic,
8010 which is standard in Fortran 2008 and later.
8012 @item @emph{Standard}:
8018 @item @emph{Syntax}:
8019 @code{RESULT = LSHIFT(I, SHIFT)}
8021 @item @emph{Arguments}:
8022 @multitable @columnfractions .15 .70
8023 @item @var{I} @tab The type shall be @code{INTEGER}.
8024 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
8027 @item @emph{Return value}:
8028 The return value is of type @code{INTEGER} and of the same kind as
8031 @item @emph{See also}:
8032 @ref{ISHFT}, @ref{ISHFTC}, @ref{RSHIFT}, @ref{SHIFTA}, @ref{SHIFTL},
8040 @section @code{LSTAT} --- Get file status
8042 @cindex file system, file status
8045 @item @emph{Description}:
8046 @code{LSTAT} is identical to @ref{STAT}, except that if path is a
8047 symbolic link, then the link itself is statted, not the file that it
8050 The elements in @code{VALUES} are the same as described by @ref{STAT}.
8052 This intrinsic is provided in both subroutine and function forms;
8053 however, only one form can be used in any given program unit.
8055 @item @emph{Standard}:
8059 Subroutine, function
8061 @item @emph{Syntax}:
8062 @multitable @columnfractions .80
8063 @item @code{CALL LSTAT(NAME, VALUES [, STATUS])}
8064 @item @code{STATUS = LSTAT(NAME, VALUES)}
8067 @item @emph{Arguments}:
8068 @multitable @columnfractions .15 .70
8069 @item @var{NAME} @tab The type shall be @code{CHARACTER} of the default
8070 kind, a valid path within the file system.
8071 @item @var{VALUES} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
8072 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}.
8073 Returns 0 on success and a system specific error code otherwise.
8076 @item @emph{Example}:
8077 See @ref{STAT} for an example.
8079 @item @emph{See also}:
8080 To stat an open file: @ref{FSTAT}, to stat a file: @ref{STAT}
8086 @section @code{LTIME} --- Convert time to local time info
8088 @cindex time, conversion to local time info
8091 @item @emph{Description}:
8092 Given a system time value @var{TIME} (as provided by the @code{TIME8}
8093 intrinsic), fills @var{VALUES} with values extracted from it appropriate
8094 to the local time zone using @code{localtime(3)}.
8096 @item @emph{Standard}:
8102 @item @emph{Syntax}:
8103 @code{CALL LTIME(TIME, VALUES)}
8105 @item @emph{Arguments}:
8106 @multitable @columnfractions .15 .70
8107 @item @var{TIME} @tab An @code{INTEGER} scalar expression
8108 corresponding to a system time, with @code{INTENT(IN)}.
8109 @item @var{VALUES} @tab A default @code{INTEGER} array with 9 elements,
8110 with @code{INTENT(OUT)}.
8113 @item @emph{Return value}:
8114 The elements of @var{VALUES} are assigned as follows:
8116 @item Seconds after the minute, range 0--59 or 0--61 to allow for leap
8118 @item Minutes after the hour, range 0--59
8119 @item Hours past midnight, range 0--23
8120 @item Day of month, range 0--31
8121 @item Number of months since January, range 0--12
8122 @item Years since 1900
8123 @item Number of days since Sunday, range 0--6
8124 @item Days since January 1
8125 @item Daylight savings indicator: positive if daylight savings is in
8126 effect, zero if not, and negative if the information is not available.
8129 @item @emph{See also}:
8130 @ref{CTIME}, @ref{GMTIME}, @ref{TIME}, @ref{TIME8}
8137 @section @code{MALLOC} --- Allocate dynamic memory
8139 @cindex pointer, cray
8142 @item @emph{Description}:
8143 @code{MALLOC(SIZE)} allocates @var{SIZE} bytes of dynamic memory and
8144 returns the address of the allocated memory. The @code{MALLOC} intrinsic
8145 is an extension intended to be used with Cray pointers, and is provided
8146 in GNU Fortran to allow the user to compile legacy code. For new code
8147 using Fortran 95 pointers, the memory allocation intrinsic is
8150 @item @emph{Standard}:
8156 @item @emph{Syntax}:
8157 @code{PTR = MALLOC(SIZE)}
8159 @item @emph{Arguments}:
8160 @multitable @columnfractions .15 .70
8161 @item @var{SIZE} @tab The type shall be @code{INTEGER}.
8164 @item @emph{Return value}:
8165 The return value is of type @code{INTEGER(K)}, with @var{K} such that
8166 variables of type @code{INTEGER(K)} have the same size as
8167 C pointers (@code{sizeof(void *)}).
8169 @item @emph{Example}:
8170 The following example demonstrates the use of @code{MALLOC} and
8171 @code{FREE} with Cray pointers.
8180 ptr_x = malloc(20*8)
8182 x(i) = sqrt(1.0d0 / i)
8190 end program test_malloc
8193 @item @emph{See also}:
8200 @section @code{MASKL} --- Left justified mask
8202 @cindex mask, left justified
8205 @item @emph{Description}:
8206 @code{MASKL(I[, KIND])} has its leftmost @var{I} bits set to 1, and the
8207 remaining bits set to 0.
8209 @item @emph{Standard}:
8210 Fortran 2008 and later
8215 @item @emph{Syntax}:
8216 @code{RESULT = MASKL(I[, KIND])}
8218 @item @emph{Arguments}:
8219 @multitable @columnfractions .15 .70
8220 @item @var{I} @tab Shall be of type @code{INTEGER}.
8221 @item @var{KIND} @tab Shall be a scalar constant expression of type
8225 @item @emph{Return value}:
8226 The return value is of type @code{INTEGER}. If @var{KIND} is present, it
8227 specifies the kind value of the return type; otherwise, it is of the
8228 default integer kind.
8230 @item @emph{See also}:
8237 @section @code{MASKR} --- Right justified mask
8239 @cindex mask, right justified
8242 @item @emph{Description}:
8243 @code{MASKL(I[, KIND])} has its rightmost @var{I} bits set to 1, and the
8244 remaining bits set to 0.
8246 @item @emph{Standard}:
8247 Fortran 2008 and later
8252 @item @emph{Syntax}:
8253 @code{RESULT = MASKR(I[, KIND])}
8255 @item @emph{Arguments}:
8256 @multitable @columnfractions .15 .70
8257 @item @var{I} @tab Shall be of type @code{INTEGER}.
8258 @item @var{KIND} @tab Shall be a scalar constant expression of type
8262 @item @emph{Return value}:
8263 The return value is of type @code{INTEGER}. If @var{KIND} is present, it
8264 specifies the kind value of the return type; otherwise, it is of the
8265 default integer kind.
8267 @item @emph{See also}:
8274 @section @code{MATMUL} --- matrix multiplication
8276 @cindex matrix multiplication
8277 @cindex product, matrix
8280 @item @emph{Description}:
8281 Performs a matrix multiplication on numeric or logical arguments.
8283 @item @emph{Standard}:
8284 Fortran 95 and later
8287 Transformational function
8289 @item @emph{Syntax}:
8290 @code{RESULT = MATMUL(MATRIX_A, MATRIX_B)}
8292 @item @emph{Arguments}:
8293 @multitable @columnfractions .15 .70
8294 @item @var{MATRIX_A} @tab An array of @code{INTEGER},
8295 @code{REAL}, @code{COMPLEX}, or @code{LOGICAL} type, with a rank of
8297 @item @var{MATRIX_B} @tab An array of @code{INTEGER},
8298 @code{REAL}, or @code{COMPLEX} type if @var{MATRIX_A} is of a numeric
8299 type; otherwise, an array of @code{LOGICAL} type. The rank shall be one
8300 or two, and the first (or only) dimension of @var{MATRIX_B} shall be
8301 equal to the last (or only) dimension of @var{MATRIX_A}.
8304 @item @emph{Return value}:
8305 The matrix product of @var{MATRIX_A} and @var{MATRIX_B}. The type and
8306 kind of the result follow the usual type and kind promotion rules, as
8307 for the @code{*} or @code{.AND.} operators.
8309 @item @emph{See also}:
8315 @section @code{MAX} --- Maximum value of an argument list
8322 @cindex maximum value
8325 @item @emph{Description}:
8326 Returns the argument with the largest (most positive) value.
8328 @item @emph{Standard}:
8329 Fortran 77 and later
8334 @item @emph{Syntax}:
8335 @code{RESULT = MAX(A1, A2 [, A3 [, ...]])}
8337 @item @emph{Arguments}:
8338 @multitable @columnfractions .15 .70
8339 @item @var{A1} @tab The type shall be @code{INTEGER} or
8341 @item @var{A2}, @var{A3}, ... @tab An expression of the same type and kind
8342 as @var{A1}. (As a GNU extension, arguments of different kinds are
8346 @item @emph{Return value}:
8347 The return value corresponds to the maximum value among the arguments,
8348 and has the same type and kind as the first argument.
8350 @item @emph{Specific names}:
8351 @multitable @columnfractions .20 .20 .20 .25
8352 @item Name @tab Argument @tab Return type @tab Standard
8353 @item @code{MAX0(A1)} @tab @code{INTEGER(4) A1} @tab @code{INTEGER(4)} @tab Fortran 77 and later
8354 @item @code{AMAX0(A1)} @tab @code{INTEGER(4) A1} @tab @code{REAL(MAX(X))} @tab Fortran 77 and later
8355 @item @code{MAX1(A1)} @tab @code{REAL A1} @tab @code{INT(MAX(X))} @tab Fortran 77 and later
8356 @item @code{AMAX1(A1)} @tab @code{REAL(4) A1} @tab @code{REAL(4)} @tab Fortran 77 and later
8357 @item @code{DMAX1(A1)} @tab @code{REAL(8) A1} @tab @code{REAL(8)} @tab Fortran 77 and later
8360 @item @emph{See also}:
8361 @ref{MAXLOC} @ref{MAXVAL}, @ref{MIN}
8368 @section @code{MAXEXPONENT} --- Maximum exponent of a real kind
8369 @fnindex MAXEXPONENT
8370 @cindex model representation, maximum exponent
8373 @item @emph{Description}:
8374 @code{MAXEXPONENT(X)} returns the maximum exponent in the model of the
8377 @item @emph{Standard}:
8378 Fortran 95 and later
8383 @item @emph{Syntax}:
8384 @code{RESULT = MAXEXPONENT(X)}
8386 @item @emph{Arguments}:
8387 @multitable @columnfractions .15 .70
8388 @item @var{X} @tab Shall be of type @code{REAL}.
8391 @item @emph{Return value}:
8392 The return value is of type @code{INTEGER} and of the default integer
8395 @item @emph{Example}:
8401 print *, minexponent(x), maxexponent(x)
8402 print *, minexponent(y), maxexponent(y)
8403 end program exponents
8410 @section @code{MAXLOC} --- Location of the maximum value within an array
8412 @cindex array, location of maximum element
8415 @item @emph{Description}:
8416 Determines the location of the element in the array with the maximum
8417 value, or, if the @var{DIM} argument is supplied, determines the
8418 locations of the maximum element along each row of the array in the
8419 @var{DIM} direction. If @var{MASK} is present, only the elements for
8420 which @var{MASK} is @code{.TRUE.} are considered. If more than one
8421 element in the array has the maximum value, the location returned is
8422 that of the first such element in array element order. If the array has
8423 zero size, or all of the elements of @var{MASK} are @code{.FALSE.}, then
8424 the result is an array of zeroes. Similarly, if @var{DIM} is supplied
8425 and all of the elements of @var{MASK} along a given row are zero, the
8426 result value for that row is zero.
8428 @item @emph{Standard}:
8429 Fortran 95 and later
8432 Transformational function
8434 @item @emph{Syntax}:
8435 @multitable @columnfractions .80
8436 @item @code{RESULT = MAXLOC(ARRAY, DIM [, MASK])}
8437 @item @code{RESULT = MAXLOC(ARRAY [, MASK])}
8440 @item @emph{Arguments}:
8441 @multitable @columnfractions .15 .70
8442 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER} or
8444 @item @var{DIM} @tab (Optional) Shall be a scalar of type
8445 @code{INTEGER}, with a value between one and the rank of @var{ARRAY},
8446 inclusive. It may not be an optional dummy argument.
8447 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL},
8448 and conformable with @var{ARRAY}.
8451 @item @emph{Return value}:
8452 If @var{DIM} is absent, the result is a rank-one array with a length
8453 equal to the rank of @var{ARRAY}. If @var{DIM} is present, the result
8454 is an array with a rank one less than the rank of @var{ARRAY}, and a
8455 size corresponding to the size of @var{ARRAY} with the @var{DIM}
8456 dimension removed. If @var{DIM} is present and @var{ARRAY} has a rank
8457 of one, the result is a scalar. In all cases, the result is of default
8458 @code{INTEGER} type.
8460 @item @emph{See also}:
8461 @ref{MAX}, @ref{MAXVAL}
8468 @section @code{MAXVAL} --- Maximum value of an array
8470 @cindex array, maximum value
8471 @cindex maximum value
8474 @item @emph{Description}:
8475 Determines the maximum value of the elements in an array value, or, if
8476 the @var{DIM} argument is supplied, determines the maximum value along
8477 each row of the array in the @var{DIM} direction. If @var{MASK} is
8478 present, only the elements for which @var{MASK} is @code{.TRUE.} are
8479 considered. If the array has zero size, or all of the elements of
8480 @var{MASK} are @code{.FALSE.}, then the result is @code{-HUGE(ARRAY)}
8481 if @var{ARRAY} is numeric, or a string of nulls if @var{ARRAY} is of character
8484 @item @emph{Standard}:
8485 Fortran 95 and later
8488 Transformational function
8490 @item @emph{Syntax}:
8491 @multitable @columnfractions .80
8492 @item @code{RESULT = MAXVAL(ARRAY, DIM [, MASK])}
8493 @item @code{RESULT = MAXVAL(ARRAY [, MASK])}
8496 @item @emph{Arguments}:
8497 @multitable @columnfractions .15 .70
8498 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER} or
8500 @item @var{DIM} @tab (Optional) Shall be a scalar of type
8501 @code{INTEGER}, with a value between one and the rank of @var{ARRAY},
8502 inclusive. It may not be an optional dummy argument.
8503 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL},
8504 and conformable with @var{ARRAY}.
8507 @item @emph{Return value}:
8508 If @var{DIM} is absent, or if @var{ARRAY} has a rank of one, the result
8509 is a scalar. If @var{DIM} is present, the result is an array with a
8510 rank one less than the rank of @var{ARRAY}, and a size corresponding to
8511 the size of @var{ARRAY} with the @var{DIM} dimension removed. In all
8512 cases, the result is of the same type and kind as @var{ARRAY}.
8514 @item @emph{See also}:
8515 @ref{MAX}, @ref{MAXLOC}
8521 @section @code{MCLOCK} --- Time function
8523 @cindex time, clock ticks
8527 @item @emph{Description}:
8528 Returns the number of clock ticks since the start of the process, based
8529 on the UNIX function @code{clock(3)}.
8531 This intrinsic is not fully portable, such as to systems with 32-bit
8532 @code{INTEGER} types but supporting times wider than 32 bits. Therefore,
8533 the values returned by this intrinsic might be, or become, negative, or
8534 numerically less than previous values, during a single run of the
8537 @item @emph{Standard}:
8543 @item @emph{Syntax}:
8544 @code{RESULT = MCLOCK()}
8546 @item @emph{Return value}:
8547 The return value is a scalar of type @code{INTEGER(4)}, equal to the
8548 number of clock ticks since the start of the process, or @code{-1} if
8549 the system does not support @code{clock(3)}.
8551 @item @emph{See also}:
8552 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK}, @ref{TIME}
8559 @section @code{MCLOCK8} --- Time function (64-bit)
8561 @cindex time, clock ticks
8565 @item @emph{Description}:
8566 Returns the number of clock ticks since the start of the process, based
8567 on the UNIX function @code{clock(3)}.
8569 @emph{Warning:} this intrinsic does not increase the range of the timing
8570 values over that returned by @code{clock(3)}. On a system with a 32-bit
8571 @code{clock(3)}, @code{MCLOCK8} will return a 32-bit value, even though
8572 it is converted to a 64-bit @code{INTEGER(8)} value. That means
8573 overflows of the 32-bit value can still occur. Therefore, the values
8574 returned by this intrinsic might be or become negative or numerically
8575 less than previous values during a single run of the compiled program.
8577 @item @emph{Standard}:
8583 @item @emph{Syntax}:
8584 @code{RESULT = MCLOCK8()}
8586 @item @emph{Return value}:
8587 The return value is a scalar of type @code{INTEGER(8)}, equal to the
8588 number of clock ticks since the start of the process, or @code{-1} if
8589 the system does not support @code{clock(3)}.
8591 @item @emph{See also}:
8592 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK}, @ref{TIME8}
8599 @section @code{MERGE} --- Merge variables
8601 @cindex array, merge arrays
8602 @cindex array, combine arrays
8605 @item @emph{Description}:
8606 Select values from two arrays according to a logical mask. The result
8607 is equal to @var{TSOURCE} if @var{MASK} is @code{.TRUE.}, or equal to
8608 @var{FSOURCE} if it is @code{.FALSE.}.
8610 @item @emph{Standard}:
8611 Fortran 95 and later
8616 @item @emph{Syntax}:
8617 @code{RESULT = MERGE(TSOURCE, FSOURCE, MASK)}
8619 @item @emph{Arguments}:
8620 @multitable @columnfractions .15 .70
8621 @item @var{TSOURCE} @tab May be of any type.
8622 @item @var{FSOURCE} @tab Shall be of the same type and type parameters
8624 @item @var{MASK} @tab Shall be of type @code{LOGICAL}.
8627 @item @emph{Return value}:
8628 The result is of the same type and type parameters as @var{TSOURCE}.
8635 @section @code{MERGE_BITS} --- Merge of bits under mask
8640 @item @emph{Description}:
8641 @code{MERGE_BITS(I, J, MASK)} merges the bits of @var{I} and @var{J}
8642 as determined by the mask. The i-th bit of the result is equal to the
8643 i-th bit of @var{I} if the i-th bit of @var{MASK} is 1; it is equal to
8644 the i-th bit of @var{J} otherwise.
8646 @item @emph{Standard}:
8647 Fortran 2008 and later
8652 @item @emph{Syntax}:
8653 @code{RESULT = MERGE_BITS(I, J, MASK)}
8655 @item @emph{Arguments}:
8656 @multitable @columnfractions .15 .70
8657 @item @var{I} @tab Shall be of type @code{INTEGER}.
8658 @item @var{J} @tab Shall be of type @code{INTEGER} and of the same
8660 @item @var{MASK} @tab Shall be of type @code{INTEGER} and of the same
8664 @item @emph{Return value}:
8665 The result is of the same type and kind as @var{I}.
8672 @section @code{MIN} --- Minimum value of an argument list
8679 @cindex minimum value
8682 @item @emph{Description}:
8683 Returns the argument with the smallest (most negative) value.
8685 @item @emph{Standard}:
8686 Fortran 77 and later
8691 @item @emph{Syntax}:
8692 @code{RESULT = MIN(A1, A2 [, A3, ...])}
8694 @item @emph{Arguments}:
8695 @multitable @columnfractions .15 .70
8696 @item @var{A1} @tab The type shall be @code{INTEGER} or
8698 @item @var{A2}, @var{A3}, ... @tab An expression of the same type and kind
8699 as @var{A1}. (As a GNU extension, arguments of different kinds are
8703 @item @emph{Return value}:
8704 The return value corresponds to the maximum value among the arguments,
8705 and has the same type and kind as the first argument.
8707 @item @emph{Specific names}:
8708 @multitable @columnfractions .20 .20 .20 .25
8709 @item Name @tab Argument @tab Return type @tab Standard
8710 @item @code{MIN0(A1)} @tab @code{INTEGER(4) A1} @tab @code{INTEGER(4)} @tab Fortran 77 and later
8711 @item @code{AMIN0(A1)} @tab @code{INTEGER(4) A1} @tab @code{REAL(4)} @tab Fortran 77 and later
8712 @item @code{MIN1(A1)} @tab @code{REAL A1} @tab @code{INTEGER(4)} @tab Fortran 77 and later
8713 @item @code{AMIN1(A1)} @tab @code{REAL(4) A1} @tab @code{REAL(4)} @tab Fortran 77 and later
8714 @item @code{DMIN1(A1)} @tab @code{REAL(8) A1} @tab @code{REAL(8)} @tab Fortran 77 and later
8717 @item @emph{See also}:
8718 @ref{MAX}, @ref{MINLOC}, @ref{MINVAL}
8724 @section @code{MINEXPONENT} --- Minimum exponent of a real kind
8725 @fnindex MINEXPONENT
8726 @cindex model representation, minimum exponent
8729 @item @emph{Description}:
8730 @code{MINEXPONENT(X)} returns the minimum exponent in the model of the
8733 @item @emph{Standard}:
8734 Fortran 95 and later
8739 @item @emph{Syntax}:
8740 @code{RESULT = MINEXPONENT(X)}
8742 @item @emph{Arguments}:
8743 @multitable @columnfractions .15 .70
8744 @item @var{X} @tab Shall be of type @code{REAL}.
8747 @item @emph{Return value}:
8748 The return value is of type @code{INTEGER} and of the default integer
8751 @item @emph{Example}:
8752 See @code{MAXEXPONENT} for an example.
8758 @section @code{MINLOC} --- Location of the minimum value within an array
8760 @cindex array, location of minimum element
8763 @item @emph{Description}:
8764 Determines the location of the element in the array with the minimum
8765 value, or, if the @var{DIM} argument is supplied, determines the
8766 locations of the minimum element along each row of the array in the
8767 @var{DIM} direction. If @var{MASK} is present, only the elements for
8768 which @var{MASK} is @code{.TRUE.} are considered. If more than one
8769 element in the array has the minimum value, the location returned is
8770 that of the first such element in array element order. If the array has
8771 zero size, or all of the elements of @var{MASK} are @code{.FALSE.}, then
8772 the result is an array of zeroes. Similarly, if @var{DIM} is supplied
8773 and all of the elements of @var{MASK} along a given row are zero, the
8774 result value for that row is zero.
8776 @item @emph{Standard}:
8777 Fortran 95 and later
8780 Transformational function
8782 @item @emph{Syntax}:
8783 @multitable @columnfractions .80
8784 @item @code{RESULT = MINLOC(ARRAY, DIM [, MASK])}
8785 @item @code{RESULT = MINLOC(ARRAY [, MASK])}
8788 @item @emph{Arguments}:
8789 @multitable @columnfractions .15 .70
8790 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER} or
8792 @item @var{DIM} @tab (Optional) Shall be a scalar of type
8793 @code{INTEGER}, with a value between one and the rank of @var{ARRAY},
8794 inclusive. It may not be an optional dummy argument.
8795 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL},
8796 and conformable with @var{ARRAY}.
8799 @item @emph{Return value}:
8800 If @var{DIM} is absent, the result is a rank-one array with a length
8801 equal to the rank of @var{ARRAY}. If @var{DIM} is present, the result
8802 is an array with a rank one less than the rank of @var{ARRAY}, and a
8803 size corresponding to the size of @var{ARRAY} with the @var{DIM}
8804 dimension removed. If @var{DIM} is present and @var{ARRAY} has a rank
8805 of one, the result is a scalar. In all cases, the result is of default
8806 @code{INTEGER} type.
8808 @item @emph{See also}:
8809 @ref{MIN}, @ref{MINVAL}
8816 @section @code{MINVAL} --- Minimum value of an array
8818 @cindex array, minimum value
8819 @cindex minimum value
8822 @item @emph{Description}:
8823 Determines the minimum value of the elements in an array value, or, if
8824 the @var{DIM} argument is supplied, determines the minimum value along
8825 each row of the array in the @var{DIM} direction. If @var{MASK} is
8826 present, only the elements for which @var{MASK} is @code{.TRUE.} are
8827 considered. If the array has zero size, or all of the elements of
8828 @var{MASK} are @code{.FALSE.}, then the result is @code{HUGE(ARRAY)} if
8829 @var{ARRAY} is numeric, or a string of @code{CHAR(255)} characters if
8830 @var{ARRAY} is of character type.
8832 @item @emph{Standard}:
8833 Fortran 95 and later
8836 Transformational function
8838 @item @emph{Syntax}:
8839 @multitable @columnfractions .80
8840 @item @code{RESULT = MINVAL(ARRAY, DIM [, MASK])}
8841 @item @code{RESULT = MINVAL(ARRAY [, MASK])}
8844 @item @emph{Arguments}:
8845 @multitable @columnfractions .15 .70
8846 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER} or
8848 @item @var{DIM} @tab (Optional) Shall be a scalar of type
8849 @code{INTEGER}, with a value between one and the rank of @var{ARRAY},
8850 inclusive. It may not be an optional dummy argument.
8851 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL},
8852 and conformable with @var{ARRAY}.
8855 @item @emph{Return value}:
8856 If @var{DIM} is absent, or if @var{ARRAY} has a rank of one, the result
8857 is a scalar. If @var{DIM} is present, the result is an array with a
8858 rank one less than the rank of @var{ARRAY}, and a size corresponding to
8859 the size of @var{ARRAY} with the @var{DIM} dimension removed. In all
8860 cases, the result is of the same type and kind as @var{ARRAY}.
8862 @item @emph{See also}:
8863 @ref{MIN}, @ref{MINLOC}
8870 @section @code{MOD} --- Remainder function
8875 @cindex division, remainder
8878 @item @emph{Description}:
8879 @code{MOD(A,P)} computes the remainder of the division of A by P@. It is
8880 calculated as @code{A - (INT(A/P) * P)}.
8882 @item @emph{Standard}:
8883 Fortran 77 and later
8888 @item @emph{Syntax}:
8889 @code{RESULT = MOD(A, P)}
8891 @item @emph{Arguments}:
8892 @multitable @columnfractions .15 .70
8893 @item @var{A} @tab Shall be a scalar of type @code{INTEGER} or @code{REAL}
8894 @item @var{P} @tab Shall be a scalar of the same type as @var{A} and not
8898 @item @emph{Return value}:
8899 The kind of the return value is the result of cross-promoting
8900 the kinds of the arguments.
8902 @item @emph{Example}:
8906 print *, mod(17.5,5.5)
8907 print *, mod(17.5d0,5.5)
8908 print *, mod(17.5,5.5d0)
8911 print *, mod(-17.5,5.5)
8912 print *, mod(-17.5d0,5.5)
8913 print *, mod(-17.5,5.5d0)
8916 print *, mod(17.5,-5.5)
8917 print *, mod(17.5d0,-5.5)
8918 print *, mod(17.5,-5.5d0)
8919 end program test_mod
8922 @item @emph{Specific names}:
8923 @multitable @columnfractions .20 .20 .20 .25
8924 @item Name @tab Arguments @tab Return type @tab Standard
8925 @item @code{MOD(A,P)} @tab @code{INTEGER A,P} @tab @code{INTEGER} @tab Fortran 95 and later
8926 @item @code{AMOD(A,P)} @tab @code{REAL(4) A,P} @tab @code{REAL(4)} @tab Fortran 95 and later
8927 @item @code{DMOD(A,P)} @tab @code{REAL(8) A,P} @tab @code{REAL(8)} @tab Fortran 95 and later
8934 @section @code{MODULO} --- Modulo function
8937 @cindex division, modulo
8940 @item @emph{Description}:
8941 @code{MODULO(A,P)} computes the @var{A} modulo @var{P}.
8943 @item @emph{Standard}:
8944 Fortran 95 and later
8949 @item @emph{Syntax}:
8950 @code{RESULT = MODULO(A, P)}
8952 @item @emph{Arguments}:
8953 @multitable @columnfractions .15 .70
8954 @item @var{A} @tab Shall be a scalar of type @code{INTEGER} or @code{REAL}
8955 @item @var{P} @tab Shall be a scalar of the same type and kind as @var{A}
8958 @item @emph{Return value}:
8959 The type and kind of the result are those of the arguments.
8961 @item If @var{A} and @var{P} are of type @code{INTEGER}:
8962 @code{MODULO(A,P)} has the value @var{R} such that @code{A=Q*P+R}, where
8963 @var{Q} is an integer and @var{R} is between 0 (inclusive) and @var{P}
8965 @item If @var{A} and @var{P} are of type @code{REAL}:
8966 @code{MODULO(A,P)} has the value of @code{A - FLOOR (A / P) * P}.
8968 In all cases, if @var{P} is zero the result is processor-dependent.
8970 @item @emph{Example}:
8973 print *, modulo(17,3)
8974 print *, modulo(17.5,5.5)
8976 print *, modulo(-17,3)
8977 print *, modulo(-17.5,5.5)
8979 print *, modulo(17,-3)
8980 print *, modulo(17.5,-5.5)
8989 @section @code{MOVE_ALLOC} --- Move allocation from one object to another
8991 @cindex moving allocation
8992 @cindex allocation, moving
8995 @item @emph{Description}:
8996 @code{MOVE_ALLOC(FROM, TO)} moves the allocation from @var{FROM} to
8997 @var{TO}. @var{FROM} will become deallocated in the process.
8999 @item @emph{Standard}:
9000 Fortran 2003 and later
9005 @item @emph{Syntax}:
9006 @code{CALL MOVE_ALLOC(FROM, TO)}
9008 @item @emph{Arguments}:
9009 @multitable @columnfractions .15 .70
9010 @item @var{FROM} @tab @code{ALLOCATABLE}, @code{INTENT(INOUT)}, may be
9011 of any type and kind.
9012 @item @var{TO} @tab @code{ALLOCATABLE}, @code{INTENT(OUT)}, shall be
9013 of the same type, kind and rank as @var{FROM}.
9016 @item @emph{Return value}:
9019 @item @emph{Example}:
9021 program test_move_alloc
9022 integer, allocatable :: a(:), b(:)
9026 call move_alloc(a, b)
9027 print *, allocated(a), allocated(b)
9029 end program test_move_alloc
9036 @section @code{MVBITS} --- Move bits from one integer to another
9041 @item @emph{Description}:
9042 Moves @var{LEN} bits from positions @var{FROMPOS} through
9043 @code{FROMPOS+LEN-1} of @var{FROM} to positions @var{TOPOS} through
9044 @code{TOPOS+LEN-1} of @var{TO}. The portion of argument @var{TO} not
9045 affected by the movement of bits is unchanged. The values of
9046 @code{FROMPOS+LEN-1} and @code{TOPOS+LEN-1} must be less than
9047 @code{BIT_SIZE(FROM)}.
9049 @item @emph{Standard}:
9050 Fortran 95 and later
9053 Elemental subroutine
9055 @item @emph{Syntax}:
9056 @code{CALL MVBITS(FROM, FROMPOS, LEN, TO, TOPOS)}
9058 @item @emph{Arguments}:
9059 @multitable @columnfractions .15 .70
9060 @item @var{FROM} @tab The type shall be @code{INTEGER}.
9061 @item @var{FROMPOS} @tab The type shall be @code{INTEGER}.
9062 @item @var{LEN} @tab The type shall be @code{INTEGER}.
9063 @item @var{TO} @tab The type shall be @code{INTEGER}, of the
9064 same kind as @var{FROM}.
9065 @item @var{TOPOS} @tab The type shall be @code{INTEGER}.
9068 @item @emph{See also}:
9069 @ref{IBCLR}, @ref{IBSET}, @ref{IBITS}, @ref{IAND}, @ref{IOR}, @ref{IEOR}
9075 @section @code{NEAREST} --- Nearest representable number
9077 @cindex real number, nearest different
9078 @cindex floating point, nearest different
9081 @item @emph{Description}:
9082 @code{NEAREST(X, S)} returns the processor-representable number nearest
9083 to @code{X} in the direction indicated by the sign of @code{S}.
9085 @item @emph{Standard}:
9086 Fortran 95 and later
9091 @item @emph{Syntax}:
9092 @code{RESULT = NEAREST(X, S)}
9094 @item @emph{Arguments}:
9095 @multitable @columnfractions .15 .70
9096 @item @var{X} @tab Shall be of type @code{REAL}.
9097 @item @var{S} @tab (Optional) shall be of type @code{REAL} and
9101 @item @emph{Return value}:
9102 The return value is of the same type as @code{X}. If @code{S} is
9103 positive, @code{NEAREST} returns the processor-representable number
9104 greater than @code{X} and nearest to it. If @code{S} is negative,
9105 @code{NEAREST} returns the processor-representable number smaller than
9106 @code{X} and nearest to it.
9108 @item @emph{Example}:
9110 program test_nearest
9112 x = nearest(42.0, 1.0)
9113 y = nearest(42.0, -1.0)
9114 write (*,"(3(G20.15))") x, y, x - y
9115 end program test_nearest
9122 @section @code{NEW_LINE} --- New line character
9125 @cindex output, newline
9128 @item @emph{Description}:
9129 @code{NEW_LINE(C)} returns the new-line character.
9131 @item @emph{Standard}:
9132 Fortran 2003 and later
9137 @item @emph{Syntax}:
9138 @code{RESULT = NEW_LINE(C)}
9140 @item @emph{Arguments}:
9141 @multitable @columnfractions .15 .70
9142 @item @var{C} @tab The argument shall be a scalar or array of the
9143 type @code{CHARACTER}.
9146 @item @emph{Return value}:
9147 Returns a @var{CHARACTER} scalar of length one with the new-line character of
9148 the same kind as parameter @var{C}.
9150 @item @emph{Example}:
9154 write(*,'(A)') 'This is record 1.'//NEW_LINE('A')//'This is record 2.'
9162 @section @code{NINT} --- Nearest whole number
9165 @cindex rounding, nearest whole number
9168 @item @emph{Description}:
9169 @code{NINT(A)} rounds its argument to the nearest whole number.
9171 @item @emph{Standard}:
9172 Fortran 77 and later, with @var{KIND} argument Fortran 90 and later
9177 @item @emph{Syntax}:
9178 @code{RESULT = NINT(A [, KIND])}
9180 @item @emph{Arguments}:
9181 @multitable @columnfractions .15 .70
9182 @item @var{A} @tab The type of the argument shall be @code{REAL}.
9183 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
9184 expression indicating the kind parameter of the result.
9187 @item @emph{Return value}:
9188 Returns @var{A} with the fractional portion of its magnitude eliminated by
9189 rounding to the nearest whole number and with its sign preserved,
9190 converted to an @code{INTEGER} of the default kind.
9192 @item @emph{Example}:
9199 print *, nint(x4), idnint(x8)
9200 end program test_nint
9203 @item @emph{Specific names}:
9204 @multitable @columnfractions .20 .20 .20 .25
9205 @item Name @tab Argument @tab Return Type @tab Standard
9206 @item @code{NINT(A)} @tab @code{REAL(4) A} @tab @code{INTEGER} @tab Fortran 95 and later
9207 @item @code{IDNINT(A)} @tab @code{REAL(8) A} @tab @code{INTEGER} @tab Fortran 95 and later
9210 @item @emph{See also}:
9211 @ref{CEILING}, @ref{FLOOR}
9218 @section @code{NORM2} --- Euclidean vector norms
9220 @cindex Euclidean vector norm
9221 @cindex L2 vector norm
9222 @cindex norm, Euclidean
9225 @item @emph{Description}:
9226 Calculates the Euclidean vector norm (@math{L_2} norm) of
9227 of @var{ARRAY} along dimension @var{DIM}.
9229 @item @emph{Standard}:
9230 Fortran 2008 and later
9233 Transformational function
9235 @item @emph{Syntax}:
9236 @multitable @columnfractions .80
9237 @item @code{RESULT = NORM2(ARRAY[, DIM])}
9240 @item @emph{Arguments}:
9241 @multitable @columnfractions .15 .70
9242 @item @var{ARRAY} @tab Shall be an array of type @code{REAL}
9243 @item @var{DIM} @tab (Optional) shall be a scalar of type
9244 @code{INTEGER} with a value in the range from 1 to n, where n
9245 equals the rank of @var{ARRAY}.
9248 @item @emph{Return value}:
9249 The result is of the same type as @var{ARRAY}.
9251 If @var{DIM} is absent, a scalar with the square root of the sum of all
9252 elements in @var{ARRAY} squared is returned. Otherwise, an array of
9253 rank @math{n-1}, where @math{n} equals the rank of @var{ARRAY}, and a
9254 shape similar to that of @var{ARRAY} with dimension @var{DIM} dropped
9257 @item @emph{Example}:
9260 REAL :: x(5) = [ real :: 1, 2, 3, 4, 5 ]
9261 print *, NORM2(x) ! = sqrt(55.) ~ 7.416
9269 @section @code{NOT} --- Logical negation
9271 @cindex bits, negate
9272 @cindex bitwise logical not
9273 @cindex logical not, bitwise
9276 @item @emph{Description}:
9277 @code{NOT} returns the bitwise Boolean inverse of @var{I}.
9279 @item @emph{Standard}:
9280 Fortran 95 and later
9285 @item @emph{Syntax}:
9286 @code{RESULT = NOT(I)}
9288 @item @emph{Arguments}:
9289 @multitable @columnfractions .15 .70
9290 @item @var{I} @tab The type shall be @code{INTEGER}.
9293 @item @emph{Return value}:
9294 The return type is @code{INTEGER}, of the same kind as the
9297 @item @emph{See also}:
9298 @ref{IAND}, @ref{IEOR}, @ref{IOR}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}
9305 @section @code{NULL} --- Function that returns an disassociated pointer
9307 @cindex pointer, status
9308 @cindex pointer, disassociated
9311 @item @emph{Description}:
9312 Returns a disassociated pointer.
9314 If @var{MOLD} is present, a disassociated pointer of the same type is
9315 returned, otherwise the type is determined by context.
9317 In Fortran 95, @var{MOLD} is optional. Please note that Fortran 2003
9318 includes cases where it is required.
9320 @item @emph{Standard}:
9321 Fortran 95 and later
9324 Transformational function
9326 @item @emph{Syntax}:
9327 @code{PTR => NULL([MOLD])}
9329 @item @emph{Arguments}:
9330 @multitable @columnfractions .15 .70
9331 @item @var{MOLD} @tab (Optional) shall be a pointer of any association
9332 status and of any type.
9335 @item @emph{Return value}:
9336 A disassociated pointer.
9338 @item @emph{Example}:
9340 REAL, POINTER, DIMENSION(:) :: VEC => NULL ()
9343 @item @emph{See also}:
9350 @section @code{NUM_IMAGES} --- Function that returns the number of images
9352 @cindex coarray, @code{NUM_IMAGES}
9353 @cindex images, number of
9356 @item @emph{Description}:
9357 Returns the number of images.
9359 @item @emph{Standard}:
9360 Fortran 2008 and later
9363 Transformational function
9365 @item @emph{Syntax}:
9366 @code{RESULT = NUM_IMAGES()}
9368 @item @emph{Arguments}: None.
9370 @item @emph{Return value}:
9371 Scalar default-kind integer.
9373 @item @emph{Example}:
9377 value = THIS_IMAGE()
9379 IF (THIS_IMAGE() == 1) THEN
9380 DO i = 1, NUM_IMAGES()
9381 WRITE(*,'(2(a,i0))') 'value[', i, '] is ', value[i]
9386 @item @emph{See also}:
9387 @ref{THIS_IMAGE}, @ref{IMAGE_INDEX}
9393 @section @code{OR} --- Bitwise logical OR
9395 @cindex bitwise logical or
9396 @cindex logical or, bitwise
9399 @item @emph{Description}:
9400 Bitwise logical @code{OR}.
9402 This intrinsic routine is provided for backwards compatibility with
9403 GNU Fortran 77. For integer arguments, programmers should consider
9404 the use of the @ref{IOR} intrinsic defined by the Fortran standard.
9406 @item @emph{Standard}:
9412 @item @emph{Syntax}:
9413 @code{RESULT = OR(I, J)}
9415 @item @emph{Arguments}:
9416 @multitable @columnfractions .15 .70
9417 @item @var{I} @tab The type shall be either a scalar @code{INTEGER}
9418 type or a scalar @code{LOGICAL} type.
9419 @item @var{J} @tab The type shall be the same as the type of @var{J}.
9422 @item @emph{Return value}:
9423 The return type is either a scalar @code{INTEGER} or a scalar
9424 @code{LOGICAL}. If the kind type parameters differ, then the
9425 smaller kind type is implicitly converted to larger kind, and the
9426 return has the larger kind.
9428 @item @emph{Example}:
9431 LOGICAL :: T = .TRUE., F = .FALSE.
9433 DATA a / Z'F' /, b / Z'3' /
9435 WRITE (*,*) OR(T, T), OR(T, F), OR(F, T), OR(F, F)
9436 WRITE (*,*) OR(a, b)
9440 @item @emph{See also}:
9441 Fortran 95 elemental function: @ref{IOR}
9447 @section @code{PACK} --- Pack an array into an array of rank one
9449 @cindex array, packing
9450 @cindex array, reduce dimension
9451 @cindex array, gather elements
9454 @item @emph{Description}:
9455 Stores the elements of @var{ARRAY} in an array of rank one.
9457 The beginning of the resulting array is made up of elements whose @var{MASK}
9458 equals @code{TRUE}. Afterwards, positions are filled with elements taken from
9461 @item @emph{Standard}:
9462 Fortran 95 and later
9465 Transformational function
9467 @item @emph{Syntax}:
9468 @code{RESULT = PACK(ARRAY, MASK[,VECTOR]}
9470 @item @emph{Arguments}:
9471 @multitable @columnfractions .15 .70
9472 @item @var{ARRAY} @tab Shall be an array of any type.
9473 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL} and
9474 of the same size as @var{ARRAY}. Alternatively, it may be a @code{LOGICAL}
9476 @item @var{VECTOR} @tab (Optional) shall be an array of the same type
9477 as @var{ARRAY} and of rank one. If present, the number of elements in
9478 @var{VECTOR} shall be equal to or greater than the number of true elements
9479 in @var{MASK}. If @var{MASK} is scalar, the number of elements in
9480 @var{VECTOR} shall be equal to or greater than the number of elements in
9484 @item @emph{Return value}:
9485 The result is an array of rank one and the same type as that of @var{ARRAY}.
9486 If @var{VECTOR} is present, the result size is that of @var{VECTOR}, the
9487 number of @code{TRUE} values in @var{MASK} otherwise.
9489 @item @emph{Example}:
9490 Gathering nonzero elements from an array:
9494 m = (/ 1, 0, 0, 0, 5, 0 /)
9495 WRITE(*, FMT="(6(I0, ' '))") pack(m, m /= 0) ! "1 5"
9499 Gathering nonzero elements from an array and appending elements from @var{VECTOR}:
9503 m = (/ 1, 0, 0, 2 /)
9504 WRITE(*, FMT="(4(I0, ' '))") pack(m, m /= 0, (/ 0, 0, 3, 4 /)) ! "1 2 3 4"
9508 @item @emph{See also}:
9515 @section @code{PARITY} --- Reduction with exclusive OR
9518 @cindex Reduction, XOR
9519 @cindex XOR reduction
9522 @item @emph{Description}:
9523 Calculates the parity, i.e. the reduction using @code{.XOR.},
9524 of @var{MASK} along dimension @var{DIM}.
9526 @item @emph{Standard}:
9527 Fortran 2008 and later
9530 Transformational function
9532 @item @emph{Syntax}:
9533 @multitable @columnfractions .80
9534 @item @code{RESULT = PARITY(MASK[, DIM])}
9537 @item @emph{Arguments}:
9538 @multitable @columnfractions .15 .70
9539 @item @var{LOGICAL} @tab Shall be an array of type @code{LOGICAL}
9540 @item @var{DIM} @tab (Optional) shall be a scalar of type
9541 @code{INTEGER} with a value in the range from 1 to n, where n
9542 equals the rank of @var{MASK}.
9545 @item @emph{Return value}:
9546 The result is of the same type as @var{MASK}.
9548 If @var{DIM} is absent, a scalar with the parity of all elements in
9549 @var{MASK} is returned, i.e. true if an odd number of elements is
9550 @code{.true.} and false otherwise. If @var{DIM} is present, an array
9551 of rank @math{n-1}, where @math{n} equals the rank of @var{ARRAY},
9552 and a shape similar to that of @var{MASK} with dimension @var{DIM}
9553 dropped is returned.
9555 @item @emph{Example}:
9558 LOGICAL :: x(2) = [ .true., .false. ]
9559 print *, PARITY(x) ! prints "T" (true).
9567 @section @code{PERROR} --- Print system error message
9569 @cindex system, error handling
9572 @item @emph{Description}:
9573 Prints (on the C @code{stderr} stream) a newline-terminated error
9574 message corresponding to the last system error. This is prefixed by
9575 @var{STRING}, a colon and a space. See @code{perror(3)}.
9577 @item @emph{Standard}:
9583 @item @emph{Syntax}:
9584 @code{CALL PERROR(STRING)}
9586 @item @emph{Arguments}:
9587 @multitable @columnfractions .15 .70
9588 @item @var{STRING} @tab A scalar of type @code{CHARACTER} and of the
9592 @item @emph{See also}:
9599 @section @code{PRECISION} --- Decimal precision of a real kind
9601 @cindex model representation, precision
9604 @item @emph{Description}:
9605 @code{PRECISION(X)} returns the decimal precision in the model of the
9608 @item @emph{Standard}:
9609 Fortran 95 and later
9614 @item @emph{Syntax}:
9615 @code{RESULT = PRECISION(X)}
9617 @item @emph{Arguments}:
9618 @multitable @columnfractions .15 .70
9619 @item @var{X} @tab Shall be of type @code{REAL} or @code{COMPLEX}.
9622 @item @emph{Return value}:
9623 The return value is of type @code{INTEGER} and of the default integer
9626 @item @emph{See also}:
9627 @ref{SELECTED_REAL_KIND}, @ref{RANGE}
9629 @item @emph{Example}:
9631 program prec_and_range
9632 real(kind=4) :: x(2)
9633 complex(kind=8) :: y
9635 print *, precision(x), range(x)
9636 print *, precision(y), range(y)
9637 end program prec_and_range
9644 @section @code{POPCNT} --- Number of bits set
9646 @cindex binary representation
9650 @item @emph{Description}:
9651 @code{POPCNT(I)} returns the number of bits set ('1' bits) in the binary
9652 representation of @code{I}.
9654 @item @emph{Standard}:
9655 Fortran 2008 and later
9660 @item @emph{Syntax}:
9661 @code{RESULT = POPCNT(I)}
9663 @item @emph{Arguments}:
9664 @multitable @columnfractions .15 .70
9665 @item @var{I} @tab Shall be of type @code{INTEGER}.
9668 @item @emph{Return value}:
9669 The return value is of type @code{INTEGER} and of the default integer
9672 @item @emph{See also}:
9673 @ref{POPPAR}, @ref{LEADZ}, @ref{TRAILZ}
9675 @item @emph{Example}:
9677 program test_population
9678 print *, popcnt(127), poppar(127)
9679 print *, popcnt(huge(0_4)), poppar(huge(0_4))
9680 print *, popcnt(huge(0_8)), poppar(huge(0_8))
9681 end program test_population
9687 @section @code{POPPAR} --- Parity of the number of bits set
9689 @cindex binary representation
9693 @item @emph{Description}:
9694 @code{POPPAR(I)} returns parity of the integer @code{I}, i.e. the parity
9695 of the number of bits set ('1' bits) in the binary representation of
9696 @code{I}. It is equal to 0 if @code{I} has an even number of bits set,
9697 and 1 for an odd number of '1' bits.
9699 @item @emph{Standard}:
9700 Fortran 2008 and later
9705 @item @emph{Syntax}:
9706 @code{RESULT = POPPAR(I)}
9708 @item @emph{Arguments}:
9709 @multitable @columnfractions .15 .70
9710 @item @var{I} @tab Shall be of type @code{INTEGER}.
9713 @item @emph{Return value}:
9714 The return value is of type @code{INTEGER} and of the default integer
9717 @item @emph{See also}:
9718 @ref{POPCNT}, @ref{LEADZ}, @ref{TRAILZ}
9720 @item @emph{Example}:
9722 program test_population
9723 print *, popcnt(127), poppar(127)
9724 print *, popcnt(huge(0_4)), poppar(huge(0_4))
9725 print *, popcnt(huge(0_8)), poppar(huge(0_8))
9726 end program test_population
9733 @section @code{PRESENT} --- Determine whether an optional dummy argument is specified
9737 @item @emph{Description}:
9738 Determines whether an optional dummy argument is present.
9740 @item @emph{Standard}:
9741 Fortran 95 and later
9746 @item @emph{Syntax}:
9747 @code{RESULT = PRESENT(A)}
9749 @item @emph{Arguments}:
9750 @multitable @columnfractions .15 .70
9751 @item @var{A} @tab May be of any type and may be a pointer, scalar or array
9752 value, or a dummy procedure. It shall be the name of an optional dummy argument
9753 accessible within the current subroutine or function.
9756 @item @emph{Return value}:
9757 Returns either @code{TRUE} if the optional argument @var{A} is present, or
9758 @code{FALSE} otherwise.
9760 @item @emph{Example}:
9762 PROGRAM test_present
9763 WRITE(*,*) f(), f(42) ! "F T"
9765 LOGICAL FUNCTION f(x)
9766 INTEGER, INTENT(IN), OPTIONAL :: x
9776 @section @code{PRODUCT} --- Product of array elements
9778 @cindex array, product
9779 @cindex array, multiply elements
9780 @cindex array, conditionally multiply elements
9781 @cindex multiply array elements
9784 @item @emph{Description}:
9785 Multiplies the elements of @var{ARRAY} along dimension @var{DIM} if
9786 the corresponding element in @var{MASK} is @code{TRUE}.
9788 @item @emph{Standard}:
9789 Fortran 95 and later
9792 Transformational function
9794 @item @emph{Syntax}:
9795 @multitable @columnfractions .80
9796 @item @code{RESULT = PRODUCT(ARRAY[, MASK])}
9797 @item @code{RESULT = PRODUCT(ARRAY, DIM[, MASK])}
9800 @item @emph{Arguments}:
9801 @multitable @columnfractions .15 .70
9802 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER},
9803 @code{REAL} or @code{COMPLEX}.
9804 @item @var{DIM} @tab (Optional) shall be a scalar of type
9805 @code{INTEGER} with a value in the range from 1 to n, where n
9806 equals the rank of @var{ARRAY}.
9807 @item @var{MASK} @tab (Optional) shall be of type @code{LOGICAL}
9808 and either be a scalar or an array of the same shape as @var{ARRAY}.
9811 @item @emph{Return value}:
9812 The result is of the same type as @var{ARRAY}.
9814 If @var{DIM} is absent, a scalar with the product of all elements in
9815 @var{ARRAY} is returned. Otherwise, an array of rank n-1, where n equals
9816 the rank of @var{ARRAY}, and a shape similar to that of @var{ARRAY} with
9817 dimension @var{DIM} dropped is returned.
9820 @item @emph{Example}:
9822 PROGRAM test_product
9823 INTEGER :: x(5) = (/ 1, 2, 3, 4 ,5 /)
9824 print *, PRODUCT(x) ! all elements, product = 120
9825 print *, PRODUCT(x, MASK=MOD(x, 2)==1) ! odd elements, product = 15
9829 @item @emph{See also}:
9836 @section @code{RADIX} --- Base of a model number
9838 @cindex model representation, base
9839 @cindex model representation, radix
9842 @item @emph{Description}:
9843 @code{RADIX(X)} returns the base of the model representing the entity @var{X}.
9845 @item @emph{Standard}:
9846 Fortran 95 and later
9851 @item @emph{Syntax}:
9852 @code{RESULT = RADIX(X)}
9854 @item @emph{Arguments}:
9855 @multitable @columnfractions .15 .70
9856 @item @var{X} @tab Shall be of type @code{INTEGER} or @code{REAL}
9859 @item @emph{Return value}:
9860 The return value is a scalar of type @code{INTEGER} and of the default
9863 @item @emph{See also}:
9864 @ref{SELECTED_REAL_KIND}
9866 @item @emph{Example}:
9869 print *, "The radix for the default integer kind is", radix(0)
9870 print *, "The radix for the default real kind is", radix(0.0)
9871 end program test_radix
9879 @section @code{RAN} --- Real pseudo-random number
9881 @cindex random number generation
9884 @item @emph{Description}:
9885 For compatibility with HP FORTRAN 77/iX, the @code{RAN} intrinsic is
9886 provided as an alias for @code{RAND}. See @ref{RAND} for complete
9889 @item @emph{Standard}:
9895 @item @emph{See also}:
9896 @ref{RAND}, @ref{RANDOM_NUMBER}
9902 @section @code{RAND} --- Real pseudo-random number
9904 @cindex random number generation
9907 @item @emph{Description}:
9908 @code{RAND(FLAG)} returns a pseudo-random number from a uniform
9909 distribution between 0 and 1. If @var{FLAG} is 0, the next number
9910 in the current sequence is returned; if @var{FLAG} is 1, the generator
9911 is restarted by @code{CALL SRAND(0)}; if @var{FLAG} has any other value,
9912 it is used as a new seed with @code{SRAND}.
9914 This intrinsic routine is provided for backwards compatibility with
9915 GNU Fortran 77. It implements a simple modulo generator as provided
9916 by @command{g77}. For new code, one should consider the use of
9917 @ref{RANDOM_NUMBER} as it implements a superior algorithm.
9919 @item @emph{Standard}:
9925 @item @emph{Syntax}:
9926 @code{RESULT = RAND(I)}
9928 @item @emph{Arguments}:
9929 @multitable @columnfractions .15 .70
9930 @item @var{I} @tab Shall be a scalar @code{INTEGER} of kind 4.
9933 @item @emph{Return value}:
9934 The return value is of @code{REAL} type and the default kind.
9936 @item @emph{Example}:
9939 integer,parameter :: seed = 86456
9942 print *, rand(), rand(), rand(), rand()
9943 print *, rand(seed), rand(), rand(), rand()
9944 end program test_rand
9947 @item @emph{See also}:
9948 @ref{SRAND}, @ref{RANDOM_NUMBER}
9955 @section @code{RANDOM_NUMBER} --- Pseudo-random number
9956 @fnindex RANDOM_NUMBER
9957 @cindex random number generation
9960 @item @emph{Description}:
9961 Returns a single pseudorandom number or an array of pseudorandom numbers
9962 from the uniform distribution over the range @math{ 0 \leq x < 1}.
9964 The runtime-library implements George Marsaglia's KISS (Keep It Simple
9965 Stupid) random number generator (RNG). This RNG combines:
9967 @item The congruential generator @math{x(n) = 69069 \cdot x(n-1) + 1327217885}
9968 with a period of @math{2^{32}},
9969 @item A 3-shift shift-register generator with a period of @math{2^{32} - 1},
9970 @item Two 16-bit multiply-with-carry generators with a period of
9971 @math{597273182964842497 > 2^{59}}.
9973 The overall period exceeds @math{2^{123}}.
9975 Please note, this RNG is thread safe if used within OpenMP directives,
9976 i.e., its state will be consistent while called from multiple threads.
9977 However, the KISS generator does not create random numbers in parallel
9978 from multiple sources, but in sequence from a single source. If an
9979 OpenMP-enabled application heavily relies on random numbers, one should
9980 consider employing a dedicated parallel random number generator instead.
9982 @item @emph{Standard}:
9983 Fortran 95 and later
9988 @item @emph{Syntax}:
9989 @code{RANDOM_NUMBER(HARVEST)}
9991 @item @emph{Arguments}:
9992 @multitable @columnfractions .15 .70
9993 @item @var{HARVEST} @tab Shall be a scalar or an array of type @code{REAL}.
9996 @item @emph{Example}:
9998 program test_random_number
10000 CALL init_random_seed() ! see example of RANDOM_SEED
10001 CALL RANDOM_NUMBER(r)
10005 @item @emph{See also}:
10012 @section @code{RANDOM_SEED} --- Initialize a pseudo-random number sequence
10013 @fnindex RANDOM_SEED
10014 @cindex random number generation, seeding
10015 @cindex seeding a random number generator
10018 @item @emph{Description}:
10019 Restarts or queries the state of the pseudorandom number generator used by
10020 @code{RANDOM_NUMBER}.
10022 If @code{RANDOM_SEED} is called without arguments, it is initialized to
10023 a default state. The example below shows how to initialize the random
10024 seed based on the system's time.
10026 @item @emph{Standard}:
10027 Fortran 95 and later
10029 @item @emph{Class}:
10032 @item @emph{Syntax}:
10033 @code{CALL RANDOM_SEED([SIZE, PUT, GET])}
10035 @item @emph{Arguments}:
10036 @multitable @columnfractions .15 .70
10037 @item @var{SIZE} @tab (Optional) Shall be a scalar and of type default
10038 @code{INTEGER}, with @code{INTENT(OUT)}. It specifies the minimum size
10039 of the arrays used with the @var{PUT} and @var{GET} arguments.
10040 @item @var{PUT} @tab (Optional) Shall be an array of type default
10041 @code{INTEGER} and rank one. It is @code{INTENT(IN)} and the size of
10042 the array must be larger than or equal to the number returned by the
10043 @var{SIZE} argument.
10044 @item @var{GET} @tab (Optional) Shall be an array of type default
10045 @code{INTEGER} and rank one. It is @code{INTENT(OUT)} and the size
10046 of the array must be larger than or equal to the number returned by
10047 the @var{SIZE} argument.
10050 @item @emph{Example}:
10052 SUBROUTINE init_random_seed()
10053 INTEGER :: i, n, clock
10054 INTEGER, DIMENSION(:), ALLOCATABLE :: seed
10056 CALL RANDOM_SEED(size = n)
10059 CALL SYSTEM_CLOCK(COUNT=clock)
10061 seed = clock + 37 * (/ (i - 1, i = 1, n) /)
10062 CALL RANDOM_SEED(PUT = seed)
10068 @item @emph{See also}:
10069 @ref{RANDOM_NUMBER}
10075 @section @code{RANGE} --- Decimal exponent range
10077 @cindex model representation, range
10080 @item @emph{Description}:
10081 @code{RANGE(X)} returns the decimal exponent range in the model of the
10084 @item @emph{Standard}:
10085 Fortran 95 and later
10087 @item @emph{Class}:
10090 @item @emph{Syntax}:
10091 @code{RESULT = RANGE(X)}
10093 @item @emph{Arguments}:
10094 @multitable @columnfractions .15 .70
10095 @item @var{X} @tab Shall be of type @code{INTEGER}, @code{REAL}
10099 @item @emph{Return value}:
10100 The return value is of type @code{INTEGER} and of the default integer
10103 @item @emph{See also}:
10104 @ref{SELECTED_REAL_KIND}, @ref{PRECISION}
10106 @item @emph{Example}:
10107 See @code{PRECISION} for an example.
10113 @section @code{REAL} --- Convert to real type
10119 @cindex conversion, to real
10120 @cindex complex numbers, real part
10123 @item @emph{Description}:
10124 @code{REAL(A [, KIND])} converts its argument @var{A} to a real type. The
10125 @code{REALPART} function is provided for compatibility with @command{g77},
10126 and its use is strongly discouraged.
10128 @item @emph{Standard}:
10129 Fortran 77 and later
10131 @item @emph{Class}:
10134 @item @emph{Syntax}:
10135 @multitable @columnfractions .80
10136 @item @code{RESULT = REAL(A [, KIND])}
10137 @item @code{RESULT = REALPART(Z)}
10140 @item @emph{Arguments}:
10141 @multitable @columnfractions .15 .70
10142 @item @var{A} @tab Shall be @code{INTEGER}, @code{REAL}, or
10144 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
10145 expression indicating the kind parameter of the result.
10148 @item @emph{Return value}:
10149 These functions return a @code{REAL} variable or array under
10150 the following rules:
10154 @code{REAL(A)} is converted to a default real type if @var{A} is an
10155 integer or real variable.
10157 @code{REAL(A)} is converted to a real type with the kind type parameter
10158 of @var{A} if @var{A} is a complex variable.
10160 @code{REAL(A, KIND)} is converted to a real type with kind type
10161 parameter @var{KIND} if @var{A} is a complex, integer, or real
10165 @item @emph{Example}:
10168 complex :: x = (1.0, 2.0)
10169 print *, real(x), real(x,8), realpart(x)
10170 end program test_real
10173 @item @emph{Specific names}:
10174 @multitable @columnfractions .20 .20 .20 .25
10175 @item Name @tab Argument @tab Return type @tab Standard
10176 @item @code{FLOAT(A)} @tab @code{INTEGER(4)} @tab @code{REAL(4)} @tab Fortran 77 and later
10177 @item @code{DFLOAT(A)} @tab @code{INTEGER(4)} @tab @code{REAL(8)} @tab GNU extension
10178 @item @code{SNGL(A)} @tab @code{INTEGER(8)} @tab @code{REAL(4)} @tab Fortran 77 and later
10182 @item @emph{See also}:
10190 @section @code{RENAME} --- Rename a file
10192 @cindex file system, rename file
10195 @item @emph{Description}:
10196 Renames a file from file @var{PATH1} to @var{PATH2}. A null
10197 character (@code{CHAR(0)}) can be used to mark the end of the names in
10198 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
10199 names are ignored. If the @var{STATUS} argument is supplied, it
10200 contains 0 on success or a nonzero error code upon return; see
10203 This intrinsic is provided in both subroutine and function forms;
10204 however, only one form can be used in any given program unit.
10206 @item @emph{Standard}:
10209 @item @emph{Class}:
10210 Subroutine, function
10212 @item @emph{Syntax}:
10213 @multitable @columnfractions .80
10214 @item @code{CALL RENAME(PATH1, PATH2 [, STATUS])}
10215 @item @code{STATUS = RENAME(PATH1, PATH2)}
10218 @item @emph{Arguments}:
10219 @multitable @columnfractions .15 .70
10220 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
10221 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
10222 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
10225 @item @emph{See also}:
10233 @section @code{REPEAT} --- Repeated string concatenation
10235 @cindex string, repeat
10236 @cindex string, concatenate
10239 @item @emph{Description}:
10240 Concatenates @var{NCOPIES} copies of a string.
10242 @item @emph{Standard}:
10243 Fortran 95 and later
10245 @item @emph{Class}:
10246 Transformational function
10248 @item @emph{Syntax}:
10249 @code{RESULT = REPEAT(STRING, NCOPIES)}
10251 @item @emph{Arguments}:
10252 @multitable @columnfractions .15 .70
10253 @item @var{STRING} @tab Shall be scalar and of type @code{CHARACTER}.
10254 @item @var{NCOPIES} @tab Shall be scalar and of type @code{INTEGER}.
10257 @item @emph{Return value}:
10258 A new scalar of type @code{CHARACTER} built up from @var{NCOPIES} copies
10261 @item @emph{Example}:
10263 program test_repeat
10264 write(*,*) repeat("x", 5) ! "xxxxx"
10272 @section @code{RESHAPE} --- Function to reshape an array
10274 @cindex array, change dimensions
10275 @cindex array, transmogrify
10278 @item @emph{Description}:
10279 Reshapes @var{SOURCE} to correspond to @var{SHAPE}. If necessary,
10280 the new array may be padded with elements from @var{PAD} or permuted
10281 as defined by @var{ORDER}.
10283 @item @emph{Standard}:
10284 Fortran 95 and later
10286 @item @emph{Class}:
10287 Transformational function
10289 @item @emph{Syntax}:
10290 @code{RESULT = RESHAPE(SOURCE, SHAPE[, PAD, ORDER])}
10292 @item @emph{Arguments}:
10293 @multitable @columnfractions .15 .70
10294 @item @var{SOURCE} @tab Shall be an array of any type.
10295 @item @var{SHAPE} @tab Shall be of type @code{INTEGER} and an
10296 array of rank one. Its values must be positive or zero.
10297 @item @var{PAD} @tab (Optional) shall be an array of the same
10298 type as @var{SOURCE}.
10299 @item @var{ORDER} @tab (Optional) shall be of type @code{INTEGER}
10300 and an array of the same shape as @var{SHAPE}. Its values shall
10301 be a permutation of the numbers from 1 to n, where n is the size of
10302 @var{SHAPE}. If @var{ORDER} is absent, the natural ordering shall
10306 @item @emph{Return value}:
10307 The result is an array of shape @var{SHAPE} with the same type as
10310 @item @emph{Example}:
10312 PROGRAM test_reshape
10313 INTEGER, DIMENSION(4) :: x
10314 WRITE(*,*) SHAPE(x) ! prints "4"
10315 WRITE(*,*) SHAPE(RESHAPE(x, (/2, 2/))) ! prints "2 2"
10319 @item @emph{See also}:
10326 @section @code{RRSPACING} --- Reciprocal of the relative spacing
10328 @cindex real number, relative spacing
10329 @cindex floating point, relative spacing
10333 @item @emph{Description}:
10334 @code{RRSPACING(X)} returns the reciprocal of the relative spacing of
10335 model numbers near @var{X}.
10337 @item @emph{Standard}:
10338 Fortran 95 and later
10340 @item @emph{Class}:
10343 @item @emph{Syntax}:
10344 @code{RESULT = RRSPACING(X)}
10346 @item @emph{Arguments}:
10347 @multitable @columnfractions .15 .70
10348 @item @var{X} @tab Shall be of type @code{REAL}.
10351 @item @emph{Return value}:
10352 The return value is of the same type and kind as @var{X}.
10353 The value returned is equal to
10354 @code{ABS(FRACTION(X)) * FLOAT(RADIX(X))**DIGITS(X)}.
10356 @item @emph{See also}:
10363 @section @code{RSHIFT} --- Right shift bits
10365 @cindex bits, shift right
10368 @item @emph{Description}:
10369 @code{RSHIFT} returns a value corresponding to @var{I} with all of the
10370 bits shifted right by @var{SHIFT} places. If the absolute value of
10371 @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the value is undefined.
10372 Bits shifted out from the right end are lost. The fill is arithmetic: the
10373 bits shifted in from the left end are equal to the leftmost bit, which in
10374 two's complement representation is the sign bit.
10376 This function has been superseded by the @code{SHIFTA} intrinsic, which
10377 is standard in Fortran 2008 and later.
10379 @item @emph{Standard}:
10382 @item @emph{Class}:
10385 @item @emph{Syntax}:
10386 @code{RESULT = RSHIFT(I, SHIFT)}
10388 @item @emph{Arguments}:
10389 @multitable @columnfractions .15 .70
10390 @item @var{I} @tab The type shall be @code{INTEGER}.
10391 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
10394 @item @emph{Return value}:
10395 The return value is of type @code{INTEGER} and of the same kind as
10398 @item @emph{See also}:
10399 @ref{ISHFT}, @ref{ISHFTC}, @ref{LSHIFT}, @ref{SHIFTA}, @ref{SHIFTR},
10407 @section @code{SAME_TYPE_AS} --- Query dynamic types for equality
10408 @fnindex SAME_TYPE_AS
10411 @item @emph{Description}:
10412 Query dynamic types for equality.
10414 @item @emph{Standard}:
10415 Fortran 2003 and later
10417 @item @emph{Class}:
10420 @item @emph{Syntax}:
10421 @code{RESULT = SAME_TYPE_AS(A, B)}
10423 @item @emph{Arguments}:
10424 @multitable @columnfractions .15 .70
10425 @item @var{A} @tab Shall be an object of extensible declared type or
10426 unlimited polymorphic.
10427 @item @var{B} @tab Shall be an object of extensible declared type or
10428 unlimited polymorphic.
10431 @item @emph{Return value}:
10432 The return value is a scalar of type default logical. It is true if and
10433 only if the dynamic type of A is the same as the dynamic type of B.
10435 @item @emph{See also}:
10436 @ref{EXTENDS_TYPE_OF}
10443 @section @code{SCALE} --- Scale a real value
10445 @cindex real number, scale
10446 @cindex floating point, scale
10449 @item @emph{Description}:
10450 @code{SCALE(X,I)} returns @code{X * RADIX(X)**I}.
10452 @item @emph{Standard}:
10453 Fortran 95 and later
10455 @item @emph{Class}:
10458 @item @emph{Syntax}:
10459 @code{RESULT = SCALE(X, I)}
10461 @item @emph{Arguments}:
10462 @multitable @columnfractions .15 .70
10463 @item @var{X} @tab The type of the argument shall be a @code{REAL}.
10464 @item @var{I} @tab The type of the argument shall be a @code{INTEGER}.
10467 @item @emph{Return value}:
10468 The return value is of the same type and kind as @var{X}.
10469 Its value is @code{X * RADIX(X)**I}.
10471 @item @emph{Example}:
10474 real :: x = 178.1387e-4
10476 print *, scale(x,i), x*radix(x)**i
10477 end program test_scale
10485 @section @code{SCAN} --- Scan a string for the presence of a set of characters
10487 @cindex string, find subset
10490 @item @emph{Description}:
10491 Scans a @var{STRING} for any of the characters in a @var{SET}
10494 If @var{BACK} is either absent or equals @code{FALSE}, this function
10495 returns the position of the leftmost character of @var{STRING} that is
10496 in @var{SET}. If @var{BACK} equals @code{TRUE}, the rightmost position
10497 is returned. If no character of @var{SET} is found in @var{STRING}, the
10500 @item @emph{Standard}:
10501 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
10503 @item @emph{Class}:
10506 @item @emph{Syntax}:
10507 @code{RESULT = SCAN(STRING, SET[, BACK [, KIND]])}
10509 @item @emph{Arguments}:
10510 @multitable @columnfractions .15 .70
10511 @item @var{STRING} @tab Shall be of type @code{CHARACTER}.
10512 @item @var{SET} @tab Shall be of type @code{CHARACTER}.
10513 @item @var{BACK} @tab (Optional) shall be of type @code{LOGICAL}.
10514 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
10515 expression indicating the kind parameter of the result.
10518 @item @emph{Return value}:
10519 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
10520 @var{KIND} is absent, the return value is of default integer kind.
10522 @item @emph{Example}:
10525 WRITE(*,*) SCAN("FORTRAN", "AO") ! 2, found 'O'
10526 WRITE(*,*) SCAN("FORTRAN", "AO", .TRUE.) ! 6, found 'A'
10527 WRITE(*,*) SCAN("FORTRAN", "C++") ! 0, found none
10531 @item @emph{See also}:
10532 @ref{INDEX intrinsic}, @ref{VERIFY}
10538 @section @code{SECNDS} --- Time function
10540 @cindex time, elapsed
10541 @cindex elapsed time
10544 @item @emph{Description}:
10545 @code{SECNDS(X)} gets the time in seconds from the real-time system clock.
10546 @var{X} is a reference time, also in seconds. If this is zero, the time in
10547 seconds from midnight is returned. This function is non-standard and its
10548 use is discouraged.
10550 @item @emph{Standard}:
10553 @item @emph{Class}:
10556 @item @emph{Syntax}:
10557 @code{RESULT = SECNDS (X)}
10559 @item @emph{Arguments}:
10560 @multitable @columnfractions .15 .70
10561 @item @var{T} @tab Shall be of type @code{REAL(4)}.
10562 @item @var{X} @tab Shall be of type @code{REAL(4)}.
10565 @item @emph{Return value}:
10568 @item @emph{Example}:
10570 program test_secnds
10573 print *, secnds (0.0) ! seconds since midnight
10574 t1 = secnds (0.0) ! reference time
10575 do i = 1, 10000000 ! do something
10577 t2 = secnds (t1) ! elapsed time
10578 print *, "Something took ", t2, " seconds."
10579 end program test_secnds
10586 @section @code{SECOND} --- CPU time function
10588 @cindex time, elapsed
10589 @cindex elapsed time
10592 @item @emph{Description}:
10593 Returns a @code{REAL(4)} value representing the elapsed CPU time in
10594 seconds. This provides the same functionality as the standard
10595 @code{CPU_TIME} intrinsic, and is only included for backwards
10598 This intrinsic is provided in both subroutine and function forms;
10599 however, only one form can be used in any given program unit.
10601 @item @emph{Standard}:
10604 @item @emph{Class}:
10605 Subroutine, function
10607 @item @emph{Syntax}:
10608 @multitable @columnfractions .80
10609 @item @code{CALL SECOND(TIME)}
10610 @item @code{TIME = SECOND()}
10613 @item @emph{Arguments}:
10614 @multitable @columnfractions .15 .70
10615 @item @var{TIME} @tab Shall be of type @code{REAL(4)}.
10618 @item @emph{Return value}:
10619 In either syntax, @var{TIME} is set to the process's current runtime in
10622 @item @emph{See also}:
10629 @node SELECTED_CHAR_KIND
10630 @section @code{SELECTED_CHAR_KIND} --- Choose character kind
10631 @fnindex SELECTED_CHAR_KIND
10632 @cindex character kind
10633 @cindex kind, character
10636 @item @emph{Description}:
10638 @code{SELECTED_CHAR_KIND(NAME)} returns the kind value for the character
10639 set named @var{NAME}, if a character set with such a name is supported,
10640 or @math{-1} otherwise. Currently, supported character sets include
10641 ``ASCII'' and ``DEFAULT'', which are equivalent, and ``ISO_10646''
10642 (Universal Character Set, UCS-4) which is commonly known as Unicode.
10644 @item @emph{Standard}:
10645 Fortran 2003 and later
10647 @item @emph{Class}:
10648 Transformational function
10650 @item @emph{Syntax}:
10651 @code{RESULT = SELECTED_CHAR_KIND(NAME)}
10653 @item @emph{Arguments}:
10654 @multitable @columnfractions .15 .70
10655 @item @var{NAME} @tab Shall be a scalar and of the default character type.
10658 @item @emph{Example}:
10660 program character_kind
10661 use iso_fortran_env
10663 integer, parameter :: ascii = selected_char_kind ("ascii")
10664 integer, parameter :: ucs4 = selected_char_kind ('ISO_10646')
10666 character(kind=ascii, len=26) :: alphabet
10667 character(kind=ucs4, len=30) :: hello_world
10669 alphabet = ascii_"abcdefghijklmnopqrstuvwxyz"
10670 hello_world = ucs4_'Hello World and Ni Hao -- ' &
10671 // char (int (z'4F60'), ucs4) &
10672 // char (int (z'597D'), ucs4)
10674 write (*,*) alphabet
10676 open (output_unit, encoding='UTF-8')
10677 write (*,*) trim (hello_world)
10678 end program character_kind
10684 @node SELECTED_INT_KIND
10685 @section @code{SELECTED_INT_KIND} --- Choose integer kind
10686 @fnindex SELECTED_INT_KIND
10687 @cindex integer kind
10688 @cindex kind, integer
10691 @item @emph{Description}:
10692 @code{SELECTED_INT_KIND(R)} return the kind value of the smallest integer
10693 type that can represent all values ranging from @math{-10^R} (exclusive)
10694 to @math{10^R} (exclusive). If there is no integer kind that accommodates
10695 this range, @code{SELECTED_INT_KIND} returns @math{-1}.
10697 @item @emph{Standard}:
10698 Fortran 95 and later
10700 @item @emph{Class}:
10701 Transformational function
10703 @item @emph{Syntax}:
10704 @code{RESULT = SELECTED_INT_KIND(R)}
10706 @item @emph{Arguments}:
10707 @multitable @columnfractions .15 .70
10708 @item @var{R} @tab Shall be a scalar and of type @code{INTEGER}.
10711 @item @emph{Example}:
10713 program large_integers
10714 integer,parameter :: k5 = selected_int_kind(5)
10715 integer,parameter :: k15 = selected_int_kind(15)
10716 integer(kind=k5) :: i5
10717 integer(kind=k15) :: i15
10719 print *, huge(i5), huge(i15)
10721 ! The following inequalities are always true
10722 print *, huge(i5) >= 10_k5**5-1
10723 print *, huge(i15) >= 10_k15**15-1
10724 end program large_integers
10730 @node SELECTED_REAL_KIND
10731 @section @code{SELECTED_REAL_KIND} --- Choose real kind
10732 @fnindex SELECTED_REAL_KIND
10735 @cindex radix, real
10738 @item @emph{Description}:
10739 @code{SELECTED_REAL_KIND(P,R)} returns the kind value of a real data type
10740 with decimal precision of at least @code{P} digits, exponent range of
10741 at least @code{R}, and with a radix of @code{RADIX}.
10743 @item @emph{Standard}:
10744 Fortran 95 and later, with @code{RADIX} Fortran 2008 or later
10746 @item @emph{Class}:
10747 Transformational function
10749 @item @emph{Syntax}:
10750 @code{RESULT = SELECTED_REAL_KIND([P, R, RADIX])}
10752 @item @emph{Arguments}:
10753 @multitable @columnfractions .15 .70
10754 @item @var{P} @tab (Optional) shall be a scalar and of type @code{INTEGER}.
10755 @item @var{R} @tab (Optional) shall be a scalar and of type @code{INTEGER}.
10756 @item @var{RADIX} @tab (Optional) shall be a scalar and of type @code{INTEGER}.
10758 Before Fortran 2008, at least one of the arguments @var{R} or @var{P} shall
10759 be present; since Fortran 2008, they are assumed to be zero if absent.
10761 @item @emph{Return value}:
10763 @code{SELECTED_REAL_KIND} returns the value of the kind type parameter of
10764 a real data type with decimal precision of at least @code{P} digits, a
10765 decimal exponent range of at least @code{R}, and with the requested
10766 @code{RADIX}. If the @code{RADIX} parameter is absent, real kinds with
10767 any radix can be returned. If more than one real data type meet the
10768 criteria, the kind of the data type with the smallest decimal precision
10769 is returned. If no real data type matches the criteria, the result is
10771 @item -1 if the processor does not support a real data type with a
10772 precision greater than or equal to @code{P}, but the @code{R} and
10773 @code{RADIX} requirements can be fulfilled
10774 @item -2 if the processor does not support a real type with an exponent
10775 range greater than or equal to @code{R}, but @code{P} and @code{RADIX}
10777 @item -3 if @code{RADIX} but not @code{P} and @code{R} requirements
10779 @item -4 if @code{RADIX} and either @code{P} or @code{R} requirements
10781 @item -5 if there is no real type with the given @code{RADIX}
10784 @item @emph{See also}:
10785 @ref{PRECISION}, @ref{RANGE}, @ref{RADIX}
10787 @item @emph{Example}:
10790 integer,parameter :: p6 = selected_real_kind(6)
10791 integer,parameter :: p10r100 = selected_real_kind(10,100)
10792 integer,parameter :: r400 = selected_real_kind(r=400)
10794 real(kind=p10r100) :: y
10795 real(kind=r400) :: z
10797 print *, precision(x), range(x)
10798 print *, precision(y), range(y)
10799 print *, precision(z), range(z)
10800 end program real_kinds
10807 @section @code{SET_EXPONENT} --- Set the exponent of the model
10808 @fnindex SET_EXPONENT
10809 @cindex real number, set exponent
10810 @cindex floating point, set exponent
10813 @item @emph{Description}:
10814 @code{SET_EXPONENT(X, I)} returns the real number whose fractional part
10815 is that that of @var{X} and whose exponent part is @var{I}.
10817 @item @emph{Standard}:
10818 Fortran 95 and later
10820 @item @emph{Class}:
10823 @item @emph{Syntax}:
10824 @code{RESULT = SET_EXPONENT(X, I)}
10826 @item @emph{Arguments}:
10827 @multitable @columnfractions .15 .70
10828 @item @var{X} @tab Shall be of type @code{REAL}.
10829 @item @var{I} @tab Shall be of type @code{INTEGER}.
10832 @item @emph{Return value}:
10833 The return value is of the same type and kind as @var{X}.
10834 The real number whose fractional part
10835 is that that of @var{X} and whose exponent part if @var{I} is returned;
10836 it is @code{FRACTION(X) * RADIX(X)**I}.
10838 @item @emph{Example}:
10840 PROGRAM test_setexp
10841 REAL :: x = 178.1387e-4
10843 PRINT *, SET_EXPONENT(x, i), FRACTION(x) * RADIX(x)**i
10852 @section @code{SHAPE} --- Determine the shape of an array
10854 @cindex array, shape
10857 @item @emph{Description}:
10858 Determines the shape of an array.
10860 @item @emph{Standard}:
10861 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
10863 @item @emph{Class}:
10866 @item @emph{Syntax}:
10867 @code{RESULT = SHAPE(SOURCE [, KIND])}
10869 @item @emph{Arguments}:
10870 @multitable @columnfractions .15 .70
10871 @item @var{SOURCE} @tab Shall be an array or scalar of any type.
10872 If @var{SOURCE} is a pointer it must be associated and allocatable
10873 arrays must be allocated.
10874 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
10875 expression indicating the kind parameter of the result.
10878 @item @emph{Return value}:
10879 An @code{INTEGER} array of rank one with as many elements as @var{SOURCE}
10880 has dimensions. The elements of the resulting array correspond to the extend
10881 of @var{SOURCE} along the respective dimensions. If @var{SOURCE} is a scalar,
10882 the result is the rank one array of size zero. If @var{KIND} is absent, the
10883 return value has the default integer kind otherwise the specified kind.
10885 @item @emph{Example}:
10888 INTEGER, DIMENSION(-1:1, -1:2) :: A
10889 WRITE(*,*) SHAPE(A) ! (/ 3, 4 /)
10890 WRITE(*,*) SIZE(SHAPE(42)) ! (/ /)
10894 @item @emph{See also}:
10895 @ref{RESHAPE}, @ref{SIZE}
10901 @section @code{SHIFTA} --- Right shift with fill
10903 @cindex bits, shift right
10904 @cindex shift, right with fill
10907 @item @emph{Description}:
10908 @code{SHIFTA} returns a value corresponding to @var{I} with all of the
10909 bits shifted right by @var{SHIFT} places. If the absolute value of
10910 @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the value is undefined.
10911 Bits shifted out from the right end are lost. The fill is arithmetic: the
10912 bits shifted in from the left end are equal to the leftmost bit, which in
10913 two's complement representation is the sign bit.
10915 @item @emph{Standard}:
10916 Fortran 2008 and later
10918 @item @emph{Class}:
10921 @item @emph{Syntax}:
10922 @code{RESULT = SHIFTA(I, SHIFT)}
10924 @item @emph{Arguments}:
10925 @multitable @columnfractions .15 .70
10926 @item @var{I} @tab The type shall be @code{INTEGER}.
10927 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
10930 @item @emph{Return value}:
10931 The return value is of type @code{INTEGER} and of the same kind as
10934 @item @emph{See also}:
10935 @ref{SHIFTL}, @ref{SHIFTR}
10941 @section @code{SHIFTL} --- Left shift
10943 @cindex bits, shift left
10944 @cindex shift, left
10947 @item @emph{Description}:
10948 @code{SHIFTL} returns a value corresponding to @var{I} with all of the
10949 bits shifted left by @var{SHIFT} places. If the absolute value of
10950 @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the value is undefined.
10951 Bits shifted out from the left end are lost, and bits shifted in from
10952 the right end are set to 0.
10954 @item @emph{Standard}:
10955 Fortran 2008 and later
10957 @item @emph{Class}:
10960 @item @emph{Syntax}:
10961 @code{RESULT = SHIFTL(I, SHIFT)}
10963 @item @emph{Arguments}:
10964 @multitable @columnfractions .15 .70
10965 @item @var{I} @tab The type shall be @code{INTEGER}.
10966 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
10969 @item @emph{Return value}:
10970 The return value is of type @code{INTEGER} and of the same kind as
10973 @item @emph{See also}:
10974 @ref{SHIFTA}, @ref{SHIFTR}
10980 @section @code{SHIFTR} --- Right shift
10982 @cindex bits, shift right
10983 @cindex shift, right
10986 @item @emph{Description}:
10987 @code{SHIFTR} returns a value corresponding to @var{I} with all of the
10988 bits shifted right by @var{SHIFT} places. If the absolute value of
10989 @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the value is undefined.
10990 Bits shifted out from the right end are lost, and bits shifted in from
10991 the left end are set to 0.
10993 @item @emph{Standard}:
10994 Fortran 2008 and later
10996 @item @emph{Class}:
10999 @item @emph{Syntax}:
11000 @code{RESULT = SHIFTR(I, SHIFT)}
11002 @item @emph{Arguments}:
11003 @multitable @columnfractions .15 .70
11004 @item @var{I} @tab The type shall be @code{INTEGER}.
11005 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
11008 @item @emph{Return value}:
11009 The return value is of type @code{INTEGER} and of the same kind as
11012 @item @emph{See also}:
11013 @ref{SHIFTA}, @ref{SHIFTL}
11019 @section @code{SIGN} --- Sign copying function
11023 @cindex sign copying
11026 @item @emph{Description}:
11027 @code{SIGN(A,B)} returns the value of @var{A} with the sign of @var{B}.
11029 @item @emph{Standard}:
11030 Fortran 77 and later
11032 @item @emph{Class}:
11035 @item @emph{Syntax}:
11036 @code{RESULT = SIGN(A, B)}
11038 @item @emph{Arguments}:
11039 @multitable @columnfractions .15 .70
11040 @item @var{A} @tab Shall be of type @code{INTEGER} or @code{REAL}
11041 @item @var{B} @tab Shall be of the same type and kind as @var{A}
11044 @item @emph{Return value}:
11045 The kind of the return value is that of @var{A} and @var{B}.
11046 If @math{B\ge 0} then the result is @code{ABS(A)}, else
11047 it is @code{-ABS(A)}.
11049 @item @emph{Example}:
11052 print *, sign(-12,1)
11053 print *, sign(-12,0)
11054 print *, sign(-12,-1)
11056 print *, sign(-12.,1.)
11057 print *, sign(-12.,0.)
11058 print *, sign(-12.,-1.)
11059 end program test_sign
11062 @item @emph{Specific names}:
11063 @multitable @columnfractions .20 .20 .20 .25
11064 @item Name @tab Arguments @tab Return type @tab Standard
11065 @item @code{SIGN(A,B)} @tab @code{REAL(4) A, B} @tab @code{REAL(4)} @tab f77, gnu
11066 @item @code{ISIGN(A,B)} @tab @code{INTEGER(4) A, B} @tab @code{INTEGER(4)} @tab f77, gnu
11067 @item @code{DSIGN(A,B)} @tab @code{REAL(8) A, B} @tab @code{REAL(8)} @tab f77, gnu
11074 @section @code{SIGNAL} --- Signal handling subroutine (or function)
11076 @cindex system, signal handling
11079 @item @emph{Description}:
11080 @code{SIGNAL(NUMBER, HANDLER [, STATUS])} causes external subroutine
11081 @var{HANDLER} to be executed with a single integer argument when signal
11082 @var{NUMBER} occurs. If @var{HANDLER} is an integer, it can be used to
11083 turn off handling of signal @var{NUMBER} or revert to its default
11084 action. See @code{signal(2)}.
11086 If @code{SIGNAL} is called as a subroutine and the @var{STATUS} argument
11087 is supplied, it is set to the value returned by @code{signal(2)}.
11089 @item @emph{Standard}:
11092 @item @emph{Class}:
11093 Subroutine, function
11095 @item @emph{Syntax}:
11096 @multitable @columnfractions .80
11097 @item @code{CALL SIGNAL(NUMBER, HANDLER [, STATUS])}
11098 @item @code{STATUS = SIGNAL(NUMBER, HANDLER)}
11101 @item @emph{Arguments}:
11102 @multitable @columnfractions .15 .70
11103 @item @var{NUMBER} @tab Shall be a scalar integer, with @code{INTENT(IN)}
11104 @item @var{HANDLER}@tab Signal handler (@code{INTEGER FUNCTION} or
11105 @code{SUBROUTINE}) or dummy/global @code{INTEGER} scalar.
11106 @code{INTEGER}. It is @code{INTENT(IN)}.
11107 @item @var{STATUS} @tab (Optional) @var{STATUS} shall be a scalar
11108 integer. It has @code{INTENT(OUT)}.
11110 @c TODO: What should the interface of the handler be? Does it take arguments?
11112 @item @emph{Return value}:
11113 The @code{SIGNAL} function returns the value returned by @code{signal(2)}.
11115 @item @emph{Example}:
11117 program test_signal
11119 external handler_print
11121 call signal (12, handler_print)
11122 call signal (10, 1)
11125 end program test_signal
11132 @section @code{SIN} --- Sine function
11138 @cindex trigonometric function, sine
11142 @item @emph{Description}:
11143 @code{SIN(X)} computes the sine of @var{X}.
11145 @item @emph{Standard}:
11146 Fortran 77 and later
11148 @item @emph{Class}:
11151 @item @emph{Syntax}:
11152 @code{RESULT = SIN(X)}
11154 @item @emph{Arguments}:
11155 @multitable @columnfractions .15 .70
11156 @item @var{X} @tab The type shall be @code{REAL} or
11160 @item @emph{Return value}:
11161 The return value has same type and kind as @var{X}.
11163 @item @emph{Example}:
11168 end program test_sin
11171 @item @emph{Specific names}:
11172 @multitable @columnfractions .20 .20 .20 .25
11173 @item Name @tab Argument @tab Return type @tab Standard
11174 @item @code{SIN(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab f77, gnu
11175 @item @code{DSIN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab f95, gnu
11176 @item @code{CSIN(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab f95, gnu
11177 @item @code{ZSIN(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
11178 @item @code{CDSIN(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
11181 @item @emph{See also}:
11188 @section @code{SINH} --- Hyperbolic sine function
11191 @cindex hyperbolic sine
11192 @cindex hyperbolic function, sine
11193 @cindex sine, hyperbolic
11196 @item @emph{Description}:
11197 @code{SINH(X)} computes the hyperbolic sine of @var{X}.
11199 @item @emph{Standard}:
11200 Fortran 95 and later, for a complex argument Fortran 2008 or later
11202 @item @emph{Class}:
11205 @item @emph{Syntax}:
11206 @code{RESULT = SINH(X)}
11208 @item @emph{Arguments}:
11209 @multitable @columnfractions .15 .70
11210 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
11213 @item @emph{Return value}:
11214 The return value has same type and kind as @var{X}.
11216 @item @emph{Example}:
11219 real(8) :: x = - 1.0_8
11221 end program test_sinh
11224 @item @emph{Specific names}:
11225 @multitable @columnfractions .20 .20 .20 .25
11226 @item Name @tab Argument @tab Return type @tab Standard
11227 @item @code{SINH(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 95 and later
11228 @item @code{DSINH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 95 and later
11231 @item @emph{See also}:
11238 @section @code{SIZE} --- Determine the size of an array
11240 @cindex array, size
11241 @cindex array, number of elements
11242 @cindex array, count elements
11245 @item @emph{Description}:
11246 Determine the extent of @var{ARRAY} along a specified dimension @var{DIM},
11247 or the total number of elements in @var{ARRAY} if @var{DIM} is absent.
11249 @item @emph{Standard}:
11250 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
11252 @item @emph{Class}:
11255 @item @emph{Syntax}:
11256 @code{RESULT = SIZE(ARRAY[, DIM [, KIND]])}
11258 @item @emph{Arguments}:
11259 @multitable @columnfractions .15 .70
11260 @item @var{ARRAY} @tab Shall be an array of any type. If @var{ARRAY} is
11261 a pointer it must be associated and allocatable arrays must be allocated.
11262 @item @var{DIM} @tab (Optional) shall be a scalar of type @code{INTEGER}
11263 and its value shall be in the range from 1 to n, where n equals the rank
11265 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
11266 expression indicating the kind parameter of the result.
11269 @item @emph{Return value}:
11270 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
11271 @var{KIND} is absent, the return value is of default integer kind.
11273 @item @emph{Example}:
11276 WRITE(*,*) SIZE((/ 1, 2 /)) ! 2
11280 @item @emph{See also}:
11281 @ref{SHAPE}, @ref{RESHAPE}
11286 @section @code{SIZEOF} --- Size in bytes of an expression
11288 @cindex expression size
11289 @cindex size of an expression
11292 @item @emph{Description}:
11293 @code{SIZEOF(X)} calculates the number of bytes of storage the
11294 expression @code{X} occupies.
11296 @item @emph{Standard}:
11299 @item @emph{Class}:
11302 @item @emph{Syntax}:
11303 @code{N = SIZEOF(X)}
11305 @item @emph{Arguments}:
11306 @multitable @columnfractions .15 .70
11307 @item @var{X} @tab The argument shall be of any type, rank or shape.
11310 @item @emph{Return value}:
11311 The return value is of type integer and of the system-dependent kind
11312 @var{C_SIZE_T} (from the @var{ISO_C_BINDING} module). Its value is the
11313 number of bytes occupied by the argument. If the argument has the
11314 @code{POINTER} attribute, the number of bytes of the storage area pointed
11315 to is returned. If the argument is of a derived type with @code{POINTER}
11316 or @code{ALLOCATABLE} components, the return value doesn't account for
11317 the sizes of the data pointed to by these components. If the argument is
11318 polymorphic, the size according to the declared type is returned.
11320 @item @emph{Example}:
11324 print *, (sizeof(s)/sizeof(r) == 5)
11327 The example will print @code{.TRUE.} unless you are using a platform
11328 where default @code{REAL} variables are unusually padded.
11330 @item @emph{See also}:
11331 @ref{C_SIZEOF}, @ref{STORAGE_SIZE}
11336 @section @code{SLEEP} --- Sleep for the specified number of seconds
11338 @cindex delayed execution
11341 @item @emph{Description}:
11342 Calling this subroutine causes the process to pause for @var{SECONDS} seconds.
11344 @item @emph{Standard}:
11347 @item @emph{Class}:
11350 @item @emph{Syntax}:
11351 @code{CALL SLEEP(SECONDS)}
11353 @item @emph{Arguments}:
11354 @multitable @columnfractions .15 .70
11355 @item @var{SECONDS} @tab The type shall be of default @code{INTEGER}.
11358 @item @emph{Example}:
11369 @section @code{SPACING} --- Smallest distance between two numbers of a given type
11371 @cindex real number, relative spacing
11372 @cindex floating point, relative spacing
11375 @item @emph{Description}:
11376 Determines the distance between the argument @var{X} and the nearest
11377 adjacent number of the same type.
11379 @item @emph{Standard}:
11380 Fortran 95 and later
11382 @item @emph{Class}:
11385 @item @emph{Syntax}:
11386 @code{RESULT = SPACING(X)}
11388 @item @emph{Arguments}:
11389 @multitable @columnfractions .15 .70
11390 @item @var{X} @tab Shall be of type @code{REAL}.
11393 @item @emph{Return value}:
11394 The result is of the same type as the input argument @var{X}.
11396 @item @emph{Example}:
11398 PROGRAM test_spacing
11399 INTEGER, PARAMETER :: SGL = SELECTED_REAL_KIND(p=6, r=37)
11400 INTEGER, PARAMETER :: DBL = SELECTED_REAL_KIND(p=13, r=200)
11402 WRITE(*,*) spacing(1.0_SGL) ! "1.1920929E-07" on i686
11403 WRITE(*,*) spacing(1.0_DBL) ! "2.220446049250313E-016" on i686
11407 @item @emph{See also}:
11414 @section @code{SPREAD} --- Add a dimension to an array
11416 @cindex array, increase dimension
11417 @cindex array, duplicate elements
11418 @cindex array, duplicate dimensions
11421 @item @emph{Description}:
11422 Replicates a @var{SOURCE} array @var{NCOPIES} times along a specified
11423 dimension @var{DIM}.
11425 @item @emph{Standard}:
11426 Fortran 95 and later
11428 @item @emph{Class}:
11429 Transformational function
11431 @item @emph{Syntax}:
11432 @code{RESULT = SPREAD(SOURCE, DIM, NCOPIES)}
11434 @item @emph{Arguments}:
11435 @multitable @columnfractions .15 .70
11436 @item @var{SOURCE} @tab Shall be a scalar or an array of any type and
11437 a rank less than seven.
11438 @item @var{DIM} @tab Shall be a scalar of type @code{INTEGER} with a
11439 value in the range from 1 to n+1, where n equals the rank of @var{SOURCE}.
11440 @item @var{NCOPIES} @tab Shall be a scalar of type @code{INTEGER}.
11443 @item @emph{Return value}:
11444 The result is an array of the same type as @var{SOURCE} and has rank n+1
11445 where n equals the rank of @var{SOURCE}.
11447 @item @emph{Example}:
11449 PROGRAM test_spread
11450 INTEGER :: a = 1, b(2) = (/ 1, 2 /)
11451 WRITE(*,*) SPREAD(A, 1, 2) ! "1 1"
11452 WRITE(*,*) SPREAD(B, 1, 2) ! "1 1 2 2"
11456 @item @emph{See also}:
11463 @section @code{SQRT} --- Square-root function
11470 @cindex square-root
11473 @item @emph{Description}:
11474 @code{SQRT(X)} computes the square root of @var{X}.
11476 @item @emph{Standard}:
11477 Fortran 77 and later
11479 @item @emph{Class}:
11482 @item @emph{Syntax}:
11483 @code{RESULT = SQRT(X)}
11485 @item @emph{Arguments}:
11486 @multitable @columnfractions .15 .70
11487 @item @var{X} @tab The type shall be @code{REAL} or
11491 @item @emph{Return value}:
11492 The return value is of type @code{REAL} or @code{COMPLEX}.
11493 The kind type parameter is the same as @var{X}.
11495 @item @emph{Example}:
11498 real(8) :: x = 2.0_8
11499 complex :: z = (1.0, 2.0)
11502 end program test_sqrt
11505 @item @emph{Specific names}:
11506 @multitable @columnfractions .20 .20 .20 .25
11507 @item Name @tab Argument @tab Return type @tab Standard
11508 @item @code{SQRT(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 95 and later
11509 @item @code{DSQRT(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 95 and later
11510 @item @code{CSQRT(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab Fortran 95 and later
11511 @item @code{ZSQRT(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
11512 @item @code{CDSQRT(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
11519 @section @code{SRAND} --- Reinitialize the random number generator
11521 @cindex random number generation, seeding
11522 @cindex seeding a random number generator
11525 @item @emph{Description}:
11526 @code{SRAND} reinitializes the pseudo-random number generator
11527 called by @code{RAND} and @code{IRAND}. The new seed used by the
11528 generator is specified by the required argument @var{SEED}.
11530 @item @emph{Standard}:
11533 @item @emph{Class}:
11536 @item @emph{Syntax}:
11537 @code{CALL SRAND(SEED)}
11539 @item @emph{Arguments}:
11540 @multitable @columnfractions .15 .70
11541 @item @var{SEED} @tab Shall be a scalar @code{INTEGER(kind=4)}.
11544 @item @emph{Return value}:
11545 Does not return anything.
11547 @item @emph{Example}:
11548 See @code{RAND} and @code{IRAND} for examples.
11550 @item @emph{Notes}:
11551 The Fortran 2003 standard specifies the intrinsic @code{RANDOM_SEED} to
11552 initialize the pseudo-random numbers generator and @code{RANDOM_NUMBER}
11553 to generate pseudo-random numbers. Please note that in
11554 GNU Fortran, these two sets of intrinsics (@code{RAND},
11555 @code{IRAND} and @code{SRAND} on the one hand, @code{RANDOM_NUMBER} and
11556 @code{RANDOM_SEED} on the other hand) access two independent
11557 pseudo-random number generators.
11559 @item @emph{See also}:
11560 @ref{RAND}, @ref{RANDOM_SEED}, @ref{RANDOM_NUMBER}
11567 @section @code{STAT} --- Get file status
11569 @cindex file system, file status
11572 @item @emph{Description}:
11573 This function returns information about a file. No permissions are required on
11574 the file itself, but execute (search) permission is required on all of the
11575 directories in path that lead to the file.
11577 The elements that are obtained and stored in the array @code{VALUES}:
11578 @multitable @columnfractions .15 .70
11579 @item @code{VALUES(1)} @tab Device ID
11580 @item @code{VALUES(2)} @tab Inode number
11581 @item @code{VALUES(3)} @tab File mode
11582 @item @code{VALUES(4)} @tab Number of links
11583 @item @code{VALUES(5)} @tab Owner's uid
11584 @item @code{VALUES(6)} @tab Owner's gid
11585 @item @code{VALUES(7)} @tab ID of device containing directory entry for file (0 if not available)
11586 @item @code{VALUES(8)} @tab File size (bytes)
11587 @item @code{VALUES(9)} @tab Last access time
11588 @item @code{VALUES(10)} @tab Last modification time
11589 @item @code{VALUES(11)} @tab Last file status change time
11590 @item @code{VALUES(12)} @tab Preferred I/O block size (-1 if not available)
11591 @item @code{VALUES(13)} @tab Number of blocks allocated (-1 if not available)
11594 Not all these elements are relevant on all systems.
11595 If an element is not relevant, it is returned as 0.
11597 This intrinsic is provided in both subroutine and function forms; however,
11598 only one form can be used in any given program unit.
11600 @item @emph{Standard}:
11603 @item @emph{Class}:
11604 Subroutine, function
11606 @item @emph{Syntax}:
11607 @multitable @columnfractions .80
11608 @item @code{CALL STAT(NAME, VALUES [, STATUS])}
11609 @item @code{STATUS = STAT(NAME, VALUES)}
11612 @item @emph{Arguments}:
11613 @multitable @columnfractions .15 .70
11614 @item @var{NAME} @tab The type shall be @code{CHARACTER}, of the
11615 default kind and a valid path within the file system.
11616 @item @var{VALUES} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
11617 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}. Returns 0
11618 on success and a system specific error code otherwise.
11621 @item @emph{Example}:
11624 INTEGER, DIMENSION(13) :: buff
11627 CALL STAT("/etc/passwd", buff, status)
11629 IF (status == 0) THEN
11630 WRITE (*, FMT="('Device ID:', T30, I19)") buff(1)
11631 WRITE (*, FMT="('Inode number:', T30, I19)") buff(2)
11632 WRITE (*, FMT="('File mode (octal):', T30, O19)") buff(3)
11633 WRITE (*, FMT="('Number of links:', T30, I19)") buff(4)
11634 WRITE (*, FMT="('Owner''s uid:', T30, I19)") buff(5)
11635 WRITE (*, FMT="('Owner''s gid:', T30, I19)") buff(6)
11636 WRITE (*, FMT="('Device where located:', T30, I19)") buff(7)
11637 WRITE (*, FMT="('File size:', T30, I19)") buff(8)
11638 WRITE (*, FMT="('Last access time:', T30, A19)") CTIME(buff(9))
11639 WRITE (*, FMT="('Last modification time', T30, A19)") CTIME(buff(10))
11640 WRITE (*, FMT="('Last status change time:', T30, A19)") CTIME(buff(11))
11641 WRITE (*, FMT="('Preferred block size:', T30, I19)") buff(12)
11642 WRITE (*, FMT="('No. of blocks allocated:', T30, I19)") buff(13)
11647 @item @emph{See also}:
11648 To stat an open file: @ref{FSTAT}, to stat a link: @ref{LSTAT}
11654 @section @code{STORAGE_SIZE} --- Storage size in bits
11655 @fnindex STORAGE_SIZE
11656 @cindex storage size
11659 @item @emph{Description}:
11660 Returns the storage size of argument @var{A} in bits.
11661 @item @emph{Standard}:
11662 Fortran 2008 and later
11663 @item @emph{Class}:
11665 @item @emph{Syntax}:
11666 @code{RESULT = STORAGE_SIZE(A [, KIND])}
11668 @item @emph{Arguments}:
11669 @multitable @columnfractions .15 .70
11670 @item @var{A} @tab Shall be a scalar or array of any type.
11671 @item @var{KIND} @tab (Optional) shall be a scalar integer constant expression.
11674 @item @emph{Return Value}:
11675 The result is a scalar integer with the kind type parameter specified by KIND (or default integer type if KIND is missing). The result value is the size expressed in bits for an element of an array that
11676 has the dynamic type and type parameters of A.
11678 @item @emph{See also}:
11679 @ref{C_SIZEOF}, @ref{SIZEOF}
11685 @section @code{SUM} --- Sum of array elements
11688 @cindex array, add elements
11689 @cindex array, conditionally add elements
11690 @cindex sum array elements
11693 @item @emph{Description}:
11694 Adds the elements of @var{ARRAY} along dimension @var{DIM} if
11695 the corresponding element in @var{MASK} is @code{TRUE}.
11697 @item @emph{Standard}:
11698 Fortran 95 and later
11700 @item @emph{Class}:
11701 Transformational function
11703 @item @emph{Syntax}:
11704 @multitable @columnfractions .80
11705 @item @code{RESULT = SUM(ARRAY[, MASK])}
11706 @item @code{RESULT = SUM(ARRAY, DIM[, MASK])}
11709 @item @emph{Arguments}:
11710 @multitable @columnfractions .15 .70
11711 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER},
11712 @code{REAL} or @code{COMPLEX}.
11713 @item @var{DIM} @tab (Optional) shall be a scalar of type
11714 @code{INTEGER} with a value in the range from 1 to n, where n
11715 equals the rank of @var{ARRAY}.
11716 @item @var{MASK} @tab (Optional) shall be of type @code{LOGICAL}
11717 and either be a scalar or an array of the same shape as @var{ARRAY}.
11720 @item @emph{Return value}:
11721 The result is of the same type as @var{ARRAY}.
11723 If @var{DIM} is absent, a scalar with the sum of all elements in @var{ARRAY}
11724 is returned. Otherwise, an array of rank n-1, where n equals the rank of
11725 @var{ARRAY}, and a shape similar to that of @var{ARRAY} with dimension @var{DIM}
11726 dropped is returned.
11728 @item @emph{Example}:
11731 INTEGER :: x(5) = (/ 1, 2, 3, 4 ,5 /)
11732 print *, SUM(x) ! all elements, sum = 15
11733 print *, SUM(x, MASK=MOD(x, 2)==1) ! odd elements, sum = 9
11737 @item @emph{See also}:
11744 @section @code{SYMLNK} --- Create a symbolic link
11746 @cindex file system, create link
11747 @cindex file system, soft link
11750 @item @emph{Description}:
11751 Makes a symbolic link from file @var{PATH1} to @var{PATH2}. A null
11752 character (@code{CHAR(0)}) can be used to mark the end of the names in
11753 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
11754 names are ignored. If the @var{STATUS} argument is supplied, it
11755 contains 0 on success or a nonzero error code upon return; see
11756 @code{symlink(2)}. If the system does not supply @code{symlink(2)},
11757 @code{ENOSYS} is returned.
11759 This intrinsic is provided in both subroutine and function forms;
11760 however, only one form can be used in any given program unit.
11762 @item @emph{Standard}:
11765 @item @emph{Class}:
11766 Subroutine, function
11768 @item @emph{Syntax}:
11769 @multitable @columnfractions .80
11770 @item @code{CALL SYMLNK(PATH1, PATH2 [, STATUS])}
11771 @item @code{STATUS = SYMLNK(PATH1, PATH2)}
11774 @item @emph{Arguments}:
11775 @multitable @columnfractions .15 .70
11776 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
11777 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
11778 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
11781 @item @emph{See also}:
11782 @ref{LINK}, @ref{UNLINK}
11789 @section @code{SYSTEM} --- Execute a shell command
11791 @cindex system, system call
11794 @item @emph{Description}:
11795 Passes the command @var{COMMAND} to a shell (see @code{system(3)}). If
11796 argument @var{STATUS} is present, it contains the value returned by
11797 @code{system(3)}, which is presumably 0 if the shell command succeeded.
11798 Note that which shell is used to invoke the command is system-dependent
11799 and environment-dependent.
11801 This intrinsic is provided in both subroutine and function forms;
11802 however, only one form can be used in any given program unit.
11804 Note that the @code{system} function need not be thread-safe. It is
11805 the responsibility of the user to ensure that @code{system} is not
11806 called concurrently.
11808 @item @emph{Standard}:
11811 @item @emph{Class}:
11812 Subroutine, function
11814 @item @emph{Syntax}:
11815 @multitable @columnfractions .80
11816 @item @code{CALL SYSTEM(COMMAND [, STATUS])}
11817 @item @code{STATUS = SYSTEM(COMMAND)}
11820 @item @emph{Arguments}:
11821 @multitable @columnfractions .15 .70
11822 @item @var{COMMAND} @tab Shall be of default @code{CHARACTER} type.
11823 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
11826 @item @emph{See also}:
11827 @ref{EXECUTE_COMMAND_LINE}, which is part of the Fortran 2008 standard
11828 and should considered in new code for future portability.
11834 @section @code{SYSTEM_CLOCK} --- Time function
11835 @fnindex SYSTEM_CLOCK
11836 @cindex time, clock ticks
11837 @cindex clock ticks
11840 @item @emph{Description}:
11841 Determines the @var{COUNT} of a processor clock since an unspecified
11842 time in the past modulo @var{COUNT_MAX}, @var{COUNT_RATE} determines
11843 the number of clock ticks per second. If the platform supports a high
11844 resolution monotonic clock, that clock is used and can provide up to
11845 nanosecond resolution. If a high resolution monotonic clock is not
11846 available, the implementation falls back to a potentially lower
11847 resolution realtime clock.
11849 @var{COUNT_RATE} and @var{COUNT_MAX} vary depending on the kind of the
11850 arguments. For @var{kind=8} arguments, @var{COUNT} represents
11851 nanoseconds, and for @var{kind=4} arguments, @var{COUNT} represents
11852 milliseconds. Other than the kind dependency, @var{COUNT_RATE} and
11853 @var{COUNT_MAX} are constant, however the particular values are
11854 specific to @command{gfortran}.
11856 If there is no clock, @var{COUNT} is set to @code{-HUGE(COUNT)}, and
11857 @var{COUNT_RATE} and @var{COUNT_MAX} are set to zero.
11859 When running on a platform using the GNU C library (glibc), or a
11860 derivative thereof, the high resolution monotonic clock is available
11861 only when linking with the @var{rt} library. This can be done
11862 explicitly by adding the @code{-lrt} flag when linking the
11863 application, but is also done implicitly when using OpenMP.
11865 @item @emph{Standard}:
11866 Fortran 95 and later
11868 @item @emph{Class}:
11871 @item @emph{Syntax}:
11872 @code{CALL SYSTEM_CLOCK([COUNT, COUNT_RATE, COUNT_MAX])}
11874 @item @emph{Arguments}:
11875 @multitable @columnfractions .15 .70
11876 @item @var{COUNT} @tab (Optional) shall be a scalar of type
11877 @code{INTEGER} with @code{INTENT(OUT)}.
11878 @item @var{COUNT_RATE} @tab (Optional) shall be a scalar of type
11879 @code{INTEGER} with @code{INTENT(OUT)}.
11880 @item @var{COUNT_MAX} @tab (Optional) shall be a scalar of type
11881 @code{INTEGER} with @code{INTENT(OUT)}.
11884 @item @emph{Example}:
11886 PROGRAM test_system_clock
11887 INTEGER :: count, count_rate, count_max
11888 CALL SYSTEM_CLOCK(count, count_rate, count_max)
11889 WRITE(*,*) count, count_rate, count_max
11893 @item @emph{See also}:
11894 @ref{DATE_AND_TIME}, @ref{CPU_TIME}
11900 @section @code{TAN} --- Tangent function
11903 @cindex trigonometric function, tangent
11907 @item @emph{Description}:
11908 @code{TAN(X)} computes the tangent of @var{X}.
11910 @item @emph{Standard}:
11911 Fortran 77 and later, for a complex argument Fortran 2008 or later
11913 @item @emph{Class}:
11916 @item @emph{Syntax}:
11917 @code{RESULT = TAN(X)}
11919 @item @emph{Arguments}:
11920 @multitable @columnfractions .15 .70
11921 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
11924 @item @emph{Return value}:
11925 The return value has same type and kind as @var{X}.
11927 @item @emph{Example}:
11930 real(8) :: x = 0.165_8
11932 end program test_tan
11935 @item @emph{Specific names}:
11936 @multitable @columnfractions .20 .20 .20 .25
11937 @item Name @tab Argument @tab Return type @tab Standard
11938 @item @code{TAN(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 95 and later
11939 @item @code{DTAN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 95 and later
11942 @item @emph{See also}:
11949 @section @code{TANH} --- Hyperbolic tangent function
11952 @cindex hyperbolic tangent
11953 @cindex hyperbolic function, tangent
11954 @cindex tangent, hyperbolic
11957 @item @emph{Description}:
11958 @code{TANH(X)} computes the hyperbolic tangent of @var{X}.
11960 @item @emph{Standard}:
11961 Fortran 77 and later, for a complex argument Fortran 2008 or later
11963 @item @emph{Class}:
11966 @item @emph{Syntax}:
11969 @item @emph{Arguments}:
11970 @multitable @columnfractions .15 .70
11971 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
11974 @item @emph{Return value}:
11975 The return value has same type and kind as @var{X}. If @var{X} is
11976 complex, the imaginary part of the result is in radians. If @var{X}
11977 is @code{REAL}, the return value lies in the range
11978 @math{ - 1 \leq tanh(x) \leq 1 }.
11980 @item @emph{Example}:
11983 real(8) :: x = 2.1_8
11985 end program test_tanh
11988 @item @emph{Specific names}:
11989 @multitable @columnfractions .20 .20 .20 .25
11990 @item Name @tab Argument @tab Return type @tab Standard
11991 @item @code{TANH(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 95 and later
11992 @item @code{DTANH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 95 and later
11995 @item @emph{See also}:
12002 @section @code{THIS_IMAGE} --- Function that returns the cosubscript index of this image
12003 @fnindex THIS_IMAGE
12004 @cindex coarray, @code{THIS_IMAGE}
12005 @cindex images, index of this image
12008 @item @emph{Description}:
12009 Returns the cosubscript for this image.
12011 @item @emph{Standard}:
12012 Fortran 2008 and later
12014 @item @emph{Class}:
12015 Transformational function
12017 @item @emph{Syntax}:
12018 @multitable @columnfractions .80
12019 @item @code{RESULT = THIS_IMAGE()}
12020 @item @code{RESULT = THIS_IMAGE(COARRAY [, DIM])}
12023 @item @emph{Arguments}:
12024 @multitable @columnfractions .15 .70
12025 @item @var{COARRAY} @tab Coarray of any type (optional; if @var{DIM}
12026 present, required).
12027 @item @var{DIM} @tab default integer scalar (optional). If present,
12028 @var{DIM} shall be between one and the corank of @var{COARRAY}.
12032 @item @emph{Return value}:
12033 Default integer. If @var{COARRAY} is not present, it is scalar and its value
12034 is the index of the invoking image. Otherwise, if @var{DIM} is not present,
12035 a rank-1 array with corank elements is returned, containing the cosubscripts
12036 for @var{COARRAY} specifying the invoking image. If @var{DIM} is present,
12037 a scalar is returned, with the value of the @var{DIM} element of
12038 @code{THIS_IMAGE(COARRAY)}.
12040 @item @emph{Example}:
12042 INTEGER :: value[*]
12044 value = THIS_IMAGE()
12046 IF (THIS_IMAGE() == 1) THEN
12047 DO i = 1, NUM_IMAGES()
12048 WRITE(*,'(2(a,i0))') 'value[', i, '] is ', value[i]
12053 @item @emph{See also}:
12054 @ref{NUM_IMAGES}, @ref{IMAGE_INDEX}
12060 @section @code{TIME} --- Time function
12062 @cindex time, current
12063 @cindex current time
12066 @item @emph{Description}:
12067 Returns the current time encoded as an integer (in the manner of the
12068 UNIX function @code{time(3)}). This value is suitable for passing to
12069 @code{CTIME}, @code{GMTIME}, and @code{LTIME}.
12071 This intrinsic is not fully portable, such as to systems with 32-bit
12072 @code{INTEGER} types but supporting times wider than 32 bits. Therefore,
12073 the values returned by this intrinsic might be, or become, negative, or
12074 numerically less than previous values, during a single run of the
12077 See @ref{TIME8}, for information on a similar intrinsic that might be
12078 portable to more GNU Fortran implementations, though to fewer Fortran
12081 @item @emph{Standard}:
12084 @item @emph{Class}:
12087 @item @emph{Syntax}:
12088 @code{RESULT = TIME()}
12090 @item @emph{Return value}:
12091 The return value is a scalar of type @code{INTEGER(4)}.
12093 @item @emph{See also}:
12094 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK}, @ref{TIME8}
12101 @section @code{TIME8} --- Time function (64-bit)
12103 @cindex time, current
12104 @cindex current time
12107 @item @emph{Description}:
12108 Returns the current time encoded as an integer (in the manner of the
12109 UNIX function @code{time(3)}). This value is suitable for passing to
12110 @code{CTIME}, @code{GMTIME}, and @code{LTIME}.
12112 @emph{Warning:} this intrinsic does not increase the range of the timing
12113 values over that returned by @code{time(3)}. On a system with a 32-bit
12114 @code{time(3)}, @code{TIME8} will return a 32-bit value, even though
12115 it is converted to a 64-bit @code{INTEGER(8)} value. That means
12116 overflows of the 32-bit value can still occur. Therefore, the values
12117 returned by this intrinsic might be or become negative or numerically
12118 less than previous values during a single run of the compiled program.
12120 @item @emph{Standard}:
12123 @item @emph{Class}:
12126 @item @emph{Syntax}:
12127 @code{RESULT = TIME8()}
12129 @item @emph{Return value}:
12130 The return value is a scalar of type @code{INTEGER(8)}.
12132 @item @emph{See also}:
12133 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK8}, @ref{TIME}
12140 @section @code{TINY} --- Smallest positive number of a real kind
12142 @cindex limits, smallest number
12143 @cindex model representation, smallest number
12146 @item @emph{Description}:
12147 @code{TINY(X)} returns the smallest positive (non zero) number
12148 in the model of the type of @code{X}.
12150 @item @emph{Standard}:
12151 Fortran 95 and later
12153 @item @emph{Class}:
12156 @item @emph{Syntax}:
12157 @code{RESULT = TINY(X)}
12159 @item @emph{Arguments}:
12160 @multitable @columnfractions .15 .70
12161 @item @var{X} @tab Shall be of type @code{REAL}.
12164 @item @emph{Return value}:
12165 The return value is of the same type and kind as @var{X}
12167 @item @emph{Example}:
12168 See @code{HUGE} for an example.
12174 @section @code{TRAILZ} --- Number of trailing zero bits of an integer
12179 @item @emph{Description}:
12180 @code{TRAILZ} returns the number of trailing zero bits of an integer.
12182 @item @emph{Standard}:
12183 Fortran 2008 and later
12185 @item @emph{Class}:
12188 @item @emph{Syntax}:
12189 @code{RESULT = TRAILZ(I)}
12191 @item @emph{Arguments}:
12192 @multitable @columnfractions .15 .70
12193 @item @var{I} @tab Shall be of type @code{INTEGER}.
12196 @item @emph{Return value}:
12197 The type of the return value is the default @code{INTEGER}.
12198 If all the bits of @code{I} are zero, the result value is @code{BIT_SIZE(I)}.
12200 @item @emph{Example}:
12202 PROGRAM test_trailz
12203 WRITE (*,*) TRAILZ(8) ! prints 3
12207 @item @emph{See also}:
12208 @ref{BIT_SIZE}, @ref{LEADZ}, @ref{POPPAR}, @ref{POPCNT}
12214 @section @code{TRANSFER} --- Transfer bit patterns
12220 @item @emph{Description}:
12221 Interprets the bitwise representation of @var{SOURCE} in memory as if it
12222 is the representation of a variable or array of the same type and type
12223 parameters as @var{MOLD}.
12225 This is approximately equivalent to the C concept of @emph{casting} one
12228 @item @emph{Standard}:
12229 Fortran 95 and later
12231 @item @emph{Class}:
12232 Transformational function
12234 @item @emph{Syntax}:
12235 @code{RESULT = TRANSFER(SOURCE, MOLD[, SIZE])}
12237 @item @emph{Arguments}:
12238 @multitable @columnfractions .15 .70
12239 @item @var{SOURCE} @tab Shall be a scalar or an array of any type.
12240 @item @var{MOLD} @tab Shall be a scalar or an array of any type.
12241 @item @var{SIZE} @tab (Optional) shall be a scalar of type
12245 @item @emph{Return value}:
12246 The result has the same type as @var{MOLD}, with the bit level
12247 representation of @var{SOURCE}. If @var{SIZE} is present, the result is
12248 a one-dimensional array of length @var{SIZE}. If @var{SIZE} is absent
12249 but @var{MOLD} is an array (of any size or shape), the result is a one-
12250 dimensional array of the minimum length needed to contain the entirety
12251 of the bitwise representation of @var{SOURCE}. If @var{SIZE} is absent
12252 and @var{MOLD} is a scalar, the result is a scalar.
12254 If the bitwise representation of the result is longer than that of
12255 @var{SOURCE}, then the leading bits of the result correspond to those of
12256 @var{SOURCE} and any trailing bits are filled arbitrarily.
12258 When the resulting bit representation does not correspond to a valid
12259 representation of a variable of the same type as @var{MOLD}, the results
12260 are undefined, and subsequent operations on the result cannot be
12261 guaranteed to produce sensible behavior. For example, it is possible to
12262 create @code{LOGICAL} variables for which @code{@var{VAR}} and
12263 @code{.NOT.@var{VAR}} both appear to be true.
12265 @item @emph{Example}:
12267 PROGRAM test_transfer
12268 integer :: x = 2143289344
12269 print *, transfer(x, 1.0) ! prints "NaN" on i686
12277 @section @code{TRANSPOSE} --- Transpose an array of rank two
12279 @cindex array, transpose
12280 @cindex matrix, transpose
12284 @item @emph{Description}:
12285 Transpose an array of rank two. Element (i, j) of the result has the value
12286 @code{MATRIX(j, i)}, for all i, j.
12288 @item @emph{Standard}:
12289 Fortran 95 and later
12291 @item @emph{Class}:
12292 Transformational function
12294 @item @emph{Syntax}:
12295 @code{RESULT = TRANSPOSE(MATRIX)}
12297 @item @emph{Arguments}:
12298 @multitable @columnfractions .15 .70
12299 @item @var{MATRIX} @tab Shall be an array of any type and have a rank of two.
12302 @item @emph{Return value}:
12303 The result has the same type as @var{MATRIX}, and has shape
12304 @code{(/ m, n /)} if @var{MATRIX} has shape @code{(/ n, m /)}.
12310 @section @code{TRIM} --- Remove trailing blank characters of a string
12312 @cindex string, remove trailing whitespace
12315 @item @emph{Description}:
12316 Removes trailing blank characters of a string.
12318 @item @emph{Standard}:
12319 Fortran 95 and later
12321 @item @emph{Class}:
12322 Transformational function
12324 @item @emph{Syntax}:
12325 @code{RESULT = TRIM(STRING)}
12327 @item @emph{Arguments}:
12328 @multitable @columnfractions .15 .70
12329 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER}.
12332 @item @emph{Return value}:
12333 A scalar of type @code{CHARACTER} which length is that of @var{STRING}
12334 less the number of trailing blanks.
12336 @item @emph{Example}:
12339 CHARACTER(len=10), PARAMETER :: s = "GFORTRAN "
12340 WRITE(*,*) LEN(s), LEN(TRIM(s)) ! "10 8", with/without trailing blanks
12344 @item @emph{See also}:
12345 @ref{ADJUSTL}, @ref{ADJUSTR}
12351 @section @code{TTYNAM} --- Get the name of a terminal device.
12353 @cindex system, terminal
12356 @item @emph{Description}:
12357 Get the name of a terminal device. For more information,
12358 see @code{ttyname(3)}.
12360 This intrinsic is provided in both subroutine and function forms;
12361 however, only one form can be used in any given program unit.
12363 @item @emph{Standard}:
12366 @item @emph{Class}:
12367 Subroutine, function
12369 @item @emph{Syntax}:
12370 @multitable @columnfractions .80
12371 @item @code{CALL TTYNAM(UNIT, NAME)}
12372 @item @code{NAME = TTYNAM(UNIT)}
12375 @item @emph{Arguments}:
12376 @multitable @columnfractions .15 .70
12377 @item @var{UNIT} @tab Shall be a scalar @code{INTEGER}.
12378 @item @var{NAME} @tab Shall be of type @code{CHARACTER}.
12381 @item @emph{Example}:
12383 PROGRAM test_ttynam
12386 IF (isatty(unit=unit)) write(*,*) ttynam(unit)
12391 @item @emph{See also}:
12398 @section @code{UBOUND} --- Upper dimension bounds of an array
12400 @cindex array, upper bound
12403 @item @emph{Description}:
12404 Returns the upper bounds of an array, or a single upper bound
12405 along the @var{DIM} dimension.
12406 @item @emph{Standard}:
12407 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
12409 @item @emph{Class}:
12412 @item @emph{Syntax}:
12413 @code{RESULT = UBOUND(ARRAY [, DIM [, KIND]])}
12415 @item @emph{Arguments}:
12416 @multitable @columnfractions .15 .70
12417 @item @var{ARRAY} @tab Shall be an array, of any type.
12418 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER}.
12419 @item @var{KIND}@tab (Optional) An @code{INTEGER} initialization
12420 expression indicating the kind parameter of the result.
12423 @item @emph{Return value}:
12424 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
12425 @var{KIND} is absent, the return value is of default integer kind.
12426 If @var{DIM} is absent, the result is an array of the upper bounds of
12427 @var{ARRAY}. If @var{DIM} is present, the result is a scalar
12428 corresponding to the upper bound of the array along that dimension. If
12429 @var{ARRAY} is an expression rather than a whole array or array
12430 structure component, or if it has a zero extent along the relevant
12431 dimension, the upper bound is taken to be the number of elements along
12432 the relevant dimension.
12434 @item @emph{See also}:
12435 @ref{LBOUND}, @ref{LCOBOUND}
12441 @section @code{UCOBOUND} --- Upper codimension bounds of an array
12443 @cindex coarray, upper bound
12446 @item @emph{Description}:
12447 Returns the upper cobounds of a coarray, or a single upper cobound
12448 along the @var{DIM} codimension.
12449 @item @emph{Standard}:
12450 Fortran 2008 and later
12452 @item @emph{Class}:
12455 @item @emph{Syntax}:
12456 @code{RESULT = UCOBOUND(COARRAY [, DIM [, KIND]])}
12458 @item @emph{Arguments}:
12459 @multitable @columnfractions .15 .70
12460 @item @var{ARRAY} @tab Shall be an coarray, of any type.
12461 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER}.
12462 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
12463 expression indicating the kind parameter of the result.
12466 @item @emph{Return value}:
12467 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
12468 @var{KIND} is absent, the return value is of default integer kind.
12469 If @var{DIM} is absent, the result is an array of the lower cobounds of
12470 @var{COARRAY}. If @var{DIM} is present, the result is a scalar
12471 corresponding to the lower cobound of the array along that codimension.
12473 @item @emph{See also}:
12474 @ref{LCOBOUND}, @ref{LBOUND}
12480 @section @code{UMASK} --- Set the file creation mask
12482 @cindex file system, file creation mask
12485 @item @emph{Description}:
12486 Sets the file creation mask to @var{MASK}. If called as a function, it
12487 returns the old value. If called as a subroutine and argument @var{OLD}
12488 if it is supplied, it is set to the old value. See @code{umask(2)}.
12490 @item @emph{Standard}:
12493 @item @emph{Class}:
12494 Subroutine, function
12496 @item @emph{Syntax}:
12497 @multitable @columnfractions .80
12498 @item @code{CALL UMASK(MASK [, OLD])}
12499 @item @code{OLD = UMASK(MASK)}
12502 @item @emph{Arguments}:
12503 @multitable @columnfractions .15 .70
12504 @item @var{MASK} @tab Shall be a scalar of type @code{INTEGER}.
12505 @item @var{OLD} @tab (Optional) Shall be a scalar of type
12514 @section @code{UNLINK} --- Remove a file from the file system
12516 @cindex file system, remove file
12519 @item @emph{Description}:
12520 Unlinks the file @var{PATH}. A null character (@code{CHAR(0)}) can be
12521 used to mark the end of the name in @var{PATH}; otherwise, trailing
12522 blanks in the file name are ignored. If the @var{STATUS} argument is
12523 supplied, it contains 0 on success or a nonzero error code upon return;
12524 see @code{unlink(2)}.
12526 This intrinsic is provided in both subroutine and function forms;
12527 however, only one form can be used in any given program unit.
12529 @item @emph{Standard}:
12532 @item @emph{Class}:
12533 Subroutine, function
12535 @item @emph{Syntax}:
12536 @multitable @columnfractions .80
12537 @item @code{CALL UNLINK(PATH [, STATUS])}
12538 @item @code{STATUS = UNLINK(PATH)}
12541 @item @emph{Arguments}:
12542 @multitable @columnfractions .15 .70
12543 @item @var{PATH} @tab Shall be of default @code{CHARACTER} type.
12544 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
12547 @item @emph{See also}:
12548 @ref{LINK}, @ref{SYMLNK}
12554 @section @code{UNPACK} --- Unpack an array of rank one into an array
12556 @cindex array, unpacking
12557 @cindex array, increase dimension
12558 @cindex array, scatter elements
12561 @item @emph{Description}:
12562 Store the elements of @var{VECTOR} in an array of higher rank.
12564 @item @emph{Standard}:
12565 Fortran 95 and later
12567 @item @emph{Class}:
12568 Transformational function
12570 @item @emph{Syntax}:
12571 @code{RESULT = UNPACK(VECTOR, MASK, FIELD)}
12573 @item @emph{Arguments}:
12574 @multitable @columnfractions .15 .70
12575 @item @var{VECTOR} @tab Shall be an array of any type and rank one. It
12576 shall have at least as many elements as @var{MASK} has @code{TRUE} values.
12577 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL}.
12578 @item @var{FIELD} @tab Shall be of the same type as @var{VECTOR} and have
12579 the same shape as @var{MASK}.
12582 @item @emph{Return value}:
12583 The resulting array corresponds to @var{FIELD} with @code{TRUE} elements
12584 of @var{MASK} replaced by values from @var{VECTOR} in array element order.
12586 @item @emph{Example}:
12588 PROGRAM test_unpack
12589 integer :: vector(2) = (/1,1/)
12590 logical :: mask(4) = (/ .TRUE., .FALSE., .FALSE., .TRUE. /)
12591 integer :: field(2,2) = 0, unity(2,2)
12593 ! result: unity matrix
12594 unity = unpack(vector, reshape(mask, (/2,2/)), field)
12598 @item @emph{See also}:
12599 @ref{PACK}, @ref{SPREAD}
12605 @section @code{VERIFY} --- Scan a string for characters not a given set
12607 @cindex string, find missing set
12610 @item @emph{Description}:
12611 Verifies that all the characters in @var{STRING} belong the set of
12612 characters in @var{SET}.
12614 If @var{BACK} is either absent or equals @code{FALSE}, this function
12615 returns the position of the leftmost character of @var{STRING} that is
12616 not in @var{SET}. If @var{BACK} equals @code{TRUE}, the rightmost
12617 position is returned. If all characters of @var{STRING} are found in
12618 @var{SET}, the result is zero.
12620 @item @emph{Standard}:
12621 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
12623 @item @emph{Class}:
12626 @item @emph{Syntax}:
12627 @code{RESULT = VERIFY(STRING, SET[, BACK [, KIND]])}
12629 @item @emph{Arguments}:
12630 @multitable @columnfractions .15 .70
12631 @item @var{STRING} @tab Shall be of type @code{CHARACTER}.
12632 @item @var{SET} @tab Shall be of type @code{CHARACTER}.
12633 @item @var{BACK} @tab (Optional) shall be of type @code{LOGICAL}.
12634 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
12635 expression indicating the kind parameter of the result.
12638 @item @emph{Return value}:
12639 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
12640 @var{KIND} is absent, the return value is of default integer kind.
12642 @item @emph{Example}:
12644 PROGRAM test_verify
12645 WRITE(*,*) VERIFY("FORTRAN", "AO") ! 1, found 'F'
12646 WRITE(*,*) VERIFY("FORTRAN", "FOO") ! 3, found 'R'
12647 WRITE(*,*) VERIFY("FORTRAN", "C++") ! 1, found 'F'
12648 WRITE(*,*) VERIFY("FORTRAN", "C++", .TRUE.) ! 7, found 'N'
12649 WRITE(*,*) VERIFY("FORTRAN", "FORTRAN") ! 0' found none
12653 @item @emph{See also}:
12654 @ref{SCAN}, @ref{INDEX intrinsic}
12660 @section @code{XOR} --- Bitwise logical exclusive OR
12662 @cindex bitwise logical exclusive or
12663 @cindex logical exclusive or, bitwise
12666 @item @emph{Description}:
12667 Bitwise logical exclusive or.
12669 This intrinsic routine is provided for backwards compatibility with
12670 GNU Fortran 77. For integer arguments, programmers should consider
12671 the use of the @ref{IEOR} intrinsic and for logical arguments the
12672 @code{.NEQV.} operator, which are both defined by the Fortran standard.
12674 @item @emph{Standard}:
12677 @item @emph{Class}:
12680 @item @emph{Syntax}:
12681 @code{RESULT = XOR(I, J)}
12683 @item @emph{Arguments}:
12684 @multitable @columnfractions .15 .70
12685 @item @var{I} @tab The type shall be either a scalar @code{INTEGER}
12686 type or a scalar @code{LOGICAL} type.
12687 @item @var{J} @tab The type shall be the same as the type of @var{I}.
12690 @item @emph{Return value}:
12691 The return type is either a scalar @code{INTEGER} or a scalar
12692 @code{LOGICAL}. If the kind type parameters differ, then the
12693 smaller kind type is implicitly converted to larger kind, and the
12694 return has the larger kind.
12696 @item @emph{Example}:
12699 LOGICAL :: T = .TRUE., F = .FALSE.
12701 DATA a / Z'F' /, b / Z'3' /
12703 WRITE (*,*) XOR(T, T), XOR(T, F), XOR(F, T), XOR(F, F)
12704 WRITE (*,*) XOR(a, b)
12708 @item @emph{See also}:
12709 Fortran 95 elemental function: @ref{IEOR}
12714 @node Intrinsic Modules
12715 @chapter Intrinsic Modules
12716 @cindex intrinsic Modules
12719 * ISO_FORTRAN_ENV::
12721 * OpenMP Modules OMP_LIB and OMP_LIB_KINDS::
12724 @node ISO_FORTRAN_ENV
12725 @section @code{ISO_FORTRAN_ENV}
12727 @item @emph{Standard}:
12728 Fortran 2003 and later, except when otherwise noted
12731 The @code{ISO_FORTRAN_ENV} module provides the following scalar default-integer
12735 @item @code{ATOMIC_INT_KIND}:
12736 Default-kind integer constant to be used as kind parameter when defining
12737 integer variables used in atomic operations. (Fortran 2008 or later.)
12739 @item @code{ATOMIC_LOGICAL_KIND}:
12740 Default-kind integer constant to be used as kind parameter when defining
12741 logical variables used in atomic operations. (Fortran 2008 or later.)
12743 @item @code{CHARACTER_KINDS}:
12744 Default-kind integer constant array of rank one containing the supported kind
12745 parameters of the @code{CHARACTER} type. (Fortran 2008 or later.)
12747 @item @code{CHARACTER_STORAGE_SIZE}:
12748 Size in bits of the character storage unit.
12750 @item @code{ERROR_UNIT}:
12751 Identifies the preconnected unit used for error reporting.
12753 @item @code{FILE_STORAGE_SIZE}:
12754 Size in bits of the file-storage unit.
12756 @item @code{INPUT_UNIT}:
12757 Identifies the preconnected unit identified by the asterisk
12758 (@code{*}) in @code{READ} statement.
12760 @item @code{INT8}, @code{INT16}, @code{INT32}, @code{INT64}:
12761 Kind type parameters to specify an INTEGER type with a storage
12762 size of 16, 32, and 64 bits. It is negative if a target platform
12763 does not support the particular kind. (Fortran 2008 or later.)
12765 @item @code{INTEGER_KINDS}:
12766 Default-kind integer constant array of rank one containing the supported kind
12767 parameters of the @code{INTEGER} type. (Fortran 2008 or later.)
12769 @item @code{IOSTAT_END}:
12770 The value assigned to the variable passed to the @code{IOSTAT=} specifier of
12771 an input/output statement if an end-of-file condition occurred.
12773 @item @code{IOSTAT_EOR}:
12774 The value assigned to the variable passed to the @code{IOSTAT=} specifier of
12775 an input/output statement if an end-of-record condition occurred.
12777 @item @code{IOSTAT_INQUIRE_INTERNAL_UNIT}:
12778 Scalar default-integer constant, used by @code{INQUIRE} for the
12779 @code{IOSTAT=} specifier to denote an that a unit number identifies an
12780 internal unit. (Fortran 2008 or later.)
12782 @item @code{NUMERIC_STORAGE_SIZE}:
12783 The size in bits of the numeric storage unit.
12785 @item @code{LOGICAL_KINDS}:
12786 Default-kind integer constant array of rank one containing the supported kind
12787 parameters of the @code{LOGICAL} type. (Fortran 2008 or later.)
12789 @item @code{OUTPUT_UNIT}:
12790 Identifies the preconnected unit identified by the asterisk
12791 (@code{*}) in @code{WRITE} statement.
12793 @item @code{REAL32}, @code{REAL64}, @code{REAL128}:
12794 Kind type parameters to specify a REAL type with a storage
12795 size of 32, 64, and 128 bits. It is negative if a target platform
12796 does not support the particular kind. (Fortran 2008 or later.)
12798 @item @code{REAL_KINDS}:
12799 Default-kind integer constant array of rank one containing the supported kind
12800 parameters of the @code{REAL} type. (Fortran 2008 or later.)
12802 @item @code{STAT_LOCKED}:
12803 Scalar default-integer constant used as STAT= return value by @code{LOCK} to
12804 denote that the lock variable is locked by the executing image. (Fortran 2008
12807 @item @code{STAT_LOCKED_OTHER_IMAGE}:
12808 Scalar default-integer constant used as STAT= return value by @code{UNLOCK} to
12809 denote that the lock variable is locked by another image. (Fortran 2008 or
12812 @item @code{STAT_STOPPED_IMAGE}:
12813 Positive, scalar default-integer constant used as STAT= return value if the
12814 argument in the statement requires synchronisation with an image, which has
12815 initiated the termination of the execution. (Fortran 2008 or later.)
12817 @item @code{STAT_UNLOCKED}:
12818 Scalar default-integer constant used as STAT= return value by @code{UNLOCK} to
12819 denote that the lock variable is unlocked. (Fortran 2008 or later.)
12822 The module also provides the following intrinsic procedures:
12823 @ref{COMPILER_OPTIONS} and @ref{COMPILER_VERSION}.
12827 @node ISO_C_BINDING
12828 @section @code{ISO_C_BINDING}
12830 @item @emph{Standard}:
12831 Fortran 2003 and later, GNU extensions
12834 The following intrinsic procedures are provided by the module; their
12835 definition can be found in the section Intrinsic Procedures of this
12839 @item @code{C_ASSOCIATED}
12840 @item @code{C_F_POINTER}
12841 @item @code{C_F_PROCPOINTER}
12842 @item @code{C_FUNLOC}
12844 @item @code{C_SIZEOF}
12846 @c TODO: Vertical spacing between C_FUNLOC and C_LOC wrong in PDF,
12847 @c don't really know why.
12849 The @code{ISO_C_BINDING} module provides the following named constants of
12850 type default integer, which can be used as KIND type parameters.
12852 In addition to the integer named constants required by the Fortran 2003
12853 standard, GNU Fortran provides as an extension named constants for the
12854 128-bit integer types supported by the C compiler: @code{C_INT128_T,
12855 C_INT_LEAST128_T, C_INT_FAST128_T}.
12857 @multitable @columnfractions .15 .35 .35 .35
12858 @item Fortran Type @tab Named constant @tab C type @tab Extension
12859 @item @code{INTEGER}@tab @code{C_INT} @tab @code{int}
12860 @item @code{INTEGER}@tab @code{C_SHORT} @tab @code{short int}
12861 @item @code{INTEGER}@tab @code{C_LONG} @tab @code{long int}
12862 @item @code{INTEGER}@tab @code{C_LONG_LONG} @tab @code{long long int}
12863 @item @code{INTEGER}@tab @code{C_SIGNED_CHAR} @tab @code{signed char}/@code{unsigned char}
12864 @item @code{INTEGER}@tab @code{C_SIZE_T} @tab @code{size_t}
12865 @item @code{INTEGER}@tab @code{C_INT8_T} @tab @code{int8_t}
12866 @item @code{INTEGER}@tab @code{C_INT16_T} @tab @code{int16_t}
12867 @item @code{INTEGER}@tab @code{C_INT32_T} @tab @code{int32_t}
12868 @item @code{INTEGER}@tab @code{C_INT64_T} @tab @code{int64_t}
12869 @item @code{INTEGER}@tab @code{C_INT128_T} @tab @code{int128_t} @tab Ext.
12870 @item @code{INTEGER}@tab @code{C_INT_LEAST8_T} @tab @code{int_least8_t}
12871 @item @code{INTEGER}@tab @code{C_INT_LEAST16_T} @tab @code{int_least16_t}
12872 @item @code{INTEGER}@tab @code{C_INT_LEAST32_T} @tab @code{int_least32_t}
12873 @item @code{INTEGER}@tab @code{C_INT_LEAST64_T} @tab @code{int_least64_t}
12874 @item @code{INTEGER}@tab @code{C_INT_LEAST128_T}@tab @code{int_least128_t} @tab Ext.
12875 @item @code{INTEGER}@tab @code{C_INT_FAST8_T} @tab @code{int_fast8_t}
12876 @item @code{INTEGER}@tab @code{C_INT_FAST16_T} @tab @code{int_fast16_t}
12877 @item @code{INTEGER}@tab @code{C_INT_FAST32_T} @tab @code{int_fast32_t}
12878 @item @code{INTEGER}@tab @code{C_INT_FAST64_T} @tab @code{int_fast64_t}
12879 @item @code{INTEGER}@tab @code{C_INT_FAST128_T} @tab @code{int_fast128_t} @tab Ext.
12880 @item @code{INTEGER}@tab @code{C_INTMAX_T} @tab @code{intmax_t}
12881 @item @code{INTEGER}@tab @code{C_INTPTR_T} @tab @code{intptr_t}
12882 @item @code{REAL} @tab @code{C_FLOAT} @tab @code{float}
12883 @item @code{REAL} @tab @code{C_DOUBLE} @tab @code{double}
12884 @item @code{REAL} @tab @code{C_LONG_DOUBLE} @tab @code{long double}
12885 @item @code{COMPLEX}@tab @code{C_FLOAT_COMPLEX} @tab @code{float _Complex}
12886 @item @code{COMPLEX}@tab @code{C_DOUBLE_COMPLEX}@tab @code{double _Complex}
12887 @item @code{COMPLEX}@tab @code{C_LONG_DOUBLE_COMPLEX}@tab @code{long double _Complex}
12888 @item @code{LOGICAL}@tab @code{C_BOOL} @tab @code{_Bool}
12889 @item @code{CHARACTER}@tab @code{C_CHAR} @tab @code{char}
12892 Additionally, the following parameters of type @code{CHARACTER(KIND=C_CHAR)}
12895 @multitable @columnfractions .20 .45 .15
12896 @item Name @tab C definition @tab Value
12897 @item @code{C_NULL_CHAR} @tab null character @tab @code{'\0'}
12898 @item @code{C_ALERT} @tab alert @tab @code{'\a'}
12899 @item @code{C_BACKSPACE} @tab backspace @tab @code{'\b'}
12900 @item @code{C_FORM_FEED} @tab form feed @tab @code{'\f'}
12901 @item @code{C_NEW_LINE} @tab new line @tab @code{'\n'}
12902 @item @code{C_CARRIAGE_RETURN} @tab carriage return @tab @code{'\r'}
12903 @item @code{C_HORIZONTAL_TAB} @tab horizontal tab @tab @code{'\t'}
12904 @item @code{C_VERTICAL_TAB} @tab vertical tab @tab @code{'\v'}
12907 Moreover, the following two named constants are defined:
12909 @multitable @columnfractions .20 .80
12910 @item Name @tab Type
12911 @item @code{C_NULL_PTR} @tab @code{C_PTR}
12912 @item @code{C_NULL_FUNPTR} @tab @code{C_FUNPTR}
12915 Both are equivalent to the value @code{NULL} in C.
12917 @node OpenMP Modules OMP_LIB and OMP_LIB_KINDS
12918 @section OpenMP Modules @code{OMP_LIB} and @code{OMP_LIB_KINDS}
12920 @item @emph{Standard}:
12921 OpenMP Application Program Interface v3.0
12925 The OpenMP Fortran runtime library routines are provided both in
12926 a form of two Fortran 90 modules, named @code{OMP_LIB} and
12927 @code{OMP_LIB_KINDS}, and in a form of a Fortran @code{include} file named
12928 @file{omp_lib.h}. The procedures provided by @code{OMP_LIB} can be found
12929 in the @ref{Top,,Introduction,libgomp,GNU OpenMP runtime library} manual,
12930 the named constants defined in the modules are listed
12933 For details refer to the actual
12934 @uref{http://www.openmp.org/mp-documents/spec30.pdf,
12935 OpenMP Application Program Interface v3.0}.
12937 @code{OMP_LIB_KINDS} provides the following scalar default-integer
12941 @item @code{omp_integer_kind}
12942 @item @code{omp_logical_kind}
12943 @item @code{omp_lock_kind}
12944 @item @code{omp_nest_lock_kind}
12945 @item @code{omp_sched_kind}
12948 @code{OMP_LIB} provides the scalar default-integer
12949 named constant @code{openmp_version} with a value of the form
12950 @var{yyyymm}, where @code{yyyy} is the year and @var{mm} the month
12951 of the OpenMP version; for OpenMP v3.0 the value is @code{200805}.
12953 And the following scalar integer named constants of the
12954 kind @code{omp_sched_kind}:
12957 @item @code{omp_sched_static}
12958 @item @code{omp_sched_dynamic}
12959 @item @code{omp_sched_guided}
12960 @item @code{omp_sched_auto}