2 Copyright (C) 2005-2024 Free Software Foundation, Inc.
3 This is part of the GNU Fortran manual.
4 For copying conditions, see the file gfortran.texi.
6 Permission is granted to copy, distribute and/or modify this document
7 under the terms of the GNU Free Documentation License, Version 1.3 or
8 any later version published by the Free Software Foundation; with the
9 Invariant Sections being ``Funding Free Software'', the Front-Cover
10 Texts being (a) (see below), and with the Back-Cover Texts being (b)
11 (see below). A copy of the license is included in the gfdl(7) man page.
14 Some basic guidelines for editing this document:
16 (1) The intrinsic procedures are to be listed in alphabetical order.
17 (2) The generic name is to be used.
18 (3) The specific names are included in the function index and in a
19 table at the end of the node (See ABS entry).
20 (4) Try to maintain the same style for each entry.
26 \gdef\acosd{\mathop{\rm acosd}\nolimits}
27 \gdef\asind{\mathop{\rm asind}\nolimits}
28 \gdef\atand{\mathop{\rm atand}\nolimits}
29 \gdef\acos{\mathop{\rm acos}\nolimits}
30 \gdef\asin{\mathop{\rm asin}\nolimits}
31 \gdef\atan{\mathop{\rm atan}\nolimits}
32 \gdef\acosh{\mathop{\rm acosh}\nolimits}
33 \gdef\asinh{\mathop{\rm asinh}\nolimits}
34 \gdef\atanh{\mathop{\rm atanh}\nolimits}
35 \gdef\cosd{\mathop{\rm cosd}\nolimits}
39 @node Intrinsic Procedures
40 @chapter Intrinsic Procedures
41 @cindex intrinsic procedures
44 * Introduction: Introduction to Intrinsics
45 * @code{ABORT}: ABORT, Abort the program
46 * @code{ABS}: ABS, Absolute value
47 * @code{ACCESS}: ACCESS, Checks file access modes
48 * @code{ACHAR}: ACHAR, Character in @acronym{ASCII} collating sequence
49 * @code{ACOS}: ACOS, Arccosine function
50 * @code{ACOSD}: ACOSD, Arccosine function, degrees
51 * @code{ACOSH}: ACOSH, Inverse hyperbolic cosine function
52 * @code{ADJUSTL}: ADJUSTL, Left adjust a string
53 * @code{ADJUSTR}: ADJUSTR, Right adjust a string
54 * @code{AIMAG}: AIMAG, Imaginary part of complex number
55 * @code{AINT}: AINT, Truncate to a whole number
56 * @code{ALARM}: ALARM, Set an alarm clock
57 * @code{ALL}: ALL, Determine if all values are true
58 * @code{ALLOCATED}: ALLOCATED, Status of allocatable entity
59 * @code{AND}: AND, Bitwise logical AND
60 * @code{ANINT}: ANINT, Nearest whole number
61 * @code{ANY}: ANY, Determine if any values are true
62 * @code{ASIN}: ASIN, Arcsine function
63 * @code{ASIND}: ASIND, Arcsine function, degrees
64 * @code{ASINH}: ASINH, Inverse hyperbolic sine function
65 * @code{ASSOCIATED}: ASSOCIATED, Status of a pointer or pointer/target pair
66 * @code{ATAN}: ATAN, Arctangent function
67 * @code{ATAND}: ATAND, Arctangent function, degrees
68 * @code{ATAN2}: ATAN2, Arctangent function
69 * @code{ATAN2D}: ATAN2D, Arctangent function, degrees
70 * @code{ATANH}: ATANH, Inverse hyperbolic tangent function
71 * @code{ATOMIC_ADD}: ATOMIC_ADD, Atomic ADD operation
72 * @code{ATOMIC_AND}: ATOMIC_AND, Atomic bitwise AND operation
73 * @code{ATOMIC_CAS}: ATOMIC_CAS, Atomic compare and swap
74 * @code{ATOMIC_DEFINE}: ATOMIC_DEFINE, Setting a variable atomically
75 * @code{ATOMIC_FETCH_ADD}: ATOMIC_FETCH_ADD, Atomic ADD operation with prior fetch
76 * @code{ATOMIC_FETCH_AND}: ATOMIC_FETCH_AND, Atomic bitwise AND operation with prior fetch
77 * @code{ATOMIC_FETCH_OR}: ATOMIC_FETCH_OR, Atomic bitwise OR operation with prior fetch
78 * @code{ATOMIC_FETCH_XOR}: ATOMIC_FETCH_XOR, Atomic bitwise XOR operation with prior fetch
79 * @code{ATOMIC_OR}: ATOMIC_OR, Atomic bitwise OR operation
80 * @code{ATOMIC_REF}: ATOMIC_REF, Obtaining the value of a variable atomically
81 * @code{ATOMIC_XOR}: ATOMIC_XOR, Atomic bitwise OR operation
82 * @code{BACKTRACE}: BACKTRACE, Show a backtrace
83 * @code{BESSEL_J0}: BESSEL_J0, Bessel function of the first kind of order 0
84 * @code{BESSEL_J1}: BESSEL_J1, Bessel function of the first kind of order 1
85 * @code{BESSEL_JN}: BESSEL_JN, Bessel function of the first kind
86 * @code{BESSEL_Y0}: BESSEL_Y0, Bessel function of the second kind of order 0
87 * @code{BESSEL_Y1}: BESSEL_Y1, Bessel function of the second kind of order 1
88 * @code{BESSEL_YN}: BESSEL_YN, Bessel function of the second kind
89 * @code{BGE}: BGE, Bitwise greater than or equal to
90 * @code{BGT}: BGT, Bitwise greater than
91 * @code{BIT_SIZE}: BIT_SIZE, Bit size inquiry function
92 * @code{BLE}: BLE, Bitwise less than or equal to
93 * @code{BLT}: BLT, Bitwise less than
94 * @code{BTEST}: BTEST, Bit test function
95 * @code{C_ASSOCIATED}: C_ASSOCIATED, Status of a C pointer
96 * @code{C_F_POINTER}: C_F_POINTER, Convert C into Fortran pointer
97 * @code{C_F_PROCPOINTER}: C_F_PROCPOINTER, Convert C into Fortran procedure pointer
98 * @code{C_FUNLOC}: C_FUNLOC, Obtain the C address of a procedure
99 * @code{C_LOC}: C_LOC, Obtain the C address of an object
100 * @code{C_SIZEOF}: C_SIZEOF, Size in bytes of an expression
101 * @code{CEILING}: CEILING, Integer ceiling function
102 * @code{CHAR}: CHAR, Integer-to-character conversion function
103 * @code{CHDIR}: CHDIR, Change working directory
104 * @code{CHMOD}: CHMOD, Change access permissions of files
105 * @code{CMPLX}: CMPLX, Complex conversion function
106 * @code{CO_BROADCAST}: CO_BROADCAST, Copy a value to all images the current set of images
107 * @code{CO_MAX}: CO_MAX, Maximal value on the current set of images
108 * @code{CO_MIN}: CO_MIN, Minimal value on the current set of images
109 * @code{CO_REDUCE}: CO_REDUCE, Reduction of values on the current set of images
110 * @code{CO_SUM}: CO_SUM, Sum of values on the current set of images
111 * @code{COMMAND_ARGUMENT_COUNT}: COMMAND_ARGUMENT_COUNT, Get number of command line arguments
112 * @code{COMPILER_OPTIONS}: COMPILER_OPTIONS, Options passed to the compiler
113 * @code{COMPILER_VERSION}: COMPILER_VERSION, Compiler version string
114 * @code{COMPLEX}: COMPLEX, Complex conversion function
115 * @code{CONJG}: CONJG, Complex conjugate function
116 * @code{COS}: COS, Cosine function
117 * @code{COSD}: COSD, Cosine function, degrees
118 * @code{COSH}: COSH, Hyperbolic cosine function
119 * @code{COTAN}: COTAN, Cotangent function
120 * @code{COTAND}: COTAND, Cotangent function, degrees
121 * @code{COUNT}: COUNT, Count occurrences of TRUE in an array
122 * @code{CPU_TIME}: CPU_TIME, CPU time subroutine
123 * @code{CSHIFT}: CSHIFT, Circular shift elements of an array
124 * @code{CTIME}: CTIME, Subroutine (or function) to convert a time into a string
125 * @code{DATE_AND_TIME}: DATE_AND_TIME, Date and time subroutine
126 * @code{DBLE}: DBLE, Double precision conversion function
127 * @code{DCMPLX}: DCMPLX, Double complex conversion function
128 * @code{DIGITS}: DIGITS, Significant digits function
129 * @code{DIM}: DIM, Positive difference
130 * @code{DOT_PRODUCT}: DOT_PRODUCT, Dot product function
131 * @code{DPROD}: DPROD, Double product function
132 * @code{DREAL}: DREAL, Double real part function
133 * @code{DSHIFTL}: DSHIFTL, Combined left shift
134 * @code{DSHIFTR}: DSHIFTR, Combined right shift
135 * @code{DTIME}: DTIME, Execution time subroutine (or function)
136 * @code{EOSHIFT}: EOSHIFT, End-off shift elements of an array
137 * @code{EPSILON}: EPSILON, Epsilon function
138 * @code{ERF}: ERF, Error function
139 * @code{ERFC}: ERFC, Complementary error function
140 * @code{ERFC_SCALED}: ERFC_SCALED, Exponentially-scaled complementary error function
141 * @code{ETIME}: ETIME, Execution time subroutine (or function)
142 * @code{EVENT_QUERY}: EVENT_QUERY, Query whether a coarray event has occurred
143 * @code{EXECUTE_COMMAND_LINE}: EXECUTE_COMMAND_LINE, Execute a shell command
144 * @code{EXIT}: EXIT, Exit the program with status.
145 * @code{EXP}: EXP, Exponential function
146 * @code{EXPONENT}: EXPONENT, Exponent function
147 * @code{EXTENDS_TYPE_OF}: EXTENDS_TYPE_OF, Query dynamic type for extension
148 * @code{FDATE}: FDATE, Subroutine (or function) to get the current time as a string
149 * @code{FGET}: FGET, Read a single character in stream mode from stdin
150 * @code{FGETC}: FGETC, Read a single character in stream mode
151 * @code{FINDLOC}: FINDLOC, Search an array for a value
152 * @code{FLOOR}: FLOOR, Integer floor function
153 * @code{FLUSH}: FLUSH, Flush I/O unit(s)
154 * @code{FNUM}: FNUM, File number function
155 * @code{FPUT}: FPUT, Write a single character in stream mode to stdout
156 * @code{FPUTC}: FPUTC, Write a single character in stream mode
157 * @code{FRACTION}: FRACTION, Fractional part of the model representation
158 * @code{FREE}: FREE, Memory de-allocation subroutine
159 * @code{FSEEK}: FSEEK, Low level file positioning subroutine
160 * @code{FSTAT}: FSTAT, Get file status
161 * @code{FTELL}: FTELL, Current stream position
162 * @code{GAMMA}: GAMMA, Gamma function
163 * @code{GERROR}: GERROR, Get last system error message
164 * @code{GETARG}: GETARG, Get command line arguments
165 * @code{GET_COMMAND}: GET_COMMAND, Get the entire command line
166 * @code{GET_COMMAND_ARGUMENT}: GET_COMMAND_ARGUMENT, Get command line arguments
167 * @code{GETCWD}: GETCWD, Get current working directory
168 * @code{GETENV}: GETENV, Get an environmental variable
169 * @code{GET_ENVIRONMENT_VARIABLE}: GET_ENVIRONMENT_VARIABLE, Get an environmental variable
170 * @code{GETGID}: GETGID, Group ID function
171 * @code{GETLOG}: GETLOG, Get login name
172 * @code{GETPID}: GETPID, Process ID function
173 * @code{GETUID}: GETUID, User ID function
174 * @code{GMTIME}: GMTIME, Convert time to GMT info
175 * @code{HOSTNM}: HOSTNM, Get system host name
176 * @code{HUGE}: HUGE, Largest number of a kind
177 * @code{HYPOT}: HYPOT, Euclidean distance function
178 * @code{IACHAR}: IACHAR, Code in @acronym{ASCII} collating sequence
179 * @code{IALL}: IALL, Bitwise AND of array elements
180 * @code{IAND}: IAND, Bitwise logical and
181 * @code{IANY}: IANY, Bitwise OR of array elements
182 * @code{IARGC}: IARGC, Get the number of command line arguments
183 * @code{IBCLR}: IBCLR, Clear bit
184 * @code{IBITS}: IBITS, Bit extraction
185 * @code{IBSET}: IBSET, Set bit
186 * @code{ICHAR}: ICHAR, Character-to-integer conversion function
187 * @code{IDATE}: IDATE, Current local time (day/month/year)
188 * @code{IEOR}: IEOR, Bitwise logical exclusive or
189 * @code{IERRNO}: IERRNO, Function to get the last system error number
190 * @code{IMAGE_INDEX}: IMAGE_INDEX, Cosubscript to image index conversion
191 * @code{INDEX}: INDEX intrinsic, Position of a substring within a string
192 * @code{INT}: INT, Convert to integer type
193 * @code{INT2}: INT2, Convert to 16-bit integer type
194 * @code{INT8}: INT8, Convert to 64-bit integer type
195 * @code{IOR}: IOR, Bitwise logical or
196 * @code{IPARITY}: IPARITY, Bitwise XOR of array elements
197 * @code{IRAND}: IRAND, Integer pseudo-random number
198 * @code{IS_CONTIGUOUS}: IS_CONTIGUOUS, Test whether an array is contiguous
199 * @code{IS_IOSTAT_END}: IS_IOSTAT_END, Test for end-of-file value
200 * @code{IS_IOSTAT_EOR}: IS_IOSTAT_EOR, Test for end-of-record value
201 * @code{ISATTY}: ISATTY, Whether a unit is a terminal device
202 * @code{ISHFT}: ISHFT, Shift bits
203 * @code{ISHFTC}: ISHFTC, Shift bits circularly
204 * @code{ISNAN}: ISNAN, Tests for a NaN
205 * @code{ITIME}: ITIME, Current local time (hour/minutes/seconds)
206 * @code{KILL}: KILL, Send a signal to a process
207 * @code{KIND}: KIND, Kind of an entity
208 * @code{LBOUND}: LBOUND, Lower dimension bounds of an array
209 * @code{LCOBOUND}: LCOBOUND, Lower codimension bounds of an array
210 * @code{LEADZ}: LEADZ, Number of leading zero bits of an integer
211 * @code{LEN}: LEN, Length of a character entity
212 * @code{LEN_TRIM}: LEN_TRIM, Length of a character entity without trailing blank characters
213 * @code{LGE}: LGE, Lexical greater than or equal
214 * @code{LGT}: LGT, Lexical greater than
215 * @code{LINK}: LINK, Create a hard link
216 * @code{LLE}: LLE, Lexical less than or equal
217 * @code{LLT}: LLT, Lexical less than
218 * @code{LNBLNK}: LNBLNK, Index of the last non-blank character in a string
219 * @code{LOC}: LOC, Returns the address of a variable
220 * @code{LOG}: LOG, Logarithm function
221 * @code{LOG10}: LOG10, Base 10 logarithm function
222 * @code{LOG_GAMMA}: LOG_GAMMA, Logarithm of the Gamma function
223 * @code{LOGICAL}: LOGICAL, Convert to logical type
224 * @code{LSHIFT}: LSHIFT, Left shift bits
225 * @code{LSTAT}: LSTAT, Get file status
226 * @code{LTIME}: LTIME, Convert time to local time info
227 * @code{MALLOC}: MALLOC, Dynamic memory allocation function
228 * @code{MASKL}: MASKL, Left justified mask
229 * @code{MASKR}: MASKR, Right justified mask
230 * @code{MATMUL}: MATMUL, matrix multiplication
231 * @code{MAX}: MAX, Maximum value of an argument list
232 * @code{MAXEXPONENT}: MAXEXPONENT, Maximum exponent of a real kind
233 * @code{MAXLOC}: MAXLOC, Location of the maximum value within an array
234 * @code{MAXVAL}: MAXVAL, Maximum value of an array
235 * @code{MCLOCK}: MCLOCK, Time function
236 * @code{MCLOCK8}: MCLOCK8, Time function (64-bit)
237 * @code{MERGE}: MERGE, Merge arrays
238 * @code{MERGE_BITS}: MERGE_BITS, Merge of bits under mask
239 * @code{MIN}: MIN, Minimum value of an argument list
240 * @code{MINEXPONENT}: MINEXPONENT, Minimum exponent of a real kind
241 * @code{MINLOC}: MINLOC, Location of the minimum value within an array
242 * @code{MINVAL}: MINVAL, Minimum value of an array
243 * @code{MOD}: MOD, Remainder function
244 * @code{MODULO}: MODULO, Modulo function
245 * @code{MOVE_ALLOC}: MOVE_ALLOC, Move allocation from one object to another
246 * @code{MVBITS}: MVBITS, Move bits from one integer to another
247 * @code{NEAREST}: NEAREST, Nearest representable number
248 * @code{NEW_LINE}: NEW_LINE, New line character
249 * @code{NINT}: NINT, Nearest whole number
250 * @code{NORM2}: NORM2, Euclidean vector norm
251 * @code{NOT}: NOT, Logical negation
252 * @code{NULL}: NULL, Function that returns an disassociated pointer
253 * @code{NUM_IMAGES}: NUM_IMAGES, Number of images
254 * @code{OR}: OR, Bitwise logical OR
255 * @code{PACK}: PACK, Pack an array into an array of rank one
256 * @code{PARITY}: PARITY, Reduction with exclusive OR
257 * @code{PERROR}: PERROR, Print system error message
258 * @code{POPCNT}: POPCNT, Number of bits set
259 * @code{POPPAR}: POPPAR, Parity of the number of bits set
260 * @code{PRECISION}: PRECISION, Decimal precision of a real kind
261 * @code{PRESENT}: PRESENT, Determine whether an optional dummy argument is specified
262 * @code{PRODUCT}: PRODUCT, Product of array elements
263 * @code{RADIX}: RADIX, Base of a data model
264 * @code{RAN}: RAN, Real pseudo-random number
265 * @code{RAND}: RAND, Real pseudo-random number
266 * @code{RANDOM_INIT}: RANDOM_INIT, Initialize pseudo-random number generator
267 * @code{RANDOM_NUMBER}: RANDOM_NUMBER, Pseudo-random number
268 * @code{RANDOM_SEED}: RANDOM_SEED, Initialize a pseudo-random number sequence
269 * @code{RANGE}: RANGE, Decimal exponent range
270 * @code{RANK} : RANK, Rank of a data object
271 * @code{REAL}: REAL, Convert to real type
272 * @code{RENAME}: RENAME, Rename a file
273 * @code{REPEAT}: REPEAT, Repeated string concatenation
274 * @code{RESHAPE}: RESHAPE, Function to reshape an array
275 * @code{RRSPACING}: RRSPACING, Reciprocal of the relative spacing
276 * @code{RSHIFT}: RSHIFT, Right shift bits
277 * @code{SAME_TYPE_AS}: SAME_TYPE_AS, Query dynamic types for equality
278 * @code{SCALE}: SCALE, Scale a real value
279 * @code{SCAN}: SCAN, Scan a string for the presence of a set of characters
280 * @code{SECNDS}: SECNDS, Time function
281 * @code{SECOND}: SECOND, CPU time function
282 * @code{SELECTED_CHAR_KIND}: SELECTED_CHAR_KIND, Choose character kind
283 * @code{SELECTED_INT_KIND}: SELECTED_INT_KIND, Choose integer kind
284 * @code{SELECTED_LOGICAL_KIND}: SELECTED_LOGICAL_KIND, Choose logical kind
285 * @code{SELECTED_REAL_KIND}: SELECTED_REAL_KIND, Choose real kind
286 * @code{SET_EXPONENT}: SET_EXPONENT, Set the exponent of the model
287 * @code{SHAPE}: SHAPE, Determine the shape of an array
288 * @code{SHIFTA}: SHIFTA, Right shift with fill
289 * @code{SHIFTL}: SHIFTL, Left shift
290 * @code{SHIFTR}: SHIFTR, Right shift
291 * @code{SIGN}: SIGN, Sign copying function
292 * @code{SIGNAL}: SIGNAL, Signal handling subroutine (or function)
293 * @code{SIN}: SIN, Sine function
294 * @code{SIND}: SIND, Sine function, degrees
295 * @code{SINH}: SINH, Hyperbolic sine function
296 * @code{SIZE}: SIZE, Function to determine the size of an array
297 * @code{SIZEOF}: SIZEOF, Determine the size in bytes of an expression
298 * @code{SLEEP}: SLEEP, Sleep for the specified number of seconds
299 * @code{SPACING}: SPACING, Smallest distance between two numbers of a given type
300 * @code{SPREAD}: SPREAD, Add a dimension to an array
301 * @code{SQRT}: SQRT, Square-root function
302 * @code{SRAND}: SRAND, Reinitialize the random number generator
303 * @code{STAT}: STAT, Get file status
304 * @code{STORAGE_SIZE}: STORAGE_SIZE, Storage size in bits
305 * @code{SUM}: SUM, Sum of array elements
306 * @code{SYMLNK}: SYMLNK, Create a symbolic link
307 * @code{SYSTEM}: SYSTEM, Execute a shell command
308 * @code{SYSTEM_CLOCK}: SYSTEM_CLOCK, Time function
309 * @code{TAN}: TAN, Tangent function
310 * @code{TAND}: TAND, Tangent function, degrees
311 * @code{TANH}: TANH, Hyperbolic tangent function
312 * @code{THIS_IMAGE}: THIS_IMAGE, Cosubscript index of this image
313 * @code{TIME}: TIME, Time function
314 * @code{TIME8}: TIME8, Time function (64-bit)
315 * @code{TINY}: TINY, Smallest positive number of a real kind
316 * @code{TRAILZ}: TRAILZ, Number of trailing zero bits of an integer
317 * @code{TRANSFER}: TRANSFER, Transfer bit patterns
318 * @code{TRANSPOSE}: TRANSPOSE, Transpose an array of rank two
319 * @code{TRIM}: TRIM, Remove trailing blank characters of a string
320 * @code{TTYNAM}: TTYNAM, Get the name of a terminal device
321 * @code{UBOUND}: UBOUND, Upper dimension bounds of an array
322 * @code{UCOBOUND}: UCOBOUND, Upper codimension bounds of an array
323 * @code{UMASK}: UMASK, Set the file creation mask
324 * @code{UNLINK}: UNLINK, Remove a file from the file system
325 * @code{UNPACK}: UNPACK, Unpack an array of rank one into an array
326 * @code{VERIFY}: VERIFY, Scan a string for the absence of a set of characters
327 * @code{XOR}: XOR, Bitwise logical exclusive or
330 @node Introduction to Intrinsics
331 @section Introduction to intrinsic procedures
333 The intrinsic procedures provided by GNU Fortran include procedures required
334 by the Fortran 95 and later supported standards, and a set of intrinsic
335 procedures for backwards compatibility with G77. Any conflict between
336 a description here and a description in the Fortran standards is
337 unintentional, and the standard(s) should be considered authoritative.
339 The enumeration of the @code{KIND} type parameter is processor defined in
340 the Fortran 95 standard. GNU Fortran defines the default integer type and
341 default real type by @code{INTEGER(KIND=4)} and @code{REAL(KIND=4)},
342 respectively. The standard mandates that both data types shall have
343 another kind, which have more precision. On typical target architectures
344 supported by @command{gfortran}, this kind type parameter is @code{KIND=8}.
345 Hence, @code{REAL(KIND=8)} and @code{DOUBLE PRECISION} are equivalent.
346 In the description of generic intrinsic procedures, the kind type parameter
347 will be specified by @code{KIND=*}, and in the description of specific
348 names for an intrinsic procedure the kind type parameter will be explicitly
349 given (e.g., @code{REAL(KIND=4)} or @code{REAL(KIND=8)}). Finally, for
350 brevity the optional @code{KIND=} syntax will be omitted.
352 Many of the intrinsic procedures take one or more optional arguments.
353 This document follows the convention used in the Fortran 95 standard,
354 and denotes such arguments by square brackets.
356 GNU Fortran offers the @option{-std=} command-line option,
357 which can be used to restrict the set of intrinsic procedures to a
358 given standard. By default, @command{gfortran} sets the @option{-std=gnu}
359 option, and so all intrinsic procedures described here are accepted. There
360 is one caveat. For a select group of intrinsic procedures, @command{g77}
361 implemented both a function and a subroutine. Both classes
362 have been implemented in @command{gfortran} for backwards compatibility
363 with @command{g77}. It is noted here that these functions and subroutines
364 cannot be intermixed in a given subprogram. In the descriptions that follow,
365 the applicable standard for each intrinsic procedure is noted.
370 @section @code{ABORT} --- Abort the program
372 @cindex program termination, with core dump
373 @cindex terminate program, with core dump
377 @item @emph{Description}:
378 @code{ABORT} causes immediate termination of the program. On operating
379 systems that support a core dump, @code{ABORT} will produce a core dump.
380 It will also print a backtrace, unless @code{-fno-backtrace} is given.
382 @item @emph{Standard}:
391 @item @emph{Return value}:
394 @item @emph{Example}:
397 integer :: i = 1, j = 2
398 if (i /= j) call abort
399 end program test_abort
402 @item @emph{See also}:
411 @section @code{ABS} --- Absolute value
422 @cindex absolute value
425 @item @emph{Description}:
426 @code{ABS(A)} computes the absolute value of @code{A}.
428 @item @emph{Standard}:
429 Fortran 77 and later, has overloads that are GNU extensions
435 @code{RESULT = ABS(A)}
437 @item @emph{Arguments}:
438 @multitable @columnfractions .15 .70
439 @item @var{A} @tab The type of the argument shall be an @code{INTEGER},
440 @code{REAL}, or @code{COMPLEX}.
443 @item @emph{Return value}:
444 The return value is of the same type and
445 kind as the argument except the return value is @code{REAL} for a
446 @code{COMPLEX} argument.
448 @item @emph{Example}:
453 complex :: z = (-1.e0,0.e0)
460 @item @emph{Specific names}:
461 @multitable @columnfractions .20 .23 .20 .33
462 @headitem Name @tab Argument @tab Return type @tab Standard
463 @item @code{ABS(A)} @tab @code{REAL(4) A} @tab @code{REAL(4)} @tab Fortran 77 and later
464 @item @code{CABS(A)} @tab @code{COMPLEX(4) A} @tab @code{REAL(4)} @tab Fortran 77 and later
465 @item @code{DABS(A)} @tab @code{REAL(8) A} @tab @code{REAL(8)} @tab Fortran 77 and later
466 @item @code{IABS(A)} @tab @code{INTEGER(4) A} @tab @code{INTEGER(4)} @tab Fortran 77 and later
467 @item @code{BABS(A)} @tab @code{INTEGER(1) A} @tab @code{INTEGER(1)} @tab GNU extension
468 @item @code{IIABS(A)} @tab @code{INTEGER(2) A} @tab @code{INTEGER(2)} @tab GNU extension
469 @item @code{JIABS(A)} @tab @code{INTEGER(4) A} @tab @code{INTEGER(4)} @tab GNU extension
470 @item @code{KIABS(A)} @tab @code{INTEGER(8) A} @tab @code{INTEGER(8)} @tab GNU extension
471 @item @code{ZABS(A)} @tab @code{COMPLEX(8) A} @tab @code{REAL(8)} @tab GNU extension
472 @item @code{CDABS(A)} @tab @code{COMPLEX(8) A} @tab @code{REAL(8)} @tab GNU extension
479 @section @code{ACCESS} --- Checks file access modes
481 @cindex file system, access mode
484 @item @emph{Description}:
485 @code{ACCESS(NAME, MODE)} checks whether the file @var{NAME}
486 exists, is readable, writable or executable. Except for the
487 executable check, @code{ACCESS} can be replaced by
488 Fortran 95's @code{INQUIRE}.
490 @item @emph{Standard}:
497 @code{RESULT = ACCESS(NAME, MODE)}
499 @item @emph{Arguments}:
500 @multitable @columnfractions .15 .70
501 @item @var{NAME} @tab Scalar @code{CHARACTER} of default kind with the
502 file name. Trailing blank are ignored unless the character @code{achar(0)}
503 is present, then all characters up to and excluding @code{achar(0)} are
505 @item @var{MODE} @tab Scalar @code{CHARACTER} of default kind with the
506 file access mode, may be any concatenation of @code{"r"} (readable),
507 @code{"w"} (writable) and @code{"x"} (executable), or @code{" "} to check
511 @item @emph{Return value}:
512 Returns a scalar @code{INTEGER}, which is @code{0} if the file is
513 accessible in the given mode; otherwise or if an invalid argument
514 has been given for @code{MODE} the value @code{1} is returned.
516 @item @emph{Example}:
520 character(len=*), parameter :: file = 'test.dat'
521 character(len=*), parameter :: file2 = 'test.dat '//achar(0)
522 if(access(file,' ') == 0) print *, trim(file),' is exists'
523 if(access(file,'r') == 0) print *, trim(file),' is readable'
524 if(access(file,'w') == 0) print *, trim(file),' is writable'
525 if(access(file,'x') == 0) print *, trim(file),' is executable'
526 if(access(file2,'rwx') == 0) &
527 print *, trim(file2),' is readable, writable and executable'
528 end program access_test
535 @section @code{ACHAR} --- Character in @acronym{ASCII} collating sequence
537 @cindex @acronym{ASCII} collating sequence
538 @cindex collating sequence, @acronym{ASCII}
541 @item @emph{Description}:
542 @code{ACHAR(I)} returns the character located at position @code{I}
543 in the @acronym{ASCII} collating sequence.
545 @item @emph{Standard}:
546 Fortran 77 and later, with @var{KIND} argument Fortran 2003 and later
552 @code{RESULT = ACHAR(I [, KIND])}
554 @item @emph{Arguments}:
555 @multitable @columnfractions .15 .70
556 @item @var{I} @tab The type shall be @code{INTEGER}.
557 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
558 expression indicating the kind parameter of the result.
561 @item @emph{Return value}:
562 The return value is of type @code{CHARACTER} with a length of one.
563 If the @var{KIND} argument is present, the return value is of the
564 specified kind and of the default kind otherwise.
566 @item @emph{Example}:
571 end program test_achar
575 See @ref{ICHAR} for a discussion of converting between numerical values
576 and formatted string representations.
578 @item @emph{See also}:
587 @section @code{ACOS} --- Arccosine function
590 @cindex trigonometric function, cosine, inverse
591 @cindex cosine, inverse
594 @item @emph{Description}:
595 @code{ACOS(X)} computes the arccosine of @var{X} (inverse of @code{COS(X)}).
597 @item @emph{Standard}:
598 Fortran 77 and later, for a complex argument Fortran 2008 or later
604 @code{RESULT = ACOS(X)}
606 @item @emph{Arguments}:
607 @multitable @columnfractions .15 .70
608 @item @var{X} @tab The type shall either be @code{REAL} with a magnitude that is
609 less than or equal to one - or the type shall be @code{COMPLEX}.
612 @item @emph{Return value}:
613 The return value is of the same type and kind as @var{X}.
614 The real part of the result is in radians and lies in the range
615 @math{0 \leq \Re \acos(x) \leq \pi}.
617 @item @emph{Example}:
620 real(8) :: x = 0.866_8
622 end program test_acos
625 @item @emph{Specific names}:
626 @multitable @columnfractions .20 .23 .20 .33
627 @headitem Name @tab Argument @tab Return type @tab Standard
628 @item @code{ACOS(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
629 @item @code{DACOS(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
632 @item @emph{See also}:
642 @section @code{ACOSD} --- Arccosine function, degrees
645 @cindex trigonometric function, cosine, inverse, degrees
646 @cindex cosine, inverse, degrees
649 @item @emph{Description}:
650 @code{ACOSD(X)} computes the arccosine of @var{X} in degrees (inverse of
653 @item @emph{Standard}:
660 @code{RESULT = ACOSD(X)}
662 @item @emph{Arguments}:
663 @multitable @columnfractions .15 .70
664 @item @var{X} @tab The type shall either be @code{REAL} with a magnitude that is
665 less than or equal to one.
668 @item @emph{Return value}:
669 The return value is of the same type and kind as @var{X}.
670 The real part of the result is in degrees and lies in the range
671 @math{0 \leq \Re \acos(x) \leq 180}.
673 @item @emph{Example}:
676 real(8) :: x = 0.866_8
678 end program test_acosd
681 @item @emph{Specific names}:
682 @multitable @columnfractions .20 .23 .20 .33
683 @headitem Name @tab Argument @tab Return type @tab Standard
684 @item @code{ACOSD(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 2023
685 @item @code{DACOSD(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
688 @item @emph{See also}:
698 @section @code{ACOSH} --- Inverse hyperbolic cosine function
701 @cindex area hyperbolic cosine
702 @cindex inverse hyperbolic cosine
703 @cindex hyperbolic function, cosine, inverse
704 @cindex cosine, hyperbolic, inverse
707 @item @emph{Description}:
708 @code{ACOSH(X)} computes the inverse hyperbolic cosine of @var{X}.
710 @item @emph{Standard}:
711 Fortran 2008 and later
717 @code{RESULT = ACOSH(X)}
719 @item @emph{Arguments}:
720 @multitable @columnfractions .15 .70
721 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
724 @item @emph{Return value}:
725 The return value has the same type and kind as @var{X}. If @var{X} is
726 complex, the imaginary part of the result is in radians and lies between
727 @math{ 0 \leq \Im \acosh(x) \leq \pi}.
729 @item @emph{Example}:
732 REAL(8), DIMENSION(3) :: x = (/ 1.0, 2.0, 3.0 /)
737 @item @emph{Specific names}:
738 @multitable @columnfractions .20 .23 .20 .33
739 @headitem Name @tab Argument @tab Return type @tab Standard
740 @item @code{DACOSH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
743 @item @emph{See also}:
751 @section @code{ADJUSTL} --- Left adjust a string
753 @cindex string, adjust left
754 @cindex adjust string
757 @item @emph{Description}:
758 @code{ADJUSTL(STRING)} will left adjust a string by removing leading spaces.
759 Spaces are inserted at the end of the string as needed.
761 @item @emph{Standard}:
768 @code{RESULT = ADJUSTL(STRING)}
770 @item @emph{Arguments}:
771 @multitable @columnfractions .15 .70
772 @item @var{STRING} @tab The type shall be @code{CHARACTER}.
775 @item @emph{Return value}:
776 The return value is of type @code{CHARACTER} and of the same kind as
777 @var{STRING} where leading spaces are removed and the same number of
778 spaces are inserted on the end of @var{STRING}.
780 @item @emph{Example}:
783 character(len=20) :: str = ' gfortran'
786 end program test_adjustl
789 @item @emph{See also}:
797 @section @code{ADJUSTR} --- Right adjust a string
799 @cindex string, adjust right
800 @cindex adjust string
803 @item @emph{Description}:
804 @code{ADJUSTR(STRING)} will right adjust a string by removing trailing spaces.
805 Spaces are inserted at the start of the string as needed.
807 @item @emph{Standard}:
814 @code{RESULT = ADJUSTR(STRING)}
816 @item @emph{Arguments}:
817 @multitable @columnfractions .15 .70
818 @item @var{STR} @tab The type shall be @code{CHARACTER}.
821 @item @emph{Return value}:
822 The return value is of type @code{CHARACTER} and of the same kind as
823 @var{STRING} where trailing spaces are removed and the same number of
824 spaces are inserted at the start of @var{STRING}.
826 @item @emph{Example}:
829 character(len=20) :: str = 'gfortran'
832 end program test_adjustr
835 @item @emph{See also}:
843 @section @code{AIMAG} --- Imaginary part of complex number
848 @cindex complex numbers, imaginary part
851 @item @emph{Description}:
852 @code{AIMAG(Z)} yields the imaginary part of complex argument @code{Z}.
853 The @code{IMAG(Z)} and @code{IMAGPART(Z)} intrinsic functions are provided
854 for compatibility with @command{g77}, and their use in new code is
855 strongly discouraged.
857 @item @emph{Standard}:
858 Fortran 77 and later, has overloads that are GNU extensions
864 @code{RESULT = AIMAG(Z)}
866 @item @emph{Arguments}:
867 @multitable @columnfractions .15 .70
868 @item @var{Z} @tab The type of the argument shall be @code{COMPLEX}.
871 @item @emph{Return value}:
872 The return value is of type @code{REAL} with the
873 kind type parameter of the argument.
875 @item @emph{Example}:
880 z4 = cmplx(1.e0_4, 0.e0_4)
881 z8 = cmplx(0.e0_8, 1.e0_8)
882 print *, aimag(z4), dimag(z8)
883 end program test_aimag
886 @item @emph{Specific names}:
887 @multitable @columnfractions .20 .23 .20 .33
888 @headitem Name @tab Argument @tab Return type @tab Standard
889 @item @code{AIMAG(Z)} @tab @code{COMPLEX Z} @tab @code{REAL} @tab Fortran 77 and later
890 @item @code{DIMAG(Z)} @tab @code{COMPLEX(8) Z} @tab @code{REAL(8)} @tab GNU extension
891 @item @code{IMAG(Z)} @tab @code{COMPLEX Z} @tab @code{REAL} @tab GNU extension
892 @item @code{IMAGPART(Z)} @tab @code{COMPLEX Z} @tab @code{REAL} @tab GNU extension
899 @section @code{AINT} --- Truncate to a whole number
903 @cindex rounding, floor
906 @item @emph{Description}:
907 @code{AINT(A [, KIND])} truncates its argument to a whole number.
909 @item @emph{Standard}:
916 @code{RESULT = AINT(A [, KIND])}
918 @item @emph{Arguments}:
919 @multitable @columnfractions .15 .70
920 @item @var{A} @tab The type of the argument shall be @code{REAL}.
921 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
922 expression indicating the kind parameter of the result.
925 @item @emph{Return value}:
926 The return value is of type @code{REAL} with the kind type parameter of the
927 argument if the optional @var{KIND} is absent; otherwise, the kind
928 type parameter will be given by @var{KIND}. If the magnitude of
929 @var{X} is less than one, @code{AINT(X)} returns zero. If the
930 magnitude is equal to or greater than one then it returns the largest
931 whole number that does not exceed its magnitude. The sign is the same
932 as the sign of @var{X}.
934 @item @emph{Example}:
941 print *, aint(x4), dint(x8)
943 end program test_aint
946 @item @emph{Specific names}:
947 @multitable @columnfractions .20 .23 .20 .33
948 @headitem Name @tab Argument @tab Return type @tab Standard
949 @item @code{AINT(A)} @tab @code{REAL(4) A} @tab @code{REAL(4)} @tab Fortran 77 and later
950 @item @code{DINT(A)} @tab @code{REAL(8) A} @tab @code{REAL(8)} @tab Fortran 77 and later
957 @section @code{ALARM} --- Execute a routine after a given delay
959 @cindex delayed execution
962 @item @emph{Description}:
963 @code{ALARM(SECONDS, HANDLER [, STATUS])} causes external subroutine @var{HANDLER}
964 to be executed after a delay of @var{SECONDS} by using @code{alarm(2)} to
965 set up a signal and @code{signal(2)} to catch it. If @var{STATUS} is
966 supplied, it will be returned with the number of seconds remaining until
967 any previously scheduled alarm was due to be delivered, or zero if there
968 was no previously scheduled alarm.
970 @item @emph{Standard}:
977 @code{CALL ALARM(SECONDS, HANDLER [, STATUS])}
979 @item @emph{Arguments}:
980 @multitable @columnfractions .15 .70
981 @item @var{SECONDS} @tab The type of the argument shall be a scalar
982 @code{INTEGER}. It is @code{INTENT(IN)}.
983 @item @var{HANDLER} @tab Signal handler (@code{INTEGER FUNCTION} or
984 @code{SUBROUTINE}) or dummy/global @code{INTEGER} scalar. The scalar
985 values may be either @code{SIG_IGN=1} to ignore the alarm generated
986 or @code{SIG_DFL=0} to set the default action. It is @code{INTENT(IN)}.
987 @item @var{STATUS} @tab (Optional) @var{STATUS} shall be a scalar
988 variable of the default @code{INTEGER} kind. It is @code{INTENT(OUT)}.
991 @item @emph{Example}:
994 external handler_print
996 call alarm (3, handler_print, i)
999 end program test_alarm
1001 This will cause the external routine @var{handler_print} to be called
1008 @section @code{ALL} --- All values in @var{MASK} along @var{DIM} are true
1010 @cindex array, apply condition
1011 @cindex array, condition testing
1014 @item @emph{Description}:
1015 @code{ALL(MASK [, DIM])} determines if all the values are true in @var{MASK}
1016 in the array along dimension @var{DIM}.
1018 @item @emph{Standard}:
1019 Fortran 90 and later
1022 Transformational function
1024 @item @emph{Syntax}:
1025 @code{RESULT = ALL(MASK [, DIM])}
1027 @item @emph{Arguments}:
1028 @multitable @columnfractions .15 .70
1029 @item @var{MASK} @tab The type of the argument shall be @code{LOGICAL} and
1030 it shall not be scalar.
1031 @item @var{DIM} @tab (Optional) @var{DIM} shall be a scalar integer
1032 with a value that lies between one and the rank of @var{MASK}.
1035 @item @emph{Return value}:
1036 @code{ALL(MASK)} returns a scalar value of type @code{LOGICAL} where
1037 the kind type parameter is the same as the kind type parameter of
1038 @var{MASK}. If @var{DIM} is present, then @code{ALL(MASK, DIM)} returns
1039 an array with the rank of @var{MASK} minus 1. The shape is determined from
1040 the shape of @var{MASK} where the @var{DIM} dimension is elided.
1044 @code{ALL(MASK)} is true if all elements of @var{MASK} are true.
1045 It also is true if @var{MASK} has zero size; otherwise, it is false.
1047 If the rank of @var{MASK} is one, then @code{ALL(MASK,DIM)} is equivalent
1048 to @code{ALL(MASK)}. If the rank is greater than one, then @code{ALL(MASK,DIM)}
1049 is determined by applying @code{ALL} to the array sections.
1052 @item @emph{Example}:
1056 l = all((/.true., .true., .true./))
1061 integer a(2,3), b(2,3)
1065 print *, all(a .eq. b, 1)
1066 print *, all(a .eq. b, 2)
1067 end subroutine section
1068 end program test_all
1075 @section @code{ALLOCATED} --- Status of an allocatable entity
1077 @cindex allocation, status
1080 @item @emph{Description}:
1081 @code{ALLOCATED(ARRAY)} and @code{ALLOCATED(SCALAR)} check the allocation
1082 status of @var{ARRAY} and @var{SCALAR}, respectively.
1084 @item @emph{Standard}:
1085 Fortran 90 and later. Note, the @code{SCALAR=} keyword and allocatable
1086 scalar entities are available in Fortran 2003 and later.
1091 @item @emph{Syntax}:
1092 @multitable @columnfractions .80
1093 @item @code{RESULT = ALLOCATED(ARRAY)}
1094 @item @code{RESULT = ALLOCATED(SCALAR)}
1097 @item @emph{Arguments}:
1098 @multitable @columnfractions .15 .70
1099 @item @var{ARRAY} @tab The argument shall be an @code{ALLOCATABLE} array.
1100 @item @var{SCALAR} @tab The argument shall be an @code{ALLOCATABLE} scalar.
1103 @item @emph{Return value}:
1104 The return value is a scalar @code{LOGICAL} with the default logical
1105 kind type parameter. If the argument is allocated, then the result is
1106 @code{.TRUE.}; otherwise, it returns @code{.FALSE.}
1108 @item @emph{Example}:
1110 program test_allocated
1112 real(4), allocatable :: x(:)
1113 if (.not. allocated(x)) allocate(x(i))
1114 end program test_allocated
1121 @section @code{AND} --- Bitwise logical AND
1123 @cindex bitwise logical and
1124 @cindex logical and, bitwise
1127 @item @emph{Description}:
1128 Bitwise logical @code{AND}.
1130 This intrinsic routine is provided for backwards compatibility with
1131 GNU Fortran 77. For integer arguments, programmers should consider
1132 the use of the @ref{IAND} intrinsic defined by the Fortran standard.
1134 @item @emph{Standard}:
1140 @item @emph{Syntax}:
1141 @code{RESULT = AND(I, J)}
1143 @item @emph{Arguments}:
1144 @multitable @columnfractions .15 .70
1145 @item @var{I} @tab The type shall be either a scalar @code{INTEGER}
1146 type or a scalar @code{LOGICAL} type or a boz-literal-constant.
1147 @item @var{J} @tab The type shall be the same as the type of @var{I} or
1148 a boz-literal-constant. @var{I} and @var{J} shall not both be
1149 boz-literal-constants. If either @var{I} or @var{J} is a
1150 boz-literal-constant, then the other argument must be a scalar @code{INTEGER}.
1153 @item @emph{Return value}:
1154 The return type is either a scalar @code{INTEGER} or a scalar
1155 @code{LOGICAL}. If the kind type parameters differ, then the
1156 smaller kind type is implicitly converted to larger kind, and the
1157 return has the larger kind. A boz-literal-constant is
1158 converted to an @code{INTEGER} with the kind type parameter of
1159 the other argument as-if a call to @ref{INT} occurred.
1161 @item @emph{Example}:
1164 LOGICAL :: T = .TRUE., F = .FALSE.
1166 DATA a / Z'F' /, b / Z'3' /
1168 WRITE (*,*) AND(T, T), AND(T, F), AND(F, T), AND(F, F)
1169 WRITE (*,*) AND(a, b)
1173 @item @emph{See also}:
1174 Fortran 95 elemental function: @*
1181 @section @code{ANINT} --- Nearest whole number
1185 @cindex rounding, ceiling
1188 @item @emph{Description}:
1189 @code{ANINT(A [, KIND])} rounds its argument to the nearest whole number.
1191 @item @emph{Standard}:
1192 Fortran 77 and later
1197 @item @emph{Syntax}:
1198 @code{RESULT = ANINT(A [, KIND])}
1200 @item @emph{Arguments}:
1201 @multitable @columnfractions .15 .70
1202 @item @var{A} @tab The type of the argument shall be @code{REAL}.
1203 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
1204 expression indicating the kind parameter of the result.
1207 @item @emph{Return value}:
1208 The return value is of type real with the kind type parameter of the
1209 argument if the optional @var{KIND} is absent; otherwise, the kind
1210 type parameter will be given by @var{KIND}. If @var{A} is greater than
1211 zero, @code{ANINT(A)} returns @code{AINT(X+0.5)}. If @var{A} is
1212 less than or equal to zero then it returns @code{AINT(X-0.5)}.
1214 @item @emph{Example}:
1221 print *, anint(x4), dnint(x8)
1223 end program test_anint
1226 @item @emph{Specific names}:
1227 @multitable @columnfractions .20 .23 .20 .33
1228 @headitem Name @tab Argument @tab Return type @tab Standard
1229 @item @code{ANINT(A)} @tab @code{REAL(4) A} @tab @code{REAL(4)} @tab Fortran 77 and later
1230 @item @code{DNINT(A)} @tab @code{REAL(8) A} @tab @code{REAL(8)} @tab Fortran 77 and later
1237 @section @code{ANY} --- Any value in @var{MASK} along @var{DIM} is true
1239 @cindex array, apply condition
1240 @cindex array, condition testing
1243 @item @emph{Description}:
1244 @code{ANY(MASK [, DIM])} determines if any of the values in the logical array
1245 @var{MASK} along dimension @var{DIM} are @code{.TRUE.}.
1247 @item @emph{Standard}:
1248 Fortran 90 and later
1251 Transformational function
1253 @item @emph{Syntax}:
1254 @code{RESULT = ANY(MASK [, DIM])}
1256 @item @emph{Arguments}:
1257 @multitable @columnfractions .15 .70
1258 @item @var{MASK} @tab The type of the argument shall be @code{LOGICAL} and
1259 it shall not be scalar.
1260 @item @var{DIM} @tab (Optional) @var{DIM} shall be a scalar integer
1261 with a value that lies between one and the rank of @var{MASK}.
1264 @item @emph{Return value}:
1265 @code{ANY(MASK)} returns a scalar value of type @code{LOGICAL} where
1266 the kind type parameter is the same as the kind type parameter of
1267 @var{MASK}. If @var{DIM} is present, then @code{ANY(MASK, DIM)} returns
1268 an array with the rank of @var{MASK} minus 1. The shape is determined from
1269 the shape of @var{MASK} where the @var{DIM} dimension is elided.
1273 @code{ANY(MASK)} is true if any element of @var{MASK} is true;
1274 otherwise, it is false. It also is false if @var{MASK} has zero size.
1276 If the rank of @var{MASK} is one, then @code{ANY(MASK,DIM)} is equivalent
1277 to @code{ANY(MASK)}. If the rank is greater than one, then @code{ANY(MASK,DIM)}
1278 is determined by applying @code{ANY} to the array sections.
1281 @item @emph{Example}:
1285 l = any((/.true., .true., .true./))
1290 integer a(2,3), b(2,3)
1294 print *, any(a .eq. b, 1)
1295 print *, any(a .eq. b, 2)
1296 end subroutine section
1297 end program test_any
1304 @section @code{ASIN} --- Arcsine function
1307 @cindex trigonometric function, sine, inverse
1308 @cindex sine, inverse
1311 @item @emph{Description}:
1312 @code{ASIN(X)} computes the arcsine of its @var{X} (inverse of @code{SIN(X)}).
1314 @item @emph{Standard}:
1315 Fortran 77 and later, for a complex argument Fortran 2008 or later
1320 @item @emph{Syntax}:
1321 @code{RESULT = ASIN(X)}
1323 @item @emph{Arguments}:
1324 @multitable @columnfractions .15 .70
1325 @item @var{X} @tab The type shall be either @code{REAL} and a magnitude that is
1326 less than or equal to one - or be @code{COMPLEX}.
1329 @item @emph{Return value}:
1330 The return value is of the same type and kind as @var{X}.
1331 The real part of the result is in radians and lies in the range
1332 @math{-\pi/2 \leq \Re \asin(x) \leq \pi/2}.
1334 @item @emph{Example}:
1337 real(8) :: x = 0.866_8
1339 end program test_asin
1342 @item @emph{Specific names}:
1343 @multitable @columnfractions .20 .23 .20 .33
1344 @headitem Name @tab Argument @tab Return type @tab Standard
1345 @item @code{ASIN(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
1346 @item @code{DASIN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
1349 @item @emph{See also}:
1350 Inverse function: @*
1352 Degrees function: @*
1359 @section @code{ASIND} --- Arcsine function, degrees
1362 @cindex trigonometric function, sine, inverse, degrees
1363 @cindex sine, inverse, degrees
1366 @item @emph{Description}:
1367 @code{ASIND(X)} computes the arcsine of its @var{X} in degrees (inverse of
1370 @item @emph{Standard}:
1376 @item @emph{Syntax}:
1377 @code{RESULT = ASIND(X)}
1379 @item @emph{Arguments}:
1380 @multitable @columnfractions .15 .70
1381 @item @var{X} @tab The type shall be either @code{REAL} and a magnitude that is
1382 less than or equal to one.
1385 @item @emph{Return value}:
1386 The return value is of the same type and kind as @var{X}.
1387 The result is in degrees and lies in the range
1388 @math{-90 \leq \Re \asin(x) \leq 90}.
1390 @item @emph{Example}:
1393 real(8) :: x = 0.866_8
1395 end program test_asind
1398 @item @emph{Specific names}:
1399 @multitable @columnfractions .20 .23 .20 .33
1400 @headitem Name @tab Argument @tab Return type @tab Standard
1401 @item @code{ASIND(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 2023
1402 @item @code{DASIND(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1405 @item @emph{See also}:
1406 Inverse function: @*
1408 Radians function: @*
1413 @section @code{ASINH} --- Inverse hyperbolic sine function
1416 @cindex area hyperbolic sine
1417 @cindex inverse hyperbolic sine
1418 @cindex hyperbolic function, sine, inverse
1419 @cindex sine, hyperbolic, inverse
1422 @item @emph{Description}:
1423 @code{ASINH(X)} computes the inverse hyperbolic sine of @var{X}.
1425 @item @emph{Standard}:
1426 Fortran 2008 and later
1431 @item @emph{Syntax}:
1432 @code{RESULT = ASINH(X)}
1434 @item @emph{Arguments}:
1435 @multitable @columnfractions .15 .70
1436 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
1439 @item @emph{Return value}:
1440 The return value is of the same type and kind as @var{X}. If @var{X} is
1441 complex, the imaginary part of the result is in radians and lies between
1442 @math{-\pi/2 \leq \Im \asinh(x) \leq \pi/2}.
1444 @item @emph{Example}:
1447 REAL(8), DIMENSION(3) :: x = (/ -1.0, 0.0, 1.0 /)
1448 WRITE (*,*) ASINH(x)
1452 @item @emph{Specific names}:
1453 @multitable @columnfractions .20 .23 .20 .33
1454 @headitem Name @tab Argument @tab Return type @tab Standard
1455 @item @code{DASINH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension.
1458 @item @emph{See also}:
1459 Inverse function: @*
1466 @section @code{ASSOCIATED} --- Status of a pointer or pointer/target pair
1468 @cindex pointer, status
1469 @cindex association status
1472 @item @emph{Description}:
1473 @code{ASSOCIATED(POINTER [, TARGET])} determines the status of the pointer
1474 @var{POINTER} or if @var{POINTER} is associated with the target @var{TARGET}.
1476 @item @emph{Standard}:
1477 Fortran 90 and later
1482 @item @emph{Syntax}:
1483 @code{RESULT = ASSOCIATED(POINTER [, TARGET])}
1485 @item @emph{Arguments}:
1486 @multitable @columnfractions .15 .70
1487 @item @var{POINTER} @tab @var{POINTER} shall have the @code{POINTER} attribute
1488 and it can be of any type.
1489 @item @var{TARGET} @tab (Optional) @var{TARGET} shall be a pointer or
1490 a target. It must have the same type, kind type parameter, and
1491 array rank as @var{POINTER}.
1493 The association status of neither @var{POINTER} nor @var{TARGET} shall be
1496 @item @emph{Return value}:
1497 @code{ASSOCIATED(POINTER)} returns a scalar value of type @code{LOGICAL(4)}.
1498 There are several cases:
1500 @item (A) When the optional @var{TARGET} is not present then
1501 @code{ASSOCIATED(POINTER)} is true if @var{POINTER} is associated with a target; otherwise, it returns false.
1502 @item (B) If @var{TARGET} is present and a scalar target, the result is true if
1503 @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
1504 disassociated, the result is false.
1505 @item (C) If @var{TARGET} is present and an array target, the result is true if
1506 @var{TARGET} and @var{POINTER} have the same shape, are not zero-sized arrays,
1507 are arrays whose elements are not zero-sized storage sequences, and
1508 @var{TARGET} and @var{POINTER} occupy the same storage units in array element
1510 As in case(B), the result is false, if @var{POINTER} is disassociated.
1511 @item (D) If @var{TARGET} is present and an scalar pointer, the result is true
1512 if @var{TARGET} is associated with @var{POINTER}, the target associated with
1513 @var{TARGET} are not zero-sized storage sequences and occupy the same storage
1515 The result is false, if either @var{TARGET} or @var{POINTER} is disassociated.
1516 @item (E) If @var{TARGET} is present and an array pointer, the result is true if
1517 target associated with @var{POINTER} and the target associated with @var{TARGET}
1518 have the same shape, are not zero-sized arrays, are arrays whose elements are
1519 not zero-sized storage sequences, and @var{TARGET} and @var{POINTER} occupy
1520 the same storage units in array element order.
1521 The result is false, if either @var{TARGET} or @var{POINTER} is disassociated.
1524 @item @emph{Example}:
1526 program test_associated
1528 real, target :: tgt(2) = (/1., 2./)
1529 real, pointer :: ptr(:)
1531 if (associated(ptr) .eqv. .false.) call abort
1532 if (associated(ptr,tgt) .eqv. .false.) call abort
1533 end program test_associated
1536 @item @emph{See also}:
1543 @section @code{ATAN} --- Arctangent function
1546 @cindex trigonometric function, tangent, inverse
1547 @cindex tangent, inverse
1550 @item @emph{Description}:
1551 @code{ATAN(X)} computes the arctangent of @var{X}.
1553 @item @emph{Standard}:
1554 Fortran 77 and later, for a complex argument and for two arguments
1555 Fortran 2008 or later
1560 @item @emph{Syntax}:
1561 @multitable @columnfractions .80
1562 @item @code{RESULT = ATAN(X)}
1563 @item @code{RESULT = ATAN(Y, X)}
1566 @item @emph{Arguments}:
1567 @multitable @columnfractions .15 .70
1568 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX};
1569 if @var{Y} is present, @var{X} shall be REAL.
1570 @item @var{Y} @tab The type and kind type parameter shall be the same as @var{X}.
1573 @item @emph{Return value}:
1574 The return value is of the same type and kind as @var{X}.
1575 If @var{Y} is present, the result is identical to @code{ATAN2(Y,X)}.
1576 Otherwise, it the arcus tangent of @var{X}, where the real part of
1577 the result is in radians and lies in the range
1578 @math{-\pi/2 \leq \Re \atan(x) \leq \pi/2}.
1580 @item @emph{Example}:
1583 real(8) :: x = 2.866_8
1585 end program test_atan
1588 @item @emph{Specific names}:
1589 @multitable @columnfractions .20 .23 .20 .33
1590 @headitem Name @tab Argument @tab Return type @tab Standard
1591 @item @code{ATAN(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
1592 @item @code{DATAN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
1595 @item @emph{See also}:
1596 Inverse function: @*
1598 Degrees function: @*
1605 @section @code{ATAND} --- Arctangent function, degrees
1608 @cindex trigonometric function, tangent, inverse, degrees
1609 @cindex tangent, inverse, degrees
1612 @item @emph{Description}:
1613 @code{ATAND(X)} computes the arctangent of @var{X} in degrees (inverse of
1616 @item @emph{Standard}:
1622 @item @emph{Syntax}:
1623 @multitable @columnfractions .80
1624 @item @code{RESULT = ATAND(X)}
1627 @item @emph{Arguments}:
1628 @multitable @columnfractions .15 .70
1629 @item @var{X} @tab The type shall be @code{REAL};
1630 if @var{Y} is present, @var{X} shall be REAL.
1631 @item @var{Y} @tab The type and kind type parameter shall be the same as @var{X}.
1634 @item @emph{Return value}:
1635 The return value is of the same type and kind as @var{X}.
1636 The result is in degrees and lies in the range
1637 @math{-90 \leq \Re \atand(x) \leq 90}.
1639 @item @emph{Example}:
1642 real(8) :: x = 2.866_8
1644 end program test_atand
1647 @item @emph{Specific names}:
1648 @multitable @columnfractions .23 .23 .20 .30
1649 @headitem Name @tab Argument @tab Return type @tab Standard
1650 @item @code{ATAND(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 2023
1651 @item @code{DATAND(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1654 @item @emph{See also}:
1655 Inverse function: @*
1657 Radians function: @*
1664 @section @code{ATAN2} --- Arctangent function
1667 @cindex trigonometric function, tangent, inverse
1668 @cindex tangent, inverse
1671 @item @emph{Description}:
1672 @code{ATAN2(Y, X)} computes the principal value of the argument
1673 function of the complex number @math{X + i Y}. This function can
1674 be used to transform from Cartesian into polar coordinates and
1675 allows to determine the angle in the correct quadrant.
1677 @item @emph{Standard}:
1678 Fortran 77 and later
1683 @item @emph{Syntax}:
1684 @code{RESULT = ATAN2(Y, X)}
1686 @item @emph{Arguments}:
1687 @multitable @columnfractions .15 .70
1688 @item @var{Y} @tab The type shall be @code{REAL}.
1689 @item @var{X} @tab The type and kind type parameter shall be the same as @var{Y}.
1690 If @var{Y} is zero, then @var{X} must be nonzero.
1693 @item @emph{Return value}:
1694 The return value has the same type and kind type parameter as @var{Y}. It
1695 is the principal value of the complex number @math{X + i Y}. If @var{X}
1696 is nonzero, then it lies in the range @math{-\pi \le \atan (x) \leq \pi}.
1697 The sign is positive if @var{Y} is positive. If @var{Y} is zero, then
1698 the return value is zero if @var{X} is strictly positive, @math{\pi} if
1699 @var{X} is negative and @var{Y} is positive zero (or the processor does
1700 not handle signed zeros), and @math{-\pi} if @var{X} is negative and
1701 @var{Y} is negative zero. Finally, if @var{X} is zero, then the
1702 magnitude of the result is @math{\pi/2}.
1704 @item @emph{Example}:
1707 real(4) :: x = 1.e0_4, y = 0.5e0_4
1709 end program test_atan2
1712 @item @emph{Specific names}:
1713 @multitable @columnfractions .22 .22 .20 .32
1714 @headitem Name @tab Argument @tab Return type @tab Standard
1715 @item @code{ATAN2(X, Y)} @tab @code{REAL(4) X, Y} @tab @code{REAL(4)} @tab Fortran 77 and later
1716 @item @code{DATAN2(X, Y)} @tab @code{REAL(8) X, Y} @tab @code{REAL(8)} @tab Fortran 77 and later
1719 @item @emph{See also}:
1722 Degrees function: @*
1729 @section @code{ATAN2D} --- Arctangent function, degrees
1732 @cindex trigonometric function, tangent, inverse, degrees
1733 @cindex tangent, inverse, degrees
1736 @item @emph{Description}:
1737 @code{ATAN2D(Y, X)} computes the principal value of the argument
1738 function of the complex number @math{X + i Y} in degrees. This function can
1739 be used to transform from Cartesian into polar coordinates and
1740 allows to determine the angle in the correct quadrant.
1742 @item @emph{Standard}:
1748 @item @emph{Syntax}:
1749 @code{RESULT = ATAN2D(Y, X)}
1751 @item @emph{Arguments}:
1752 @multitable @columnfractions .15 .70
1753 @item @var{Y} @tab The type shall be @code{REAL}.
1754 @item @var{X} @tab The type and kind type parameter shall be the same as @var{Y}.
1755 If @var{Y} is zero, then @var{X} must be nonzero.
1758 @item @emph{Return value}:
1759 The return value has the same type and kind type parameter as @var{Y}. It
1760 is the principal value of the complex number @math{X + i Y}. If @var{X}
1761 is nonzero, then it lies in the range @math{-180 \le \atan (x) \leq 180}.
1762 The sign is positive if @var{Y} is positive. If @var{Y} is zero, then
1763 the return value is zero if @var{X} is strictly positive, @math{180} if
1764 @var{X} is negative and @var{Y} is positive zero (or the processor does
1765 not handle signed zeros), and @math{-180} if @var{X} is negative and
1766 @var{Y} is negative zero. Finally, if @var{X} is zero, then the
1767 magnitude of the result is @math{90}.
1769 @item @emph{Example}:
1772 real(4) :: x = 1.e0_4, y = 0.5e0_4
1774 end program test_atan2d
1777 @item @emph{Specific names}:
1778 @multitable @columnfractions .23 .23 .20 .30
1779 @headitem Name @tab Argument @tab Return type @tab Standard
1780 @item @code{ATAN2D(X, Y)} @tab @code{REAL(4) X, Y} @tab @code{REAL(4)} @tab Fortran 2023
1781 @item @code{DATAN2D(X, Y)} @tab @code{REAL(8) X, Y} @tab @code{REAL(8)} @tab GNU extension
1784 @item @emph{See also}:
1787 Radians function: @*
1792 @section @code{ATANH} --- Inverse hyperbolic tangent function
1795 @cindex area hyperbolic tangent
1796 @cindex inverse hyperbolic tangent
1797 @cindex hyperbolic function, tangent, inverse
1798 @cindex tangent, hyperbolic, inverse
1801 @item @emph{Description}:
1802 @code{ATANH(X)} computes the inverse hyperbolic tangent of @var{X}.
1804 @item @emph{Standard}:
1805 Fortran 2008 and later
1810 @item @emph{Syntax}:
1811 @code{RESULT = ATANH(X)}
1813 @item @emph{Arguments}:
1814 @multitable @columnfractions .15 .70
1815 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
1818 @item @emph{Return value}:
1819 The return value has same type and kind as @var{X}. If @var{X} is
1820 complex, the imaginary part of the result is in radians and lies between
1821 @math{-\pi/2 \leq \Im \atanh(x) \leq \pi/2}.
1823 @item @emph{Example}:
1826 REAL, DIMENSION(3) :: x = (/ -1.0, 0.0, 1.0 /)
1827 WRITE (*,*) ATANH(x)
1831 @item @emph{Specific names}:
1832 @multitable @columnfractions .20 .23 .20 .33
1833 @headitem Name @tab Argument @tab Return type @tab Standard
1834 @item @code{DATANH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1837 @item @emph{See also}:
1838 Inverse function: @*
1845 @section @code{ATOMIC_ADD} --- Atomic ADD operation
1847 @cindex Atomic subroutine, add
1850 @item @emph{Description}:
1851 @code{ATOMIC_ADD(ATOM, VALUE)} atomically adds the value of @var{VALUE} to the
1852 variable @var{ATOM}. When @var{STAT} is present and the invocation was
1853 successful, it is assigned the value 0. If it is present and the invocation
1854 has failed, it is assigned a positive value; in particular, for a coindexed
1855 @var{ATOM}, if the remote image has stopped, it is assigned the value of
1856 @code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote image has
1857 failed, the value @code{STAT_FAILED_IMAGE}.
1859 @item @emph{Standard}:
1865 @item @emph{Syntax}:
1866 @code{CALL ATOMIC_ADD (ATOM, VALUE [, STAT])}
1868 @item @emph{Arguments}:
1869 @multitable @columnfractions .15 .70
1870 @item @var{ATOM} @tab Scalar coarray or coindexed variable of integer
1871 type with @code{ATOMIC_INT_KIND} kind.
1872 @item @var{VALUE} @tab Scalar of the same type as @var{ATOM}. If the kind
1873 is different, the value is converted to the kind of @var{ATOM}.
1874 @item @var{STAT} @tab (optional) Scalar default-kind integer variable.
1877 @item @emph{Example}:
1881 integer(atomic_int_kind) :: atom[*]
1882 call atomic_add (atom[1], this_image())
1886 @item @emph{See also}:
1887 @ref{ATOMIC_DEFINE}, @*
1888 @ref{ATOMIC_FETCH_ADD}, @*
1889 @ref{ISO_FORTRAN_ENV}, @*
1890 @ref{ATOMIC_AND}, @*
1899 @section @code{ATOMIC_AND} --- Atomic bitwise AND operation
1901 @cindex Atomic subroutine, AND
1904 @item @emph{Description}:
1905 @code{ATOMIC_AND(ATOM, VALUE)} atomically defines @var{ATOM} with the bitwise
1906 AND between the values of @var{ATOM} and @var{VALUE}. When @var{STAT} is present
1907 and the invocation was successful, it is assigned the value 0. If it is present
1908 and the invocation has failed, it is assigned a positive value; in particular,
1909 for a coindexed @var{ATOM}, if the remote image has stopped, it is assigned the
1910 value of @code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote
1911 image has failed, the value @code{STAT_FAILED_IMAGE}.
1913 @item @emph{Standard}:
1919 @item @emph{Syntax}:
1920 @code{CALL ATOMIC_AND (ATOM, VALUE [, STAT])}
1922 @item @emph{Arguments}:
1923 @multitable @columnfractions .15 .70
1924 @item @var{ATOM} @tab Scalar coarray or coindexed variable of integer
1925 type with @code{ATOMIC_INT_KIND} kind.
1926 @item @var{VALUE} @tab Scalar of the same type as @var{ATOM}. If the kind
1927 is different, the value is converted to the kind of @var{ATOM}.
1928 @item @var{STAT} @tab (optional) Scalar default-kind integer variable.
1931 @item @emph{Example}:
1935 integer(atomic_int_kind) :: atom[*]
1936 call atomic_and (atom[1], int(b'10100011101'))
1940 @item @emph{See also}:
1941 @ref{ATOMIC_DEFINE}, @*
1942 @ref{ATOMIC_FETCH_AND}, @*
1943 @ref{ISO_FORTRAN_ENV}, @*
1944 @ref{ATOMIC_ADD}, @*
1952 @section @code{ATOMIC_CAS} --- Atomic compare and swap
1953 @fnindex ATOMIC_DEFINE
1954 @cindex Atomic subroutine, compare and swap
1957 @item @emph{Description}:
1958 @code{ATOMIC_CAS} compares the variable @var{ATOM} with the value of
1959 @var{COMPARE}; if the value is the same, @var{ATOM} is set to the value
1960 of @var{NEW}. Additionally, @var{OLD} is set to the value of @var{ATOM}
1961 that was used for the comparison. When @var{STAT} is present and the invocation
1962 was successful, it is assigned the value 0. If it is present and the invocation
1963 has failed, it is assigned a positive value; in particular, for a coindexed
1964 @var{ATOM}, if the remote image has stopped, it is assigned the value of
1965 @code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote image has
1966 failed, the value @code{STAT_FAILED_IMAGE}.
1968 @item @emph{Standard}:
1974 @item @emph{Syntax}:
1975 @code{CALL ATOMIC_CAS (ATOM, OLD, COMPARE, NEW [, STAT])}
1977 @item @emph{Arguments}:
1978 @multitable @columnfractions .15 .70
1979 @item @var{ATOM} @tab Scalar coarray or coindexed variable of either integer
1980 type with @code{ATOMIC_INT_KIND} kind or logical type with
1981 @code{ATOMIC_LOGICAL_KIND} kind.
1982 @item @var{OLD} @tab Scalar of the same type and kind as @var{ATOM}.
1983 @item @var{COMPARE} @tab Scalar variable of the same type and kind as
1985 @item @var{NEW} @tab Scalar variable of the same type as @var{ATOM}. If kind
1986 is different, the value is converted to the kind of @var{ATOM}.
1987 @item @var{STAT} @tab (optional) Scalar default-kind integer variable.
1990 @item @emph{Example}:
1994 logical(atomic_logical_kind) :: atom[*], prev
1995 call atomic_cas (atom[1], prev, .false., .true.))
1999 @item @emph{See also}:
2000 @ref{ATOMIC_DEFINE}, @*
2001 @ref{ATOMIC_REF}, @*
2002 @ref{ISO_FORTRAN_ENV}
2008 @section @code{ATOMIC_DEFINE} --- Setting a variable atomically
2009 @fnindex ATOMIC_DEFINE
2010 @cindex Atomic subroutine, define
2013 @item @emph{Description}:
2014 @code{ATOMIC_DEFINE(ATOM, VALUE)} defines the variable @var{ATOM} with the value
2015 @var{VALUE} atomically. When @var{STAT} is present and the invocation was
2016 successful, it is assigned the value 0. If it is present and the invocation
2017 has failed, it is assigned a positive value; in particular, for a coindexed
2018 @var{ATOM}, if the remote image has stopped, it is assigned the value of
2019 @code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote image has
2020 failed, the value @code{STAT_FAILED_IMAGE}.
2022 @item @emph{Standard}:
2023 Fortran 2008 and later; with @var{STAT}, TS 18508 or later
2028 @item @emph{Syntax}:
2029 @code{CALL ATOMIC_DEFINE (ATOM, VALUE [, STAT])}
2031 @item @emph{Arguments}:
2032 @multitable @columnfractions .15 .70
2033 @item @var{ATOM} @tab Scalar coarray or coindexed variable of either integer
2034 type with @code{ATOMIC_INT_KIND} kind or logical type with
2035 @code{ATOMIC_LOGICAL_KIND} kind.
2037 @item @var{VALUE} @tab Scalar of the same type as @var{ATOM}. If the kind
2038 is different, the value is converted to the kind of @var{ATOM}.
2039 @item @var{STAT} @tab (optional) Scalar default-kind integer variable.
2042 @item @emph{Example}:
2046 integer(atomic_int_kind) :: atom[*]
2047 call atomic_define (atom[1], this_image())
2051 @item @emph{See also}:
2052 @ref{ATOMIC_REF}, @*
2053 @ref{ATOMIC_CAS}, @*
2054 @ref{ISO_FORTRAN_ENV}, @*
2055 @ref{ATOMIC_ADD}, @*
2056 @ref{ATOMIC_AND}, @*
2063 @node ATOMIC_FETCH_ADD
2064 @section @code{ATOMIC_FETCH_ADD} --- Atomic ADD operation with prior fetch
2065 @fnindex ATOMIC_FETCH_ADD
2066 @cindex Atomic subroutine, ADD with fetch
2069 @item @emph{Description}:
2070 @code{ATOMIC_FETCH_ADD(ATOM, VALUE, OLD)} atomically stores the value of
2071 @var{ATOM} in @var{OLD} and adds the value of @var{VALUE} to the
2072 variable @var{ATOM}. When @var{STAT} is present and the invocation was
2073 successful, it is assigned the value 0. If it is present and the invocation
2074 has failed, it is assigned a positive value; in particular, for a coindexed
2075 @var{ATOM}, if the remote image has stopped, it is assigned the value of
2076 @code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote image has
2077 failed, the value @code{STAT_FAILED_IMAGE}.
2079 @item @emph{Standard}:
2085 @item @emph{Syntax}:
2086 @code{CALL ATOMIC_FETCH_ADD (ATOM, VALUE, old [, STAT])}
2088 @item @emph{Arguments}:
2089 @multitable @columnfractions .15 .70
2090 @item @var{ATOM} @tab Scalar coarray or coindexed variable of integer
2091 type with @code{ATOMIC_INT_KIND} kind.
2092 @code{ATOMIC_LOGICAL_KIND} kind.
2094 @item @var{VALUE} @tab Scalar of the same type as @var{ATOM}. If the kind
2095 is different, the value is converted to the kind of @var{ATOM}.
2096 @item @var{OLD} @tab Scalar of the same type and kind as @var{ATOM}.
2097 @item @var{STAT} @tab (optional) Scalar default-kind integer variable.
2100 @item @emph{Example}:
2104 integer(atomic_int_kind) :: atom[*], old
2105 call atomic_add (atom[1], this_image(), old)
2109 @item @emph{See also}:
2110 @ref{ATOMIC_DEFINE}, @*
2111 @ref{ATOMIC_ADD}, @*
2112 @ref{ISO_FORTRAN_ENV}, @*
2113 @ref{ATOMIC_FETCH_AND}, @*
2114 @ref{ATOMIC_FETCH_OR}, @*
2115 @ref{ATOMIC_FETCH_XOR}
2120 @node ATOMIC_FETCH_AND
2121 @section @code{ATOMIC_FETCH_AND} --- Atomic bitwise AND operation with prior fetch
2122 @fnindex ATOMIC_FETCH_AND
2123 @cindex Atomic subroutine, AND with fetch
2126 @item @emph{Description}:
2127 @code{ATOMIC_AND(ATOM, VALUE)} atomically stores the value of @var{ATOM} in
2128 @var{OLD} and defines @var{ATOM} with the bitwise AND between the values of
2129 @var{ATOM} and @var{VALUE}. When @var{STAT} is present and the invocation was
2130 successful, it is assigned the value 0. If it is present and the invocation has
2131 failed, it is assigned a positive value; in particular, for a coindexed
2132 @var{ATOM}, if the remote image has stopped, it is assigned the value of
2133 @code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote image has
2134 failed, the value @code{STAT_FAILED_IMAGE}.
2136 @item @emph{Standard}:
2142 @item @emph{Syntax}:
2143 @code{CALL ATOMIC_FETCH_AND (ATOM, VALUE, OLD [, STAT])}
2145 @item @emph{Arguments}:
2146 @multitable @columnfractions .15 .70
2147 @item @var{ATOM} @tab Scalar coarray or coindexed variable of integer
2148 type with @code{ATOMIC_INT_KIND} kind.
2149 @item @var{VALUE} @tab Scalar of the same type as @var{ATOM}. If the kind
2150 is different, the value is converted to the kind of @var{ATOM}.
2151 @item @var{OLD} @tab Scalar of the same type and kind as @var{ATOM}.
2152 @item @var{STAT} @tab (optional) Scalar default-kind integer variable.
2155 @item @emph{Example}:
2159 integer(atomic_int_kind) :: atom[*], old
2160 call atomic_fetch_and (atom[1], int(b'10100011101'), old)
2164 @item @emph{See also}:
2165 @ref{ATOMIC_DEFINE}, @*
2166 @ref{ATOMIC_AND}, @*
2167 @ref{ISO_FORTRAN_ENV}, @*
2168 @ref{ATOMIC_FETCH_ADD}, @*
2169 @ref{ATOMIC_FETCH_OR}, @*
2170 @ref{ATOMIC_FETCH_XOR}
2175 @node ATOMIC_FETCH_OR
2176 @section @code{ATOMIC_FETCH_OR} --- Atomic bitwise OR operation with prior fetch
2177 @fnindex ATOMIC_FETCH_OR
2178 @cindex Atomic subroutine, OR with fetch
2181 @item @emph{Description}:
2182 @code{ATOMIC_OR(ATOM, VALUE)} atomically stores the value of @var{ATOM} in
2183 @var{OLD} and defines @var{ATOM} with the bitwise OR between the values of
2184 @var{ATOM} and @var{VALUE}. When @var{STAT} is present and the invocation was
2185 successful, it is assigned the value 0. If it is present and the invocation has
2186 failed, it is assigned a positive value; in particular, for a coindexed
2187 @var{ATOM}, if the remote image has stopped, it is assigned the value of
2188 @code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote image has
2189 failed, the value @code{STAT_FAILED_IMAGE}.
2191 @item @emph{Standard}:
2197 @item @emph{Syntax}:
2198 @code{CALL ATOMIC_FETCH_OR (ATOM, VALUE, OLD [, STAT])}
2200 @item @emph{Arguments}:
2201 @multitable @columnfractions .15 .70
2202 @item @var{ATOM} @tab Scalar coarray or coindexed variable of integer
2203 type with @code{ATOMIC_INT_KIND} kind.
2204 @item @var{VALUE} @tab Scalar of the same type as @var{ATOM}. If the kind
2205 is different, the value is converted to the kind of @var{ATOM}.
2206 @item @var{OLD} @tab Scalar of the same type and kind as @var{ATOM}.
2207 @item @var{STAT} @tab (optional) Scalar default-kind integer variable.
2210 @item @emph{Example}:
2214 integer(atomic_int_kind) :: atom[*], old
2215 call atomic_fetch_or (atom[1], int(b'10100011101'), old)
2219 @item @emph{See also}:
2220 @ref{ATOMIC_DEFINE}, @*
2222 @ref{ISO_FORTRAN_ENV}, @*
2223 @ref{ATOMIC_FETCH_ADD}, @*
2224 @ref{ATOMIC_FETCH_AND}, @*
2225 @ref{ATOMIC_FETCH_XOR}
2230 @node ATOMIC_FETCH_XOR
2231 @section @code{ATOMIC_FETCH_XOR} --- Atomic bitwise XOR operation with prior fetch
2232 @fnindex ATOMIC_FETCH_XOR
2233 @cindex Atomic subroutine, XOR with fetch
2236 @item @emph{Description}:
2237 @code{ATOMIC_XOR(ATOM, VALUE)} atomically stores the value of @var{ATOM} in
2238 @var{OLD} and defines @var{ATOM} with the bitwise XOR between the values of
2239 @var{ATOM} and @var{VALUE}. When @var{STAT} is present and the invocation was
2240 successful, it is assigned the value 0. If it is present and the invocation has
2241 failed, it is assigned a positive value; in particular, for a coindexed
2242 @var{ATOM}, if the remote image has stopped, it is assigned the value of
2243 @code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote image has
2244 failed, the value @code{STAT_FAILED_IMAGE}.
2246 @item @emph{Standard}:
2252 @item @emph{Syntax}:
2253 @code{CALL ATOMIC_FETCH_XOR (ATOM, VALUE, OLD [, STAT])}
2255 @item @emph{Arguments}:
2256 @multitable @columnfractions .15 .70
2257 @item @var{ATOM} @tab Scalar coarray or coindexed variable of integer
2258 type with @code{ATOMIC_INT_KIND} kind.
2259 @item @var{VALUE} @tab Scalar of the same type as @var{ATOM}. If the kind
2260 is different, the value is converted to the kind of @var{ATOM}.
2261 @item @var{OLD} @tab Scalar of the same type and kind as @var{ATOM}.
2262 @item @var{STAT} @tab (optional) Scalar default-kind integer variable.
2265 @item @emph{Example}:
2269 integer(atomic_int_kind) :: atom[*], old
2270 call atomic_fetch_xor (atom[1], int(b'10100011101'), old)
2274 @item @emph{See also}:
2275 @ref{ATOMIC_DEFINE}, @*
2276 @ref{ATOMIC_XOR}, @*
2277 @ref{ISO_FORTRAN_ENV}, @*
2278 @ref{ATOMIC_FETCH_ADD}, @*
2279 @ref{ATOMIC_FETCH_AND}, @*
2280 @ref{ATOMIC_FETCH_OR}
2286 @section @code{ATOMIC_OR} --- Atomic bitwise OR operation
2288 @cindex Atomic subroutine, OR
2291 @item @emph{Description}:
2292 @code{ATOMIC_OR(ATOM, VALUE)} atomically defines @var{ATOM} with the bitwise
2293 AND between the values of @var{ATOM} and @var{VALUE}. When @var{STAT} is present
2294 and the invocation was successful, it is assigned the value 0. If it is present
2295 and the invocation has failed, it is assigned a positive value; in particular,
2296 for a coindexed @var{ATOM}, if the remote image has stopped, it is assigned the
2297 value of @code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote
2298 image has failed, the value @code{STAT_FAILED_IMAGE}.
2300 @item @emph{Standard}:
2306 @item @emph{Syntax}:
2307 @code{CALL ATOMIC_OR (ATOM, VALUE [, STAT])}
2309 @item @emph{Arguments}:
2310 @multitable @columnfractions .15 .70
2311 @item @var{ATOM} @tab Scalar coarray or coindexed variable of integer
2312 type with @code{ATOMIC_INT_KIND} kind.
2313 @item @var{VALUE} @tab Scalar of the same type as @var{ATOM}. If the kind
2314 is different, the value is converted to the kind of @var{ATOM}.
2315 @item @var{STAT} @tab (optional) Scalar default-kind integer variable.
2318 @item @emph{Example}:
2322 integer(atomic_int_kind) :: atom[*]
2323 call atomic_or (atom[1], int(b'10100011101'))
2327 @item @emph{See also}:
2328 @ref{ATOMIC_DEFINE}, @*
2329 @ref{ATOMIC_FETCH_OR}, @*
2330 @ref{ISO_FORTRAN_ENV}, @*
2331 @ref{ATOMIC_ADD}, @*
2339 @section @code{ATOMIC_REF} --- Obtaining the value of a variable atomically
2341 @cindex Atomic subroutine, reference
2344 @item @emph{Description}:
2345 @code{ATOMIC_DEFINE(ATOM, VALUE)} atomically assigns the value of the
2346 variable @var{ATOM} to @var{VALUE}. When @var{STAT} is present and the
2347 invocation was successful, it is assigned the value 0. If it is present and the
2348 invocation has failed, it is assigned a positive value; in particular, for a
2349 coindexed @var{ATOM}, if the remote image has stopped, it is assigned the value
2350 of @code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote image
2351 has failed, the value @code{STAT_FAILED_IMAGE}.
2354 @item @emph{Standard}:
2355 Fortran 2008 and later; with @var{STAT}, TS 18508 or later
2360 @item @emph{Syntax}:
2361 @code{CALL ATOMIC_REF(VALUE, ATOM [, STAT])}
2363 @item @emph{Arguments}:
2364 @multitable @columnfractions .15 .70
2365 @item @var{VALUE} @tab Scalar of the same type as @var{ATOM}. If the kind
2366 is different, the value is converted to the kind of @var{ATOM}.
2367 @item @var{ATOM} @tab Scalar coarray or coindexed variable of either integer
2368 type with @code{ATOMIC_INT_KIND} kind or logical type with
2369 @code{ATOMIC_LOGICAL_KIND} kind.
2370 @item @var{STAT} @tab (optional) Scalar default-kind integer variable.
2373 @item @emph{Example}:
2377 logical(atomic_logical_kind) :: atom[*]
2379 call atomic_ref (atom, .false.)
2381 call atomic_ref (atom, val)
2388 @item @emph{See also}:
2389 @ref{ATOMIC_DEFINE}, @*
2390 @ref{ATOMIC_CAS}, @*
2391 @ref{ISO_FORTRAN_ENV}, @*
2392 @ref{ATOMIC_FETCH_ADD}, @*
2393 @ref{ATOMIC_FETCH_AND}, @*
2394 @ref{ATOMIC_FETCH_OR}, @*
2395 @ref{ATOMIC_FETCH_XOR}
2400 @section @code{ATOMIC_XOR} --- Atomic bitwise OR operation
2402 @cindex Atomic subroutine, XOR
2405 @item @emph{Description}:
2406 @code{ATOMIC_AND(ATOM, VALUE)} atomically defines @var{ATOM} with the bitwise
2407 XOR between the values of @var{ATOM} and @var{VALUE}. When @var{STAT} is present
2408 and the invocation was successful, it is assigned the value 0. If it is present
2409 and the invocation has failed, it is assigned a positive value; in particular,
2410 for a coindexed @var{ATOM}, if the remote image has stopped, it is assigned the
2411 value of @code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote
2412 image has failed, the value @code{STAT_FAILED_IMAGE}.
2414 @item @emph{Standard}:
2420 @item @emph{Syntax}:
2421 @code{CALL ATOMIC_XOR (ATOM, VALUE [, STAT])}
2423 @item @emph{Arguments}:
2424 @multitable @columnfractions .15 .70
2425 @item @var{ATOM} @tab Scalar coarray or coindexed variable of integer
2426 type with @code{ATOMIC_INT_KIND} kind.
2427 @item @var{VALUE} @tab Scalar of the same type as @var{ATOM}. If the kind
2428 is different, the value is converted to the kind of @var{ATOM}.
2429 @item @var{STAT} @tab (optional) Scalar default-kind integer variable.
2432 @item @emph{Example}:
2436 integer(atomic_int_kind) :: atom[*]
2437 call atomic_xor (atom[1], int(b'10100011101'))
2441 @item @emph{See also}:
2442 @ref{ATOMIC_DEFINE}, @*
2443 @ref{ATOMIC_FETCH_XOR}, @*
2444 @ref{ISO_FORTRAN_ENV}, @*
2445 @ref{ATOMIC_ADD}, @*
2452 @section @code{BACKTRACE} --- Show a backtrace
2457 @item @emph{Description}:
2458 @code{BACKTRACE} shows a backtrace at an arbitrary place in user code. Program
2459 execution continues normally afterwards. The backtrace information is printed
2460 to the unit corresponding to @code{ERROR_UNIT} in @code{ISO_FORTRAN_ENV}.
2462 @item @emph{Standard}:
2468 @item @emph{Syntax}:
2469 @code{CALL BACKTRACE}
2471 @item @emph{Arguments}:
2474 @item @emph{See also}:
2481 @section @code{BESSEL_J0} --- Bessel function of the first kind of order 0
2485 @cindex Bessel function, first kind
2488 @item @emph{Description}:
2489 @code{BESSEL_J0(X)} computes the Bessel function of the first kind of
2490 order 0 of @var{X}. This function is available under the name
2491 @code{BESJ0} as a GNU extension.
2493 @item @emph{Standard}:
2494 Fortran 2008 and later
2499 @item @emph{Syntax}:
2500 @code{RESULT = BESSEL_J0(X)}
2502 @item @emph{Arguments}:
2503 @multitable @columnfractions .15 .70
2504 @item @var{X} @tab The type shall be @code{REAL}.
2507 @item @emph{Return value}:
2508 The return value is of type @code{REAL} and lies in the
2509 range @math{ - 0.4027... \leq Bessel (0,x) \leq 1}. It has the same
2512 @item @emph{Example}:
2515 real(8) :: x = 0.0_8
2517 end program test_besj0
2520 @item @emph{Specific names}:
2521 @multitable @columnfractions .21 .22 .20 .33
2522 @headitem Name @tab Argument @tab Return type @tab Standard
2523 @item @code{DBESJ0(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
2530 @section @code{BESSEL_J1} --- Bessel function of the first kind of order 1
2534 @cindex Bessel function, first kind
2537 @item @emph{Description}:
2538 @code{BESSEL_J1(X)} computes the Bessel function of the first kind of
2539 order 1 of @var{X}. This function is available under the name
2540 @code{BESJ1} as a GNU extension.
2542 @item @emph{Standard}:
2548 @item @emph{Syntax}:
2549 @code{RESULT = BESSEL_J1(X)}
2551 @item @emph{Arguments}:
2552 @multitable @columnfractions .15 .70
2553 @item @var{X} @tab The type shall be @code{REAL}.
2556 @item @emph{Return value}:
2557 The return value is of type @code{REAL} and lies in the
2558 range @math{ - 0.5818... \leq Bessel (0,x) \leq 0.5818 }. It has the same
2561 @item @emph{Example}:
2564 real(8) :: x = 1.0_8
2566 end program test_besj1
2569 @item @emph{Specific names}:
2570 @multitable @columnfractions .20 .23 .20 .33
2571 @headitem Name @tab Argument @tab Return type @tab Standard
2572 @item @code{DBESJ1(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
2579 @section @code{BESSEL_JN} --- Bessel function of the first kind
2583 @cindex Bessel function, first kind
2586 @item @emph{Description}:
2587 @code{BESSEL_JN(N, X)} computes the Bessel function of the first kind of
2588 order @var{N} of @var{X}. This function is available under the name
2589 @code{BESJN} as a GNU extension. If @var{N} and @var{X} are arrays,
2590 their ranks and shapes shall conform.
2592 @code{BESSEL_JN(N1, N2, X)} returns an array with the Bessel functions
2593 of the first kind of the orders @var{N1} to @var{N2}.
2595 @item @emph{Standard}:
2596 Fortran 2008 and later, negative @var{N} is allowed as GNU extension
2599 Elemental function, except for the transformational function
2600 @code{BESSEL_JN(N1, N2, X)}
2602 @item @emph{Syntax}:
2603 @multitable @columnfractions .80
2604 @item @code{RESULT = BESSEL_JN(N, X)}
2605 @item @code{RESULT = BESSEL_JN(N1, N2, X)}
2608 @item @emph{Arguments}:
2609 @multitable @columnfractions .15 .70
2610 @item @var{N} @tab Shall be a scalar or an array of type @code{INTEGER}.
2611 @item @var{N1} @tab Shall be a non-negative scalar of type @code{INTEGER}.
2612 @item @var{N2} @tab Shall be a non-negative scalar of type @code{INTEGER}.
2613 @item @var{X} @tab Shall be a scalar or an array of type @code{REAL};
2614 for @code{BESSEL_JN(N1, N2, X)} it shall be scalar.
2617 @item @emph{Return value}:
2618 The return value is a scalar of type @code{REAL}. It has the same
2622 The transformational function uses a recurrence algorithm which might,
2623 for some values of @var{X}, lead to different results than calls to
2624 the elemental function.
2626 @item @emph{Example}:
2629 real(8) :: x = 1.0_8
2631 end program test_besjn
2634 @item @emph{Specific names}:
2635 @multitable @columnfractions .22 .22 .20 .32
2636 @headitem Name @tab Argument @tab Return type @tab Standard
2637 @item @code{DBESJN(N, X)} @tab @code{INTEGER N} @tab @code{REAL(8)} @tab GNU extension
2638 @item @tab @code{REAL(8) X} @tab @tab
2645 @section @code{BESSEL_Y0} --- Bessel function of the second kind of order 0
2649 @cindex Bessel function, second kind
2652 @item @emph{Description}:
2653 @code{BESSEL_Y0(X)} computes the Bessel function of the second kind of
2654 order 0 of @var{X}. This function is available under the name
2655 @code{BESY0} as a GNU extension.
2657 @item @emph{Standard}:
2658 Fortran 2008 and later
2663 @item @emph{Syntax}:
2664 @code{RESULT = BESSEL_Y0(X)}
2666 @item @emph{Arguments}:
2667 @multitable @columnfractions .15 .70
2668 @item @var{X} @tab The type shall be @code{REAL}.
2671 @item @emph{Return value}:
2672 The return value is of type @code{REAL}. It has the same kind as @var{X}.
2674 @item @emph{Example}:
2677 real(8) :: x = 0.0_8
2679 end program test_besy0
2682 @item @emph{Specific names}:
2683 @multitable @columnfractions .20 .23 .20 .33
2684 @headitem Name @tab Argument @tab Return type @tab Standard
2685 @item @code{DBESY0(X)}@tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
2692 @section @code{BESSEL_Y1} --- Bessel function of the second kind of order 1
2696 @cindex Bessel function, second kind
2699 @item @emph{Description}:
2700 @code{BESSEL_Y1(X)} computes the Bessel function of the second kind of
2701 order 1 of @var{X}. This function is available under the name
2702 @code{BESY1} as a GNU extension.
2704 @item @emph{Standard}:
2705 Fortran 2008 and later
2710 @item @emph{Syntax}:
2711 @code{RESULT = BESSEL_Y1(X)}
2713 @item @emph{Arguments}:
2714 @multitable @columnfractions .15 .70
2715 @item @var{X} @tab The type shall be @code{REAL}.
2718 @item @emph{Return value}:
2719 The return value is of type @code{REAL}. It has the same kind as @var{X}.
2721 @item @emph{Example}:
2724 real(8) :: x = 1.0_8
2726 end program test_besy1
2729 @item @emph{Specific names}:
2730 @multitable @columnfractions .20 .23 .20 .33
2731 @headitem Name @tab Argument @tab Return type @tab Standard
2732 @item @code{DBESY1(X)}@tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
2739 @section @code{BESSEL_YN} --- Bessel function of the second kind
2743 @cindex Bessel function, second kind
2746 @item @emph{Description}:
2747 @code{BESSEL_YN(N, X)} computes the Bessel function of the second kind of
2748 order @var{N} of @var{X}. This function is available under the name
2749 @code{BESYN} as a GNU extension. If @var{N} and @var{X} are arrays,
2750 their ranks and shapes shall conform.
2752 @code{BESSEL_YN(N1, N2, X)} returns an array with the Bessel functions
2753 of the first kind of the orders @var{N1} to @var{N2}.
2755 @item @emph{Standard}:
2756 Fortran 2008 and later, negative @var{N} is allowed as GNU extension
2759 Elemental function, except for the transformational function
2760 @code{BESSEL_YN(N1, N2, X)}
2762 @item @emph{Syntax}:
2763 @multitable @columnfractions .80
2764 @item @code{RESULT = BESSEL_YN(N, X)}
2765 @item @code{RESULT = BESSEL_YN(N1, N2, X)}
2768 @item @emph{Arguments}:
2769 @multitable @columnfractions .15 .70
2770 @item @var{N} @tab Shall be a scalar or an array of type @code{INTEGER} .
2771 @item @var{N1} @tab Shall be a non-negative scalar of type @code{INTEGER}.
2772 @item @var{N2} @tab Shall be a non-negative scalar of type @code{INTEGER}.
2773 @item @var{X} @tab Shall be a scalar or an array of type @code{REAL};
2774 for @code{BESSEL_YN(N1, N2, X)} it shall be scalar.
2777 @item @emph{Return value}:
2778 The return value is a scalar of type @code{REAL}. It has the same
2782 The transformational function uses a recurrence algorithm which might,
2783 for some values of @var{X}, lead to different results than calls to
2784 the elemental function.
2786 @item @emph{Example}:
2789 real(8) :: x = 1.0_8
2791 end program test_besyn
2794 @item @emph{Specific names}:
2795 @multitable @columnfractions .20 .23 .20 .33
2796 @headitem Name @tab Argument @tab Return type @tab Standard
2797 @item @code{DBESYN(N,X)} @tab @code{INTEGER N} @tab @code{REAL(8)} @tab GNU extension
2798 @item @tab @code{REAL(8) X} @tab @tab
2805 @section @code{BGE} --- Bitwise greater than or equal to
2807 @cindex bitwise comparison
2810 @item @emph{Description}:
2811 Determines whether an integral is a bitwise greater than or equal to
2814 @item @emph{Standard}:
2815 Fortran 2008 and later
2820 @item @emph{Syntax}:
2821 @code{RESULT = BGE(I, J)}
2823 @item @emph{Arguments}:
2824 @multitable @columnfractions .15 .70
2825 @item @var{I} @tab Shall be of @code{INTEGER} type.
2826 @item @var{J} @tab Shall be of @code{INTEGER} type, and of the same kind
2830 @item @emph{Return value}:
2831 The return value is of type @code{LOGICAL} and of the default kind.
2833 @item @emph{See also}:
2842 @section @code{BGT} --- Bitwise greater than
2844 @cindex bitwise comparison
2847 @item @emph{Description}:
2848 Determines whether an integral is a bitwise greater than another.
2850 @item @emph{Standard}:
2851 Fortran 2008 and later
2856 @item @emph{Syntax}:
2857 @code{RESULT = BGT(I, J)}
2859 @item @emph{Arguments}:
2860 @multitable @columnfractions .15 .70
2861 @item @var{I} @tab Shall be of @code{INTEGER} type.
2862 @item @var{J} @tab Shall be of @code{INTEGER} type, and of the same kind
2866 @item @emph{Return value}:
2867 The return value is of type @code{LOGICAL} and of the default kind.
2869 @item @emph{See also}:
2878 @section @code{BIT_SIZE} --- Bit size inquiry function
2880 @cindex bits, number of
2881 @cindex size of a variable, in bits
2884 @item @emph{Description}:
2885 @code{BIT_SIZE(I)} returns the number of bits (integer precision plus sign bit)
2886 represented by the type of @var{I}. The result of @code{BIT_SIZE(I)} is
2887 independent of the actual value of @var{I}.
2889 @item @emph{Standard}:
2890 Fortran 90 and later
2895 @item @emph{Syntax}:
2896 @code{RESULT = BIT_SIZE(I)}
2898 @item @emph{Arguments}:
2899 @multitable @columnfractions .15 .70
2900 @item @var{I} @tab The type shall be @code{INTEGER}.
2903 @item @emph{Return value}:
2904 The return value is of type @code{INTEGER}
2906 @item @emph{Example}:
2908 program test_bit_size
2913 end program test_bit_size
2920 @section @code{BLE} --- Bitwise less than or equal to
2922 @cindex bitwise comparison
2925 @item @emph{Description}:
2926 Determines whether an integral is a bitwise less than or equal to
2929 @item @emph{Standard}:
2930 Fortran 2008 and later
2935 @item @emph{Syntax}:
2936 @code{RESULT = BLE(I, J)}
2938 @item @emph{Arguments}:
2939 @multitable @columnfractions .15 .70
2940 @item @var{I} @tab Shall be of @code{INTEGER} type.
2941 @item @var{J} @tab Shall be of @code{INTEGER} type, and of the same kind
2945 @item @emph{Return value}:
2946 The return value is of type @code{LOGICAL} and of the default kind.
2948 @item @emph{See also}:
2957 @section @code{BLT} --- Bitwise less than
2959 @cindex bitwise comparison
2962 @item @emph{Description}:
2963 Determines whether an integral is a bitwise less than another.
2965 @item @emph{Standard}:
2966 Fortran 2008 and later
2971 @item @emph{Syntax}:
2972 @code{RESULT = BLT(I, J)}
2974 @item @emph{Arguments}:
2975 @multitable @columnfractions .15 .70
2976 @item @var{I} @tab Shall be of @code{INTEGER} type.
2977 @item @var{J} @tab Shall be of @code{INTEGER} type, and of the same kind
2981 @item @emph{Return value}:
2982 The return value is of type @code{LOGICAL} and of the default kind.
2984 @item @emph{See also}:
2993 @section @code{BTEST} --- Bit test function
2999 @cindex bits, testing
3002 @item @emph{Description}:
3003 @code{BTEST(I,POS)} returns logical @code{.TRUE.} if the bit at @var{POS}
3004 in @var{I} is set. The counting of the bits starts at 0.
3006 @item @emph{Standard}:
3007 Fortran 90 and later, has overloads that are GNU extensions
3012 @item @emph{Syntax}:
3013 @code{RESULT = BTEST(I, POS)}
3015 @item @emph{Arguments}:
3016 @multitable @columnfractions .15 .70
3017 @item @var{I} @tab The type shall be @code{INTEGER}.
3018 @item @var{POS} @tab The type shall be @code{INTEGER}.
3021 @item @emph{Return value}:
3022 The return value is of type @code{LOGICAL}
3024 @item @emph{Example}:
3027 integer :: i = 32768 + 1024 + 64
3031 bool = btest(i, pos)
3034 end program test_btest
3037 @item @emph{Specific names}:
3038 @multitable @columnfractions .21 .28 .18 .30
3039 @headitem Name @tab Argument @tab Return type @tab Standard
3040 @item @code{BTEST(I,POS)} @tab @code{INTEGER I,POS} @tab @code{LOGICAL} @tab Fortran 95 and later
3041 @item @code{BBTEST(I,POS)} @tab @code{INTEGER(1) I,POS} @tab @code{LOGICAL(1)} @tab GNU extension
3042 @item @code{BITEST(I,POS)} @tab @code{INTEGER(2) I,POS} @tab @code{LOGICAL(2)} @tab GNU extension
3043 @item @code{BJTEST(I,POS)} @tab @code{INTEGER(4) I,POS} @tab @code{LOGICAL(4)} @tab GNU extension
3044 @item @code{BKTEST(I,POS)} @tab @code{INTEGER(8) I,POS} @tab @code{LOGICAL(8)} @tab GNU extension
3049 @section @code{C_ASSOCIATED} --- Status of a C pointer
3050 @fnindex C_ASSOCIATED
3051 @cindex association status, C pointer
3052 @cindex pointer, C association status
3055 @item @emph{Description}:
3056 @code{C_ASSOCIATED(c_ptr_1[, c_ptr_2])} determines the status of the C pointer
3057 @var{c_ptr_1} or if @var{c_ptr_1} is associated with the target @var{c_ptr_2}.
3059 @item @emph{Standard}:
3060 Fortran 2003 and later
3065 @item @emph{Syntax}:
3066 @code{RESULT = C_ASSOCIATED(c_ptr_1[, c_ptr_2])}
3068 @item @emph{Arguments}:
3069 @multitable @columnfractions .15 .70
3070 @item @var{c_ptr_1} @tab Scalar of the type @code{C_PTR} or @code{C_FUNPTR}.
3071 @item @var{c_ptr_2} @tab (Optional) Scalar of the same type as @var{c_ptr_1}.
3074 @item @emph{Return value}:
3075 The return value is of type @code{LOGICAL}; it is @code{.false.} if either
3076 @var{c_ptr_1} is a C NULL pointer or if @var{c_ptr1} and @var{c_ptr_2}
3077 point to different addresses.
3079 @item @emph{Example}:
3081 subroutine association_test(a,b)
3082 use iso_c_binding, only: c_associated, c_loc, c_ptr
3086 if(c_associated(b, c_loc(a))) &
3087 stop 'b and a do not point to same target'
3088 end subroutine association_test
3091 @item @emph{See also}:
3098 @section @code{C_F_POINTER} --- Convert C into Fortran pointer
3099 @fnindex C_F_POINTER
3100 @cindex pointer, convert C to Fortran
3103 @item @emph{Description}:
3104 @code{C_F_POINTER(CPTR, FPTR[, SHAPE])} assigns the target of the C pointer
3105 @var{CPTR} to the Fortran pointer @var{FPTR} and specifies its shape.
3107 @item @emph{Standard}:
3108 Fortran 2003 and later
3113 @item @emph{Syntax}:
3114 @code{CALL C_F_POINTER(CPTR, FPTR[, SHAPE])}
3116 @item @emph{Arguments}:
3117 @multitable @columnfractions .15 .70
3118 @item @var{CPTR} @tab scalar of the type @code{C_PTR}. It is
3120 @item @var{FPTR} @tab pointer interoperable with @var{cptr}. It is
3122 @item @var{SHAPE} @tab (Optional) Rank-one array of type @code{INTEGER}
3123 with @code{INTENT(IN)}. It shall be present
3124 if and only if @var{fptr} is an array. The size
3125 must be equal to the rank of @var{fptr}.
3128 @item @emph{Example}:
3134 subroutine my_routine(p) bind(c,name='myC_func')
3136 type(c_ptr), intent(out) :: p
3140 real,pointer :: a(:)
3141 call my_routine(cptr)
3142 call c_f_pointer(cptr, a, [12])
3146 @item @emph{See also}:
3148 @ref{C_F_PROCPOINTER}
3152 @node C_F_PROCPOINTER
3153 @section @code{C_F_PROCPOINTER} --- Convert C into Fortran procedure pointer
3154 @fnindex C_F_PROCPOINTER
3155 @cindex pointer, C address of pointers
3158 @item @emph{Description}:
3159 @code{C_F_PROCPOINTER(CPTR, FPTR)} Assign the target of the C function pointer
3160 @var{CPTR} to the Fortran procedure pointer @var{FPTR}.
3162 @item @emph{Standard}:
3163 Fortran 2003 and later
3168 @item @emph{Syntax}:
3169 @code{CALL C_F_PROCPOINTER(cptr, fptr)}
3171 @item @emph{Arguments}:
3172 @multitable @columnfractions .15 .70
3173 @item @var{CPTR} @tab scalar of the type @code{C_FUNPTR}. It is
3175 @item @var{FPTR} @tab procedure pointer interoperable with @var{cptr}. It is
3179 @item @emph{Example}:
3187 real(c_float), intent(in) :: a
3188 real(c_float) :: func
3192 function getIterFunc() bind(c,name="getIterFunc")
3194 type(c_funptr) :: getIterFunc
3197 type(c_funptr) :: cfunptr
3198 procedure(func), pointer :: myFunc
3199 cfunptr = getIterFunc()
3200 call c_f_procpointer(cfunptr, myFunc)
3204 @item @emph{See also}:
3211 @section @code{C_FUNLOC} --- Obtain the C address of a procedure
3213 @cindex pointer, C address of procedures
3216 @item @emph{Description}:
3217 @code{C_FUNLOC(x)} determines the C address of the argument.
3219 @item @emph{Standard}:
3220 Fortran 2003 and later
3225 @item @emph{Syntax}:
3226 @code{RESULT = C_FUNLOC(x)}
3228 @item @emph{Arguments}:
3229 @multitable @columnfractions .15 .70
3230 @item @var{x} @tab Interoperable function or pointer to such function.
3233 @item @emph{Return value}:
3234 The return value is of type @code{C_FUNPTR} and contains the C address
3237 @item @emph{Example}:
3243 subroutine sub(a) bind(c)
3253 subroutine my_routine(p) bind(c,name='myC_func')
3255 type(c_funptr), intent(in) :: p
3258 call my_routine(c_funloc(sub))
3262 @item @emph{See also}:
3263 @ref{C_ASSOCIATED}, @*
3265 @ref{C_F_POINTER}, @*
3266 @ref{C_F_PROCPOINTER}
3271 @section @code{C_LOC} --- Obtain the C address of an object
3273 @cindex procedure pointer, convert C to Fortran
3276 @item @emph{Description}:
3277 @code{C_LOC(X)} determines the C address of the argument.
3279 @item @emph{Standard}:
3280 Fortran 2003 and later
3285 @item @emph{Syntax}:
3286 @code{RESULT = C_LOC(X)}
3288 @item @emph{Arguments}:
3289 @multitable @columnfractions .10 .75
3290 @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.
3294 @item @emph{Return value}:
3295 The return value is of type @code{C_PTR} and contains the C address
3298 @item @emph{Example}:
3300 subroutine association_test(a,b)
3301 use iso_c_binding, only: c_associated, c_loc, c_ptr
3305 if(c_associated(b, c_loc(a))) &
3306 stop 'b and a do not point to same target'
3307 end subroutine association_test
3310 @item @emph{See also}:
3311 @ref{C_ASSOCIATED}, @*
3313 @ref{C_F_POINTER}, @*
3314 @ref{C_F_PROCPOINTER}
3319 @section @code{C_SIZEOF} --- Size in bytes of an expression
3321 @cindex expression size
3322 @cindex size of an expression
3325 @item @emph{Description}:
3326 @code{C_SIZEOF(X)} calculates the number of bytes of storage the
3327 expression @code{X} occupies.
3329 @item @emph{Standard}:
3333 Inquiry function of the module @code{ISO_C_BINDING}
3335 @item @emph{Syntax}:
3336 @code{N = C_SIZEOF(X)}
3338 @item @emph{Arguments}:
3339 @multitable @columnfractions .15 .70
3340 @item @var{X} @tab The argument shall be an interoperable data entity.
3343 @item @emph{Return value}:
3344 The return value is of type integer and of the system-dependent kind
3345 @code{C_SIZE_T} (from the @code{ISO_C_BINDING} module). Its value is the
3346 number of bytes occupied by the argument. If the argument has the
3347 @code{POINTER} attribute, the number of bytes of the storage area pointed
3348 to is returned. If the argument is of a derived type with @code{POINTER}
3349 or @code{ALLOCATABLE} components, the return value does not account for
3350 the sizes of the data pointed to by these components.
3352 @item @emph{Example}:
3356 real(c_float) :: r, s(5)
3357 print *, (c_sizeof(s)/c_sizeof(r) == 5)
3360 The example will print @code{T} unless you are using a platform
3361 where default @code{REAL} variables are unusually padded.
3363 @item @emph{See also}:
3370 @section @code{CEILING} --- Integer ceiling function
3373 @cindex rounding, ceiling
3376 @item @emph{Description}:
3377 @code{CEILING(A)} returns the least integer greater than or equal to @var{A}.
3379 @item @emph{Standard}:
3380 Fortran 95 and later
3385 @item @emph{Syntax}:
3386 @code{RESULT = CEILING(A [, KIND])}
3388 @item @emph{Arguments}:
3389 @multitable @columnfractions .15 .70
3390 @item @var{A} @tab The type shall be @code{REAL}.
3391 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
3392 expression indicating the kind parameter of the result.
3395 @item @emph{Return value}:
3396 The return value is of type @code{INTEGER(KIND)} if @var{KIND} is present
3397 and a default-kind @code{INTEGER} otherwise.
3399 @item @emph{Example}:
3401 program test_ceiling
3404 print *, ceiling(x) ! returns 64
3405 print *, ceiling(y) ! returns -63
3406 end program test_ceiling
3409 @item @emph{See also}:
3417 @section @code{CHAR} --- Character conversion function
3419 @cindex conversion, to character
3422 @item @emph{Description}:
3423 @code{CHAR(I [, KIND])} returns the character represented by the integer @var{I}.
3425 @item @emph{Standard}:
3426 Fortran 77 and later
3431 @item @emph{Syntax}:
3432 @code{RESULT = CHAR(I [, KIND])}
3434 @item @emph{Arguments}:
3435 @multitable @columnfractions .15 .70
3436 @item @var{I} @tab The type shall be @code{INTEGER}.
3437 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
3438 expression indicating the kind parameter of the result.
3441 @item @emph{Return value}:
3442 The return value is of type @code{CHARACTER(1)}
3444 @item @emph{Example}:
3450 print *, i, c ! returns 'J'
3451 end program test_char
3454 @item @emph{Specific names}:
3455 @multitable @columnfractions .19 .19 .25 .33
3456 @headitem Name @tab Argument @tab Return type @tab Standard
3457 @item @code{CHAR(I)} @tab @code{INTEGER I} @tab @code{CHARACTER(LEN=1)} @tab Fortran 77 and later
3461 See @ref{ICHAR} for a discussion of converting between numerical values
3462 and formatted string representations.
3464 @item @emph{See also}:
3474 @section @code{CHDIR} --- Change working directory
3476 @cindex system, working directory
3479 @item @emph{Description}:
3480 Change current working directory to a specified path.
3482 This intrinsic is provided in both subroutine and function forms; however,
3483 only one form can be used in any given program unit.
3485 @item @emph{Standard}:
3489 Subroutine, function
3491 @item @emph{Syntax}:
3492 @multitable @columnfractions .80
3493 @item @code{CALL CHDIR(NAME [, STATUS])}
3494 @item @code{STATUS = CHDIR(NAME)}
3497 @item @emph{Arguments}:
3498 @multitable @columnfractions .15 .70
3499 @item @var{NAME} @tab The type shall be @code{CHARACTER} of default
3500 kind and shall specify a valid path within the file system.
3501 @item @var{STATUS} @tab (Optional) @code{INTEGER} status flag of the default
3502 kind. Returns 0 on success, and a system specific and nonzero error code
3506 @item @emph{Example}:
3509 CHARACTER(len=255) :: path
3511 WRITE(*,*) TRIM(path)
3514 WRITE(*,*) TRIM(path)
3518 @item @emph{See also}:
3525 @section @code{CHMOD} --- Change access permissions of files
3527 @cindex file system, change access mode
3530 @item @emph{Description}:
3531 @code{CHMOD} changes the permissions of a file.
3533 This intrinsic is provided in both subroutine and function forms; however,
3534 only one form can be used in any given program unit.
3536 @item @emph{Standard}:
3540 Subroutine, function
3542 @item @emph{Syntax}:
3543 @multitable @columnfractions .80
3544 @item @code{CALL CHMOD(NAME, MODE[, STATUS])}
3545 @item @code{STATUS = CHMOD(NAME, MODE)}
3548 @item @emph{Arguments}:
3549 @multitable @columnfractions .15 .70
3551 @item @var{NAME} @tab Scalar @code{CHARACTER} of default kind with the
3552 file name. Trailing blanks are ignored unless the character
3553 @code{achar(0)} is present, then all characters up to and excluding
3554 @code{achar(0)} are used as the file name.
3556 @item @var{MODE} @tab Scalar @code{CHARACTER} of default kind giving the
3557 file permission. @var{MODE} uses the same syntax as the @code{chmod} utility
3558 as defined by the POSIX standard. The argument shall either be a string of
3559 a nonnegative octal number or a symbolic mode.
3561 @item @var{STATUS} @tab (optional) scalar @code{INTEGER}, which is
3562 @code{0} on success and nonzero otherwise.
3565 @item @emph{Return value}:
3566 In either syntax, @var{STATUS} is set to @code{0} on success and nonzero
3569 @item @emph{Example}:
3570 @code{CHMOD} as subroutine
3575 call chmod('test.dat','u+x',status)
3576 print *, 'Status: ', status
3577 end program chmod_test
3579 @code{CHMOD} as function:
3584 status = chmod('test.dat','u+x')
3585 print *, 'Status: ', status
3586 end program chmod_test
3594 @section @code{CMPLX} --- Complex conversion function
3596 @cindex complex numbers, conversion to
3597 @cindex conversion, to complex
3600 @item @emph{Description}:
3601 @code{CMPLX(X [, Y [, KIND]])} returns a complex number where @var{X} is converted to
3602 the real component. If @var{Y} is present it is converted to the imaginary
3603 component. If @var{Y} is not present then the imaginary component is set to
3604 0.0. If @var{X} is complex then @var{Y} must not be present.
3606 @item @emph{Standard}:
3607 Fortran 77 and later
3612 @item @emph{Syntax}:
3613 @code{RESULT = CMPLX(X [, Y [, KIND]])}
3615 @item @emph{Arguments}:
3616 @multitable @columnfractions .15 .70
3617 @item @var{X} @tab The type may be @code{INTEGER}, @code{REAL},
3619 @item @var{Y} @tab (Optional; only allowed if @var{X} is not
3620 @code{COMPLEX}.) May be @code{INTEGER} or @code{REAL}.
3621 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
3622 expression indicating the kind parameter of the result.
3625 @item @emph{Return value}:
3626 The return value is of @code{COMPLEX} type, with a kind equal to
3627 @var{KIND} if it is specified. If @var{KIND} is not specified, the
3628 result is of the default @code{COMPLEX} kind, regardless of the kinds of
3629 @var{X} and @var{Y}.
3631 @item @emph{Example}:
3638 print *, z, cmplx(x)
3639 end program test_cmplx
3642 @item @emph{See also}:
3649 @section @code{CO_BROADCAST} --- Copy a value to all images the current set of images
3650 @fnindex CO_BROADCAST
3651 @cindex Collectives, value broadcasting
3654 @item @emph{Description}:
3655 @code{CO_BROADCAST} copies the value of argument @var{A} on the image with
3656 image index @code{SOURCE_IMAGE} to all images in the current team. @var{A}
3657 becomes defined as if by intrinsic assignment. If the execution was
3658 successful and @var{STAT} is present, it is assigned the value zero. If the
3659 execution failed, @var{STAT} gets assigned a nonzero value and, if present,
3660 @var{ERRMSG} gets assigned a value describing the occurred error.
3662 @item @emph{Standard}:
3663 Technical Specification (TS) 18508 or later
3666 Collective subroutine
3668 @item @emph{Syntax}:
3669 @code{CALL CO_BROADCAST(A, SOURCE_IMAGE [, STAT, ERRMSG])}
3671 @item @emph{Arguments}:
3672 @multitable @columnfractions .20 .65
3673 @item @var{A} @tab INTENT(INOUT) argument; shall have the same
3674 dynamic type and type parameters on all images of the current team. If it
3675 is an array, it shall have the same shape on all images.
3676 @item @var{SOURCE_IMAGE} @tab a scalar integer expression.
3677 It shall have the same value on all images and refer to an
3678 image of the current team.
3679 @item @var{STAT} @tab (optional) a scalar integer variable
3680 @item @var{ERRMSG} @tab (optional) a scalar character variable
3683 @item @emph{Example}:
3687 if (this_image() == 1) then
3690 call co_broadcast (val, source_image=1)
3691 print *, this_image, ":", val
3695 @item @emph{See also}:
3705 @section @code{CO_MAX} --- Maximal value on the current set of images
3707 @cindex Collectives, maximal value
3710 @item @emph{Description}:
3711 @code{CO_MAX} determines element-wise the maximal value of @var{A} on all
3712 images of the current team. If @var{RESULT_IMAGE} is present, the maximum
3713 values are returned in @var{A} on the specified image only and the value
3714 of @var{A} on the other images become undefined. If @var{RESULT_IMAGE} is
3715 not present, the value is returned on all images. If the execution was
3716 successful and @var{STAT} is present, it is assigned the value zero. If the
3717 execution failed, @var{STAT} gets assigned a nonzero value and, if present,
3718 @var{ERRMSG} gets assigned a value describing the occurred error.
3720 @item @emph{Standard}:
3721 Technical Specification (TS) 18508 or later
3724 Collective subroutine
3726 @item @emph{Syntax}:
3727 @code{CALL CO_MAX(A [, RESULT_IMAGE, STAT, ERRMSG])}
3729 @item @emph{Arguments}:
3730 @multitable @columnfractions .20 .65
3731 @item @var{A} @tab shall be an integer, real or character variable,
3732 which has the same type and type parameters on all images of the team.
3733 @item @var{RESULT_IMAGE} @tab (optional) a scalar integer expression; if
3734 present, it shall have the same value on all images and refer to an
3735 image of the current team.
3736 @item @var{STAT} @tab (optional) a scalar integer variable
3737 @item @var{ERRMSG} @tab (optional) a scalar character variable
3740 @item @emph{Example}:
3745 call co_max (val, result_image=1)
3746 if (this_image() == 1) then
3747 write(*,*) "Maximal value", val ! prints num_images()
3752 @item @emph{See also}:
3762 @section @code{CO_MIN} --- Minimal value on the current set of images
3764 @cindex Collectives, minimal value
3767 @item @emph{Description}:
3768 @code{CO_MIN} determines element-wise the minimal value of @var{A} on all
3769 images of the current team. If @var{RESULT_IMAGE} is present, the minimal
3770 values are returned in @var{A} on the specified image only and the value
3771 of @var{A} on the other images become undefined. If @var{RESULT_IMAGE} is
3772 not present, the value is returned on all images. If the execution was
3773 successful and @var{STAT} is present, it is assigned the value zero. If the
3774 execution failed, @var{STAT} gets assigned a nonzero value and, if present,
3775 @var{ERRMSG} gets assigned a value describing the occurred error.
3777 @item @emph{Standard}:
3778 Technical Specification (TS) 18508 or later
3781 Collective subroutine
3783 @item @emph{Syntax}:
3784 @code{CALL CO_MIN(A [, RESULT_IMAGE, STAT, ERRMSG])}
3786 @item @emph{Arguments}:
3787 @multitable @columnfractions .20 .65
3788 @item @var{A} @tab shall be an integer, real or character variable,
3789 which has the same type and type parameters on all images of the team.
3790 @item @var{RESULT_IMAGE} @tab (optional) a scalar integer expression; if
3791 present, it shall have the same value on all images and refer to an
3792 image of the current team.
3793 @item @var{STAT} @tab (optional) a scalar integer variable
3794 @item @var{ERRMSG} @tab (optional) a scalar character variable
3797 @item @emph{Example}:
3802 call co_min (val, result_image=1)
3803 if (this_image() == 1) then
3804 write(*,*) "Minimal value", val ! prints 1
3809 @item @emph{See also}:
3819 @section @code{CO_REDUCE} --- Reduction of values on the current set of images
3821 @cindex Collectives, generic reduction
3824 @item @emph{Description}:
3825 @code{CO_REDUCE} determines element-wise the reduction of the value of @var{A}
3826 on all images of the current team. The pure function passed as @var{OPERATION}
3827 is used to pairwise reduce the values of @var{A} by passing either the value
3828 of @var{A} of different images or the result values of such a reduction as
3829 argument. If @var{A} is an array, the deduction is done element wise. If
3830 @var{RESULT_IMAGE} is present, the result values are returned in @var{A} on
3831 the specified image only and the value of @var{A} on the other images become
3832 undefined. If @var{RESULT_IMAGE} is not present, the value is returned on all
3833 images. If the execution was successful and @var{STAT} is present, it is
3834 assigned the value zero. If the execution failed, @var{STAT} gets assigned
3835 a nonzero value and, if present, @var{ERRMSG} gets assigned a value describing
3838 @item @emph{Standard}:
3839 Technical Specification (TS) 18508 or later
3842 Collective subroutine
3844 @item @emph{Syntax}:
3845 @code{CALL CO_REDUCE(A, OPERATION, [, RESULT_IMAGE, STAT, ERRMSG])}
3847 @item @emph{Arguments}:
3848 @multitable @columnfractions .20 .65
3849 @item @var{A} @tab is an @code{INTENT(INOUT)} argument and shall be
3850 nonpolymorphic. If it is allocatable, it shall be allocated; if it is a pointer,
3851 it shall be associated. @var{A} shall have the same type and type parameters on
3852 all images of the team; if it is an array, it shall have the same shape on all
3854 @item @var{OPERATION} @tab pure function with two scalar nonallocatable
3855 arguments, which shall be nonpolymorphic and have the same type and type
3856 parameters as @var{A}. The function shall return a nonallocatable scalar of
3857 the same type and type parameters as @var{A}. The function shall be the same on
3858 all images and with regards to the arguments mathematically commutative and
3859 associative. Note that @var{OPERATION} may not be an elemental function, unless
3860 it is an intrisic function.
3861 @item @var{RESULT_IMAGE} @tab (optional) a scalar integer expression; if
3862 present, it shall have the same value on all images and refer to an
3863 image of the current team.
3864 @item @var{STAT} @tab (optional) a scalar integer variable
3865 @item @var{ERRMSG} @tab (optional) a scalar character variable
3868 @item @emph{Example}:
3873 call co_reduce (val, result_image=1, operation=myprod)
3874 if (this_image() == 1) then
3875 write(*,*) "Product value", val ! prints num_images() factorial
3878 pure function myprod(a, b)
3879 integer, value :: a, b
3887 While the rules permit in principle an intrinsic function, none of the
3888 intrinsics in the standard fulfill the criteria of having a specific
3889 function, which takes two arguments of the same type and returning that
3892 @item @emph{See also}:
3902 @section @code{CO_SUM} --- Sum of values on the current set of images
3904 @cindex Collectives, sum of values
3907 @item @emph{Description}:
3908 @code{CO_SUM} sums up the values of each element of @var{A} on all
3909 images of the current team. If @var{RESULT_IMAGE} is present, the summed-up
3910 values are returned in @var{A} on the specified image only and the value
3911 of @var{A} on the other images become undefined. If @var{RESULT_IMAGE} is
3912 not present, the value is returned on all images. If the execution was
3913 successful and @var{STAT} is present, it is assigned the value zero. If the
3914 execution failed, @var{STAT} gets assigned a nonzero value and, if present,
3915 @var{ERRMSG} gets assigned a value describing the occurred error.
3917 @item @emph{Standard}:
3918 Technical Specification (TS) 18508 or later
3921 Collective subroutine
3923 @item @emph{Syntax}:
3924 @code{CALL CO_SUM(A [, RESULT_IMAGE, STAT, ERRMSG])}
3926 @item @emph{Arguments}:
3927 @multitable @columnfractions .20 .65
3928 @item @var{A} @tab shall be an integer, real or complex variable,
3929 which has the same type and type parameters on all images of the team.
3930 @item @var{RESULT_IMAGE} @tab (optional) a scalar integer expression; if
3931 present, it shall have the same value on all images and refer to an
3932 image of the current team.
3933 @item @var{STAT} @tab (optional) a scalar integer variable
3934 @item @var{ERRMSG} @tab (optional) a scalar character variable
3937 @item @emph{Example}:
3942 call co_sum (val, result_image=1)
3943 if (this_image() == 1) then
3944 write(*,*) "The sum is ", val ! prints (n**2 + n)/2,
3945 ! with n = num_images()
3950 @item @emph{See also}:
3959 @node COMMAND_ARGUMENT_COUNT
3960 @section @code{COMMAND_ARGUMENT_COUNT} --- Get number of command line arguments
3961 @fnindex COMMAND_ARGUMENT_COUNT
3962 @cindex command-line arguments
3963 @cindex command-line arguments, number of
3964 @cindex arguments, to program
3967 @item @emph{Description}:
3968 @code{COMMAND_ARGUMENT_COUNT} returns the number of arguments passed on the
3969 command line when the containing program was invoked.
3971 @item @emph{Standard}:
3972 Fortran 2003 and later
3977 @item @emph{Syntax}:
3978 @code{RESULT = COMMAND_ARGUMENT_COUNT()}
3980 @item @emph{Arguments}:
3981 @multitable @columnfractions .15 .70
3985 @item @emph{Return value}:
3986 The return value is an @code{INTEGER} of default kind.
3988 @item @emph{Example}:
3990 program test_command_argument_count
3992 count = command_argument_count()
3994 end program test_command_argument_count
3997 @item @emph{See also}:
3998 @ref{GET_COMMAND}, @*
3999 @ref{GET_COMMAND_ARGUMENT}
4004 @node COMPILER_OPTIONS
4005 @section @code{COMPILER_OPTIONS} --- Options passed to the compiler
4006 @fnindex COMPILER_OPTIONS
4007 @cindex flags inquiry function
4008 @cindex options inquiry function
4009 @cindex compiler flags inquiry function
4012 @item @emph{Description}:
4013 @code{COMPILER_OPTIONS} returns a string with the options used for
4016 @item @emph{Standard}:
4020 Inquiry function of the module @code{ISO_FORTRAN_ENV}
4022 @item @emph{Syntax}:
4023 @code{STR = COMPILER_OPTIONS()}
4025 @item @emph{Arguments}:
4028 @item @emph{Return value}:
4029 The return value is a default-kind string with system-dependent length.
4030 It contains the compiler flags used to compile the file, which called
4031 the @code{COMPILER_OPTIONS} intrinsic.
4033 @item @emph{Example}:
4036 print '(4a)', 'This file was compiled by ', &
4037 compiler_version(), ' using the options ', &
4042 @item @emph{See also}:
4043 @ref{COMPILER_VERSION}, @*
4044 @ref{ISO_FORTRAN_ENV}
4049 @node COMPILER_VERSION
4050 @section @code{COMPILER_VERSION} --- Compiler version string
4051 @fnindex COMPILER_VERSION
4052 @cindex compiler, name and version
4053 @cindex version of the compiler
4056 @item @emph{Description}:
4057 @code{COMPILER_VERSION} returns a string with the name and the
4058 version of the compiler.
4060 @item @emph{Standard}:
4064 Inquiry function of the module @code{ISO_FORTRAN_ENV}
4066 @item @emph{Syntax}:
4067 @code{STR = COMPILER_VERSION()}
4069 @item @emph{Arguments}:
4072 @item @emph{Return value}:
4073 The return value is a default-kind string with system-dependent length.
4074 It contains the name of the compiler and its version number.
4076 @item @emph{Example}:
4079 print '(4a)', 'This file was compiled by ', &
4080 compiler_version(), ' using the options ', &
4085 @item @emph{See also}:
4086 @ref{COMPILER_OPTIONS}, @*
4087 @ref{ISO_FORTRAN_ENV}
4093 @section @code{COMPLEX} --- Complex conversion function
4095 @cindex complex numbers, conversion to
4096 @cindex conversion, to complex
4099 @item @emph{Description}:
4100 @code{COMPLEX(X, Y)} returns a complex number where @var{X} is converted
4101 to the real component and @var{Y} is converted to the imaginary
4104 @item @emph{Standard}:
4110 @item @emph{Syntax}:
4111 @code{RESULT = COMPLEX(X, Y)}
4113 @item @emph{Arguments}:
4114 @multitable @columnfractions .15 .70
4115 @item @var{X} @tab The type may be @code{INTEGER} or @code{REAL}.
4116 @item @var{Y} @tab The type may be @code{INTEGER} or @code{REAL}.
4119 @item @emph{Return value}:
4120 If @var{X} and @var{Y} are both of @code{INTEGER} type, then the return
4121 value is of default @code{COMPLEX} type.
4123 If @var{X} and @var{Y} are of @code{REAL} type, or one is of @code{REAL}
4124 type and one is of @code{INTEGER} type, then the return value is of
4125 @code{COMPLEX} type with a kind equal to that of the @code{REAL}
4126 argument with the highest precision.
4128 @item @emph{Example}:
4130 program test_complex
4133 print *, complex(i, x)
4134 end program test_complex
4137 @item @emph{See also}:
4144 @section @code{CONJG} --- Complex conjugate function
4147 @cindex complex conjugate
4150 @item @emph{Description}:
4151 @code{CONJG(Z)} returns the conjugate of @var{Z}. If @var{Z} is @code{(x, y)}
4152 then the result is @code{(x, -y)}
4154 @item @emph{Standard}:
4155 Fortran 77 and later, has an overload that is a GNU extension
4160 @item @emph{Syntax}:
4163 @item @emph{Arguments}:
4164 @multitable @columnfractions .15 .70
4165 @item @var{Z} @tab The type shall be @code{COMPLEX}.
4168 @item @emph{Return value}:
4169 The return value is of type @code{COMPLEX}.
4171 @item @emph{Example}:
4174 complex :: z = (2.0, 3.0)
4175 complex(8) :: dz = (2.71_8, -3.14_8)
4180 end program test_conjg
4183 @item @emph{Specific names}:
4184 @multitable @columnfractions .20 .23 .20 .33
4185 @headitem Name @tab Argument @tab Return type @tab Standard
4186 @item @code{DCONJG(Z)} @tab @code{COMPLEX(8) Z} @tab @code{COMPLEX(8)} @tab GNU extension
4193 @section @code{COS} --- Cosine function
4199 @cindex trigonometric function, cosine
4203 @item @emph{Description}:
4204 @code{COS(X)} computes the cosine of @var{X}.
4206 @item @emph{Standard}:
4207 Fortran 77 and later, has overloads that are GNU extensions
4212 @item @emph{Syntax}:
4213 @code{RESULT = COS(X)}
4215 @item @emph{Arguments}:
4216 @multitable @columnfractions .15 .70
4217 @item @var{X} @tab The type shall be @code{REAL} or
4221 @item @emph{Return value}:
4222 The return value is of the same type and kind as @var{X}. The real part
4223 of the result is in radians. If @var{X} is of the type @code{REAL},
4224 the return value lies in the range @math{ -1 \leq \cos (x) \leq 1}.
4226 @item @emph{Example}:
4231 end program test_cos
4234 @item @emph{Specific names}:
4235 @multitable @columnfractions .20 .23 .20 .33
4236 @headitem Name @tab Argument @tab Return type @tab Standard
4237 @item @code{COS(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
4238 @item @code{DCOS(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
4239 @item @code{CCOS(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab Fortran 77 and later
4240 @item @code{ZCOS(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
4241 @item @code{CDCOS(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
4244 @item @emph{See also}:
4245 Inverse function: @*
4247 Degrees function: @*
4254 @section @code{COSD} --- Cosine function, degrees
4260 @cindex trigonometric function, cosine, degrees
4261 @cindex cosine, degrees
4264 @item @emph{Description}:
4265 @code{COSD(X)} computes the cosine of @var{X} in degrees.
4267 @item @emph{Standard}:
4273 @item @emph{Syntax}:
4274 @code{RESULT = COSD(X)}
4276 @item @emph{Arguments}:
4277 @multitable @columnfractions .15 .70
4278 @item @var{X} @tab The type shall be @code{REAL}.
4281 @item @emph{Return value}:
4282 The return value is of the same type and kind as @var{X} and
4283 lies in the range @math{ -1 \leq \cosd (x) \leq 1}.
4285 @item @emph{Example}:
4290 end program test_cosd
4293 @item @emph{Specific names}:
4294 @multitable @columnfractions .20 .23 .20 .33
4295 @headitem Name @tab Argument @tab Return type @tab Standard
4296 @item @code{COSD(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 2023
4297 @item @code{DCOSD(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
4298 @item @code{CCOSD(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab GNU extension
4299 @item @code{ZCOSD(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
4300 @item @code{CDCOSD(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
4303 @item @emph{See also}:
4304 Inverse function: @*
4306 Radians function: @*
4313 @section @code{COSH} --- Hyperbolic cosine function
4316 @cindex hyperbolic cosine
4317 @cindex hyperbolic function, cosine
4318 @cindex cosine, hyperbolic
4321 @item @emph{Description}:
4322 @code{COSH(X)} computes the hyperbolic cosine of @var{X}.
4324 @item @emph{Standard}:
4325 Fortran 77 and later, for a complex argument Fortran 2008 or later
4330 @item @emph{Syntax}:
4333 @item @emph{Arguments}:
4334 @multitable @columnfractions .15 .70
4335 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
4338 @item @emph{Return value}:
4339 The return value has same type and kind as @var{X}. If @var{X} is
4340 complex, the imaginary part of the result is in radians. If @var{X}
4341 is @code{REAL}, the return value has a lower bound of one,
4342 @math{\cosh (x) \geq 1}.
4344 @item @emph{Example}:
4347 real(8) :: x = 1.0_8
4349 end program test_cosh
4352 @item @emph{Specific names}:
4353 @multitable @columnfractions .20 .23 .20 .33
4354 @headitem Name @tab Argument @tab Return type @tab Standard
4355 @item @code{COSH(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
4356 @item @code{DCOSH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
4359 @item @emph{See also}:
4360 Inverse function: @*
4367 @section @code{COTAN} --- Cotangent function
4370 @cindex trigonometric function, cotangent
4374 @item @emph{Description}:
4375 @code{COTAN(X)} computes the cotangent of @var{X}. Equivalent to @code{COS(x)}
4376 divided by @code{SIN(x)}, or @code{1 / TAN(x)}.
4378 This function is for compatibility only and should be avoided in favor of
4379 standard constructs wherever possible.
4381 @item @emph{Standard}:
4382 GNU extension, enabled with @option{-fdec-math}.
4387 @item @emph{Syntax}:
4388 @code{RESULT = COTAN(X)}
4390 @item @emph{Arguments}:
4391 @multitable @columnfractions .15 .70
4392 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
4395 @item @emph{Return value}:
4396 The return value has same type and kind as @var{X}, and its value is in radians.
4398 @item @emph{Example}:
4401 real(8) :: x = 0.165_8
4403 end program test_cotan
4406 @item @emph{Specific names}:
4407 @multitable @columnfractions .20 .23 .20 .33
4408 @headitem Name @tab Argument @tab Return type @tab Standard
4409 @item @code{COTAN(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab GNU extension
4410 @item @code{DCOTAN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
4413 @item @emph{See also}:
4414 Converse function: @*
4416 Degrees function: @*
4423 @section @code{COTAND} --- Cotangent function, degrees
4426 @cindex trigonometric function, cotangent, degrees
4427 @cindex cotangent, degrees
4430 @item @emph{Description}:
4431 @code{COTAND(X)} computes the cotangent of @var{X} in degrees. Equivalent to
4432 @code{COSD(x)} divided by @code{SIND(x)}, or @code{1 / TAND(x)}.
4434 @item @emph{Standard}:
4437 This function is for compatibility only and should be avoided in favor of
4438 standard constructs wherever possible.
4443 @item @emph{Syntax}:
4444 @code{RESULT = COTAND(X)}
4446 @item @emph{Arguments}:
4447 @multitable @columnfractions .15 .70
4448 @item @var{X} @tab The type shall be @code{REAL}.
4451 @item @emph{Return value}:
4452 The return value has same type and kind as @var{X}, and its value is in degrees.
4454 @item @emph{Example}:
4457 real(8) :: x = 0.165_8
4459 end program test_cotand
4462 @item @emph{Specific names}:
4463 @multitable @columnfractions .20 .23 .20 .33
4464 @headitem Name @tab Argument @tab Return type @tab Standard
4465 @item @code{COTAND(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab GNU extension
4466 @item @code{DCOTAND(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
4469 @item @emph{See also}:
4470 Converse function: @*
4472 Radians function: @*
4479 @section @code{COUNT} --- Count function
4481 @cindex array, conditionally count elements
4482 @cindex array, element counting
4483 @cindex array, number of elements
4486 @item @emph{Description}:
4488 Counts the number of @code{.TRUE.} elements in a logical @var{MASK},
4489 or, if the @var{DIM} argument is supplied, counts the number of
4490 elements along each row of the array in the @var{DIM} direction.
4491 If the array has zero size, or all of the elements of @var{MASK} are
4492 @code{.FALSE.}, then the result is @code{0}.
4494 @item @emph{Standard}:
4495 Fortran 90 and later, with @var{KIND} argument Fortran 2003 and later
4498 Transformational function
4500 @item @emph{Syntax}:
4501 @code{RESULT = COUNT(MASK [, DIM, KIND])}
4503 @item @emph{Arguments}:
4504 @multitable @columnfractions .15 .70
4505 @item @var{MASK} @tab The type shall be @code{LOGICAL}.
4506 @item @var{DIM} @tab (Optional) The type shall be @code{INTEGER}.
4507 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
4508 expression indicating the kind parameter of the result.
4511 @item @emph{Return value}:
4512 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
4513 @var{KIND} is absent, the return value is of default integer kind.
4514 If @var{DIM} is present, the result is an array with a rank one less
4515 than the rank of @var{ARRAY}, and a size corresponding to the shape
4516 of @var{ARRAY} with the @var{DIM} dimension removed.
4518 @item @emph{Example}:
4521 integer, dimension(2,3) :: a, b
4522 logical, dimension(2,3) :: mask
4523 a = reshape( (/ 1, 2, 3, 4, 5, 6 /), (/ 2, 3 /))
4524 b = reshape( (/ 0, 7, 3, 4, 5, 8 /), (/ 2, 3 /))
4525 print '(3i3)', a(1,:)
4526 print '(3i3)', a(2,:)
4528 print '(3i3)', b(1,:)
4529 print '(3i3)', b(2,:)
4532 print '(3l3)', mask(1,:)
4533 print '(3l3)', mask(2,:)
4535 print '(3i3)', count(mask)
4537 print '(3i3)', count(mask, 1)
4539 print '(3i3)', count(mask, 2)
4540 end program test_count
4547 @section @code{CPU_TIME} --- CPU elapsed time in seconds
4549 @cindex time, elapsed
4552 @item @emph{Description}:
4553 Returns a @code{REAL} value representing the elapsed CPU time in
4554 seconds. This is useful for testing segments of code to determine
4557 If a time source is available, time will be reported with microsecond
4558 resolution. If no time source is available, @var{TIME} is set to
4561 Note that @var{TIME} may contain a, system dependent, arbitrary offset
4562 and may not start with @code{0.0}. For @code{CPU_TIME}, the absolute
4563 value is meaningless, only differences between subsequent calls to
4564 this subroutine, as shown in the example below, should be used.
4567 @item @emph{Standard}:
4568 Fortran 95 and later
4573 @item @emph{Syntax}:
4574 @code{CALL CPU_TIME(TIME)}
4576 @item @emph{Arguments}:
4577 @multitable @columnfractions .15 .70
4578 @item @var{TIME} @tab The type shall be @code{REAL} with @code{INTENT(OUT)}.
4581 @item @emph{Return value}:
4584 @item @emph{Example}:
4586 program test_cpu_time
4587 real :: start, finish
4588 call cpu_time(start)
4589 ! put code to test here
4590 call cpu_time(finish)
4591 print '("Time = ",f6.3," seconds.")',finish-start
4592 end program test_cpu_time
4595 @item @emph{See also}:
4596 @ref{SYSTEM_CLOCK}, @*
4603 @section @code{CSHIFT} --- Circular shift elements of an array
4605 @cindex array, shift circularly
4606 @cindex array, permutation
4607 @cindex array, rotate
4610 @item @emph{Description}:
4611 @code{CSHIFT(ARRAY, SHIFT [, DIM])} performs a circular shift on elements of
4612 @var{ARRAY} along the dimension of @var{DIM}. If @var{DIM} is omitted it is
4613 taken to be @code{1}. @var{DIM} is a scalar of type @code{INTEGER} in the
4614 range of @math{1 \leq DIM \leq n)} where @math{n} is the rank of @var{ARRAY}.
4615 If the rank of @var{ARRAY} is one, then all elements of @var{ARRAY} are shifted
4616 by @var{SHIFT} places. If rank is greater than one, then all complete rank one
4617 sections of @var{ARRAY} along the given dimension are shifted. Elements
4618 shifted out one end of each rank one section are shifted back in the other end.
4620 @item @emph{Standard}:
4621 Fortran 90 and later
4624 Transformational function
4626 @item @emph{Syntax}:
4627 @code{RESULT = CSHIFT(ARRAY, SHIFT [, DIM])}
4629 @item @emph{Arguments}:
4630 @multitable @columnfractions .15 .70
4631 @item @var{ARRAY} @tab Shall be an array of any type.
4632 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
4633 @item @var{DIM} @tab The type shall be @code{INTEGER}.
4636 @item @emph{Return value}:
4637 Returns an array of same type and rank as the @var{ARRAY} argument.
4639 @item @emph{Example}:
4642 integer, dimension(3,3) :: a
4643 a = reshape( (/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /), (/ 3, 3 /))
4644 print '(3i3)', a(1,:)
4645 print '(3i3)', a(2,:)
4646 print '(3i3)', a(3,:)
4647 a = cshift(a, SHIFT=(/1, 2, -1/), DIM=2)
4649 print '(3i3)', a(1,:)
4650 print '(3i3)', a(2,:)
4651 print '(3i3)', a(3,:)
4652 end program test_cshift
4659 @section @code{CTIME} --- Convert a time into a string
4661 @cindex time, conversion to string
4662 @cindex conversion, to string
4665 @item @emph{Description}:
4666 @code{CTIME} converts a system time value, such as returned by
4667 @ref{TIME8}, to a string. The output will be of the form @samp{Sat
4668 Aug 19 18:13:14 1995}.
4670 This intrinsic is provided in both subroutine and function forms; however,
4671 only one form can be used in any given program unit.
4673 @item @emph{Standard}:
4677 Subroutine, function
4679 @item @emph{Syntax}:
4680 @multitable @columnfractions .80
4681 @item @code{CALL CTIME(TIME, RESULT)}.
4682 @item @code{RESULT = CTIME(TIME)}.
4685 @item @emph{Arguments}:
4686 @multitable @columnfractions .15 .70
4687 @item @var{TIME} @tab The type shall be of type @code{INTEGER}.
4688 @item @var{RESULT} @tab The type shall be of type @code{CHARACTER} and
4689 of default kind. It is an @code{INTENT(OUT)} argument. If the length
4690 of this variable is too short for the time and date string to fit
4691 completely, it will be blank on procedure return.
4694 @item @emph{Return value}:
4695 The converted date and time as a string.
4697 @item @emph{Example}:
4701 character(len=30) :: date
4704 ! Do something, main part of the program
4707 print *, 'Program was started on ', date
4708 end program test_ctime
4711 @item @emph{See Also}:
4712 @ref{DATE_AND_TIME}, @*
4722 @section @code{DATE_AND_TIME} --- Date and time subroutine
4723 @fnindex DATE_AND_TIME
4724 @cindex date, current
4725 @cindex current date
4726 @cindex time, current
4727 @cindex current time
4730 @item @emph{Description}:
4731 @code{DATE_AND_TIME(DATE, TIME, ZONE, VALUES)} gets the corresponding date and
4732 time information from the real-time system clock. @var{DATE} is
4733 @code{INTENT(OUT)} and of the form ccyymmdd. @var{TIME} is @code{INTENT(OUT)}
4734 and of the form hhmmss.sss. @var{ZONE} is @code{INTENT(OUT)} and of the form
4735 (+-)hhmm, representing the difference with respect to Coordinated Universal
4736 Time (UTC). Unavailable time and date parameters return blanks.
4738 @var{VALUES} is @code{INTENT(OUT)} and provides the following:
4740 @multitable @columnfractions .15 .70
4741 @item @code{VALUES(1)}: @tab The year, including the century
4742 @item @code{VALUES(2)}: @tab The month of the year
4743 @item @code{VALUES(3)}: @tab The day of the month
4744 @item @code{VALUES(4)}: @tab The time difference from UTC in minutes
4745 @item @code{VALUES(5)}: @tab The hour of the day
4746 @item @code{VALUES(6)}: @tab The minutes of the hour
4747 @item @code{VALUES(7)}: @tab The seconds of the minute
4748 @item @code{VALUES(8)}: @tab The milliseconds of the second
4751 @item @emph{Standard}:
4752 Fortran 90 and later
4757 @item @emph{Syntax}:
4758 @code{CALL DATE_AND_TIME([DATE, TIME, ZONE, VALUES])}
4760 @item @emph{Arguments}:
4761 @multitable @columnfractions .15 .70
4762 @item @var{DATE} @tab (Optional) Scalar of type default @code{CHARACTER}.
4763 Recommended length is 8 or larger.
4764 @item @var{TIME} @tab (Optional) Scalar of type default @code{CHARACTER}.
4765 Recommended length is 10 or larger.
4766 @item @var{ZONE} @tab (Optional) Scalar of type default @code{CHARACTER}.
4767 Recommended length is 5 or larger.
4768 @item @var{VALUES}@tab (Optional) Rank-1 array of type @code{INTEGER} with
4769 a decimal exponent range of at least four and array size at least 8.
4772 @item @emph{Return value}:
4775 @item @emph{Example}:
4777 program test_time_and_date
4778 character(8) :: date
4779 character(10) :: time
4780 character(5) :: zone
4781 integer,dimension(8) :: values
4782 ! using keyword arguments
4783 call date_and_time(date,time,zone,values)
4784 call date_and_time(DATE=date,ZONE=zone)
4785 call date_and_time(TIME=time)
4786 call date_and_time(VALUES=values)
4787 print '(a,2x,a,2x,a)', date, time, zone
4788 print '(8i5)', values
4789 end program test_time_and_date
4792 @item @emph{See also}:
4800 @section @code{DBLE} --- Double conversion function
4802 @cindex conversion, to real
4805 @item @emph{Description}:
4806 @code{DBLE(A)} Converts @var{A} to double precision real type.
4808 @item @emph{Standard}:
4809 Fortran 77 and later
4814 @item @emph{Syntax}:
4815 @code{RESULT = DBLE(A)}
4817 @item @emph{Arguments}:
4818 @multitable @columnfractions .15 .70
4819 @item @var{A} @tab The type shall be @code{INTEGER}, @code{REAL},
4823 @item @emph{Return value}:
4824 The return value is of type double precision real.
4826 @item @emph{Example}:
4831 complex :: z = (2.3,1.14)
4832 print *, dble(x), dble(i), dble(z)
4833 end program test_dble
4836 @item @emph{See also}:
4843 @section @code{DCMPLX} --- Double complex conversion function
4845 @cindex complex numbers, conversion to
4846 @cindex conversion, to complex
4849 @item @emph{Description}:
4850 @code{DCMPLX(X [,Y])} returns a double complex number where @var{X} is
4851 converted to the real component. If @var{Y} is present it is converted to the
4852 imaginary component. If @var{Y} is not present then the imaginary component is
4853 set to 0.0. If @var{X} is complex then @var{Y} must not be present.
4855 @item @emph{Standard}:
4861 @item @emph{Syntax}:
4862 @code{RESULT = DCMPLX(X [, Y])}
4864 @item @emph{Arguments}:
4865 @multitable @columnfractions .15 .70
4866 @item @var{X} @tab The type may be @code{INTEGER}, @code{REAL},
4868 @item @var{Y} @tab (Optional if @var{X} is not @code{COMPLEX}.) May be
4869 @code{INTEGER} or @code{REAL}.
4872 @item @emph{Return value}:
4873 The return value is of type @code{COMPLEX(8)}
4875 @item @emph{Example}:
4885 print *, dcmplx(x,i)
4886 end program test_dcmplx
4892 @section @code{DIGITS} --- Significant binary digits function
4894 @cindex model representation, significant digits
4897 @item @emph{Description}:
4898 @code{DIGITS(X)} returns the number of significant binary digits of the internal
4899 model representation of @var{X}. For example, on a system using a 32-bit
4900 floating point representation, a default real number would likely return 24.
4902 @item @emph{Standard}:
4903 Fortran 90 and later
4908 @item @emph{Syntax}:
4909 @code{RESULT = DIGITS(X)}
4911 @item @emph{Arguments}:
4912 @multitable @columnfractions .15 .70
4913 @item @var{X} @tab The type may be @code{INTEGER} or @code{REAL}.
4916 @item @emph{Return value}:
4917 The return value is of type @code{INTEGER}.
4919 @item @emph{Example}:
4922 integer :: i = 12345
4928 end program test_digits
4935 @section @code{DIM} --- Positive difference
4939 @cindex positive difference
4942 @item @emph{Description}:
4943 @code{DIM(X,Y)} returns the difference @code{X-Y} if the result is positive;
4944 otherwise returns zero.
4946 @item @emph{Standard}:
4947 Fortran 77 and later
4952 @item @emph{Syntax}:
4953 @code{RESULT = DIM(X, Y)}
4955 @item @emph{Arguments}:
4956 @multitable @columnfractions .15 .70
4957 @item @var{X} @tab The type shall be @code{INTEGER} or @code{REAL}
4958 @item @var{Y} @tab The type shall be the same type and kind as @var{X}. (As
4959 a GNU extension, arguments of different kinds are permitted.)
4962 @item @emph{Return value}:
4963 The return value is of type @code{INTEGER} or @code{REAL}. (As a GNU
4964 extension, kind is the largest kind of the actual arguments.)
4966 @item @emph{Example}:
4972 x = dim(4.345_8, 2.111_8)
4975 end program test_dim
4978 @item @emph{Specific names}:
4979 @multitable @columnfractions .20 .26 .20 .30
4980 @headitem Name @tab Argument @tab Return type @tab Standard
4981 @item @code{DIM(X,Y)} @tab @code{REAL(4) X, Y} @tab @code{REAL(4)} @tab Fortran 77 and later
4982 @item @code{IDIM(X,Y)} @tab @code{INTEGER(4) X, Y} @tab @code{INTEGER(4)} @tab Fortran 77 and later
4983 @item @code{DDIM(X,Y)} @tab @code{REAL(8) X, Y} @tab @code{REAL(8)} @tab Fortran 77 and later
4990 @section @code{DOT_PRODUCT} --- Dot product function
4991 @fnindex DOT_PRODUCT
4993 @cindex vector product
4994 @cindex product, vector
4997 @item @emph{Description}:
4998 @code{DOT_PRODUCT(VECTOR_A, VECTOR_B)} computes the dot product multiplication
4999 of two vectors @var{VECTOR_A} and @var{VECTOR_B}. The two vectors may be
5000 either numeric or logical and must be arrays of rank one and of equal size. If
5001 the vectors are @code{INTEGER} or @code{REAL}, the result is
5002 @code{SUM(VECTOR_A*VECTOR_B)}. If the vectors are @code{COMPLEX}, the result
5003 is @code{SUM(CONJG(VECTOR_A)*VECTOR_B)}. If the vectors are @code{LOGICAL},
5004 the result is @code{ANY(VECTOR_A .AND. VECTOR_B)}.
5006 @item @emph{Standard}:
5007 Fortran 90 and later
5010 Transformational function
5012 @item @emph{Syntax}:
5013 @code{RESULT = DOT_PRODUCT(VECTOR_A, VECTOR_B)}
5015 @item @emph{Arguments}:
5016 @multitable @columnfractions .15 .70
5017 @item @var{VECTOR_A} @tab The type shall be numeric or @code{LOGICAL}, rank 1.
5018 @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.
5021 @item @emph{Return value}:
5022 If the arguments are numeric, the return value is a scalar of numeric type,
5023 @code{INTEGER}, @code{REAL}, or @code{COMPLEX}. If the arguments are
5024 @code{LOGICAL}, the return value is @code{.TRUE.} or @code{.FALSE.}.
5026 @item @emph{Example}:
5028 program test_dot_prod
5029 integer, dimension(3) :: a, b
5036 print *, dot_product(a,b)
5037 end program test_dot_prod
5044 @section @code{DPROD} --- Double product function
5046 @cindex product, double-precision
5049 @item @emph{Description}:
5050 @code{DPROD(X,Y)} returns the product @code{X*Y}.
5052 @item @emph{Standard}:
5053 Fortran 77 and later
5058 @item @emph{Syntax}:
5059 @code{RESULT = DPROD(X, Y)}
5061 @item @emph{Arguments}:
5062 @multitable @columnfractions .15 .70
5063 @item @var{X} @tab The type shall be @code{REAL}.
5064 @item @var{Y} @tab The type shall be @code{REAL}.
5067 @item @emph{Return value}:
5068 The return value is of type @code{REAL(8)}.
5070 @item @emph{Example}:
5078 end program test_dprod
5081 @item @emph{Specific names}:
5082 @multitable @columnfractions .20 .23 .20 .33
5083 @headitem Name @tab Argument @tab Return type @tab Standard
5084 @item @code{DPROD(X,Y)} @tab @code{REAL(4) X, Y} @tab @code{REAL(8)} @tab Fortran 77 and later
5091 @section @code{DREAL} --- Double real part function
5093 @cindex complex numbers, real part
5096 @item @emph{Description}:
5097 @code{DREAL(Z)} returns the real part of complex variable @var{Z}.
5099 @item @emph{Standard}:
5105 @item @emph{Syntax}:
5106 @code{RESULT = DREAL(A)}
5108 @item @emph{Arguments}:
5109 @multitable @columnfractions .15 .70
5110 @item @var{A} @tab The type shall be @code{COMPLEX(8)}.
5113 @item @emph{Return value}:
5114 The return value is of type @code{REAL(8)}.
5116 @item @emph{Example}:
5119 complex(8) :: z = (1.3_8,7.2_8)
5121 end program test_dreal
5124 @item @emph{See also}:
5132 @section @code{DSHIFTL} --- Combined left shift
5134 @cindex left shift, combined
5138 @item @emph{Description}:
5139 @code{DSHIFTL(I, J, SHIFT)} combines bits of @var{I} and @var{J}. The
5140 rightmost @var{SHIFT} bits of the result are the leftmost @var{SHIFT}
5141 bits of @var{J}, and the remaining bits are the rightmost bits of
5144 @item @emph{Standard}:
5145 Fortran 2008 and later
5150 @item @emph{Syntax}:
5151 @code{RESULT = DSHIFTL(I, J, SHIFT)}
5153 @item @emph{Arguments}:
5154 @multitable @columnfractions .15 .70
5155 @item @var{I} @tab Shall be of type @code{INTEGER} or a BOZ constant.
5156 @item @var{J} @tab Shall be of type @code{INTEGER} or a BOZ constant.
5157 If both @var{I} and @var{J} have integer type, then they shall have
5158 the same kind type parameter. @var{I} and @var{J} shall not both be
5160 @item @var{SHIFT} @tab Shall be of type @code{INTEGER}. It shall
5161 be nonnegative. If @var{I} is not a BOZ constant, then @var{SHIFT}
5162 shall be less than or equal to @code{BIT_SIZE(I)}; otherwise,
5163 @var{SHIFT} shall be less than or equal to @code{BIT_SIZE(J)}.
5166 @item @emph{Return value}:
5167 If either @var{I} or @var{J} is a BOZ constant, it is first converted
5168 as if by the intrinsic function @code{INT} to an integer type with the
5169 kind type parameter of the other.
5171 @item @emph{See also}:
5177 @section @code{DSHIFTR} --- Combined right shift
5179 @cindex right shift, combined
5180 @cindex shift, right
5183 @item @emph{Description}:
5184 @code{DSHIFTR(I, J, SHIFT)} combines bits of @var{I} and @var{J}. The
5185 leftmost @var{SHIFT} bits of the result are the rightmost @var{SHIFT}
5186 bits of @var{I}, and the remaining bits are the leftmost bits of
5189 @item @emph{Standard}:
5190 Fortran 2008 and later
5195 @item @emph{Syntax}:
5196 @code{RESULT = DSHIFTR(I, J, SHIFT)}
5198 @item @emph{Arguments}:
5199 @multitable @columnfractions .15 .70
5200 @item @var{I} @tab Shall be of type @code{INTEGER} or a BOZ constant.
5201 @item @var{J} @tab Shall be of type @code{INTEGER} or a BOZ constant.
5202 If both @var{I} and @var{J} have integer type, then they shall have
5203 the same kind type parameter. @var{I} and @var{J} shall not both be
5205 @item @var{SHIFT} @tab Shall be of type @code{INTEGER}. It shall
5206 be nonnegative. If @var{I} is not a BOZ constant, then @var{SHIFT}
5207 shall be less than or equal to @code{BIT_SIZE(I)}; otherwise,
5208 @var{SHIFT} shall be less than or equal to @code{BIT_SIZE(J)}.
5211 @item @emph{Return value}:
5212 If either @var{I} or @var{J} is a BOZ constant, it is first converted
5213 as if by the intrinsic function @code{INT} to an integer type with the
5214 kind type parameter of the other.
5216 @item @emph{See also}:
5222 @section @code{DTIME} --- Execution time subroutine (or function)
5224 @cindex time, elapsed
5225 @cindex elapsed time
5228 @item @emph{Description}:
5229 @code{DTIME(VALUES, TIME)} initially returns the number of seconds of runtime
5230 since the start of the process's execution in @var{TIME}. @var{VALUES}
5231 returns the user and system components of this time in @code{VALUES(1)} and
5232 @code{VALUES(2)} respectively. @var{TIME} is equal to @code{VALUES(1) +
5235 Subsequent invocations of @code{DTIME} return values accumulated since the
5236 previous invocation.
5238 On some systems, the underlying timings are represented using types with
5239 sufficiently small limits that overflows (wrap around) are possible, such as
5240 32-bit types. Therefore, the values returned by this intrinsic might be, or
5241 become, negative, or numerically less than previous values, during a single
5242 run of the compiled program.
5244 Please note, that this implementation is thread safe if used within OpenMP
5245 directives, i.e., its state will be consistent while called from multiple
5246 threads. However, if @code{DTIME} is called from multiple threads, the result
5247 is still the time since the last invocation. This may not give the intended
5248 results. If possible, use @code{CPU_TIME} instead.
5250 This intrinsic is provided in both subroutine and function forms; however,
5251 only one form can be used in any given program unit.
5253 @var{VALUES} and @var{TIME} are @code{INTENT(OUT)} and provide the following:
5255 @multitable @columnfractions .15 .70
5256 @item @code{VALUES(1)}: @tab User time in seconds.
5257 @item @code{VALUES(2)}: @tab System time in seconds.
5258 @item @code{TIME}: @tab Run time since start in seconds.
5261 @item @emph{Standard}:
5265 Subroutine, function
5267 @item @emph{Syntax}:
5268 @multitable @columnfractions .80
5269 @item @code{CALL DTIME(VALUES, TIME)}.
5270 @item @code{TIME = DTIME(VALUES)}, (not recommended).
5273 @item @emph{Arguments}:
5274 @multitable @columnfractions .15 .70
5275 @item @var{VALUES}@tab The type shall be @code{REAL(4), DIMENSION(2)}.
5276 @item @var{TIME}@tab The type shall be @code{REAL(4)}.
5279 @item @emph{Return value}:
5280 Elapsed time in seconds since the last invocation or since the start of program
5281 execution if not called before.
5283 @item @emph{Example}:
5287 real, dimension(2) :: tarray
5289 call dtime(tarray, result)
5293 do i=1,100000000 ! Just a delay
5296 call dtime(tarray, result)
5300 end program test_dtime
5303 @item @emph{See also}:
5311 @section @code{EOSHIFT} --- End-off shift elements of an array
5313 @cindex array, shift
5316 @item @emph{Description}:
5317 @code{EOSHIFT(ARRAY, SHIFT[, BOUNDARY, DIM])} performs an end-off shift on
5318 elements of @var{ARRAY} along the dimension of @var{DIM}. If @var{DIM} is
5319 omitted it is taken to be @code{1}. @var{DIM} is a scalar of type
5320 @code{INTEGER} in the range of @math{1 \leq DIM \leq n)} where @math{n} is the
5321 rank of @var{ARRAY}. If the rank of @var{ARRAY} is one, then all elements of
5322 @var{ARRAY} are shifted by @var{SHIFT} places. If rank is greater than one,
5323 then all complete rank one sections of @var{ARRAY} along the given dimension are
5324 shifted. Elements shifted out one end of each rank one section are dropped. If
5325 @var{BOUNDARY} is present then the corresponding value of from @var{BOUNDARY}
5326 is copied back in the other end. If @var{BOUNDARY} is not present then the
5327 following are copied in depending on the type of @var{ARRAY}.
5329 @multitable @columnfractions .15 .80
5330 @item @emph{Array Type} @tab @emph{Boundary Value}
5331 @item Numeric @tab 0 of the type and kind of @var{ARRAY}.
5332 @item Logical @tab @code{.FALSE.}.
5333 @item Character(@var{len}) @tab @var{len} blanks.
5336 @item @emph{Standard}:
5337 Fortran 90 and later
5340 Transformational function
5342 @item @emph{Syntax}:
5343 @code{RESULT = EOSHIFT(ARRAY, SHIFT [, BOUNDARY, DIM])}
5345 @item @emph{Arguments}:
5346 @multitable @columnfractions .15 .70
5347 @item @var{ARRAY} @tab May be any type, not scalar.
5348 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
5349 @item @var{BOUNDARY} @tab Same type as @var{ARRAY}.
5350 @item @var{DIM} @tab The type shall be @code{INTEGER}.
5353 @item @emph{Return value}:
5354 Returns an array of same type and rank as the @var{ARRAY} argument.
5356 @item @emph{Example}:
5358 program test_eoshift
5359 integer, dimension(3,3) :: a
5360 a = reshape( (/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /), (/ 3, 3 /))
5361 print '(3i3)', a(1,:)
5362 print '(3i3)', a(2,:)
5363 print '(3i3)', a(3,:)
5364 a = EOSHIFT(a, SHIFT=(/1, 2, 1/), BOUNDARY=-5, DIM=2)
5366 print '(3i3)', a(1,:)
5367 print '(3i3)', a(2,:)
5368 print '(3i3)', a(3,:)
5369 end program test_eoshift
5376 @section @code{EPSILON} --- Epsilon function
5378 @cindex model representation, epsilon
5381 @item @emph{Description}:
5382 @code{EPSILON(X)} returns the smallest number @var{E} of the same kind
5383 as @var{X} such that @math{1 + E > 1}.
5385 @item @emph{Standard}:
5386 Fortran 90 and later
5391 @item @emph{Syntax}:
5392 @code{RESULT = EPSILON(X)}
5394 @item @emph{Arguments}:
5395 @multitable @columnfractions .15 .70
5396 @item @var{X} @tab The type shall be @code{REAL}.
5399 @item @emph{Return value}:
5400 The return value is of same type as the argument.
5402 @item @emph{Example}:
5404 program test_epsilon
5409 end program test_epsilon
5416 @section @code{ERF} --- Error function
5418 @cindex error function
5421 @item @emph{Description}:
5422 @code{ERF(X)} computes the error function of @var{X}.
5424 @item @emph{Standard}:
5425 Fortran 2008 and later
5430 @item @emph{Syntax}:
5431 @code{RESULT = ERF(X)}
5433 @item @emph{Arguments}:
5434 @multitable @columnfractions .15 .70
5435 @item @var{X} @tab The type shall be @code{REAL}.
5438 @item @emph{Return value}:
5439 The return value is of type @code{REAL}, of the same kind as
5440 @var{X} and lies in the range @math{-1 \leq erf (x) \leq 1 }.
5442 @item @emph{Example}:
5445 real(8) :: x = 0.17_8
5447 end program test_erf
5450 @item @emph{Specific names}:
5451 @multitable @columnfractions .20 .23 .20 .33
5452 @headitem Name @tab Argument @tab Return type @tab Standard
5453 @item @code{DERF(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
5460 @section @code{ERFC} --- Error function
5462 @cindex error function, complementary
5465 @item @emph{Description}:
5466 @code{ERFC(X)} computes the complementary error function of @var{X}.
5468 @item @emph{Standard}:
5469 Fortran 2008 and later
5474 @item @emph{Syntax}:
5475 @code{RESULT = ERFC(X)}
5477 @item @emph{Arguments}:
5478 @multitable @columnfractions .15 .70
5479 @item @var{X} @tab The type shall be @code{REAL}.
5482 @item @emph{Return value}:
5483 The return value is of type @code{REAL} and of the same kind as @var{X}.
5484 It lies in the range @math{ 0 \leq erfc (x) \leq 2 }.
5486 @item @emph{Example}:
5489 real(8) :: x = 0.17_8
5491 end program test_erfc
5494 @item @emph{Specific names}:
5495 @multitable @columnfractions .20 .23 .20 .33
5496 @headitem Name @tab Argument @tab Return type @tab Standard
5497 @item @code{DERFC(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
5504 @section @code{ERFC_SCALED} --- Error function
5505 @fnindex ERFC_SCALED
5506 @cindex error function, complementary, exponentially-scaled
5509 @item @emph{Description}:
5510 @code{ERFC_SCALED(X)} computes the exponentially-scaled complementary
5511 error function of @var{X}.
5513 @item @emph{Standard}:
5514 Fortran 2008 and later
5519 @item @emph{Syntax}:
5520 @code{RESULT = ERFC_SCALED(X)}
5522 @item @emph{Arguments}:
5523 @multitable @columnfractions .15 .70
5524 @item @var{X} @tab The type shall be @code{REAL}.
5527 @item @emph{Return value}:
5528 The return value is of type @code{REAL} and of the same kind as @var{X}.
5530 @item @emph{Example}:
5532 program test_erfc_scaled
5533 real(8) :: x = 0.17_8
5535 end program test_erfc_scaled
5542 @section @code{ETIME} --- Execution time subroutine (or function)
5544 @cindex time, elapsed
5547 @item @emph{Description}:
5548 @code{ETIME(VALUES, TIME)} returns the number of seconds of runtime
5549 since the start of the process's execution in @var{TIME}. @var{VALUES}
5550 returns the user and system components of this time in @code{VALUES(1)} and
5551 @code{VALUES(2)} respectively. @var{TIME} is equal to @code{VALUES(1) + VALUES(2)}.
5553 On some systems, the underlying timings are represented using types with
5554 sufficiently small limits that overflows (wrap around) are possible, such as
5555 32-bit types. Therefore, the values returned by this intrinsic might be, or
5556 become, negative, or numerically less than previous values, during a single
5557 run of the compiled program.
5559 This intrinsic is provided in both subroutine and function forms; however,
5560 only one form can be used in any given program unit.
5562 @var{VALUES} and @var{TIME} are @code{INTENT(OUT)} and provide the following:
5564 @multitable @columnfractions .15 .70
5565 @item @code{VALUES(1)}: @tab User time in seconds.
5566 @item @code{VALUES(2)}: @tab System time in seconds.
5567 @item @code{TIME}: @tab Run time since start in seconds.
5570 @item @emph{Standard}:
5574 Subroutine, function
5576 @item @emph{Syntax}:
5577 @multitable @columnfractions .80
5578 @item @code{CALL ETIME(VALUES, TIME)}.
5579 @item @code{TIME = ETIME(VALUES)}, (not recommended).
5582 @item @emph{Arguments}:
5583 @multitable @columnfractions .15 .70
5584 @item @var{VALUES}@tab The type shall be @code{REAL(4), DIMENSION(2)}.
5585 @item @var{TIME}@tab The type shall be @code{REAL(4)}.
5588 @item @emph{Return value}:
5589 Elapsed time in seconds since the start of program execution.
5591 @item @emph{Example}:
5595 real, dimension(2) :: tarray
5597 call ETIME(tarray, result)
5601 do i=1,100000000 ! Just a delay
5604 call ETIME(tarray, result)
5608 end program test_etime
5611 @item @emph{See also}:
5619 @section @code{EVENT_QUERY} --- Query whether a coarray event has occurred
5620 @fnindex EVENT_QUERY
5621 @cindex Events, EVENT_QUERY
5624 @item @emph{Description}:
5625 @code{EVENT_QUERY} assignes the number of events to @var{COUNT} which have been
5626 posted to the @var{EVENT} variable and not yet been removed by calling
5627 @code{EVENT WAIT}. When @var{STAT} is present and the invocation was successful,
5628 it is assigned the value 0. If it is present and the invocation has failed,
5629 it is assigned a positive value and @var{COUNT} is assigned the value @math{-1}.
5631 @item @emph{Standard}:
5637 @item @emph{Syntax}:
5638 @code{CALL EVENT_QUERY (EVENT, COUNT [, STAT])}
5640 @item @emph{Arguments}:
5641 @multitable @columnfractions .15 .70
5642 @item @var{EVENT} @tab (intent(IN)) Scalar of type @code{EVENT_TYPE},
5643 defined in @code{ISO_FORTRAN_ENV}; shall not be coindexed.
5644 @item @var{COUNT} @tab (intent(out))Scalar integer with at least the
5645 precision of default integer.
5646 @item @var{STAT} @tab (optional) Scalar default-kind integer variable.
5649 @item @emph{Example}:
5654 type(event_type) :: event_value_has_been_set[*]
5656 if (this_image() == 1) then
5657 call event_query (event_value_has_been_set, cnt)
5658 if (cnt > 0) write(*,*) "Value has been set"
5659 elseif (this_image() == 2) then
5660 event post (event_value_has_been_set[1])
5669 @node EXECUTE_COMMAND_LINE
5670 @section @code{EXECUTE_COMMAND_LINE} --- Execute a shell command
5671 @fnindex EXECUTE_COMMAND_LINE
5672 @cindex system, system call
5673 @cindex command line
5676 @item @emph{Description}:
5677 @code{EXECUTE_COMMAND_LINE} runs a shell command, synchronously or
5680 The @code{COMMAND} argument is passed to the shell and executed (The
5681 shell is @code{sh} on Unix systems, and @code{cmd.exe} on Windows.).
5682 If @code{WAIT} is present and has the value false, the execution of
5683 the command is asynchronous if the system supports it; otherwise, the
5684 command is executed synchronously using the C library's @code{system}
5687 The three last arguments allow the user to get status information. After
5688 synchronous execution, @code{EXITSTAT} contains the integer exit code of
5689 the command, as returned by @code{system}. @code{CMDSTAT} is set to zero
5690 if the command line was executed (whatever its exit status was).
5691 @code{CMDMSG} is assigned an error message if an error has occurred.
5693 Note that the @code{system} function need not be thread-safe. It is
5694 the responsibility of the user to ensure that @code{system} is not
5695 called concurrently.
5697 For asynchronous execution on supported targets, the POSIX
5698 @code{posix_spawn} or @code{fork} functions are used. Also, a signal
5699 handler for the @code{SIGCHLD} signal is installed.
5701 @item @emph{Standard}:
5702 Fortran 2008 and later
5707 @item @emph{Syntax}:
5708 @code{CALL EXECUTE_COMMAND_LINE(COMMAND [, WAIT, EXITSTAT, CMDSTAT, CMDMSG ])}
5710 @item @emph{Arguments}:
5711 @multitable @columnfractions .15 .70
5712 @item @var{COMMAND} @tab Shall be a default @code{CHARACTER} scalar.
5713 @item @var{WAIT} @tab (Optional) Shall be a default @code{LOGICAL} scalar.
5714 @item @var{EXITSTAT} @tab (Optional) Shall be an @code{INTEGER} of the
5716 @item @var{CMDSTAT} @tab (Optional) Shall be an @code{INTEGER} of the
5718 @item @var{CMDMSG} @tab (Optional) Shall be an @code{CHARACTER} scalar of the
5722 @item @emph{Example}:
5727 call execute_command_line ("external_prog.exe", exitstat=i)
5728 print *, "Exit status of external_prog.exe was ", i
5730 call execute_command_line ("reindex_files.exe", wait=.false.)
5731 print *, "Now reindexing files in the background"
5733 end program test_exec
5739 Because this intrinsic is implemented in terms of the @code{system}
5740 function call, its behavior with respect to signaling is processor
5741 dependent. In particular, on POSIX-compliant systems, the SIGINT and
5742 SIGQUIT signals will be ignored, and the SIGCHLD will be blocked. As
5743 such, if the parent process is terminated, the child process might not be
5744 terminated alongside.
5747 @item @emph{See also}:
5754 @section @code{EXIT} --- Exit the program with status.
5756 @cindex program termination
5757 @cindex terminate program
5760 @item @emph{Description}:
5761 @code{EXIT} causes immediate termination of the program with status. If status
5762 is omitted it returns the canonical @emph{success} for the system. All Fortran
5763 I/O units are closed.
5765 @item @emph{Standard}:
5771 @item @emph{Syntax}:
5772 @code{CALL EXIT([STATUS])}
5774 @item @emph{Arguments}:
5775 @multitable @columnfractions .15 .70
5776 @item @var{STATUS} @tab Shall be an @code{INTEGER} of the default kind.
5779 @item @emph{Return value}:
5780 @code{STATUS} is passed to the parent process on exit.
5782 @item @emph{Example}:
5785 integer :: STATUS = 0
5786 print *, 'This program is going to exit.'
5788 end program test_exit
5791 @item @emph{See also}:
5799 @section @code{EXP} --- Exponential function
5805 @cindex exponential function
5806 @cindex logarithm function, inverse
5809 @item @emph{Description}:
5810 @code{EXP(X)} computes the base @math{e} exponential of @var{X}.
5812 @item @emph{Standard}:
5813 Fortran 77 and later, has overloads that are GNU extensions
5818 @item @emph{Syntax}:
5819 @code{RESULT = EXP(X)}
5821 @item @emph{Arguments}:
5822 @multitable @columnfractions .15 .70
5823 @item @var{X} @tab The type shall be @code{REAL} or
5827 @item @emph{Return value}:
5828 The return value has same type and kind as @var{X}.
5830 @item @emph{Example}:
5835 end program test_exp
5838 @item @emph{Specific names}:
5839 @multitable @columnfractions .20 .23 .20 .33
5840 @headitem Name @tab Argument @tab Return type @tab Standard
5841 @item @code{EXP(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
5842 @item @code{DEXP(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
5843 @item @code{CEXP(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab Fortran 77 and later
5844 @item @code{ZEXP(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
5845 @item @code{CDEXP(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
5852 @section @code{EXPONENT} --- Exponent function
5854 @cindex real number, exponent
5855 @cindex floating point, exponent
5858 @item @emph{Description}:
5859 @code{EXPONENT(X)} returns the value of the exponent part of @var{X}. If @var{X}
5860 is zero the value returned is zero.
5862 @item @emph{Standard}:
5863 Fortran 90 and later
5868 @item @emph{Syntax}:
5869 @code{RESULT = EXPONENT(X)}
5871 @item @emph{Arguments}:
5872 @multitable @columnfractions .15 .70
5873 @item @var{X} @tab The type shall be @code{REAL}.
5876 @item @emph{Return value}:
5877 The return value is of type default @code{INTEGER}.
5879 @item @emph{Example}:
5881 program test_exponent
5886 print *, exponent(0.0)
5887 end program test_exponent
5893 @node EXTENDS_TYPE_OF
5894 @section @code{EXTENDS_TYPE_OF} --- Query dynamic type for extension
5895 @fnindex EXTENDS_TYPE_OF
5898 @item @emph{Description}:
5899 Query dynamic type for extension.
5901 @item @emph{Standard}:
5902 Fortran 2003 and later
5907 @item @emph{Syntax}:
5908 @code{RESULT = EXTENDS_TYPE_OF(A, MOLD)}
5910 @item @emph{Arguments}:
5911 @multitable @columnfractions .15 .70
5912 @item @var{A} @tab Shall be an object of extensible declared type or
5913 unlimited polymorphic.
5914 @item @var{MOLD} @tab Shall be an object of extensible declared type or
5915 unlimited polymorphic.
5918 @item @emph{Return value}:
5919 The return value is a scalar of type default logical. It is true if and only if
5920 the dynamic type of A is an extension type of the dynamic type of MOLD.
5923 @item @emph{See also}:
5930 @section @code{FDATE} --- Get the current time as a string
5932 @cindex time, current
5933 @cindex current time
5934 @cindex date, current
5935 @cindex current date
5938 @item @emph{Description}:
5939 @code{FDATE(DATE)} returns the current date (using the same format as
5940 @ref{CTIME}) in @var{DATE}. It is equivalent to @code{CALL CTIME(DATE,
5943 This intrinsic is provided in both subroutine and function forms; however,
5944 only one form can be used in any given program unit.
5946 @item @emph{Standard}:
5950 Subroutine, function
5952 @item @emph{Syntax}:
5953 @multitable @columnfractions .80
5954 @item @code{CALL FDATE(DATE)}.
5955 @item @code{DATE = FDATE()}.
5958 @item @emph{Arguments}:
5959 @multitable @columnfractions .15 .70
5960 @item @var{DATE}@tab The type shall be of type @code{CHARACTER} of the
5961 default kind. It is an @code{INTENT(OUT)} argument. If the length of
5962 this variable is too short for the date and time string to fit
5963 completely, it will be blank on procedure return.
5966 @item @emph{Return value}:
5967 The current date and time as a string.
5969 @item @emph{Example}:
5973 character(len=30) :: date
5975 print *, 'Program started on ', date
5976 do i = 1, 100000000 ! Just a delay
5980 print *, 'Program ended on ', date
5981 end program test_fdate
5984 @item @emph{See also}:
5985 @ref{DATE_AND_TIME}, @*
5991 @section @code{FGET} --- Read a single character in stream mode from stdin
5993 @cindex read character, stream mode
5994 @cindex stream mode, read character
5995 @cindex file operation, read character
5998 @item @emph{Description}:
5999 Read a single character in stream mode from stdin by bypassing normal
6000 formatted output. Stream I/O should not be mixed with normal record-oriented
6001 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
6003 This intrinsic is provided in both subroutine and function forms; however,
6004 only one form can be used in any given program unit.
6006 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
6007 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
6008 Programmers should consider the use of new stream IO feature in new code
6009 for future portability. See also @ref{Fortran 2003 status}.
6011 @item @emph{Standard}:
6015 Subroutine, function
6017 @item @emph{Syntax}:
6018 @multitable @columnfractions .80
6019 @item @code{CALL FGET(C [, STATUS])}
6020 @item @code{STATUS = FGET(C)}
6023 @item @emph{Arguments}:
6024 @multitable @columnfractions .15 .70
6025 @item @var{C} @tab The type shall be @code{CHARACTER} and of default
6027 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
6028 Returns 0 on success, -1 on end-of-file, and a system specific positive
6029 error code otherwise.
6032 @item @emph{Example}:
6035 INTEGER, PARAMETER :: strlen = 100
6036 INTEGER :: status, i = 1
6037 CHARACTER(len=strlen) :: str = ""
6039 WRITE (*,*) 'Enter text:'
6041 CALL fget(str(i:i), status)
6042 if (status /= 0 .OR. i > strlen) exit
6045 WRITE (*,*) TRIM(str)
6049 @item @emph{See also}:
6058 @section @code{FGETC} --- Read a single character in stream mode
6060 @cindex read character, stream mode
6061 @cindex stream mode, read character
6062 @cindex file operation, read character
6065 @item @emph{Description}:
6066 Read a single character in stream mode by bypassing normal formatted output.
6067 Stream I/O should not be mixed with normal record-oriented (formatted or
6068 unformatted) I/O on the same unit; the results are unpredictable.
6070 This intrinsic is provided in both subroutine and function forms; however,
6071 only one form can be used in any given program unit.
6073 Note that the @code{FGET} intrinsic is provided for backwards compatibility
6074 with @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
6075 Programmers should consider the use of new stream IO feature in new code
6076 for future portability. See also @ref{Fortran 2003 status}.
6078 @item @emph{Standard}:
6082 Subroutine, function
6084 @item @emph{Syntax}:
6085 @multitable @columnfractions .80
6086 @item @code{CALL FGETC(UNIT, C [, STATUS])}
6087 @item @code{STATUS = FGETC(UNIT, C)}
6090 @item @emph{Arguments}:
6091 @multitable @columnfractions .15 .70
6092 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
6093 @item @var{C} @tab The type shall be @code{CHARACTER} and of default
6095 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
6096 Returns 0 on success, -1 on end-of-file and a system specific positive
6097 error code otherwise.
6100 @item @emph{Example}:
6103 INTEGER :: fd = 42, status
6106 OPEN(UNIT=fd, FILE="/etc/passwd", ACTION="READ", STATUS = "OLD")
6108 CALL fgetc(fd, c, status)
6109 IF (status /= 0) EXIT
6116 @item @emph{See also}:
6123 @section @code{FINDLOC} --- Search an array for a value
6128 @item @emph{Description}:
6129 Determines the location of the element in the array with the value
6130 given in the @var{VALUE} argument, or, if the @var{DIM} argument is
6131 supplied, determines the locations of the elements equal to the
6132 @var{VALUE} argument element along each
6133 row of the array in the @var{DIM} direction. If @var{MASK} is
6134 present, only the elements for which @var{MASK} is @code{.TRUE.} are
6135 considered. If more than one element in the array has the value
6136 @var{VALUE}, the location returned is that of the first such element
6137 in array element order if the @var{BACK} is not present or if it is
6138 @code{.FALSE.}. If @var{BACK} is true, the location returned is that
6139 of the last such element. If the array has zero size, or all of the
6140 elements of @var{MASK} are @code{.FALSE.}, then the result is an array
6141 of zeroes. Similarly, if @var{DIM} is supplied and all of the
6142 elements of @var{MASK} along a given row are zero, the result value
6143 for that row is zero.
6145 @item @emph{Standard}:
6146 Fortran 2008 and later.
6149 Transformational function
6151 @item @emph{Syntax}:
6152 @multitable @columnfractions .80
6153 @item @code{RESULT = FINDLOC(ARRAY, VALUE, DIM [, MASK] [,KIND] [,BACK])}
6154 @item @code{RESULT = FINDLOC(ARRAY, VALUE, [, MASK] [,KIND] [,BACK])}
6157 @item @emph{Arguments}:
6158 @multitable @columnfractions .15 .70
6159 @item @var{ARRAY} @tab Shall be an array of intrinsic type.
6160 @item @var{VALUE} @tab A scalar of intrinsic type which is in type
6161 conformance with @var{ARRAY}.
6162 @item @var{DIM} @tab (Optional) Shall be a scalar of type
6163 @code{INTEGER}, with a value between one and the rank of @var{ARRAY},
6164 inclusive. It may not be an optional dummy argument.
6165 @item @var{MASK} @tab (Optional) Shall be of type @code{LOGICAL},
6166 and conformable with @var{ARRAY}.
6167 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
6168 expression indicating the kind parameter of the result.
6169 @item @var{BACK} @tab (Optional) A scalar of type @code{LOGICAL}.
6172 @item @emph{Return value}:
6173 If @var{DIM} is absent, the result is a rank-one array with a length
6174 equal to the rank of @var{ARRAY}. If @var{DIM} is present, the result
6175 is an array with a rank one less than the rank of @var{ARRAY}, and a
6176 size corresponding to the size of @var{ARRAY} with the @var{DIM}
6177 dimension removed. If @var{DIM} is present and @var{ARRAY} has a rank
6178 of one, the result is a scalar. If the optional argument @var{KIND}
6179 is present, the result is an integer of kind @var{KIND}, otherwise it
6182 @item @emph{See also}:
6189 @section @code{FLOOR} --- Integer floor function
6192 @cindex rounding, floor
6195 @item @emph{Description}:
6196 @code{FLOOR(A)} returns the greatest integer less than or equal to @var{A}.
6198 @item @emph{Standard}:
6199 Fortran 95 and later
6204 @item @emph{Syntax}:
6205 @code{RESULT = FLOOR(A [, KIND])}
6207 @item @emph{Arguments}:
6208 @multitable @columnfractions .15 .70
6209 @item @var{A} @tab The type shall be @code{REAL}.
6210 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
6211 expression indicating the kind parameter of the result.
6214 @item @emph{Return value}:
6215 The return value is of type @code{INTEGER(KIND)} if @var{KIND} is present
6216 and of default-kind @code{INTEGER} otherwise.
6218 @item @emph{Example}:
6223 print *, floor(x) ! returns 63
6224 print *, floor(y) ! returns -64
6225 end program test_floor
6228 @item @emph{See also}:
6236 @section @code{FLUSH} --- Flush I/O unit(s)
6238 @cindex file operation, flush
6241 @item @emph{Description}:
6242 Flushes Fortran unit(s) currently open for output. Without the optional
6243 argument, all units are flushed, otherwise just the unit specified.
6245 @item @emph{Standard}:
6251 @item @emph{Syntax}:
6252 @code{CALL FLUSH(UNIT)}
6254 @item @emph{Arguments}:
6255 @multitable @columnfractions .15 .70
6256 @item @var{UNIT} @tab (Optional) The type shall be @code{INTEGER}.
6260 Beginning with the Fortran 2003 standard, there is a @code{FLUSH}
6261 statement that should be preferred over the @code{FLUSH} intrinsic.
6263 The @code{FLUSH} intrinsic and the Fortran 2003 @code{FLUSH} statement
6264 have identical effect: they flush the runtime library's I/O buffer so
6265 that the data becomes visible to other processes. This does not guarantee
6266 that the data is committed to disk.
6268 On POSIX systems, you can request that all data is transferred to the
6269 storage device by calling the @code{fsync} function, with the POSIX file
6270 descriptor of the I/O unit as argument (retrieved with GNU intrinsic
6271 @code{FNUM}). The following example shows how:
6274 ! Declare the interface for POSIX fsync function
6276 function fsync (fd) bind(c,name="fsync")
6277 use iso_c_binding, only: c_int
6278 integer(c_int), value :: fd
6279 integer(c_int) :: fsync
6283 ! Variable declaration
6287 open (10,file="foo")
6290 ! Perform I/O on unit 10
6295 ret = fsync(fnum(10))
6297 ! Handle possible error
6298 if (ret /= 0) stop "Error calling FSYNC"
6306 @section @code{FNUM} --- File number function
6308 @cindex file operation, file number
6311 @item @emph{Description}:
6312 @code{FNUM(UNIT)} returns the POSIX file descriptor number corresponding to the
6313 open Fortran I/O unit @code{UNIT}.
6315 @item @emph{Standard}:
6321 @item @emph{Syntax}:
6322 @code{RESULT = FNUM(UNIT)}
6324 @item @emph{Arguments}:
6325 @multitable @columnfractions .15 .70
6326 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
6329 @item @emph{Return value}:
6330 The return value is of type @code{INTEGER}
6332 @item @emph{Example}:
6336 open (unit=10, status = "scratch")
6340 end program test_fnum
6347 @section @code{FPUT} --- Write a single character in stream mode to stdout
6349 @cindex write character, stream mode
6350 @cindex stream mode, write character
6351 @cindex file operation, write character
6354 @item @emph{Description}:
6355 Write a single character in stream mode to stdout by bypassing normal
6356 formatted output. Stream I/O should not be mixed with normal record-oriented
6357 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
6359 This intrinsic is provided in both subroutine and function forms; however,
6360 only one form can be used in any given program unit.
6362 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
6363 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
6364 Programmers should consider the use of new stream IO feature in new code
6365 for future portability. See also @ref{Fortran 2003 status}.
6367 @item @emph{Standard}:
6371 Subroutine, function
6373 @item @emph{Syntax}:
6374 @multitable @columnfractions .80
6375 @item @code{CALL FPUT(C [, STATUS])}
6376 @item @code{STATUS = FPUT(C)}
6379 @item @emph{Arguments}:
6380 @multitable @columnfractions .15 .70
6381 @item @var{C} @tab The type shall be @code{CHARACTER} and of default
6383 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
6384 Returns 0 on success, -1 on end-of-file and a system specific positive
6385 error code otherwise.
6388 @item @emph{Example}:
6391 CHARACTER(len=10) :: str = "gfortran"
6393 DO i = 1, len_trim(str)
6399 @item @emph{See also}:
6408 @section @code{FPUTC} --- Write a single character in stream mode
6410 @cindex write character, stream mode
6411 @cindex stream mode, write character
6412 @cindex file operation, write character
6415 @item @emph{Description}:
6416 Write a single character in stream mode by bypassing normal formatted
6417 output. Stream I/O should not be mixed with normal record-oriented
6418 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
6420 This intrinsic is provided in both subroutine and function forms; however,
6421 only one form can be used in any given program unit.
6423 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
6424 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
6425 Programmers should consider the use of new stream IO feature in new code
6426 for future portability. See also @ref{Fortran 2003 status}.
6428 @item @emph{Standard}:
6432 Subroutine, function
6434 @item @emph{Syntax}:
6435 @multitable @columnfractions .80
6436 @item @code{CALL FPUTC(UNIT, C [, STATUS])}
6437 @item @code{STATUS = FPUTC(UNIT, C)}
6440 @item @emph{Arguments}:
6441 @multitable @columnfractions .15 .70
6442 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
6443 @item @var{C} @tab The type shall be @code{CHARACTER} and of default
6445 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
6446 Returns 0 on success, -1 on end-of-file and a system specific positive
6447 error code otherwise.
6450 @item @emph{Example}:
6453 CHARACTER(len=10) :: str = "gfortran"
6454 INTEGER :: fd = 42, i
6456 OPEN(UNIT = fd, FILE = "out", ACTION = "WRITE", STATUS="NEW")
6457 DO i = 1, len_trim(str)
6458 CALL fputc(fd, str(i:i))
6464 @item @emph{See also}:
6473 @section @code{FRACTION} --- Fractional part of the model representation
6475 @cindex real number, fraction
6476 @cindex floating point, fraction
6479 @item @emph{Description}:
6480 @code{FRACTION(X)} returns the fractional part of the model
6481 representation of @code{X}.
6483 @item @emph{Standard}:
6484 Fortran 90 and later
6489 @item @emph{Syntax}:
6490 @code{Y = FRACTION(X)}
6492 @item @emph{Arguments}:
6493 @multitable @columnfractions .15 .70
6494 @item @var{X} @tab The type of the argument shall be a @code{REAL}.
6497 @item @emph{Return value}:
6498 The return value is of the same type and kind as the argument.
6499 The fractional part of the model representation of @code{X} is returned;
6500 it is @code{X * RADIX(X)**(-EXPONENT(X))}.
6502 @item @emph{Example}:
6504 program test_fraction
6507 print *, fraction(x), x * radix(x)**(-exponent(x))
6508 end program test_fraction
6516 @section @code{FREE} --- Frees memory
6518 @cindex pointer, cray
6521 @item @emph{Description}:
6522 Frees memory previously allocated by @code{MALLOC}. The @code{FREE}
6523 intrinsic is an extension intended to be used with Cray pointers, and is
6524 provided in GNU Fortran to allow user to compile legacy code. For
6525 new code using Fortran 95 pointers, the memory de-allocation intrinsic is
6528 @item @emph{Standard}:
6534 @item @emph{Syntax}:
6535 @code{CALL FREE(PTR)}
6537 @item @emph{Arguments}:
6538 @multitable @columnfractions .15 .70
6539 @item @var{PTR} @tab The type shall be @code{INTEGER}. It represents the
6540 location of the memory that should be de-allocated.
6543 @item @emph{Return value}:
6546 @item @emph{Example}:
6547 See @code{MALLOC} for an example.
6549 @item @emph{See also}:
6556 @section @code{FSEEK} --- Low level file positioning subroutine
6558 @cindex file operation, seek
6559 @cindex file operation, position
6562 @item @emph{Description}:
6563 Moves @var{UNIT} to the specified @var{OFFSET}. If @var{WHENCE}
6564 is set to 0, the @var{OFFSET} is taken as an absolute value @code{SEEK_SET},
6565 if set to 1, @var{OFFSET} is taken to be relative to the current position
6566 @code{SEEK_CUR}, and if set to 2 relative to the end of the file @code{SEEK_END}.
6567 On error, @var{STATUS} is set to a nonzero value. If @var{STATUS} the seek
6570 This intrinsic routine is not fully backwards compatible with @command{g77}.
6571 In @command{g77}, the @code{FSEEK} takes a statement label instead of a
6572 @var{STATUS} variable. If FSEEK is used in old code, change
6574 CALL FSEEK(UNIT, OFFSET, WHENCE, *label)
6579 CALL FSEEK(UNIT, OFFSET, WHENCE, status)
6580 IF (status /= 0) GOTO label
6583 Please note that GNU Fortran provides the Fortran 2003 Stream facility.
6584 Programmers should consider the use of new stream IO feature in new code
6585 for future portability. See also @ref{Fortran 2003 status}.
6587 @item @emph{Standard}:
6593 @item @emph{Syntax}:
6594 @code{CALL FSEEK(UNIT, OFFSET, WHENCE[, STATUS])}
6596 @item @emph{Arguments}:
6597 @multitable @columnfractions .15 .70
6598 @item @var{UNIT} @tab Shall be a scalar of type @code{INTEGER}.
6599 @item @var{OFFSET} @tab Shall be a scalar of type @code{INTEGER}.
6600 @item @var{WHENCE} @tab Shall be a scalar of type @code{INTEGER}.
6601 Its value shall be either 0, 1 or 2.
6602 @item @var{STATUS} @tab (Optional) shall be a scalar of type
6606 @item @emph{Example}:
6609 INTEGER, PARAMETER :: SEEK_SET = 0, SEEK_CUR = 1, SEEK_END = 2
6610 INTEGER :: fd, offset, ierr
6616 OPEN(UNIT=fd, FILE="fseek.test")
6617 CALL FSEEK(fd, offset, SEEK_SET, ierr) ! move to OFFSET
6618 print *, FTELL(fd), ierr
6620 CALL FSEEK(fd, 0, SEEK_END, ierr) ! move to end
6621 print *, FTELL(fd), ierr
6623 CALL FSEEK(fd, 0, SEEK_SET, ierr) ! move to beginning
6624 print *, FTELL(fd), ierr
6630 @item @emph{See also}:
6637 @section @code{FSTAT} --- Get file status
6639 @cindex file system, file status
6642 @item @emph{Description}:
6643 @code{FSTAT} is identical to @ref{STAT}, except that information about an
6644 already opened file is obtained.
6646 The elements in @code{VALUES} are the same as described by @ref{STAT}.
6648 This intrinsic is provided in both subroutine and function forms; however,
6649 only one form can be used in any given program unit.
6651 @item @emph{Standard}:
6655 Subroutine, function
6657 @item @emph{Syntax}:
6658 @multitable @columnfractions .80
6659 @item @code{CALL FSTAT(UNIT, VALUES [, STATUS])}
6660 @item @code{STATUS = FSTAT(UNIT, VALUES)}
6663 @item @emph{Arguments}:
6664 @multitable @columnfractions .15 .70
6665 @item @var{UNIT} @tab An open I/O unit number of type @code{INTEGER}.
6666 @item @var{VALUES} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
6667 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}. Returns 0
6668 on success and a system specific error code otherwise.
6671 @item @emph{Example}:
6672 See @ref{STAT} for an example.
6674 @item @emph{See also}:
6684 @section @code{FTELL} --- Current stream position
6686 @cindex file operation, position
6689 @item @emph{Description}:
6690 Retrieves the current position within an open file.
6692 This intrinsic is provided in both subroutine and function forms; however,
6693 only one form can be used in any given program unit.
6695 @item @emph{Standard}:
6699 Subroutine, function
6701 @item @emph{Syntax}:
6702 @multitable @columnfractions .80
6703 @item @code{CALL FTELL(UNIT, OFFSET)}
6704 @item @code{OFFSET = FTELL(UNIT)}
6707 @item @emph{Arguments}:
6708 @multitable @columnfractions .15 .70
6709 @item @var{OFFSET} @tab Shall of type @code{INTEGER}.
6710 @item @var{UNIT} @tab Shall of type @code{INTEGER}.
6713 @item @emph{Return value}:
6714 In either syntax, @var{OFFSET} is set to the current offset of unit
6715 number @var{UNIT}, or to @math{-1} if the unit is not currently open.
6717 @item @emph{Example}:
6721 OPEN(10, FILE="temp.dat")
6727 @item @emph{See also}:
6734 @section @code{GAMMA} --- Gamma function
6737 @cindex Gamma function
6738 @cindex Factorial function
6741 @item @emph{Description}:
6742 @code{GAMMA(X)} computes Gamma (@math{\Gamma}) of @var{X}. For positive,
6743 integer values of @var{X} the Gamma function simplifies to the factorial
6744 function @math{\Gamma(x)=(x-1)!}.
6748 \Gamma(x) = \int_0^\infty t^{x-1}{\rm e}^{-t}\,{\rm d}t
6752 @item @emph{Standard}:
6753 Fortran 2008 and later
6758 @item @emph{Syntax}:
6761 @item @emph{Arguments}:
6762 @multitable @columnfractions .15 .70
6763 @item @var{X} @tab Shall be of type @code{REAL} and neither zero
6764 nor a negative integer.
6767 @item @emph{Return value}:
6768 The return value is of type @code{REAL} of the same kind as @var{X}.
6770 @item @emph{Example}:
6774 x = gamma(x) ! returns 1.0
6775 end program test_gamma
6778 @item @emph{Specific names}:
6779 @multitable @columnfractions .20 .23 .20 .33
6780 @headitem Name @tab Argument @tab Return type @tab Standard
6781 @item @code{DGAMMA(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
6784 @item @emph{See also}:
6785 Logarithm of the Gamma function: @*
6792 @section @code{GERROR} --- Get last system error message
6794 @cindex system, error handling
6797 @item @emph{Description}:
6798 Returns the system error message corresponding to the last system error.
6799 This resembles the functionality of @code{strerror(3)} in C.
6801 @item @emph{Standard}:
6807 @item @emph{Syntax}:
6808 @code{CALL GERROR(RESULT)}
6810 @item @emph{Arguments}:
6811 @multitable @columnfractions .15 .70
6812 @item @var{RESULT} @tab Shall be of type @code{CHARACTER} and of default kind.
6815 @item @emph{Example}:
6818 CHARACTER(len=100) :: msg
6824 @item @emph{See also}:
6832 @section @code{GETARG} --- Get command line arguments
6834 @cindex command-line arguments
6835 @cindex arguments, to program
6838 @item @emph{Description}:
6839 Retrieve the @var{POS}-th argument that was passed on the
6840 command line when the containing program was invoked.
6842 This intrinsic routine is provided for backwards compatibility with
6843 GNU Fortran 77. In new code, programmers should consider the use of
6844 the @ref{GET_COMMAND_ARGUMENT} intrinsic defined by the Fortran 2003
6847 @item @emph{Standard}:
6853 @item @emph{Syntax}:
6854 @code{CALL GETARG(POS, VALUE)}
6856 @item @emph{Arguments}:
6857 @multitable @columnfractions .15 .70
6858 @item @var{POS} @tab Shall be of type @code{INTEGER} and not wider than
6859 the default integer kind; @math{@var{POS} \geq 0}
6860 @item @var{VALUE} @tab Shall be of type @code{CHARACTER} and of default
6864 @item @emph{Return value}:
6865 After @code{GETARG} returns, the @var{VALUE} argument holds the
6866 @var{POS}th command line argument. If @var{VALUE} cannot hold the
6867 argument, it is truncated to fit the length of @var{VALUE}. If there are
6868 less than @var{POS} arguments specified at the command line, @var{VALUE}
6869 will be filled with blanks. If @math{@var{POS} = 0}, @var{VALUE} is set
6870 to the name of the program (on systems that support this feature).
6872 @item @emph{Example}:
6876 CHARACTER(len=32) :: arg
6885 @item @emph{See also}:
6886 GNU Fortran 77 compatibility function: @*
6888 Fortran 2003 functions and subroutines: @*
6889 @ref{GET_COMMAND}, @*
6890 @ref{GET_COMMAND_ARGUMENT}, @*
6891 @ref{COMMAND_ARGUMENT_COUNT}
6897 @section @code{GET_COMMAND} --- Get the entire command line
6898 @fnindex GET_COMMAND
6899 @cindex command-line arguments
6900 @cindex arguments, to program
6903 @item @emph{Description}:
6904 Retrieve the entire command line that was used to invoke the program.
6906 @item @emph{Standard}:
6907 Fortran 2003 and later
6912 @item @emph{Syntax}:
6913 @code{CALL GET_COMMAND([COMMAND, LENGTH, STATUS])}
6915 @item @emph{Arguments}:
6916 @multitable @columnfractions .15 .70
6917 @item @var{COMMAND} @tab (Optional) shall be of type @code{CHARACTER} and
6919 @item @var{LENGTH} @tab (Optional) Shall be of type @code{INTEGER} and of
6921 @item @var{STATUS} @tab (Optional) Shall be of type @code{INTEGER} and of
6925 @item @emph{Return value}:
6926 If @var{COMMAND} is present, stores the entire command line that was used
6927 to invoke the program in @var{COMMAND}. If @var{LENGTH} is present, it is
6928 assigned the length of the command line. If @var{STATUS} is present, it
6929 is assigned 0 upon success of the command, -1 if @var{COMMAND} is too
6930 short to store the command line, or a positive value in case of an error.
6932 @item @emph{Example}:
6934 PROGRAM test_get_command
6935 CHARACTER(len=255) :: cmd
6936 CALL get_command(cmd)
6937 WRITE (*,*) TRIM(cmd)
6941 @item @emph{See also}:
6942 @ref{GET_COMMAND_ARGUMENT}, @*
6943 @ref{COMMAND_ARGUMENT_COUNT}
6948 @node GET_COMMAND_ARGUMENT
6949 @section @code{GET_COMMAND_ARGUMENT} --- Get command line arguments
6950 @fnindex GET_COMMAND_ARGUMENT
6951 @cindex command-line arguments
6952 @cindex arguments, to program
6955 @item @emph{Description}:
6956 Retrieve the @var{NUMBER}-th argument that was passed on the
6957 command line when the containing program was invoked.
6959 @item @emph{Standard}:
6960 Fortran 2003 and later
6965 @item @emph{Syntax}:
6966 @code{CALL GET_COMMAND_ARGUMENT(NUMBER [, VALUE, LENGTH, STATUS])}
6968 @item @emph{Arguments}:
6969 @multitable @columnfractions .15 .70
6970 @item @var{NUMBER} @tab Shall be a scalar of type @code{INTEGER} and of
6971 default kind, @math{@var{NUMBER} \geq 0}
6972 @item @var{VALUE} @tab (Optional) Shall be a scalar of type @code{CHARACTER}
6973 and of default kind.
6974 @item @var{LENGTH} @tab (Optional) Shall be a scalar of type @code{INTEGER}
6975 and of default kind.
6976 @item @var{STATUS} @tab (Optional) Shall be a scalar of type @code{INTEGER}
6977 and of default kind.
6980 @item @emph{Return value}:
6981 After @code{GET_COMMAND_ARGUMENT} returns, the @var{VALUE} argument holds the
6982 @var{NUMBER}-th command line argument. If @var{VALUE} cannot hold the argument, it is
6983 truncated to fit the length of @var{VALUE}. If there are less than @var{NUMBER}
6984 arguments specified at the command line, @var{VALUE} will be filled with blanks.
6985 If @math{@var{NUMBER} = 0}, @var{VALUE} is set to the name of the program (on
6986 systems that support this feature). The @var{LENGTH} argument contains the
6987 length of the @var{NUMBER}-th command line argument. If the argument retrieval
6988 fails, @var{STATUS} is a positive number; if @var{VALUE} contains a truncated
6989 command line argument, @var{STATUS} is -1; and otherwise the @var{STATUS} is
6992 @item @emph{Example}:
6994 PROGRAM test_get_command_argument
6996 CHARACTER(len=32) :: arg
7000 CALL get_command_argument(i, arg)
7001 IF (LEN_TRIM(arg) == 0) EXIT
7003 WRITE (*,*) TRIM(arg)
7009 @item @emph{See also}:
7010 @ref{GET_COMMAND}, @*
7011 @ref{COMMAND_ARGUMENT_COUNT}
7017 @section @code{GETCWD} --- Get current working directory
7019 @cindex system, working directory
7022 @item @emph{Description}:
7023 Get current working directory.
7025 This intrinsic is provided in both subroutine and function forms; however,
7026 only one form can be used in any given program unit.
7028 @item @emph{Standard}:
7032 Subroutine, function
7034 @item @emph{Syntax}:
7035 @multitable @columnfractions .80
7036 @item @code{CALL GETCWD(C [, STATUS])}
7037 @item @code{STATUS = GETCWD(C)}
7040 @item @emph{Arguments}:
7041 @multitable @columnfractions .15 .70
7042 @item @var{C} @tab The type shall be @code{CHARACTER} and of default kind.
7043 @item @var{STATUS} @tab (Optional) status flag. Returns 0 on success,
7044 a system specific and nonzero error code otherwise.
7047 @item @emph{Example}:
7050 CHARACTER(len=255) :: cwd
7052 WRITE(*,*) TRIM(cwd)
7056 @item @emph{See also}:
7063 @section @code{GETENV} --- Get an environmental variable
7065 @cindex environment variable
7068 @item @emph{Description}:
7069 Get the @var{VALUE} of the environmental variable @var{NAME}.
7071 This intrinsic routine is provided for backwards compatibility with
7072 GNU Fortran 77. In new code, programmers should consider the use of
7073 the @ref{GET_ENVIRONMENT_VARIABLE} intrinsic defined by the Fortran
7076 Note that @code{GETENV} need not be thread-safe. It is the
7077 responsibility of the user to ensure that the environment is not being
7078 updated concurrently with a call to the @code{GETENV} intrinsic.
7080 @item @emph{Standard}:
7086 @item @emph{Syntax}:
7087 @code{CALL GETENV(NAME, VALUE)}
7089 @item @emph{Arguments}:
7090 @multitable @columnfractions .15 .70
7091 @item @var{NAME} @tab Shall be of type @code{CHARACTER} and of default kind.
7092 @item @var{VALUE} @tab Shall be of type @code{CHARACTER} and of default kind.
7095 @item @emph{Return value}:
7096 Stores the value of @var{NAME} in @var{VALUE}. If @var{VALUE} is
7097 not large enough to hold the data, it is truncated. If @var{NAME}
7098 is not set, @var{VALUE} will be filled with blanks.
7100 @item @emph{Example}:
7103 CHARACTER(len=255) :: homedir
7104 CALL getenv("HOME", homedir)
7105 WRITE (*,*) TRIM(homedir)
7109 @item @emph{See also}:
7110 @ref{GET_ENVIRONMENT_VARIABLE}
7115 @node GET_ENVIRONMENT_VARIABLE
7116 @section @code{GET_ENVIRONMENT_VARIABLE} --- Get an environmental variable
7117 @fnindex GET_ENVIRONMENT_VARIABLE
7118 @cindex environment variable
7121 @item @emph{Description}:
7122 Get the @var{VALUE} of the environmental variable @var{NAME}.
7124 Note that @code{GET_ENVIRONMENT_VARIABLE} need not be thread-safe. It
7125 is the responsibility of the user to ensure that the environment is
7126 not being updated concurrently with a call to the
7127 @code{GET_ENVIRONMENT_VARIABLE} intrinsic.
7129 @item @emph{Standard}:
7130 Fortran 2003 and later
7135 @item @emph{Syntax}:
7136 @code{CALL GET_ENVIRONMENT_VARIABLE(NAME[, VALUE, LENGTH, STATUS, TRIM_NAME)}
7138 @item @emph{Arguments}:
7139 @multitable @columnfractions .15 .70
7140 @item @var{NAME} @tab Shall be a scalar of type @code{CHARACTER}
7141 and of default kind.
7142 @item @var{VALUE} @tab (Optional) Shall be a scalar of type @code{CHARACTER}
7143 and of default kind.
7144 @item @var{LENGTH} @tab (Optional) Shall be a scalar of type @code{INTEGER}
7145 and of default kind.
7146 @item @var{STATUS} @tab (Optional) Shall be a scalar of type @code{INTEGER}
7147 and of default kind.
7148 @item @var{TRIM_NAME} @tab (Optional) Shall be a scalar of type @code{LOGICAL}
7149 and of default kind.
7152 @item @emph{Return value}:
7153 Stores the value of @var{NAME} in @var{VALUE}. If @var{VALUE} is
7154 not large enough to hold the data, it is truncated. If @var{NAME}
7155 is not set, @var{VALUE} will be filled with blanks. Argument @var{LENGTH}
7156 contains the length needed for storing the environment variable @var{NAME}
7157 or zero if it is not present. @var{STATUS} is -1 if @var{VALUE} is present
7158 but too short for the environment variable; it is 1 if the environment
7159 variable does not exist and 2 if the processor does not support environment
7160 variables; in all other cases @var{STATUS} is zero. If @var{TRIM_NAME} is
7161 present with the value @code{.FALSE.}, the trailing blanks in @var{NAME}
7162 are significant; otherwise they are not part of the environment variable
7165 @item @emph{Example}:
7168 CHARACTER(len=255) :: homedir
7169 CALL get_environment_variable("HOME", homedir)
7170 WRITE (*,*) TRIM(homedir)
7178 @section @code{GETGID} --- Group ID function
7180 @cindex system, group ID
7183 @item @emph{Description}:
7184 Returns the numerical group ID of the current process.
7186 @item @emph{Standard}:
7192 @item @emph{Syntax}:
7193 @code{RESULT = GETGID()}
7195 @item @emph{Return value}:
7196 The return value of @code{GETGID} is an @code{INTEGER} of the default
7200 @item @emph{Example}:
7201 See @code{GETPID} for an example.
7203 @item @emph{See also}:
7211 @section @code{GETLOG} --- Get login name
7213 @cindex system, login name
7217 @item @emph{Description}:
7218 Gets the username under which the program is running.
7220 @item @emph{Standard}:
7226 @item @emph{Syntax}:
7227 @code{CALL GETLOG(C)}
7229 @item @emph{Arguments}:
7230 @multitable @columnfractions .15 .70
7231 @item @var{C} @tab Shall be of type @code{CHARACTER} and of default kind.
7234 @item @emph{Return value}:
7235 Stores the current user name in @var{C}. (On systems where POSIX
7236 functions @code{geteuid} and @code{getpwuid} are not available, and
7237 the @code{getlogin} function is not implemented either, this will
7238 return a blank string.)
7240 @item @emph{Example}:
7243 CHARACTER(32) :: login
7249 @item @emph{See also}:
7256 @section @code{GETPID} --- Process ID function
7258 @cindex system, process ID
7262 @item @emph{Description}:
7263 Returns the numerical process identifier of the current process.
7265 @item @emph{Standard}:
7271 @item @emph{Syntax}:
7272 @code{RESULT = GETPID()}
7274 @item @emph{Return value}:
7275 The return value of @code{GETPID} is an @code{INTEGER} of the default
7279 @item @emph{Example}:
7282 print *, "The current process ID is ", getpid()
7283 print *, "Your numerical user ID is ", getuid()
7284 print *, "Your numerical group ID is ", getgid()
7288 @item @emph{See also}:
7296 @section @code{GETUID} --- User ID function
7298 @cindex system, user ID
7302 @item @emph{Description}:
7303 Returns the numerical user ID of the current process.
7305 @item @emph{Standard}:
7311 @item @emph{Syntax}:
7312 @code{RESULT = GETUID()}
7314 @item @emph{Return value}:
7315 The return value of @code{GETUID} is an @code{INTEGER} of the default
7319 @item @emph{Example}:
7320 See @code{GETPID} for an example.
7322 @item @emph{See also}:
7330 @section @code{GMTIME} --- Convert time to GMT info
7332 @cindex time, conversion to GMT info
7335 @item @emph{Description}:
7336 Given a system time value @var{TIME} (as provided by the @ref{TIME}
7337 intrinsic), fills @var{VALUES} with values extracted from it appropriate
7338 to the UTC time zone (Universal Coordinated Time, also known in some
7339 countries as GMT, Greenwich Mean Time), using @code{gmtime(3)}.
7341 This intrinsic routine is provided for backwards compatibility with
7342 GNU Fortran 77. In new code, programmers should consider the use of
7343 the @ref{DATE_AND_TIME} intrinsic defined by the Fortran 95
7346 @item @emph{Standard}:
7352 @item @emph{Syntax}:
7353 @code{CALL GMTIME(TIME, VALUES)}
7355 @item @emph{Arguments}:
7356 @multitable @columnfractions .15 .70
7357 @item @var{TIME} @tab An @code{INTEGER} scalar expression
7358 corresponding to a system time, with @code{INTENT(IN)}.
7359 @item @var{VALUES} @tab A default @code{INTEGER} array with 9 elements,
7360 with @code{INTENT(OUT)}.
7363 @item @emph{Return value}:
7364 The elements of @var{VALUES} are assigned as follows:
7366 @item Seconds after the minute, range 0--59 or 0--61 to allow for leap
7368 @item Minutes after the hour, range 0--59
7369 @item Hours past midnight, range 0--23
7370 @item Day of month, range 1--31
7371 @item Number of months since January, range 0--11
7372 @item Years since 1900
7373 @item Number of days since Sunday, range 0--6
7374 @item Days since January 1, range 0--365
7375 @item Daylight savings indicator: positive if daylight savings is in
7376 effect, zero if not, and negative if the information is not available.
7379 @item @emph{See also}:
7380 @ref{DATE_AND_TIME}, @*
7390 @section @code{HOSTNM} --- Get system host name
7392 @cindex system, host name
7395 @item @emph{Description}:
7396 Retrieves the host name of the system on which the program is running.
7398 This intrinsic is provided in both subroutine and function forms; however,
7399 only one form can be used in any given program unit.
7401 @item @emph{Standard}:
7405 Subroutine, function
7407 @item @emph{Syntax}:
7408 @multitable @columnfractions .80
7409 @item @code{CALL HOSTNM(C [, STATUS])}
7410 @item @code{STATUS = HOSTNM(NAME)}
7413 @item @emph{Arguments}:
7414 @multitable @columnfractions .15 .70
7415 @item @var{C} @tab Shall of type @code{CHARACTER} and of default kind.
7416 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
7417 Returns 0 on success, or a system specific error code otherwise.
7420 @item @emph{Return value}:
7421 In either syntax, @var{NAME} is set to the current hostname if it can
7422 be obtained, or to a blank string otherwise.
7429 @section @code{HUGE} --- Largest number of a kind
7431 @cindex limits, largest number
7432 @cindex model representation, largest number
7435 @item @emph{Description}:
7436 @code{HUGE(X)} returns the largest number that is not an infinity in
7437 the model of the type of @code{X}.
7439 @item @emph{Standard}:
7440 Fortran 90 and later
7445 @item @emph{Syntax}:
7446 @code{RESULT = HUGE(X)}
7448 @item @emph{Arguments}:
7449 @multitable @columnfractions .15 .70
7450 @item @var{X} @tab Shall be of type @code{REAL} or @code{INTEGER}.
7453 @item @emph{Return value}:
7454 The return value is of the same type and kind as @var{X}
7456 @item @emph{Example}:
7458 program test_huge_tiny
7459 print *, huge(0), huge(0.0), huge(0.0d0)
7460 print *, tiny(0.0), tiny(0.0d0)
7461 end program test_huge_tiny
7468 @section @code{HYPOT} --- Euclidean distance function
7470 @cindex Euclidean distance
7473 @item @emph{Description}:
7474 @code{HYPOT(X,Y)} is the Euclidean distance function. It is equal to
7475 @math{\sqrt{X^2 + Y^2}}, without undue underflow or overflow.
7477 @item @emph{Standard}:
7478 Fortran 2008 and later
7483 @item @emph{Syntax}:
7484 @code{RESULT = HYPOT(X, Y)}
7486 @item @emph{Arguments}:
7487 @multitable @columnfractions .15 .70
7488 @item @var{X} @tab The type shall be @code{REAL}.
7489 @item @var{Y} @tab The type and kind type parameter shall be the same as
7493 @item @emph{Return value}:
7494 The return value has the same type and kind type parameter as @var{X}.
7496 @item @emph{Example}:
7499 real(4) :: x = 1.e0_4, y = 0.5e0_4
7501 end program test_hypot
7508 @section @code{IACHAR} --- Code in @acronym{ASCII} collating sequence
7510 @cindex @acronym{ASCII} collating sequence
7511 @cindex collating sequence, @acronym{ASCII}
7512 @cindex conversion, to integer
7515 @item @emph{Description}:
7516 @code{IACHAR(C)} returns the code for the @acronym{ASCII} character
7517 in the first character position of @code{C}.
7519 @item @emph{Standard}:
7520 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
7525 @item @emph{Syntax}:
7526 @code{RESULT = IACHAR(C [, KIND])}
7528 @item @emph{Arguments}:
7529 @multitable @columnfractions .15 .70
7530 @item @var{C} @tab Shall be a scalar @code{CHARACTER}, with @code{INTENT(IN)}
7531 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
7532 expression indicating the kind parameter of the result.
7535 @item @emph{Return value}:
7536 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
7537 @var{KIND} is absent, the return value is of default integer kind.
7539 @item @emph{Example}:
7544 end program test_iachar
7548 See @ref{ICHAR} for a discussion of converting between numerical values
7549 and formatted string representations.
7551 @item @emph{See also}:
7560 @section @code{IALL} --- Bitwise AND of array elements
7563 @cindex bits, AND of array elements
7566 @item @emph{Description}:
7567 Reduces with bitwise AND the elements of @var{ARRAY} along dimension @var{DIM}
7568 if the corresponding element in @var{MASK} is @code{TRUE}.
7570 @item @emph{Standard}:
7571 Fortran 2008 and later
7574 Transformational function
7576 @item @emph{Syntax}:
7577 @multitable @columnfractions .80
7578 @item @code{RESULT = IALL(ARRAY[, MASK])}
7579 @item @code{RESULT = IALL(ARRAY, DIM[, MASK])}
7582 @item @emph{Arguments}:
7583 @multitable @columnfractions .15 .70
7584 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER}
7585 @item @var{DIM} @tab (Optional) shall be a scalar of type
7586 @code{INTEGER} with a value in the range from 1 to n, where n
7587 equals the rank of @var{ARRAY}.
7588 @item @var{MASK} @tab (Optional) shall be of type @code{LOGICAL}
7589 and either be a scalar or an array of the same shape as @var{ARRAY}.
7592 @item @emph{Return value}:
7593 The result is of the same type as @var{ARRAY}.
7595 If @var{DIM} is absent, a scalar with the bitwise ALL of all elements in
7596 @var{ARRAY} is returned. Otherwise, an array of rank n-1, where n equals
7597 the rank of @var{ARRAY}, and a shape similar to that of @var{ARRAY} with
7598 dimension @var{DIM} dropped is returned.
7600 @item @emph{Example}:
7609 PRINT '(b8.8)', IALL(a)
7613 @item @emph{See also}:
7622 @section @code{IAND} --- Bitwise logical and
7628 @cindex bitwise logical and
7629 @cindex logical and, bitwise
7632 @item @emph{Description}:
7633 Bitwise logical @code{AND}.
7635 @item @emph{Standard}:
7636 Fortran 90 and later, with boz-literal-constant Fortran 2008 and later, has overloads that are GNU extensions
7641 @item @emph{Syntax}:
7642 @code{RESULT = IAND(I, J)}
7644 @item @emph{Arguments}:
7645 @multitable @columnfractions .15 .70
7646 @item @var{I} @tab The type shall be @code{INTEGER} or a boz-literal-constant.
7647 @item @var{J} @tab The type shall be @code{INTEGER} with the same
7648 kind type parameter as @var{I} or a boz-literal-constant.
7649 @var{I} and @var{J} shall not both be boz-literal-constants.
7652 @item @emph{Return value}:
7653 The return type is @code{INTEGER} with the kind type parameter of the
7655 A boz-literal-constant is converted to an @code{INTEGER} with the kind
7656 type parameter of the other argument as-if a call to @ref{INT} occurred.
7658 @item @emph{Example}:
7662 DATA a / Z'F' /, b / Z'3' /
7663 WRITE (*,*) IAND(a, b)
7667 @item @emph{Specific names}:
7668 @multitable @columnfractions .20 .23 .20 .33
7669 @headitem Name @tab Argument @tab Return type @tab Standard
7670 @item @code{IAND(A)} @tab @code{INTEGER A} @tab @code{INTEGER} @tab Fortran 90 and later
7671 @item @code{BIAND(A)} @tab @code{INTEGER(1) A} @tab @code{INTEGER(1)} @tab GNU extension
7672 @item @code{IIAND(A)} @tab @code{INTEGER(2) A} @tab @code{INTEGER(2)} @tab GNU extension
7673 @item @code{JIAND(A)} @tab @code{INTEGER(4) A} @tab @code{INTEGER(4)} @tab GNU extension
7674 @item @code{KIAND(A)} @tab @code{INTEGER(8) A} @tab @code{INTEGER(8)} @tab GNU extension
7677 @item @emph{See also}:
7689 @section @code{IANY} --- Bitwise OR of array elements
7692 @cindex bits, OR of array elements
7695 @item @emph{Description}:
7696 Reduces with bitwise OR (inclusive or) the elements of @var{ARRAY} along
7697 dimension @var{DIM} if the corresponding element in @var{MASK} is @code{TRUE}.
7699 @item @emph{Standard}:
7700 Fortran 2008 and later
7703 Transformational function
7705 @item @emph{Syntax}:
7706 @multitable @columnfractions .80
7707 @item @code{RESULT = IANY(ARRAY[, MASK])}
7708 @item @code{RESULT = IANY(ARRAY, DIM[, MASK])}
7711 @item @emph{Arguments}:
7712 @multitable @columnfractions .15 .70
7713 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER}
7714 @item @var{DIM} @tab (Optional) shall be a scalar of type
7715 @code{INTEGER} with a value in the range from 1 to n, where n
7716 equals the rank of @var{ARRAY}.
7717 @item @var{MASK} @tab (Optional) shall be of type @code{LOGICAL}
7718 and either be a scalar or an array of the same shape as @var{ARRAY}.
7721 @item @emph{Return value}:
7722 The result is of the same type as @var{ARRAY}.
7724 If @var{DIM} is absent, a scalar with the bitwise OR of all elements in
7725 @var{ARRAY} is returned. Otherwise, an array of rank n-1, where n equals
7726 the rank of @var{ARRAY}, and a shape similar to that of @var{ARRAY} with
7727 dimension @var{DIM} dropped is returned.
7729 @item @emph{Example}:
7738 PRINT '(b8.8)', IANY(a)
7742 @item @emph{See also}:
7751 @section @code{IARGC} --- Get the number of command line arguments
7753 @cindex command-line arguments
7754 @cindex command-line arguments, number of
7755 @cindex arguments, to program
7758 @item @emph{Description}:
7759 @code{IARGC} returns the number of arguments passed on the
7760 command line when the containing program was invoked.
7762 This intrinsic routine is provided for backwards compatibility with
7763 GNU Fortran 77. In new code, programmers should consider the use of
7764 the @ref{COMMAND_ARGUMENT_COUNT} intrinsic defined by the Fortran 2003
7767 @item @emph{Standard}:
7773 @item @emph{Syntax}:
7774 @code{RESULT = IARGC()}
7776 @item @emph{Arguments}:
7779 @item @emph{Return value}:
7780 The number of command line arguments, type @code{INTEGER(4)}.
7782 @item @emph{Example}:
7785 @item @emph{See also}:
7786 GNU Fortran 77 compatibility subroutine: @*
7788 Fortran 2003 functions and subroutines: @*
7789 @ref{GET_COMMAND}, @*
7790 @ref{GET_COMMAND_ARGUMENT}, @*
7791 @ref{COMMAND_ARGUMENT_COUNT}
7797 @section @code{IBCLR} --- Clear bit
7807 @item @emph{Description}:
7808 @code{IBCLR} returns the value of @var{I} with the bit at position
7809 @var{POS} set to zero.
7811 @item @emph{Standard}:
7812 Fortran 90 and later, has overloads that are GNU extensions
7817 @item @emph{Syntax}:
7818 @code{RESULT = IBCLR(I, POS)}
7820 @item @emph{Arguments}:
7821 @multitable @columnfractions .15 .70
7822 @item @var{I} @tab The type shall be @code{INTEGER}.
7823 @item @var{POS} @tab The type shall be @code{INTEGER}.
7826 @item @emph{Return value}:
7827 The return value is of type @code{INTEGER} and of the same kind as
7830 @item @emph{Specific names}:
7831 @multitable @columnfractions .20 .23 .20 .33
7832 @headitem Name @tab Argument @tab Return type @tab Standard
7833 @item @code{IBCLR(A)} @tab @code{INTEGER A} @tab @code{INTEGER} @tab Fortran 90 and later
7834 @item @code{BBCLR(A)} @tab @code{INTEGER(1) A} @tab @code{INTEGER(1)} @tab GNU extension
7835 @item @code{IIBCLR(A)} @tab @code{INTEGER(2) A} @tab @code{INTEGER(2)} @tab GNU extension
7836 @item @code{JIBCLR(A)} @tab @code{INTEGER(4) A} @tab @code{INTEGER(4)} @tab GNU extension
7837 @item @code{KIBCLR(A)} @tab @code{INTEGER(8) A} @tab @code{INTEGER(8)} @tab GNU extension
7840 @item @emph{See also}:
7852 @section @code{IBITS} --- Bit extraction
7859 @cindex bits, extract
7862 @item @emph{Description}:
7863 @code{IBITS} extracts a field of length @var{LEN} from @var{I},
7864 starting from bit position @var{POS} and extending left for @var{LEN}
7865 bits. The result is right-justified and the remaining bits are
7866 zeroed. The value of @code{POS+LEN} must be less than or equal to the
7867 value @code{BIT_SIZE(I)}.
7869 @item @emph{Standard}:
7870 Fortran 90 and later, has overloads that are GNU extensions
7875 @item @emph{Syntax}:
7876 @code{RESULT = IBITS(I, POS, LEN)}
7878 @item @emph{Arguments}:
7879 @multitable @columnfractions .15 .70
7880 @item @var{I} @tab The type shall be @code{INTEGER}.
7881 @item @var{POS} @tab The type shall be @code{INTEGER}.
7882 @item @var{LEN} @tab The type shall be @code{INTEGER}.
7885 @item @emph{Return value}:
7886 The return value is of type @code{INTEGER} and of the same kind as
7889 @item @emph{Specific names}:
7890 @multitable @columnfractions .20 .23 .20 .33
7891 @headitem Name @tab Argument @tab Return type @tab Standard
7892 @item @code{IBITS(A)} @tab @code{INTEGER A} @tab @code{INTEGER} @tab Fortran 90 and later
7893 @item @code{BBITS(A)} @tab @code{INTEGER(1) A} @tab @code{INTEGER(1)} @tab GNU extension
7894 @item @code{IIBITS(A)} @tab @code{INTEGER(2) A} @tab @code{INTEGER(2)} @tab GNU extension
7895 @item @code{JIBITS(A)} @tab @code{INTEGER(4) A} @tab @code{INTEGER(4)} @tab GNU extension
7896 @item @code{KIBITS(A)} @tab @code{INTEGER(8) A} @tab @code{INTEGER(8)} @tab GNU extension
7899 @item @emph{See also}:
7911 @section @code{IBSET} --- Set bit
7920 @item @emph{Description}:
7921 @code{IBSET} returns the value of @var{I} with the bit at position
7922 @var{POS} set to one.
7924 @item @emph{Standard}:
7925 Fortran 90 and later, has overloads that are GNU extensions
7930 @item @emph{Syntax}:
7931 @code{RESULT = IBSET(I, POS)}
7933 @item @emph{Arguments}:
7934 @multitable @columnfractions .15 .70
7935 @item @var{I} @tab The type shall be @code{INTEGER}.
7936 @item @var{POS} @tab The type shall be @code{INTEGER}.
7939 @item @emph{Return value}:
7940 The return value is of type @code{INTEGER} and of the same kind as
7943 @item @emph{Specific names}:
7944 @multitable @columnfractions .20 .23 .20 .33
7945 @headitem Name @tab Argument @tab Return type @tab Standard
7946 @item @code{IBSET(A)} @tab @code{INTEGER A} @tab @code{INTEGER} @tab Fortran 90 and later
7947 @item @code{BBSET(A)} @tab @code{INTEGER(1) A} @tab @code{INTEGER(1)} @tab GNU extension
7948 @item @code{IIBSET(A)} @tab @code{INTEGER(2) A} @tab @code{INTEGER(2)} @tab GNU extension
7949 @item @code{JIBSET(A)} @tab @code{INTEGER(4) A} @tab @code{INTEGER(4)} @tab GNU extension
7950 @item @code{KIBSET(A)} @tab @code{INTEGER(8) A} @tab @code{INTEGER(8)} @tab GNU extension
7953 @item @emph{See also}:
7965 @section @code{ICHAR} --- Character-to-integer conversion function
7967 @cindex conversion, to integer
7970 @item @emph{Description}:
7971 @code{ICHAR(C)} returns the code for the character in the first character
7972 position of @code{C} in the system's native character set.
7973 The correspondence between characters and their codes is not necessarily
7974 the same across different GNU Fortran implementations.
7976 @item @emph{Standard}:
7977 Fortran 77 and later, with @var{KIND} argument Fortran 2003 and later
7982 @item @emph{Syntax}:
7983 @code{RESULT = ICHAR(C [, KIND])}
7985 @item @emph{Arguments}:
7986 @multitable @columnfractions .15 .70
7987 @item @var{C} @tab Shall be a scalar @code{CHARACTER}, with @code{INTENT(IN)}
7988 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
7989 expression indicating the kind parameter of the result.
7992 @item @emph{Return value}:
7993 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
7994 @var{KIND} is absent, the return value is of default integer kind.
7996 @item @emph{Example}:
8001 end program test_ichar
8004 @item @emph{Specific names}:
8005 @multitable @columnfractions .20 .23 .20 .33
8006 @headitem Name @tab Argument @tab Return type @tab Standard
8007 @item @code{ICHAR(C)} @tab @code{CHARACTER C} @tab @code{INTEGER(4)} @tab Fortran 77 and later
8011 No intrinsic exists to convert between a numeric value and a formatted
8012 character string representation -- for instance, given the
8013 @code{CHARACTER} value @code{'154'}, obtaining an @code{INTEGER} or
8014 @code{REAL} value with the value 154, or vice versa. Instead, this
8015 functionality is provided by internal-file I/O, as in the following
8020 character(len=10) string, string2
8023 ! Convert a string to a numeric value
8024 read (string,'(I10)') value
8027 ! Convert a value to a formatted string
8028 write (string2,'(I10)') value
8030 end program read_val
8033 @item @emph{See also}:
8042 @section @code{IDATE} --- Get current local time subroutine (day/month/year)
8044 @cindex date, current
8045 @cindex current date
8048 @item @emph{Description}:
8049 @code{IDATE(VALUES)} Fills @var{VALUES} with the numerical values at the
8050 current local time. The day (in the range 1-31), month (in the range 1-12),
8051 and year appear in elements 1, 2, and 3 of @var{VALUES}, respectively.
8052 The year has four significant digits.
8054 This intrinsic routine is provided for backwards compatibility with
8055 GNU Fortran 77. In new code, programmers should consider the use of
8056 the @ref{DATE_AND_TIME} intrinsic defined by the Fortran 95
8059 @item @emph{Standard}:
8065 @item @emph{Syntax}:
8066 @code{CALL IDATE(VALUES)}
8068 @item @emph{Arguments}:
8069 @multitable @columnfractions .15 .70
8070 @item @var{VALUES} @tab The type shall be @code{INTEGER, DIMENSION(3)} and
8071 the kind shall be the default integer kind.
8074 @item @emph{Return value}:
8075 Does not return anything.
8077 @item @emph{Example}:
8080 integer, dimension(3) :: tarray
8085 end program test_idate
8088 @item @emph{See also}:
8094 @section @code{IEOR} --- Bitwise logical exclusive or
8100 @cindex bitwise logical exclusive or
8101 @cindex logical exclusive or, bitwise
8104 @item @emph{Description}:
8105 @code{IEOR} returns the bitwise Boolean exclusive-OR of @var{I} and
8108 @item @emph{Standard}:
8109 Fortran 90 and later, with boz-literal-constant Fortran 2008 and later, has overloads that are GNU extensions
8114 @item @emph{Syntax}:
8115 @code{RESULT = IEOR(I, J)}
8117 @item @emph{Arguments}:
8118 @multitable @columnfractions .15 .70
8119 @item @var{I} @tab The type shall be @code{INTEGER} or a boz-literal-constant.
8120 @item @var{J} @tab The type shall be @code{INTEGER} with the same
8121 kind type parameter as @var{I} or a boz-literal-constant.
8122 @var{I} and @var{J} shall not both be boz-literal-constants.
8125 @item @emph{Return value}:
8126 The return type is @code{INTEGER} with the kind type parameter of the
8128 A boz-literal-constant is converted to an @code{INTEGER} with the kind
8129 type parameter of the other argument as-if a call to @ref{INT} occurred.
8131 @item @emph{Specific names}:
8132 @multitable @columnfractions .20 .23 .20 .33
8133 @headitem Name @tab Argument @tab Return type @tab Standard
8134 @item @code{IEOR(A)} @tab @code{INTEGER A} @tab @code{INTEGER} @tab Fortran 90 and later
8135 @item @code{BIEOR(A)} @tab @code{INTEGER(1) A} @tab @code{INTEGER(1)} @tab GNU extension
8136 @item @code{IIEOR(A)} @tab @code{INTEGER(2) A} @tab @code{INTEGER(2)} @tab GNU extension
8137 @item @code{JIEOR(A)} @tab @code{INTEGER(4) A} @tab @code{INTEGER(4)} @tab GNU extension
8138 @item @code{KIEOR(A)} @tab @code{INTEGER(8) A} @tab @code{INTEGER(8)} @tab GNU extension
8141 @item @emph{See also}:
8153 @section @code{IERRNO} --- Get the last system error number
8155 @cindex system, error handling
8158 @item @emph{Description}:
8159 Returns the last system error number, as given by the C @code{errno}
8162 @item @emph{Standard}:
8168 @item @emph{Syntax}:
8169 @code{RESULT = IERRNO()}
8171 @item @emph{Arguments}:
8174 @item @emph{Return value}:
8175 The return value is of type @code{INTEGER} and of the default integer
8178 @item @emph{See also}:
8185 @section @code{IMAGE_INDEX} --- Function that converts a cosubscript to an image index
8186 @fnindex IMAGE_INDEX
8187 @cindex coarray, @code{IMAGE_INDEX}
8188 @cindex images, cosubscript to image index conversion
8191 @item @emph{Description}:
8192 Returns the image index belonging to a cosubscript.
8194 @item @emph{Standard}:
8195 Fortran 2008 and later
8200 @item @emph{Syntax}:
8201 @code{RESULT = IMAGE_INDEX(COARRAY, SUB)}
8203 @item @emph{Arguments}:
8204 @multitable @columnfractions .15 .70
8205 @item @var{COARRAY} @tab Coarray of any type.
8206 @item @var{SUB} @tab default integer rank-1 array of a size equal to
8207 the corank of @var{COARRAY}.
8211 @item @emph{Return value}:
8212 Scalar default integer with the value of the image index which corresponds
8213 to the cosubscripts. For invalid cosubscripts the result is zero.
8215 @item @emph{Example}:
8217 INTEGER :: array[2,-1:4,8,*]
8218 ! Writes 28 (or 0 if there are fewer than 28 images)
8219 WRITE (*,*) IMAGE_INDEX (array, [2,0,3,1])
8222 @item @emph{See also}:
8223 @ref{THIS_IMAGE}, @*
8229 @node INDEX intrinsic
8230 @section @code{INDEX} --- Position of a substring within a string
8232 @cindex substring position
8233 @cindex string, find substring
8236 @item @emph{Description}:
8237 Returns the position of the start of the first occurrence of string
8238 @var{SUBSTRING} as a substring in @var{STRING}, counting from one. If
8239 @var{SUBSTRING} is not present in @var{STRING}, zero is returned. If
8240 the @var{BACK} argument is present and true, the return value is the
8241 start of the last occurrence rather than the first.
8243 @item @emph{Standard}:
8244 Fortran 77 and later, with @var{KIND} argument Fortran 2003 and later
8249 @item @emph{Syntax}:
8250 @code{RESULT = INDEX(STRING, SUBSTRING [, BACK [, KIND]])}
8252 @item @emph{Arguments}:
8253 @multitable @columnfractions .15 .70
8254 @item @var{STRING} @tab Shall be a scalar @code{CHARACTER}, with
8256 @item @var{SUBSTRING} @tab Shall be a scalar @code{CHARACTER}, with
8258 @item @var{BACK} @tab (Optional) Shall be a scalar @code{LOGICAL}, with
8260 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
8261 expression indicating the kind parameter of the result.
8264 @item @emph{Return value}:
8265 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
8266 @var{KIND} is absent, the return value is of default integer kind.
8268 @item @emph{Specific names}:
8269 @multitable @columnfractions .35 .15 .17 .30
8270 @headitem Name @tab Argument @tab Return type @tab Standard
8271 @item @code{INDEX(STRING,SUBSTRING)} @tab @code{CHARACTER} @tab @code{INTEGER(4)} @tab Fortran 77 and later
8274 @item @emph{See also}:
8282 @section @code{INT} --- Convert to integer type
8286 @cindex conversion, to integer
8289 @item @emph{Description}:
8290 Convert to integer type
8292 @item @emph{Standard}:
8293 Fortran 77 and later, with boz-literal-constant Fortran 2008 and later.
8298 @item @emph{Syntax}:
8299 @code{RESULT = INT(A [, KIND))}
8301 @item @emph{Arguments}:
8302 @multitable @columnfractions .15 .70
8303 @item @var{A} @tab Shall be of type @code{INTEGER},
8304 @code{REAL}, or @code{COMPLEX} or a boz-literal-constant.
8305 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
8306 expression indicating the kind parameter of the result.
8309 @item @emph{Return value}:
8310 These functions return a @code{INTEGER} variable or array under
8311 the following rules:
8315 If @var{A} is of type @code{INTEGER}, @code{INT(A) = A}
8317 If @var{A} is of type @code{REAL} and @math{|A| < 1}, @code{INT(A)}
8318 equals @code{0}. If @math{|A| \geq 1}, then @code{INT(A)} is the integer
8319 whose magnitude is the largest integer that does not exceed the magnitude
8320 of @var{A} and whose sign is the same as the sign of @var{A}.
8322 If @var{A} is of type @code{COMPLEX}, rule B is applied to the real part of @var{A}.
8325 @item @emph{Example}:
8329 complex :: z = (-3.7, 1.0)
8331 print *, int(z), int(z,8)
8335 @item @emph{Specific names}:
8336 @multitable @columnfractions .20 .23 .20 .33
8337 @headitem Name @tab Argument @tab Return type @tab Standard
8338 @item @code{INT(A)} @tab @code{REAL(4) A} @tab @code{INTEGER} @tab Fortran 77 and later
8339 @item @code{IFIX(A)} @tab @code{REAL(4) A} @tab @code{INTEGER} @tab Fortran 77 and later
8340 @item @code{IDINT(A)} @tab @code{REAL(8) A} @tab @code{INTEGER} @tab Fortran 77 and later
8347 @section @code{INT2} --- Convert to 16-bit integer type
8349 @cindex conversion, to integer
8352 @item @emph{Description}:
8353 Convert to a @code{KIND=2} integer type. This is equivalent to the
8354 standard @code{INT} intrinsic with an optional argument of
8355 @code{KIND=2}, and is only included for backwards compatibility.
8357 @item @emph{Standard}:
8363 @item @emph{Syntax}:
8364 @code{RESULT = INT2(A)}
8366 @item @emph{Arguments}:
8367 @multitable @columnfractions .15 .70
8368 @item @var{A} @tab Shall be of type @code{INTEGER},
8369 @code{REAL}, or @code{COMPLEX}.
8372 @item @emph{Return value}:
8373 The return value is a @code{INTEGER(2)} variable.
8375 @item @emph{See also}:
8383 @section @code{INT8} --- Convert to 64-bit integer type
8385 @cindex conversion, to integer
8388 @item @emph{Description}:
8389 Convert to a @code{KIND=8} integer type. This is equivalent to the
8390 standard @code{INT} intrinsic with an optional argument of
8391 @code{KIND=8}, and is only included for backwards compatibility.
8393 @item @emph{Standard}:
8399 @item @emph{Syntax}:
8400 @code{RESULT = INT8(A)}
8402 @item @emph{Arguments}:
8403 @multitable @columnfractions .15 .70
8404 @item @var{A} @tab Shall be of type @code{INTEGER},
8405 @code{REAL}, or @code{COMPLEX}.
8408 @item @emph{Return value}:
8409 The return value is a @code{INTEGER(8)} variable.
8411 @item @emph{See also}:
8419 @section @code{IOR} --- Bitwise logical or
8425 @cindex bitwise logical or
8426 @cindex logical or, bitwise
8429 @item @emph{Description}:
8430 @code{IOR} returns the bitwise Boolean inclusive-OR of @var{I} and
8433 @item @emph{Standard}:
8434 Fortran 90 and later, with boz-literal-constant Fortran 2008 and later, has overloads that are GNU extensions
8439 @item @emph{Syntax}:
8440 @code{RESULT = IOR(I, J)}
8442 @item @emph{Arguments}:
8443 @multitable @columnfractions .15 .70
8444 @item @var{I} @tab The type shall be @code{INTEGER} or a boz-literal-constant.
8445 @item @var{J} @tab The type shall be @code{INTEGER} with the same
8446 kind type parameter as @var{I} or a boz-literal-constant.
8447 @var{I} and @var{J} shall not both be boz-literal-constants.
8450 @item @emph{Return value}:
8451 The return type is @code{INTEGER} with the kind type parameter of the
8453 A boz-literal-constant is converted to an @code{INTEGER} with the kind
8454 type parameter of the other argument as-if a call to @ref{INT} occurred.
8456 @item @emph{Specific names}:
8457 @multitable @columnfractions .20 .23 .20 .33
8458 @headitem Name @tab Argument @tab Return type @tab Standard
8459 @item @code{IOR(A)} @tab @code{INTEGER A} @tab @code{INTEGER} @tab Fortran 90 and later
8460 @item @code{BIOR(A)} @tab @code{INTEGER(1) A} @tab @code{INTEGER(1)} @tab GNU extension
8461 @item @code{IIOR(A)} @tab @code{INTEGER(2) A} @tab @code{INTEGER(2)} @tab GNU extension
8462 @item @code{JIOR(A)} @tab @code{INTEGER(4) A} @tab @code{INTEGER(4)} @tab GNU extension
8463 @item @code{KIOR(A)} @tab @code{INTEGER(8) A} @tab @code{INTEGER(8)} @tab GNU extension
8466 @item @emph{See also}:
8478 @section @code{IPARITY} --- Bitwise XOR of array elements
8480 @cindex array, parity
8482 @cindex bits, XOR of array elements
8485 @item @emph{Description}:
8486 Reduces with bitwise XOR (exclusive or) the elements of @var{ARRAY} along
8487 dimension @var{DIM} if the corresponding element in @var{MASK} is @code{TRUE}.
8489 @item @emph{Standard}:
8490 Fortran 2008 and later
8493 Transformational function
8495 @item @emph{Syntax}:
8496 @multitable @columnfractions .80
8497 @item @code{RESULT = IPARITY(ARRAY[, MASK])}
8498 @item @code{RESULT = IPARITY(ARRAY, DIM[, MASK])}
8501 @item @emph{Arguments}:
8502 @multitable @columnfractions .15 .70
8503 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER}
8504 @item @var{DIM} @tab (Optional) shall be a scalar of type
8505 @code{INTEGER} with a value in the range from 1 to n, where n
8506 equals the rank of @var{ARRAY}.
8507 @item @var{MASK} @tab (Optional) shall be of type @code{LOGICAL}
8508 and either be a scalar or an array of the same shape as @var{ARRAY}.
8511 @item @emph{Return value}:
8512 The result is of the same type as @var{ARRAY}.
8514 If @var{DIM} is absent, a scalar with the bitwise XOR of all elements in
8515 @var{ARRAY} is returned. Otherwise, an array of rank n-1, where n equals
8516 the rank of @var{ARRAY}, and a shape similar to that of @var{ARRAY} with
8517 dimension @var{DIM} dropped is returned.
8519 @item @emph{Example}:
8521 PROGRAM test_iparity
8524 a(1) = int(b'00100100', 1)
8525 a(2) = int(b'01101010', 1)
8528 PRINT '(b8.8)', IPARITY(a)
8532 @item @emph{See also}:
8542 @section @code{IRAND} --- Integer pseudo-random number
8544 @cindex random number generation
8547 @item @emph{Description}:
8548 @code{IRAND(FLAG)} returns a pseudo-random number from a uniform
8549 distribution between 0 and a system-dependent limit (which is in most
8550 cases 2147483647). If @var{FLAG} is 0, the next number
8551 in the current sequence is returned; if @var{FLAG} is 1, the generator
8552 is restarted by @code{CALL SRAND(0)}; if @var{FLAG} has any other value,
8553 it is used as a new seed with @code{SRAND}.
8555 This intrinsic routine is provided for backwards compatibility with
8556 GNU Fortran 77. It implements a simple modulo generator as provided
8557 by @command{g77}. For new code, one should consider the use of
8558 @ref{RANDOM_NUMBER} as it implements a superior algorithm.
8560 @item @emph{Standard}:
8566 @item @emph{Syntax}:
8567 @code{RESULT = IRAND(I)}
8569 @item @emph{Arguments}:
8570 @multitable @columnfractions .15 .70
8571 @item @var{I} @tab Shall be a scalar @code{INTEGER} of kind 4.
8574 @item @emph{Return value}:
8575 The return value is of @code{INTEGER(kind=4)} type.
8577 @item @emph{Example}:
8580 integer,parameter :: seed = 86456
8583 print *, irand(), irand(), irand(), irand()
8584 print *, irand(seed), irand(), irand(), irand()
8585 end program test_irand
8593 @section @code{IS_CONTIGUOUS} --- Test whether an array is contiguous
8594 @fnindex IS_IOSTAT_EOR
8595 @cindex array, contiguity
8598 @item @emph{Description}:
8599 @code{IS_CONTIGUOUS} tests whether an array is contiguous.
8601 @item @emph{Standard}:
8602 Fortran 2008 and later
8607 @item @emph{Syntax}:
8608 @code{RESULT = IS_CONTIGUOUS(ARRAY)}
8610 @item @emph{Arguments}:
8611 @multitable @columnfractions .15 .70
8612 @item @var{ARRAY} @tab Shall be an array of any type.
8615 @item @emph{Return value}:
8616 Returns a @code{LOGICAL} of the default kind, which @code{.TRUE.} if
8617 @var{ARRAY} is contiguous and false otherwise.
8619 @item @emph{Example}:
8623 a = [1,2,3,4,5,6,7,8,9,10]
8624 call sub (a) ! every element, is contiguous
8625 call sub (a(::2)) ! every other element, is noncontiguous
8629 if (is_contiguous (x)) then
8630 write (*,*) 'X is contiguous'
8632 write (*,*) 'X is not contiguous'
8642 @section @code{IS_IOSTAT_END} --- Test for end-of-file value
8643 @fnindex IS_IOSTAT_END
8644 @cindex @code{IOSTAT}, end of file
8647 @item @emph{Description}:
8648 @code{IS_IOSTAT_END} tests whether an variable has the value of the I/O
8649 status ``end of file''. The function is equivalent to comparing the variable
8650 with the @code{IOSTAT_END} parameter of the intrinsic module
8651 @code{ISO_FORTRAN_ENV}.
8653 @item @emph{Standard}:
8654 Fortran 2003 and later
8659 @item @emph{Syntax}:
8660 @code{RESULT = IS_IOSTAT_END(I)}
8662 @item @emph{Arguments}:
8663 @multitable @columnfractions .15 .70
8664 @item @var{I} @tab Shall be of the type @code{INTEGER}.
8667 @item @emph{Return value}:
8668 Returns a @code{LOGICAL} of the default kind, which @code{.TRUE.} if
8669 @var{I} has the value which indicates an end of file condition for
8670 @code{IOSTAT=} specifiers, and is @code{.FALSE.} otherwise.
8672 @item @emph{Example}:
8677 OPEN(88, FILE='test.dat')
8678 READ(88, *, IOSTAT=stat) i
8679 IF(IS_IOSTAT_END(stat)) STOP 'END OF FILE'
8687 @section @code{IS_IOSTAT_EOR} --- Test for end-of-record value
8688 @fnindex IS_IOSTAT_EOR
8689 @cindex @code{IOSTAT}, end of record
8692 @item @emph{Description}:
8693 @code{IS_IOSTAT_EOR} tests whether an variable has the value of the I/O
8694 status ``end of record''. The function is equivalent to comparing the
8695 variable with the @code{IOSTAT_EOR} parameter of the intrinsic module
8696 @code{ISO_FORTRAN_ENV}.
8698 @item @emph{Standard}:
8699 Fortran 2003 and later
8704 @item @emph{Syntax}:
8705 @code{RESULT = IS_IOSTAT_EOR(I)}
8707 @item @emph{Arguments}:
8708 @multitable @columnfractions .15 .70
8709 @item @var{I} @tab Shall be of the type @code{INTEGER}.
8712 @item @emph{Return value}:
8713 Returns a @code{LOGICAL} of the default kind, which @code{.TRUE.} if
8714 @var{I} has the value which indicates an end of file condition for
8715 @code{IOSTAT=} specifiers, and is @code{.FALSE.} otherwise.
8717 @item @emph{Example}:
8721 INTEGER :: stat, i(50)
8722 OPEN(88, FILE='test.dat', FORM='UNFORMATTED')
8723 READ(88, IOSTAT=stat) i
8724 IF(IS_IOSTAT_EOR(stat)) STOP 'END OF RECORD'
8731 @section @code{ISATTY} --- Whether a unit is a terminal device
8733 @cindex system, terminal
8736 @item @emph{Description}:
8737 Determine whether a unit is connected to a terminal device.
8739 @item @emph{Standard}:
8745 @item @emph{Syntax}:
8746 @code{RESULT = ISATTY(UNIT)}
8748 @item @emph{Arguments}:
8749 @multitable @columnfractions .15 .70
8750 @item @var{UNIT} @tab Shall be a scalar @code{INTEGER}.
8753 @item @emph{Return value}:
8754 Returns @code{.TRUE.} if the @var{UNIT} is connected to a terminal
8755 device, @code{.FALSE.} otherwise.
8757 @item @emph{Example}:
8760 INTEGER(kind=1) :: unit
8762 write(*,*) isatty(unit=unit)
8766 @item @emph{See also}:
8773 @section @code{ISHFT} --- Shift bits
8782 @item @emph{Description}:
8783 @code{ISHFT} returns a value corresponding to @var{I} with all of the
8784 bits shifted @var{SHIFT} places. A value of @var{SHIFT} greater than
8785 zero corresponds to a left shift, a value of zero corresponds to no
8786 shift, and a value less than zero corresponds to a right shift. If the
8787 absolute value of @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the
8788 value is undefined. Bits shifted out from the left end or right end are
8789 lost; zeros are shifted in from the opposite end.
8791 @item @emph{Standard}:
8792 Fortran 90 and later, has overloads that are GNU extensions
8797 @item @emph{Syntax}:
8798 @code{RESULT = ISHFT(I, SHIFT)}
8800 @item @emph{Arguments}:
8801 @multitable @columnfractions .15 .70
8802 @item @var{I} @tab The type shall be @code{INTEGER}.
8803 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
8806 @item @emph{Return value}:
8807 The return value is of type @code{INTEGER} and of the same kind as
8810 @item @emph{Specific names}:
8811 @multitable @columnfractions .20 .23 .20 .33
8812 @headitem Name @tab Argument @tab Return type @tab Standard
8813 @item @code{ISHFT(A)} @tab @code{INTEGER A} @tab @code{INTEGER} @tab Fortran 90 and later
8814 @item @code{BSHFT(A)} @tab @code{INTEGER(1) A} @tab @code{INTEGER(1)} @tab GNU extension
8815 @item @code{IISHFT(A)} @tab @code{INTEGER(2) A} @tab @code{INTEGER(2)} @tab GNU extension
8816 @item @code{JISHFT(A)} @tab @code{INTEGER(4) A} @tab @code{INTEGER(4)} @tab GNU extension
8817 @item @code{KISHFT(A)} @tab @code{INTEGER(8) A} @tab @code{INTEGER(8)} @tab GNU extension
8820 @item @emph{See also}:
8827 @section @code{ISHFTC} --- Shift bits circularly
8833 @cindex bits, shift circular
8836 @item @emph{Description}:
8837 @code{ISHFTC} returns a value corresponding to @var{I} with the
8838 rightmost @var{SIZE} bits shifted circularly @var{SHIFT} places; that
8839 is, bits shifted out one end are shifted into the opposite end. A value
8840 of @var{SHIFT} greater than zero corresponds to a left shift, a value of
8841 zero corresponds to no shift, and a value less than zero corresponds to
8842 a right shift. The absolute value of @var{SHIFT} must be less than
8843 @var{SIZE}. If the @var{SIZE} argument is omitted, it is taken to be
8844 equivalent to @code{BIT_SIZE(I)}.
8846 @item @emph{Standard}:
8847 Fortran 90 and later, has overloads that are GNU extensions
8852 @item @emph{Syntax}:
8853 @code{RESULT = ISHFTC(I, SHIFT [, SIZE])}
8855 @item @emph{Arguments}:
8856 @multitable @columnfractions .15 .70
8857 @item @var{I} @tab The type shall be @code{INTEGER}.
8858 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
8859 @item @var{SIZE} @tab (Optional) The type shall be @code{INTEGER};
8860 the value must be greater than zero and less than or equal to
8864 @item @emph{Return value}:
8865 The return value is of type @code{INTEGER} and of the same kind as
8868 @item @emph{Specific names}:
8869 @multitable @columnfractions .20 .23 .20 .33
8870 @headitem Name @tab Argument @tab Return type @tab Standard
8871 @item @code{ISHFTC(A)} @tab @code{INTEGER A} @tab @code{INTEGER} @tab Fortran 90 and later
8872 @item @code{BSHFTC(A)} @tab @code{INTEGER(1) A} @tab @code{INTEGER(1)} @tab GNU extension
8873 @item @code{IISHFTC(A)} @tab @code{INTEGER(2) A} @tab @code{INTEGER(2)} @tab GNU extension
8874 @item @code{JISHFTC(A)} @tab @code{INTEGER(4) A} @tab @code{INTEGER(4)} @tab GNU extension
8875 @item @code{KISHFTC(A)} @tab @code{INTEGER(8) A} @tab @code{INTEGER(8)} @tab GNU extension
8878 @item @emph{See also}:
8885 @section @code{ISNAN} --- Test for a NaN
8890 @item @emph{Description}:
8891 @code{ISNAN} tests whether a floating-point value is an IEEE
8893 @item @emph{Standard}:
8899 @item @emph{Syntax}:
8902 @item @emph{Arguments}:
8903 @multitable @columnfractions .15 .70
8904 @item @var{X} @tab Variable of the type @code{REAL}.
8908 @item @emph{Return value}:
8909 Returns a default-kind @code{LOGICAL}. The returned value is @code{TRUE}
8910 if @var{X} is a NaN and @code{FALSE} otherwise.
8912 @item @emph{Example}:
8919 if (isnan(x)) stop '"x" is a NaN'
8920 end program test_nan
8927 @section @code{ITIME} --- Get current local time subroutine (hour/minutes/seconds)
8929 @cindex time, current
8930 @cindex current time
8933 @item @emph{Description}:
8934 @code{ITIME(VALUES)} Fills @var{VALUES} with the numerical values at the
8935 current local time. The hour (in the range 1-24), minute (in the range 1-60),
8936 and seconds (in the range 1-60) appear in elements 1, 2, and 3 of @var{VALUES},
8939 This intrinsic routine is provided for backwards compatibility with
8940 GNU Fortran 77. In new code, programmers should consider the use of
8941 the @ref{DATE_AND_TIME} intrinsic defined by the Fortran 95
8944 @item @emph{Standard}:
8950 @item @emph{Syntax}:
8951 @code{CALL ITIME(VALUES)}
8953 @item @emph{Arguments}:
8954 @multitable @columnfractions .15 .70
8955 @item @var{VALUES} @tab The type shall be @code{INTEGER, DIMENSION(3)}
8956 and the kind shall be the default integer kind.
8959 @item @emph{Return value}:
8960 Does not return anything.
8963 @item @emph{Example}:
8966 integer, dimension(3) :: tarray
8971 end program test_itime
8974 @item @emph{See also}:
8981 @section @code{KILL} --- Send a signal to a process
8985 @item @emph{Description}:
8986 Sends the signal specified by @var{SIG} to the process @var{PID}.
8989 This intrinsic is provided in both subroutine and function forms;
8990 however, only one form can be used in any given program unit.
8991 @item @emph{Standard}:
8994 @item @emph{Standard}:
8998 Subroutine, function
9000 @item @emph{Syntax}:
9001 @multitable @columnfractions .80
9002 @item @code{CALL KILL(PID, SIG [, STATUS])}
9003 @item @code{STATUS = KILL(PID, SIG)}
9006 @item @emph{Arguments}:
9007 @multitable @columnfractions .15 .70
9008 @item @var{PID} @tab Shall be a scalar @code{INTEGER} with @code{INTENT(IN)}.
9009 @item @var{SIG} @tab Shall be a scalar @code{INTEGER} with @code{INTENT(IN)}.
9010 @item @var{STATUS} @tab [Subroutine](Optional)
9011 Shall be a scalar @code{INTEGER}.
9012 Returns 0 on success; otherwise a system-specific error code is returned.
9013 @item @var{STATUS} @tab [Function] The kind type parameter is that of
9015 Returns 0 on success; otherwise a system-specific error code is returned.
9018 @item @emph{See also}:
9025 @section @code{KIND} --- Kind of an entity
9030 @item @emph{Description}:
9031 @code{KIND(X)} returns the kind value of the entity @var{X}.
9033 @item @emph{Standard}:
9034 Fortran 95 and later
9039 @item @emph{Syntax}:
9042 @item @emph{Arguments}:
9043 @multitable @columnfractions .15 .70
9044 @item @var{X} @tab Shall be of type @code{LOGICAL}, @code{INTEGER},
9045 @code{REAL}, @code{COMPLEX} or @code{CHARACTER}. It may be scalar or
9049 @item @emph{Return value}:
9050 The return value is a scalar of type @code{INTEGER} and of the default
9053 @item @emph{Example}:
9056 integer,parameter :: kc = kind(' ')
9057 integer,parameter :: kl = kind(.true.)
9059 print *, "The default character kind is ", kc
9060 print *, "The default logical kind is ", kl
9061 end program test_kind
9069 @section @code{LBOUND} --- Lower dimension bounds of an array
9071 @cindex array, lower bound
9074 @item @emph{Description}:
9075 Returns the lower bounds of an array, or a single lower bound
9076 along the @var{DIM} dimension.
9077 @item @emph{Standard}:
9078 Fortran 90 and later, with @var{KIND} argument Fortran 2003 and later
9083 @item @emph{Syntax}:
9084 @code{RESULT = LBOUND(ARRAY [, DIM [, KIND]])}
9086 @item @emph{Arguments}:
9087 @multitable @columnfractions .15 .70
9088 @item @var{ARRAY} @tab Shall be an array, of any type.
9089 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER}.
9090 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
9091 expression indicating the kind parameter of the result.
9094 @item @emph{Return value}:
9095 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
9096 @var{KIND} is absent, the return value is of default integer kind.
9097 If @var{DIM} is absent, the result is an array of the lower bounds of
9098 @var{ARRAY}. If @var{DIM} is present, the result is a scalar
9099 corresponding to the lower bound of the array along that dimension. If
9100 @var{ARRAY} is an expression rather than a whole array or array
9101 structure component, or if it has a zero extent along the relevant
9102 dimension, the lower bound is taken to be 1.
9104 @item @emph{See also}:
9112 @section @code{LCOBOUND} --- Lower codimension bounds of an array
9114 @cindex coarray, lower bound
9117 @item @emph{Description}:
9118 Returns the lower bounds of a coarray, or a single lower cobound
9119 along the @var{DIM} codimension.
9120 @item @emph{Standard}:
9121 Fortran 2008 and later
9126 @item @emph{Syntax}:
9127 @code{RESULT = LCOBOUND(COARRAY [, DIM [, KIND]])}
9129 @item @emph{Arguments}:
9130 @multitable @columnfractions .15 .70
9131 @item @var{ARRAY} @tab Shall be an coarray, of any type.
9132 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER}.
9133 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
9134 expression indicating the kind parameter of the result.
9137 @item @emph{Return value}:
9138 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
9139 @var{KIND} is absent, the return value is of default integer kind.
9140 If @var{DIM} is absent, the result is an array of the lower cobounds of
9141 @var{COARRAY}. If @var{DIM} is present, the result is a scalar
9142 corresponding to the lower cobound of the array along that codimension.
9144 @item @emph{See also}:
9152 @section @code{LEADZ} --- Number of leading zero bits of an integer
9157 @item @emph{Description}:
9158 @code{LEADZ} returns the number of leading zero bits of an integer.
9160 @item @emph{Standard}:
9161 Fortran 2008 and later
9166 @item @emph{Syntax}:
9167 @code{RESULT = LEADZ(I)}
9169 @item @emph{Arguments}:
9170 @multitable @columnfractions .15 .70
9171 @item @var{I} @tab Shall be of type @code{INTEGER}.
9174 @item @emph{Return value}:
9175 The type of the return value is the default @code{INTEGER}.
9176 If all the bits of @code{I} are zero, the result value is @code{BIT_SIZE(I)}.
9178 @item @emph{Example}:
9181 WRITE (*,*) BIT_SIZE(1) ! prints 32
9182 WRITE (*,*) LEADZ(1) ! prints 31
9186 @item @emph{See also}:
9196 @section @code{LEN} --- Length of a character entity
9198 @cindex string, length
9201 @item @emph{Description}:
9202 Returns the length of a character string. If @var{STRING} is an array,
9203 the length of an element of @var{STRING} is returned. Note that
9204 @var{STRING} need not be defined when this intrinsic is invoked, since
9205 only the length, not the content, of @var{STRING} is needed.
9207 @item @emph{Standard}:
9208 Fortran 77 and later, with @var{KIND} argument Fortran 2003 and later
9213 @item @emph{Syntax}:
9214 @code{L = LEN(STRING [, KIND])}
9216 @item @emph{Arguments}:
9217 @multitable @columnfractions .15 .70
9218 @item @var{STRING} @tab Shall be a scalar or array of type
9219 @code{CHARACTER}, with @code{INTENT(IN)}
9220 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
9221 expression indicating the kind parameter of the result.
9224 @item @emph{Return value}:
9225 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
9226 @var{KIND} is absent, the return value is of default integer kind.
9229 @item @emph{Specific names}:
9230 @multitable @columnfractions .20 .23 .20 .33
9231 @headitem Name @tab Argument @tab Return type @tab Standard
9232 @item @code{LEN(STRING)} @tab @code{CHARACTER} @tab @code{INTEGER} @tab Fortran 77 and later
9236 @item @emph{See also}:
9245 @section @code{LEN_TRIM} --- Length of a character entity without trailing blank characters
9247 @cindex string, length, without trailing whitespace
9250 @item @emph{Description}:
9251 Returns the length of a character string, ignoring any trailing blanks.
9253 @item @emph{Standard}:
9254 Fortran 90 and later, with @var{KIND} argument Fortran 2003 and later
9259 @item @emph{Syntax}:
9260 @code{RESULT = LEN_TRIM(STRING [, KIND])}
9262 @item @emph{Arguments}:
9263 @multitable @columnfractions .15 .70
9264 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER},
9265 with @code{INTENT(IN)}
9266 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
9267 expression indicating the kind parameter of the result.
9270 @item @emph{Return value}:
9271 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
9272 @var{KIND} is absent, the return value is of default integer kind.
9274 @item @emph{See also}:
9283 @section @code{LGE} --- Lexical greater than or equal
9285 @cindex lexical comparison of strings
9286 @cindex string, comparison
9289 @item @emph{Description}:
9290 Determines whether one string is lexically greater than or equal to
9291 another string, where the two strings are interpreted as containing
9292 ASCII character codes. If the String A and String B are not the same
9293 length, the shorter is compared as if spaces were appended to it to form
9294 a value that has the same length as the longer.
9296 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
9297 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
9298 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
9299 that the latter use the processor's character ordering (which is not
9300 ASCII on some targets), whereas the former always use the ASCII
9303 @item @emph{Standard}:
9304 Fortran 77 and later
9309 @item @emph{Syntax}:
9310 @code{RESULT = LGE(STRING_A, STRING_B)}
9312 @item @emph{Arguments}:
9313 @multitable @columnfractions .15 .70
9314 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
9315 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
9318 @item @emph{Return value}:
9319 Returns @code{.TRUE.} if @code{STRING_A >= STRING_B}, and @code{.FALSE.}
9320 otherwise, based on the ASCII ordering.
9322 @item @emph{Specific names}:
9323 @multitable @columnfractions .34 .16 .17 .30
9324 @headitem Name @tab Argument @tab Return type @tab Standard
9325 @item @code{LGE(STRING_A,STRING_B)} @tab @code{CHARACTER} @tab @code{LOGICAL} @tab Fortran 77 and later
9328 @item @emph{See also}:
9337 @section @code{LGT} --- Lexical greater than
9339 @cindex lexical comparison of strings
9340 @cindex string, comparison
9343 @item @emph{Description}:
9344 Determines whether one string is lexically greater than another string,
9345 where the two strings are interpreted as containing ASCII character
9346 codes. If the String A and String B are not the same length, the
9347 shorter is compared as if spaces were appended to it to form a value
9348 that has the same length as the longer.
9350 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
9351 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
9352 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
9353 that the latter use the processor's character ordering (which is not
9354 ASCII on some targets), whereas the former always use the ASCII
9357 @item @emph{Standard}:
9358 Fortran 77 and later
9363 @item @emph{Syntax}:
9364 @code{RESULT = LGT(STRING_A, STRING_B)}
9366 @item @emph{Arguments}:
9367 @multitable @columnfractions .15 .70
9368 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
9369 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
9372 @item @emph{Return value}:
9373 Returns @code{.TRUE.} if @code{STRING_A > STRING_B}, and @code{.FALSE.}
9374 otherwise, based on the ASCII ordering.
9376 @item @emph{Specific names}:
9377 @multitable @columnfractions .34 .16 .17 .30
9378 @headitem Name @tab Argument @tab Return type @tab Standard
9379 @item @code{LGT(STRING_A,STRING_B)} @tab @code{CHARACTER} @tab @code{LOGICAL} @tab Fortran 77 and later
9382 @item @emph{See also}:
9391 @section @code{LINK} --- Create a hard link
9393 @cindex file system, create link
9394 @cindex file system, hard link
9397 @item @emph{Description}:
9398 Makes a (hard) link from file @var{PATH1} to @var{PATH2}. A null
9399 character (@code{CHAR(0)}) can be used to mark the end of the names in
9400 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
9401 names are ignored. If the @var{STATUS} argument is supplied, it
9402 contains 0 on success or a nonzero error code upon return; see
9405 This intrinsic is provided in both subroutine and function forms;
9406 however, only one form can be used in any given program unit.
9408 @item @emph{Standard}:
9412 Subroutine, function
9414 @item @emph{Syntax}:
9415 @multitable @columnfractions .80
9416 @item @code{CALL LINK(PATH1, PATH2 [, STATUS])}
9417 @item @code{STATUS = LINK(PATH1, PATH2)}
9420 @item @emph{Arguments}:
9421 @multitable @columnfractions .15 .70
9422 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
9423 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
9424 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
9427 @item @emph{See also}:
9435 @section @code{LLE} --- Lexical less than or equal
9437 @cindex lexical comparison of strings
9438 @cindex string, comparison
9441 @item @emph{Description}:
9442 Determines whether one string is lexically less than or equal to another
9443 string, where the two strings are interpreted as containing ASCII
9444 character codes. If the String A and String B are not the same length,
9445 the shorter is compared as if spaces were appended to it to form a value
9446 that has the same length as the longer.
9448 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
9449 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
9450 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
9451 that the latter use the processor's character ordering (which is not
9452 ASCII on some targets), whereas the former always use the ASCII
9455 @item @emph{Standard}:
9456 Fortran 77 and later
9461 @item @emph{Syntax}:
9462 @code{RESULT = LLE(STRING_A, STRING_B)}
9464 @item @emph{Arguments}:
9465 @multitable @columnfractions .15 .70
9466 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
9467 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
9470 @item @emph{Return value}:
9471 Returns @code{.TRUE.} if @code{STRING_A <= STRING_B}, and @code{.FALSE.}
9472 otherwise, based on the ASCII ordering.
9474 @item @emph{Specific names}:
9475 @multitable @columnfractions .34 .16 .17 .30
9476 @headitem Name @tab Argument @tab Return type @tab Standard
9477 @item @code{LLE(STRING_A,STRING_B)} @tab @code{CHARACTER} @tab @code{LOGICAL} @tab Fortran 77 and later
9480 @item @emph{See also}:
9489 @section @code{LLT} --- Lexical less than
9491 @cindex lexical comparison of strings
9492 @cindex string, comparison
9495 @item @emph{Description}:
9496 Determines whether one string is lexically less than another string,
9497 where the two strings are interpreted as containing ASCII character
9498 codes. If the String A and String B are not the same length, the
9499 shorter is compared as if spaces were appended to it to form a value
9500 that has the same length as the longer.
9502 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
9503 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
9504 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
9505 that the latter use the processor's character ordering (which is not
9506 ASCII on some targets), whereas the former always use the ASCII
9509 @item @emph{Standard}:
9510 Fortran 77 and later
9515 @item @emph{Syntax}:
9516 @code{RESULT = LLT(STRING_A, STRING_B)}
9518 @item @emph{Arguments}:
9519 @multitable @columnfractions .15 .70
9520 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
9521 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
9524 @item @emph{Return value}:
9525 Returns @code{.TRUE.} if @code{STRING_A < STRING_B}, and @code{.FALSE.}
9526 otherwise, based on the ASCII ordering.
9528 @item @emph{Specific names}:
9529 @multitable @columnfractions .34 .16 .17 .30
9530 @headitem Name @tab Argument @tab Return type @tab Standard
9531 @item @code{LLT(STRING_A,STRING_B)} @tab @code{CHARACTER} @tab @code{LOGICAL} @tab Fortran 77 and later
9534 @item @emph{See also}:
9543 @section @code{LNBLNK} --- Index of the last non-blank character in a string
9545 @cindex string, find non-blank character
9548 @item @emph{Description}:
9549 Returns the length of a character string, ignoring any trailing blanks.
9550 This is identical to the standard @code{LEN_TRIM} intrinsic, and is only
9551 included for backwards compatibility.
9553 @item @emph{Standard}:
9559 @item @emph{Syntax}:
9560 @code{RESULT = LNBLNK(STRING)}
9562 @item @emph{Arguments}:
9563 @multitable @columnfractions .15 .70
9564 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER},
9565 with @code{INTENT(IN)}
9568 @item @emph{Return value}:
9569 The return value is of @code{INTEGER(kind=4)} type.
9571 @item @emph{See also}:
9572 @ref{INDEX intrinsic}, @*
9579 @section @code{LOC} --- Returns the address of a variable
9581 @cindex location of a variable in memory
9584 @item @emph{Description}:
9585 @code{LOC(X)} returns the address of @var{X} as an integer.
9587 @item @emph{Standard}:
9593 @item @emph{Syntax}:
9594 @code{RESULT = LOC(X)}
9596 @item @emph{Arguments}:
9597 @multitable @columnfractions .15 .70
9598 @item @var{X} @tab Variable of any type.
9601 @item @emph{Return value}:
9602 The return value is of type @code{INTEGER}, with a @code{KIND}
9603 corresponding to the size (in bytes) of a memory address on the target
9606 @item @emph{Example}:
9613 end program test_loc
9620 @section @code{LOG} --- Natural logarithm function
9627 @cindex exponential function, inverse
9628 @cindex logarithm function
9629 @cindex natural logarithm function
9632 @item @emph{Description}:
9633 @code{LOG(X)} computes the natural logarithm of @var{X}, i.e. the
9634 logarithm to the base @math{e}.
9636 @item @emph{Standard}:
9637 Fortran 77 and later, has GNU extensions
9642 @item @emph{Syntax}:
9643 @code{RESULT = LOG(X)}
9645 @item @emph{Arguments}:
9646 @multitable @columnfractions .15 .70
9647 @item @var{X} @tab The type shall be @code{REAL} or
9651 @item @emph{Return value}:
9652 The return value is of type @code{REAL} or @code{COMPLEX}.
9653 The kind type parameter is the same as @var{X}.
9654 If @var{X} is @code{COMPLEX}, the imaginary part @math{\omega} is in the range
9655 @math{-\pi < \omega \leq \pi}.
9657 @item @emph{Example}:
9660 real(8) :: x = 2.7182818284590451_8
9661 complex :: z = (1.0, 2.0)
9662 x = log(x) ! will yield (approximately) 1
9664 end program test_log
9667 @item @emph{Specific names}:
9668 @multitable @columnfractions .20 .23 .20 .33
9669 @headitem Name @tab Argument @tab Return type @tab Standard
9670 @item @code{ALOG(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 or later
9671 @item @code{DLOG(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 or later
9672 @item @code{CLOG(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab Fortran 77 or later
9673 @item @code{ZLOG(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
9674 @item @code{CDLOG(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
9681 @section @code{LOG10} --- Base 10 logarithm function
9685 @cindex exponential function, inverse
9686 @cindex logarithm function with base 10
9687 @cindex base 10 logarithm function
9690 @item @emph{Description}:
9691 @code{LOG10(X)} computes the base 10 logarithm of @var{X}.
9693 @item @emph{Standard}:
9694 Fortran 77 and later
9699 @item @emph{Syntax}:
9700 @code{RESULT = LOG10(X)}
9702 @item @emph{Arguments}:
9703 @multitable @columnfractions .15 .70
9704 @item @var{X} @tab The type shall be @code{REAL}.
9707 @item @emph{Return value}:
9708 The return value is of type @code{REAL} or @code{COMPLEX}.
9709 The kind type parameter is the same as @var{X}.
9711 @item @emph{Example}:
9714 real(8) :: x = 10.0_8
9716 end program test_log10
9719 @item @emph{Specific names}:
9720 @multitable @columnfractions .20 .23 .20 .33
9721 @headitem Name @tab Argument @tab Return type @tab Standard
9722 @item @code{ALOG10(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
9723 @item @code{DLOG10(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
9730 @section @code{LOG_GAMMA} --- Logarithm of the Gamma function
9735 @cindex Gamma function, logarithm of
9738 @item @emph{Description}:
9739 @code{LOG_GAMMA(X)} computes the natural logarithm of the absolute value
9740 of the Gamma (@math{\Gamma}) function.
9742 @item @emph{Standard}:
9743 Fortran 2008 and later
9748 @item @emph{Syntax}:
9749 @code{X = LOG_GAMMA(X)}
9751 @item @emph{Arguments}:
9752 @multitable @columnfractions .15 .70
9753 @item @var{X} @tab Shall be of type @code{REAL} and neither zero
9754 nor a negative integer.
9757 @item @emph{Return value}:
9758 The return value is of type @code{REAL} of the same kind as @var{X}.
9760 @item @emph{Example}:
9762 program test_log_gamma
9764 x = lgamma(x) ! returns 0.0
9765 end program test_log_gamma
9768 @item @emph{Specific names}:
9769 @multitable @columnfractions .20 .23 .20 .33
9770 @headitem Name @tab Argument @tab Return type @tab Standard
9771 @item @code{LGAMMA(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab GNU extension
9772 @item @code{ALGAMA(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab GNU extension
9773 @item @code{DLGAMA(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
9776 @item @emph{See also}:
9784 @section @code{LOGICAL} --- Convert to logical type
9786 @cindex conversion, to logical
9789 @item @emph{Description}:
9790 Converts one kind of @code{LOGICAL} variable to another.
9792 @item @emph{Standard}:
9793 Fortran 90 and later
9798 @item @emph{Syntax}:
9799 @code{RESULT = LOGICAL(L [, KIND])}
9801 @item @emph{Arguments}:
9802 @multitable @columnfractions .15 .70
9803 @item @var{L} @tab The type shall be @code{LOGICAL}.
9804 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
9805 expression indicating the kind parameter of the result.
9808 @item @emph{Return value}:
9809 The return value is a @code{LOGICAL} value equal to @var{L}, with a
9810 kind corresponding to @var{KIND}, or of the default logical kind if
9811 @var{KIND} is not given.
9813 @item @emph{See also}:
9822 @section @code{LSHIFT} --- Left shift bits
9824 @cindex bits, shift left
9827 @item @emph{Description}:
9828 @code{LSHIFT} returns a value corresponding to @var{I} with all of the
9829 bits shifted left by @var{SHIFT} places. @var{SHIFT} shall be
9830 nonnegative and less than or equal to @code{BIT_SIZE(I)}, otherwise
9831 the result value is undefined. Bits shifted out from the left end are
9832 lost; zeros are shifted in from the opposite end.
9834 This function has been superseded by the @code{ISHFT} intrinsic, which
9835 is standard in Fortran 95 and later, and the @code{SHIFTL} intrinsic,
9836 which is standard in Fortran 2008 and later.
9838 @item @emph{Standard}:
9844 @item @emph{Syntax}:
9845 @code{RESULT = LSHIFT(I, SHIFT)}
9847 @item @emph{Arguments}:
9848 @multitable @columnfractions .15 .70
9849 @item @var{I} @tab The type shall be @code{INTEGER}.
9850 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
9853 @item @emph{Return value}:
9854 The return value is of type @code{INTEGER} and of the same kind as
9857 @item @emph{See also}:
9869 @section @code{LSTAT} --- Get file status
9871 @cindex file system, file status
9874 @item @emph{Description}:
9875 @code{LSTAT} is identical to @ref{STAT}, except that if path is a
9876 symbolic link, then the link itself is statted, not the file that it
9879 The elements in @code{VALUES} are the same as described by @ref{STAT}.
9881 This intrinsic is provided in both subroutine and function forms;
9882 however, only one form can be used in any given program unit.
9884 @item @emph{Standard}:
9888 Subroutine, function
9890 @item @emph{Syntax}:
9891 @multitable @columnfractions .80
9892 @item @code{CALL LSTAT(NAME, VALUES [, STATUS])}
9893 @item @code{STATUS = LSTAT(NAME, VALUES)}
9896 @item @emph{Arguments}:
9897 @multitable @columnfractions .15 .70
9898 @item @var{NAME} @tab The type shall be @code{CHARACTER} of the default
9899 kind, a valid path within the file system.
9900 @item @var{VALUES} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
9901 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}.
9902 Returns 0 on success and a system specific error code otherwise.
9905 @item @emph{Example}:
9906 See @ref{STAT} for an example.
9908 @item @emph{See also}:
9909 To stat an open file: @*
9918 @section @code{LTIME} --- Convert time to local time info
9920 @cindex time, conversion to local time info
9923 @item @emph{Description}:
9924 Given a system time value @var{TIME} (as provided by the @ref{TIME}
9925 intrinsic), fills @var{VALUES} with values extracted from it appropriate
9926 to the local time zone using @code{localtime(3)}.
9928 This intrinsic routine is provided for backwards compatibility with
9929 GNU Fortran 77. In new code, programmers should consider the use of
9930 the @ref{DATE_AND_TIME} intrinsic defined by the Fortran 95
9933 @item @emph{Standard}:
9939 @item @emph{Syntax}:
9940 @code{CALL LTIME(TIME, VALUES)}
9942 @item @emph{Arguments}:
9943 @multitable @columnfractions .15 .70
9944 @item @var{TIME} @tab An @code{INTEGER} scalar expression
9945 corresponding to a system time, with @code{INTENT(IN)}.
9946 @item @var{VALUES} @tab A default @code{INTEGER} array with 9 elements,
9947 with @code{INTENT(OUT)}.
9950 @item @emph{Return value}:
9951 The elements of @var{VALUES} are assigned as follows:
9953 @item Seconds after the minute, range 0--59 or 0--61 to allow for leap
9955 @item Minutes after the hour, range 0--59
9956 @item Hours past midnight, range 0--23
9957 @item Day of month, range 1--31
9958 @item Number of months since January, range 0--11
9959 @item Years since 1900
9960 @item Number of days since Sunday, range 0--6
9961 @item Days since January 1, range 0--365
9962 @item Daylight savings indicator: positive if daylight savings is in
9963 effect, zero if not, and negative if the information is not available.
9966 @item @emph{See also}:
9967 @ref{DATE_AND_TIME}, @*
9977 @section @code{MALLOC} --- Allocate dynamic memory
9979 @cindex pointer, cray
9982 @item @emph{Description}:
9983 @code{MALLOC(SIZE)} allocates @var{SIZE} bytes of dynamic memory and
9984 returns the address of the allocated memory. The @code{MALLOC} intrinsic
9985 is an extension intended to be used with Cray pointers, and is provided
9986 in GNU Fortran to allow the user to compile legacy code. For new code
9987 using Fortran 95 pointers, the memory allocation intrinsic is
9990 @item @emph{Standard}:
9996 @item @emph{Syntax}:
9997 @code{PTR = MALLOC(SIZE)}
9999 @item @emph{Arguments}:
10000 @multitable @columnfractions .15 .70
10001 @item @var{SIZE} @tab The type shall be @code{INTEGER}.
10004 @item @emph{Return value}:
10005 The return value is of type @code{INTEGER(K)}, with @var{K} such that
10006 variables of type @code{INTEGER(K)} have the same size as
10007 C pointers (@code{sizeof(void *)}).
10009 @item @emph{Example}:
10010 The following example demonstrates the use of @code{MALLOC} and
10011 @code{FREE} with Cray pointers.
10014 program test_malloc
10020 ptr_x = malloc(20*8)
10022 x(i) = sqrt(1.0d0 / i)
10030 end program test_malloc
10033 @item @emph{See also}:
10040 @section @code{MASKL} --- Left justified mask
10042 @cindex mask, left justified
10045 @item @emph{Description}:
10046 @code{MASKL(I[, KIND])} has its leftmost @var{I} bits set to 1, and the
10047 remaining bits set to 0.
10049 @item @emph{Standard}:
10050 Fortran 2008 and later
10052 @item @emph{Class}:
10055 @item @emph{Syntax}:
10056 @code{RESULT = MASKL(I[, KIND])}
10058 @item @emph{Arguments}:
10059 @multitable @columnfractions .15 .70
10060 @item @var{I} @tab Shall be of type @code{INTEGER}.
10061 @item @var{KIND} @tab Shall be a scalar constant expression of type
10065 @item @emph{Return value}:
10066 The return value is of type @code{INTEGER}. If @var{KIND} is present, it
10067 specifies the kind value of the return type; otherwise, it is of the
10068 default integer kind.
10070 @item @emph{See also}:
10077 @section @code{MASKR} --- Right justified mask
10079 @cindex mask, right justified
10082 @item @emph{Description}:
10083 @code{MASKL(I[, KIND])} has its rightmost @var{I} bits set to 1, and the
10084 remaining bits set to 0.
10086 @item @emph{Standard}:
10087 Fortran 2008 and later
10089 @item @emph{Class}:
10092 @item @emph{Syntax}:
10093 @code{RESULT = MASKR(I[, KIND])}
10095 @item @emph{Arguments}:
10096 @multitable @columnfractions .15 .70
10097 @item @var{I} @tab Shall be of type @code{INTEGER}.
10098 @item @var{KIND} @tab Shall be a scalar constant expression of type
10102 @item @emph{Return value}:
10103 The return value is of type @code{INTEGER}. If @var{KIND} is present, it
10104 specifies the kind value of the return type; otherwise, it is of the
10105 default integer kind.
10107 @item @emph{See also}:
10114 @section @code{MATMUL} --- matrix multiplication
10116 @cindex matrix multiplication
10117 @cindex product, matrix
10120 @item @emph{Description}:
10121 Performs a matrix multiplication on numeric or logical arguments.
10123 @item @emph{Standard}:
10124 Fortran 90 and later
10126 @item @emph{Class}:
10127 Transformational function
10129 @item @emph{Syntax}:
10130 @code{RESULT = MATMUL(MATRIX_A, MATRIX_B)}
10132 @item @emph{Arguments}:
10133 @multitable @columnfractions .15 .70
10134 @item @var{MATRIX_A} @tab An array of @code{INTEGER},
10135 @code{REAL}, @code{COMPLEX}, or @code{LOGICAL} type, with a rank of
10137 @item @var{MATRIX_B} @tab An array of @code{INTEGER},
10138 @code{REAL}, or @code{COMPLEX} type if @var{MATRIX_A} is of a numeric
10139 type; otherwise, an array of @code{LOGICAL} type. The rank shall be one
10140 or two, and the first (or only) dimension of @var{MATRIX_B} shall be
10141 equal to the last (or only) dimension of @var{MATRIX_A}.
10142 @var{MATRIX_A} and @var{MATRIX_B} shall not both be rank one arrays.
10145 @item @emph{Return value}:
10146 The matrix product of @var{MATRIX_A} and @var{MATRIX_B}. The type and
10147 kind of the result follow the usual type and kind promotion rules, as
10148 for the @code{*} or @code{.AND.} operators.
10154 @section @code{MAX} --- Maximum value of an argument list
10161 @cindex maximum value
10164 @item @emph{Description}:
10165 Returns the argument with the largest (most positive) value.
10167 @item @emph{Standard}:
10168 Fortran 77 and later
10170 @item @emph{Class}:
10173 @item @emph{Syntax}:
10174 @code{RESULT = MAX(A1, A2 [, A3 [, ...]])}
10176 @item @emph{Arguments}:
10177 @multitable @columnfractions .15 .70
10178 @item @var{A1} @tab The type shall be @code{INTEGER} or
10180 @item @var{A2}, @var{A3}, ... @tab An expression of the same type and kind
10181 as @var{A1}. (As a GNU extension, arguments of different kinds are
10185 @item @emph{Return value}:
10186 The return value corresponds to the maximum value among the arguments,
10187 and has the same type and kind as the first argument.
10189 @item @emph{Specific names}:
10190 @multitable @columnfractions .20 .23 .20 .33
10191 @headitem Name @tab Argument @tab Return type @tab Standard
10192 @item @code{MAX0(A1)} @tab @code{INTEGER(4) A1} @tab @code{INTEGER(4)} @tab Fortran 77 and later
10193 @item @code{AMAX0(A1)} @tab @code{INTEGER(4) A1} @tab @code{REAL(MAX(X))} @tab Fortran 77 and later
10194 @item @code{MAX1(A1)} @tab @code{REAL A1} @tab @code{INT(MAX(X))} @tab Fortran 77 and later
10195 @item @code{AMAX1(A1)} @tab @code{REAL(4) A1} @tab @code{REAL(4)} @tab Fortran 77 and later
10196 @item @code{DMAX1(A1)} @tab @code{REAL(8) A1} @tab @code{REAL(8)} @tab Fortran 77 and later
10199 @item @emph{See also}:
10208 @section @code{MAXEXPONENT} --- Maximum exponent of a real kind
10209 @fnindex MAXEXPONENT
10210 @cindex model representation, maximum exponent
10213 @item @emph{Description}:
10214 @code{MAXEXPONENT(X)} returns the maximum exponent in the model of the
10217 @item @emph{Standard}:
10218 Fortran 90 and later
10220 @item @emph{Class}:
10223 @item @emph{Syntax}:
10224 @code{RESULT = MAXEXPONENT(X)}
10226 @item @emph{Arguments}:
10227 @multitable @columnfractions .15 .70
10228 @item @var{X} @tab Shall be of type @code{REAL}.
10231 @item @emph{Return value}:
10232 The return value is of type @code{INTEGER} and of the default integer
10235 @item @emph{Example}:
10241 print *, minexponent(x), maxexponent(x)
10242 print *, minexponent(y), maxexponent(y)
10243 end program exponents
10250 @section @code{MAXLOC} --- Location of the maximum value within an array
10252 @cindex array, location of maximum element
10255 @item @emph{Description}:
10256 Determines the location of the element in the array with the maximum
10257 value, or, if the @var{DIM} argument is supplied, determines the
10258 locations of the maximum element along each row of the array in the
10259 @var{DIM} direction. If @var{MASK} is present, only the elements for
10260 which @var{MASK} is @code{.TRUE.} are considered. If more than one
10261 element in the array has the maximum value, the location returned is
10262 that of the first such element in array element order if the
10263 @var{BACK} is not present, or is false; if @var{BACK} is true, the location
10264 returned is that of the last such element. If the array has zero
10265 size, or all of the elements of @var{MASK} are @code{.FALSE.}, then
10266 the result is an array of zeroes. Similarly, if @var{DIM} is supplied
10267 and all of the elements of @var{MASK} along a given row are zero, the
10268 result value for that row is zero.
10270 @item @emph{Standard}:
10271 Fortran 95 and later; @var{ARRAY} of @code{CHARACTER} and the
10272 @var{KIND} argument are available in Fortran 2003 and later.
10273 The @var{BACK} argument is available in Fortran 2008 and later.
10275 @item @emph{Class}:
10276 Transformational function
10278 @item @emph{Syntax}:
10279 @multitable @columnfractions .80
10280 @item @code{RESULT = MAXLOC(ARRAY, DIM [, MASK] [,KIND] [,BACK])}
10281 @item @code{RESULT = MAXLOC(ARRAY [, MASK] [,KIND] [,BACK])}
10284 @item @emph{Arguments}:
10285 @multitable @columnfractions .15 .70
10286 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER} or
10288 @item @var{DIM} @tab (Optional) Shall be a scalar of type
10289 @code{INTEGER}, with a value between one and the rank of @var{ARRAY},
10290 inclusive. It may not be an optional dummy argument.
10291 @item @var{MASK} @tab Shall be of type @code{LOGICAL},
10292 and conformable with @var{ARRAY}.
10293 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
10294 expression indicating the kind parameter of the result.
10295 @item @var{BACK} @tab (Optional) A scalar of type @code{LOGICAL}.
10298 @item @emph{Return value}:
10299 If @var{DIM} is absent, the result is a rank-one array with a length
10300 equal to the rank of @var{ARRAY}. If @var{DIM} is present, the result
10301 is an array with a rank one less than the rank of @var{ARRAY}, and a
10302 size corresponding to the size of @var{ARRAY} with the @var{DIM}
10303 dimension removed. If @var{DIM} is present and @var{ARRAY} has a rank
10304 of one, the result is a scalar. If the optional argument @var{KIND}
10305 is present, the result is an integer of kind @var{KIND}, otherwise it
10306 is of default kind.
10308 @item @emph{See also}:
10317 @section @code{MAXVAL} --- Maximum value of an array
10319 @cindex array, maximum value
10320 @cindex maximum value
10323 @item @emph{Description}:
10324 Determines the maximum value of the elements in an array value, or, if
10325 the @var{DIM} argument is supplied, determines the maximum value along
10326 each row of the array in the @var{DIM} direction. If @var{MASK} is
10327 present, only the elements for which @var{MASK} is @code{.TRUE.} are
10328 considered. If the array has zero size, or all of the elements of
10329 @var{MASK} are @code{.FALSE.}, then the result is @code{-HUGE(ARRAY)}
10330 if @var{ARRAY} is numeric, or a string of nulls if @var{ARRAY} is of character
10333 @item @emph{Standard}:
10334 Fortran 90 and later
10336 @item @emph{Class}:
10337 Transformational function
10339 @item @emph{Syntax}:
10340 @multitable @columnfractions .80
10341 @item @code{RESULT = MAXVAL(ARRAY, DIM [, MASK])}
10342 @item @code{RESULT = MAXVAL(ARRAY [, MASK])}
10345 @item @emph{Arguments}:
10346 @multitable @columnfractions .15 .70
10347 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER} or
10349 @item @var{DIM} @tab (Optional) Shall be a scalar of type
10350 @code{INTEGER}, with a value between one and the rank of @var{ARRAY},
10351 inclusive. It may not be an optional dummy argument.
10352 @item @var{MASK} @tab (Optional) Shall be of type @code{LOGICAL},
10353 and conformable with @var{ARRAY}.
10356 @item @emph{Return value}:
10357 If @var{DIM} is absent, or if @var{ARRAY} has a rank of one, the result
10358 is a scalar. If @var{DIM} is present, the result is an array with a
10359 rank one less than the rank of @var{ARRAY}, and a size corresponding to
10360 the size of @var{ARRAY} with the @var{DIM} dimension removed. In all
10361 cases, the result is of the same type and kind as @var{ARRAY}.
10363 @item @emph{See also}:
10371 @section @code{MCLOCK} --- Time function
10373 @cindex time, clock ticks
10374 @cindex clock ticks
10377 @item @emph{Description}:
10378 Returns the number of clock ticks since the start of the process, based
10379 on the function @code{clock(3)} in the C standard library.
10381 This intrinsic is not fully portable, such as to systems with 32-bit
10382 @code{INTEGER} types but supporting times wider than 32 bits. Therefore,
10383 the values returned by this intrinsic might be, or become, negative, or
10384 numerically less than previous values, during a single run of the
10387 @item @emph{Standard}:
10390 @item @emph{Class}:
10393 @item @emph{Syntax}:
10394 @code{RESULT = MCLOCK()}
10396 @item @emph{Return value}:
10397 The return value is a scalar of type @code{INTEGER(4)}, equal to the
10398 number of clock ticks since the start of the process, or @code{-1} if
10399 the system does not support @code{clock(3)}.
10401 @item @emph{See also}:
10412 @section @code{MCLOCK8} --- Time function (64-bit)
10414 @cindex time, clock ticks
10415 @cindex clock ticks
10418 @item @emph{Description}:
10419 Returns the number of clock ticks since the start of the process, based
10420 on the function @code{clock(3)} in the C standard library.
10422 @emph{Warning:} this intrinsic does not increase the range of the timing
10423 values over that returned by @code{clock(3)}. On a system with a 32-bit
10424 @code{clock(3)}, @code{MCLOCK8} will return a 32-bit value, even though
10425 it is converted to a 64-bit @code{INTEGER(8)} value. That means
10426 overflows of the 32-bit value can still occur. Therefore, the values
10427 returned by this intrinsic might be or become negative or numerically
10428 less than previous values during a single run of the compiled program.
10430 @item @emph{Standard}:
10433 @item @emph{Class}:
10436 @item @emph{Syntax}:
10437 @code{RESULT = MCLOCK8()}
10439 @item @emph{Return value}:
10440 The return value is a scalar of type @code{INTEGER(8)}, equal to the
10441 number of clock ticks since the start of the process, or @code{-1} if
10442 the system does not support @code{clock(3)}.
10444 @item @emph{See also}:
10455 @section @code{MERGE} --- Merge variables
10457 @cindex array, merge arrays
10458 @cindex array, combine arrays
10461 @item @emph{Description}:
10462 Select values from two arrays according to a logical mask. The result
10463 is equal to @var{TSOURCE} if @var{MASK} is @code{.TRUE.}, or equal to
10464 @var{FSOURCE} if it is @code{.FALSE.}.
10466 @item @emph{Standard}:
10467 Fortran 90 and later
10469 @item @emph{Class}:
10472 @item @emph{Syntax}:
10473 @code{RESULT = MERGE(TSOURCE, FSOURCE, MASK)}
10475 @item @emph{Arguments}:
10476 @multitable @columnfractions .15 .70
10477 @item @var{TSOURCE} @tab May be of any type.
10478 @item @var{FSOURCE} @tab Shall be of the same type and type parameters
10480 @item @var{MASK} @tab Shall be of type @code{LOGICAL}.
10483 @item @emph{Return value}:
10484 The result is of the same type and type parameters as @var{TSOURCE}.
10491 @section @code{MERGE_BITS} --- Merge of bits under mask
10492 @fnindex MERGE_BITS
10493 @cindex bits, merge
10496 @item @emph{Description}:
10497 @code{MERGE_BITS(I, J, MASK)} merges the bits of @var{I} and @var{J}
10498 as determined by the mask. The i-th bit of the result is equal to the
10499 i-th bit of @var{I} if the i-th bit of @var{MASK} is 1; it is equal to
10500 the i-th bit of @var{J} otherwise.
10502 @item @emph{Standard}:
10503 Fortran 2008 and later
10505 @item @emph{Class}:
10508 @item @emph{Syntax}:
10509 @code{RESULT = MERGE_BITS(I, J, MASK)}
10511 @item @emph{Arguments}:
10512 @multitable @columnfractions .15 .70
10513 @item @var{I} @tab Shall be of type @code{INTEGER} or a boz-literal-constant.
10514 @item @var{J} @tab Shall be of type @code{INTEGER} with the same
10515 kind type parameter as @var{I} or a boz-literal-constant.
10516 @var{I} and @var{J} shall not both be boz-literal-constants.
10517 @item @var{MASK} @tab Shall be of type @code{INTEGER} or a boz-literal-constant
10518 and of the same kind as @var{I}.
10521 @item @emph{Return value}:
10522 The result is of the same type and kind as @var{I}.
10529 @section @code{MIN} --- Minimum value of an argument list
10536 @cindex minimum value
10539 @item @emph{Description}:
10540 Returns the argument with the smallest (most negative) value.
10542 @item @emph{Standard}:
10543 Fortran 77 and later
10545 @item @emph{Class}:
10548 @item @emph{Syntax}:
10549 @code{RESULT = MIN(A1, A2 [, A3, ...])}
10551 @item @emph{Arguments}:
10552 @multitable @columnfractions .15 .70
10553 @item @var{A1} @tab The type shall be @code{INTEGER} or
10555 @item @var{A2}, @var{A3}, ... @tab An expression of the same type and kind
10556 as @var{A1}. (As a GNU extension, arguments of different kinds are
10560 @item @emph{Return value}:
10561 The return value corresponds to the minimum value among the arguments,
10562 and has the same type and kind as the first argument.
10564 @item @emph{Specific names}:
10565 @multitable @columnfractions .20 .23 .20 .33
10566 @headitem Name @tab Argument @tab Return type @tab Standard
10567 @item @code{MIN0(A1)} @tab @code{INTEGER(4) A1} @tab @code{INTEGER(4)} @tab Fortran 77 and later
10568 @item @code{AMIN0(A1)} @tab @code{INTEGER(4) A1} @tab @code{REAL(4)} @tab Fortran 77 and later
10569 @item @code{MIN1(A1)} @tab @code{REAL A1} @tab @code{INTEGER(4)} @tab Fortran 77 and later
10570 @item @code{AMIN1(A1)} @tab @code{REAL(4) A1} @tab @code{REAL(4)} @tab Fortran 77 and later
10571 @item @code{DMIN1(A1)} @tab @code{REAL(8) A1} @tab @code{REAL(8)} @tab Fortran 77 and later
10574 @item @emph{See also}:
10583 @section @code{MINEXPONENT} --- Minimum exponent of a real kind
10584 @fnindex MINEXPONENT
10585 @cindex model representation, minimum exponent
10588 @item @emph{Description}:
10589 @code{MINEXPONENT(X)} returns the minimum exponent in the model of the
10592 @item @emph{Standard}:
10593 Fortran 90 and later
10595 @item @emph{Class}:
10598 @item @emph{Syntax}:
10599 @code{RESULT = MINEXPONENT(X)}
10601 @item @emph{Arguments}:
10602 @multitable @columnfractions .15 .70
10603 @item @var{X} @tab Shall be of type @code{REAL}.
10606 @item @emph{Return value}:
10607 The return value is of type @code{INTEGER} and of the default integer
10610 @item @emph{Example}:
10611 See @code{MAXEXPONENT} for an example.
10617 @section @code{MINLOC} --- Location of the minimum value within an array
10619 @cindex array, location of minimum element
10622 @item @emph{Description}:
10623 Determines the location of the element in the array with the minimum
10624 value, or, if the @var{DIM} argument is supplied, determines the
10625 locations of the minimum element along each row of the array in the
10626 @var{DIM} direction. If @var{MASK} is present, only the elements for
10627 which @var{MASK} is @code{.TRUE.} are considered. If more than one
10628 element in the array has the minimum value, the location returned is
10629 that of the first such element in array element order if the
10630 @var{BACK} is not present, or is false; if @var{BACK} is true, the location
10631 returned is that of the last such element. If the array has
10632 zero size, or all of the elements of @var{MASK} are @code{.FALSE.}, then
10633 the result is an array of zeroes. Similarly, if @var{DIM} is supplied
10634 and all of the elements of @var{MASK} along a given row are zero, the
10635 result value for that row is zero.
10637 @item @emph{Standard}:
10638 Fortran 90 and later; @var{ARRAY} of @code{CHARACTER} and the
10639 @var{KIND} argument are available in Fortran 2003 and later.
10640 The @var{BACK} argument is available in Fortran 2008 and later.
10642 @item @emph{Class}:
10643 Transformational function
10645 @item @emph{Syntax}:
10646 @multitable @columnfractions .80
10647 @item @code{RESULT = MINLOC(ARRAY, DIM [, MASK] [,KIND] [,BACK])}
10648 @item @code{RESULT = MINLOC(ARRAY [, MASK], [,KIND] [,BACK])}
10651 @item @emph{Arguments}:
10652 @multitable @columnfractions .15 .70
10653 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER},
10654 @code{REAL} or @code{CHARACTER}.
10655 @item @var{DIM} @tab (Optional) Shall be a scalar of type
10656 @code{INTEGER}, with a value between one and the rank of @var{ARRAY},
10657 inclusive. It may not be an optional dummy argument.
10658 @item @var{MASK} @tab Shall be of type @code{LOGICAL},
10659 and conformable with @var{ARRAY}.
10660 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
10661 expression indicating the kind parameter of the result.
10662 @item @var{BACK} @tab (Optional) A scalar of type @code{LOGICAL}.
10665 @item @emph{Return value}:
10666 If @var{DIM} is absent, the result is a rank-one array with a length
10667 equal to the rank of @var{ARRAY}. If @var{DIM} is present, the result
10668 is an array with a rank one less than the rank of @var{ARRAY}, and a
10669 size corresponding to the size of @var{ARRAY} with the @var{DIM}
10670 dimension removed. If @var{DIM} is present and @var{ARRAY} has a rank
10671 of one, the result is a scalar. If the optional argument @var{KIND}
10672 is present, the result is an integer of kind @var{KIND}, otherwise it
10673 is of default kind.
10675 @item @emph{See also}:
10684 @section @code{MINVAL} --- Minimum value of an array
10686 @cindex array, minimum value
10687 @cindex minimum value
10690 @item @emph{Description}:
10691 Determines the minimum value of the elements in an array value, or, if
10692 the @var{DIM} argument is supplied, determines the minimum value along
10693 each row of the array in the @var{DIM} direction. If @var{MASK} is
10694 present, only the elements for which @var{MASK} is @code{.TRUE.} are
10695 considered. If the array has zero size, or all of the elements of
10696 @var{MASK} are @code{.FALSE.}, then the result is @code{HUGE(ARRAY)} if
10697 @var{ARRAY} is numeric, or a string of @code{CHAR(255)} characters if
10698 @var{ARRAY} is of character type.
10700 @item @emph{Standard}:
10701 Fortran 90 and later
10703 @item @emph{Class}:
10704 Transformational function
10706 @item @emph{Syntax}:
10707 @multitable @columnfractions .80
10708 @item @code{RESULT = MINVAL(ARRAY, DIM [, MASK])}
10709 @item @code{RESULT = MINVAL(ARRAY [, MASK])}
10712 @item @emph{Arguments}:
10713 @multitable @columnfractions .15 .70
10714 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER} or
10716 @item @var{DIM} @tab (Optional) Shall be a scalar of type
10717 @code{INTEGER}, with a value between one and the rank of @var{ARRAY},
10718 inclusive. It may not be an optional dummy argument.
10719 @item @var{MASK} @tab Shall be of type @code{LOGICAL},
10720 and conformable with @var{ARRAY}.
10723 @item @emph{Return value}:
10724 If @var{DIM} is absent, or if @var{ARRAY} has a rank of one, the result
10725 is a scalar. If @var{DIM} is present, the result is an array with a
10726 rank one less than the rank of @var{ARRAY}, and a size corresponding to
10727 the size of @var{ARRAY} with the @var{DIM} dimension removed. In all
10728 cases, the result is of the same type and kind as @var{ARRAY}.
10730 @item @emph{See also}:
10738 @section @code{MOD} --- Remainder function
10747 @cindex division, remainder
10750 @item @emph{Description}:
10751 @code{MOD(A,P)} computes the remainder of the division of A by P@.
10753 @item @emph{Standard}:
10754 Fortran 77 and later, has overloads that are GNU extensions
10756 @item @emph{Class}:
10759 @item @emph{Syntax}:
10760 @code{RESULT = MOD(A, P)}
10762 @item @emph{Arguments}:
10763 @multitable @columnfractions .15 .70
10764 @item @var{A} @tab Shall be a scalar of type @code{INTEGER} or @code{REAL}.
10765 @item @var{P} @tab Shall be a scalar of the same type and kind as @var{A}
10766 and not equal to zero. (As a GNU extension, arguments of different kinds are
10770 @item @emph{Return value}:
10771 The return value is the result of @code{A - (INT(A/P) * P)}. The type
10772 and kind of the return value is the same as that of the arguments. The
10773 returned value has the same sign as A and a magnitude less than the
10774 magnitude of P. (As a GNU extension, kind is the largest kind of the actual
10777 @item @emph{Example}:
10781 print *, mod(17.5,5.5)
10782 print *, mod(17.5d0,5.5)
10783 print *, mod(17.5,5.5d0)
10785 print *, mod(-17,3)
10786 print *, mod(-17.5,5.5)
10787 print *, mod(-17.5d0,5.5)
10788 print *, mod(-17.5,5.5d0)
10790 print *, mod(17,-3)
10791 print *, mod(17.5,-5.5)
10792 print *, mod(17.5d0,-5.5)
10793 print *, mod(17.5,-5.5d0)
10794 end program test_mod
10797 @item @emph{Specific names}:
10798 @multitable @columnfractions .20 .25 .20 .31
10799 @headitem Name @tab Arguments @tab Return type @tab Standard
10800 @item @code{MOD(A,P)} @tab @code{INTEGER A,P} @tab @code{INTEGER} @tab Fortran 77 and later
10801 @item @code{AMOD(A,P)} @tab @code{REAL(4) A,P} @tab @code{REAL(4)} @tab Fortran 77 and later
10802 @item @code{DMOD(A,P)} @tab @code{REAL(8) A,P} @tab @code{REAL(8)} @tab Fortran 77 and later
10803 @item @code{BMOD(A,P)} @tab @code{INTEGER(1) A,P} @tab @code{INTEGER(1)} @tab GNU extension
10804 @item @code{IMOD(A,P)} @tab @code{INTEGER(2) A,P} @tab @code{INTEGER(2)} @tab GNU extension
10805 @item @code{JMOD(A,P)} @tab @code{INTEGER(4) A,P} @tab @code{INTEGER(4)} @tab GNU extension
10806 @item @code{KMOD(A,P)} @tab @code{INTEGER(8) A,P} @tab @code{INTEGER(8)} @tab GNU extension
10809 @item @emph{See also}:
10817 @section @code{MODULO} --- Modulo function
10820 @cindex division, modulo
10823 @item @emph{Description}:
10824 @code{MODULO(A,P)} computes the @var{A} modulo @var{P}.
10826 @item @emph{Standard}:
10827 Fortran 95 and later
10829 @item @emph{Class}:
10832 @item @emph{Syntax}:
10833 @code{RESULT = MODULO(A, P)}
10835 @item @emph{Arguments}:
10836 @multitable @columnfractions .15 .70
10837 @item @var{A} @tab Shall be a scalar of type @code{INTEGER} or @code{REAL}.
10838 @item @var{P} @tab Shall be a scalar of the same type and kind as @var{A}.
10839 It shall not be zero. (As a GNU extension, arguments of different kinds are
10843 @item @emph{Return value}:
10844 The type and kind of the result are those of the arguments. (As a GNU
10845 extension, kind is the largest kind of the actual arguments.)
10847 @item If @var{A} and @var{P} are of type @code{INTEGER}:
10848 @code{MODULO(A,P)} has the value @var{R} such that @code{A=Q*P+R}, where
10849 @var{Q} is an integer and @var{R} is between 0 (inclusive) and @var{P}
10851 @item If @var{A} and @var{P} are of type @code{REAL}:
10852 @code{MODULO(A,P)} has the value of @code{A - FLOOR (A / P) * P}.
10854 The returned value has the same sign as P and a magnitude less than
10855 the magnitude of P.
10857 @item @emph{Example}:
10859 program test_modulo
10860 print *, modulo(17,3)
10861 print *, modulo(17.5,5.5)
10863 print *, modulo(-17,3)
10864 print *, modulo(-17.5,5.5)
10866 print *, modulo(17,-3)
10867 print *, modulo(17.5,-5.5)
10871 @item @emph{See also}:
10879 @section @code{MOVE_ALLOC} --- Move allocation from one object to another
10880 @fnindex MOVE_ALLOC
10881 @cindex moving allocation
10882 @cindex allocation, moving
10885 @item @emph{Description}:
10886 @code{MOVE_ALLOC(FROM, TO)} moves the allocation from @var{FROM} to
10887 @var{TO}. @var{FROM} will become deallocated in the process.
10889 @item @emph{Standard}:
10890 Fortran 2003 and later
10892 @item @emph{Class}:
10895 @item @emph{Syntax}:
10896 @code{CALL MOVE_ALLOC(FROM, TO)}
10898 @item @emph{Arguments}:
10899 @multitable @columnfractions .15 .70
10900 @item @var{FROM} @tab @code{ALLOCATABLE}, @code{INTENT(INOUT)}, may be
10901 of any type and kind.
10902 @item @var{TO} @tab @code{ALLOCATABLE}, @code{INTENT(OUT)}, shall be
10903 of the same type, kind and rank as @var{FROM}.
10906 @item @emph{Return value}:
10909 @item @emph{Example}:
10911 program test_move_alloc
10912 integer, allocatable :: a(:), b(:)
10916 call move_alloc(a, b)
10917 print *, allocated(a), allocated(b)
10919 end program test_move_alloc
10926 @section @code{MVBITS} --- Move bits from one integer to another
10935 @item @emph{Description}:
10936 Moves @var{LEN} bits from positions @var{FROMPOS} through
10937 @code{FROMPOS+LEN-1} of @var{FROM} to positions @var{TOPOS} through
10938 @code{TOPOS+LEN-1} of @var{TO}. The portion of argument @var{TO} not
10939 affected by the movement of bits is unchanged. The values of
10940 @code{FROMPOS+LEN-1} and @code{TOPOS+LEN-1} must be less than
10941 @code{BIT_SIZE(FROM)}.
10943 @item @emph{Standard}:
10944 Fortran 90 and later, has overloads that are GNU extensions
10946 @item @emph{Class}:
10947 Elemental subroutine
10949 @item @emph{Syntax}:
10950 @code{CALL MVBITS(FROM, FROMPOS, LEN, TO, TOPOS)}
10952 @item @emph{Arguments}:
10953 @multitable @columnfractions .15 .70
10954 @item @var{FROM} @tab The type shall be @code{INTEGER}.
10955 @item @var{FROMPOS} @tab The type shall be @code{INTEGER}.
10956 @item @var{LEN} @tab The type shall be @code{INTEGER}.
10957 @item @var{TO} @tab The type shall be @code{INTEGER}, of the
10958 same kind as @var{FROM}.
10959 @item @var{TOPOS} @tab The type shall be @code{INTEGER}.
10962 @item @emph{Specific names}:
10963 @multitable @columnfractions .20 .23 .20 .33
10964 @headitem Name @tab Argument @tab Return type @tab Standard
10965 @item @code{MVBITS(A)} @tab @code{INTEGER A} @tab @code{INTEGER} @tab Fortran 90 and later
10966 @item @code{BMVBITS(A)} @tab @code{INTEGER(1) A} @tab @code{INTEGER(1)} @tab GNU extension
10967 @item @code{IMVBITS(A)} @tab @code{INTEGER(2) A} @tab @code{INTEGER(2)} @tab GNU extension
10968 @item @code{JMVBITS(A)} @tab @code{INTEGER(4) A} @tab @code{INTEGER(4)} @tab GNU extension
10969 @item @code{KMVBITS(A)} @tab @code{INTEGER(8) A} @tab @code{INTEGER(8)} @tab GNU extension
10972 @item @emph{See also}:
10984 @section @code{NEAREST} --- Nearest representable number
10986 @cindex real number, nearest different
10987 @cindex floating point, nearest different
10990 @item @emph{Description}:
10991 @code{NEAREST(X, S)} returns the processor-representable number nearest
10992 to @code{X} in the direction indicated by the sign of @code{S}.
10994 @item @emph{Standard}:
10995 Fortran 90 and later
10997 @item @emph{Class}:
11000 @item @emph{Syntax}:
11001 @code{RESULT = NEAREST(X, S)}
11003 @item @emph{Arguments}:
11004 @multitable @columnfractions .15 .70
11005 @item @var{X} @tab Shall be of type @code{REAL}.
11006 @item @var{S} @tab Shall be of type @code{REAL} and
11010 @item @emph{Return value}:
11011 The return value is of the same type as @code{X}. If @code{S} is
11012 positive, @code{NEAREST} returns the processor-representable number
11013 greater than @code{X} and nearest to it. If @code{S} is negative,
11014 @code{NEAREST} returns the processor-representable number smaller than
11015 @code{X} and nearest to it.
11017 @item @emph{Example}:
11019 program test_nearest
11021 x = nearest(42.0, 1.0)
11022 y = nearest(42.0, -1.0)
11023 write (*,"(3(G20.15))") x, y, x - y
11024 end program test_nearest
11031 @section @code{NEW_LINE} --- New line character
11034 @cindex output, newline
11037 @item @emph{Description}:
11038 @code{NEW_LINE(C)} returns the new-line character.
11040 @item @emph{Standard}:
11041 Fortran 2003 and later
11043 @item @emph{Class}:
11046 @item @emph{Syntax}:
11047 @code{RESULT = NEW_LINE(C)}
11049 @item @emph{Arguments}:
11050 @multitable @columnfractions .15 .70
11051 @item @var{C} @tab The argument shall be a scalar or array of the
11052 type @code{CHARACTER}.
11055 @item @emph{Return value}:
11056 Returns a @var{CHARACTER} scalar of length one with the new-line character of
11057 the same kind as parameter @var{C}.
11059 @item @emph{Example}:
11063 write(*,'(A)') 'This is record 1.'//NEW_LINE('A')//'This is record 2.'
11064 end program newline
11071 @section @code{NINT} --- Nearest whole number
11074 @cindex rounding, nearest whole number
11077 @item @emph{Description}:
11078 @code{NINT(A)} rounds its argument to the nearest whole number.
11080 @item @emph{Standard}:
11081 Fortran 77 and later, with @var{KIND} argument Fortran 90 and later
11083 @item @emph{Class}:
11086 @item @emph{Syntax}:
11087 @code{RESULT = NINT(A [, KIND])}
11089 @item @emph{Arguments}:
11090 @multitable @columnfractions .15 .70
11091 @item @var{A} @tab The type of the argument shall be @code{REAL}.
11092 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
11093 expression indicating the kind parameter of the result.
11096 @item @emph{Return value}:
11097 Returns @var{A} with the fractional portion of its magnitude eliminated by
11098 rounding to the nearest whole number and with its sign preserved,
11099 converted to an @code{INTEGER} of the default kind.
11101 @item @emph{Example}:
11108 print *, nint(x4), idnint(x8)
11109 end program test_nint
11112 @item @emph{Specific names}:
11113 @multitable @columnfractions .20 .23 .20 .33
11114 @headitem Name @tab Argument @tab Return Type @tab Standard
11115 @item @code{NINT(A)} @tab @code{REAL(4) A} @tab @code{INTEGER} @tab Fortran 77 and later
11116 @item @code{IDNINT(A)} @tab @code{REAL(8) A} @tab @code{INTEGER} @tab Fortran 77 and later
11119 @item @emph{See also}:
11127 @section @code{NORM2} --- Euclidean vector norms
11129 @cindex Euclidean vector norm
11130 @cindex L2 vector norm
11131 @cindex norm, Euclidean
11134 @item @emph{Description}:
11135 Calculates the Euclidean vector norm (@math{L_2} norm)
11136 of @var{ARRAY} along dimension @var{DIM}.
11138 @item @emph{Standard}:
11139 Fortran 2008 and later
11141 @item @emph{Class}:
11142 Transformational function
11144 @item @emph{Syntax}:
11145 @multitable @columnfractions .80
11146 @item @code{RESULT = NORM2(ARRAY[, DIM])}
11149 @item @emph{Arguments}:
11150 @multitable @columnfractions .15 .70
11151 @item @var{ARRAY} @tab Shall be an array of type @code{REAL}
11152 @item @var{DIM} @tab (Optional) shall be a scalar of type
11153 @code{INTEGER} with a value in the range from 1 to n, where n
11154 equals the rank of @var{ARRAY}.
11157 @item @emph{Return value}:
11158 The result is of the same type as @var{ARRAY}.
11160 If @var{DIM} is absent, a scalar with the square root of the sum of all
11161 elements in @var{ARRAY} squared is returned. Otherwise, an array of
11162 rank @math{n-1}, where @math{n} equals the rank of @var{ARRAY}, and a
11163 shape similar to that of @var{ARRAY} with dimension @var{DIM} dropped
11166 @item @emph{Example}:
11169 REAL :: x(5) = [ real :: 1, 2, 3, 4, 5 ]
11170 print *, NORM2(x) ! = sqrt(55.) ~ 7.416
11178 @section @code{NOT} --- Logical negation
11184 @cindex bits, negate
11185 @cindex bitwise logical not
11186 @cindex logical not, bitwise
11189 @item @emph{Description}:
11190 @code{NOT} returns the bitwise Boolean inverse of @var{I}.
11192 @item @emph{Standard}:
11193 Fortran 90 and later, has overloads that are GNU extensions
11195 @item @emph{Class}:
11198 @item @emph{Syntax}:
11199 @code{RESULT = NOT(I)}
11201 @item @emph{Arguments}:
11202 @multitable @columnfractions .15 .70
11203 @item @var{I} @tab The type shall be @code{INTEGER}.
11206 @item @emph{Return value}:
11207 The return type is @code{INTEGER}, of the same kind as the
11210 @item @emph{Specific names}:
11211 @multitable @columnfractions .20 .23 .20 .33
11212 @headitem Name @tab Argument @tab Return type @tab Standard
11213 @item @code{NOT(A)} @tab @code{INTEGER A} @tab @code{INTEGER} @tab Fortran 95 and later
11214 @item @code{BNOT(A)} @tab @code{INTEGER(1) A} @tab @code{INTEGER(1)} @tab GNU extension
11215 @item @code{INOT(A)} @tab @code{INTEGER(2) A} @tab @code{INTEGER(2)} @tab GNU extension
11216 @item @code{JNOT(A)} @tab @code{INTEGER(4) A} @tab @code{INTEGER(4)} @tab GNU extension
11217 @item @code{KNOT(A)} @tab @code{INTEGER(8) A} @tab @code{INTEGER(8)} @tab GNU extension
11220 @item @emph{See also}:
11232 @section @code{NULL} --- Function that returns an disassociated pointer
11234 @cindex pointer, status
11235 @cindex pointer, disassociated
11238 @item @emph{Description}:
11239 Returns a disassociated pointer.
11241 If @var{MOLD} is present, a disassociated pointer of the same type is
11242 returned, otherwise the type is determined by context.
11244 In Fortran 95, @var{MOLD} is optional. Please note that Fortran 2003
11245 includes cases where it is required.
11247 @item @emph{Standard}:
11248 Fortran 95 and later
11250 @item @emph{Class}:
11251 Transformational function
11253 @item @emph{Syntax}:
11254 @code{PTR => NULL([MOLD])}
11256 @item @emph{Arguments}:
11257 @multitable @columnfractions .15 .70
11258 @item @var{MOLD} @tab (Optional) shall be a pointer of any association
11259 status and of any type.
11262 @item @emph{Return value}:
11263 A disassociated pointer.
11265 @item @emph{Example}:
11267 REAL, POINTER, DIMENSION(:) :: VEC => NULL ()
11270 @item @emph{See also}:
11277 @section @code{NUM_IMAGES} --- Function that returns the number of images
11278 @fnindex NUM_IMAGES
11279 @cindex coarray, @code{NUM_IMAGES}
11280 @cindex images, number of
11283 @item @emph{Description}:
11284 Returns the number of images.
11286 @item @emph{Standard}:
11287 Fortran 2008 and later. With @var{DISTANCE} or @var{FAILED} argument,
11288 Technical Specification (TS) 18508 or later
11291 @item @emph{Class}:
11292 Transformational function
11294 @item @emph{Syntax}:
11295 @code{RESULT = NUM_IMAGES(DISTANCE, FAILED)}
11297 @item @emph{Arguments}:
11298 @multitable @columnfractions .15 .70
11299 @item @var{DISTANCE} @tab (optional, intent(in)) Nonnegative scalar integer
11300 @item @var{FAILED} @tab (optional, intent(in)) Scalar logical expression
11303 @item @emph{Return value}:
11304 Scalar default-kind integer. If @var{DISTANCE} is not present or has value 0,
11305 the number of images in the current team is returned. For values smaller or
11306 equal distance to the initial team, it returns the number of images index
11307 on the ancestor team which has a distance of @var{DISTANCE} from the invoking
11308 team. If @var{DISTANCE} is larger than the distance to the initial team, the
11309 number of images of the initial team is returned. If @var{FAILED} is not present
11310 the total number of images is returned; if it has the value @code{.TRUE.},
11311 the number of failed images is returned, otherwise, the number of images which
11312 do have not the failed status.
11314 @item @emph{Example}:
11316 INTEGER :: value[*]
11318 value = THIS_IMAGE()
11320 IF (THIS_IMAGE() == 1) THEN
11321 DO i = 1, NUM_IMAGES()
11322 WRITE(*,'(2(a,i0))') 'value[', i, '] is ', value[i]
11327 @item @emph{See also}:
11328 @ref{THIS_IMAGE}, @*
11335 @section @code{OR} --- Bitwise logical OR
11337 @cindex bitwise logical or
11338 @cindex logical or, bitwise
11341 @item @emph{Description}:
11342 Bitwise logical @code{OR}.
11344 This intrinsic routine is provided for backwards compatibility with
11345 GNU Fortran 77. For integer arguments, programmers should consider
11346 the use of the @ref{IOR} intrinsic defined by the Fortran standard.
11348 @item @emph{Standard}:
11351 @item @emph{Class}:
11354 @item @emph{Syntax}:
11355 @code{RESULT = OR(I, J)}
11357 @item @emph{Arguments}:
11358 @multitable @columnfractions .15 .70
11359 @item @var{I} @tab The type shall be either a scalar @code{INTEGER}
11360 type or a scalar @code{LOGICAL} type or a boz-literal-constant.
11361 @item @var{J} @tab The type shall be the same as the type of @var{I} or
11362 a boz-literal-constant. @var{I} and @var{J} shall not both be
11363 boz-literal-constants. If either @var{I} and @var{J} is a
11364 boz-literal-constant, then the other argument must be a scalar @code{INTEGER}.
11367 @item @emph{Return value}:
11368 The return type is either a scalar @code{INTEGER} or a scalar
11369 @code{LOGICAL}. If the kind type parameters differ, then the
11370 smaller kind type is implicitly converted to larger kind, and the
11371 return has the larger kind. A boz-literal-constant is
11372 converted to an @code{INTEGER} with the kind type parameter of
11373 the other argument as-if a call to @ref{INT} occurred.
11375 @item @emph{Example}:
11378 LOGICAL :: T = .TRUE., F = .FALSE.
11380 DATA a / Z'F' /, b / Z'3' /
11382 WRITE (*,*) OR(T, T), OR(T, F), OR(F, T), OR(F, F)
11383 WRITE (*,*) OR(a, b)
11387 @item @emph{See also}:
11388 Fortran 95 elemental function: @*
11395 @section @code{PACK} --- Pack an array into an array of rank one
11397 @cindex array, packing
11398 @cindex array, reduce dimension
11399 @cindex array, gather elements
11402 @item @emph{Description}:
11403 Stores the elements of @var{ARRAY} in an array of rank one.
11405 The beginning of the resulting array is made up of elements whose @var{MASK}
11406 equals @code{TRUE}. Afterwards, positions are filled with elements taken from
11409 @item @emph{Standard}:
11410 Fortran 90 and later
11412 @item @emph{Class}:
11413 Transformational function
11415 @item @emph{Syntax}:
11416 @code{RESULT = PACK(ARRAY, MASK[,VECTOR])}
11418 @item @emph{Arguments}:
11419 @multitable @columnfractions .15 .70
11420 @item @var{ARRAY} @tab Shall be an array of any type.
11421 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL} and
11422 of the same size as @var{ARRAY}. Alternatively, it may be a @code{LOGICAL}
11424 @item @var{VECTOR} @tab (Optional) shall be an array of the same type
11425 as @var{ARRAY} and of rank one. If present, the number of elements in
11426 @var{VECTOR} shall be equal to or greater than the number of true elements
11427 in @var{MASK}. If @var{MASK} is scalar, the number of elements in
11428 @var{VECTOR} shall be equal to or greater than the number of elements in
11432 @item @emph{Return value}:
11433 The result is an array of rank one and the same type as that of @var{ARRAY}.
11434 If @var{VECTOR} is present, the result size is that of @var{VECTOR}, the
11435 number of @code{TRUE} values in @var{MASK} otherwise.
11437 @item @emph{Example}:
11438 Gathering nonzero elements from an array:
11440 PROGRAM test_pack_1
11442 m = (/ 1, 0, 0, 0, 5, 0 /)
11443 WRITE(*, FMT="(6(I0, ' '))") pack(m, m /= 0) ! "1 5"
11447 Gathering nonzero elements from an array and appending elements from @var{VECTOR}:
11449 PROGRAM test_pack_2
11451 m = (/ 1, 0, 0, 2 /)
11452 ! The following results in "1 2 3 4"
11453 WRITE(*, FMT="(4(I0, ' '))") pack(m, m /= 0, (/ 0, 0, 3, 4 /))
11457 @item @emph{See also}:
11464 @section @code{PARITY} --- Reduction with exclusive OR
11467 @cindex Reduction, XOR
11468 @cindex XOR reduction
11471 @item @emph{Description}:
11472 Calculates the parity, i.e. the reduction using @code{.XOR.},
11473 of @var{MASK} along dimension @var{DIM}.
11475 @item @emph{Standard}:
11476 Fortran 2008 and later
11478 @item @emph{Class}:
11479 Transformational function
11481 @item @emph{Syntax}:
11482 @multitable @columnfractions .80
11483 @item @code{RESULT = PARITY(MASK[, DIM])}
11486 @item @emph{Arguments}:
11487 @multitable @columnfractions .15 .70
11488 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL}
11489 @item @var{DIM} @tab (Optional) shall be a scalar of type
11490 @code{INTEGER} with a value in the range from 1 to n, where n
11491 equals the rank of @var{MASK}.
11494 @item @emph{Return value}:
11495 The result is of the same type as @var{MASK}.
11497 If @var{DIM} is absent, a scalar with the parity of all elements in
11498 @var{MASK} is returned, i.e. true if an odd number of elements is
11499 @code{.true.} and false otherwise. If @var{DIM} is present, an array
11500 of rank @math{n-1}, where @math{n} equals the rank of @var{ARRAY},
11501 and a shape similar to that of @var{MASK} with dimension @var{DIM}
11502 dropped is returned.
11504 @item @emph{Example}:
11507 LOGICAL :: x(2) = [ .true., .false. ]
11508 print *, PARITY(x) ! prints "T" (true).
11516 @section @code{PERROR} --- Print system error message
11518 @cindex system, error handling
11521 @item @emph{Description}:
11522 Prints (on the C @code{stderr} stream) a newline-terminated error
11523 message corresponding to the last system error. This is prefixed by
11524 @var{STRING}, a colon and a space. See @code{perror(3)}.
11526 @item @emph{Standard}:
11529 @item @emph{Class}:
11532 @item @emph{Syntax}:
11533 @code{CALL PERROR(STRING)}
11535 @item @emph{Arguments}:
11536 @multitable @columnfractions .15 .70
11537 @item @var{STRING} @tab A scalar of type @code{CHARACTER} and of the
11541 @item @emph{See also}:
11548 @section @code{POPCNT} --- Number of bits set
11550 @cindex binary representation
11554 @item @emph{Description}:
11555 @code{POPCNT(I)} returns the number of bits set ('1' bits) in the binary
11556 representation of @code{I}.
11558 @item @emph{Standard}:
11559 Fortran 2008 and later
11561 @item @emph{Class}:
11564 @item @emph{Syntax}:
11565 @code{RESULT = POPCNT(I)}
11567 @item @emph{Arguments}:
11568 @multitable @columnfractions .15 .70
11569 @item @var{I} @tab Shall be of type @code{INTEGER}.
11572 @item @emph{Return value}:
11573 The return value is of type @code{INTEGER} and of the default integer
11576 @item @emph{Example}:
11578 program test_population
11579 print *, popcnt(127), poppar(127)
11580 print *, popcnt(huge(0_4)), poppar(huge(0_4))
11581 print *, popcnt(huge(0_8)), poppar(huge(0_8))
11582 end program test_population
11584 @item @emph{See also}:
11593 @section @code{POPPAR} --- Parity of the number of bits set
11595 @cindex binary representation
11599 @item @emph{Description}:
11600 @code{POPPAR(I)} returns parity of the integer @code{I}, i.e. the parity
11601 of the number of bits set ('1' bits) in the binary representation of
11602 @code{I}. It is equal to 0 if @code{I} has an even number of bits set,
11603 and 1 for an odd number of '1' bits.
11605 @item @emph{Standard}:
11606 Fortran 2008 and later
11608 @item @emph{Class}:
11611 @item @emph{Syntax}:
11612 @code{RESULT = POPPAR(I)}
11614 @item @emph{Arguments}:
11615 @multitable @columnfractions .15 .70
11616 @item @var{I} @tab Shall be of type @code{INTEGER}.
11619 @item @emph{Return value}:
11620 The return value is of type @code{INTEGER} and of the default integer
11623 @item @emph{Example}:
11625 program test_population
11626 print *, popcnt(127), poppar(127)
11627 print *, popcnt(huge(0_4)), poppar(huge(0_4))
11628 print *, popcnt(huge(0_8)), poppar(huge(0_8))
11629 end program test_population
11631 @item @emph{See also}:
11640 @section @code{PRECISION} --- Decimal precision of a real kind
11642 @cindex model representation, precision
11645 @item @emph{Description}:
11646 @code{PRECISION(X)} returns the decimal precision in the model of the
11649 @item @emph{Standard}:
11650 Fortran 90 and later
11652 @item @emph{Class}:
11655 @item @emph{Syntax}:
11656 @code{RESULT = PRECISION(X)}
11658 @item @emph{Arguments}:
11659 @multitable @columnfractions .15 .70
11660 @item @var{X} @tab Shall be of type @code{REAL} or @code{COMPLEX}. It may
11661 be scalar or valued.
11664 @item @emph{Return value}:
11665 The return value is of type @code{INTEGER} and of the default integer
11668 @item @emph{Example}:
11670 program prec_and_range
11671 real(kind=4) :: x(2)
11672 complex(kind=8) :: y
11674 print *, precision(x), range(x)
11675 print *, precision(y), range(y)
11676 end program prec_and_range
11678 @item @emph{See also}:
11679 @ref{SELECTED_REAL_KIND}, @*
11686 @section @code{PRESENT} --- Determine whether an optional dummy argument is specified
11690 @item @emph{Description}:
11691 Determines whether an optional dummy argument is present.
11693 @item @emph{Standard}:
11694 Fortran 90 and later
11696 @item @emph{Class}:
11699 @item @emph{Syntax}:
11700 @code{RESULT = PRESENT(A)}
11702 @item @emph{Arguments}:
11703 @multitable @columnfractions .15 .70
11704 @item @var{A} @tab May be of any type and may be a pointer, scalar or array
11705 value, or a dummy procedure. It shall be the name of an optional dummy argument
11706 accessible within the current subroutine or function.
11709 @item @emph{Return value}:
11710 Returns either @code{TRUE} if the optional argument @var{A} is present, or
11711 @code{FALSE} otherwise.
11713 @item @emph{Example}:
11715 PROGRAM test_present
11716 WRITE(*,*) f(), f(42) ! "F T"
11718 LOGICAL FUNCTION f(x)
11719 INTEGER, INTENT(IN), OPTIONAL :: x
11729 @section @code{PRODUCT} --- Product of array elements
11731 @cindex array, product
11732 @cindex array, multiply elements
11733 @cindex array, conditionally multiply elements
11734 @cindex multiply array elements
11737 @item @emph{Description}:
11738 Multiplies the elements of @var{ARRAY} along dimension @var{DIM} if
11739 the corresponding element in @var{MASK} is @code{TRUE}.
11741 @item @emph{Standard}:
11742 Fortran 90 and later
11744 @item @emph{Class}:
11745 Transformational function
11747 @item @emph{Syntax}:
11748 @multitable @columnfractions .80
11749 @item @code{RESULT = PRODUCT(ARRAY[, MASK])}
11750 @item @code{RESULT = PRODUCT(ARRAY, DIM[, MASK])}
11753 @item @emph{Arguments}:
11754 @multitable @columnfractions .15 .70
11755 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER},
11756 @code{REAL} or @code{COMPLEX}.
11757 @item @var{DIM} @tab (Optional) shall be a scalar of type
11758 @code{INTEGER} with a value in the range from 1 to n, where n
11759 equals the rank of @var{ARRAY}.
11760 @item @var{MASK} @tab (Optional) shall be of type @code{LOGICAL}
11761 and either be a scalar or an array of the same shape as @var{ARRAY}.
11764 @item @emph{Return value}:
11765 The result is of the same type as @var{ARRAY}.
11767 If @var{DIM} is absent, a scalar with the product of all elements in
11768 @var{ARRAY} is returned. Otherwise, an array of rank n-1, where n equals
11769 the rank of @var{ARRAY}, and a shape similar to that of @var{ARRAY} with
11770 dimension @var{DIM} dropped is returned.
11773 @item @emph{Example}:
11775 PROGRAM test_product
11776 INTEGER :: x(5) = (/ 1, 2, 3, 4 ,5 /)
11777 print *, PRODUCT(x) ! all elements, product = 120
11778 print *, PRODUCT(x, MASK=MOD(x, 2)==1) ! odd elements, product = 15
11782 @item @emph{See also}:
11789 @section @code{RADIX} --- Base of a model number
11791 @cindex model representation, base
11792 @cindex model representation, radix
11795 @item @emph{Description}:
11796 @code{RADIX(X)} returns the base of the model representing the entity @var{X}.
11798 @item @emph{Standard}:
11799 Fortran 90 and later
11801 @item @emph{Class}:
11804 @item @emph{Syntax}:
11805 @code{RESULT = RADIX(X)}
11807 @item @emph{Arguments}:
11808 @multitable @columnfractions .15 .70
11809 @item @var{X} @tab Shall be of type @code{INTEGER} or @code{REAL}
11812 @item @emph{Return value}:
11813 The return value is a scalar of type @code{INTEGER} and of the default
11816 @item @emph{Example}:
11819 print *, "The radix for the default integer kind is", radix(0)
11820 print *, "The radix for the default real kind is", radix(0.0)
11821 end program test_radix
11823 @item @emph{See also}:
11824 @ref{SELECTED_REAL_KIND}
11830 @section @code{RAN} --- Real pseudo-random number
11832 @cindex random number generation
11835 @item @emph{Description}:
11836 For compatibility with HP FORTRAN 77/iX, the @code{RAN} intrinsic is
11837 provided as an alias for @code{RAND}. See @ref{RAND} for complete
11840 @item @emph{Standard}:
11843 @item @emph{Class}:
11846 @item @emph{See also}:
11848 @ref{RANDOM_NUMBER}
11854 @section @code{RAND} --- Real pseudo-random number
11856 @cindex random number generation
11859 @item @emph{Description}:
11860 @code{RAND(FLAG)} returns a pseudo-random number from a uniform
11861 distribution between 0 and 1. If @var{FLAG} is 0, the next number
11862 in the current sequence is returned; if @var{FLAG} is 1, the generator
11863 is restarted by @code{CALL SRAND(0)}; if @var{FLAG} has any other value,
11864 it is used as a new seed with @code{SRAND}.
11866 This intrinsic routine is provided for backwards compatibility with
11867 GNU Fortran 77. It implements a simple modulo generator as provided
11868 by @command{g77}. For new code, one should consider the use of
11869 @ref{RANDOM_NUMBER} as it implements a superior algorithm.
11871 @item @emph{Standard}:
11874 @item @emph{Class}:
11877 @item @emph{Syntax}:
11878 @code{RESULT = RAND(I)}
11880 @item @emph{Arguments}:
11881 @multitable @columnfractions .15 .70
11882 @item @var{I} @tab Shall be a scalar @code{INTEGER} of kind 4.
11885 @item @emph{Return value}:
11886 The return value is of @code{REAL} type and the default kind.
11888 @item @emph{Example}:
11891 integer,parameter :: seed = 86456
11894 print *, rand(), rand(), rand(), rand()
11895 print *, rand(seed), rand(), rand(), rand()
11896 end program test_rand
11899 @item @emph{See also}:
11901 @ref{RANDOM_NUMBER}
11907 @section @code{RANDOM_INIT} --- Initialize a pseudo-random number generator
11908 @fnindex RANDOM_INIT
11909 @cindex random number generation, initialization
11912 @item @emph{Description}:
11913 Initializes the state of the pseudorandom number generator used by
11914 @code{RANDOM_NUMBER}.
11916 @item @emph{Standard}:
11919 @item @emph{Class}:
11922 @item @emph{Syntax}:
11923 @code{CALL RANDOM_INIT(REPEATABLE, IMAGE_DISTINCT)}
11925 @item @emph{Arguments}:
11926 @multitable @columnfractions .25 .70
11927 @item @var{REPEATABLE} @tab Shall be a scalar with a @code{LOGICAL} type,
11928 and it is @code{INTENT(IN)}. If it is @code{.true.}, the seed is set to
11929 a processor-dependent value that is the same each time @code{RANDOM_INIT}
11930 is called from the same image. The term ``same image'' means a single
11931 instance of program execution. The sequence of random numbers is the same
11932 for repeated execution of the program with the same execution environment.
11933 If it is @code{.false.}, the seed is set to a processor-dependent value.
11934 @item @var{IMAGE_DISTINCT} @tab Shall be a scalar with a
11935 @code{LOGICAL} type, and it is @code{INTENT(IN)}. If it is @code{.true.},
11936 the seed is set to a processor-dependent value that is distinct from the
11937 seed set by a call to @code{RANDOM_INIT} in another image. If it is
11938 @code{.false.}, the seed is set to a value that is the same on every image
11939 calling @code{RANDOM_INIT}.
11942 @item @emph{Example}:
11944 program test_random_seed
11947 call random_init(.true., .true.)
11948 call random_number(x)
11949 call random_init(.true., .true.)
11950 call random_number(y)
11951 ! x and y are the same sequence
11952 if (any(x /= y)) call abort
11953 end program test_random_seed
11956 @item @emph{See also}:
11957 @ref{RANDOM_NUMBER}, @*
11962 @node RANDOM_NUMBER
11963 @section @code{RANDOM_NUMBER} --- Pseudo-random number
11964 @fnindex RANDOM_NUMBER
11965 @cindex random number generation
11968 @item @emph{Description}:
11969 Returns a single pseudorandom number or an array of pseudorandom numbers
11970 from the uniform distribution over the range @math{ 0 \leq x < 1}.
11972 The runtime-library implements the xoshiro256** pseudorandom number
11973 generator (PRNG). This generator has a period of @math{2^{256} - 1},
11974 and when using multiple threads up to @math{2^{128}} threads can each
11975 generate @math{2^{128}} random numbers before any aliasing occurs.
11977 Note that in a multi-threaded program (e.g. using OpenMP directives),
11978 each thread will have its own random number state. For details of the
11979 seeding procedure, see the documentation for the @code{RANDOM_SEED}
11983 @item @emph{Standard}:
11984 Fortran 90 and later
11986 @item @emph{Class}:
11989 @item @emph{Syntax}:
11990 @code{CALL RANDOM_NUMBER(HARVEST)}
11992 @item @emph{Arguments}:
11993 @multitable @columnfractions .15 .70
11994 @item @var{HARVEST} @tab Shall be a scalar or an array of type @code{REAL}.
11997 @item @emph{Example}:
11999 program test_random_number
12001 CALL RANDOM_NUMBER(r)
12005 @item @emph{See also}:
12006 @ref{RANDOM_SEED}, @*
12013 @section @code{RANDOM_SEED} --- Initialize a pseudo-random number sequence
12014 @fnindex RANDOM_SEED
12015 @cindex random number generation, seeding
12016 @cindex seeding a random number generator
12019 @item @emph{Description}:
12020 Restarts or queries the state of the pseudorandom number generator used by
12021 @code{RANDOM_NUMBER}.
12023 If @code{RANDOM_SEED} is called without arguments, it is seeded with
12024 random data retrieved from the operating system.
12026 As an extension to the Fortran standard, the GFortran
12027 @code{RANDOM_NUMBER} supports multiple threads. Each thread in a
12028 multi-threaded program has its own seed. When @code{RANDOM_SEED} is
12029 called either without arguments or with the @var{PUT} argument, the
12030 given seed is copied into a master seed as well as the seed of the
12031 current thread. When a new thread uses @code{RANDOM_NUMBER} for the
12032 first time, the seed is copied from the master seed, and forwarded
12033 @math{N * 2^{128}} steps to guarantee that the random stream does not
12034 alias any other stream in the system, where @var{N} is the number of
12035 threads that have used @code{RANDOM_NUMBER} so far during the program
12038 @item @emph{Standard}:
12039 Fortran 90 and later
12041 @item @emph{Class}:
12044 @item @emph{Syntax}:
12045 @code{CALL RANDOM_SEED([SIZE, PUT, GET])}
12047 @item @emph{Arguments}:
12048 @multitable @columnfractions .15 .70
12049 @item @var{SIZE} @tab (Optional) Shall be a scalar and of type default
12050 @code{INTEGER}, with @code{INTENT(OUT)}. It specifies the minimum size
12051 of the arrays used with the @var{PUT} and @var{GET} arguments.
12052 @item @var{PUT} @tab (Optional) Shall be an array of type default
12053 @code{INTEGER} and rank one. It is @code{INTENT(IN)} and the size of
12054 the array must be larger than or equal to the number returned by the
12055 @var{SIZE} argument.
12056 @item @var{GET} @tab (Optional) Shall be an array of type default
12057 @code{INTEGER} and rank one. It is @code{INTENT(OUT)} and the size
12058 of the array must be larger than or equal to the number returned by
12059 the @var{SIZE} argument.
12062 @item @emph{Example}:
12064 program test_random_seed
12066 integer, allocatable :: seed(:)
12069 call random_seed(size = n)
12071 call random_seed(get=seed)
12073 end program test_random_seed
12076 @item @emph{See also}:
12077 @ref{RANDOM_NUMBER}, @*
12084 @section @code{RANGE} --- Decimal exponent range
12086 @cindex model representation, range
12089 @item @emph{Description}:
12090 @code{RANGE(X)} returns the decimal exponent range in the model of the
12093 @item @emph{Standard}:
12094 Fortran 90 and later
12096 @item @emph{Class}:
12099 @item @emph{Syntax}:
12100 @code{RESULT = RANGE(X)}
12102 @item @emph{Arguments}:
12103 @multitable @columnfractions .15 .70
12104 @item @var{X} @tab Shall be of type @code{INTEGER}, @code{REAL}
12108 @item @emph{Return value}:
12109 The return value is of type @code{INTEGER} and of the default integer
12112 @item @emph{Example}:
12113 See @code{PRECISION} for an example.
12114 @item @emph{See also}:
12115 @ref{SELECTED_REAL_KIND}, @*
12122 @section @code{RANK} --- Rank of a data object
12127 @item @emph{Description}:
12128 @code{RANK(A)} returns the rank of a scalar or array data object.
12130 @item @emph{Standard}:
12131 Technical Specification (TS) 29113
12133 @item @emph{Class}:
12136 @item @emph{Syntax}:
12137 @code{RESULT = RANK(A)}
12139 @item @emph{Arguments}:
12140 @multitable @columnfractions .15 .70
12141 @item @var{A} @tab can be of any type
12144 @item @emph{Return value}:
12145 The return value is of type @code{INTEGER} and of the default integer
12146 kind. For arrays, their rank is returned; for scalars zero is returned.
12148 @item @emph{Example}:
12152 real, allocatable :: b(:,:)
12154 print *, rank(a), rank(b) ! Prints: 0 2
12155 end program test_rank
12163 @section @code{REAL} --- Convert to real type
12172 @cindex conversion, to real
12173 @cindex complex numbers, real part
12176 @item @emph{Description}:
12177 @code{REAL(A [, KIND])} converts its argument @var{A} to a real type. The
12178 @code{REALPART} function is provided for compatibility with @command{g77},
12179 and its use is strongly discouraged.
12181 @item @emph{Standard}:
12182 Fortran 77 and later, with @var{KIND} argument Fortran 90 and later, has GNU extensions
12184 @item @emph{Class}:
12187 @item @emph{Syntax}:
12188 @multitable @columnfractions .80
12189 @item @code{RESULT = REAL(A [, KIND])}
12190 @item @code{RESULT = REALPART(Z)}
12193 @item @emph{Arguments}:
12194 @multitable @columnfractions .15 .70
12195 @item @var{A} @tab Shall be @code{INTEGER}, @code{REAL}, or
12197 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
12198 expression indicating the kind parameter of the result.
12201 @item @emph{Return value}:
12202 These functions return a @code{REAL} variable or array under
12203 the following rules:
12207 @code{REAL(A)} is converted to a default real type if @var{A} is an
12208 integer or real variable.
12210 @code{REAL(A)} is converted to a real type with the kind type parameter
12211 of @var{A} if @var{A} is a complex variable.
12213 @code{REAL(A, KIND)} is converted to a real type with kind type
12214 parameter @var{KIND} if @var{A} is a complex, integer, or real
12218 @item @emph{Example}:
12221 complex :: x = (1.0, 2.0)
12222 print *, real(x), real(x,8), realpart(x)
12223 end program test_real
12226 @item @emph{Specific names}:
12227 @multitable @columnfractions .20 .23 .20 .33
12228 @headitem Name @tab Argument @tab Return type @tab Standard
12229 @item @code{FLOAT(A)} @tab @code{INTEGER(4)} @tab @code{REAL(4)} @tab Fortran 77 and later
12230 @item @code{DFLOAT(A)} @tab @code{INTEGER(4)} @tab @code{REAL(8)} @tab GNU extension
12231 @item @code{FLOATI(A)} @tab @code{INTEGER(2)} @tab @code{REAL(4)} @tab GNU extension (-fdec)
12232 @item @code{FLOATJ(A)} @tab @code{INTEGER(4)} @tab @code{REAL(4)} @tab GNU extension (-fdec)
12233 @item @code{FLOATK(A)} @tab @code{INTEGER(8)} @tab @code{REAL(4)} @tab GNU extension (-fdec)
12234 @item @code{SNGL(A)} @tab @code{REAL(8)} @tab @code{REAL(4)} @tab Fortran 77 and later
12238 @item @emph{See also}:
12246 @section @code{RENAME} --- Rename a file
12248 @cindex file system, rename file
12251 @item @emph{Description}:
12252 Renames a file from file @var{PATH1} to @var{PATH2}. A null
12253 character (@code{CHAR(0)}) can be used to mark the end of the names in
12254 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
12255 names are ignored. If the @var{STATUS} argument is supplied, it
12256 contains 0 on success or a nonzero error code upon return; see
12259 This intrinsic is provided in both subroutine and function forms;
12260 however, only one form can be used in any given program unit.
12262 @item @emph{Standard}:
12265 @item @emph{Class}:
12266 Subroutine, function
12268 @item @emph{Syntax}:
12269 @multitable @columnfractions .80
12270 @item @code{CALL RENAME(PATH1, PATH2 [, STATUS])}
12271 @item @code{STATUS = RENAME(PATH1, PATH2)}
12274 @item @emph{Arguments}:
12275 @multitable @columnfractions .15 .70
12276 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
12277 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
12278 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
12281 @item @emph{See also}:
12289 @section @code{REPEAT} --- Repeated string concatenation
12291 @cindex string, repeat
12292 @cindex string, concatenate
12295 @item @emph{Description}:
12296 Concatenates @var{NCOPIES} copies of a string.
12298 @item @emph{Standard}:
12299 Fortran 90 and later
12301 @item @emph{Class}:
12302 Transformational function
12304 @item @emph{Syntax}:
12305 @code{RESULT = REPEAT(STRING, NCOPIES)}
12307 @item @emph{Arguments}:
12308 @multitable @columnfractions .15 .70
12309 @item @var{STRING} @tab Shall be scalar and of type @code{CHARACTER}.
12310 @item @var{NCOPIES} @tab Shall be scalar and of type @code{INTEGER}.
12313 @item @emph{Return value}:
12314 A new scalar of type @code{CHARACTER} built up from @var{NCOPIES} copies
12317 @item @emph{Example}:
12319 program test_repeat
12320 write(*,*) repeat("x", 5) ! "xxxxx"
12328 @section @code{RESHAPE} --- Function to reshape an array
12330 @cindex array, change dimensions
12331 @cindex array, transmogrify
12334 @item @emph{Description}:
12335 Reshapes @var{SOURCE} to correspond to @var{SHAPE}. If necessary,
12336 the new array may be padded with elements from @var{PAD} or permuted
12337 as defined by @var{ORDER}.
12339 @item @emph{Standard}:
12340 Fortran 90 and later
12342 @item @emph{Class}:
12343 Transformational function
12345 @item @emph{Syntax}:
12346 @code{RESULT = RESHAPE(SOURCE, SHAPE[, PAD, ORDER])}
12348 @item @emph{Arguments}:
12349 @multitable @columnfractions .15 .70
12350 @item @var{SOURCE} @tab Shall be an array of any type.
12351 @item @var{SHAPE} @tab Shall be of type @code{INTEGER} and an
12352 array of rank one. Its values must be positive or zero.
12353 @item @var{PAD} @tab (Optional) shall be an array of the same
12354 type as @var{SOURCE}.
12355 @item @var{ORDER} @tab (Optional) shall be of type @code{INTEGER}
12356 and an array of the same shape as @var{SHAPE}. Its values shall
12357 be a permutation of the numbers from 1 to n, where n is the size of
12358 @var{SHAPE}. If @var{ORDER} is absent, the natural ordering shall
12362 @item @emph{Return value}:
12363 The result is an array of shape @var{SHAPE} with the same type as
12366 @item @emph{Example}:
12368 PROGRAM test_reshape
12369 INTEGER, DIMENSION(4) :: x
12370 WRITE(*,*) SHAPE(x) ! prints "4"
12371 WRITE(*,*) SHAPE(RESHAPE(x, (/2, 2/))) ! prints "2 2"
12375 @item @emph{See also}:
12382 @section @code{RRSPACING} --- Reciprocal of the relative spacing
12384 @cindex real number, relative spacing
12385 @cindex floating point, relative spacing
12389 @item @emph{Description}:
12390 @code{RRSPACING(X)} returns the reciprocal of the relative spacing of
12391 model numbers near @var{X}.
12393 @item @emph{Standard}:
12394 Fortran 90 and later
12396 @item @emph{Class}:
12399 @item @emph{Syntax}:
12400 @code{RESULT = RRSPACING(X)}
12402 @item @emph{Arguments}:
12403 @multitable @columnfractions .15 .70
12404 @item @var{X} @tab Shall be of type @code{REAL}.
12407 @item @emph{Return value}:
12408 The return value is of the same type and kind as @var{X}.
12409 The value returned is equal to
12410 @code{ABS(FRACTION(X)) * FLOAT(RADIX(X))**DIGITS(X)}.
12412 @item @emph{See also}:
12419 @section @code{RSHIFT} --- Right shift bits
12421 @cindex bits, shift right
12424 @item @emph{Description}:
12425 @code{RSHIFT} returns a value corresponding to @var{I} with all of the
12426 bits shifted right by @var{SHIFT} places. @var{SHIFT} shall be
12427 nonnegative and less than or equal to @code{BIT_SIZE(I)}, otherwise
12428 the result value is undefined. Bits shifted out from the right end
12429 are lost. The fill is arithmetic: the bits shifted in from the left
12430 end are equal to the leftmost bit, which in two's complement
12431 representation is the sign bit.
12433 This function has been superseded by the @code{SHIFTA} intrinsic, which
12434 is standard in Fortran 2008 and later.
12436 @item @emph{Standard}:
12439 @item @emph{Class}:
12442 @item @emph{Syntax}:
12443 @code{RESULT = RSHIFT(I, SHIFT)}
12445 @item @emph{Arguments}:
12446 @multitable @columnfractions .15 .70
12447 @item @var{I} @tab The type shall be @code{INTEGER}.
12448 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
12451 @item @emph{Return value}:
12452 The return value is of type @code{INTEGER} and of the same kind as
12455 @item @emph{See also}:
12468 @section @code{SAME_TYPE_AS} --- Query dynamic types for equality
12469 @fnindex SAME_TYPE_AS
12472 @item @emph{Description}:
12473 Query dynamic types for equality.
12475 @item @emph{Standard}:
12476 Fortran 2003 and later
12478 @item @emph{Class}:
12481 @item @emph{Syntax}:
12482 @code{RESULT = SAME_TYPE_AS(A, B)}
12484 @item @emph{Arguments}:
12485 @multitable @columnfractions .15 .70
12486 @item @var{A} @tab Shall be an object of extensible declared type or
12487 unlimited polymorphic.
12488 @item @var{B} @tab Shall be an object of extensible declared type or
12489 unlimited polymorphic.
12492 @item @emph{Return value}:
12493 The return value is a scalar of type default logical. It is true if and
12494 only if the dynamic type of A is the same as the dynamic type of B.
12496 @item @emph{See also}:
12497 @ref{EXTENDS_TYPE_OF}
12504 @section @code{SCALE} --- Scale a real value
12506 @cindex real number, scale
12507 @cindex floating point, scale
12510 @item @emph{Description}:
12511 @code{SCALE(X,I)} returns @code{X * RADIX(X)**I}.
12513 @item @emph{Standard}:
12514 Fortran 90 and later
12516 @item @emph{Class}:
12519 @item @emph{Syntax}:
12520 @code{RESULT = SCALE(X, I)}
12522 @item @emph{Arguments}:
12523 @multitable @columnfractions .15 .70
12524 @item @var{X} @tab The type of the argument shall be a @code{REAL}.
12525 @item @var{I} @tab The type of the argument shall be a @code{INTEGER}.
12528 @item @emph{Return value}:
12529 The return value is of the same type and kind as @var{X}.
12530 Its value is @code{X * RADIX(X)**I}.
12532 @item @emph{Example}:
12535 real :: x = 178.1387e-4
12537 print *, scale(x,i), x*radix(x)**i
12538 end program test_scale
12546 @section @code{SCAN} --- Scan a string for the presence of a set of characters
12548 @cindex string, find subset
12551 @item @emph{Description}:
12552 Scans a @var{STRING} for any of the characters in a @var{SET}
12555 If @var{BACK} is either absent or equals @code{FALSE}, this function
12556 returns the position of the leftmost character of @var{STRING} that is
12557 in @var{SET}. If @var{BACK} equals @code{TRUE}, the rightmost position
12558 is returned. If no character of @var{SET} is found in @var{STRING}, the
12561 @item @emph{Standard}:
12562 Fortran 90 and later, with @var{KIND} argument Fortran 2003 and later
12564 @item @emph{Class}:
12567 @item @emph{Syntax}:
12568 @code{RESULT = SCAN(STRING, SET[, BACK [, KIND]])}
12570 @item @emph{Arguments}:
12571 @multitable @columnfractions .15 .70
12572 @item @var{STRING} @tab Shall be of type @code{CHARACTER}.
12573 @item @var{SET} @tab Shall be of type @code{CHARACTER}.
12574 @item @var{BACK} @tab (Optional) shall be of type @code{LOGICAL}.
12575 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
12576 expression indicating the kind parameter of the result.
12579 @item @emph{Return value}:
12580 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
12581 @var{KIND} is absent, the return value is of default integer kind.
12583 @item @emph{Example}:
12586 WRITE(*,*) SCAN("FORTRAN", "AO") ! 2, found 'O'
12587 WRITE(*,*) SCAN("FORTRAN", "AO", .TRUE.) ! 6, found 'A'
12588 WRITE(*,*) SCAN("FORTRAN", "C++") ! 0, found none
12592 @item @emph{See also}:
12593 @ref{INDEX intrinsic}, @*
12600 @section @code{SECNDS} --- Time function
12602 @cindex time, elapsed
12603 @cindex elapsed time
12606 @item @emph{Description}:
12607 @code{SECNDS(X)} gets the time in seconds from the real-time system clock.
12608 @var{X} is a reference time, also in seconds. If this is zero, the time in
12609 seconds from midnight is returned. This function is non-standard and its
12610 use is discouraged.
12612 @item @emph{Standard}:
12615 @item @emph{Class}:
12618 @item @emph{Syntax}:
12619 @code{RESULT = SECNDS (X)}
12621 @item @emph{Arguments}:
12622 @multitable @columnfractions .15 .70
12623 @item @var{T} @tab Shall be of type @code{REAL(4)}.
12624 @item @var{X} @tab Shall be of type @code{REAL(4)}.
12627 @item @emph{Return value}:
12630 @item @emph{Example}:
12632 program test_secnds
12635 print *, secnds (0.0) ! seconds since midnight
12636 t1 = secnds (0.0) ! reference time
12637 do i = 1, 10000000 ! do something
12639 t2 = secnds (t1) ! elapsed time
12640 print *, "Something took ", t2, " seconds."
12641 end program test_secnds
12648 @section @code{SECOND} --- CPU time function
12650 @cindex time, elapsed
12651 @cindex elapsed time
12654 @item @emph{Description}:
12655 Returns a @code{REAL(4)} value representing the elapsed CPU time in
12656 seconds. This provides the same functionality as the standard
12657 @code{CPU_TIME} intrinsic, and is only included for backwards
12660 This intrinsic is provided in both subroutine and function forms;
12661 however, only one form can be used in any given program unit.
12663 @item @emph{Standard}:
12666 @item @emph{Class}:
12667 Subroutine, function
12669 @item @emph{Syntax}:
12670 @multitable @columnfractions .80
12671 @item @code{CALL SECOND(TIME)}
12672 @item @code{TIME = SECOND()}
12675 @item @emph{Arguments}:
12676 @multitable @columnfractions .15 .70
12677 @item @var{TIME} @tab Shall be of type @code{REAL(4)}.
12680 @item @emph{Return value}:
12681 In either syntax, @var{TIME} is set to the process's current runtime in
12684 @item @emph{See also}:
12691 @node SELECTED_CHAR_KIND
12692 @section @code{SELECTED_CHAR_KIND} --- Choose character kind
12693 @fnindex SELECTED_CHAR_KIND
12694 @cindex character kind
12695 @cindex kind, character
12698 @item @emph{Description}:
12700 @code{SELECTED_CHAR_KIND(NAME)} returns the kind value for the character
12701 set named @var{NAME}, if a character set with such a name is supported,
12702 or @math{-1} otherwise. Currently, supported character sets include
12703 ``ASCII'' and ``DEFAULT'', which are equivalent, and ``ISO_10646''
12704 (Universal Character Set, UCS-4) which is commonly known as Unicode.
12706 @item @emph{Standard}:
12707 Fortran 2003 and later
12709 @item @emph{Class}:
12710 Transformational function
12712 @item @emph{Syntax}:
12713 @code{RESULT = SELECTED_CHAR_KIND(NAME)}
12715 @item @emph{Arguments}:
12716 @multitable @columnfractions .15 .70
12717 @item @var{NAME} @tab Shall be a scalar and of the default character type.
12720 @item @emph{Example}:
12722 program character_kind
12723 use iso_fortran_env
12725 integer, parameter :: ascii = selected_char_kind ("ascii")
12726 integer, parameter :: ucs4 = selected_char_kind ('ISO_10646')
12728 character(kind=ascii, len=26) :: alphabet
12729 character(kind=ucs4, len=30) :: hello_world
12731 alphabet = ascii_"abcdefghijklmnopqrstuvwxyz"
12732 hello_world = ucs4_'Hello World and Ni Hao -- ' &
12733 // char (int (z'4F60'), ucs4) &
12734 // char (int (z'597D'), ucs4)
12736 write (*,*) alphabet
12738 open (output_unit, encoding='UTF-8')
12739 write (*,*) trim (hello_world)
12740 end program character_kind
12746 @node SELECTED_INT_KIND
12747 @section @code{SELECTED_INT_KIND} --- Choose integer kind
12748 @fnindex SELECTED_INT_KIND
12749 @cindex integer kind
12750 @cindex kind, integer
12753 @item @emph{Description}:
12754 @code{SELECTED_INT_KIND(R)} return the kind value of the smallest integer
12755 type that can represent all values ranging from @math{-10^R} (exclusive)
12756 to @math{10^R} (exclusive). If there is no integer kind that accommodates
12757 this range, @code{SELECTED_INT_KIND} returns @math{-1}.
12759 @item @emph{Standard}:
12760 Fortran 90 and later
12762 @item @emph{Class}:
12763 Transformational function
12765 @item @emph{Syntax}:
12766 @code{RESULT = SELECTED_INT_KIND(R)}
12768 @item @emph{Arguments}:
12769 @multitable @columnfractions .15 .70
12770 @item @var{R} @tab Shall be a scalar and of type @code{INTEGER}.
12773 @item @emph{Example}:
12775 program large_integers
12776 integer,parameter :: k5 = selected_int_kind(5)
12777 integer,parameter :: k15 = selected_int_kind(15)
12778 integer(kind=k5) :: i5
12779 integer(kind=k15) :: i15
12781 print *, huge(i5), huge(i15)
12783 ! The following inequalities are always true
12784 print *, huge(i5) >= 10_k5**5-1
12785 print *, huge(i15) >= 10_k15**15-1
12786 end program large_integers
12792 @node SELECTED_LOGICAL_KIND
12793 @section @code{SELECTED_LOGICAL_KIND} --- Choose logical kind
12794 @fnindex SELECTED_LOGICAL_KIND
12795 @cindex logical kind
12796 @cindex kind, logical
12799 @item @emph{Description}:
12800 @code{SELECTED_LOGICAL_KIND(BITS)} return the kind value of the smallest
12801 logical type whose storage size in bits is at least @var{BITS}. If there
12802 is no such logical kind, @code{SELECTED_LOGICAL_KIND} returns @math{-1}.
12804 @item @emph{Standard}:
12805 Fortran 2023 and later
12807 @item @emph{Class}:
12808 Transformational function
12810 @item @emph{Syntax}:
12811 @code{RESULT = SELECTED_LOGICAL_KIND(BITS)}
12813 @item @emph{Arguments}:
12814 @multitable @columnfractions .15 .70
12815 @item @var{BITS} @tab Shall be a scalar and of type @code{INTEGER}.
12818 @item @emph{Example}:
12820 program logical_kinds
12821 integer, parameter :: k1 = selected_logical_kind(1)
12822 integer, parameter :: k40 = selected_logical_kind(40)
12823 logical(kind=k1) :: l1 ! At least one bit
12824 logical(kind=k40) :: l40 ! At least 40 bits
12826 ! What is their actual size?
12827 print *, storage_size(l1), storage_size(l40)
12828 end program logical_kinds
12834 @node SELECTED_REAL_KIND
12835 @section @code{SELECTED_REAL_KIND} --- Choose real kind
12836 @fnindex SELECTED_REAL_KIND
12839 @cindex radix, real
12842 @item @emph{Description}:
12843 @code{SELECTED_REAL_KIND(P,R)} returns the kind value of a real data type
12844 with decimal precision of at least @code{P} digits, exponent range of
12845 at least @code{R}, and with a radix of @code{RADIX}.
12847 @item @emph{Standard}:
12848 Fortran 90 and later, with @code{RADIX} Fortran 2008 or later
12850 @item @emph{Class}:
12851 Transformational function
12853 @item @emph{Syntax}:
12854 @code{RESULT = SELECTED_REAL_KIND([P, R, RADIX])}
12856 @item @emph{Arguments}:
12857 @multitable @columnfractions .15 .70
12858 @item @var{P} @tab (Optional) shall be a scalar and of type @code{INTEGER}.
12859 @item @var{R} @tab (Optional) shall be a scalar and of type @code{INTEGER}.
12860 @item @var{RADIX} @tab (Optional) shall be a scalar and of type @code{INTEGER}.
12862 Before Fortran 2008, at least one of the arguments @var{R} or @var{P} shall
12863 be present; since Fortran 2008, they are assumed to be zero if absent.
12865 @item @emph{Return value}:
12867 @code{SELECTED_REAL_KIND} returns the value of the kind type parameter of
12868 a real data type with decimal precision of at least @code{P} digits, a
12869 decimal exponent range of at least @code{R}, and with the requested
12870 @code{RADIX}. If the @code{RADIX} parameter is absent, real kinds with
12871 any radix can be returned. If more than one real data type meet the
12872 criteria, the kind of the data type with the smallest decimal precision
12873 is returned. If no real data type matches the criteria, the result is
12875 @item -1 if the processor does not support a real data type with a
12876 precision greater than or equal to @code{P}, but the @code{R} and
12877 @code{RADIX} requirements can be fulfilled
12878 @item -2 if the processor does not support a real type with an exponent
12879 range greater than or equal to @code{R}, but @code{P} and @code{RADIX}
12881 @item -3 if @code{RADIX} but not @code{P} and @code{R} requirements
12883 @item -4 if @code{RADIX} and either @code{P} or @code{R} requirements
12885 @item -5 if there is no real type with the given @code{RADIX}
12888 @item @emph{Example}:
12891 integer,parameter :: p6 = selected_real_kind(6)
12892 integer,parameter :: p10r100 = selected_real_kind(10,100)
12893 integer,parameter :: r400 = selected_real_kind(r=400)
12895 real(kind=p10r100) :: y
12896 real(kind=r400) :: z
12898 print *, precision(x), range(x)
12899 print *, precision(y), range(y)
12900 print *, precision(z), range(z)
12901 end program real_kinds
12903 @item @emph{See also}:
12904 @ref{PRECISION}, @*
12912 @section @code{SET_EXPONENT} --- Set the exponent of the model
12913 @fnindex SET_EXPONENT
12914 @cindex real number, set exponent
12915 @cindex floating point, set exponent
12918 @item @emph{Description}:
12919 @code{SET_EXPONENT(X, I)} returns the real number whose fractional part
12920 is that of @var{X} and whose exponent part is @var{I}.
12922 @item @emph{Standard}:
12923 Fortran 90 and later
12925 @item @emph{Class}:
12928 @item @emph{Syntax}:
12929 @code{RESULT = SET_EXPONENT(X, I)}
12931 @item @emph{Arguments}:
12932 @multitable @columnfractions .15 .70
12933 @item @var{X} @tab Shall be of type @code{REAL}.
12934 @item @var{I} @tab Shall be of type @code{INTEGER}.
12937 @item @emph{Return value}:
12938 The return value is of the same type and kind as @var{X}.
12939 The real number whose fractional part
12940 is that of @var{X} and whose exponent part if @var{I} is returned;
12941 it is @code{FRACTION(X) * RADIX(X)**I}.
12943 @item @emph{Example}:
12945 PROGRAM test_setexp
12946 REAL :: x = 178.1387e-4
12948 PRINT *, SET_EXPONENT(x, i), FRACTION(x) * RADIX(x)**i
12957 @section @code{SHAPE} --- Determine the shape of an array
12959 @cindex array, shape
12962 @item @emph{Description}:
12963 Determines the shape of an array.
12965 @item @emph{Standard}:
12966 Fortran 90 and later, with @var{KIND} argument Fortran 2003 and later
12968 @item @emph{Class}:
12971 @item @emph{Syntax}:
12972 @code{RESULT = SHAPE(SOURCE [, KIND])}
12974 @item @emph{Arguments}:
12975 @multitable @columnfractions .15 .70
12976 @item @var{SOURCE} @tab Shall be an array or scalar of any type.
12977 If @var{SOURCE} is a pointer it must be associated and allocatable
12978 arrays must be allocated.
12979 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
12980 expression indicating the kind parameter of the result.
12983 @item @emph{Return value}:
12984 An @code{INTEGER} array of rank one with as many elements as @var{SOURCE}
12985 has dimensions. The elements of the resulting array correspond to the extend
12986 of @var{SOURCE} along the respective dimensions. If @var{SOURCE} is a scalar,
12987 the result is the rank one array of size zero. If @var{KIND} is absent, the
12988 return value has the default integer kind otherwise the specified kind.
12990 @item @emph{Example}:
12993 INTEGER, DIMENSION(-1:1, -1:2) :: A
12994 WRITE(*,*) SHAPE(A) ! (/ 3, 4 /)
12995 WRITE(*,*) SIZE(SHAPE(42)) ! (/ /)
12999 @item @emph{See also}:
13007 @section @code{SHIFTA} --- Right shift with fill
13009 @cindex bits, shift right
13010 @cindex shift, right with fill
13013 @item @emph{Description}:
13014 @code{SHIFTA} returns a value corresponding to @var{I} with all of the
13015 bits shifted right by @var{SHIFT} places. @var{SHIFT} that be
13016 nonnegative and less than or equal to @code{BIT_SIZE(I)}, otherwise
13017 the result value is undefined. Bits shifted out from the right end
13018 are lost. The fill is arithmetic: the bits shifted in from the left
13019 end are equal to the leftmost bit, which in two's complement
13020 representation is the sign bit.
13022 @item @emph{Standard}:
13023 Fortran 2008 and later
13025 @item @emph{Class}:
13028 @item @emph{Syntax}:
13029 @code{RESULT = SHIFTA(I, SHIFT)}
13031 @item @emph{Arguments}:
13032 @multitable @columnfractions .15 .70
13033 @item @var{I} @tab The type shall be @code{INTEGER}.
13034 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
13037 @item @emph{Return value}:
13038 The return value is of type @code{INTEGER} and of the same kind as
13041 @item @emph{See also}:
13049 @section @code{SHIFTL} --- Left shift
13051 @cindex bits, shift left
13052 @cindex shift, left
13055 @item @emph{Description}:
13056 @code{SHIFTL} returns a value corresponding to @var{I} with all of the
13057 bits shifted left by @var{SHIFT} places. @var{SHIFT} shall be
13058 nonnegative and less than or equal to @code{BIT_SIZE(I)}, otherwise
13059 the result value is undefined. Bits shifted out from the left end are
13060 lost, and bits shifted in from the right end are set to 0.
13062 @item @emph{Standard}:
13063 Fortran 2008 and later
13065 @item @emph{Class}:
13068 @item @emph{Syntax}:
13069 @code{RESULT = SHIFTL(I, SHIFT)}
13071 @item @emph{Arguments}:
13072 @multitable @columnfractions .15 .70
13073 @item @var{I} @tab The type shall be @code{INTEGER}.
13074 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
13077 @item @emph{Return value}:
13078 The return value is of type @code{INTEGER} and of the same kind as
13081 @item @emph{See also}:
13089 @section @code{SHIFTR} --- Right shift
13091 @cindex bits, shift right
13092 @cindex shift, right
13095 @item @emph{Description}:
13096 @code{SHIFTR} returns a value corresponding to @var{I} with all of the
13097 bits shifted right by @var{SHIFT} places. @var{SHIFT} shall be
13098 nonnegative and less than or equal to @code{BIT_SIZE(I)}, otherwise
13099 the result value is undefined. Bits shifted out from the right end
13100 are lost, and bits shifted in from the left end are set to 0.
13102 @item @emph{Standard}:
13103 Fortran 2008 and later
13105 @item @emph{Class}:
13108 @item @emph{Syntax}:
13109 @code{RESULT = SHIFTR(I, SHIFT)}
13111 @item @emph{Arguments}:
13112 @multitable @columnfractions .15 .70
13113 @item @var{I} @tab The type shall be @code{INTEGER}.
13114 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
13117 @item @emph{Return value}:
13118 The return value is of type @code{INTEGER} and of the same kind as
13121 @item @emph{See also}:
13129 @section @code{SIGN} --- Sign copying function
13133 @cindex sign copying
13136 @item @emph{Description}:
13137 @code{SIGN(A,B)} returns the value of @var{A} with the sign of @var{B}.
13139 @item @emph{Standard}:
13140 Fortran 77 and later
13142 @item @emph{Class}:
13145 @item @emph{Syntax}:
13146 @code{RESULT = SIGN(A, B)}
13148 @item @emph{Arguments}:
13149 @multitable @columnfractions .15 .70
13150 @item @var{A} @tab Shall be of type @code{INTEGER} or @code{REAL}
13151 @item @var{B} @tab Shall be of the same type and kind as @var{A}.
13154 @item @emph{Return value}:
13155 The kind of the return value is that of @var{A} and @var{B}.
13156 If @math{B \ge 0} then the result is @code{ABS(A)}, else
13157 it is @code{-ABS(A)}.
13159 @item @emph{Example}:
13162 print *, sign(-12,1)
13163 print *, sign(-12,0)
13164 print *, sign(-12,-1)
13166 print *, sign(-12.,1.)
13167 print *, sign(-12.,0.)
13168 print *, sign(-12.,-1.)
13169 end program test_sign
13172 @item @emph{Specific names}:
13173 @multitable @columnfractions .20 .26 .20 .30
13174 @headitem Name @tab Arguments @tab Return type @tab Standard
13175 @item @code{SIGN(A,B)} @tab @code{REAL(4) A, B} @tab @code{REAL(4)} @tab Fortran 77 and later
13176 @item @code{ISIGN(A,B)} @tab @code{INTEGER(4) A, B} @tab @code{INTEGER(4)} @tab Fortran 77 and later
13177 @item @code{DSIGN(A,B)} @tab @code{REAL(8) A, B} @tab @code{REAL(8)} @tab Fortran 77 and later
13184 @section @code{SIGNAL} --- Signal handling subroutine (or function)
13186 @cindex system, signal handling
13189 @item @emph{Description}:
13190 @code{SIGNAL(NUMBER, HANDLER [, STATUS])} causes external subroutine
13191 @var{HANDLER} to be executed with a single integer argument passed by
13192 value when signal @var{NUMBER} occurs. If @var{HANDLER} is an integer,
13193 it can be used to turn off handling of signal @var{NUMBER} or revert to
13194 its default action. See @code{signal(2)}.
13196 If @code{SIGNAL} is called as a subroutine and the @var{STATUS} argument
13197 is supplied, it is set to the value returned by @code{signal(2)}.
13199 @item @emph{Standard}:
13202 @item @emph{Class}:
13203 Subroutine, function
13205 @item @emph{Syntax}:
13206 @multitable @columnfractions .80
13207 @item @code{CALL SIGNAL(NUMBER, HANDLER [, STATUS])}
13208 @item @code{STATUS = SIGNAL(NUMBER, HANDLER)}
13211 @item @emph{Arguments}:
13212 @multitable @columnfractions .15 .70
13213 @item @var{NUMBER} @tab Shall be a scalar integer, with @code{INTENT(IN)}
13214 @item @var{HANDLER}@tab Signal handler (@code{INTEGER FUNCTION} or
13215 @code{SUBROUTINE}) or dummy/global @code{INTEGER} scalar.
13216 @code{INTEGER}. It is @code{INTENT(IN)}.
13217 @item @var{STATUS} @tab (Optional) @var{STATUS} shall be a scalar
13218 integer. It has @code{INTENT(OUT)}.
13221 @item @emph{Return value}:
13222 The @code{SIGNAL} function returns the value returned by @code{signal(2)}.
13224 @item @emph{Example}:
13228 ! POSIX.1-2017: void (*func)(int)
13229 subroutine handler_print(signum) bind(C)
13230 use iso_c_binding, only: c_int
13231 integer(c_int), value :: signum
13232 print *, 'handler_print invoked with signum =', signum
13235 program test_signal
13237 intrinsic :: signal, sleep
13238 call signal (12, handler_print) ! 12 = SIGUSR2 (on some systems)
13239 call signal (10, 1) ! 10 = SIGUSR1 and 1 = SIG_IGN (on some systems)
13242 end program test_signal
13249 @section @code{SIN} --- Sine function
13255 @cindex trigonometric function, sine
13259 @item @emph{Description}:
13260 @code{SIN(X)} computes the sine of @var{X}.
13262 @item @emph{Standard}:
13263 Fortran 77 and later
13265 @item @emph{Class}:
13268 @item @emph{Syntax}:
13269 @code{RESULT = SIN(X)}
13271 @item @emph{Arguments}:
13272 @multitable @columnfractions .15 .70
13273 @item @var{X} @tab The type shall be @code{REAL} or
13277 @item @emph{Return value}:
13278 The return value has same type and kind as @var{X}.
13280 @item @emph{Example}:
13285 end program test_sin
13288 @item @emph{Specific names}:
13289 @multitable @columnfractions .20 .23 .20 .33
13290 @headitem Name @tab Argument @tab Return type @tab Standard
13291 @item @code{SIN(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
13292 @item @code{DSIN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
13293 @item @code{CSIN(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab Fortran 77 and later
13294 @item @code{ZSIN(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
13295 @item @code{CDSIN(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
13298 @item @emph{See also}:
13299 Inverse function: @*
13301 Degrees function: @*
13308 @section @code{SIND} --- Sine function, degrees
13314 @cindex trigonometric function, sine, degrees
13315 @cindex sine, degrees
13318 @item @emph{Description}:
13319 @code{SIND(X)} computes the sine of @var{X} in degrees.
13321 @item @emph{Standard}:
13324 @item @emph{Class}:
13327 @item @emph{Syntax}:
13328 @code{RESULT = SIND(X)}
13330 @item @emph{Arguments}:
13331 @multitable @columnfractions .15 .70
13332 @item @var{X} @tab The type shall be @code{REAL}.
13335 @item @emph{Return value}:
13336 The return value has same type and kind as @var{X}, and its value is in degrees.
13338 @item @emph{Example}:
13343 end program test_sind
13346 @item @emph{Specific names}:
13347 @multitable @columnfractions .20 .23 .20 .33
13348 @headitem Name @tab Argument @tab Return type @tab Standard
13349 @item @code{SIND(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 2023
13350 @item @code{DSIND(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
13351 @item @code{CSIND(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab GNU extension
13352 @item @code{ZSIND(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
13353 @item @code{CDSIND(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
13356 @item @emph{See also}:
13357 Inverse function: @*
13359 Radians function: @*
13364 @section @code{SINH} --- Hyperbolic sine function
13367 @cindex hyperbolic sine
13368 @cindex hyperbolic function, sine
13369 @cindex sine, hyperbolic
13372 @item @emph{Description}:
13373 @code{SINH(X)} computes the hyperbolic sine of @var{X}.
13375 @item @emph{Standard}:
13376 Fortran 90 and later, for a complex argument Fortran 2008 or later, has
13379 @item @emph{Class}:
13382 @item @emph{Syntax}:
13383 @code{RESULT = SINH(X)}
13385 @item @emph{Arguments}:
13386 @multitable @columnfractions .15 .70
13387 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
13390 @item @emph{Return value}:
13391 The return value has same type and kind as @var{X}.
13393 @item @emph{Example}:
13396 real(8) :: x = - 1.0_8
13398 end program test_sinh
13401 @item @emph{Specific names}:
13402 @multitable @columnfractions .20 .23 .20 .33
13403 @headitem Name @tab Argument @tab Return type @tab Standard
13404 @item @code{DSINH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 90 and later
13407 @item @emph{See also}:
13414 @section @code{SIZE} --- Determine the size of an array
13416 @cindex array, size
13417 @cindex array, number of elements
13418 @cindex array, count elements
13421 @item @emph{Description}:
13422 Determine the extent of @var{ARRAY} along a specified dimension @var{DIM},
13423 or the total number of elements in @var{ARRAY} if @var{DIM} is absent.
13425 @item @emph{Standard}:
13426 Fortran 90 and later, with @var{KIND} argument Fortran 2003 and later
13428 @item @emph{Class}:
13431 @item @emph{Syntax}:
13432 @code{RESULT = SIZE(ARRAY[, DIM [, KIND]])}
13434 @item @emph{Arguments}:
13435 @multitable @columnfractions .15 .70
13436 @item @var{ARRAY} @tab Shall be an array of any type. If @var{ARRAY} is
13437 a pointer it must be associated and allocatable arrays must be allocated.
13438 @item @var{DIM} @tab (Optional) shall be a scalar of type @code{INTEGER}
13439 and its value shall be in the range from 1 to n, where n equals the rank
13441 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
13442 expression indicating the kind parameter of the result.
13445 @item @emph{Return value}:
13446 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
13447 @var{KIND} is absent, the return value is of default integer kind.
13449 @item @emph{Example}:
13452 WRITE(*,*) SIZE((/ 1, 2 /)) ! 2
13456 @item @emph{See also}:
13463 @section @code{SIZEOF} --- Size in bytes of an expression
13465 @cindex expression size
13466 @cindex size of an expression
13469 @item @emph{Description}:
13470 @code{SIZEOF(X)} calculates the number of bytes of storage the
13471 expression @code{X} occupies.
13473 @item @emph{Standard}:
13476 @item @emph{Class}:
13479 @item @emph{Syntax}:
13480 @code{N = SIZEOF(X)}
13482 @item @emph{Arguments}:
13483 @multitable @columnfractions .15 .70
13484 @item @var{X} @tab The argument shall be of any type, rank or shape.
13487 @item @emph{Return value}:
13488 The return value is of type integer and of the system-dependent kind
13489 @var{C_SIZE_T} (from the @var{ISO_C_BINDING} module). Its value is the
13490 number of bytes occupied by the argument. If the argument has the
13491 @code{POINTER} attribute, the number of bytes of the storage area pointed
13492 to is returned. If the argument is of a derived type with @code{POINTER}
13493 or @code{ALLOCATABLE} components, the return value does not account for
13494 the sizes of the data pointed to by these components. If the argument is
13495 polymorphic, the size according to the dynamic type is returned. The argument
13496 may not be a procedure or procedure pointer. Note that the code assumes for
13497 arrays that those are contiguous; for contiguous arrays, it returns the
13498 storage or an array element multiplied by the size of the array.
13500 @item @emph{Example}:
13504 print *, (sizeof(s)/sizeof(r) == 5)
13507 The example will print @code{.TRUE.} unless you are using a platform
13508 where default @code{REAL} variables are unusually padded.
13510 @item @emph{See also}:
13517 @section @code{SLEEP} --- Sleep for the specified number of seconds
13519 @cindex delayed execution
13522 @item @emph{Description}:
13523 Calling this subroutine causes the process to pause for @var{SECONDS} seconds.
13525 @item @emph{Standard}:
13528 @item @emph{Class}:
13531 @item @emph{Syntax}:
13532 @code{CALL SLEEP(SECONDS)}
13534 @item @emph{Arguments}:
13535 @multitable @columnfractions .15 .70
13536 @item @var{SECONDS} @tab The type shall be of default @code{INTEGER}.
13539 @item @emph{Example}:
13550 @section @code{SPACING} --- Smallest distance between two numbers of a given type
13552 @cindex real number, relative spacing
13553 @cindex floating point, relative spacing
13556 @item @emph{Description}:
13557 Determines the distance between the argument @var{X} and the nearest
13558 adjacent number of the same type.
13560 @item @emph{Standard}:
13561 Fortran 90 and later
13563 @item @emph{Class}:
13566 @item @emph{Syntax}:
13567 @code{RESULT = SPACING(X)}
13569 @item @emph{Arguments}:
13570 @multitable @columnfractions .15 .70
13571 @item @var{X} @tab Shall be of type @code{REAL}.
13574 @item @emph{Return value}:
13575 The result is of the same type as the input argument @var{X}.
13577 @item @emph{Example}:
13579 PROGRAM test_spacing
13580 INTEGER, PARAMETER :: SGL = SELECTED_REAL_KIND(p=6, r=37)
13581 INTEGER, PARAMETER :: DBL = SELECTED_REAL_KIND(p=13, r=200)
13583 WRITE(*,*) spacing(1.0_SGL) ! "1.1920929E-07" on i686
13584 WRITE(*,*) spacing(1.0_DBL) ! "2.220446049250313E-016" on i686
13588 @item @emph{See also}:
13595 @section @code{SPREAD} --- Add a dimension to an array
13597 @cindex array, increase dimension
13598 @cindex array, duplicate elements
13599 @cindex array, duplicate dimensions
13602 @item @emph{Description}:
13603 Replicates a @var{SOURCE} array @var{NCOPIES} times along a specified
13604 dimension @var{DIM}.
13606 @item @emph{Standard}:
13607 Fortran 90 and later
13609 @item @emph{Class}:
13610 Transformational function
13612 @item @emph{Syntax}:
13613 @code{RESULT = SPREAD(SOURCE, DIM, NCOPIES)}
13615 @item @emph{Arguments}:
13616 @multitable @columnfractions .15 .70
13617 @item @var{SOURCE} @tab Shall be a scalar or an array of any type and
13618 a rank less than seven.
13619 @item @var{DIM} @tab Shall be a scalar of type @code{INTEGER} with a
13620 value in the range from 1 to n+1, where n equals the rank of @var{SOURCE}.
13621 @item @var{NCOPIES} @tab Shall be a scalar of type @code{INTEGER}.
13624 @item @emph{Return value}:
13625 The result is an array of the same type as @var{SOURCE} and has rank n+1
13626 where n equals the rank of @var{SOURCE}.
13628 @item @emph{Example}:
13630 PROGRAM test_spread
13631 INTEGER :: a = 1, b(2) = (/ 1, 2 /)
13632 WRITE(*,*) SPREAD(A, 1, 2) ! "1 1"
13633 WRITE(*,*) SPREAD(B, 1, 2) ! "1 1 2 2"
13637 @item @emph{See also}:
13644 @section @code{SQRT} --- Square-root function
13651 @cindex square-root
13654 @item @emph{Description}:
13655 @code{SQRT(X)} computes the square root of @var{X}.
13657 @item @emph{Standard}:
13658 Fortran 77 and later
13660 @item @emph{Class}:
13663 @item @emph{Syntax}:
13664 @code{RESULT = SQRT(X)}
13666 @item @emph{Arguments}:
13667 @multitable @columnfractions .15 .70
13668 @item @var{X} @tab The type shall be @code{REAL} or
13672 @item @emph{Return value}:
13673 The return value is of type @code{REAL} or @code{COMPLEX}.
13674 The kind type parameter is the same as @var{X}.
13676 @item @emph{Example}:
13679 real(8) :: x = 2.0_8
13680 complex :: z = (1.0, 2.0)
13683 end program test_sqrt
13686 @item @emph{Specific names}:
13687 @multitable @columnfractions .20 .23 .20 .33
13688 @headitem Name @tab Argument @tab Return type @tab Standard
13689 @item @code{SQRT(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
13690 @item @code{DSQRT(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
13691 @item @code{CSQRT(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab Fortran 77 and later
13692 @item @code{ZSQRT(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
13693 @item @code{CDSQRT(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
13700 @section @code{SRAND} --- Reinitialize the random number generator
13702 @cindex random number generation, seeding
13703 @cindex seeding a random number generator
13706 @item @emph{Description}:
13707 @code{SRAND} reinitializes the pseudo-random number generator
13708 called by @code{RAND} and @code{IRAND}. The new seed used by the
13709 generator is specified by the required argument @var{SEED}.
13711 @item @emph{Standard}:
13714 @item @emph{Class}:
13717 @item @emph{Syntax}:
13718 @code{CALL SRAND(SEED)}
13720 @item @emph{Arguments}:
13721 @multitable @columnfractions .15 .70
13722 @item @var{SEED} @tab Shall be a scalar @code{INTEGER(kind=4)}.
13725 @item @emph{Return value}:
13726 Does not return anything.
13728 @item @emph{Example}:
13729 See @code{RAND} and @code{IRAND} for examples.
13731 @item @emph{Notes}:
13732 The Fortran standard specifies the intrinsic subroutines
13733 @code{RANDOM_SEED} to initialize the pseudo-random number
13734 generator and @code{RANDOM_NUMBER} to generate pseudo-random numbers.
13735 These subroutines should be used in new codes.
13737 Please note that in GNU Fortran, these two sets of intrinsics (@code{RAND},
13738 @code{IRAND} and @code{SRAND} on the one hand, @code{RANDOM_NUMBER} and
13739 @code{RANDOM_SEED} on the other hand) access two independent
13740 pseudo-random number generators.
13742 @item @emph{See also}:
13744 @ref{RANDOM_SEED}, @*
13745 @ref{RANDOM_NUMBER}
13751 @section @code{STAT} --- Get file status
13753 @cindex file system, file status
13756 @item @emph{Description}:
13757 This function returns information about a file. No permissions are required on
13758 the file itself, but execute (search) permission is required on all of the
13759 directories in path that lead to the file.
13761 The elements that are obtained and stored in the array @code{VALUES}:
13762 @multitable @columnfractions .15 .70
13763 @item @code{VALUES(1)} @tab Device ID
13764 @item @code{VALUES(2)} @tab Inode number
13765 @item @code{VALUES(3)} @tab File mode
13766 @item @code{VALUES(4)} @tab Number of links
13767 @item @code{VALUES(5)} @tab Owner's uid
13768 @item @code{VALUES(6)} @tab Owner's gid
13769 @item @code{VALUES(7)} @tab ID of device containing directory entry for file (0 if not available)
13770 @item @code{VALUES(8)} @tab File size (bytes)
13771 @item @code{VALUES(9)} @tab Last access time
13772 @item @code{VALUES(10)} @tab Last modification time
13773 @item @code{VALUES(11)} @tab Last file status change time
13774 @item @code{VALUES(12)} @tab Preferred I/O block size (-1 if not available)
13775 @item @code{VALUES(13)} @tab Number of blocks allocated (-1 if not available)
13778 Not all these elements are relevant on all systems.
13779 If an element is not relevant, it is returned as 0.
13781 This intrinsic is provided in both subroutine and function forms; however,
13782 only one form can be used in any given program unit.
13784 @item @emph{Standard}:
13787 @item @emph{Class}:
13788 Subroutine, function
13790 @item @emph{Syntax}:
13791 @multitable @columnfractions .80
13792 @item @code{CALL STAT(NAME, VALUES [, STATUS])}
13793 @item @code{STATUS = STAT(NAME, VALUES)}
13796 @item @emph{Arguments}:
13797 @multitable @columnfractions .15 .70
13798 @item @var{NAME} @tab The type shall be @code{CHARACTER}, of the
13799 default kind and a valid path within the file system.
13800 @item @var{VALUES} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
13801 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}. Returns 0
13802 on success and a system specific error code otherwise.
13805 @item @emph{Example}:
13808 INTEGER, DIMENSION(13) :: buff
13811 CALL STAT("/etc/passwd", buff, status)
13813 IF (status == 0) THEN
13814 WRITE (*, FMT="('Device ID:', T30, I19)") buff(1)
13815 WRITE (*, FMT="('Inode number:', T30, I19)") buff(2)
13816 WRITE (*, FMT="('File mode (octal):', T30, O19)") buff(3)
13817 WRITE (*, FMT="('Number of links:', T30, I19)") buff(4)
13818 WRITE (*, FMT="('Owner''s uid:', T30, I19)") buff(5)
13819 WRITE (*, FMT="('Owner''s gid:', T30, I19)") buff(6)
13820 WRITE (*, FMT="('Device where located:', T30, I19)") buff(7)
13821 WRITE (*, FMT="('File size:', T30, I19)") buff(8)
13822 WRITE (*, FMT="('Last access time:', T30, A19)") CTIME(buff(9))
13823 WRITE (*, FMT="('Last modification time', T30, A19)") CTIME(buff(10))
13824 WRITE (*, FMT="('Last status change time:', T30, A19)") CTIME(buff(11))
13825 WRITE (*, FMT="('Preferred block size:', T30, I19)") buff(12)
13826 WRITE (*, FMT="('No. of blocks allocated:', T30, I19)") buff(13)
13831 @item @emph{See also}:
13832 To stat an open file: @*
13841 @section @code{STORAGE_SIZE} --- Storage size in bits
13842 @fnindex STORAGE_SIZE
13843 @cindex storage size
13846 @item @emph{Description}:
13847 Returns the storage size of argument @var{A} in bits.
13848 @item @emph{Standard}:
13849 Fortran 2008 and later
13850 @item @emph{Class}:
13852 @item @emph{Syntax}:
13853 @code{RESULT = STORAGE_SIZE(A [, KIND])}
13855 @item @emph{Arguments}:
13856 @multitable @columnfractions .15 .70
13857 @item @var{A} @tab Shall be a scalar or array of any type.
13858 @item @var{KIND} @tab (Optional) shall be a scalar integer constant expression.
13861 @item @emph{Return Value}:
13862 The result is a scalar integer with the kind type parameter specified by KIND
13863 (or default integer type if KIND is missing). The result value is the size
13864 expressed in bits for an element of an array that has the dynamic type and type
13867 @item @emph{See also}:
13875 @section @code{SUM} --- Sum of array elements
13878 @cindex array, add elements
13879 @cindex array, conditionally add elements
13880 @cindex sum array elements
13883 @item @emph{Description}:
13884 Adds the elements of @var{ARRAY} along dimension @var{DIM} if
13885 the corresponding element in @var{MASK} is @code{TRUE}.
13887 @item @emph{Standard}:
13888 Fortran 90 and later
13890 @item @emph{Class}:
13891 Transformational function
13893 @item @emph{Syntax}:
13894 @multitable @columnfractions .80
13895 @item @code{RESULT = SUM(ARRAY[, MASK])}
13896 @item @code{RESULT = SUM(ARRAY, DIM[, MASK])}
13899 @item @emph{Arguments}:
13900 @multitable @columnfractions .15 .70
13901 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER},
13902 @code{REAL} or @code{COMPLEX}.
13903 @item @var{DIM} @tab (Optional) shall be a scalar of type
13904 @code{INTEGER} with a value in the range from 1 to n, where n
13905 equals the rank of @var{ARRAY}.
13906 @item @var{MASK} @tab (Optional) shall be of type @code{LOGICAL}
13907 and either be a scalar or an array of the same shape as @var{ARRAY}.
13910 @item @emph{Return value}:
13911 The result is of the same type as @var{ARRAY}.
13913 If @var{DIM} is absent, a scalar with the sum of all elements in @var{ARRAY}
13914 is returned. Otherwise, an array of rank n-1, where n equals the rank of
13915 @var{ARRAY}, and a shape similar to that of @var{ARRAY} with dimension @var{DIM}
13916 dropped is returned.
13918 @item @emph{Example}:
13921 INTEGER :: x(5) = (/ 1, 2, 3, 4 ,5 /)
13922 print *, SUM(x) ! all elements, sum = 15
13923 print *, SUM(x, MASK=MOD(x, 2)==1) ! odd elements, sum = 9
13927 @item @emph{See also}:
13934 @section @code{SYMLNK} --- Create a symbolic link
13936 @cindex file system, create link
13937 @cindex file system, soft link
13940 @item @emph{Description}:
13941 Makes a symbolic link from file @var{PATH1} to @var{PATH2}. A null
13942 character (@code{CHAR(0)}) can be used to mark the end of the names in
13943 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
13944 names are ignored. If the @var{STATUS} argument is supplied, it
13945 contains 0 on success or a nonzero error code upon return; see
13946 @code{symlink(2)}. If the system does not supply @code{symlink(2)},
13947 @code{ENOSYS} is returned.
13949 This intrinsic is provided in both subroutine and function forms;
13950 however, only one form can be used in any given program unit.
13952 @item @emph{Standard}:
13955 @item @emph{Class}:
13956 Subroutine, function
13958 @item @emph{Syntax}:
13959 @multitable @columnfractions .80
13960 @item @code{CALL SYMLNK(PATH1, PATH2 [, STATUS])}
13961 @item @code{STATUS = SYMLNK(PATH1, PATH2)}
13964 @item @emph{Arguments}:
13965 @multitable @columnfractions .15 .70
13966 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
13967 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
13968 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
13971 @item @emph{See also}:
13979 @section @code{SYSTEM} --- Execute a shell command
13981 @cindex system, system call
13984 @item @emph{Description}:
13985 Passes the command @var{COMMAND} to a shell (see @code{system(3)}). If
13986 argument @var{STATUS} is present, it contains the value returned by
13987 @code{system(3)}, which is presumably 0 if the shell command succeeded.
13988 Note that which shell is used to invoke the command is system-dependent
13989 and environment-dependent.
13991 This intrinsic is provided in both subroutine and function forms;
13992 however, only one form can be used in any given program unit.
13994 Note that the @code{system} function need not be thread-safe. It is
13995 the responsibility of the user to ensure that @code{system} is not
13996 called concurrently.
13998 @item @emph{Standard}:
14001 @item @emph{Class}:
14002 Subroutine, function
14004 @item @emph{Syntax}:
14005 @multitable @columnfractions .80
14006 @item @code{CALL SYSTEM(COMMAND [, STATUS])}
14007 @item @code{STATUS = SYSTEM(COMMAND)}
14010 @item @emph{Arguments}:
14011 @multitable @columnfractions .15 .70
14012 @item @var{COMMAND} @tab Shall be of default @code{CHARACTER} type.
14013 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
14016 @item @emph{See also}:
14017 @ref{EXECUTE_COMMAND_LINE}, which is part of the Fortran 2008 standard
14018 and should considered in new code for future portability.
14024 @section @code{SYSTEM_CLOCK} --- Time function
14025 @fnindex SYSTEM_CLOCK
14026 @cindex time, clock ticks
14027 @cindex clock ticks
14030 @item @emph{Description}:
14031 Determines the @var{COUNT} of a processor clock since an unspecified
14032 time in the past modulo @var{COUNT_MAX}, @var{COUNT_RATE} determines
14033 the number of clock ticks per second. If the platform supports a
14034 monotonic clock, that clock is used and can, depending on the platform
14035 clock implementation, provide up to nanosecond resolution. If a
14036 monotonic clock is not available, the implementation falls back to a
14039 @var{COUNT_RATE} is system dependent and can vary depending on the kind of
14040 the arguments. For @var{kind=4} arguments (and smaller integer kinds),
14041 @var{COUNT} represents milliseconds, while for @var{kind=8} arguments (and
14042 larger integer kinds), @var{COUNT} typically represents micro- or
14043 nanoseconds depending on resolution of the underlying platform clock.
14044 @var{COUNT_MAX} usually equals @code{HUGE(COUNT_MAX)}. Note that the
14045 millisecond resolution of the @var{kind=4} version implies that the
14046 @var{COUNT} will wrap around in roughly 25 days. In order to avoid issues
14047 with the wrap around and for more precise timing, please use the
14048 @var{kind=8} version.
14050 If there is no clock, or querying the clock fails, @var{COUNT} is set
14051 to @code{-HUGE(COUNT)}, and @var{COUNT_RATE} and @var{COUNT_MAX} are
14054 When running on a platform using the GNU C library (glibc) version
14055 2.16 or older, or a derivative thereof, the high resolution monotonic
14056 clock is available only when linking with the @var{rt} library. This
14057 can be done explicitly by adding the @code{-lrt} flag when linking the
14058 application, but is also done implicitly when using OpenMP.
14060 On the Windows platform, the version with @var{kind=4} arguments uses
14061 the @code{GetTickCount} function, whereas the @var{kind=8} version
14062 uses @code{QueryPerformanceCounter} and
14063 @code{QueryPerformanceCounterFrequency}. For more information, and
14064 potential caveats, please see the platform documentation.
14066 @item @emph{Standard}:
14067 Fortran 90 and later
14069 @item @emph{Class}:
14072 @item @emph{Syntax}:
14073 @code{CALL SYSTEM_CLOCK([COUNT, COUNT_RATE, COUNT_MAX])}
14075 @item @emph{Arguments}:
14076 @multitable @columnfractions .20 .65
14077 @item @var{COUNT} @tab (Optional) shall be a scalar of type
14078 @code{INTEGER} with @code{INTENT(OUT)}.
14079 @item @var{COUNT_RATE} @tab (Optional) shall be a scalar of type
14080 @code{INTEGER} or @code{REAL}, with @code{INTENT(OUT)}.
14081 @item @var{COUNT_MAX} @tab (Optional) shall be a scalar of type
14082 @code{INTEGER} with @code{INTENT(OUT)}.
14085 @item @emph{Example}:
14087 PROGRAM test_system_clock
14088 INTEGER :: count, count_rate, count_max
14089 CALL SYSTEM_CLOCK(count, count_rate, count_max)
14090 WRITE(*,*) count, count_rate, count_max
14094 @item @emph{See also}:
14095 @ref{DATE_AND_TIME}, @*
14102 @section @code{TAN} --- Tangent function
14105 @cindex trigonometric function, tangent
14109 @item @emph{Description}:
14110 @code{TAN(X)} computes the tangent of @var{X}.
14112 @item @emph{Standard}:
14113 Fortran 77 and later, for a complex argument Fortran 2008 or later
14115 @item @emph{Class}:
14118 @item @emph{Syntax}:
14119 @code{RESULT = TAN(X)}
14121 @item @emph{Arguments}:
14122 @multitable @columnfractions .15 .70
14123 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
14126 @item @emph{Return value}:
14127 The return value has same type and kind as @var{X}, and its value is in radians.
14129 @item @emph{Example}:
14132 real(8) :: x = 0.165_8
14134 end program test_tan
14137 @item @emph{Specific names}:
14138 @multitable @columnfractions .20 .23 .20 .33
14139 @headitem Name @tab Argument @tab Return type @tab Standard
14140 @item @code{TAN(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
14141 @item @code{DTAN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
14144 @item @emph{See also}:
14145 Inverse function: @*
14147 Degrees function: @*
14154 @section @code{TAND} --- Tangent function, degrees
14157 @cindex trigonometric function, tangent, degrees
14158 @cindex tangent, degrees
14161 @item @emph{Description}:
14162 @code{TAND(X)} computes the tangent of @var{X} in degrees.
14164 @item @emph{Standard}:
14167 @item @emph{Class}:
14170 @item @emph{Syntax}:
14171 @code{RESULT = TAND(X)}
14173 @item @emph{Arguments}:
14174 @multitable @columnfractions .15 .70
14175 @item @var{X} @tab The type shall be @code{REAL}.
14178 @item @emph{Return value}:
14179 The return value has same type and kind as @var{X}.
14181 @item @emph{Example}:
14184 real(8) :: x = 45_8
14186 end program test_tand
14189 @item @emph{Specific names}:
14190 @multitable @columnfractions .20 .23 .20 .33
14191 @headitem Name @tab Argument @tab Return type @tab Standard
14192 @item @code{TAND(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 2023
14193 @item @code{DTAND(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
14196 @item @emph{See also}:
14197 Inverse function: @*
14199 Radians function: @*
14206 @section @code{TANH} --- Hyperbolic tangent function
14209 @cindex hyperbolic tangent
14210 @cindex hyperbolic function, tangent
14211 @cindex tangent, hyperbolic
14214 @item @emph{Description}:
14215 @code{TANH(X)} computes the hyperbolic tangent of @var{X}.
14217 @item @emph{Standard}:
14218 Fortran 77 and later, for a complex argument Fortran 2008 or later
14220 @item @emph{Class}:
14223 @item @emph{Syntax}:
14226 @item @emph{Arguments}:
14227 @multitable @columnfractions .15 .70
14228 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
14231 @item @emph{Return value}:
14232 The return value has same type and kind as @var{X}. If @var{X} is
14233 complex, the imaginary part of the result is in radians. If @var{X}
14234 is @code{REAL}, the return value lies in the range
14235 @math{ - 1 \leq tanh(x) \leq 1 }.
14237 @item @emph{Example}:
14240 real(8) :: x = 2.1_8
14242 end program test_tanh
14245 @item @emph{Specific names}:
14246 @multitable @columnfractions .20 .23 .20 .33
14247 @headitem Name @tab Argument @tab Return type @tab Standard
14248 @item @code{TANH(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
14249 @item @code{DTANH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
14252 @item @emph{See also}:
14259 @section @code{THIS_IMAGE} --- Function that returns the cosubscript index of this image
14260 @fnindex THIS_IMAGE
14261 @cindex coarray, @code{THIS_IMAGE}
14262 @cindex images, index of this image
14265 @item @emph{Description}:
14266 Returns the cosubscript for this image.
14268 @item @emph{Standard}:
14269 Fortran 2008 and later. With @var{DISTANCE} argument,
14270 Technical Specification (TS) 18508 or later
14272 @item @emph{Class}:
14273 Transformational function
14275 @item @emph{Syntax}:
14276 @multitable @columnfractions .80
14277 @item @code{RESULT = THIS_IMAGE()}
14278 @item @code{RESULT = THIS_IMAGE(DISTANCE)}
14279 @item @code{RESULT = THIS_IMAGE(COARRAY [, DIM])}
14282 @item @emph{Arguments}:
14283 @multitable @columnfractions .15 .70
14284 @item @var{DISTANCE} @tab (optional, intent(in)) Nonnegative scalar integer
14285 (not permitted together with @var{COARRAY}).
14286 @item @var{COARRAY} @tab Coarray of any type (optional; if @var{DIM}
14287 present, required).
14288 @item @var{DIM} @tab default integer scalar (optional). If present,
14289 @var{DIM} shall be between one and the corank of @var{COARRAY}.
14293 @item @emph{Return value}:
14294 Default integer. If @var{COARRAY} is not present, it is scalar; if
14295 @var{DISTANCE} is not present or has value 0, its value is the image index on
14296 the invoking image for the current team, for values smaller or equal
14297 distance to the initial team, it returns the image index on the ancestor team
14298 which has a distance of @var{DISTANCE} from the invoking team. If
14299 @var{DISTANCE} is larger than the distance to the initial team, the image
14300 index of the initial team is returned. Otherwise when the @var{COARRAY} is
14301 present, if @var{DIM} is not present, a rank-1 array with corank elements is
14302 returned, containing the cosubscripts for @var{COARRAY} specifying the invoking
14303 image. If @var{DIM} is present, a scalar is returned, with the value of
14304 the @var{DIM} element of @code{THIS_IMAGE(COARRAY)}.
14306 @item @emph{Example}:
14308 INTEGER :: value[*]
14310 value = THIS_IMAGE()
14312 IF (THIS_IMAGE() == 1) THEN
14313 DO i = 1, NUM_IMAGES()
14314 WRITE(*,'(2(a,i0))') 'value[', i, '] is ', value[i]
14318 ! Check whether the current image is the initial image
14319 IF (THIS_IMAGE(HUGE(1)) /= THIS_IMAGE())
14320 error stop "something is rotten here"
14323 @item @emph{See also}:
14324 @ref{NUM_IMAGES}, @*
14331 @section @code{TIME} --- Time function
14333 @cindex time, current
14334 @cindex current time
14337 @item @emph{Description}:
14338 Returns the current time encoded as an integer (in the manner of the
14339 function @code{time(3)} in the C standard library). This value is
14340 suitable for passing to @ref{CTIME}, @ref{GMTIME}, and @ref{LTIME}.
14342 This intrinsic is not fully portable, such as to systems with 32-bit
14343 @code{INTEGER} types but supporting times wider than 32 bits. Therefore,
14344 the values returned by this intrinsic might be, or become, negative, or
14345 numerically less than previous values, during a single run of the
14348 See @ref{TIME8}, for information on a similar intrinsic that might be
14349 portable to more GNU Fortran implementations, though to fewer Fortran
14352 @item @emph{Standard}:
14355 @item @emph{Class}:
14358 @item @emph{Syntax}:
14359 @code{RESULT = TIME()}
14361 @item @emph{Return value}:
14362 The return value is a scalar of type @code{INTEGER(4)}.
14364 @item @emph{See also}:
14365 @ref{DATE_AND_TIME}, @*
14376 @section @code{TIME8} --- Time function (64-bit)
14378 @cindex time, current
14379 @cindex current time
14382 @item @emph{Description}:
14383 Returns the current time encoded as an integer (in the manner of the
14384 function @code{time(3)} in the C standard library). This value is
14385 suitable for passing to @ref{CTIME}, @ref{GMTIME}, and @ref{LTIME}.
14387 @emph{Warning:} this intrinsic does not increase the range of the timing
14388 values over that returned by @code{time(3)}. On a system with a 32-bit
14389 @code{time(3)}, @code{TIME8} will return a 32-bit value, even though
14390 it is converted to a 64-bit @code{INTEGER(8)} value. That means
14391 overflows of the 32-bit value can still occur. Therefore, the values
14392 returned by this intrinsic might be or become negative or numerically
14393 less than previous values during a single run of the compiled program.
14395 @item @emph{Standard}:
14398 @item @emph{Class}:
14401 @item @emph{Syntax}:
14402 @code{RESULT = TIME8()}
14404 @item @emph{Return value}:
14405 The return value is a scalar of type @code{INTEGER(8)}.
14407 @item @emph{See also}:
14408 @ref{DATE_AND_TIME}, @*
14419 @section @code{TINY} --- Smallest positive number of a real kind
14421 @cindex limits, smallest number
14422 @cindex model representation, smallest number
14425 @item @emph{Description}:
14426 @code{TINY(X)} returns the smallest positive (non zero) number
14427 in the model of the type of @code{X}.
14429 @item @emph{Standard}:
14430 Fortran 90 and later
14432 @item @emph{Class}:
14435 @item @emph{Syntax}:
14436 @code{RESULT = TINY(X)}
14438 @item @emph{Arguments}:
14439 @multitable @columnfractions .15 .70
14440 @item @var{X} @tab Shall be of type @code{REAL}.
14443 @item @emph{Return value}:
14444 The return value is of the same type and kind as @var{X}
14446 @item @emph{Example}:
14447 See @code{HUGE} for an example.
14453 @section @code{TRAILZ} --- Number of trailing zero bits of an integer
14458 @item @emph{Description}:
14459 @code{TRAILZ} returns the number of trailing zero bits of an integer.
14461 @item @emph{Standard}:
14462 Fortran 2008 and later
14464 @item @emph{Class}:
14467 @item @emph{Syntax}:
14468 @code{RESULT = TRAILZ(I)}
14470 @item @emph{Arguments}:
14471 @multitable @columnfractions .15 .70
14472 @item @var{I} @tab Shall be of type @code{INTEGER}.
14475 @item @emph{Return value}:
14476 The type of the return value is the default @code{INTEGER}.
14477 If all the bits of @code{I} are zero, the result value is @code{BIT_SIZE(I)}.
14479 @item @emph{Example}:
14481 PROGRAM test_trailz
14482 WRITE (*,*) TRAILZ(8) ! prints 3
14486 @item @emph{See also}:
14496 @section @code{TRANSFER} --- Transfer bit patterns
14502 @item @emph{Description}:
14503 Interprets the bitwise representation of @var{SOURCE} in memory as if it
14504 is the representation of a variable or array of the same type and type
14505 parameters as @var{MOLD}.
14507 This is approximately equivalent to the C concept of @emph{casting} one
14510 @item @emph{Standard}:
14511 Fortran 90 and later
14513 @item @emph{Class}:
14514 Transformational function
14516 @item @emph{Syntax}:
14517 @code{RESULT = TRANSFER(SOURCE, MOLD[, SIZE])}
14519 @item @emph{Arguments}:
14520 @multitable @columnfractions .15 .70
14521 @item @var{SOURCE} @tab Shall be a scalar or an array of any type.
14522 @item @var{MOLD} @tab Shall be a scalar or an array of any type.
14523 @item @var{SIZE} @tab (Optional) shall be a scalar of type
14527 @item @emph{Return value}:
14528 The result has the same type as @var{MOLD}, with the bit level
14529 representation of @var{SOURCE}. If @var{SIZE} is present, the result is
14530 a one-dimensional array of length @var{SIZE}. If @var{SIZE} is absent
14531 but @var{MOLD} is an array (of any size or shape), the result is a one-
14532 dimensional array of the minimum length needed to contain the entirety
14533 of the bitwise representation of @var{SOURCE}. If @var{SIZE} is absent
14534 and @var{MOLD} is a scalar, the result is a scalar.
14536 If the bitwise representation of the result is longer than that of
14537 @var{SOURCE}, then the leading bits of the result correspond to those of
14538 @var{SOURCE} and any trailing bits are filled arbitrarily.
14540 When the resulting bit representation does not correspond to a valid
14541 representation of a variable of the same type as @var{MOLD}, the results
14542 are undefined, and subsequent operations on the result cannot be
14543 guaranteed to produce sensible behavior. For example, it is possible to
14544 create @code{LOGICAL} variables for which @code{@var{VAR}} and
14545 @code{.NOT.@var{VAR}} both appear to be true.
14547 @item @emph{Example}:
14549 PROGRAM test_transfer
14550 integer :: x = 2143289344
14551 print *, transfer(x, 1.0) ! prints "NaN" on i686
14559 @section @code{TRANSPOSE} --- Transpose an array of rank two
14561 @cindex array, transpose
14562 @cindex matrix, transpose
14566 @item @emph{Description}:
14567 Transpose an array of rank two. Element (i, j) of the result has the value
14568 @code{MATRIX(j, i)}, for all i, j.
14570 @item @emph{Standard}:
14571 Fortran 90 and later
14573 @item @emph{Class}:
14574 Transformational function
14576 @item @emph{Syntax}:
14577 @code{RESULT = TRANSPOSE(MATRIX)}
14579 @item @emph{Arguments}:
14580 @multitable @columnfractions .15 .70
14581 @item @var{MATRIX} @tab Shall be an array of any type and have a rank of two.
14584 @item @emph{Return value}:
14585 The result has the same type as @var{MATRIX}, and has shape
14586 @code{(/ m, n /)} if @var{MATRIX} has shape @code{(/ n, m /)}.
14592 @section @code{TRIM} --- Remove trailing blank characters of a string
14594 @cindex string, remove trailing whitespace
14597 @item @emph{Description}:
14598 Removes trailing blank characters of a string.
14600 @item @emph{Standard}:
14601 Fortran 90 and later
14603 @item @emph{Class}:
14604 Transformational function
14606 @item @emph{Syntax}:
14607 @code{RESULT = TRIM(STRING)}
14609 @item @emph{Arguments}:
14610 @multitable @columnfractions .15 .70
14611 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER}.
14614 @item @emph{Return value}:
14615 A scalar of type @code{CHARACTER} which length is that of @var{STRING}
14616 less the number of trailing blanks.
14618 @item @emph{Example}:
14621 CHARACTER(len=10), PARAMETER :: s = "GFORTRAN "
14622 WRITE(*,*) LEN(s), LEN(TRIM(s)) ! "10 8", with/without trailing blanks
14626 @item @emph{See also}:
14634 @section @code{TTYNAM} --- Get the name of a terminal device
14636 @cindex system, terminal
14639 @item @emph{Description}:
14640 Get the name of a terminal device. For more information,
14641 see @code{ttyname(3)}.
14643 This intrinsic is provided in both subroutine and function forms;
14644 however, only one form can be used in any given program unit.
14646 @item @emph{Standard}:
14649 @item @emph{Class}:
14650 Subroutine, function
14652 @item @emph{Syntax}:
14653 @multitable @columnfractions .80
14654 @item @code{CALL TTYNAM(UNIT, NAME)}
14655 @item @code{NAME = TTYNAM(UNIT)}
14658 @item @emph{Arguments}:
14659 @multitable @columnfractions .15 .70
14660 @item @var{UNIT} @tab Shall be a scalar @code{INTEGER}.
14661 @item @var{NAME} @tab Shall be of type @code{CHARACTER}.
14664 @item @emph{Example}:
14666 PROGRAM test_ttynam
14669 IF (isatty(unit=unit)) write(*,*) ttynam(unit)
14674 @item @emph{See also}:
14681 @section @code{UBOUND} --- Upper dimension bounds of an array
14683 @cindex array, upper bound
14686 @item @emph{Description}:
14687 Returns the upper bounds of an array, or a single upper bound
14688 along the @var{DIM} dimension.
14689 @item @emph{Standard}:
14690 Fortran 90 and later, with @var{KIND} argument Fortran 2003 and later
14692 @item @emph{Class}:
14695 @item @emph{Syntax}:
14696 @code{RESULT = UBOUND(ARRAY [, DIM [, KIND]])}
14698 @item @emph{Arguments}:
14699 @multitable @columnfractions .15 .70
14700 @item @var{ARRAY} @tab Shall be an array, of any type.
14701 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER}.
14702 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
14703 expression indicating the kind parameter of the result.
14706 @item @emph{Return value}:
14707 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
14708 @var{KIND} is absent, the return value is of default integer kind.
14709 If @var{DIM} is absent, the result is an array of the upper bounds of
14710 @var{ARRAY}. If @var{DIM} is present, the result is a scalar
14711 corresponding to the upper bound of the array along that dimension. If
14712 @var{ARRAY} is an expression rather than a whole array or array
14713 structure component, or if it has a zero extent along the relevant
14714 dimension, the upper bound is taken to be the number of elements along
14715 the relevant dimension.
14717 @item @emph{See also}:
14725 @section @code{UCOBOUND} --- Upper codimension bounds of an array
14727 @cindex coarray, upper bound
14730 @item @emph{Description}:
14731 Returns the upper cobounds of a coarray, or a single upper cobound
14732 along the @var{DIM} codimension.
14733 @item @emph{Standard}:
14734 Fortran 2008 and later
14736 @item @emph{Class}:
14739 @item @emph{Syntax}:
14740 @code{RESULT = UCOBOUND(COARRAY [, DIM [, KIND]])}
14742 @item @emph{Arguments}:
14743 @multitable @columnfractions .15 .70
14744 @item @var{ARRAY} @tab Shall be an coarray, of any type.
14745 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER}.
14746 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
14747 expression indicating the kind parameter of the result.
14750 @item @emph{Return value}:
14751 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
14752 @var{KIND} is absent, the return value is of default integer kind.
14753 If @var{DIM} is absent, the result is an array of the lower cobounds of
14754 @var{COARRAY}. If @var{DIM} is present, the result is a scalar
14755 corresponding to the lower cobound of the array along that codimension.
14757 @item @emph{See also}:
14765 @section @code{UMASK} --- Set the file creation mask
14767 @cindex file system, file creation mask
14770 @item @emph{Description}:
14771 Sets the file creation mask to @var{MASK}. If called as a function, it
14772 returns the old value. If called as a subroutine and argument @var{OLD}
14773 if it is supplied, it is set to the old value. See @code{umask(2)}.
14775 @item @emph{Standard}:
14778 @item @emph{Class}:
14779 Subroutine, function
14781 @item @emph{Syntax}:
14782 @multitable @columnfractions .80
14783 @item @code{CALL UMASK(MASK [, OLD])}
14784 @item @code{OLD = UMASK(MASK)}
14787 @item @emph{Arguments}:
14788 @multitable @columnfractions .15 .70
14789 @item @var{MASK} @tab Shall be a scalar of type @code{INTEGER}.
14790 @item @var{OLD} @tab (Optional) Shall be a scalar of type
14799 @section @code{UNLINK} --- Remove a file from the file system
14801 @cindex file system, remove file
14804 @item @emph{Description}:
14805 Unlinks the file @var{PATH}. A null character (@code{CHAR(0)}) can be
14806 used to mark the end of the name in @var{PATH}; otherwise, trailing
14807 blanks in the file name are ignored. If the @var{STATUS} argument is
14808 supplied, it contains 0 on success or a nonzero error code upon return;
14809 see @code{unlink(2)}.
14811 This intrinsic is provided in both subroutine and function forms;
14812 however, only one form can be used in any given program unit.
14814 @item @emph{Standard}:
14817 @item @emph{Class}:
14818 Subroutine, function
14820 @item @emph{Syntax}:
14821 @multitable @columnfractions .80
14822 @item @code{CALL UNLINK(PATH [, STATUS])}
14823 @item @code{STATUS = UNLINK(PATH)}
14826 @item @emph{Arguments}:
14827 @multitable @columnfractions .15 .70
14828 @item @var{PATH} @tab Shall be of default @code{CHARACTER} type.
14829 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
14832 @item @emph{See also}:
14840 @section @code{UNPACK} --- Unpack an array of rank one into an array
14842 @cindex array, unpacking
14843 @cindex array, increase dimension
14844 @cindex array, scatter elements
14847 @item @emph{Description}:
14848 Store the elements of @var{VECTOR} in an array of higher rank.
14850 @item @emph{Standard}:
14851 Fortran 90 and later
14853 @item @emph{Class}:
14854 Transformational function
14856 @item @emph{Syntax}:
14857 @code{RESULT = UNPACK(VECTOR, MASK, FIELD)}
14859 @item @emph{Arguments}:
14860 @multitable @columnfractions .15 .70
14861 @item @var{VECTOR} @tab Shall be an array of any type and rank one. It
14862 shall have at least as many elements as @var{MASK} has @code{TRUE} values.
14863 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL}.
14864 @item @var{FIELD} @tab Shall be of the same type as @var{VECTOR} and have
14865 the same shape as @var{MASK}.
14868 @item @emph{Return value}:
14869 The resulting array corresponds to @var{FIELD} with @code{TRUE} elements
14870 of @var{MASK} replaced by values from @var{VECTOR} in array element order.
14872 @item @emph{Example}:
14874 PROGRAM test_unpack
14875 integer :: vector(2) = (/1,1/)
14876 logical :: mask(4) = (/ .TRUE., .FALSE., .FALSE., .TRUE. /)
14877 integer :: field(2,2) = 0, unity(2,2)
14879 ! result: unity matrix
14880 unity = unpack(vector, reshape(mask, (/2,2/)), field)
14884 @item @emph{See also}:
14892 @section @code{VERIFY} --- Scan a string for characters not a given set
14894 @cindex string, find missing set
14897 @item @emph{Description}:
14898 Verifies that all the characters in @var{STRING} belong to the set of
14899 characters in @var{SET}.
14901 If @var{BACK} is either absent or equals @code{FALSE}, this function
14902 returns the position of the leftmost character of @var{STRING} that is
14903 not in @var{SET}. If @var{BACK} equals @code{TRUE}, the rightmost
14904 position is returned. If all characters of @var{STRING} are found in
14905 @var{SET}, the result is zero.
14907 @item @emph{Standard}:
14908 Fortran 90 and later, with @var{KIND} argument Fortran 2003 and later
14910 @item @emph{Class}:
14913 @item @emph{Syntax}:
14914 @code{RESULT = VERIFY(STRING, SET[, BACK [, KIND]])}
14916 @item @emph{Arguments}:
14917 @multitable @columnfractions .15 .70
14918 @item @var{STRING} @tab Shall be of type @code{CHARACTER}.
14919 @item @var{SET} @tab Shall be of type @code{CHARACTER}.
14920 @item @var{BACK} @tab (Optional) shall be of type @code{LOGICAL}.
14921 @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant
14922 expression indicating the kind parameter of the result.
14925 @item @emph{Return value}:
14926 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
14927 @var{KIND} is absent, the return value is of default integer kind.
14929 @item @emph{Example}:
14931 PROGRAM test_verify
14932 WRITE(*,*) VERIFY("FORTRAN", "AO") ! 1, found 'F'
14933 WRITE(*,*) VERIFY("FORTRAN", "FOO") ! 3, found 'R'
14934 WRITE(*,*) VERIFY("FORTRAN", "C++") ! 1, found 'F'
14935 WRITE(*,*) VERIFY("FORTRAN", "C++", .TRUE.) ! 7, found 'N'
14936 WRITE(*,*) VERIFY("FORTRAN", "FORTRAN") ! 0' found none
14940 @item @emph{See also}:
14942 @ref{INDEX intrinsic}
14948 @section @code{XOR} --- Bitwise logical exclusive OR
14950 @cindex bitwise logical exclusive or
14951 @cindex logical exclusive or, bitwise
14954 @item @emph{Description}:
14955 Bitwise logical exclusive or.
14957 This intrinsic routine is provided for backwards compatibility with
14958 GNU Fortran 77. For integer arguments, programmers should consider
14959 the use of the @ref{IEOR} intrinsic and for logical arguments the
14960 @code{.NEQV.} operator, which are both defined by the Fortran standard.
14962 @item @emph{Standard}:
14965 @item @emph{Class}:
14968 @item @emph{Syntax}:
14969 @code{RESULT = XOR(I, J)}
14971 @item @emph{Arguments}:
14972 @multitable @columnfractions .15 .70
14973 @item @var{I} @tab The type shall be either a scalar @code{INTEGER}
14974 type or a scalar @code{LOGICAL} type or a boz-literal-constant.
14975 @item @var{J} @tab The type shall be the same as the type of @var{I} or
14976 a boz-literal-constant. @var{I} and @var{J} shall not both be
14977 boz-literal-constants. If either @var{I} and @var{J} is a
14978 boz-literal-constant, then the other argument must be a scalar @code{INTEGER}.
14981 @item @emph{Return value}:
14982 The return type is either a scalar @code{INTEGER} or a scalar
14983 @code{LOGICAL}. If the kind type parameters differ, then the
14984 smaller kind type is implicitly converted to larger kind, and the
14985 return has the larger kind. A boz-literal-constant is
14986 converted to an @code{INTEGER} with the kind type parameter of
14987 the other argument as-if a call to @ref{INT} occurred.
14989 @item @emph{Example}:
14992 LOGICAL :: T = .TRUE., F = .FALSE.
14994 DATA a / Z'F' /, b / Z'3' /
14996 WRITE (*,*) XOR(T, T), XOR(T, F), XOR(F, T), XOR(F, F)
14997 WRITE (*,*) XOR(a, b)
15001 @item @emph{See also}:
15002 Fortran 95 elemental function: @*
15008 @node Intrinsic Modules
15009 @chapter Intrinsic Modules
15010 @cindex intrinsic Modules
15013 * ISO_FORTRAN_ENV::
15016 * OpenMP Modules OMP_LIB and OMP_LIB_KINDS::
15017 * OpenACC Module OPENACC::
15020 @node ISO_FORTRAN_ENV
15021 @section @code{ISO_FORTRAN_ENV}
15023 @item @emph{Standard}:
15024 Fortran 2003 and later, except when otherwise noted
15027 The @code{ISO_FORTRAN_ENV} module provides the following scalar default-integer
15031 @item @code{ATOMIC_INT_KIND}:
15032 Default-kind integer constant to be used as kind parameter when defining
15033 integer variables used in atomic operations. (Fortran 2008 or later.)
15035 @item @code{ATOMIC_LOGICAL_KIND}:
15036 Default-kind integer constant to be used as kind parameter when defining
15037 logical variables used in atomic operations. (Fortran 2008 or later.)
15039 @item @code{CHARACTER_KINDS}:
15040 Default-kind integer constant array of rank one containing the supported kind
15041 parameters of the @code{CHARACTER} type. (Fortran 2008 or later.)
15043 @item @code{CHARACTER_STORAGE_SIZE}:
15044 Size in bits of the character storage unit.
15046 @item @code{ERROR_UNIT}:
15047 Identifies the preconnected unit used for error reporting.
15049 @item @code{FILE_STORAGE_SIZE}:
15050 Size in bits of the file-storage unit.
15052 @item @code{INPUT_UNIT}:
15053 Identifies the preconnected unit identified by the asterisk
15054 (@code{*}) in @code{READ} statement.
15056 @item @code{INT8}, @code{INT16}, @code{INT32}, @code{INT64}:
15057 Kind type parameters to specify an INTEGER type with a storage
15058 size of 16, 32, and 64 bits. It is negative if a target platform
15059 does not support the particular kind. (Fortran 2008 or later.)
15061 @item @code{INTEGER_KINDS}:
15062 Default-kind integer constant array of rank one containing the supported kind
15063 parameters of the @code{INTEGER} type. (Fortran 2008 or later.)
15065 @item @code{IOSTAT_END}:
15066 The value assigned to the variable passed to the @code{IOSTAT=} specifier of
15067 an input/output statement if an end-of-file condition occurred.
15069 @item @code{IOSTAT_EOR}:
15070 The value assigned to the variable passed to the @code{IOSTAT=} specifier of
15071 an input/output statement if an end-of-record condition occurred.
15073 @item @code{IOSTAT_INQUIRE_INTERNAL_UNIT}:
15074 Scalar default-integer constant, used by @code{INQUIRE} for the
15075 @code{IOSTAT=} specifier to denote an that a unit number identifies an
15076 internal unit. (Fortran 2008 or later.)
15078 @item @code{NUMERIC_STORAGE_SIZE}:
15079 The size in bits of the numeric storage unit.
15081 @item @code{LOGICAL_KINDS}:
15082 Default-kind integer constant array of rank one containing the supported kind
15083 parameters of the @code{LOGICAL} type. (Fortran 2008 or later.)
15085 @item @code{OUTPUT_UNIT}:
15086 Identifies the preconnected unit identified by the asterisk
15087 (@code{*}) in @code{WRITE} statement.
15089 @item @code{REAL32}, @code{REAL64}, @code{REAL128}:
15090 Kind type parameters to specify a REAL type with a storage
15091 size of 32, 64, and 128 bits. It is negative if a target platform
15092 does not support the particular kind. (Fortran 2008 or later.)
15094 @item @code{REAL_KINDS}:
15095 Default-kind integer constant array of rank one containing the supported kind
15096 parameters of the @code{REAL} type. (Fortran 2008 or later.)
15098 @item @code{STAT_LOCKED}:
15099 Scalar default-integer constant used as STAT= return value by @code{LOCK} to
15100 denote that the lock variable is locked by the executing image. (Fortran 2008
15103 @item @code{STAT_LOCKED_OTHER_IMAGE}:
15104 Scalar default-integer constant used as STAT= return value by @code{UNLOCK} to
15105 denote that the lock variable is locked by another image. (Fortran 2008 or
15108 @item @code{STAT_STOPPED_IMAGE}:
15109 Positive, scalar default-integer constant used as STAT= return value if the
15110 argument in the statement requires synchronisation with an image, which has
15111 initiated the termination of the execution. (Fortran 2008 or later.)
15113 @item @code{STAT_FAILED_IMAGE}:
15114 Positive, scalar default-integer constant used as STAT= return value if the
15115 argument in the statement requires communication with an image, which has
15116 is in the failed state. (TS 18508 or later.)
15118 @item @code{STAT_UNLOCKED}:
15119 Scalar default-integer constant used as STAT= return value by @code{UNLOCK} to
15120 denote that the lock variable is unlocked. (Fortran 2008 or later.)
15123 The module provides the following derived type:
15126 @item @code{LOCK_TYPE}:
15127 Derived type with private components to be use with the @code{LOCK} and
15128 @code{UNLOCK} statement. A variable of its type has to be always declared
15129 as coarray and may not appear in a variable-definition context.
15130 (Fortran 2008 or later.)
15133 The module also provides the following intrinsic procedures:
15134 @ref{COMPILER_OPTIONS} and @ref{COMPILER_VERSION}.
15138 @node ISO_C_BINDING
15139 @section @code{ISO_C_BINDING}
15141 @item @emph{Standard}:
15142 Fortran 2003 and later, GNU extensions
15145 The following intrinsic procedures are provided by the module; their
15146 definition can be found in the section Intrinsic Procedures of this
15150 @item @code{C_ASSOCIATED}
15151 @item @code{C_F_POINTER}
15152 @item @code{C_F_PROCPOINTER}
15153 @item @code{C_FUNLOC}
15155 @item @code{C_SIZEOF}
15157 @c TODO: Vertical spacing between C_FUNLOC and C_LOC wrong in PDF,
15158 @c don't really know why.
15160 The @code{ISO_C_BINDING} module provides the following named constants of
15161 type default integer, which can be used as KIND type parameters.
15163 In addition to the integer named constants required by the Fortran 2003
15164 standard and @code{C_PTRDIFF_T} of TS 29113, GNU Fortran provides as an
15165 extension named constants for the 128-bit integer types supported by the
15166 C compiler: @code{C_INT128_T, C_INT_LEAST128_T, C_INT_FAST128_T}.
15167 Furthermore, if @code{_Float128} is supported in C, the named constants
15168 @code{C_FLOAT128} and @code{C_FLOAT128_COMPLEX} are defined.
15170 @multitable @columnfractions .19 .32 .34 .15
15171 @headitem Fortran Type @tab Named constant @tab C type @tab Extension
15172 @item @code{INTEGER}@tab @code{C_INT} @tab @code{int}
15173 @item @code{INTEGER}@tab @code{C_SHORT} @tab @code{short int}
15174 @item @code{INTEGER}@tab @code{C_LONG} @tab @code{long int}
15175 @item @code{INTEGER}@tab @code{C_LONG_LONG} @tab @code{long long int}
15176 @item @code{INTEGER}@tab @code{C_SIGNED_CHAR} @tab @code{signed char}/@code{unsigned char}
15177 @item @code{INTEGER}@tab @code{C_SIZE_T} @tab @code{size_t}
15178 @item @code{INTEGER}@tab @code{C_INT8_T} @tab @code{int8_t}
15179 @item @code{INTEGER}@tab @code{C_INT16_T} @tab @code{int16_t}
15180 @item @code{INTEGER}@tab @code{C_INT32_T} @tab @code{int32_t}
15181 @item @code{INTEGER}@tab @code{C_INT64_T} @tab @code{int64_t}
15182 @item @code{INTEGER}@tab @code{C_INT128_T} @tab @code{int128_t} @tab Ext.
15183 @item @code{INTEGER}@tab @code{C_INT_LEAST8_T} @tab @code{int_least8_t}
15184 @item @code{INTEGER}@tab @code{C_INT_LEAST16_T} @tab @code{int_least16_t}
15185 @item @code{INTEGER}@tab @code{C_INT_LEAST32_T} @tab @code{int_least32_t}
15186 @item @code{INTEGER}@tab @code{C_INT_LEAST64_T} @tab @code{int_least64_t}
15187 @item @code{INTEGER}@tab @code{C_INT_LEAST128_T}@tab @code{int_least128_t} @tab Ext.
15188 @item @code{INTEGER}@tab @code{C_INT_FAST8_T} @tab @code{int_fast8_t}
15189 @item @code{INTEGER}@tab @code{C_INT_FAST16_T} @tab @code{int_fast16_t}
15190 @item @code{INTEGER}@tab @code{C_INT_FAST32_T} @tab @code{int_fast32_t}
15191 @item @code{INTEGER}@tab @code{C_INT_FAST64_T} @tab @code{int_fast64_t}
15192 @item @code{INTEGER}@tab @code{C_INT_FAST128_T} @tab @code{int_fast128_t} @tab Ext.
15193 @item @code{INTEGER}@tab @code{C_INTMAX_T} @tab @code{intmax_t}
15194 @item @code{INTEGER}@tab @code{C_INTPTR_T} @tab @code{intptr_t}
15195 @item @code{INTEGER}@tab @code{C_PTRDIFF_T} @tab @code{ptrdiff_t} @tab TS 29113
15196 @item @code{REAL} @tab @code{C_FLOAT} @tab @code{float}
15197 @item @code{REAL} @tab @code{C_DOUBLE} @tab @code{double}
15198 @item @code{REAL} @tab @code{C_LONG_DOUBLE} @tab @code{long double}
15199 @item @code{REAL} @tab @code{C_FLOAT128} @tab @code{_Float128} @tab Ext.
15200 @item @code{COMPLEX}@tab @code{C_FLOAT_COMPLEX} @tab @code{float _Complex}
15201 @item @code{COMPLEX}@tab @code{C_DOUBLE_COMPLEX}@tab @code{double _Complex}
15202 @item @code{COMPLEX}@tab @code{C_LONG_DOUBLE_COMPLEX}@tab @code{long double _Complex}
15203 @item @code{COMPLEX}@tab @code{C_FLOAT128_COMPLEX} @tab @code{_Float128 _Complex} @tab Ext.
15204 @item @code{LOGICAL}@tab @code{C_BOOL} @tab @code{_Bool}
15205 @item @code{CHARACTER}@tab @code{C_CHAR} @tab @code{char}
15208 Additionally, the following parameters of type @code{CHARACTER(KIND=C_CHAR)}
15211 @multitable @columnfractions .20 .45 .15
15212 @headitem Name @tab C definition @tab Value
15213 @item @code{C_NULL_CHAR} @tab null character @tab @code{'\0'}
15214 @item @code{C_ALERT} @tab alert @tab @code{'\a'}
15215 @item @code{C_BACKSPACE} @tab backspace @tab @code{'\b'}
15216 @item @code{C_FORM_FEED} @tab form feed @tab @code{'\f'}
15217 @item @code{C_NEW_LINE} @tab new line @tab @code{'\n'}
15218 @item @code{C_CARRIAGE_RETURN} @tab carriage return @tab @code{'\r'}
15219 @item @code{C_HORIZONTAL_TAB} @tab horizontal tab @tab @code{'\t'}
15220 @item @code{C_VERTICAL_TAB} @tab vertical tab @tab @code{'\v'}
15223 Moreover, the following two named constants are defined:
15225 @multitable @columnfractions .20 .80
15226 @headitem Name @tab Type
15227 @item @code{C_NULL_PTR} @tab @code{C_PTR}
15228 @item @code{C_NULL_FUNPTR} @tab @code{C_FUNPTR}
15231 Both are equivalent to the value @code{NULL} in C.
15236 @section IEEE modules: @code{IEEE_EXCEPTIONS}, @code{IEEE_ARITHMETIC}, and @code{IEEE_FEATURES}
15238 @item @emph{Standard}:
15239 Fortran 2003 and later
15242 The @code{IEEE_EXCEPTIONS}, @code{IEEE_ARITHMETIC}, and @code{IEEE_FEATURES}
15243 intrinsic modules provide support for exceptions and IEEE arithmetic, as
15244 defined in Fortran 2003 and later standards, and the IEC 60559:1989 standard
15245 (@emph{Binary floating-point arithmetic for microprocessor systems}). These
15246 modules are only provided on the following supported platforms:
15249 @item i386 and x86_64 processors
15250 @item platforms which use the GNU C Library (glibc)
15251 @item platforms with support for SysV/386 routines for floating point
15252 interface (including Solaris and BSDs)
15253 @item platforms with the AIX OS
15256 For full compliance with the Fortran standards, code using the
15257 @code{IEEE_EXCEPTIONS} or @code{IEEE_ARITHMETIC} modules should be compiled
15258 with the following options: @code{-fno-unsafe-math-optimizations
15259 -frounding-math -fsignaling-nans}.
15263 @node OpenMP Modules OMP_LIB and OMP_LIB_KINDS
15264 @section OpenMP Modules @code{OMP_LIB} and @code{OMP_LIB_KINDS}
15266 @item @emph{Standard}:
15267 OpenMP Application Program Interface v4.5,
15268 OpenMP Application Program Interface v5.0 (partially supported),
15269 OpenMP Application Program Interface v5.1 (partially supported) and
15270 OpenMP Application Program Interface v5.2 (partially supported).
15273 The OpenMP Fortran runtime library routines are provided both in
15274 a form of two Fortran modules, named @code{OMP_LIB} and
15275 @code{OMP_LIB_KINDS}, and in a form of a Fortran @code{include} file named
15276 @file{omp_lib.h}. The procedures provided by @code{OMP_LIB} can be found
15277 in the @ref{Top,,Introduction,libgomp,GNU Offloading and Multi
15278 Processing Runtime Library} manual,
15279 the named constants defined in the modules are listed
15282 For details refer to the actual
15283 @uref{https://www.openmp.org/wp-content/uploads/openmp-4.5.pdf,
15284 OpenMP Application Program Interface v4.5},
15285 @uref{https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5.0.pdf,
15286 OpenMP Application Program Interface v5.0},
15287 @uref{https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5-1.pdf,
15288 OpenMP Application Program Interface v5.1} and
15289 @uref{https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5-2.pdf,
15290 OpenMP Application Program Interface v5.2}.
15292 @code{OMP_LIB_KINDS} provides the following scalar default-integer
15296 @item @code{omp_allocator_handle_kind}
15297 @item @code{omp_alloctrait_key_kind}
15298 @item @code{omp_alloctrait_val_kind}
15299 @item @code{omp_depend_kind}
15300 @item @code{omp_lock_kind}
15301 @item @code{omp_lock_hint_kind}
15302 @item @code{omp_nest_lock_kind}
15303 @item @code{omp_pause_resource_kind}
15304 @item @code{omp_memspace_handle_kind}
15305 @item @code{omp_proc_bind_kind}
15306 @item @code{omp_sched_kind}
15307 @item @code{omp_sync_hint_kind}
15310 @code{OMP_LIB} provides the scalar default-integer
15311 named constant @code{openmp_version} with a value of the form
15312 @var{yyyymm}, where @code{yyyy} is the year and @var{mm} the month
15313 of the OpenMP version; for OpenMP v4.5 the value is @code{201511}.
15315 The following derived type:
15318 @item @code{omp_alloctrait}
15321 The following scalar default-integer named constants:
15323 @item @code{omp_initial_device}
15324 @item @code{omp_invalid_device}
15328 The following scalar integer named constants of the
15329 kind @code{omp_sched_kind}:
15332 @item @code{omp_sched_static}
15333 @item @code{omp_sched_dynamic}
15334 @item @code{omp_sched_guided}
15335 @item @code{omp_sched_auto}
15338 And the following scalar integer named constants of the
15339 kind @code{omp_proc_bind_kind}:
15342 @item @code{omp_proc_bind_false}
15343 @item @code{omp_proc_bind_true}
15344 @item @code{omp_proc_bind_primary}
15345 @item @code{omp_proc_bind_master}
15346 @item @code{omp_proc_bind_close}
15347 @item @code{omp_proc_bind_spread}
15350 The following scalar integer named constants are of the
15351 kind @code{omp_lock_hint_kind}:
15354 @item @code{omp_lock_hint_none}
15355 @item @code{omp_lock_hint_uncontended}
15356 @item @code{omp_lock_hint_contended}
15357 @item @code{omp_lock_hint_nonspeculative}
15358 @item @code{omp_lock_hint_speculative}
15359 @item @code{omp_sync_hint_none}
15360 @item @code{omp_sync_hint_uncontended}
15361 @item @code{omp_sync_hint_contended}
15362 @item @code{omp_sync_hint_nonspeculative}
15363 @item @code{omp_sync_hint_speculative}
15366 And the following two scalar integer named constants are of the
15367 kind @code{omp_pause_resource_kind}:
15370 @item @code{omp_pause_soft}
15371 @item @code{omp_pause_hard}
15374 The following scalar integer named constants are of the kind
15375 @code{omp_alloctrait_key_kind}:
15378 @item @code{omp_atk_sync_hint}
15379 @item @code{omp_atk_alignment}
15380 @item @code{omp_atk_access}
15381 @item @code{omp_atk_pool_size}
15382 @item @code{omp_atk_fallback}
15383 @item @code{omp_atk_fb_data}
15384 @item @code{omp_atk_pinned}
15385 @item @code{omp_atk_partition}
15388 The following scalar integer named constants are of the kind
15389 @code{omp_alloctrait_val_kind}:
15392 @code{omp_alloctrait_key_kind}:
15393 @item @code{omp_atv_default}
15394 @item @code{omp_atv_false}
15395 @item @code{omp_atv_true}
15396 @item @code{omp_atv_contended}
15397 @item @code{omp_atv_uncontended}
15398 @item @code{omp_atv_serialized}
15399 @item @code{omp_atv_sequential}
15400 @item @code{omp_atv_private}
15401 @item @code{omp_atv_all}
15402 @item @code{omp_atv_thread}
15403 @item @code{omp_atv_pteam}
15404 @item @code{omp_atv_cgroup}
15405 @item @code{omp_atv_default_mem_fb}
15406 @item @code{omp_atv_null_fb}
15407 @item @code{omp_atv_abort_fb}
15408 @item @code{omp_atv_allocator_fb}
15409 @item @code{omp_atv_environment}
15410 @item @code{omp_atv_nearest}
15411 @item @code{omp_atv_blocked}
15414 The following scalar integer named constants are of the kind
15415 @code{omp_allocator_handle_kind}:
15418 @item @code{omp_null_allocator}
15419 @item @code{omp_default_mem_alloc}
15420 @item @code{omp_large_cap_mem_alloc}
15421 @item @code{omp_const_mem_alloc}
15422 @item @code{omp_high_bw_mem_alloc}
15423 @item @code{omp_low_lat_mem_alloc}
15424 @item @code{omp_cgroup_mem_alloc}
15425 @item @code{omp_pteam_mem_alloc}
15426 @item @code{omp_thread_mem_alloc}
15429 The following scalar integer named constants are of the kind
15430 @code{omp_memspace_handle_kind}:
15433 @item @code{omp_default_mem_space}
15434 @item @code{omp_large_cap_mem_space}
15435 @item @code{omp_const_mem_space}
15436 @item @code{omp_high_bw_mem_space}
15437 @item @code{omp_low_lat_mem_space}
15442 @node OpenACC Module OPENACC
15443 @section OpenACC Module @code{OPENACC}
15445 @item @emph{Standard}:
15446 OpenACC Application Programming Interface v2.6
15450 The OpenACC Fortran runtime library routines are provided both in a
15451 form of a Fortran 90 module, named @code{OPENACC}, and in form of a
15452 Fortran @code{include} file named @file{openacc_lib.h}. The
15453 procedures provided by @code{OPENACC} can be found in the
15454 @ref{Top,,Introduction,libgomp,GNU Offloading and Multi Processing
15455 Runtime Library} manual, the named constants defined in the modules
15458 For details refer to the actual
15459 @uref{https://www.openacc.org/,
15460 OpenACC Application Programming Interface v2.6}.
15462 @code{OPENACC} provides the scalar default-integer
15463 named constant @code{openacc_version} with a value of the form
15464 @var{yyyymm}, where @code{yyyy} is the year and @var{mm} the month
15465 of the OpenACC version; for OpenACC v2.6 the value is @code{201711}.