2 Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 This is part of the GNU Fortran manual.
5 For copying conditions, see the file gfortran.texi.
7 Permission is granted to copy, distribute and/or modify this document
8 under the terms of the GNU Free Documentation License, Version 1.2 or
9 any later version published by the Free Software Foundation; with the
10 Invariant Sections being ``Funding Free Software'', the Front-Cover
11 Texts being (a) (see below), and with the Back-Cover Texts being (b)
12 (see below). A copy of the license is included in the gfdl(7) man page.
15 Some basic guidelines for editing this document:
17 (1) The intrinsic procedures are to be listed in alphabetical order.
18 (2) The generic name is to be used.
19 (3) The specific names are included in the function index and in a
20 table at the end of the node (See ABS entry).
21 (4) Try to maintain the same style for each entry.
27 \gdef\acos{\mathop{\rm acos}\nolimits}
28 \gdef\asin{\mathop{\rm asin}\nolimits}
29 \gdef\atan{\mathop{\rm atan}\nolimits}
30 \gdef\acosh{\mathop{\rm acosh}\nolimits}
31 \gdef\asinh{\mathop{\rm asinh}\nolimits}
32 \gdef\atanh{\mathop{\rm atanh}\nolimits}
36 @node Intrinsic Procedures
37 @chapter Intrinsic Procedures
38 @cindex intrinsic procedures
41 * Introduction: Introduction to Intrinsics
42 * @code{ABORT}: ABORT, Abort the program
43 * @code{ABS}: ABS, Absolute value
44 * @code{ACCESS}: ACCESS, Checks file access modes
45 * @code{ACHAR}: ACHAR, Character in @acronym{ASCII} collating sequence
46 * @code{ACOS}: ACOS, Arccosine function
47 * @code{ACOSH}: ACOSH, Hyperbolic arccosine function
48 * @code{ADJUSTL}: ADJUSTL, Left adjust a string
49 * @code{ADJUSTR}: ADJUSTR, Right adjust a string
50 * @code{AIMAG}: AIMAG, Imaginary part of complex number
51 * @code{AINT}: AINT, Truncate to a whole number
52 * @code{ALARM}: ALARM, Set an alarm clock
53 * @code{ALL}: ALL, Determine if all values are true
54 * @code{ALLOCATED}: ALLOCATED, Status of allocatable entity
55 * @code{AND}: AND, Bitwise logical AND
56 * @code{ANINT}: ANINT, Nearest whole number
57 * @code{ANY}: ANY, Determine if any values are true
58 * @code{ASIN}: ASIN, Arcsine function
59 * @code{ASINH}: ASINH, Hyperbolic arcsine function
60 * @code{ASSOCIATED}: ASSOCIATED, Status of a pointer or pointer/target pair
61 * @code{ATAN}: ATAN, Arctangent function
62 * @code{ATAN2}: ATAN2, Arctangent function
63 * @code{ATANH}: ATANH, Hyperbolic arctangent function
64 * @code{BESSEL_J0}: BESSEL_J0, Bessel function of the first kind of order 0
65 * @code{BESSEL_J1}: BESSEL_J1, Bessel function of the first kind of order 1
66 * @code{BESSEL_JN}: BESSEL_JN, Bessel function of the first kind
67 * @code{BESSEL_Y0}: BESSEL_Y0, Bessel function of the second kind of order 0
68 * @code{BESSEL_Y1}: BESSEL_Y1, Bessel function of the second kind of order 1
69 * @code{BESSEL_YN}: BESSEL_YN, Bessel function of the second kind
70 * @code{BIT_SIZE}: BIT_SIZE, Bit size inquiry function
71 * @code{BTEST}: BTEST, Bit test function
72 * @code{C_ASSOCIATED}: C_ASSOCIATED, Status of a C pointer
73 * @code{C_F_POINTER}: C_F_POINTER, Convert C into Fortran pointer
74 * @code{C_F_PROCPOINTER}: C_F_PROCPOINTER, Convert C into Fortran procedure pointer
75 * @code{C_FUNLOC}: C_FUNLOC, Obtain the C address of a procedure
76 * @code{C_LOC}: C_LOC, Obtain the C address of an object
77 * @code{C_SIZEOF}: C_SIZEOF, Size in bytes of an expression
78 * @code{CEILING}: CEILING, Integer ceiling function
79 * @code{CHAR}: CHAR, Integer-to-character conversion function
80 * @code{CHDIR}: CHDIR, Change working directory
81 * @code{CHMOD}: CHMOD, Change access permissions of files
82 * @code{CMPLX}: CMPLX, Complex conversion function
83 * @code{COMMAND_ARGUMENT_COUNT}: COMMAND_ARGUMENT_COUNT, Get number of command line arguments
84 * @code{COMPLEX}: COMPLEX, Complex conversion function
85 * @code{CONJG}: CONJG, Complex conjugate function
86 * @code{COS}: COS, Cosine function
87 * @code{COSH}: COSH, Hyperbolic cosine function
88 * @code{COUNT}: COUNT, Count occurrences of TRUE in an array
89 * @code{CPU_TIME}: CPU_TIME, CPU time subroutine
90 * @code{CSHIFT}: CSHIFT, Circular shift elements of an array
91 * @code{CTIME}: CTIME, Subroutine (or function) to convert a time into a string
92 * @code{DATE_AND_TIME}: DATE_AND_TIME, Date and time subroutine
93 * @code{DBLE}: DBLE, Double precision conversion function
94 * @code{DCMPLX}: DCMPLX, Double complex conversion function
95 * @code{DFLOAT}: DFLOAT, Double precision conversion function
96 * @code{DIGITS}: DIGITS, Significant digits function
97 * @code{DIM}: DIM, Positive difference
98 * @code{DOT_PRODUCT}: DOT_PRODUCT, Dot product function
99 * @code{DPROD}: DPROD, Double product function
100 * @code{DREAL}: DREAL, Double real part function
101 * @code{DTIME}: DTIME, Execution time subroutine (or function)
102 * @code{EOSHIFT}: EOSHIFT, End-off shift elements of an array
103 * @code{EPSILON}: EPSILON, Epsilon function
104 * @code{ERF}: ERF, Error function
105 * @code{ERFC}: ERFC, Complementary error function
106 * @code{ERFC_SCALED}: ERFC_SCALED, Exponentially-scaled complementary error function
107 * @code{ETIME}: ETIME, Execution time subroutine (or function)
108 * @code{EXIT}: EXIT, Exit the program with status.
109 * @code{EXP}: EXP, Exponential function
110 * @code{EXPONENT}: EXPONENT, Exponent function
111 * @code{FDATE}: FDATE, Subroutine (or function) to get the current time as a string
112 * @code{FGET}: FGET, Read a single character in stream mode from stdin
113 * @code{FGETC}: FGETC, Read a single character in stream mode
114 * @code{FLOAT}: FLOAT, Convert integer to default real
115 * @code{FLOOR}: FLOOR, Integer floor function
116 * @code{FLUSH}: FLUSH, Flush I/O unit(s)
117 * @code{FNUM}: FNUM, File number function
118 * @code{FPUT}: FPUT, Write a single character in stream mode to stdout
119 * @code{FPUTC}: FPUTC, Write a single character in stream mode
120 * @code{FRACTION}: FRACTION, Fractional part of the model representation
121 * @code{FREE}: FREE, Memory de-allocation subroutine
122 * @code{FSEEK}: FSEEK, Low level file positioning subroutine
123 * @code{FSTAT}: FSTAT, Get file status
124 * @code{FTELL}: FTELL, Current stream position
125 * @code{GAMMA}: GAMMA, Gamma function
126 * @code{GERROR}: GERROR, Get last system error message
127 * @code{GETARG}: GETARG, Get command line arguments
128 * @code{GET_COMMAND}: GET_COMMAND, Get the entire command line
129 * @code{GET_COMMAND_ARGUMENT}: GET_COMMAND_ARGUMENT, Get command line arguments
130 * @code{GETCWD}: GETCWD, Get current working directory
131 * @code{GETENV}: GETENV, Get an environmental variable
132 * @code{GET_ENVIRONMENT_VARIABLE}: GET_ENVIRONMENT_VARIABLE, Get an environmental variable
133 * @code{GETGID}: GETGID, Group ID function
134 * @code{GETLOG}: GETLOG, Get login name
135 * @code{GETPID}: GETPID, Process ID function
136 * @code{GETUID}: GETUID, User ID function
137 * @code{GMTIME}: GMTIME, Convert time to GMT info
138 * @code{HOSTNM}: HOSTNM, Get system host name
139 * @code{HUGE}: HUGE, Largest number of a kind
140 * @code{HYPOT}: HYPOT, Euclidian distance function
141 * @code{IACHAR}: IACHAR, Code in @acronym{ASCII} collating sequence
142 * @code{IAND}: IAND, Bitwise logical and
143 * @code{IARGC}: IARGC, Get the number of command line arguments
144 * @code{IBCLR}: IBCLR, Clear bit
145 * @code{IBITS}: IBITS, Bit extraction
146 * @code{IBSET}: IBSET, Set bit
147 * @code{ICHAR}: ICHAR, Character-to-integer conversion function
148 * @code{IDATE}: IDATE, Current local time (day/month/year)
149 * @code{IEOR}: IEOR, Bitwise logical exclusive or
150 * @code{IERRNO}: IERRNO, Function to get the last system error number
151 * @code{INDEX}: INDEX intrinsic, Position of a substring within a string
152 * @code{INT}: INT, Convert to integer type
153 * @code{INT2}: INT2, Convert to 16-bit integer type
154 * @code{INT8}: INT8, Convert to 64-bit integer type
155 * @code{IOR}: IOR, Bitwise logical or
156 * @code{IRAND}: IRAND, Integer pseudo-random number
157 * @code{IMAGE_INDEX}: IMAGE_INDEX, Cosubscript to image index convertion
158 * @code{IS_IOSTAT_END}: IS_IOSTAT_END, Test for end-of-file value
159 * @code{IS_IOSTAT_EOR}: IS_IOSTAT_EOR, Test for end-of-record value
160 * @code{ISATTY}: ISATTY, Whether a unit is a terminal device
161 * @code{ISHFT}: ISHFT, Shift bits
162 * @code{ISHFTC}: ISHFTC, Shift bits circularly
163 * @code{ISNAN}: ISNAN, Tests for a NaN
164 * @code{ITIME}: ITIME, Current local time (hour/minutes/seconds)
165 * @code{KILL}: KILL, Send a signal to a process
166 * @code{KIND}: KIND, Kind of an entity
167 * @code{LBOUND}: LBOUND, Lower dimension bounds of an array
168 * @code{LCOBOUND}: LCOBOUND, Lower codimension bounds of an array
169 * @code{LEADZ}: LEADZ, Number of leading zero bits of an integer
170 * @code{LEN}: LEN, Length of a character entity
171 * @code{LEN_TRIM}: LEN_TRIM, Length of a character entity without trailing blank characters
172 * @code{LGE}: LGE, Lexical greater than or equal
173 * @code{LGT}: LGT, Lexical greater than
174 * @code{LINK}: LINK, Create a hard link
175 * @code{LLE}: LLE, Lexical less than or equal
176 * @code{LLT}: LLT, Lexical less than
177 * @code{LNBLNK}: LNBLNK, Index of the last non-blank character in a string
178 * @code{LOC}: LOC, Returns the address of a variable
179 * @code{LOG}: LOG, Logarithm function
180 * @code{LOG10}: LOG10, Base 10 logarithm function
181 * @code{LOG_GAMMA}: LOG_GAMMA, Logarithm of the Gamma function
182 * @code{LOGICAL}: LOGICAL, Convert to logical type
183 * @code{LONG}: LONG, Convert to integer type
184 * @code{LSHIFT}: LSHIFT, Left shift bits
185 * @code{LSTAT}: LSTAT, Get file status
186 * @code{LTIME}: LTIME, Convert time to local time info
187 * @code{MALLOC}: MALLOC, Dynamic memory allocation function
188 * @code{MATMUL}: MATMUL, matrix multiplication
189 * @code{MAX}: MAX, Maximum value of an argument list
190 * @code{MAXEXPONENT}: MAXEXPONENT, Maximum exponent of a real kind
191 * @code{MAXLOC}: MAXLOC, Location of the maximum value within an array
192 * @code{MAXVAL}: MAXVAL, Maximum value of an array
193 * @code{MCLOCK}: MCLOCK, Time function
194 * @code{MCLOCK8}: MCLOCK8, Time function (64-bit)
195 * @code{MERGE}: MERGE, Merge arrays
196 * @code{MIN}: MIN, Minimum value of an argument list
197 * @code{MINEXPONENT}: MINEXPONENT, Minimum exponent of a real kind
198 * @code{MINLOC}: MINLOC, Location of the minimum value within an array
199 * @code{MINVAL}: MINVAL, Minimum value of an array
200 * @code{MOD}: MOD, Remainder function
201 * @code{MODULO}: MODULO, Modulo function
202 * @code{MOVE_ALLOC}: MOVE_ALLOC, Move allocation from one object to another
203 * @code{MVBITS}: MVBITS, Move bits from one integer to another
204 * @code{NEAREST}: NEAREST, Nearest representable number
205 * @code{NEW_LINE}: NEW_LINE, New line character
206 * @code{NINT}: NINT, Nearest whole number
207 * @code{NOT}: NOT, Logical negation
208 * @code{NULL}: NULL, Function that returns an disassociated pointer
209 * @code{NUM_IMAGES}: NUM_IMAGES, Number of images
210 * @code{OR}: OR, Bitwise logical OR
211 * @code{PACK}: PACK, Pack an array into an array of rank one
212 * @code{PERROR}: PERROR, Print system error message
213 * @code{PRECISION}: PRECISION, Decimal precision of a real kind
214 * @code{PRESENT}: PRESENT, Determine whether an optional dummy argument is specified
215 * @code{PRODUCT}: PRODUCT, Product of array elements
216 * @code{RADIX}: RADIX, Base of a data model
217 * @code{RANDOM_NUMBER}: RANDOM_NUMBER, Pseudo-random number
218 * @code{RANDOM_SEED}: RANDOM_SEED, Initialize a pseudo-random number sequence
219 * @code{RAND}: RAND, Real pseudo-random number
220 * @code{RANGE}: RANGE, Decimal exponent range
221 * @code{RAN}: RAN, Real pseudo-random number
222 * @code{REAL}: REAL, Convert to real type
223 * @code{RENAME}: RENAME, Rename a file
224 * @code{REPEAT}: REPEAT, Repeated string concatenation
225 * @code{RESHAPE}: RESHAPE, Function to reshape an array
226 * @code{RRSPACING}: RRSPACING, Reciprocal of the relative spacing
227 * @code{RSHIFT}: RSHIFT, Right shift bits
228 * @code{SCALE}: SCALE, Scale a real value
229 * @code{SCAN}: SCAN, Scan a string for the presence of a set of characters
230 * @code{SECNDS}: SECNDS, Time function
231 * @code{SECOND}: SECOND, CPU time function
232 * @code{SELECTED_CHAR_KIND}: SELECTED_CHAR_KIND, Choose character kind
233 * @code{SELECTED_INT_KIND}: SELECTED_INT_KIND, Choose integer kind
234 * @code{SELECTED_REAL_KIND}: SELECTED_REAL_KIND, Choose real kind
235 * @code{SET_EXPONENT}: SET_EXPONENT, Set the exponent of the model
236 * @code{SHAPE}: SHAPE, Determine the shape of an array
237 * @code{SIGN}: SIGN, Sign copying function
238 * @code{SIGNAL}: SIGNAL, Signal handling subroutine (or function)
239 * @code{SIN}: SIN, Sine function
240 * @code{SINH}: SINH, Hyperbolic sine function
241 * @code{SIZE}: SIZE, Function to determine the size of an array
242 * @code{SIZEOF}: SIZEOF, Determine the size in bytes of an expression
243 * @code{SLEEP}: SLEEP, Sleep for the specified number of seconds
244 * @code{SNGL}: SNGL, Convert double precision real to default real
245 * @code{SPACING}: SPACING, Smallest distance between two numbers of a given type
246 * @code{SPREAD}: SPREAD, Add a dimension to an array
247 * @code{SQRT}: SQRT, Square-root function
248 * @code{SRAND}: SRAND, Reinitialize the random number generator
249 * @code{STAT}: STAT, Get file status
250 * @code{SUM}: SUM, Sum of array elements
251 * @code{SYMLNK}: SYMLNK, Create a symbolic link
252 * @code{SYSTEM}: SYSTEM, Execute a shell command
253 * @code{SYSTEM_CLOCK}: SYSTEM_CLOCK, Time function
254 * @code{TAN}: TAN, Tangent function
255 * @code{TANH}: TANH, Hyperbolic tangent function
256 * @code{THIS_IMAGE}: THIS_IMAGE, Cosubscript index of this image
257 * @code{TIME}: TIME, Time function
258 * @code{TIME8}: TIME8, Time function (64-bit)
259 * @code{TINY}: TINY, Smallest positive number of a real kind
260 * @code{TRAILZ}: TRAILZ, Number of trailing zero bits of an integer
261 * @code{TRANSFER}: TRANSFER, Transfer bit patterns
262 * @code{TRANSPOSE}: TRANSPOSE, Transpose an array of rank two
263 * @code{TRIM}: TRIM, Remove trailing blank characters of a string
264 * @code{TTYNAM}: TTYNAM, Get the name of a terminal device.
265 * @code{UBOUND}: UBOUND, Upper dimension bounds of an array
266 * @code{UCOBOUND}: UCOBOUND, Upper codimension bounds of an array
267 * @code{UMASK}: UMASK, Set the file creation mask
268 * @code{UNLINK}: UNLINK, Remove a file from the file system
269 * @code{UNPACK}: UNPACK, Unpack an array of rank one into an array
270 * @code{VERIFY}: VERIFY, Scan a string for the absence of a set of characters
271 * @code{XOR}: XOR, Bitwise logical exclusive or
274 @node Introduction to Intrinsics
275 @section Introduction to intrinsic procedures
277 The intrinsic procedures provided by GNU Fortran include all of the
278 intrinsic procedures required by the Fortran 95 standard, a set of
279 intrinsic procedures for backwards compatibility with G77, and a
280 selection of intrinsic procedures from the Fortran 2003 and Fortran 2008
281 standards. Any conflict between a description here and a description in
282 either the Fortran 95 standard, the Fortran 2003 standard or the Fortran
283 2008 standard is unintentional, and the standard(s) should be considered
286 The enumeration of the @code{KIND} type parameter is processor defined in
287 the Fortran 95 standard. GNU Fortran defines the default integer type and
288 default real type by @code{INTEGER(KIND=4)} and @code{REAL(KIND=4)},
289 respectively. The standard mandates that both data types shall have
290 another kind, which have more precision. On typical target architectures
291 supported by @command{gfortran}, this kind type parameter is @code{KIND=8}.
292 Hence, @code{REAL(KIND=8)} and @code{DOUBLE PRECISION} are equivalent.
293 In the description of generic intrinsic procedures, the kind type parameter
294 will be specified by @code{KIND=*}, and in the description of specific
295 names for an intrinsic procedure the kind type parameter will be explicitly
296 given (e.g., @code{REAL(KIND=4)} or @code{REAL(KIND=8)}). Finally, for
297 brevity the optional @code{KIND=} syntax will be omitted.
299 Many of the intrinsic procedures take one or more optional arguments.
300 This document follows the convention used in the Fortran 95 standard,
301 and denotes such arguments by square brackets.
303 GNU Fortran offers the @option{-std=f95} and @option{-std=gnu} options,
304 which can be used to restrict the set of intrinsic procedures to a
305 given standard. By default, @command{gfortran} sets the @option{-std=gnu}
306 option, and so all intrinsic procedures described here are accepted. There
307 is one caveat. For a select group of intrinsic procedures, @command{g77}
308 implemented both a function and a subroutine. Both classes
309 have been implemented in @command{gfortran} for backwards compatibility
310 with @command{g77}. It is noted here that these functions and subroutines
311 cannot be intermixed in a given subprogram. In the descriptions that follow,
312 the applicable standard for each intrinsic procedure is noted.
317 @section @code{ABORT} --- Abort the program
319 @cindex program termination, with core dump
320 @cindex terminate program, with core dump
324 @item @emph{Description}:
325 @code{ABORT} causes immediate termination of the program. On operating
326 systems that support a core dump, @code{ABORT} will produce a core dump even if
327 the option @option{-fno-dump-core} is in effect, which is suitable for debugging
329 @c TODO: Check if this (with -fno-dump-core) is correct.
331 @item @emph{Standard}:
340 @item @emph{Return value}:
343 @item @emph{Example}:
346 integer :: i = 1, j = 2
347 if (i /= j) call abort
348 end program test_abort
351 @item @emph{See also}:
352 @ref{EXIT}, @ref{KILL}
359 @section @code{ABS} --- Absolute value
366 @cindex absolute value
369 @item @emph{Description}:
370 @code{ABS(A)} computes the absolute value of @code{A}.
372 @item @emph{Standard}:
373 Fortran 77 and later, has overloads that are GNU extensions
379 @code{RESULT = ABS(A)}
381 @item @emph{Arguments}:
382 @multitable @columnfractions .15 .70
383 @item @var{A} @tab The type of the argument shall be an @code{INTEGER},
384 @code{REAL}, or @code{COMPLEX}.
387 @item @emph{Return value}:
388 The return value is of the same type and
389 kind as the argument except the return value is @code{REAL} for a
390 @code{COMPLEX} argument.
392 @item @emph{Example}:
397 complex :: z = (-1.e0,0.e0)
404 @item @emph{Specific names}:
405 @multitable @columnfractions .20 .20 .20 .25
406 @item Name @tab Argument @tab Return type @tab Standard
407 @item @code{CABS(A)} @tab @code{COMPLEX(4) Z} @tab @code{REAL(4)} @tab Fortran 77 and later
408 @item @code{DABS(A)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
409 @item @code{IABS(A)} @tab @code{INTEGER(4) I} @tab @code{INTEGER(4)} @tab Fortran 77 and later
410 @item @code{ZABS(A)} @tab @code{COMPLEX(8) Z} @tab @code{COMPLEX(8)} @tab GNU extension
411 @item @code{CDABS(A)} @tab @code{COMPLEX(8) Z} @tab @code{COMPLEX(8)} @tab GNU extension
418 @section @code{ACCESS} --- Checks file access modes
420 @cindex file system, access mode
423 @item @emph{Description}:
424 @code{ACCESS(NAME, MODE)} checks whether the file @var{NAME}
425 exists, is readable, writable or executable. Except for the
426 executable check, @code{ACCESS} can be replaced by
427 Fortran 95's @code{INQUIRE}.
429 @item @emph{Standard}:
436 @code{RESULT = ACCESS(NAME, MODE)}
438 @item @emph{Arguments}:
439 @multitable @columnfractions .15 .70
440 @item @var{NAME} @tab Scalar @code{CHARACTER} of default kind with the
441 file name. Tailing blank are ignored unless the character @code{achar(0)}
442 is present, then all characters up to and excluding @code{achar(0)} are
444 @item @var{MODE} @tab Scalar @code{CHARACTER} of default kind with the
445 file access mode, may be any concatenation of @code{"r"} (readable),
446 @code{"w"} (writable) and @code{"x"} (executable), or @code{" "} to check
450 @item @emph{Return value}:
451 Returns a scalar @code{INTEGER}, which is @code{0} if the file is
452 accessible in the given mode; otherwise or if an invalid argument
453 has been given for @code{MODE} the value @code{1} is returned.
455 @item @emph{Example}:
459 character(len=*), parameter :: file = 'test.dat'
460 character(len=*), parameter :: file2 = 'test.dat '//achar(0)
461 if(access(file,' ') == 0) print *, trim(file),' is exists'
462 if(access(file,'r') == 0) print *, trim(file),' is readable'
463 if(access(file,'w') == 0) print *, trim(file),' is writable'
464 if(access(file,'x') == 0) print *, trim(file),' is executable'
465 if(access(file2,'rwx') == 0) &
466 print *, trim(file2),' is readable, writable and executable'
467 end program access_test
469 @item @emph{Specific names}:
470 @item @emph{See also}:
477 @section @code{ACHAR} --- Character in @acronym{ASCII} collating sequence
479 @cindex @acronym{ASCII} collating sequence
480 @cindex collating sequence, @acronym{ASCII}
483 @item @emph{Description}:
484 @code{ACHAR(I)} returns the character located at position @code{I}
485 in the @acronym{ASCII} collating sequence.
487 @item @emph{Standard}:
488 Fortran 77 and later, with @var{KIND} argument Fortran 2003 and later
494 @code{RESULT = ACHAR(I [, KIND])}
496 @item @emph{Arguments}:
497 @multitable @columnfractions .15 .70
498 @item @var{I} @tab The type shall be @code{INTEGER}.
499 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
500 expression indicating the kind parameter of the result.
503 @item @emph{Return value}:
504 The return value is of type @code{CHARACTER} with a length of one.
505 If the @var{KIND} argument is present, the return value is of the
506 specified kind and of the default kind otherwise.
508 @item @emph{Example}:
513 end program test_achar
517 See @ref{ICHAR} for a discussion of converting between numerical values
518 and formatted string representations.
520 @item @emph{See also}:
521 @ref{CHAR}, @ref{IACHAR}, @ref{ICHAR}
528 @section @code{ACOS} --- Arccosine function
531 @cindex trigonometric function, cosine, inverse
532 @cindex cosine, inverse
535 @item @emph{Description}:
536 @code{ACOS(X)} computes the arccosine of @var{X} (inverse of @code{COS(X)}).
538 @item @emph{Standard}:
539 Fortran 77 and later, for a complex argument Fortran 2008 or later
545 @code{RESULT = ACOS(X)}
547 @item @emph{Arguments}:
548 @multitable @columnfractions .15 .70
549 @item @var{X} @tab The type shall either be @code{REAL} with a magnitude that is
550 less than or equal to one - or the type shall be @code{COMPLEX}.
553 @item @emph{Return value}:
554 The return value is of the same type and kind as @var{X}.
555 The real part of the result is in radians and lies in the range
556 @math{0 \leq \Re \acos(x) \leq \pi}.
558 @item @emph{Example}:
561 real(8) :: x = 0.866_8
563 end program test_acos
566 @item @emph{Specific names}:
567 @multitable @columnfractions .20 .20 .20 .25
568 @item Name @tab Argument @tab Return type @tab Standard
569 @item @code{DACOS(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
572 @item @emph{See also}:
573 Inverse function: @ref{COS}
580 @section @code{ACOSH} --- Hyperbolic arccosine function
583 @cindex area hyperbolic cosine
584 @cindex hyperbolic arccosine
585 @cindex hyperbolic function, cosine, inverse
586 @cindex cosine, hyperbolic, inverse
589 @item @emph{Description}:
590 @code{ACOSH(X)} computes the hyperbolic arccosine of @var{X} (inverse of
593 @item @emph{Standard}:
594 Fortran 2008 and later
600 @code{RESULT = ACOSH(X)}
602 @item @emph{Arguments}:
603 @multitable @columnfractions .15 .70
604 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
607 @item @emph{Return value}:
608 The return value has the same type and kind as @var{X}. If @var{X} is
609 complex, the imaginary part of the result is in radians and lies between
610 @math{ 0 \leq \Im \acosh(x) \leq \pi}.
612 @item @emph{Example}:
615 REAL(8), DIMENSION(3) :: x = (/ 1.0, 2.0, 3.0 /)
620 @item @emph{Specific names}:
621 @multitable @columnfractions .20 .20 .20 .25
622 @item Name @tab Argument @tab Return type @tab Standard
623 @item @code{DACOSH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
626 @item @emph{See also}:
627 Inverse function: @ref{COSH}
633 @section @code{ADJUSTL} --- Left adjust a string
635 @cindex string, adjust left
636 @cindex adjust string
639 @item @emph{Description}:
640 @code{ADJUSTL(STRING)} will left adjust a string by removing leading spaces.
641 Spaces are inserted at the end of the string as needed.
643 @item @emph{Standard}:
650 @code{RESULT = ADJUSTL(STRING)}
652 @item @emph{Arguments}:
653 @multitable @columnfractions .15 .70
654 @item @var{STRING} @tab The type shall be @code{CHARACTER}.
657 @item @emph{Return value}:
658 The return value is of type @code{CHARACTER} and of the same kind as
659 @var{STRING} where leading spaces are removed and the same number of
660 spaces are inserted on the end of @var{STRING}.
662 @item @emph{Example}:
665 character(len=20) :: str = ' gfortran'
668 end program test_adjustl
671 @item @emph{See also}:
672 @ref{ADJUSTR}, @ref{TRIM}
678 @section @code{ADJUSTR} --- Right adjust a string
680 @cindex string, adjust right
681 @cindex adjust string
684 @item @emph{Description}:
685 @code{ADJUSTR(STRING)} will right adjust a string by removing trailing spaces.
686 Spaces are inserted at the start of the string as needed.
688 @item @emph{Standard}:
695 @code{RESULT = ADJUSTR(STRING)}
697 @item @emph{Arguments}:
698 @multitable @columnfractions .15 .70
699 @item @var{STR} @tab The type shall be @code{CHARACTER}.
702 @item @emph{Return value}:
703 The return value is of type @code{CHARACTER} and of the same kind as
704 @var{STRING} where trailing spaces are removed and the same number of
705 spaces are inserted at the start of @var{STRING}.
707 @item @emph{Example}:
710 character(len=20) :: str = 'gfortran'
713 end program test_adjustr
716 @item @emph{See also}:
717 @ref{ADJUSTL}, @ref{TRIM}
723 @section @code{AIMAG} --- Imaginary part of complex number
728 @cindex complex numbers, imaginary part
731 @item @emph{Description}:
732 @code{AIMAG(Z)} yields the imaginary part of complex argument @code{Z}.
733 The @code{IMAG(Z)} and @code{IMAGPART(Z)} intrinsic functions are provided
734 for compatibility with @command{g77}, and their use in new code is
735 strongly discouraged.
737 @item @emph{Standard}:
738 Fortran 77 and later, has overloads that are GNU extensions
744 @code{RESULT = AIMAG(Z)}
746 @item @emph{Arguments}:
747 @multitable @columnfractions .15 .70
748 @item @var{Z} @tab The type of the argument shall be @code{COMPLEX}.
751 @item @emph{Return value}:
752 The return value is of type @code{REAL} with the
753 kind type parameter of the argument.
755 @item @emph{Example}:
760 z4 = cmplx(1.e0_4, 0.e0_4)
761 z8 = cmplx(0.e0_8, 1.e0_8)
762 print *, aimag(z4), dimag(z8)
763 end program test_aimag
766 @item @emph{Specific names}:
767 @multitable @columnfractions .20 .20 .20 .25
768 @item Name @tab Argument @tab Return type @tab Standard
769 @item @code{DIMAG(Z)} @tab @code{COMPLEX(8) Z} @tab @code{REAL(8)} @tab GNU extension
770 @item @code{IMAG(Z)} @tab @code{COMPLEX Z} @tab @code{REAL} @tab GNU extension
771 @item @code{IMAGPART(Z)} @tab @code{COMPLEX Z} @tab @code{REAL} @tab GNU extension
778 @section @code{AINT} --- Truncate to a whole number
782 @cindex rounding, floor
785 @item @emph{Description}:
786 @code{AINT(A [, KIND])} truncates its argument to a whole number.
788 @item @emph{Standard}:
795 @code{RESULT = AINT(A [, KIND])}
797 @item @emph{Arguments}:
798 @multitable @columnfractions .15 .70
799 @item @var{A} @tab The type of the argument shall be @code{REAL}.
800 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
801 expression indicating the kind parameter of the result.
804 @item @emph{Return value}:
805 The return value is of type @code{REAL} with the kind type parameter of the
806 argument if the optional @var{KIND} is absent; otherwise, the kind
807 type parameter will be given by @var{KIND}. If the magnitude of
808 @var{X} is less than one, @code{AINT(X)} returns zero. If the
809 magnitude is equal to or greater than one then it returns the largest
810 whole number that does not exceed its magnitude. The sign is the same
811 as the sign of @var{X}.
813 @item @emph{Example}:
820 print *, aint(x4), dint(x8)
822 end program test_aint
825 @item @emph{Specific names}:
826 @multitable @columnfractions .20 .20 .20 .25
827 @item Name @tab Argument @tab Return type @tab Standard
828 @item @code{DINT(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
835 @section @code{ALARM} --- Execute a routine after a given delay
837 @cindex delayed execution
840 @item @emph{Description}:
841 @code{ALARM(SECONDS, HANDLER [, STATUS])} causes external subroutine @var{HANDLER}
842 to be executed after a delay of @var{SECONDS} by using @code{alarm(2)} to
843 set up a signal and @code{signal(2)} to catch it. If @var{STATUS} is
844 supplied, it will be returned with the number of seconds remaining until
845 any previously scheduled alarm was due to be delivered, or zero if there
846 was no previously scheduled alarm.
848 @item @emph{Standard}:
855 @code{CALL ALARM(SECONDS, HANDLER [, STATUS])}
857 @item @emph{Arguments}:
858 @multitable @columnfractions .15 .70
859 @item @var{SECONDS} @tab The type of the argument shall be a scalar
860 @code{INTEGER}. It is @code{INTENT(IN)}.
861 @item @var{HANDLER} @tab Signal handler (@code{INTEGER FUNCTION} or
862 @code{SUBROUTINE}) or dummy/global @code{INTEGER} scalar. The scalar
863 values may be either @code{SIG_IGN=1} to ignore the alarm generated
864 or @code{SIG_DFL=0} to set the default action. It is @code{INTENT(IN)}.
865 @item @var{STATUS} @tab (Optional) @var{STATUS} shall be a scalar
866 variable of the default @code{INTEGER} kind. It is @code{INTENT(OUT)}.
869 @item @emph{Example}:
872 external handler_print
874 call alarm (3, handler_print, i)
877 end program test_alarm
879 This will cause the external routine @var{handler_print} to be called
886 @section @code{ALL} --- All values in @var{MASK} along @var{DIM} are true
888 @cindex array, apply condition
889 @cindex array, condition testing
892 @item @emph{Description}:
893 @code{ALL(MASK [, DIM])} determines if all the values are true in @var{MASK}
894 in the array along dimension @var{DIM}.
896 @item @emph{Standard}:
900 Transformational function
903 @code{RESULT = ALL(MASK [, DIM])}
905 @item @emph{Arguments}:
906 @multitable @columnfractions .15 .70
907 @item @var{MASK} @tab The type of the argument shall be @code{LOGICAL} and
908 it shall not be scalar.
909 @item @var{DIM} @tab (Optional) @var{DIM} shall be a scalar integer
910 with a value that lies between one and the rank of @var{MASK}.
913 @item @emph{Return value}:
914 @code{ALL(MASK)} returns a scalar value of type @code{LOGICAL} where
915 the kind type parameter is the same as the kind type parameter of
916 @var{MASK}. If @var{DIM} is present, then @code{ALL(MASK, DIM)} returns
917 an array with the rank of @var{MASK} minus 1. The shape is determined from
918 the shape of @var{MASK} where the @var{DIM} dimension is elided.
922 @code{ALL(MASK)} is true if all elements of @var{MASK} are true.
923 It also is true if @var{MASK} has zero size; otherwise, it is false.
925 If the rank of @var{MASK} is one, then @code{ALL(MASK,DIM)} is equivalent
926 to @code{ALL(MASK)}. If the rank is greater than one, then @code{ALL(MASK,DIM)}
927 is determined by applying @code{ALL} to the array sections.
930 @item @emph{Example}:
934 l = all((/.true., .true., .true./))
939 integer a(2,3), b(2,3)
943 print *, all(a .eq. b, 1)
944 print *, all(a .eq. b, 2)
945 end subroutine section
953 @section @code{ALLOCATED} --- Status of an allocatable entity
955 @cindex allocation, status
958 @item @emph{Description}:
959 @code{ALLOCATED(ARRAY)} checks the status of whether @var{X} is allocated.
961 @item @emph{Standard}:
968 @code{RESULT = ALLOCATED(ARRAY)}
970 @item @emph{Arguments}:
971 @multitable @columnfractions .15 .70
972 @item @var{ARRAY} @tab The argument shall be an @code{ALLOCATABLE} array.
975 @item @emph{Return value}:
976 The return value is a scalar @code{LOGICAL} with the default logical
977 kind type parameter. If @var{ARRAY} is allocated, @code{ALLOCATED(ARRAY)}
978 is @code{.TRUE.}; otherwise, it returns @code{.FALSE.}
980 @item @emph{Example}:
982 program test_allocated
984 real(4), allocatable :: x(:)
985 if (.not. allocated(x)) allocate(x(i))
986 end program test_allocated
993 @section @code{AND} --- Bitwise logical AND
995 @cindex bitwise logical and
996 @cindex logical and, bitwise
999 @item @emph{Description}:
1000 Bitwise logical @code{AND}.
1002 This intrinsic routine is provided for backwards compatibility with
1003 GNU Fortran 77. For integer arguments, programmers should consider
1004 the use of the @ref{IAND} intrinsic defined by the Fortran standard.
1006 @item @emph{Standard}:
1012 @item @emph{Syntax}:
1013 @code{RESULT = AND(I, J)}
1015 @item @emph{Arguments}:
1016 @multitable @columnfractions .15 .70
1017 @item @var{I} @tab The type shall be either a scalar @code{INTEGER}
1018 type or a scalar @code{LOGICAL} type.
1019 @item @var{J} @tab The type shall be the same as the type of @var{I}.
1022 @item @emph{Return value}:
1023 The return type is either a scalar @code{INTEGER} or a scalar
1024 @code{LOGICAL}. If the kind type parameters differ, then the
1025 smaller kind type is implicitly converted to larger kind, and the
1026 return has the larger kind.
1028 @item @emph{Example}:
1031 LOGICAL :: T = .TRUE., F = .FALSE.
1033 DATA a / Z'F' /, b / Z'3' /
1035 WRITE (*,*) AND(T, T), AND(T, F), AND(F, T), AND(F, F)
1036 WRITE (*,*) AND(a, b)
1040 @item @emph{See also}:
1041 Fortran 95 elemental function: @ref{IAND}
1047 @section @code{ANINT} --- Nearest whole number
1051 @cindex rounding, ceiling
1054 @item @emph{Description}:
1055 @code{ANINT(A [, KIND])} rounds its argument to the nearest whole number.
1057 @item @emph{Standard}:
1058 Fortran 77 and later
1063 @item @emph{Syntax}:
1064 @code{RESULT = ANINT(A [, KIND])}
1066 @item @emph{Arguments}:
1067 @multitable @columnfractions .15 .70
1068 @item @var{A} @tab The type of the argument shall be @code{REAL}.
1069 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
1070 expression indicating the kind parameter of the result.
1073 @item @emph{Return value}:
1074 The return value is of type real with the kind type parameter of the
1075 argument if the optional @var{KIND} is absent; otherwise, the kind
1076 type parameter will be given by @var{KIND}. If @var{A} is greater than
1077 zero, @code{ANINT(A)} returns @code{AINT(X+0.5)}. If @var{A} is
1078 less than or equal to zero then it returns @code{AINT(X-0.5)}.
1080 @item @emph{Example}:
1087 print *, anint(x4), dnint(x8)
1089 end program test_anint
1092 @item @emph{Specific names}:
1093 @multitable @columnfractions .20 .20 .20 .25
1094 @item Name @tab Argument @tab Return type @tab Standard
1095 @item @code{DNINT(A)} @tab @code{REAL(8) A} @tab @code{REAL(8)} @tab Fortran 77 and later
1102 @section @code{ANY} --- Any value in @var{MASK} along @var{DIM} is true
1104 @cindex array, apply condition
1105 @cindex array, condition testing
1108 @item @emph{Description}:
1109 @code{ANY(MASK [, DIM])} determines if any of the values in the logical array
1110 @var{MASK} along dimension @var{DIM} are @code{.TRUE.}.
1112 @item @emph{Standard}:
1113 Fortran 95 and later
1116 Transformational function
1118 @item @emph{Syntax}:
1119 @code{RESULT = ANY(MASK [, DIM])}
1121 @item @emph{Arguments}:
1122 @multitable @columnfractions .15 .70
1123 @item @var{MASK} @tab The type of the argument shall be @code{LOGICAL} and
1124 it shall not be scalar.
1125 @item @var{DIM} @tab (Optional) @var{DIM} shall be a scalar integer
1126 with a value that lies between one and the rank of @var{MASK}.
1129 @item @emph{Return value}:
1130 @code{ANY(MASK)} returns a scalar value of type @code{LOGICAL} where
1131 the kind type parameter is the same as the kind type parameter of
1132 @var{MASK}. If @var{DIM} is present, then @code{ANY(MASK, DIM)} returns
1133 an array with the rank of @var{MASK} minus 1. The shape is determined from
1134 the shape of @var{MASK} where the @var{DIM} dimension is elided.
1138 @code{ANY(MASK)} is true if any element of @var{MASK} is true;
1139 otherwise, it is false. It also is false if @var{MASK} has zero size.
1141 If the rank of @var{MASK} is one, then @code{ANY(MASK,DIM)} is equivalent
1142 to @code{ANY(MASK)}. If the rank is greater than one, then @code{ANY(MASK,DIM)}
1143 is determined by applying @code{ANY} to the array sections.
1146 @item @emph{Example}:
1150 l = any((/.true., .true., .true./))
1155 integer a(2,3), b(2,3)
1159 print *, any(a .eq. b, 1)
1160 print *, any(a .eq. b, 2)
1161 end subroutine section
1162 end program test_any
1169 @section @code{ASIN} --- Arcsine function
1172 @cindex trigonometric function, sine, inverse
1173 @cindex sine, inverse
1176 @item @emph{Description}:
1177 @code{ASIN(X)} computes the arcsine of its @var{X} (inverse of @code{SIN(X)}).
1179 @item @emph{Standard}:
1180 Fortran 77 and later, for a complex argument Fortran 2008 or later
1185 @item @emph{Syntax}:
1186 @code{RESULT = ASIN(X)}
1188 @item @emph{Arguments}:
1189 @multitable @columnfractions .15 .70
1190 @item @var{X} @tab The type shall be either @code{REAL} and a magnitude that is
1191 less than or equal to one - or be @code{COMPLEX}.
1194 @item @emph{Return value}:
1195 The return value is of the same type and kind as @var{X}.
1196 The real part of the result is in radians and lies in the range
1197 @math{-\pi/2 \leq \Re \asin(x) \leq \pi/2}.
1199 @item @emph{Example}:
1202 real(8) :: x = 0.866_8
1204 end program test_asin
1207 @item @emph{Specific names}:
1208 @multitable @columnfractions .20 .20 .20 .25
1209 @item Name @tab Argument @tab Return type @tab Standard
1210 @item @code{DASIN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
1213 @item @emph{See also}:
1214 Inverse function: @ref{SIN}
1221 @section @code{ASINH} --- Hyperbolic arcsine function
1224 @cindex area hyperbolic sine
1225 @cindex hyperbolic arcsine
1226 @cindex hyperbolic function, sine, inverse
1227 @cindex sine, hyperbolic, inverse
1230 @item @emph{Description}:
1231 @code{ASINH(X)} computes the hyperbolic arcsine of @var{X} (inverse of @code{SINH(X)}).
1233 @item @emph{Standard}:
1234 Fortran 2008 and later
1239 @item @emph{Syntax}:
1240 @code{RESULT = ASINH(X)}
1242 @item @emph{Arguments}:
1243 @multitable @columnfractions .15 .70
1244 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
1247 @item @emph{Return value}:
1248 The return value is of the same type and kind as @var{X}. If @var{X} is
1249 complex, the imaginary part of the result is in radians and lies between
1250 @math{-\pi/2 \leq \Im \asinh(x) \leq \pi/2}.
1252 @item @emph{Example}:
1255 REAL(8), DIMENSION(3) :: x = (/ -1.0, 0.0, 1.0 /)
1256 WRITE (*,*) ASINH(x)
1260 @item @emph{Specific names}:
1261 @multitable @columnfractions .20 .20 .20 .25
1262 @item Name @tab Argument @tab Return type @tab Standard
1263 @item @code{DASINH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension.
1266 @item @emph{See also}:
1267 Inverse function: @ref{SINH}
1273 @section @code{ASSOCIATED} --- Status of a pointer or pointer/target pair
1275 @cindex pointer, status
1276 @cindex association status
1279 @item @emph{Description}:
1280 @code{ASSOCIATED(POINTER [, TARGET])} determines the status of the pointer
1281 @var{POINTER} or if @var{POINTER} is associated with the target @var{TARGET}.
1283 @item @emph{Standard}:
1284 Fortran 95 and later
1289 @item @emph{Syntax}:
1290 @code{RESULT = ASSOCIATED(POINTER [, TARGET])}
1292 @item @emph{Arguments}:
1293 @multitable @columnfractions .15 .70
1294 @item @var{POINTER} @tab @var{POINTER} shall have the @code{POINTER} attribute
1295 and it can be of any type.
1296 @item @var{TARGET} @tab (Optional) @var{TARGET} shall be a pointer or
1297 a target. It must have the same type, kind type parameter, and
1298 array rank as @var{POINTER}.
1300 The association status of neither @var{POINTER} nor @var{TARGET} shall be
1303 @item @emph{Return value}:
1304 @code{ASSOCIATED(POINTER)} returns a scalar value of type @code{LOGICAL(4)}.
1305 There are several cases:
1307 @item (A) When the optional @var{TARGET} is not present then
1308 @code{ASSOCIATED(POINTER)} is true if @var{POINTER} is associated with a target; otherwise, it returns false.
1309 @item (B) If @var{TARGET} is present and a scalar target, the result is true if
1310 @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
1311 disassociated, the result is false.
1312 @item (C) If @var{TARGET} is present and an array target, the result is true if
1313 @var{TARGET} and @var{POINTER} have the same shape, are not zero-sized arrays,
1314 are arrays whose elements are not zero-sized storage sequences, and
1315 @var{TARGET} and @var{POINTER} occupy the same storage units in array element
1317 As in case(B), the result is false, if @var{POINTER} is disassociated.
1318 @item (D) If @var{TARGET} is present and an scalar pointer, the result is true
1319 if @var{TARGET} is associated with @var{POINTER}, the target associated with
1320 @var{TARGET} are not zero-sized storage sequences and occupy the same storage
1322 The result is false, if either @var{TARGET} or @var{POINTER} is disassociated.
1323 @item (E) If @var{TARGET} is present and an array pointer, the result is true if
1324 target associated with @var{POINTER} and the target associated with @var{TARGET}
1325 have the same shape, are not zero-sized arrays, are arrays whose elements are
1326 not zero-sized storage sequences, and @var{TARGET} and @var{POINTER} occupy
1327 the same storage units in array element order.
1328 The result is false, if either @var{TARGET} or @var{POINTER} is disassociated.
1331 @item @emph{Example}:
1333 program test_associated
1335 real, target :: tgt(2) = (/1., 2./)
1336 real, pointer :: ptr(:)
1338 if (associated(ptr) .eqv. .false.) call abort
1339 if (associated(ptr,tgt) .eqv. .false.) call abort
1340 end program test_associated
1343 @item @emph{See also}:
1350 @section @code{ATAN} --- Arctangent function
1353 @cindex trigonometric function, tangent, inverse
1354 @cindex tangent, inverse
1357 @item @emph{Description}:
1358 @code{ATAN(X)} computes the arctangent of @var{X}.
1360 @item @emph{Standard}:
1361 Fortran 77 and later, for a complex argument and for two arguments
1362 Fortran 2008 or later
1367 @item @emph{Syntax}:
1368 @code{RESULT = ATAN(X)}
1369 @code{RESULT = ATAN(Y, X)}
1371 @item @emph{Arguments}:
1372 @multitable @columnfractions .15 .70
1373 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX};
1374 if @var{Y} is present, @var{X} shall be REAL.
1375 @item @var{Y} shall be of the same type and kind as @var{X}.
1378 @item @emph{Return value}:
1379 The return value is of the same type and kind as @var{X}.
1380 If @var{Y} is present, the result is identical to @code{ATAN2(Y,X)}.
1381 Otherwise, it the arcus tangent of @var{X}, where the real part of
1382 the result is in radians and lies in the range
1383 @math{-\pi/2 \leq \Re \atan(x) \leq \pi/2}.
1385 @item @emph{Example}:
1388 real(8) :: x = 2.866_8
1390 end program test_atan
1393 @item @emph{Specific names}:
1394 @multitable @columnfractions .20 .20 .20 .25
1395 @item Name @tab Argument @tab Return type @tab Standard
1396 @item @code{DATAN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
1399 @item @emph{See also}:
1400 Inverse function: @ref{TAN}
1407 @section @code{ATAN2} --- Arctangent function
1410 @cindex trigonometric function, tangent, inverse
1411 @cindex tangent, inverse
1414 @item @emph{Description}:
1415 @code{ATAN2(Y, X)} computes the principal value of the argument
1416 function of the complex number @math{X + i Y}. This function can
1417 be used to transform from carthesian into polar coordinates and
1418 allows to determine the angle in the correct quadrant.
1420 @item @emph{Standard}:
1421 Fortran 77 and later
1426 @item @emph{Syntax}:
1427 @code{RESULT = ATAN2(Y, X)}
1429 @item @emph{Arguments}:
1430 @multitable @columnfractions .15 .70
1431 @item @var{Y} @tab The type shall be @code{REAL}.
1432 @item @var{X} @tab The type and kind type parameter shall be the same as @var{Y}.
1433 If @var{Y} is zero, then @var{X} must be nonzero.
1436 @item @emph{Return value}:
1437 The return value has the same type and kind type parameter as @var{Y}.
1438 It is the principal value of the complex number @math{X + i Y}. If
1439 @var{X} is nonzero, then it lies in the range @math{-\pi \le \atan (x) \leq \pi}.
1440 The sign is positive if @var{Y} is positive. If @var{Y} is zero, then
1441 the return value is zero if @var{X} is positive and @math{\pi} if @var{X}
1442 is negative. Finally, if @var{X} is zero, then the magnitude of the result
1445 @item @emph{Example}:
1448 real(4) :: x = 1.e0_4, y = 0.5e0_4
1450 end program test_atan2
1453 @item @emph{Specific names}:
1454 @multitable @columnfractions .20 .20 .20 .25
1455 @item Name @tab Argument @tab Return type @tab Standard
1456 @item @code{DATAN2(X, Y)} @tab @code{REAL(8) X}, @code{REAL(8) Y} @tab @code{REAL(8)} @tab Fortran 77 and later
1463 @section @code{ATANH} --- Hyperbolic arctangent function
1466 @cindex area hyperbolic tangent
1467 @cindex hyperbolic arctangent
1468 @cindex hyperbolic function, tangent, inverse
1469 @cindex tangent, hyperbolic, inverse
1472 @item @emph{Description}:
1473 @code{ATANH(X)} computes the hyperbolic arctangent of @var{X} (inverse
1476 @item @emph{Standard}:
1477 Fortran 2008 and later
1482 @item @emph{Syntax}:
1483 @code{RESULT = ATANH(X)}
1485 @item @emph{Arguments}:
1486 @multitable @columnfractions .15 .70
1487 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
1490 @item @emph{Return value}:
1491 The return value has same type and kind as @var{X}. If @var{X} is
1492 complex, the imaginary part of the result is in radians and lies between
1493 @math{-\pi/2 \leq \Im \atanh(x) \leq \pi/2}.
1495 @item @emph{Example}:
1498 REAL, DIMENSION(3) :: x = (/ -1.0, 0.0, 1.0 /)
1499 WRITE (*,*) ATANH(x)
1503 @item @emph{Specific names}:
1504 @multitable @columnfractions .20 .20 .20 .25
1505 @item Name @tab Argument @tab Return type @tab Standard
1506 @item @code{DATANH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1509 @item @emph{See also}:
1510 Inverse function: @ref{TANH}
1516 @section @code{BESSEL_J0} --- Bessel function of the first kind of order 0
1520 @cindex Bessel function, first kind
1523 @item @emph{Description}:
1524 @code{BESSEL_J0(X)} computes the Bessel function of the first kind of
1525 order 0 of @var{X}. This function is available under the name
1526 @code{BESJ0} as a GNU extension.
1528 @item @emph{Standard}:
1529 Fortran 2008 and later
1534 @item @emph{Syntax}:
1535 @code{RESULT = BESSEL_J0(X)}
1537 @item @emph{Arguments}:
1538 @multitable @columnfractions .15 .70
1539 @item @var{X} @tab The type shall be @code{REAL}, and it shall be scalar.
1542 @item @emph{Return value}:
1543 The return value is of type @code{REAL} and lies in the
1544 range @math{ - 0.4027... \leq Bessel (0,x) \leq 1}. It has the same
1547 @item @emph{Example}:
1550 real(8) :: x = 0.0_8
1552 end program test_besj0
1555 @item @emph{Specific names}:
1556 @multitable @columnfractions .20 .20 .20 .25
1557 @item Name @tab Argument @tab Return type @tab Standard
1558 @item @code{DBESJ0(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1565 @section @code{BESSEL_J1} --- Bessel function of the first kind of order 1
1569 @cindex Bessel function, first kind
1572 @item @emph{Description}:
1573 @code{BESSEL_J1(X)} computes the Bessel function of the first kind of
1574 order 1 of @var{X}. This function is available under the name
1575 @code{BESJ1} as a GNU extension.
1577 @item @emph{Standard}:
1583 @item @emph{Syntax}:
1584 @code{RESULT = BESSEL_J1(X)}
1586 @item @emph{Arguments}:
1587 @multitable @columnfractions .15 .70
1588 @item @var{X} @tab The type shall be @code{REAL}, and it shall be scalar.
1591 @item @emph{Return value}:
1592 The return value is of type @code{REAL} and it lies in the
1593 range @math{ - 0.5818... \leq Bessel (0,x) \leq 0.5818 }. It has the same
1596 @item @emph{Example}:
1599 real(8) :: x = 1.0_8
1601 end program test_besj1
1604 @item @emph{Specific names}:
1605 @multitable @columnfractions .20 .20 .20 .25
1606 @item Name @tab Argument @tab Return type @tab Standard
1607 @item @code{DBESJ1(X)}@tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1614 @section @code{BESSEL_JN} --- Bessel function of the first kind
1618 @cindex Bessel function, first kind
1621 @item @emph{Description}:
1622 @code{BESSEL_JN(N, X)} computes the Bessel function of the first kind of
1623 order @var{N} of @var{X}. This function is available under the name
1624 @code{BESJN} as a GNU extension.
1626 If both arguments are arrays, their ranks and shapes shall conform.
1628 @item @emph{Standard}:
1629 Fortran 2008 and later
1634 @item @emph{Syntax}:
1635 @code{RESULT = BESSEL_JN(N, X)}
1637 @item @emph{Arguments}:
1638 @multitable @columnfractions .15 .70
1639 @item @var{N} @tab Shall be a scalar or an array of type @code{INTEGER}.
1640 @item @var{X} @tab Shall be a scalar or an array of type @code{REAL}.
1643 @item @emph{Return value}:
1644 The return value is a scalar of type @code{REAL}. It has the same
1647 @item @emph{Example}:
1650 real(8) :: x = 1.0_8
1652 end program test_besjn
1655 @item @emph{Specific names}:
1656 @multitable @columnfractions .20 .20 .20 .25
1657 @item Name @tab Argument @tab Return type @tab Standard
1658 @item @code{DBESJN(N, X)} @tab @code{INTEGER N} @tab @code{REAL(8)} @tab GNU extension
1659 @item @tab @code{REAL(8) X} @tab @tab
1666 @section @code{BESSEL_Y0} --- Bessel function of the second kind of order 0
1670 @cindex Bessel function, second kind
1673 @item @emph{Description}:
1674 @code{BESSEL_Y0(X)} computes the Bessel function of the second kind of
1675 order 0 of @var{X}. This function is available under the name
1676 @code{BESY0} as a GNU extension.
1678 @item @emph{Standard}:
1679 Fortran 2008 and later
1684 @item @emph{Syntax}:
1685 @code{RESULT = BESSEL_Y0(X)}
1687 @item @emph{Arguments}:
1688 @multitable @columnfractions .15 .70
1689 @item @var{X} @tab The type shall be @code{REAL}, and it shall be scalar.
1692 @item @emph{Return value}:
1693 The return value is a scalar of type @code{REAL}. It has the same
1696 @item @emph{Example}:
1699 real(8) :: x = 0.0_8
1701 end program test_besy0
1704 @item @emph{Specific names}:
1705 @multitable @columnfractions .20 .20 .20 .25
1706 @item Name @tab Argument @tab Return type @tab Standard
1707 @item @code{DBESY0(X)}@tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1714 @section @code{BESSEL_Y1} --- Bessel function of the second kind of order 1
1718 @cindex Bessel function, second kind
1721 @item @emph{Description}:
1722 @code{BESSEL_Y1(X)} computes the Bessel function of the second kind of
1723 order 1 of @var{X}. This function is available under the name
1724 @code{BESY1} as a GNU extension.
1726 @item @emph{Standard}:
1727 Fortran 2008 and later
1732 @item @emph{Syntax}:
1733 @code{RESULT = BESSEL_Y1(X)}
1735 @item @emph{Arguments}:
1736 @multitable @columnfractions .15 .70
1737 @item @var{X} @tab The type shall be @code{REAL}, and it shall be scalar.
1740 @item @emph{Return value}:
1741 The return value is a scalar of type @code{REAL}. It has the same
1744 @item @emph{Example}:
1747 real(8) :: x = 1.0_8
1749 end program test_besy1
1752 @item @emph{Specific names}:
1753 @multitable @columnfractions .20 .20 .20 .25
1754 @item Name @tab Argument @tab Return type @tab Standard
1755 @item @code{DBESY1(X)}@tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1762 @section @code{BESSEL_YN} --- Bessel function of the second kind
1766 @cindex Bessel function, second kind
1769 @item @emph{Description}:
1770 @code{BESSEL_YN(N, X)} computes the Bessel function of the second kind of
1771 order @var{N} of @var{X}. This function is available under the name
1772 @code{BESYN} as a GNU extension.
1774 If both arguments are arrays, their ranks and shapes shall conform.
1776 @item @emph{Standard}:
1777 Fortran 2008 and later
1782 @item @emph{Syntax}:
1783 @code{RESULT = BESSEL_YN(N, X)}
1785 @item @emph{Arguments}:
1786 @multitable @columnfractions .15 .70
1787 @item @var{N} @tab Shall be a scalar or an array of type @code{INTEGER}.
1788 @item @var{X} @tab Shall be a scalar or an array of type @code{REAL}.
1791 @item @emph{Return value}:
1792 The return value is a scalar of type @code{REAL}. It has the same
1795 @item @emph{Example}:
1798 real(8) :: x = 1.0_8
1800 end program test_besyn
1803 @item @emph{Specific names}:
1804 @multitable @columnfractions .20 .20 .20 .25
1805 @item Name @tab Argument @tab Return type @tab Standard
1806 @item @code{DBESYN(N,X)} @tab @code{INTEGER N} @tab @code{REAL(8)} @tab GNU extension
1807 @item @tab @code{REAL(8) X} @tab @tab
1814 @section @code{BIT_SIZE} --- Bit size inquiry function
1816 @cindex bits, number of
1817 @cindex size of a variable, in bits
1820 @item @emph{Description}:
1821 @code{BIT_SIZE(I)} returns the number of bits (integer precision plus sign bit)
1822 represented by the type of @var{I}. The result of @code{BIT_SIZE(I)} is
1823 independent of the actual value of @var{I}.
1825 @item @emph{Standard}:
1826 Fortran 95 and later
1831 @item @emph{Syntax}:
1832 @code{RESULT = BIT_SIZE(I)}
1834 @item @emph{Arguments}:
1835 @multitable @columnfractions .15 .70
1836 @item @var{I} @tab The type shall be @code{INTEGER}.
1839 @item @emph{Return value}:
1840 The return value is of type @code{INTEGER}
1842 @item @emph{Example}:
1844 program test_bit_size
1849 end program test_bit_size
1856 @section @code{BTEST} --- Bit test function
1858 @cindex bits, testing
1861 @item @emph{Description}:
1862 @code{BTEST(I,POS)} returns logical @code{.TRUE.} if the bit at @var{POS}
1863 in @var{I} is set. The counting of the bits starts at 0.
1865 @item @emph{Standard}:
1866 Fortran 95 and later
1871 @item @emph{Syntax}:
1872 @code{RESULT = BTEST(I, POS)}
1874 @item @emph{Arguments}:
1875 @multitable @columnfractions .15 .70
1876 @item @var{I} @tab The type shall be @code{INTEGER}.
1877 @item @var{POS} @tab The type shall be @code{INTEGER}.
1880 @item @emph{Return value}:
1881 The return value is of type @code{LOGICAL}
1883 @item @emph{Example}:
1886 integer :: i = 32768 + 1024 + 64
1890 bool = btest(i, pos)
1893 end program test_btest
1899 @section @code{C_ASSOCIATED} --- Status of a C pointer
1900 @fnindex C_ASSOCIATED
1901 @cindex association status, C pointer
1902 @cindex pointer, C association status
1905 @item @emph{Description}:
1906 @code{C_ASSOCIATED(c_prt_1[, c_ptr_2])} determines the status of the C pointer
1907 @var{c_ptr_1} or if @var{c_ptr_1} is associated with the target @var{c_ptr_2}.
1909 @item @emph{Standard}:
1910 Fortran 2003 and later
1915 @item @emph{Syntax}:
1916 @code{RESULT = C_ASSOCIATED(c_prt_1[, c_ptr_2])}
1918 @item @emph{Arguments}:
1919 @multitable @columnfractions .15 .70
1920 @item @var{c_ptr_1} @tab Scalar of the type @code{C_PTR} or @code{C_FUNPTR}.
1921 @item @var{c_ptr_2} @tab (Optional) Scalar of the same type as @var{c_ptr_1}.
1924 @item @emph{Return value}:
1925 The return value is of type @code{LOGICAL}; it is @code{.false.} if either
1926 @var{c_ptr_1} is a C NULL pointer or if @var{c_ptr1} and @var{c_ptr_2}
1927 point to different addresses.
1929 @item @emph{Example}:
1931 subroutine association_test(a,b)
1932 use iso_c_binding, only: c_associated, c_loc, c_ptr
1936 if(c_associated(b, c_loc(a))) &
1937 stop 'b and a do not point to same target'
1938 end subroutine association_test
1941 @item @emph{See also}:
1942 @ref{C_LOC}, @ref{C_FUNLOC}
1947 @section @code{C_FUNLOC} --- Obtain the C address of a procedure
1949 @cindex pointer, C address of procedures
1952 @item @emph{Description}:
1953 @code{C_FUNLOC(x)} determines the C address of the argument.
1955 @item @emph{Standard}:
1956 Fortran 2003 and later
1961 @item @emph{Syntax}:
1962 @code{RESULT = C_FUNLOC(x)}
1964 @item @emph{Arguments}:
1965 @multitable @columnfractions .15 .70
1966 @item @var{x} @tab Interoperable function or pointer to such function.
1969 @item @emph{Return value}:
1970 The return value is of type @code{C_FUNPTR} and contains the C address
1973 @item @emph{Example}:
1979 subroutine sub(a) bind(c)
1989 subroutine my_routine(p) bind(c,name='myC_func')
1991 type(c_funptr), intent(in) :: p
1994 call my_routine(c_funloc(sub))
1998 @item @emph{See also}:
1999 @ref{C_ASSOCIATED}, @ref{C_LOC}, @ref{C_F_POINTER}, @ref{C_F_PROCPOINTER}
2003 @node C_F_PROCPOINTER
2004 @section @code{C_F_PROCPOINTER} --- Convert C into Fortran procedure pointer
2005 @fnindex C_F_PROCPOINTER
2006 @cindex pointer, C address of pointers
2009 @item @emph{Description}:
2010 @code{C_F_PROCPOINTER(CPTR, FPTR)} Assign the target of the C function pointer
2011 @var{CPTR} to the Fortran procedure pointer @var{FPTR}.
2013 @item @emph{Standard}:
2014 Fortran 2003 and later
2019 @item @emph{Syntax}:
2020 @code{CALL C_F_PROCPOINTER(cptr, fptr)}
2022 @item @emph{Arguments}:
2023 @multitable @columnfractions .15 .70
2024 @item @var{CPTR} @tab scalar of the type @code{C_FUNPTR}. It is
2026 @item @var{FPTR} @tab procedure pointer interoperable with @var{cptr}. It is
2030 @item @emph{Example}:
2038 real(c_float), intent(in) :: a
2039 real(c_float) :: func
2043 function getIterFunc() bind(c,name="getIterFunc")
2045 type(c_funptr) :: getIterFunc
2048 type(c_funptr) :: cfunptr
2049 procedure(func), pointer :: myFunc
2050 cfunptr = getIterFunc()
2051 call c_f_procpointer(cfunptr, myFunc)
2055 @item @emph{See also}:
2056 @ref{C_LOC}, @ref{C_F_POINTER}
2061 @section @code{C_F_POINTER} --- Convert C into Fortran pointer
2062 @fnindex C_F_POINTER
2063 @cindex pointer, convert C to Fortran
2066 @item @emph{Description}:
2067 @code{C_F_POINTER(CPTR, FPTR[, SHAPE])} Assign the target the C pointer
2068 @var{CPTR} to the Fortran pointer @var{FPTR} and specify its
2071 @item @emph{Standard}:
2072 Fortran 2003 and later
2077 @item @emph{Syntax}:
2078 @code{CALL C_F_POINTER(CPTR, FPTR[, SHAPE])}
2080 @item @emph{Arguments}:
2081 @multitable @columnfractions .15 .70
2082 @item @var{CPTR} @tab scalar of the type @code{C_PTR}. It is
2084 @item @var{FPTR} @tab pointer interoperable with @var{cptr}. It is
2086 @item @var{SHAPE} @tab (Optional) Rank-one array of type @code{INTEGER}
2087 with @code{INTENT(IN)}. It shall be present
2088 if and only if @var{fptr} is an array. The size
2089 must be equal to the rank of @var{fptr}.
2092 @item @emph{Example}:
2098 subroutine my_routine(p) bind(c,name='myC_func')
2100 type(c_ptr), intent(out) :: p
2104 real,pointer :: a(:)
2105 call my_routine(cptr)
2106 call c_f_pointer(cptr, a, [12])
2110 @item @emph{See also}:
2111 @ref{C_LOC}, @ref{C_F_PROCPOINTER}
2116 @section @code{C_LOC} --- Obtain the C address of an object
2118 @cindex procedure pointer, convert C to Fortran
2121 @item @emph{Description}:
2122 @code{C_LOC(X)} determines the C address of the argument.
2124 @item @emph{Standard}:
2125 Fortran 2003 and later
2130 @item @emph{Syntax}:
2131 @code{RESULT = C_LOC(X)}
2133 @item @emph{Arguments}:
2134 @multitable @columnfractions .15 .70
2135 @item @var{X} @tab Associated scalar pointer or interoperable scalar
2136 or allocated allocatable variable with @code{TARGET} attribute.
2139 @item @emph{Return value}:
2140 The return value is of type @code{C_PTR} and contains the C address
2143 @item @emph{Example}:
2145 subroutine association_test(a,b)
2146 use iso_c_binding, only: c_associated, c_loc, c_ptr
2150 if(c_associated(b, c_loc(a))) &
2151 stop 'b and a do not point to same target'
2152 end subroutine association_test
2155 @item @emph{See also}:
2156 @ref{C_ASSOCIATED}, @ref{C_FUNLOC}, @ref{C_F_POINTER}, @ref{C_F_PROCPOINTER}
2161 @section @code{C_SIZEOF} --- Size in bytes of an expression
2163 @cindex expression size
2164 @cindex size of an expression
2167 @item @emph{Description}:
2168 @code{C_SIZEOF(X)} calculates the number of bytes of storage the
2169 expression @code{X} occupies.
2171 @item @emph{Standard}:
2177 @item @emph{Syntax}:
2178 @code{N = C_SIZEOF(X)}
2180 @item @emph{Arguments}:
2181 @multitable @columnfractions .15 .70
2182 @item @var{X} @tab The argument shall be of any type, rank or shape.
2185 @item @emph{Return value}:
2186 The return value is of type integer and of the system-dependent kind
2187 @var{C_SIZE_T} (from the @var{ISO_C_BINDING} module). Its value is the
2188 number of bytes occupied by the argument. If the argument has the
2189 @code{POINTER} attribute, the number of bytes of the storage area pointed
2190 to is returned. If the argument is of a derived type with @code{POINTER}
2191 or @code{ALLOCATABLE} components, the return value doesn't account for
2192 the sizes of the data pointed to by these components.
2194 @item @emph{Example}:
2198 real(c_float) :: r, s(5)
2199 print *, (c_sizeof(s)/c_sizeof(r) == 5)
2202 The example will print @code{.TRUE.} unless you are using a platform
2203 where default @code{REAL} variables are unusually padded.
2205 @item @emph{See also}:
2211 @section @code{CEILING} --- Integer ceiling function
2214 @cindex rounding, ceiling
2217 @item @emph{Description}:
2218 @code{CEILING(A)} returns the least integer greater than or equal to @var{A}.
2220 @item @emph{Standard}:
2221 Fortran 95 and later
2226 @item @emph{Syntax}:
2227 @code{RESULT = CEILING(A [, KIND])}
2229 @item @emph{Arguments}:
2230 @multitable @columnfractions .15 .70
2231 @item @var{A} @tab The type shall be @code{REAL}.
2232 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
2233 expression indicating the kind parameter of the result.
2236 @item @emph{Return value}:
2237 The return value is of type @code{INTEGER(KIND)} if @var{KIND} is present
2238 and a default-kind @code{INTEGER} otherwise.
2240 @item @emph{Example}:
2242 program test_ceiling
2245 print *, ceiling(x) ! returns 64
2246 print *, ceiling(y) ! returns -63
2247 end program test_ceiling
2250 @item @emph{See also}:
2251 @ref{FLOOR}, @ref{NINT}
2258 @section @code{CHAR} --- Character conversion function
2260 @cindex conversion, to character
2263 @item @emph{Description}:
2264 @code{CHAR(I [, KIND])} returns the character represented by the integer @var{I}.
2266 @item @emph{Standard}:
2267 Fortran 77 and later
2272 @item @emph{Syntax}:
2273 @code{RESULT = CHAR(I [, KIND])}
2275 @item @emph{Arguments}:
2276 @multitable @columnfractions .15 .70
2277 @item @var{I} @tab The type shall be @code{INTEGER}.
2278 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
2279 expression indicating the kind parameter of the result.
2282 @item @emph{Return value}:
2283 The return value is of type @code{CHARACTER(1)}
2285 @item @emph{Example}:
2291 print *, i, c ! returns 'J'
2292 end program test_char
2296 See @ref{ICHAR} for a discussion of converting between numerical values
2297 and formatted string representations.
2299 @item @emph{See also}:
2300 @ref{ACHAR}, @ref{IACHAR}, @ref{ICHAR}
2307 @section @code{CHDIR} --- Change working directory
2309 @cindex system, working directory
2312 @item @emph{Description}:
2313 Change current working directory to a specified path.
2315 This intrinsic is provided in both subroutine and function forms; however,
2316 only one form can be used in any given program unit.
2318 @item @emph{Standard}:
2322 Subroutine, function
2324 @item @emph{Syntax}:
2325 @multitable @columnfractions .80
2326 @item @code{CALL CHDIR(NAME [, STATUS])}
2327 @item @code{STATUS = CHDIR(NAME)}
2330 @item @emph{Arguments}:
2331 @multitable @columnfractions .15 .70
2332 @item @var{NAME} @tab The type shall be @code{CHARACTER} of default
2333 kind and shall specify a valid path within the file system.
2334 @item @var{STATUS} @tab (Optional) @code{INTEGER} status flag of the default
2335 kind. Returns 0 on success, and a system specific and nonzero error code
2339 @item @emph{Example}:
2342 CHARACTER(len=255) :: path
2344 WRITE(*,*) TRIM(path)
2347 WRITE(*,*) TRIM(path)
2351 @item @emph{See also}:
2358 @section @code{CHMOD} --- Change access permissions of files
2360 @cindex file system, change access mode
2363 @item @emph{Description}:
2364 @code{CHMOD} changes the permissions of a file. This function invokes
2365 @code{/bin/chmod} and might therefore not work on all platforms.
2367 This intrinsic is provided in both subroutine and function forms; however,
2368 only one form can be used in any given program unit.
2370 @item @emph{Standard}:
2374 Subroutine, function
2376 @item @emph{Syntax}:
2377 @multitable @columnfractions .80
2378 @item @code{CALL CHMOD(NAME, MODE[, STATUS])}
2379 @item @code{STATUS = CHMOD(NAME, MODE)}
2382 @item @emph{Arguments}:
2383 @multitable @columnfractions .15 .70
2385 @item @var{NAME} @tab Scalar @code{CHARACTER} of default kind with the
2386 file name. Trailing blanks are ignored unless the character
2387 @code{achar(0)} is present, then all characters up to and excluding
2388 @code{achar(0)} are used as the file name.
2390 @item @var{MODE} @tab Scalar @code{CHARACTER} of default kind giving the
2391 file permission. @var{MODE} uses the same syntax as the @var{MODE}
2392 argument of @code{/bin/chmod}.
2394 @item @var{STATUS} @tab (optional) scalar @code{INTEGER}, which is
2395 @code{0} on success and nonzero otherwise.
2398 @item @emph{Return value}:
2399 In either syntax, @var{STATUS} is set to @code{0} on success and nonzero
2402 @item @emph{Example}:
2403 @code{CHMOD} as subroutine
2408 call chmod('test.dat','u+x',status)
2409 print *, 'Status: ', status
2410 end program chmod_test
2412 @code{CHMOD} as function:
2417 status = chmod('test.dat','u+x')
2418 print *, 'Status: ', status
2419 end program chmod_test
2427 @section @code{CMPLX} --- Complex conversion function
2429 @cindex complex numbers, conversion to
2430 @cindex conversion, to complex
2433 @item @emph{Description}:
2434 @code{CMPLX(X [, Y [, KIND]])} returns a complex number where @var{X} is converted to
2435 the real component. If @var{Y} is present it is converted to the imaginary
2436 component. If @var{Y} is not present then the imaginary component is set to
2437 0.0. If @var{X} is complex then @var{Y} must not be present.
2439 @item @emph{Standard}:
2440 Fortran 77 and later
2445 @item @emph{Syntax}:
2446 @code{RESULT = CMPLX(X [, Y [, KIND]])}
2448 @item @emph{Arguments}:
2449 @multitable @columnfractions .15 .70
2450 @item @var{X} @tab The type may be @code{INTEGER}, @code{REAL},
2452 @item @var{Y} @tab (Optional; only allowed if @var{X} is not
2453 @code{COMPLEX}.) May be @code{INTEGER} or @code{REAL}.
2454 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
2455 expression indicating the kind parameter of the result.
2458 @item @emph{Return value}:
2459 The return value is of @code{COMPLEX} type, with a kind equal to
2460 @var{KIND} if it is specified. If @var{KIND} is not specified, the
2461 result is of the default @code{COMPLEX} kind, regardless of the kinds of
2462 @var{X} and @var{Y}.
2464 @item @emph{Example}:
2471 print *, z, cmplx(x)
2472 end program test_cmplx
2475 @item @emph{See also}:
2481 @node COMMAND_ARGUMENT_COUNT
2482 @section @code{COMMAND_ARGUMENT_COUNT} --- Get number of command line arguments
2483 @fnindex COMMAND_ARGUMENT_COUNT
2484 @cindex command-line arguments
2485 @cindex command-line arguments, number of
2486 @cindex arguments, to program
2489 @item @emph{Description}:
2490 @code{COMMAND_ARGUMENT_COUNT()} returns the number of arguments passed on the
2491 command line when the containing program was invoked.
2493 @item @emph{Standard}:
2494 Fortran 2003 and later
2499 @item @emph{Syntax}:
2500 @code{RESULT = COMMAND_ARGUMENT_COUNT()}
2502 @item @emph{Arguments}:
2503 @multitable @columnfractions .15 .70
2507 @item @emph{Return value}:
2508 The return value is an @code{INTEGER} of default kind.
2510 @item @emph{Example}:
2512 program test_command_argument_count
2514 count = command_argument_count()
2516 end program test_command_argument_count
2519 @item @emph{See also}:
2520 @ref{GET_COMMAND}, @ref{GET_COMMAND_ARGUMENT}
2526 @section @code{COMPLEX} --- Complex conversion function
2528 @cindex complex numbers, conversion to
2529 @cindex conversion, to complex
2532 @item @emph{Description}:
2533 @code{COMPLEX(X, Y)} returns a complex number where @var{X} is converted
2534 to the real component and @var{Y} is converted to the imaginary
2537 @item @emph{Standard}:
2543 @item @emph{Syntax}:
2544 @code{RESULT = COMPLEX(X, Y)}
2546 @item @emph{Arguments}:
2547 @multitable @columnfractions .15 .70
2548 @item @var{X} @tab The type may be @code{INTEGER} or @code{REAL}.
2549 @item @var{Y} @tab The type may be @code{INTEGER} or @code{REAL}.
2552 @item @emph{Return value}:
2553 If @var{X} and @var{Y} are both of @code{INTEGER} type, then the return
2554 value is of default @code{COMPLEX} type.
2556 If @var{X} and @var{Y} are of @code{REAL} type, or one is of @code{REAL}
2557 type and one is of @code{INTEGER} type, then the return value is of
2558 @code{COMPLEX} type with a kind equal to that of the @code{REAL}
2559 argument with the highest precision.
2561 @item @emph{Example}:
2563 program test_complex
2566 print *, complex(i, x)
2567 end program test_complex
2570 @item @emph{See also}:
2577 @section @code{CONJG} --- Complex conjugate function
2580 @cindex complex conjugate
2583 @item @emph{Description}:
2584 @code{CONJG(Z)} returns the conjugate of @var{Z}. If @var{Z} is @code{(x, y)}
2585 then the result is @code{(x, -y)}
2587 @item @emph{Standard}:
2588 Fortran 77 and later, has overloads that are GNU extensions
2593 @item @emph{Syntax}:
2596 @item @emph{Arguments}:
2597 @multitable @columnfractions .15 .70
2598 @item @var{Z} @tab The type shall be @code{COMPLEX}.
2601 @item @emph{Return value}:
2602 The return value is of type @code{COMPLEX}.
2604 @item @emph{Example}:
2607 complex :: z = (2.0, 3.0)
2608 complex(8) :: dz = (2.71_8, -3.14_8)
2613 end program test_conjg
2616 @item @emph{Specific names}:
2617 @multitable @columnfractions .20 .20 .20 .25
2618 @item Name @tab Argument @tab Return type @tab Standard
2619 @item @code{DCONJG(Z)} @tab @code{COMPLEX(8) Z} @tab @code{COMPLEX(8)} @tab GNU extension
2626 @section @code{COS} --- Cosine function
2632 @cindex trigonometric function, cosine
2636 @item @emph{Description}:
2637 @code{COS(X)} computes the cosine of @var{X}.
2639 @item @emph{Standard}:
2640 Fortran 77 and later, has overloads that are GNU extensions
2645 @item @emph{Syntax}:
2646 @code{RESULT = COS(X)}
2648 @item @emph{Arguments}:
2649 @multitable @columnfractions .15 .70
2650 @item @var{X} @tab The type shall be @code{REAL} or
2654 @item @emph{Return value}:
2655 The return value is of the same type and kind as @var{X}. The real part
2656 of the result is in radians. If @var{X} is of the type @code{REAL},
2657 the return value lies in the range @math{ -1 \leq \cos (x) \leq 1}.
2659 @item @emph{Example}:
2664 end program test_cos
2667 @item @emph{Specific names}:
2668 @multitable @columnfractions .20 .20 .20 .25
2669 @item Name @tab Argument @tab Return type @tab Standard
2670 @item @code{DCOS(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
2671 @item @code{CCOS(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab Fortran 77 and later
2672 @item @code{ZCOS(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
2673 @item @code{CDCOS(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
2676 @item @emph{See also}:
2677 Inverse function: @ref{ACOS}
2684 @section @code{COSH} --- Hyperbolic cosine function
2687 @cindex hyperbolic cosine
2688 @cindex hyperbolic function, cosine
2689 @cindex cosine, hyperbolic
2692 @item @emph{Description}:
2693 @code{COSH(X)} computes the hyperbolic cosine of @var{X}.
2695 @item @emph{Standard}:
2696 Fortran 77 and later, for a complex argument Fortran 2008 or later
2701 @item @emph{Syntax}:
2704 @item @emph{Arguments}:
2705 @multitable @columnfractions .15 .70
2706 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
2709 @item @emph{Return value}:
2710 The return value has same type and kind as @var{X}. If @var{X} is
2711 complex, the imaginary part of the result is in radians. If @var{X}
2712 is @code{REAL}, the return value has a lower bound of one,
2713 @math{\cosh (x) \geq 1}.
2715 @item @emph{Example}:
2718 real(8) :: x = 1.0_8
2720 end program test_cosh
2723 @item @emph{Specific names}:
2724 @multitable @columnfractions .20 .20 .20 .25
2725 @item Name @tab Argument @tab Return type @tab Standard
2726 @item @code{DCOSH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
2729 @item @emph{See also}:
2730 Inverse function: @ref{ACOSH}
2737 @section @code{COUNT} --- Count function
2739 @cindex array, conditionally count elements
2740 @cindex array, element counting
2741 @cindex array, number of elements
2744 @item @emph{Description}:
2746 Counts the number of @code{.TRUE.} elements in a logical @var{MASK},
2747 or, if the @var{DIM} argument is supplied, counts the number of
2748 elements along each row of the array in the @var{DIM} direction.
2749 If the array has zero size, or all of the elements of @var{MASK} are
2750 @code{.FALSE.}, then the result is @code{0}.
2752 @item @emph{Standard}:
2753 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
2756 Transformational function
2758 @item @emph{Syntax}:
2759 @code{RESULT = COUNT(MASK [, DIM, KIND])}
2761 @item @emph{Arguments}:
2762 @multitable @columnfractions .15 .70
2763 @item @var{MASK} @tab The type shall be @code{LOGICAL}.
2764 @item @var{DIM} @tab (Optional) The type shall be @code{INTEGER}.
2765 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
2766 expression indicating the kind parameter of the result.
2769 @item @emph{Return value}:
2770 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
2771 @var{KIND} is absent, the return value is of default integer kind.
2772 If @var{DIM} is present, the result is an array with a rank one less
2773 than the rank of @var{ARRAY}, and a size corresponding to the shape
2774 of @var{ARRAY} with the @var{DIM} dimension removed.
2776 @item @emph{Example}:
2779 integer, dimension(2,3) :: a, b
2780 logical, dimension(2,3) :: mask
2781 a = reshape( (/ 1, 2, 3, 4, 5, 6 /), (/ 2, 3 /))
2782 b = reshape( (/ 0, 7, 3, 4, 5, 8 /), (/ 2, 3 /))
2783 print '(3i3)', a(1,:)
2784 print '(3i3)', a(2,:)
2786 print '(3i3)', b(1,:)
2787 print '(3i3)', b(2,:)
2790 print '(3l3)', mask(1,:)
2791 print '(3l3)', mask(2,:)
2793 print '(3i3)', count(mask)
2795 print '(3i3)', count(mask, 1)
2797 print '(3i3)', count(mask, 2)
2798 end program test_count
2805 @section @code{CPU_TIME} --- CPU elapsed time in seconds
2807 @cindex time, elapsed
2810 @item @emph{Description}:
2811 Returns a @code{REAL} value representing the elapsed CPU time in
2812 seconds. This is useful for testing segments of code to determine
2815 If a time source is available, time will be reported with microsecond
2816 resolution. If no time source is available, @var{TIME} is set to
2819 Note that @var{TIME} may contain a, system dependent, arbitrary offset
2820 and may not start with @code{0.0}. For @code{CPU_TIME}, the absolute
2821 value is meaningless, only differences between subsequent calls to
2822 this subroutine, as shown in the example below, should be used.
2825 @item @emph{Standard}:
2826 Fortran 95 and later
2831 @item @emph{Syntax}:
2832 @code{CALL CPU_TIME(TIME)}
2834 @item @emph{Arguments}:
2835 @multitable @columnfractions .15 .70
2836 @item @var{TIME} @tab The type shall be @code{REAL} with @code{INTENT(OUT)}.
2839 @item @emph{Return value}:
2842 @item @emph{Example}:
2844 program test_cpu_time
2845 real :: start, finish
2846 call cpu_time(start)
2847 ! put code to test here
2848 call cpu_time(finish)
2849 print '("Time = ",f6.3," seconds.")',finish-start
2850 end program test_cpu_time
2853 @item @emph{See also}:
2854 @ref{SYSTEM_CLOCK}, @ref{DATE_AND_TIME}
2860 @section @code{CSHIFT} --- Circular shift elements of an array
2862 @cindex array, shift circularly
2863 @cindex array, permutation
2864 @cindex array, rotate
2867 @item @emph{Description}:
2868 @code{CSHIFT(ARRAY, SHIFT [, DIM])} performs a circular shift on elements of
2869 @var{ARRAY} along the dimension of @var{DIM}. If @var{DIM} is omitted it is
2870 taken to be @code{1}. @var{DIM} is a scalar of type @code{INTEGER} in the
2871 range of @math{1 \leq DIM \leq n)} where @math{n} is the rank of @var{ARRAY}.
2872 If the rank of @var{ARRAY} is one, then all elements of @var{ARRAY} are shifted
2873 by @var{SHIFT} places. If rank is greater than one, then all complete rank one
2874 sections of @var{ARRAY} along the given dimension are shifted. Elements
2875 shifted out one end of each rank one section are shifted back in the other end.
2877 @item @emph{Standard}:
2878 Fortran 95 and later
2881 Transformational function
2883 @item @emph{Syntax}:
2884 @code{RESULT = CSHIFT(ARRAY, SHIFT [, DIM])}
2886 @item @emph{Arguments}:
2887 @multitable @columnfractions .15 .70
2888 @item @var{ARRAY} @tab Shall be an array of any type.
2889 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
2890 @item @var{DIM} @tab The type shall be @code{INTEGER}.
2893 @item @emph{Return value}:
2894 Returns an array of same type and rank as the @var{ARRAY} argument.
2896 @item @emph{Example}:
2899 integer, dimension(3,3) :: a
2900 a = reshape( (/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /), (/ 3, 3 /))
2901 print '(3i3)', a(1,:)
2902 print '(3i3)', a(2,:)
2903 print '(3i3)', a(3,:)
2904 a = cshift(a, SHIFT=(/1, 2, -1/), DIM=2)
2906 print '(3i3)', a(1,:)
2907 print '(3i3)', a(2,:)
2908 print '(3i3)', a(3,:)
2909 end program test_cshift
2916 @section @code{CTIME} --- Convert a time into a string
2918 @cindex time, conversion to string
2919 @cindex conversion, to string
2922 @item @emph{Description}:
2923 @code{CTIME} converts a system time value, such as returned by
2924 @code{TIME8()}, to a string of the form @samp{Sat Aug 19 18:13:14 1995}.
2926 This intrinsic is provided in both subroutine and function forms; however,
2927 only one form can be used in any given program unit.
2929 @item @emph{Standard}:
2933 Subroutine, function
2935 @item @emph{Syntax}:
2936 @multitable @columnfractions .80
2937 @item @code{CALL CTIME(TIME, RESULT)}.
2938 @item @code{RESULT = CTIME(TIME)}, (not recommended).
2941 @item @emph{Arguments}:
2942 @multitable @columnfractions .15 .70
2943 @item @var{TIME} @tab The type shall be of type @code{INTEGER(KIND=8)}.
2944 @item @var{RESULT} @tab The type shall be of type @code{CHARACTER} and
2948 @item @emph{Return value}:
2949 The converted date and time as a string.
2951 @item @emph{Example}:
2955 character(len=30) :: date
2958 ! Do something, main part of the program
2961 print *, 'Program was started on ', date
2962 end program test_ctime
2965 @item @emph{See Also}:
2966 @ref{GMTIME}, @ref{LTIME}, @ref{TIME}, @ref{TIME8}
2972 @section @code{DATE_AND_TIME} --- Date and time subroutine
2973 @fnindex DATE_AND_TIME
2974 @cindex date, current
2975 @cindex current date
2976 @cindex time, current
2977 @cindex current time
2980 @item @emph{Description}:
2981 @code{DATE_AND_TIME(DATE, TIME, ZONE, VALUES)} gets the corresponding date and
2982 time information from the real-time system clock. @var{DATE} is
2983 @code{INTENT(OUT)} and has form ccyymmdd. @var{TIME} is @code{INTENT(OUT)} and
2984 has form hhmmss.sss. @var{ZONE} is @code{INTENT(OUT)} and has form (+-)hhmm,
2985 representing the difference with respect to Coordinated Universal Time (UTC).
2986 Unavailable time and date parameters return blanks.
2988 @var{VALUES} is @code{INTENT(OUT)} and provides the following:
2990 @multitable @columnfractions .15 .30 .40
2991 @item @tab @code{VALUE(1)}: @tab The year
2992 @item @tab @code{VALUE(2)}: @tab The month
2993 @item @tab @code{VALUE(3)}: @tab The day of the month
2994 @item @tab @code{VALUE(4)}: @tab Time difference with UTC in minutes
2995 @item @tab @code{VALUE(5)}: @tab The hour of the day
2996 @item @tab @code{VALUE(6)}: @tab The minutes of the hour
2997 @item @tab @code{VALUE(7)}: @tab The seconds of the minute
2998 @item @tab @code{VALUE(8)}: @tab The milliseconds of the second
3001 @item @emph{Standard}:
3002 Fortran 95 and later
3007 @item @emph{Syntax}:
3008 @code{CALL DATE_AND_TIME([DATE, TIME, ZONE, VALUES])}
3010 @item @emph{Arguments}:
3011 @multitable @columnfractions .15 .70
3012 @item @var{DATE} @tab (Optional) The type shall be @code{CHARACTER(LEN=8)}
3013 or larger, and of default kind.
3014 @item @var{TIME} @tab (Optional) The type shall be @code{CHARACTER(LEN=10)}
3015 or larger, and of default kind.
3016 @item @var{ZONE} @tab (Optional) The type shall be @code{CHARACTER(LEN=5)}
3017 or larger, and of default kind.
3018 @item @var{VALUES}@tab (Optional) The type shall be @code{INTEGER(8)}.
3021 @item @emph{Return value}:
3024 @item @emph{Example}:
3026 program test_time_and_date
3027 character(8) :: date
3028 character(10) :: time
3029 character(5) :: zone
3030 integer,dimension(8) :: values
3031 ! using keyword arguments
3032 call date_and_time(date,time,zone,values)
3033 call date_and_time(DATE=date,ZONE=zone)
3034 call date_and_time(TIME=time)
3035 call date_and_time(VALUES=values)
3036 print '(a,2x,a,2x,a)', date, time, zone
3037 print '(8i5))', values
3038 end program test_time_and_date
3041 @item @emph{See also}:
3042 @ref{CPU_TIME}, @ref{SYSTEM_CLOCK}
3048 @section @code{DBLE} --- Double conversion function
3050 @cindex conversion, to real
3053 @item @emph{Description}:
3054 @code{DBLE(A)} Converts @var{A} to double precision real type.
3056 @item @emph{Standard}:
3057 Fortran 77 and later
3062 @item @emph{Syntax}:
3063 @code{RESULT = DBLE(A)}
3065 @item @emph{Arguments}:
3066 @multitable @columnfractions .15 .70
3067 @item @var{A} @tab The type shall be @code{INTEGER}, @code{REAL},
3071 @item @emph{Return value}:
3072 The return value is of type double precision real.
3074 @item @emph{Example}:
3079 complex :: z = (2.3,1.14)
3080 print *, dble(x), dble(i), dble(z)
3081 end program test_dble
3084 @item @emph{See also}:
3085 @ref{DFLOAT}, @ref{FLOAT}, @ref{REAL}
3091 @section @code{DCMPLX} --- Double complex conversion function
3093 @cindex complex numbers, conversion to
3094 @cindex conversion, to complex
3097 @item @emph{Description}:
3098 @code{DCMPLX(X [,Y])} returns a double complex number where @var{X} is
3099 converted to the real component. If @var{Y} is present it is converted to the
3100 imaginary component. If @var{Y} is not present then the imaginary component is
3101 set to 0.0. If @var{X} is complex then @var{Y} must not be present.
3103 @item @emph{Standard}:
3109 @item @emph{Syntax}:
3110 @code{RESULT = DCMPLX(X [, Y])}
3112 @item @emph{Arguments}:
3113 @multitable @columnfractions .15 .70
3114 @item @var{X} @tab The type may be @code{INTEGER}, @code{REAL},
3116 @item @var{Y} @tab (Optional if @var{X} is not @code{COMPLEX}.) May be
3117 @code{INTEGER} or @code{REAL}.
3120 @item @emph{Return value}:
3121 The return value is of type @code{COMPLEX(8)}
3123 @item @emph{Example}:
3133 print *, dcmplx(x,i)
3134 end program test_dcmplx
3141 @section @code{DFLOAT} --- Double conversion function
3143 @cindex conversion, to real
3146 @item @emph{Description}:
3147 @code{DFLOAT(A)} Converts @var{A} to double precision real type.
3149 @item @emph{Standard}:
3155 @item @emph{Syntax}:
3156 @code{RESULT = DFLOAT(A)}
3158 @item @emph{Arguments}:
3159 @multitable @columnfractions .15 .70
3160 @item @var{A} @tab The type shall be @code{INTEGER}.
3163 @item @emph{Return value}:
3164 The return value is of type double precision real.
3166 @item @emph{Example}:
3171 end program test_dfloat
3174 @item @emph{See also}:
3175 @ref{DBLE}, @ref{FLOAT}, @ref{REAL}
3181 @section @code{DIGITS} --- Significant binary digits function
3183 @cindex model representation, significant digits
3186 @item @emph{Description}:
3187 @code{DIGITS(X)} returns the number of significant binary digits of the internal
3188 model representation of @var{X}. For example, on a system using a 32-bit
3189 floating point representation, a default real number would likely return 24.
3191 @item @emph{Standard}:
3192 Fortran 95 and later
3197 @item @emph{Syntax}:
3198 @code{RESULT = DIGITS(X)}
3200 @item @emph{Arguments}:
3201 @multitable @columnfractions .15 .70
3202 @item @var{X} @tab The type may be @code{INTEGER} or @code{REAL}.
3205 @item @emph{Return value}:
3206 The return value is of type @code{INTEGER}.
3208 @item @emph{Example}:
3211 integer :: i = 12345
3217 end program test_digits
3224 @section @code{DIM} --- Positive difference
3228 @cindex positive difference
3231 @item @emph{Description}:
3232 @code{DIM(X,Y)} returns the difference @code{X-Y} if the result is positive;
3233 otherwise returns zero.
3235 @item @emph{Standard}:
3236 Fortran 77 and later
3241 @item @emph{Syntax}:
3242 @code{RESULT = DIM(X, Y)}
3244 @item @emph{Arguments}:
3245 @multitable @columnfractions .15 .70
3246 @item @var{X} @tab The type shall be @code{INTEGER} or @code{REAL}
3247 @item @var{Y} @tab The type shall be the same type and kind as @var{X}.
3250 @item @emph{Return value}:
3251 The return value is of type @code{INTEGER} or @code{REAL}.
3253 @item @emph{Example}:
3259 x = dim(4.345_8, 2.111_8)
3262 end program test_dim
3265 @item @emph{Specific names}:
3266 @multitable @columnfractions .20 .20 .20 .25
3267 @item Name @tab Argument @tab Return type @tab Standard
3268 @item @code{IDIM(X,Y)} @tab @code{INTEGER(4) X,Y} @tab @code{INTEGER(4)} @tab Fortran 77 and later
3269 @item @code{DDIM(X,Y)} @tab @code{REAL(8) X,Y} @tab @code{REAL(8)} @tab Fortran 77 and later
3276 @section @code{DOT_PRODUCT} --- Dot product function
3277 @fnindex DOT_PRODUCT
3279 @cindex vector product
3280 @cindex product, vector
3283 @item @emph{Description}:
3284 @code{DOT_PRODUCT(VECTOR_A, VECTOR_B)} computes the dot product multiplication
3285 of two vectors @var{VECTOR_A} and @var{VECTOR_B}. The two vectors may be
3286 either numeric or logical and must be arrays of rank one and of equal size. If
3287 the vectors are @code{INTEGER} or @code{REAL}, the result is
3288 @code{SUM(VECTOR_A*VECTOR_B)}. If the vectors are @code{COMPLEX}, the result
3289 is @code{SUM(CONJG(VECTOR_A)*VECTOR_B)}. If the vectors are @code{LOGICAL},
3290 the result is @code{ANY(VECTOR_A .AND. VECTOR_B)}.
3292 @item @emph{Standard}:
3293 Fortran 95 and later
3296 Transformational function
3298 @item @emph{Syntax}:
3299 @code{RESULT = DOT_PRODUCT(VECTOR_A, VECTOR_B)}
3301 @item @emph{Arguments}:
3302 @multitable @columnfractions .15 .70
3303 @item @var{VECTOR_A} @tab The type shall be numeric or @code{LOGICAL}, rank 1.
3304 @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.
3307 @item @emph{Return value}:
3308 If the arguments are numeric, the return value is a scalar of numeric type,
3309 @code{INTEGER}, @code{REAL}, or @code{COMPLEX}. If the arguments are
3310 @code{LOGICAL}, the return value is @code{.TRUE.} or @code{.FALSE.}.
3312 @item @emph{Example}:
3314 program test_dot_prod
3315 integer, dimension(3) :: a, b
3322 print *, dot_product(a,b)
3323 end program test_dot_prod
3330 @section @code{DPROD} --- Double product function
3332 @cindex product, double-precision
3335 @item @emph{Description}:
3336 @code{DPROD(X,Y)} returns the product @code{X*Y}.
3338 @item @emph{Standard}:
3339 Fortran 77 and later
3344 @item @emph{Syntax}:
3345 @code{RESULT = DPROD(X, Y)}
3347 @item @emph{Arguments}:
3348 @multitable @columnfractions .15 .70
3349 @item @var{X} @tab The type shall be @code{REAL}.
3350 @item @var{Y} @tab The type shall be @code{REAL}.
3353 @item @emph{Return value}:
3354 The return value is of type @code{REAL(8)}.
3356 @item @emph{Example}:
3364 end program test_dprod
3371 @section @code{DREAL} --- Double real part function
3373 @cindex complex numbers, real part
3376 @item @emph{Description}:
3377 @code{DREAL(Z)} returns the real part of complex variable @var{Z}.
3379 @item @emph{Standard}:
3385 @item @emph{Syntax}:
3386 @code{RESULT = DREAL(A)}
3388 @item @emph{Arguments}:
3389 @multitable @columnfractions .15 .70
3390 @item @var{A} @tab The type shall be @code{COMPLEX(8)}.
3393 @item @emph{Return value}:
3394 The return value is of type @code{REAL(8)}.
3396 @item @emph{Example}:
3399 complex(8) :: z = (1.3_8,7.2_8)
3401 end program test_dreal
3404 @item @emph{See also}:
3412 @section @code{DTIME} --- Execution time subroutine (or function)
3414 @cindex time, elapsed
3415 @cindex elapsed time
3418 @item @emph{Description}:
3419 @code{DTIME(VALUES, TIME)} initially returns the number of seconds of runtime
3420 since the start of the process's execution in @var{TIME}. @var{VALUES}
3421 returns the user and system components of this time in @code{VALUES(1)} and
3422 @code{VALUES(2)} respectively. @var{TIME} is equal to @code{VALUES(1) +
3425 Subsequent invocations of @code{DTIME} return values accumulated since the
3426 previous invocation.
3428 On some systems, the underlying timings are represented using types with
3429 sufficiently small limits that overflows (wrap around) are possible, such as
3430 32-bit types. Therefore, the values returned by this intrinsic might be, or
3431 become, negative, or numerically less than previous values, during a single
3432 run of the compiled program.
3434 Please note, that this implementation is thread safe if used within OpenMP
3435 directives, i.e., its state will be consistent while called from multiple
3436 threads. However, if @code{DTIME} is called from multiple threads, the result
3437 is still the time since the last invocation. This may not give the intended
3438 results. If possible, use @code{CPU_TIME} instead.
3440 This intrinsic is provided in both subroutine and function forms; however,
3441 only one form can be used in any given program unit.
3443 @var{VALUES} and @var{TIME} are @code{INTENT(OUT)} and provide the following:
3445 @multitable @columnfractions .15 .30 .40
3446 @item @tab @code{VALUES(1)}: @tab User time in seconds.
3447 @item @tab @code{VALUES(2)}: @tab System time in seconds.
3448 @item @tab @code{TIME}: @tab Run time since start in seconds.
3451 @item @emph{Standard}:
3455 Subroutine, function
3457 @item @emph{Syntax}:
3458 @multitable @columnfractions .80
3459 @item @code{CALL DTIME(VALUES, TIME)}.
3460 @item @code{TIME = DTIME(VALUES)}, (not recommended).
3463 @item @emph{Arguments}:
3464 @multitable @columnfractions .15 .70
3465 @item @var{VALUES}@tab The type shall be @code{REAL(4), DIMENSION(2)}.
3466 @item @var{TIME}@tab The type shall be @code{REAL(4)}.
3469 @item @emph{Return value}:
3470 Elapsed time in seconds since the last invocation or since the start of program
3471 execution if not called before.
3473 @item @emph{Example}:
3477 real, dimension(2) :: tarray
3479 call dtime(tarray, result)
3483 do i=1,100000000 ! Just a delay
3486 call dtime(tarray, result)
3490 end program test_dtime
3493 @item @emph{See also}:
3501 @section @code{EOSHIFT} --- End-off shift elements of an array
3503 @cindex array, shift
3506 @item @emph{Description}:
3507 @code{EOSHIFT(ARRAY, SHIFT[, BOUNDARY, DIM])} performs an end-off shift on
3508 elements of @var{ARRAY} along the dimension of @var{DIM}. If @var{DIM} is
3509 omitted it is taken to be @code{1}. @var{DIM} is a scalar of type
3510 @code{INTEGER} in the range of @math{1 \leq DIM \leq n)} where @math{n} is the
3511 rank of @var{ARRAY}. If the rank of @var{ARRAY} is one, then all elements of
3512 @var{ARRAY} are shifted by @var{SHIFT} places. If rank is greater than one,
3513 then all complete rank one sections of @var{ARRAY} along the given dimension are
3514 shifted. Elements shifted out one end of each rank one section are dropped. If
3515 @var{BOUNDARY} is present then the corresponding value of from @var{BOUNDARY}
3516 is copied back in the other end. If @var{BOUNDARY} is not present then the
3517 following are copied in depending on the type of @var{ARRAY}.
3519 @multitable @columnfractions .15 .80
3520 @item @emph{Array Type} @tab @emph{Boundary Value}
3521 @item Numeric @tab 0 of the type and kind of @var{ARRAY}.
3522 @item Logical @tab @code{.FALSE.}.
3523 @item Character(@var{len}) @tab @var{len} blanks.
3526 @item @emph{Standard}:
3527 Fortran 95 and later
3530 Transformational function
3532 @item @emph{Syntax}:
3533 @code{RESULT = EOSHIFT(ARRAY, SHIFT [, BOUNDARY, DIM])}
3535 @item @emph{Arguments}:
3536 @multitable @columnfractions .15 .70
3537 @item @var{ARRAY} @tab May be any type, not scalar.
3538 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
3539 @item @var{BOUNDARY} @tab Same type as @var{ARRAY}.
3540 @item @var{DIM} @tab The type shall be @code{INTEGER}.
3543 @item @emph{Return value}:
3544 Returns an array of same type and rank as the @var{ARRAY} argument.
3546 @item @emph{Example}:
3548 program test_eoshift
3549 integer, dimension(3,3) :: a
3550 a = reshape( (/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /), (/ 3, 3 /))
3551 print '(3i3)', a(1,:)
3552 print '(3i3)', a(2,:)
3553 print '(3i3)', a(3,:)
3554 a = EOSHIFT(a, SHIFT=(/1, 2, 1/), BOUNDARY=-5, DIM=2)
3556 print '(3i3)', a(1,:)
3557 print '(3i3)', a(2,:)
3558 print '(3i3)', a(3,:)
3559 end program test_eoshift
3566 @section @code{EPSILON} --- Epsilon function
3568 @cindex model representation, epsilon
3571 @item @emph{Description}:
3572 @code{EPSILON(X)} returns the smallest number @var{E} of the same kind
3573 as @var{X} such that @math{1 + E > 1}.
3575 @item @emph{Standard}:
3576 Fortran 95 and later
3581 @item @emph{Syntax}:
3582 @code{RESULT = EPSILON(X)}
3584 @item @emph{Arguments}:
3585 @multitable @columnfractions .15 .70
3586 @item @var{X} @tab The type shall be @code{REAL}.
3589 @item @emph{Return value}:
3590 The return value is of same type as the argument.
3592 @item @emph{Example}:
3594 program test_epsilon
3599 end program test_epsilon
3606 @section @code{ERF} --- Error function
3608 @cindex error function
3611 @item @emph{Description}:
3612 @code{ERF(X)} computes the error function of @var{X}.
3614 @item @emph{Standard}:
3615 Fortran 2008 and later
3620 @item @emph{Syntax}:
3621 @code{RESULT = ERF(X)}
3623 @item @emph{Arguments}:
3624 @multitable @columnfractions .15 .70
3625 @item @var{X} @tab The type shall be @code{REAL}.
3628 @item @emph{Return value}:
3629 The return value is of type @code{REAL}, of the same kind as
3630 @var{X} and lies in the range @math{-1 \leq erf (x) \leq 1 }.
3632 @item @emph{Example}:
3635 real(8) :: x = 0.17_8
3637 end program test_erf
3640 @item @emph{Specific names}:
3641 @multitable @columnfractions .20 .20 .20 .25
3642 @item Name @tab Argument @tab Return type @tab Standard
3643 @item @code{DERF(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
3650 @section @code{ERFC} --- Error function
3652 @cindex error function, complementary
3655 @item @emph{Description}:
3656 @code{ERFC(X)} computes the complementary error function of @var{X}.
3658 @item @emph{Standard}:
3659 Fortran 2008 and later
3664 @item @emph{Syntax}:
3665 @code{RESULT = ERFC(X)}
3667 @item @emph{Arguments}:
3668 @multitable @columnfractions .15 .70
3669 @item @var{X} @tab The type shall be @code{REAL}.
3672 @item @emph{Return value}:
3673 The return value is of type @code{REAL} and of the same kind as @var{X}.
3674 It lies in the range @math{ 0 \leq erfc (x) \leq 2 }.
3676 @item @emph{Example}:
3679 real(8) :: x = 0.17_8
3681 end program test_erfc
3684 @item @emph{Specific names}:
3685 @multitable @columnfractions .20 .20 .20 .25
3686 @item Name @tab Argument @tab Return type @tab Standard
3687 @item @code{DERFC(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
3694 @section @code{ERFC_SCALED} --- Error function
3695 @fnindex ERFC_SCALED
3696 @cindex error function, complementary, exponentially-scaled
3699 @item @emph{Description}:
3700 @code{ERFC_SCALED(X)} computes the exponentially-scaled complementary
3701 error function of @var{X}.
3703 @item @emph{Standard}:
3704 Fortran 2008 and later
3709 @item @emph{Syntax}:
3710 @code{RESULT = ERFC_SCALED(X)}
3712 @item @emph{Arguments}:
3713 @multitable @columnfractions .15 .70
3714 @item @var{X} @tab The type shall be @code{REAL}.
3717 @item @emph{Return value}:
3718 The return value is of type @code{REAL} and of the same kind as @var{X}.
3720 @item @emph{Example}:
3722 program test_erfc_scaled
3723 real(8) :: x = 0.17_8
3725 end program test_erfc_scaled
3732 @section @code{ETIME} --- Execution time subroutine (or function)
3734 @cindex time, elapsed
3737 @item @emph{Description}:
3738 @code{ETIME(VALUES, TIME)} returns the number of seconds of runtime
3739 since the start of the process's execution in @var{TIME}. @var{VALUES}
3740 returns the user and system components of this time in @code{VALUES(1)} and
3741 @code{VALUES(2)} respectively. @var{TIME} is equal to @code{VALUES(1) + VALUES(2)}.
3743 On some systems, the underlying timings are represented using types with
3744 sufficiently small limits that overflows (wrap around) are possible, such as
3745 32-bit types. Therefore, the values returned by this intrinsic might be, or
3746 become, negative, or numerically less than previous values, during a single
3747 run of the compiled program.
3749 This intrinsic is provided in both subroutine and function forms; however,
3750 only one form can be used in any given program unit.
3752 @var{VALUES} and @var{TIME} are @code{INTENT(OUT)} and provide the following:
3754 @multitable @columnfractions .15 .30 .60
3755 @item @tab @code{VALUES(1)}: @tab User time in seconds.
3756 @item @tab @code{VALUES(2)}: @tab System time in seconds.
3757 @item @tab @code{TIME}: @tab Run time since start in seconds.
3760 @item @emph{Standard}:
3764 Subroutine, function
3766 @item @emph{Syntax}:
3767 @multitable @columnfractions .80
3768 @item @code{CALL ETIME(VALUES, TIME)}.
3769 @item @code{TIME = ETIME(VALUES)}, (not recommended).
3772 @item @emph{Arguments}:
3773 @multitable @columnfractions .15 .70
3774 @item @var{VALUES}@tab The type shall be @code{REAL(4), DIMENSION(2)}.
3775 @item @var{TIME}@tab The type shall be @code{REAL(4)}.
3778 @item @emph{Return value}:
3779 Elapsed time in seconds since the start of program execution.
3781 @item @emph{Example}:
3785 real, dimension(2) :: tarray
3787 call ETIME(tarray, result)
3791 do i=1,100000000 ! Just a delay
3794 call ETIME(tarray, result)
3798 end program test_etime
3801 @item @emph{See also}:
3809 @section @code{EXIT} --- Exit the program with status.
3811 @cindex program termination
3812 @cindex terminate program
3815 @item @emph{Description}:
3816 @code{EXIT} causes immediate termination of the program with status. If status
3817 is omitted it returns the canonical @emph{success} for the system. All Fortran
3818 I/O units are closed.
3820 @item @emph{Standard}:
3826 @item @emph{Syntax}:
3827 @code{CALL EXIT([STATUS])}
3829 @item @emph{Arguments}:
3830 @multitable @columnfractions .15 .70
3831 @item @var{STATUS} @tab Shall be an @code{INTEGER} of the default kind.
3834 @item @emph{Return value}:
3835 @code{STATUS} is passed to the parent process on exit.
3837 @item @emph{Example}:
3840 integer :: STATUS = 0
3841 print *, 'This program is going to exit.'
3843 end program test_exit
3846 @item @emph{See also}:
3847 @ref{ABORT}, @ref{KILL}
3853 @section @code{EXP} --- Exponential function
3859 @cindex exponential function
3860 @cindex logarithmic function, inverse
3863 @item @emph{Description}:
3864 @code{EXP(X)} computes the base @math{e} exponential of @var{X}.
3866 @item @emph{Standard}:
3867 Fortran 77 and later, has overloads that are GNU extensions
3872 @item @emph{Syntax}:
3873 @code{RESULT = EXP(X)}
3875 @item @emph{Arguments}:
3876 @multitable @columnfractions .15 .70
3877 @item @var{X} @tab The type shall be @code{REAL} or
3881 @item @emph{Return value}:
3882 The return value has same type and kind as @var{X}.
3884 @item @emph{Example}:
3889 end program test_exp
3892 @item @emph{Specific names}:
3893 @multitable @columnfractions .20 .20 .20 .25
3894 @item Name @tab Argument @tab Return type @tab Standard
3895 @item @code{DEXP(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
3896 @item @code{CEXP(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab Fortran 77 and later
3897 @item @code{ZEXP(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
3898 @item @code{CDEXP(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
3905 @section @code{EXPONENT} --- Exponent function
3907 @cindex real number, exponent
3908 @cindex floating point, exponent
3911 @item @emph{Description}:
3912 @code{EXPONENT(X)} returns the value of the exponent part of @var{X}. If @var{X}
3913 is zero the value returned is zero.
3915 @item @emph{Standard}:
3916 Fortran 95 and later
3921 @item @emph{Syntax}:
3922 @code{RESULT = EXPONENT(X)}
3924 @item @emph{Arguments}:
3925 @multitable @columnfractions .15 .70
3926 @item @var{X} @tab The type shall be @code{REAL}.
3929 @item @emph{Return value}:
3930 The return value is of type default @code{INTEGER}.
3932 @item @emph{Example}:
3934 program test_exponent
3939 print *, exponent(0.0)
3940 end program test_exponent
3947 @section @code{FDATE} --- Get the current time as a string
3949 @cindex time, current
3950 @cindex current time
3951 @cindex date, current
3952 @cindex current date
3955 @item @emph{Description}:
3956 @code{FDATE(DATE)} returns the current date (using the same format as
3957 @code{CTIME}) in @var{DATE}. It is equivalent to @code{CALL CTIME(DATE,
3960 This intrinsic is provided in both subroutine and function forms; however,
3961 only one form can be used in any given program unit.
3963 @var{DATE} is an @code{INTENT(OUT)} @code{CHARACTER} variable of the
3966 @item @emph{Standard}:
3970 Subroutine, function
3972 @item @emph{Syntax}:
3973 @multitable @columnfractions .80
3974 @item @code{CALL FDATE(DATE)}.
3975 @item @code{DATE = FDATE()}, (not recommended).
3978 @item @emph{Arguments}:
3979 @multitable @columnfractions .15 .70
3980 @item @var{DATE}@tab The type shall be of type @code{CHARACTER} of the
3984 @item @emph{Return value}:
3985 The current date as a string.
3987 @item @emph{Example}:
3991 character(len=30) :: date
3993 print *, 'Program started on ', date
3994 do i = 1, 100000000 ! Just a delay
3998 print *, 'Program ended on ', date
3999 end program test_fdate
4006 @section @code{FLOAT} --- Convert integer to default real
4008 @cindex conversion, to real
4011 @item @emph{Description}:
4012 @code{FLOAT(A)} converts the integer @var{A} to a default real value.
4014 @item @emph{Standard}:
4015 Fortran 77 and later
4020 @item @emph{Syntax}:
4021 @code{RESULT = FLOAT(A)}
4023 @item @emph{Arguments}:
4024 @multitable @columnfractions .15 .70
4025 @item @var{A} @tab The type shall be @code{INTEGER}.
4028 @item @emph{Return value}:
4029 The return value is of type default @code{REAL}.
4031 @item @emph{Example}:
4035 if (float(i) /= 1.) call abort
4036 end program test_float
4039 @item @emph{See also}:
4040 @ref{DBLE}, @ref{DFLOAT}, @ref{REAL}
4046 @section @code{FGET} --- Read a single character in stream mode from stdin
4048 @cindex read character, stream mode
4049 @cindex stream mode, read character
4050 @cindex file operation, read character
4053 @item @emph{Description}:
4054 Read a single character in stream mode from stdin by bypassing normal
4055 formatted output. Stream I/O should not be mixed with normal record-oriented
4056 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
4058 This intrinsic is provided in both subroutine and function forms; however,
4059 only one form can be used in any given program unit.
4061 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
4062 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
4063 Programmers should consider the use of new stream IO feature in new code
4064 for future portability. See also @ref{Fortran 2003 status}.
4066 @item @emph{Standard}:
4070 Subroutine, function
4072 @item @emph{Syntax}:
4073 @code{CALL FGET(C [, STATUS])}
4075 @item @emph{Arguments}:
4076 @multitable @columnfractions .15 .70
4077 @item @var{C} @tab The type shall be @code{CHARACTER} and of default
4079 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
4080 Returns 0 on success, -1 on end-of-file, and a system specific positive
4081 error code otherwise.
4084 @item @emph{Example}:
4087 INTEGER, PARAMETER :: strlen = 100
4088 INTEGER :: status, i = 1
4089 CHARACTER(len=strlen) :: str = ""
4091 WRITE (*,*) 'Enter text:'
4093 CALL fget(str(i:i), status)
4094 if (status /= 0 .OR. i > strlen) exit
4097 WRITE (*,*) TRIM(str)
4101 @item @emph{See also}:
4102 @ref{FGETC}, @ref{FPUT}, @ref{FPUTC}
4108 @section @code{FGETC} --- Read a single character in stream mode
4110 @cindex read character, stream mode
4111 @cindex stream mode, read character
4112 @cindex file operation, read character
4115 @item @emph{Description}:
4116 Read a single character in stream mode by bypassing normal formatted output.
4117 Stream I/O should not be mixed with normal record-oriented (formatted or
4118 unformatted) I/O on the same unit; the results are unpredictable.
4120 This intrinsic is provided in both subroutine and function forms; however,
4121 only one form can be used in any given program unit.
4123 Note that the @code{FGET} intrinsic is provided for backwards compatibility
4124 with @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
4125 Programmers should consider the use of new stream IO feature in new code
4126 for future portability. See also @ref{Fortran 2003 status}.
4128 @item @emph{Standard}:
4132 Subroutine, function
4134 @item @emph{Syntax}:
4135 @code{CALL FGETC(UNIT, C [, STATUS])}
4137 @item @emph{Arguments}:
4138 @multitable @columnfractions .15 .70
4139 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
4140 @item @var{C} @tab The type shall be @code{CHARACTER} and of default
4142 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
4143 Returns 0 on success, -1 on end-of-file and a system specific positive
4144 error code otherwise.
4147 @item @emph{Example}:
4150 INTEGER :: fd = 42, status
4153 OPEN(UNIT=fd, FILE="/etc/passwd", ACTION="READ", STATUS = "OLD")
4155 CALL fgetc(fd, c, status)
4156 IF (status /= 0) EXIT
4163 @item @emph{See also}:
4164 @ref{FGET}, @ref{FPUT}, @ref{FPUTC}
4170 @section @code{FLOOR} --- Integer floor function
4173 @cindex rounding, floor
4176 @item @emph{Description}:
4177 @code{FLOOR(A)} returns the greatest integer less than or equal to @var{X}.
4179 @item @emph{Standard}:
4180 Fortran 95 and later
4185 @item @emph{Syntax}:
4186 @code{RESULT = FLOOR(A [, KIND])}
4188 @item @emph{Arguments}:
4189 @multitable @columnfractions .15 .70
4190 @item @var{A} @tab The type shall be @code{REAL}.
4191 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
4192 expression indicating the kind parameter of the result.
4195 @item @emph{Return value}:
4196 The return value is of type @code{INTEGER(KIND)} if @var{KIND} is present
4197 and of default-kind @code{INTEGER} otherwise.
4199 @item @emph{Example}:
4204 print *, floor(x) ! returns 63
4205 print *, floor(y) ! returns -64
4206 end program test_floor
4209 @item @emph{See also}:
4210 @ref{CEILING}, @ref{NINT}
4217 @section @code{FLUSH} --- Flush I/O unit(s)
4219 @cindex file operation, flush
4222 @item @emph{Description}:
4223 Flushes Fortran unit(s) currently open for output. Without the optional
4224 argument, all units are flushed, otherwise just the unit specified.
4226 @item @emph{Standard}:
4232 @item @emph{Syntax}:
4233 @code{CALL FLUSH(UNIT)}
4235 @item @emph{Arguments}:
4236 @multitable @columnfractions .15 .70
4237 @item @var{UNIT} @tab (Optional) The type shall be @code{INTEGER}.
4241 Beginning with the Fortran 2003 standard, there is a @code{FLUSH}
4242 statement that should be preferred over the @code{FLUSH} intrinsic.
4249 @section @code{FNUM} --- File number function
4251 @cindex file operation, file number
4254 @item @emph{Description}:
4255 @code{FNUM(UNIT)} returns the POSIX file descriptor number corresponding to the
4256 open Fortran I/O unit @code{UNIT}.
4258 @item @emph{Standard}:
4264 @item @emph{Syntax}:
4265 @code{RESULT = FNUM(UNIT)}
4267 @item @emph{Arguments}:
4268 @multitable @columnfractions .15 .70
4269 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
4272 @item @emph{Return value}:
4273 The return value is of type @code{INTEGER}
4275 @item @emph{Example}:
4279 open (unit=10, status = "scratch")
4283 end program test_fnum
4290 @section @code{FPUT} --- Write a single character in stream mode to stdout
4292 @cindex write character, stream mode
4293 @cindex stream mode, write character
4294 @cindex file operation, write character
4297 @item @emph{Description}:
4298 Write a single character in stream mode to stdout by bypassing normal
4299 formatted output. Stream I/O should not be mixed with normal record-oriented
4300 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
4302 This intrinsic is provided in both subroutine and function forms; however,
4303 only one form can be used in any given program unit.
4305 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
4306 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
4307 Programmers should consider the use of new stream IO feature in new code
4308 for future portability. See also @ref{Fortran 2003 status}.
4310 @item @emph{Standard}:
4314 Subroutine, function
4316 @item @emph{Syntax}:
4317 @code{CALL FPUT(C [, STATUS])}
4319 @item @emph{Arguments}:
4320 @multitable @columnfractions .15 .70
4321 @item @var{C} @tab The type shall be @code{CHARACTER} and of default
4323 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
4324 Returns 0 on success, -1 on end-of-file and a system specific positive
4325 error code otherwise.
4328 @item @emph{Example}:
4331 CHARACTER(len=10) :: str = "gfortran"
4333 DO i = 1, len_trim(str)
4339 @item @emph{See also}:
4340 @ref{FPUTC}, @ref{FGET}, @ref{FGETC}
4346 @section @code{FPUTC} --- Write a single character in stream mode
4348 @cindex write character, stream mode
4349 @cindex stream mode, write character
4350 @cindex file operation, write character
4353 @item @emph{Description}:
4354 Write a single character in stream mode by bypassing normal formatted
4355 output. Stream I/O should not be mixed with normal record-oriented
4356 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
4358 This intrinsic is provided in both subroutine and function forms; however,
4359 only one form can be used in any given program unit.
4361 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
4362 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
4363 Programmers should consider the use of new stream IO feature in new code
4364 for future portability. See also @ref{Fortran 2003 status}.
4366 @item @emph{Standard}:
4370 Subroutine, function
4372 @item @emph{Syntax}:
4373 @code{CALL FPUTC(UNIT, C [, STATUS])}
4375 @item @emph{Arguments}:
4376 @multitable @columnfractions .15 .70
4377 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
4378 @item @var{C} @tab The type shall be @code{CHARACTER} and of default
4380 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
4381 Returns 0 on success, -1 on end-of-file and a system specific positive
4382 error code otherwise.
4385 @item @emph{Example}:
4388 CHARACTER(len=10) :: str = "gfortran"
4389 INTEGER :: fd = 42, i
4391 OPEN(UNIT = fd, FILE = "out", ACTION = "WRITE", STATUS="NEW")
4392 DO i = 1, len_trim(str)
4393 CALL fputc(fd, str(i:i))
4399 @item @emph{See also}:
4400 @ref{FPUT}, @ref{FGET}, @ref{FGETC}
4406 @section @code{FRACTION} --- Fractional part of the model representation
4408 @cindex real number, fraction
4409 @cindex floating point, fraction
4412 @item @emph{Description}:
4413 @code{FRACTION(X)} returns the fractional part of the model
4414 representation of @code{X}.
4416 @item @emph{Standard}:
4417 Fortran 95 and later
4422 @item @emph{Syntax}:
4423 @code{Y = FRACTION(X)}
4425 @item @emph{Arguments}:
4426 @multitable @columnfractions .15 .70
4427 @item @var{X} @tab The type of the argument shall be a @code{REAL}.
4430 @item @emph{Return value}:
4431 The return value is of the same type and kind as the argument.
4432 The fractional part of the model representation of @code{X} is returned;
4433 it is @code{X * RADIX(X)**(-EXPONENT(X))}.
4435 @item @emph{Example}:
4437 program test_fraction
4440 print *, fraction(x), x * radix(x)**(-exponent(x))
4441 end program test_fraction
4449 @section @code{FREE} --- Frees memory
4451 @cindex pointer, cray
4454 @item @emph{Description}:
4455 Frees memory previously allocated by @code{MALLOC()}. The @code{FREE}
4456 intrinsic is an extension intended to be used with Cray pointers, and is
4457 provided in GNU Fortran to allow user to compile legacy code. For
4458 new code using Fortran 95 pointers, the memory de-allocation intrinsic is
4461 @item @emph{Standard}:
4467 @item @emph{Syntax}:
4468 @code{CALL FREE(PTR)}
4470 @item @emph{Arguments}:
4471 @multitable @columnfractions .15 .70
4472 @item @var{PTR} @tab The type shall be @code{INTEGER}. It represents the
4473 location of the memory that should be de-allocated.
4476 @item @emph{Return value}:
4479 @item @emph{Example}:
4480 See @code{MALLOC} for an example.
4482 @item @emph{See also}:
4489 @section @code{FSEEK} --- Low level file positioning subroutine
4491 @cindex file operation, seek
4492 @cindex file operation, position
4495 @item @emph{Description}:
4496 Moves @var{UNIT} to the specified @var{OFFSET}. If @var{WHENCE}
4497 is set to 0, the @var{OFFSET} is taken as an absolute value @code{SEEK_SET},
4498 if set to 1, @var{OFFSET} is taken to be relative to the current position
4499 @code{SEEK_CUR}, and if set to 2 relative to the end of the file @code{SEEK_END}.
4500 On error, @var{STATUS} is set to a nonzero value. If @var{STATUS} the seek
4503 This intrinsic routine is not fully backwards compatible with @command{g77}.
4504 In @command{g77}, the @code{FSEEK} takes a statement label instead of a
4505 @var{STATUS} variable. If FSEEK is used in old code, change
4507 CALL FSEEK(UNIT, OFFSET, WHENCE, *label)
4512 CALL FSEEK(UNIT, OFFSET, WHENCE, status)
4513 IF (status /= 0) GOTO label
4516 Please note that GNU Fortran provides the Fortran 2003 Stream facility.
4517 Programmers should consider the use of new stream IO feature in new code
4518 for future portability. See also @ref{Fortran 2003 status}.
4520 @item @emph{Standard}:
4526 @item @emph{Syntax}:
4527 @code{CALL FSEEK(UNIT, OFFSET, WHENCE[, STATUS])}
4529 @item @emph{Arguments}:
4530 @multitable @columnfractions .15 .70
4531 @item @var{UNIT} @tab Shall be a scalar of type @code{INTEGER}.
4532 @item @var{OFFSET} @tab Shall be a scalar of type @code{INTEGER}.
4533 @item @var{WHENCE} @tab Shall be a scalar of type @code{INTEGER}.
4534 Its value shall be either 0, 1 or 2.
4535 @item @var{STATUS} @tab (Optional) shall be a scalar of type
4539 @item @emph{Example}:
4542 INTEGER, PARAMETER :: SEEK_SET = 0, SEEK_CUR = 1, SEEK_END = 2
4543 INTEGER :: fd, offset, ierr
4549 OPEN(UNIT=fd, FILE="fseek.test")
4550 CALL FSEEK(fd, offset, SEEK_SET, ierr) ! move to OFFSET
4551 print *, FTELL(fd), ierr
4553 CALL FSEEK(fd, 0, SEEK_END, ierr) ! move to end
4554 print *, FTELL(fd), ierr
4556 CALL FSEEK(fd, 0, SEEK_SET, ierr) ! move to beginning
4557 print *, FTELL(fd), ierr
4563 @item @emph{See also}:
4570 @section @code{FSTAT} --- Get file status
4572 @cindex file system, file status
4575 @item @emph{Description}:
4576 @code{FSTAT} is identical to @ref{STAT}, except that information about an
4577 already opened file is obtained.
4579 The elements in @code{VALUES} are the same as described by @ref{STAT}.
4581 This intrinsic is provided in both subroutine and function forms; however,
4582 only one form can be used in any given program unit.
4584 @item @emph{Standard}:
4588 Subroutine, function
4590 @item @emph{Syntax}:
4591 @code{CALL FSTAT(UNIT, VALUES [, STATUS])}
4593 @item @emph{Arguments}:
4594 @multitable @columnfractions .15 .70
4595 @item @var{UNIT} @tab An open I/O unit number of type @code{INTEGER}.
4596 @item @var{VALUES} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
4597 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}. Returns 0
4598 on success and a system specific error code otherwise.
4601 @item @emph{Example}:
4602 See @ref{STAT} for an example.
4604 @item @emph{See also}:
4605 To stat a link: @ref{LSTAT}, to stat a file: @ref{STAT}
4611 @section @code{FTELL} --- Current stream position
4613 @cindex file operation, position
4616 @item @emph{Description}:
4617 Retrieves the current position within an open file.
4619 This intrinsic is provided in both subroutine and function forms; however,
4620 only one form can be used in any given program unit.
4622 @item @emph{Standard}:
4626 Subroutine, function
4628 @item @emph{Syntax}:
4629 @multitable @columnfractions .80
4630 @item @code{CALL FTELL(UNIT, OFFSET)}
4631 @item @code{OFFSET = FTELL(UNIT)}
4634 @item @emph{Arguments}:
4635 @multitable @columnfractions .15 .70
4636 @item @var{OFFSET} @tab Shall of type @code{INTEGER}.
4637 @item @var{UNIT} @tab Shall of type @code{INTEGER}.
4640 @item @emph{Return value}:
4641 In either syntax, @var{OFFSET} is set to the current offset of unit
4642 number @var{UNIT}, or to @math{-1} if the unit is not currently open.
4644 @item @emph{Example}:
4648 OPEN(10, FILE="temp.dat")
4654 @item @emph{See also}:
4661 @section @code{GAMMA} --- Gamma function
4664 @cindex Gamma function
4665 @cindex Factorial function
4668 @item @emph{Description}:
4669 @code{GAMMA(X)} computes Gamma (@math{\Gamma}) of @var{X}. For positive,
4670 integer values of @var{X} the Gamma function simplifies to the factorial
4671 function @math{\Gamma(x)=(x-1)!}.
4675 \Gamma(x) = \int_0^\infty t^{x-1}{\rm e}^{-t}\,{\rm d}t
4679 @item @emph{Standard}:
4680 Fortran 2008 and later
4685 @item @emph{Syntax}:
4688 @item @emph{Arguments}:
4689 @multitable @columnfractions .15 .70
4690 @item @var{X} @tab Shall be of type @code{REAL} and neither zero
4691 nor a negative integer.
4694 @item @emph{Return value}:
4695 The return value is of type @code{REAL} of the same kind as @var{X}.
4697 @item @emph{Example}:
4701 x = gamma(x) ! returns 1.0
4702 end program test_gamma
4705 @item @emph{Specific names}:
4706 @multitable @columnfractions .20 .20 .20 .25
4707 @item Name @tab Argument @tab Return type @tab Standard
4708 @item @code{GAMMA(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab GNU Extension
4709 @item @code{DGAMMA(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU Extension
4712 @item @emph{See also}:
4713 Logarithm of the Gamma function: @ref{LOG_GAMMA}
4720 @section @code{GERROR} --- Get last system error message
4722 @cindex system, error handling
4725 @item @emph{Description}:
4726 Returns the system error message corresponding to the last system error.
4727 This resembles the functionality of @code{strerror(3)} in C.
4729 @item @emph{Standard}:
4735 @item @emph{Syntax}:
4736 @code{CALL GERROR(RESULT)}
4738 @item @emph{Arguments}:
4739 @multitable @columnfractions .15 .70
4740 @item @var{RESULT} @tab Shall of type @code{CHARACTER} and of default
4743 @item @emph{Example}:
4746 CHARACTER(len=100) :: msg
4752 @item @emph{See also}:
4753 @ref{IERRNO}, @ref{PERROR}
4759 @section @code{GETARG} --- Get command line arguments
4761 @cindex command-line arguments
4762 @cindex arguments, to program
4765 @item @emph{Description}:
4766 Retrieve the @var{POS}-th argument that was passed on the
4767 command line when the containing program was invoked.
4769 This intrinsic routine is provided for backwards compatibility with
4770 GNU Fortran 77. In new code, programmers should consider the use of
4771 the @ref{GET_COMMAND_ARGUMENT} intrinsic defined by the Fortran 2003
4774 @item @emph{Standard}:
4780 @item @emph{Syntax}:
4781 @code{CALL GETARG(POS, VALUE)}
4783 @item @emph{Arguments}:
4784 @multitable @columnfractions .15 .70
4785 @item @var{POS} @tab Shall be of type @code{INTEGER} and not wider than
4786 the default integer kind; @math{@var{POS} \geq 0}
4787 @item @var{VALUE} @tab Shall be of type @code{CHARACTER} and of default
4789 @item @var{VALUE} @tab Shall be of type @code{CHARACTER}.
4792 @item @emph{Return value}:
4793 After @code{GETARG} returns, the @var{VALUE} argument holds the
4794 @var{POS}th command line argument. If @var{VALUE} can not hold the
4795 argument, it is truncated to fit the length of @var{VALUE}. If there are
4796 less than @var{POS} arguments specified at the command line, @var{VALUE}
4797 will be filled with blanks. If @math{@var{POS} = 0}, @var{VALUE} is set
4798 to the name of the program (on systems that support this feature).
4800 @item @emph{Example}:
4804 CHARACTER(len=32) :: arg
4813 @item @emph{See also}:
4814 GNU Fortran 77 compatibility function: @ref{IARGC}
4816 Fortran 2003 functions and subroutines: @ref{GET_COMMAND},
4817 @ref{GET_COMMAND_ARGUMENT}, @ref{COMMAND_ARGUMENT_COUNT}
4823 @section @code{GET_COMMAND} --- Get the entire command line
4824 @fnindex GET_COMMAND
4825 @cindex command-line arguments
4826 @cindex arguments, to program
4829 @item @emph{Description}:
4830 Retrieve the entire command line that was used to invoke the program.
4832 @item @emph{Standard}:
4833 Fortran 2003 and later
4838 @item @emph{Syntax}:
4839 @code{CALL GET_COMMAND([COMMAND, LENGTH, STATUS])}
4841 @item @emph{Arguments}:
4842 @multitable @columnfractions .15 .70
4843 @item @var{COMMAND} @tab (Optional) shall be of type @code{CHARACTER} and
4845 @item @var{LENGTH} @tab (Optional) Shall be of type @code{INTEGER} and of
4847 @item @var{STATUS} @tab (Optional) Shall be of type @code{INTEGER} and of
4851 @item @emph{Return value}:
4852 If @var{COMMAND} is present, stores the entire command line that was used
4853 to invoke the program in @var{COMMAND}. If @var{LENGTH} is present, it is
4854 assigned the length of the command line. If @var{STATUS} is present, it
4855 is assigned 0 upon success of the command, -1 if @var{COMMAND} is too
4856 short to store the command line, or a positive value in case of an error.
4858 @item @emph{Example}:
4860 PROGRAM test_get_command
4861 CHARACTER(len=255) :: cmd
4862 CALL get_command(cmd)
4863 WRITE (*,*) TRIM(cmd)
4867 @item @emph{See also}:
4868 @ref{GET_COMMAND_ARGUMENT}, @ref{COMMAND_ARGUMENT_COUNT}
4873 @node GET_COMMAND_ARGUMENT
4874 @section @code{GET_COMMAND_ARGUMENT} --- Get command line arguments
4875 @fnindex GET_COMMAND_ARGUMENT
4876 @cindex command-line arguments
4877 @cindex arguments, to program
4880 @item @emph{Description}:
4881 Retrieve the @var{NUMBER}-th argument that was passed on the
4882 command line when the containing program was invoked.
4884 @item @emph{Standard}:
4885 Fortran 2003 and later
4890 @item @emph{Syntax}:
4891 @code{CALL GET_COMMAND_ARGUMENT(NUMBER [, VALUE, LENGTH, STATUS])}
4893 @item @emph{Arguments}:
4894 @multitable @columnfractions .15 .70
4895 @item @var{NUMBER} @tab Shall be a scalar of type @code{INTEGER} and of
4896 default kind, @math{@var{NUMBER} \geq 0}
4897 @item @var{VALUE} @tab Shall be a scalar of type @code{CHARACTER}
4898 and of default kind.
4899 @item @var{LENGTH} @tab (Option) Shall be a scalar of type @code{INTEGER}
4900 and of default kind.
4901 @item @var{STATUS} @tab (Option) Shall be a scalar of type @code{INTEGER}
4902 and of default kind.
4905 @item @emph{Return value}:
4906 After @code{GET_COMMAND_ARGUMENT} returns, the @var{VALUE} argument holds the
4907 @var{NUMBER}-th command line argument. If @var{VALUE} can not hold the argument, it is
4908 truncated to fit the length of @var{VALUE}. If there are less than @var{NUMBER}
4909 arguments specified at the command line, @var{VALUE} will be filled with blanks.
4910 If @math{@var{NUMBER} = 0}, @var{VALUE} is set to the name of the program (on
4911 systems that support this feature). The @var{LENGTH} argument contains the
4912 length of the @var{NUMBER}-th command line argument. If the argument retrieval
4913 fails, @var{STATUS} is a positive number; if @var{VALUE} contains a truncated
4914 command line argument, @var{STATUS} is -1; and otherwise the @var{STATUS} is
4917 @item @emph{Example}:
4919 PROGRAM test_get_command_argument
4921 CHARACTER(len=32) :: arg
4925 CALL get_command_argument(i, arg)
4926 IF (LEN_TRIM(arg) == 0) EXIT
4928 WRITE (*,*) TRIM(arg)
4934 @item @emph{See also}:
4935 @ref{GET_COMMAND}, @ref{COMMAND_ARGUMENT_COUNT}
4941 @section @code{GETCWD} --- Get current working directory
4943 @cindex system, working directory
4946 @item @emph{Description}:
4947 Get current working directory.
4949 This intrinsic is provided in both subroutine and function forms; however,
4950 only one form can be used in any given program unit.
4952 @item @emph{Standard}:
4956 Subroutine, function
4958 @item @emph{Syntax}:
4959 @code{CALL GETCWD(C [, STATUS])}
4961 @item @emph{Arguments}:
4962 @multitable @columnfractions .15 .70
4963 @item @var{C} @tab The type shall be @code{CHARACTER} and of default kind.
4964 @item @var{STATUS} @tab (Optional) status flag. Returns 0 on success,
4965 a system specific and nonzero error code otherwise.
4968 @item @emph{Example}:
4971 CHARACTER(len=255) :: cwd
4973 WRITE(*,*) TRIM(cwd)
4977 @item @emph{See also}:
4984 @section @code{GETENV} --- Get an environmental variable
4986 @cindex environment variable
4989 @item @emph{Description}:
4990 Get the @var{VALUE} of the environmental variable @var{NAME}.
4992 This intrinsic routine is provided for backwards compatibility with
4993 GNU Fortran 77. In new code, programmers should consider the use of
4994 the @ref{GET_ENVIRONMENT_VARIABLE} intrinsic defined by the Fortran
4997 @item @emph{Standard}:
5003 @item @emph{Syntax}:
5004 @code{CALL GETENV(NAME, VALUE)}
5006 @item @emph{Arguments}:
5007 @multitable @columnfractions .15 .70
5008 @item @var{NAME} @tab Shall be of type @code{CHARACTER} and of default kind.
5009 @item @var{VALUE} @tab Shall be of type @code{CHARACTER} and of default kind.
5012 @item @emph{Return value}:
5013 Stores the value of @var{NAME} in @var{VALUE}. If @var{VALUE} is
5014 not large enough to hold the data, it is truncated. If @var{NAME}
5015 is not set, @var{VALUE} will be filled with blanks.
5017 @item @emph{Example}:
5020 CHARACTER(len=255) :: homedir
5021 CALL getenv("HOME", homedir)
5022 WRITE (*,*) TRIM(homedir)
5026 @item @emph{See also}:
5027 @ref{GET_ENVIRONMENT_VARIABLE}
5032 @node GET_ENVIRONMENT_VARIABLE
5033 @section @code{GET_ENVIRONMENT_VARIABLE} --- Get an environmental variable
5034 @fnindex GET_ENVIRONMENT_VARIABLE
5035 @cindex environment variable
5038 @item @emph{Description}:
5039 Get the @var{VALUE} of the environmental variable @var{NAME}.
5041 @item @emph{Standard}:
5042 Fortran 2003 and later
5047 @item @emph{Syntax}:
5048 @code{CALL GET_ENVIRONMENT_VARIABLE(NAME[, VALUE, LENGTH, STATUS, TRIM_NAME)}
5050 @item @emph{Arguments}:
5051 @multitable @columnfractions .15 .70
5052 @item @var{NAME} @tab Shall be a scalar of type @code{CHARACTER}
5053 and of default kind.
5054 @item @var{VALUE} @tab Shall be a scalar of type @code{CHARACTER}
5055 and of default kind.
5056 @item @var{LENGTH} @tab Shall be a scalar of type @code{INTEGER}
5057 and of default kind.
5058 @item @var{STATUS} @tab Shall be a scalar of type @code{INTEGER}
5059 and of default kind.
5060 @item @var{TRIM_NAME} @tab Shall be a scalar of type @code{LOGICAL}
5061 and of default kind.
5064 @item @emph{Return value}:
5065 Stores the value of @var{NAME} in @var{VALUE}. If @var{VALUE} is
5066 not large enough to hold the data, it is truncated. If @var{NAME}
5067 is not set, @var{VALUE} will be filled with blanks. Argument @var{LENGTH}
5068 contains the length needed for storing the environment variable @var{NAME}
5069 or zero if it is not present. @var{STATUS} is -1 if @var{VALUE} is present
5070 but too short for the environment variable; it is 1 if the environment
5071 variable does not exist and 2 if the processor does not support environment
5072 variables; in all other cases @var{STATUS} is zero. If @var{TRIM_NAME} is
5073 present with the value @code{.FALSE.}, the trailing blanks in @var{NAME}
5074 are significant; otherwise they are not part of the environment variable
5077 @item @emph{Example}:
5080 CHARACTER(len=255) :: homedir
5081 CALL get_environment_variable("HOME", homedir)
5082 WRITE (*,*) TRIM(homedir)
5090 @section @code{GETGID} --- Group ID function
5092 @cindex system, group id
5095 @item @emph{Description}:
5096 Returns the numerical group ID of the current process.
5098 @item @emph{Standard}:
5104 @item @emph{Syntax}:
5105 @code{RESULT = GETGID()}
5107 @item @emph{Return value}:
5108 The return value of @code{GETGID} is an @code{INTEGER} of the default
5112 @item @emph{Example}:
5113 See @code{GETPID} for an example.
5115 @item @emph{See also}:
5116 @ref{GETPID}, @ref{GETUID}
5122 @section @code{GETLOG} --- Get login name
5124 @cindex system, login name
5128 @item @emph{Description}:
5129 Gets the username under which the program is running.
5131 @item @emph{Standard}:
5137 @item @emph{Syntax}:
5138 @code{CALL GETLOG(C)}
5140 @item @emph{Arguments}:
5141 @multitable @columnfractions .15 .70
5142 @item @var{C} @tab Shall be of type @code{CHARACTER} and of default kind.
5145 @item @emph{Return value}:
5146 Stores the current user name in @var{LOGIN}. (On systems where POSIX
5147 functions @code{geteuid} and @code{getpwuid} are not available, and
5148 the @code{getlogin} function is not implemented either, this will
5149 return a blank string.)
5151 @item @emph{Example}:
5154 CHARACTER(32) :: login
5160 @item @emph{See also}:
5167 @section @code{GETPID} --- Process ID function
5169 @cindex system, process id
5173 @item @emph{Description}:
5174 Returns the numerical process identifier of the current process.
5176 @item @emph{Standard}:
5182 @item @emph{Syntax}:
5183 @code{RESULT = GETPID()}
5185 @item @emph{Return value}:
5186 The return value of @code{GETPID} is an @code{INTEGER} of the default
5190 @item @emph{Example}:
5193 print *, "The current process ID is ", getpid()
5194 print *, "Your numerical user ID is ", getuid()
5195 print *, "Your numerical group ID is ", getgid()
5199 @item @emph{See also}:
5200 @ref{GETGID}, @ref{GETUID}
5206 @section @code{GETUID} --- User ID function
5208 @cindex system, user id
5212 @item @emph{Description}:
5213 Returns the numerical user ID of the current process.
5215 @item @emph{Standard}:
5221 @item @emph{Syntax}:
5222 @code{RESULT = GETUID()}
5224 @item @emph{Return value}:
5225 The return value of @code{GETUID} is an @code{INTEGER} of the default
5229 @item @emph{Example}:
5230 See @code{GETPID} for an example.
5232 @item @emph{See also}:
5233 @ref{GETPID}, @ref{GETLOG}
5239 @section @code{GMTIME} --- Convert time to GMT info
5241 @cindex time, conversion to GMT info
5244 @item @emph{Description}:
5245 Given a system time value @var{TIME} (as provided by the @code{TIME8()}
5246 intrinsic), fills @var{VALUES} with values extracted from it appropriate
5247 to the UTC time zone (Universal Coordinated Time, also known in some
5248 countries as GMT, Greenwich Mean Time), using @code{gmtime(3)}.
5250 @item @emph{Standard}:
5256 @item @emph{Syntax}:
5257 @code{CALL GMTIME(TIME, VALUES)}
5259 @item @emph{Arguments}:
5260 @multitable @columnfractions .15 .70
5261 @item @var{TIME} @tab An @code{INTEGER} scalar expression
5262 corresponding to a system time, with @code{INTENT(IN)}.
5263 @item @var{VALUES} @tab A default @code{INTEGER} array with 9 elements,
5264 with @code{INTENT(OUT)}.
5267 @item @emph{Return value}:
5268 The elements of @var{VALUES} are assigned as follows:
5270 @item Seconds after the minute, range 0--59 or 0--61 to allow for leap
5272 @item Minutes after the hour, range 0--59
5273 @item Hours past midnight, range 0--23
5274 @item Day of month, range 0--31
5275 @item Number of months since January, range 0--12
5276 @item Years since 1900
5277 @item Number of days since Sunday, range 0--6
5278 @item Days since January 1
5279 @item Daylight savings indicator: positive if daylight savings is in
5280 effect, zero if not, and negative if the information is not available.
5283 @item @emph{See also}:
5284 @ref{CTIME}, @ref{LTIME}, @ref{TIME}, @ref{TIME8}
5291 @section @code{HOSTNM} --- Get system host name
5293 @cindex system, host name
5296 @item @emph{Description}:
5297 Retrieves the host name of the system on which the program is running.
5299 This intrinsic is provided in both subroutine and function forms; however,
5300 only one form can be used in any given program unit.
5302 @item @emph{Standard}:
5306 Subroutine, function
5308 @item @emph{Syntax}:
5309 @multitable @columnfractions .80
5310 @item @code{CALL HOSTNM(C [, STATUS])}
5311 @item @code{STATUS = HOSTNM(NAME)}
5314 @item @emph{Arguments}:
5315 @multitable @columnfractions .15 .70
5316 @item @var{C} @tab Shall of type @code{CHARACTER} and of default kind.
5317 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
5318 Returns 0 on success, or a system specific error code otherwise.
5321 @item @emph{Return value}:
5322 In either syntax, @var{NAME} is set to the current hostname if it can
5323 be obtained, or to a blank string otherwise.
5330 @section @code{HUGE} --- Largest number of a kind
5332 @cindex limits, largest number
5333 @cindex model representation, largest number
5336 @item @emph{Description}:
5337 @code{HUGE(X)} returns the largest number that is not an infinity in
5338 the model of the type of @code{X}.
5340 @item @emph{Standard}:
5341 Fortran 95 and later
5346 @item @emph{Syntax}:
5347 @code{RESULT = HUGE(X)}
5349 @item @emph{Arguments}:
5350 @multitable @columnfractions .15 .70
5351 @item @var{X} @tab Shall be of type @code{REAL} or @code{INTEGER}.
5354 @item @emph{Return value}:
5355 The return value is of the same type and kind as @var{X}
5357 @item @emph{Example}:
5359 program test_huge_tiny
5360 print *, huge(0), huge(0.0), huge(0.0d0)
5361 print *, tiny(0.0), tiny(0.0d0)
5362 end program test_huge_tiny
5369 @section @code{HYPOT} --- Euclidean distance function
5371 @cindex Euclidean distance
5374 @item @emph{Description}:
5375 @code{HYPOT(X,Y)} is the Euclidean distance function. It is equal to
5376 @math{\sqrt{X^2 + Y^2}}, without undue underflow or overflow.
5378 @item @emph{Standard}:
5379 Fortran 2008 and later
5384 @item @emph{Syntax}:
5385 @code{RESULT = HYPOT(X, Y)}
5387 @item @emph{Arguments}:
5388 @multitable @columnfractions .15 .70
5389 @item @var{X} @tab The type shall be @code{REAL}.
5390 @item @var{Y} @tab The type and kind type parameter shall be the same as
5394 @item @emph{Return value}:
5395 The return value has the same type and kind type parameter as @var{X}.
5397 @item @emph{Example}:
5400 real(4) :: x = 1.e0_4, y = 0.5e0_4
5402 end program test_hypot
5409 @section @code{IACHAR} --- Code in @acronym{ASCII} collating sequence
5411 @cindex @acronym{ASCII} collating sequence
5412 @cindex collating sequence, @acronym{ASCII}
5413 @cindex conversion, to integer
5416 @item @emph{Description}:
5417 @code{IACHAR(C)} returns the code for the @acronym{ASCII} character
5418 in the first character position of @code{C}.
5420 @item @emph{Standard}:
5421 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
5426 @item @emph{Syntax}:
5427 @code{RESULT = IACHAR(C [, KIND])}
5429 @item @emph{Arguments}:
5430 @multitable @columnfractions .15 .70
5431 @item @var{C} @tab Shall be a scalar @code{CHARACTER}, with @code{INTENT(IN)}
5432 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
5433 expression indicating the kind parameter of the result.
5436 @item @emph{Return value}:
5437 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
5438 @var{KIND} is absent, the return value is of default integer kind.
5440 @item @emph{Example}:
5445 end program test_iachar
5449 See @ref{ICHAR} for a discussion of converting between numerical values
5450 and formatted string representations.
5452 @item @emph{See also}:
5453 @ref{ACHAR}, @ref{CHAR}, @ref{ICHAR}
5460 @section @code{IAND} --- Bitwise logical and
5462 @cindex bitwise logical and
5463 @cindex logical and, bitwise
5466 @item @emph{Description}:
5467 Bitwise logical @code{AND}.
5469 @item @emph{Standard}:
5470 Fortran 95 and later
5475 @item @emph{Syntax}:
5476 @code{RESULT = IAND(I, J)}
5478 @item @emph{Arguments}:
5479 @multitable @columnfractions .15 .70
5480 @item @var{I} @tab The type shall be @code{INTEGER}.
5481 @item @var{J} @tab The type shall be @code{INTEGER}, of the same
5482 kind as @var{I}. (As a GNU extension, different kinds are also
5486 @item @emph{Return value}:
5487 The return type is @code{INTEGER}, of the same kind as the
5488 arguments. (If the argument kinds differ, it is of the same kind as
5489 the larger argument.)
5491 @item @emph{Example}:
5495 DATA a / Z'F' /, b / Z'3' /
5496 WRITE (*,*) IAND(a, b)
5500 @item @emph{See also}:
5501 @ref{IOR}, @ref{IEOR}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}, @ref{NOT}
5508 @section @code{IARGC} --- Get the number of command line arguments
5510 @cindex command-line arguments
5511 @cindex command-line arguments, number of
5512 @cindex arguments, to program
5515 @item @emph{Description}:
5516 @code{IARGC()} returns the number of arguments passed on the
5517 command line when the containing program was invoked.
5519 This intrinsic routine is provided for backwards compatibility with
5520 GNU Fortran 77. In new code, programmers should consider the use of
5521 the @ref{COMMAND_ARGUMENT_COUNT} intrinsic defined by the Fortran 2003
5524 @item @emph{Standard}:
5530 @item @emph{Syntax}:
5531 @code{RESULT = IARGC()}
5533 @item @emph{Arguments}:
5536 @item @emph{Return value}:
5537 The number of command line arguments, type @code{INTEGER(4)}.
5539 @item @emph{Example}:
5542 @item @emph{See also}:
5543 GNU Fortran 77 compatibility subroutine: @ref{GETARG}
5545 Fortran 2003 functions and subroutines: @ref{GET_COMMAND},
5546 @ref{GET_COMMAND_ARGUMENT}, @ref{COMMAND_ARGUMENT_COUNT}
5552 @section @code{IBCLR} --- Clear bit
5558 @item @emph{Description}:
5559 @code{IBCLR} returns the value of @var{I} with the bit at position
5560 @var{POS} set to zero.
5562 @item @emph{Standard}:
5563 Fortran 95 and later
5568 @item @emph{Syntax}:
5569 @code{RESULT = IBCLR(I, POS)}
5571 @item @emph{Arguments}:
5572 @multitable @columnfractions .15 .70
5573 @item @var{I} @tab The type shall be @code{INTEGER}.
5574 @item @var{POS} @tab The type shall be @code{INTEGER}.
5577 @item @emph{Return value}:
5578 The return value is of type @code{INTEGER} and of the same kind as
5581 @item @emph{See also}:
5582 @ref{IBITS}, @ref{IBSET}, @ref{IAND}, @ref{IOR}, @ref{IEOR}, @ref{MVBITS}
5589 @section @code{IBITS} --- Bit extraction
5592 @cindex bits, extract
5595 @item @emph{Description}:
5596 @code{IBITS} extracts a field of length @var{LEN} from @var{I},
5597 starting from bit position @var{POS} and extending left for @var{LEN}
5598 bits. The result is right-justified and the remaining bits are
5599 zeroed. The value of @code{POS+LEN} must be less than or equal to the
5600 value @code{BIT_SIZE(I)}.
5602 @item @emph{Standard}:
5603 Fortran 95 and later
5608 @item @emph{Syntax}:
5609 @code{RESULT = IBITS(I, POS, LEN)}
5611 @item @emph{Arguments}:
5612 @multitable @columnfractions .15 .70
5613 @item @var{I} @tab The type shall be @code{INTEGER}.
5614 @item @var{POS} @tab The type shall be @code{INTEGER}.
5615 @item @var{LEN} @tab The type shall be @code{INTEGER}.
5618 @item @emph{Return value}:
5619 The return value is of type @code{INTEGER} and of the same kind as
5622 @item @emph{See also}:
5623 @ref{BIT_SIZE}, @ref{IBCLR}, @ref{IBSET}, @ref{IAND}, @ref{IOR}, @ref{IEOR}
5629 @section @code{IBSET} --- Set bit
5634 @item @emph{Description}:
5635 @code{IBSET} returns the value of @var{I} with the bit at position
5636 @var{POS} set to one.
5638 @item @emph{Standard}:
5639 Fortran 95 and later
5644 @item @emph{Syntax}:
5645 @code{RESULT = IBSET(I, POS)}
5647 @item @emph{Arguments}:
5648 @multitable @columnfractions .15 .70
5649 @item @var{I} @tab The type shall be @code{INTEGER}.
5650 @item @var{POS} @tab The type shall be @code{INTEGER}.
5653 @item @emph{Return value}:
5654 The return value is of type @code{INTEGER} and of the same kind as
5657 @item @emph{See also}:
5658 @ref{IBCLR}, @ref{IBITS}, @ref{IAND}, @ref{IOR}, @ref{IEOR}, @ref{MVBITS}
5665 @section @code{ICHAR} --- Character-to-integer conversion function
5667 @cindex conversion, to integer
5670 @item @emph{Description}:
5671 @code{ICHAR(C)} returns the code for the character in the first character
5672 position of @code{C} in the system's native character set.
5673 The correspondence between characters and their codes is not necessarily
5674 the same across different GNU Fortran implementations.
5676 @item @emph{Standard}:
5677 Fortan 95 and later, with @var{KIND} argument Fortran 2003 and later
5682 @item @emph{Syntax}:
5683 @code{RESULT = ICHAR(C [, KIND])}
5685 @item @emph{Arguments}:
5686 @multitable @columnfractions .15 .70
5687 @item @var{C} @tab Shall be a scalar @code{CHARACTER}, with @code{INTENT(IN)}
5688 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
5689 expression indicating the kind parameter of the result.
5692 @item @emph{Return value}:
5693 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
5694 @var{KIND} is absent, the return value is of default integer kind.
5696 @item @emph{Example}:
5701 end program test_ichar
5705 No intrinsic exists to convert between a numeric value and a formatted
5706 character string representation -- for instance, given the
5707 @code{CHARACTER} value @code{'154'}, obtaining an @code{INTEGER} or
5708 @code{REAL} value with the value 154, or vice versa. Instead, this
5709 functionality is provided by internal-file I/O, as in the following
5714 character(len=10) string, string2
5717 ! Convert a string to a numeric value
5718 read (string,'(I10)') value
5721 ! Convert a value to a formatted string
5722 write (string2,'(I10)') value
5724 end program read_val
5727 @item @emph{See also}:
5728 @ref{ACHAR}, @ref{CHAR}, @ref{IACHAR}
5735 @section @code{IDATE} --- Get current local time subroutine (day/month/year)
5737 @cindex date, current
5738 @cindex current date
5741 @item @emph{Description}:
5742 @code{IDATE(VALUES)} Fills @var{VALUES} with the numerical values at the
5743 current local time. The day (in the range 1-31), month (in the range 1-12),
5744 and year appear in elements 1, 2, and 3 of @var{VALUES}, respectively.
5745 The year has four significant digits.
5747 @item @emph{Standard}:
5753 @item @emph{Syntax}:
5754 @code{CALL IDATE(VALUES)}
5756 @item @emph{Arguments}:
5757 @multitable @columnfractions .15 .70
5758 @item @var{VALUES} @tab The type shall be @code{INTEGER, DIMENSION(3)} and
5759 the kind shall be the default integer kind.
5762 @item @emph{Return value}:
5763 Does not return anything.
5765 @item @emph{Example}:
5768 integer, dimension(3) :: tarray
5773 end program test_idate
5780 @section @code{IEOR} --- Bitwise logical exclusive or
5782 @cindex bitwise logical exclusive or
5783 @cindex logical exclusive or, bitwise
5786 @item @emph{Description}:
5787 @code{IEOR} returns the bitwise boolean exclusive-OR of @var{I} and
5790 @item @emph{Standard}:
5791 Fortran 95 and later
5796 @item @emph{Syntax}:
5797 @code{RESULT = IEOR(I, J)}
5799 @item @emph{Arguments}:
5800 @multitable @columnfractions .15 .70
5801 @item @var{I} @tab The type shall be @code{INTEGER}.
5802 @item @var{J} @tab The type shall be @code{INTEGER}, of the same
5803 kind as @var{I}. (As a GNU extension, different kinds are also
5807 @item @emph{Return value}:
5808 The return type is @code{INTEGER}, of the same kind as the
5809 arguments. (If the argument kinds differ, it is of the same kind as
5810 the larger argument.)
5812 @item @emph{See also}:
5813 @ref{IOR}, @ref{IAND}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}, @ref{NOT}
5819 @section @code{IERRNO} --- Get the last system error number
5821 @cindex system, error handling
5824 @item @emph{Description}:
5825 Returns the last system error number, as given by the C @code{errno()}
5828 @item @emph{Standard}:
5834 @item @emph{Syntax}:
5835 @code{RESULT = IERRNO()}
5837 @item @emph{Arguments}:
5840 @item @emph{Return value}:
5841 The return value is of type @code{INTEGER} and of the default integer
5844 @item @emph{See also}:
5850 @node INDEX intrinsic
5851 @section @code{INDEX} --- Position of a substring within a string
5853 @cindex substring position
5854 @cindex string, find substring
5857 @item @emph{Description}:
5858 Returns the position of the start of the first occurrence of string
5859 @var{SUBSTRING} as a substring in @var{STRING}, counting from one. If
5860 @var{SUBSTRING} is not present in @var{STRING}, zero is returned. If
5861 the @var{BACK} argument is present and true, the return value is the
5862 start of the last occurrence rather than the first.
5864 @item @emph{Standard}:
5865 Fortran 77 and later, with @var{KIND} argument Fortran 2003 and later
5870 @item @emph{Syntax}:
5871 @code{RESULT = INDEX(STRING, SUBSTRING [, BACK [, KIND]])}
5873 @item @emph{Arguments}:
5874 @multitable @columnfractions .15 .70
5875 @item @var{STRING} @tab Shall be a scalar @code{CHARACTER}, with
5877 @item @var{SUBSTRING} @tab Shall be a scalar @code{CHARACTER}, with
5879 @item @var{BACK} @tab (Optional) Shall be a scalar @code{LOGICAL}, with
5881 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
5882 expression indicating the kind parameter of the result.
5885 @item @emph{Return value}:
5886 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
5887 @var{KIND} is absent, the return value is of default integer kind.
5889 @item @emph{See also}:
5890 @ref{SCAN}, @ref{VERIFY}
5896 @section @code{INT} --- Convert to integer type
5900 @cindex conversion, to integer
5903 @item @emph{Description}:
5904 Convert to integer type
5906 @item @emph{Standard}:
5907 Fortran 77 and later
5912 @item @emph{Syntax}:
5913 @code{RESULT = INT(A [, KIND))}
5915 @item @emph{Arguments}:
5916 @multitable @columnfractions .15 .70
5917 @item @var{A} @tab Shall be of type @code{INTEGER},
5918 @code{REAL}, or @code{COMPLEX}.
5919 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
5920 expression indicating the kind parameter of the result.
5923 @item @emph{Return value}:
5924 These functions return a @code{INTEGER} variable or array under
5925 the following rules:
5929 If @var{A} is of type @code{INTEGER}, @code{INT(A) = A}
5931 If @var{A} is of type @code{REAL} and @math{|A| < 1}, @code{INT(A)} equals @code{0}.
5932 If @math{|A| \geq 1}, then @code{INT(A)} equals the largest integer that does not exceed
5933 the range of @var{A} and whose sign is the same as the sign of @var{A}.
5935 If @var{A} is of type @code{COMPLEX}, rule B is applied to the real part of @var{A}.
5938 @item @emph{Example}:
5942 complex :: z = (-3.7, 1.0)
5944 print *, int(z), int(z,8)
5948 @item @emph{Specific names}:
5949 @multitable @columnfractions .20 .20 .20 .25
5950 @item Name @tab Argument @tab Return type @tab Standard
5951 @item @code{IFIX(A)} @tab @code{REAL(4) A} @tab @code{INTEGER} @tab Fortran 77 and later
5952 @item @code{IDINT(A)} @tab @code{REAL(8) A} @tab @code{INTEGER} @tab Fortran 77 and later
5960 @section @code{INT2} --- Convert to 16-bit integer type
5963 @cindex conversion, to integer
5966 @item @emph{Description}:
5967 Convert to a @code{KIND=2} integer type. This is equivalent to the
5968 standard @code{INT} intrinsic with an optional argument of
5969 @code{KIND=2}, and is only included for backwards compatibility.
5971 The @code{SHORT} intrinsic is equivalent to @code{INT2}.
5973 @item @emph{Standard}:
5979 @item @emph{Syntax}:
5980 @code{RESULT = INT2(A)}
5982 @item @emph{Arguments}:
5983 @multitable @columnfractions .15 .70
5984 @item @var{A} @tab Shall be of type @code{INTEGER},
5985 @code{REAL}, or @code{COMPLEX}.
5988 @item @emph{Return value}:
5989 The return value is a @code{INTEGER(2)} variable.
5991 @item @emph{See also}:
5992 @ref{INT}, @ref{INT8}, @ref{LONG}
5998 @section @code{INT8} --- Convert to 64-bit integer type
6000 @cindex conversion, to integer
6003 @item @emph{Description}:
6004 Convert to a @code{KIND=8} integer type. This is equivalent to the
6005 standard @code{INT} intrinsic with an optional argument of
6006 @code{KIND=8}, and is only included for backwards compatibility.
6008 @item @emph{Standard}:
6014 @item @emph{Syntax}:
6015 @code{RESULT = INT8(A)}
6017 @item @emph{Arguments}:
6018 @multitable @columnfractions .15 .70
6019 @item @var{A} @tab Shall be of type @code{INTEGER},
6020 @code{REAL}, or @code{COMPLEX}.
6023 @item @emph{Return value}:
6024 The return value is a @code{INTEGER(8)} variable.
6026 @item @emph{See also}:
6027 @ref{INT}, @ref{INT2}, @ref{LONG}
6033 @section @code{IOR} --- Bitwise logical or
6035 @cindex bitwise logical or
6036 @cindex logical or, bitwise
6039 @item @emph{Description}:
6040 @code{IOR} returns the bitwise boolean inclusive-OR of @var{I} and
6043 @item @emph{Standard}:
6044 Fortran 95 and later
6049 @item @emph{Syntax}:
6050 @code{RESULT = IOR(I, J)}
6052 @item @emph{Arguments}:
6053 @multitable @columnfractions .15 .70
6054 @item @var{I} @tab The type shall be @code{INTEGER}.
6055 @item @var{J} @tab The type shall be @code{INTEGER}, of the same
6056 kind as @var{I}. (As a GNU extension, different kinds are also
6060 @item @emph{Return value}:
6061 The return type is @code{INTEGER}, of the same kind as the
6062 arguments. (If the argument kinds differ, it is of the same kind as
6063 the larger argument.)
6065 @item @emph{See also}:
6066 @ref{IEOR}, @ref{IAND}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}, @ref{NOT}
6072 @section @code{IRAND} --- Integer pseudo-random number
6074 @cindex random number generation
6077 @item @emph{Description}:
6078 @code{IRAND(FLAG)} returns a pseudo-random number from a uniform
6079 distribution between 0 and a system-dependent limit (which is in most
6080 cases 2147483647). If @var{FLAG} is 0, the next number
6081 in the current sequence is returned; if @var{FLAG} is 1, the generator
6082 is restarted by @code{CALL SRAND(0)}; if @var{FLAG} has any other value,
6083 it is used as a new seed with @code{SRAND}.
6085 This intrinsic routine is provided for backwards compatibility with
6086 GNU Fortran 77. It implements a simple modulo generator as provided
6087 by @command{g77}. For new code, one should consider the use of
6088 @ref{RANDOM_NUMBER} as it implements a superior algorithm.
6090 @item @emph{Standard}:
6096 @item @emph{Syntax}:
6097 @code{RESULT = IRAND(I)}
6099 @item @emph{Arguments}:
6100 @multitable @columnfractions .15 .70
6101 @item @var{I} @tab Shall be a scalar @code{INTEGER} of kind 4.
6104 @item @emph{Return value}:
6105 The return value is of @code{INTEGER(kind=4)} type.
6107 @item @emph{Example}:
6110 integer,parameter :: seed = 86456
6113 print *, irand(), irand(), irand(), irand()
6114 print *, irand(seed), irand(), irand(), irand()
6115 end program test_irand
6123 @section @code{IMAGE_INDEX} --- Function that converts a cosubscript to an image index
6124 @fnindex IMAGE_INDEX
6125 @cindex coarray, IMAGE_INDEX
6126 @cindex images, cosubscript to image index conversion
6129 @item @emph{Description}:
6130 Returns the image index belonging to a cosubscript.
6132 @item @emph{Standard}:
6133 Fortran 2008 and later
6138 @item @emph{Syntax}:
6139 @code{RESULT = IMAGE_INDEX(COARRAY, SUB)}
6141 @item @emph{Arguments}: None.
6142 @multitable @columnfractions .15 .70
6143 @item @var{COARRAY} @tab Coarray of any type.
6144 @item @var{SUB} @tab default integer rank-1 array of a size equal to
6145 the corank of @var{COARRAY}.
6149 @item @emph{Return value}:
6150 Scalar default integer with the value of the image index which corresponds
6151 to the cosubscripts. For invalid cosubscripts the result is zero.
6153 @item @emph{Example}:
6155 INTEGER :: array[2,-1:4,8,*]
6156 ! Writes 28 (or 0 if there are fewer than 28 images)
6157 WRITE (*,*) IMAGE_INDEX (array, [2,0,3,1])
6160 @item @emph{See also}:
6161 @ref{THIS_IMAGE}, @ref{NUM_IMAGES}
6167 @section @code{IS_IOSTAT_END} --- Test for end-of-file value
6168 @fnindex IS_IOSTAT_END
6169 @cindex IOSTAT, end of file
6172 @item @emph{Description}:
6173 @code{IS_IOSTAT_END} tests whether an variable has the value of the I/O
6174 status ``end of file''. The function is equivalent to comparing the variable
6175 with the @code{IOSTAT_END} parameter of the intrinsic module
6176 @code{ISO_FORTRAN_ENV}.
6178 @item @emph{Standard}:
6179 Fortran 2003 and later
6184 @item @emph{Syntax}:
6185 @code{RESULT = IS_IOSTAT_END(I)}
6187 @item @emph{Arguments}:
6188 @multitable @columnfractions .15 .70
6189 @item @var{I} @tab Shall be of the type @code{INTEGER}.
6192 @item @emph{Return value}:
6193 Returns a @code{LOGICAL} of the default kind, which @code{.TRUE.} if
6194 @var{I} has the value which indicates an end of file condition for
6195 IOSTAT= specifiers, and is @code{.FALSE.} otherwise.
6197 @item @emph{Example}:
6202 OPEN(88, FILE='test.dat')
6203 READ(88, *, IOSTAT=stat) i
6204 IF(IS_IOSTAT_END(stat)) STOP 'END OF FILE'
6212 @section @code{IS_IOSTAT_EOR} --- Test for end-of-record value
6213 @fnindex IS_IOSTAT_EOR
6214 @cindex IOSTAT, end of record
6217 @item @emph{Description}:
6218 @code{IS_IOSTAT_EOR} tests whether an variable has the value of the I/O
6219 status ``end of record''. The function is equivalent to comparing the
6220 variable with the @code{IOSTAT_EOR} parameter of the intrinsic module
6221 @code{ISO_FORTRAN_ENV}.
6223 @item @emph{Standard}:
6224 Fortran 2003 and later
6229 @item @emph{Syntax}:
6230 @code{RESULT = IS_IOSTAT_EOR(I)}
6232 @item @emph{Arguments}:
6233 @multitable @columnfractions .15 .70
6234 @item @var{I} @tab Shall be of the type @code{INTEGER}.
6237 @item @emph{Return value}:
6238 Returns a @code{LOGICAL} of the default kind, which @code{.TRUE.} if
6239 @var{I} has the value which indicates an end of file condition for
6240 IOSTAT= specifiers, and is @code{.FALSE.} otherwise.
6242 @item @emph{Example}:
6246 INTEGER :: stat, i(50)
6247 OPEN(88, FILE='test.dat', FORM='UNFORMATTED')
6248 READ(88, IOSTAT=stat) i
6249 IF(IS_IOSTAT_EOR(stat)) STOP 'END OF RECORD'
6257 @section @code{ISATTY} --- Whether a unit is a terminal device.
6259 @cindex system, terminal
6262 @item @emph{Description}:
6263 Determine whether a unit is connected to a terminal device.
6265 @item @emph{Standard}:
6271 @item @emph{Syntax}:
6272 @code{RESULT = ISATTY(UNIT)}
6274 @item @emph{Arguments}:
6275 @multitable @columnfractions .15 .70
6276 @item @var{UNIT} @tab Shall be a scalar @code{INTEGER}.
6279 @item @emph{Return value}:
6280 Returns @code{.TRUE.} if the @var{UNIT} is connected to a terminal
6281 device, @code{.FALSE.} otherwise.
6283 @item @emph{Example}:
6286 INTEGER(kind=1) :: unit
6288 write(*,*) isatty(unit=unit)
6292 @item @emph{See also}:
6299 @section @code{ISHFT} --- Shift bits
6304 @item @emph{Description}:
6305 @code{ISHFT} returns a value corresponding to @var{I} with all of the
6306 bits shifted @var{SHIFT} places. A value of @var{SHIFT} greater than
6307 zero corresponds to a left shift, a value of zero corresponds to no
6308 shift, and a value less than zero corresponds to a right shift. If the
6309 absolute value of @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the
6310 value is undefined. Bits shifted out from the left end or right end are
6311 lost; zeros are shifted in from the opposite end.
6313 @item @emph{Standard}:
6314 Fortran 95 and later
6319 @item @emph{Syntax}:
6320 @code{RESULT = ISHFT(I, SHIFT)}
6322 @item @emph{Arguments}:
6323 @multitable @columnfractions .15 .70
6324 @item @var{I} @tab The type shall be @code{INTEGER}.
6325 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
6328 @item @emph{Return value}:
6329 The return value is of type @code{INTEGER} and of the same kind as
6332 @item @emph{See also}:
6339 @section @code{ISHFTC} --- Shift bits circularly
6341 @cindex bits, shift circular
6344 @item @emph{Description}:
6345 @code{ISHFTC} returns a value corresponding to @var{I} with the
6346 rightmost @var{SIZE} bits shifted circularly @var{SHIFT} places; that
6347 is, bits shifted out one end are shifted into the opposite end. A value
6348 of @var{SHIFT} greater than zero corresponds to a left shift, a value of
6349 zero corresponds to no shift, and a value less than zero corresponds to
6350 a right shift. The absolute value of @var{SHIFT} must be less than
6351 @var{SIZE}. If the @var{SIZE} argument is omitted, it is taken to be
6352 equivalent to @code{BIT_SIZE(I)}.
6354 @item @emph{Standard}:
6355 Fortran 95 and later
6360 @item @emph{Syntax}:
6361 @code{RESULT = ISHFTC(I, SHIFT [, SIZE])}
6363 @item @emph{Arguments}:
6364 @multitable @columnfractions .15 .70
6365 @item @var{I} @tab The type shall be @code{INTEGER}.
6366 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
6367 @item @var{SIZE} @tab (Optional) The type shall be @code{INTEGER};
6368 the value must be greater than zero and less than or equal to
6372 @item @emph{Return value}:
6373 The return value is of type @code{INTEGER} and of the same kind as
6376 @item @emph{See also}:
6383 @section @code{ISNAN} --- Test for a NaN
6388 @item @emph{Description}:
6389 @code{ISNAN} tests whether a floating-point value is an IEEE
6391 @item @emph{Standard}:
6397 @item @emph{Syntax}:
6400 @item @emph{Arguments}:
6401 @multitable @columnfractions .15 .70
6402 @item @var{X} @tab Variable of the type @code{REAL}.
6406 @item @emph{Return value}:
6407 Returns a default-kind @code{LOGICAL}. The returned value is @code{TRUE}
6408 if @var{X} is a NaN and @code{FALSE} otherwise.
6410 @item @emph{Example}:
6417 if (isnan(x)) stop '"x" is a NaN'
6418 end program test_nan
6425 @section @code{ITIME} --- Get current local time subroutine (hour/minutes/seconds)
6427 @cindex time, current
6428 @cindex current time
6431 @item @emph{Description}:
6432 @code{IDATE(VALUES)} Fills @var{VALUES} with the numerical values at the
6433 current local time. The hour (in the range 1-24), minute (in the range 1-60),
6434 and seconds (in the range 1-60) appear in elements 1, 2, and 3 of @var{VALUES},
6437 @item @emph{Standard}:
6443 @item @emph{Syntax}:
6444 @code{CALL ITIME(VALUES)}
6446 @item @emph{Arguments}:
6447 @multitable @columnfractions .15 .70
6448 @item @var{VALUES} @tab The type shall be @code{INTEGER, DIMENSION(3)}
6449 and the kind shall be the default integer kind.
6452 @item @emph{Return value}:
6453 Does not return anything.
6456 @item @emph{Example}:
6459 integer, dimension(3) :: tarray
6464 end program test_itime
6471 @section @code{KILL} --- Send a signal to a process
6475 @item @emph{Description}:
6476 @item @emph{Standard}:
6477 Sends the signal specified by @var{SIGNAL} to the process @var{PID}.
6480 This intrinsic is provided in both subroutine and function forms; however,
6481 only one form can be used in any given program unit.
6484 Subroutine, function
6486 @item @emph{Syntax}:
6487 @code{CALL KILL(C, VALUE [, STATUS])}
6489 @item @emph{Arguments}:
6490 @multitable @columnfractions .15 .70
6491 @item @var{C} @tab Shall be a scalar @code{INTEGER}, with
6493 @item @var{VALUE} @tab Shall be a scalar @code{INTEGER}, with
6495 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)} or
6496 @code{INTEGER(8)}. Returns 0 on success, or a system-specific error code
6500 @item @emph{See also}:
6501 @ref{ABORT}, @ref{EXIT}
6507 @section @code{KIND} --- Kind of an entity
6512 @item @emph{Description}:
6513 @code{KIND(X)} returns the kind value of the entity @var{X}.
6515 @item @emph{Standard}:
6516 Fortran 95 and later
6521 @item @emph{Syntax}:
6524 @item @emph{Arguments}:
6525 @multitable @columnfractions .15 .70
6526 @item @var{X} @tab Shall be of type @code{LOGICAL}, @code{INTEGER},
6527 @code{REAL}, @code{COMPLEX} or @code{CHARACTER}.
6530 @item @emph{Return value}:
6531 The return value is a scalar of type @code{INTEGER} and of the default
6534 @item @emph{Example}:
6537 integer,parameter :: kc = kind(' ')
6538 integer,parameter :: kl = kind(.true.)
6540 print *, "The default character kind is ", kc
6541 print *, "The default logical kind is ", kl
6542 end program test_kind
6550 @section @code{LBOUND} --- Lower dimension bounds of an array
6552 @cindex array, lower bound
6555 @item @emph{Description}:
6556 Returns the lower bounds of an array, or a single lower bound
6557 along the @var{DIM} dimension.
6558 @item @emph{Standard}:
6559 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
6564 @item @emph{Syntax}:
6565 @code{RESULT = LBOUND(ARRAY [, DIM [, KIND]])}
6567 @item @emph{Arguments}:
6568 @multitable @columnfractions .15 .70
6569 @item @var{ARRAY} @tab Shall be an array, of any type.
6570 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER}.
6571 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
6572 expression indicating the kind parameter of the result.
6575 @item @emph{Return value}:
6576 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
6577 @var{KIND} is absent, the return value is of default integer kind.
6578 If @var{DIM} is absent, the result is an array of the lower bounds of
6579 @var{ARRAY}. If @var{DIM} is present, the result is a scalar
6580 corresponding to the lower bound of the array along that dimension. If
6581 @var{ARRAY} is an expression rather than a whole array or array
6582 structure component, or if it has a zero extent along the relevant
6583 dimension, the lower bound is taken to be 1.
6585 @item @emph{See also}:
6586 @ref{UBOUND}, @ref{LCOBOUND}
6592 @section @code{LCOBOUND} --- Lower codimension bounds of an array
6594 @cindex coarray, lower bound
6597 @item @emph{Description}:
6598 Returns the lower bounds of a coarray, or a single lower cobound
6599 along the @var{DIM} codimension.
6600 @item @emph{Standard}:
6601 Fortran 2008 and later
6606 @item @emph{Syntax}:
6607 @code{RESULT = LCOBOUND(COARRAY [, DIM [, KIND]])}
6609 @item @emph{Arguments}:
6610 @multitable @columnfractions .15 .70
6611 @item @var{ARRAY} @tab Shall be an coarray, of any type.
6612 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER}.
6613 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
6614 expression indicating the kind parameter of the result.
6617 @item @emph{Return value}:
6618 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
6619 @var{KIND} is absent, the return value is of default integer kind.
6620 If @var{DIM} is absent, the result is an array of the lower cobounds of
6621 @var{COARRAY}. If @var{DIM} is present, the result is a scalar
6622 corresponding to the lower cobound of the array along that codimension.
6624 @item @emph{See also}:
6625 @ref{UCOBOUND}, @ref{LBOUND}
6631 @section @code{LEADZ} --- Number of leading zero bits of an integer
6636 @item @emph{Description}:
6637 @code{LEADZ} returns the number of leading zero bits of an integer.
6639 @item @emph{Standard}:
6640 Fortran 2008 and later
6645 @item @emph{Syntax}:
6646 @code{RESULT = LEADZ(I)}
6648 @item @emph{Arguments}:
6649 @multitable @columnfractions .15 .70
6650 @item @var{I} @tab Shall be of type @code{INTEGER}.
6653 @item @emph{Return value}:
6654 The type of the return value is the default @code{INTEGER}.
6655 If all the bits of @code{I} are zero, the result value is @code{BIT_SIZE(I)}.
6657 @item @emph{Example}:
6660 WRITE (*,*) LEADZ(1) ! prints 8 if BITSIZE(I) has the value 32
6664 @item @emph{See also}:
6665 @ref{BIT_SIZE}, @ref{TRAILZ}
6671 @section @code{LEN} --- Length of a character entity
6673 @cindex string, length
6676 @item @emph{Description}:
6677 Returns the length of a character string. If @var{STRING} is an array,
6678 the length of an element of @var{STRING} is returned. Note that
6679 @var{STRING} need not be defined when this intrinsic is invoked, since
6680 only the length, not the content, of @var{STRING} is needed.
6682 @item @emph{Standard}:
6683 Fortran 77 and later, with @var{KIND} argument Fortran 2003 and later
6688 @item @emph{Syntax}:
6689 @code{L = LEN(STRING [, KIND])}
6691 @item @emph{Arguments}:
6692 @multitable @columnfractions .15 .70
6693 @item @var{STRING} @tab Shall be a scalar or array of type
6694 @code{CHARACTER}, with @code{INTENT(IN)}
6695 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
6696 expression indicating the kind parameter of the result.
6699 @item @emph{Return value}:
6700 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
6701 @var{KIND} is absent, the return value is of default integer kind.
6703 @item @emph{See also}:
6704 @ref{LEN_TRIM}, @ref{ADJUSTL}, @ref{ADJUSTR}
6710 @section @code{LEN_TRIM} --- Length of a character entity without trailing blank characters
6712 @cindex string, length, without trailing whitespace
6715 @item @emph{Description}:
6716 Returns the length of a character string, ignoring any trailing blanks.
6718 @item @emph{Standard}:
6719 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
6724 @item @emph{Syntax}:
6725 @code{RESULT = LEN_TRIM(STRING [, KIND])}
6727 @item @emph{Arguments}:
6728 @multitable @columnfractions .15 .70
6729 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER},
6730 with @code{INTENT(IN)}
6731 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
6732 expression indicating the kind parameter of the result.
6735 @item @emph{Return value}:
6736 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
6737 @var{KIND} is absent, the return value is of default integer kind.
6739 @item @emph{See also}:
6740 @ref{LEN}, @ref{ADJUSTL}, @ref{ADJUSTR}
6746 @section @code{LGE} --- Lexical greater than or equal
6748 @cindex lexical comparison of strings
6749 @cindex string, comparison
6752 @item @emph{Description}:
6753 Determines whether one string is lexically greater than or equal to
6754 another string, where the two strings are interpreted as containing
6755 ASCII character codes. If the String A and String B are not the same
6756 length, the shorter is compared as if spaces were appended to it to form
6757 a value that has the same length as the longer.
6759 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
6760 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
6761 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
6762 that the latter use the processor's character ordering (which is not
6763 ASCII on some targets), whereas the former always use the ASCII
6766 @item @emph{Standard}:
6767 Fortran 77 and later
6772 @item @emph{Syntax}:
6773 @code{RESULT = LGE(STRING_A, STRING_B)}
6775 @item @emph{Arguments}:
6776 @multitable @columnfractions .15 .70
6777 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
6778 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
6781 @item @emph{Return value}:
6782 Returns @code{.TRUE.} if @code{STRING_A >= STRING_B}, and @code{.FALSE.}
6783 otherwise, based on the ASCII ordering.
6785 @item @emph{See also}:
6786 @ref{LGT}, @ref{LLE}, @ref{LLT}
6792 @section @code{LGT} --- Lexical greater than
6794 @cindex lexical comparison of strings
6795 @cindex string, comparison
6798 @item @emph{Description}:
6799 Determines whether one string is lexically greater than another string,
6800 where the two strings are interpreted as containing ASCII character
6801 codes. If the String A and String B are not the same length, the
6802 shorter is compared as if spaces were appended to it to form a value
6803 that has the same length as the longer.
6805 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
6806 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
6807 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
6808 that the latter use the processor's character ordering (which is not
6809 ASCII on some targets), whereas the former always use the ASCII
6812 @item @emph{Standard}:
6813 Fortran 77 and later
6818 @item @emph{Syntax}:
6819 @code{RESULT = LGT(STRING_A, STRING_B)}
6821 @item @emph{Arguments}:
6822 @multitable @columnfractions .15 .70
6823 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
6824 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
6827 @item @emph{Return value}:
6828 Returns @code{.TRUE.} if @code{STRING_A > STRING_B}, and @code{.FALSE.}
6829 otherwise, based on the ASCII ordering.
6831 @item @emph{See also}:
6832 @ref{LGE}, @ref{LLE}, @ref{LLT}
6838 @section @code{LINK} --- Create a hard link
6840 @cindex file system, create link
6841 @cindex file system, hard link
6844 @item @emph{Description}:
6845 Makes a (hard) link from file @var{PATH1} to @var{PATH2}. A null
6846 character (@code{CHAR(0)}) can be used to mark the end of the names in
6847 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
6848 names are ignored. If the @var{STATUS} argument is supplied, it
6849 contains 0 on success or a nonzero error code upon return; see
6852 This intrinsic is provided in both subroutine and function forms;
6853 however, only one form can be used in any given program unit.
6855 @item @emph{Standard}:
6859 Subroutine, function
6861 @item @emph{Syntax}:
6862 @multitable @columnfractions .80
6863 @item @code{CALL LINK(PATH1, PATH2 [, STATUS])}
6864 @item @code{STATUS = LINK(PATH1, PATH2)}
6867 @item @emph{Arguments}:
6868 @multitable @columnfractions .15 .70
6869 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
6870 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
6871 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
6874 @item @emph{See also}:
6875 @ref{SYMLNK}, @ref{UNLINK}
6881 @section @code{LLE} --- Lexical less than or equal
6883 @cindex lexical comparison of strings
6884 @cindex string, comparison
6887 @item @emph{Description}:
6888 Determines whether one string is lexically less than or equal to another
6889 string, where the two strings are interpreted as containing ASCII
6890 character codes. If the String A and String B are not the same length,
6891 the shorter is compared as if spaces were appended to it to form a value
6892 that has the same length as the longer.
6894 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
6895 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
6896 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
6897 that the latter use the processor's character ordering (which is not
6898 ASCII on some targets), whereas the former always use the ASCII
6901 @item @emph{Standard}:
6902 Fortran 77 and later
6907 @item @emph{Syntax}:
6908 @code{RESULT = LLE(STRING_A, STRING_B)}
6910 @item @emph{Arguments}:
6911 @multitable @columnfractions .15 .70
6912 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
6913 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
6916 @item @emph{Return value}:
6917 Returns @code{.TRUE.} if @code{STRING_A <= STRING_B}, and @code{.FALSE.}
6918 otherwise, based on the ASCII ordering.
6920 @item @emph{See also}:
6921 @ref{LGE}, @ref{LGT}, @ref{LLT}
6927 @section @code{LLT} --- Lexical less than
6929 @cindex lexical comparison of strings
6930 @cindex string, comparison
6933 @item @emph{Description}:
6934 Determines whether one string is lexically less than another string,
6935 where the two strings are interpreted as containing ASCII character
6936 codes. If the String A and String B are not the same length, the
6937 shorter is compared as if spaces were appended to it to form a value
6938 that has the same length as the longer.
6940 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
6941 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
6942 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
6943 that the latter use the processor's character ordering (which is not
6944 ASCII on some targets), whereas the former always use the ASCII
6947 @item @emph{Standard}:
6948 Fortran 77 and later
6953 @item @emph{Syntax}:
6954 @code{RESULT = LLT(STRING_A, STRING_B)}
6956 @item @emph{Arguments}:
6957 @multitable @columnfractions .15 .70
6958 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
6959 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
6962 @item @emph{Return value}:
6963 Returns @code{.TRUE.} if @code{STRING_A < STRING_B}, and @code{.FALSE.}
6964 otherwise, based on the ASCII ordering.
6966 @item @emph{See also}:
6967 @ref{LGE}, @ref{LGT}, @ref{LLE}
6973 @section @code{LNBLNK} --- Index of the last non-blank character in a string
6975 @cindex string, find non-blank character
6978 @item @emph{Description}:
6979 Returns the length of a character string, ignoring any trailing blanks.
6980 This is identical to the standard @code{LEN_TRIM} intrinsic, and is only
6981 included for backwards compatibility.
6983 @item @emph{Standard}:
6989 @item @emph{Syntax}:
6990 @code{RESULT = LNBLNK(STRING)}
6992 @item @emph{Arguments}:
6993 @multitable @columnfractions .15 .70
6994 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER},
6995 with @code{INTENT(IN)}
6998 @item @emph{Return value}:
6999 The return value is of @code{INTEGER(kind=4)} type.
7001 @item @emph{See also}:
7002 @ref{INDEX intrinsic}, @ref{LEN_TRIM}
7008 @section @code{LOC} --- Returns the address of a variable
7010 @cindex location of a variable in memory
7013 @item @emph{Description}:
7014 @code{LOC(X)} returns the address of @var{X} as an integer.
7016 @item @emph{Standard}:
7022 @item @emph{Syntax}:
7023 @code{RESULT = LOC(X)}
7025 @item @emph{Arguments}:
7026 @multitable @columnfractions .15 .70
7027 @item @var{X} @tab Variable of any type.
7030 @item @emph{Return value}:
7031 The return value is of type @code{INTEGER}, with a @code{KIND}
7032 corresponding to the size (in bytes) of a memory address on the target
7035 @item @emph{Example}:
7042 end program test_loc
7049 @section @code{LOG} --- Logarithm function
7056 @cindex exponential function, inverse
7057 @cindex logarithmic function
7060 @item @emph{Description}:
7061 @code{LOG(X)} computes the logarithm of @var{X}.
7063 @item @emph{Standard}:
7064 Fortran 77 and later
7069 @item @emph{Syntax}:
7070 @code{RESULT = LOG(X)}
7072 @item @emph{Arguments}:
7073 @multitable @columnfractions .15 .70
7074 @item @var{X} @tab The type shall be @code{REAL} or
7078 @item @emph{Return value}:
7079 The return value is of type @code{REAL} or @code{COMPLEX}.
7080 The kind type parameter is the same as @var{X}.
7081 If @var{X} is @code{COMPLEX}, the imaginary part @math{\omega} is in the range
7082 @math{-\pi \leq \omega \leq \pi}.
7084 @item @emph{Example}:
7087 real(8) :: x = 1.0_8
7088 complex :: z = (1.0, 2.0)
7091 end program test_log
7094 @item @emph{Specific names}:
7095 @multitable @columnfractions .20 .20 .20 .25
7096 @item Name @tab Argument @tab Return type @tab Standard
7097 @item @code{ALOG(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab f95, gnu
7098 @item @code{DLOG(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab f95, gnu
7099 @item @code{CLOG(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab f95, gnu
7100 @item @code{ZLOG(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
7101 @item @code{CDLOG(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
7108 @section @code{LOG10} --- Base 10 logarithm function
7112 @cindex exponential function, inverse
7113 @cindex logarithmic function
7116 @item @emph{Description}:
7117 @code{LOG10(X)} computes the base 10 logarithm of @var{X}.
7119 @item @emph{Standard}:
7120 Fortran 77 and later
7125 @item @emph{Syntax}:
7126 @code{RESULT = LOG10(X)}
7128 @item @emph{Arguments}:
7129 @multitable @columnfractions .15 .70
7130 @item @var{X} @tab The type shall be @code{REAL}.
7133 @item @emph{Return value}:
7134 The return value is of type @code{REAL} or @code{COMPLEX}.
7135 The kind type parameter is the same as @var{X}.
7137 @item @emph{Example}:
7140 real(8) :: x = 10.0_8
7142 end program test_log10
7145 @item @emph{Specific names}:
7146 @multitable @columnfractions .20 .20 .20 .25
7147 @item Name @tab Argument @tab Return type @tab Standard
7148 @item @code{ALOG10(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 95 and later
7149 @item @code{DLOG10(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 95 and later
7156 @section @code{LOG_GAMMA} --- Logarithm of the Gamma function
7161 @cindex Gamma function, logarithm of
7164 @item @emph{Description}:
7165 @code{LOG_GAMMA(X)} computes the natural logarithm of the absolute value
7166 of the Gamma (@math{\Gamma}) function.
7168 @item @emph{Standard}:
7169 Fortran 2008 and later
7174 @item @emph{Syntax}:
7175 @code{X = LOG_GAMMA(X)}
7177 @item @emph{Arguments}:
7178 @multitable @columnfractions .15 .70
7179 @item @var{X} @tab Shall be of type @code{REAL} and neither zero
7180 nor a negative integer.
7183 @item @emph{Return value}:
7184 The return value is of type @code{REAL} of the same kind as @var{X}.
7186 @item @emph{Example}:
7188 program test_log_gamma
7190 x = lgamma(x) ! returns 0.0
7191 end program test_log_gamma
7194 @item @emph{Specific names}:
7195 @multitable @columnfractions .20 .20 .20 .25
7196 @item Name @tab Argument @tab Return type @tab Standard
7197 @item @code{LGAMMA(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab GNU Extension
7198 @item @code{ALGAMA(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab GNU Extension
7199 @item @code{DLGAMA(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU Extension
7202 @item @emph{See also}:
7203 Gamma function: @ref{GAMMA}
7210 @section @code{LOGICAL} --- Convert to logical type
7212 @cindex conversion, to logical
7215 @item @emph{Description}:
7216 Converts one kind of @code{LOGICAL} variable to another.
7218 @item @emph{Standard}:
7219 Fortran 95 and later
7224 @item @emph{Syntax}:
7225 @code{RESULT = LOGICAL(L [, KIND])}
7227 @item @emph{Arguments}:
7228 @multitable @columnfractions .15 .70
7229 @item @var{L} @tab The type shall be @code{LOGICAL}.
7230 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
7231 expression indicating the kind parameter of the result.
7234 @item @emph{Return value}:
7235 The return value is a @code{LOGICAL} value equal to @var{L}, with a
7236 kind corresponding to @var{KIND}, or of the default logical kind if
7237 @var{KIND} is not given.
7239 @item @emph{See also}:
7240 @ref{INT}, @ref{REAL}, @ref{CMPLX}
7246 @section @code{LONG} --- Convert to integer type
7248 @cindex conversion, to integer
7251 @item @emph{Description}:
7252 Convert to a @code{KIND=4} integer type, which is the same size as a C
7253 @code{long} integer. This is equivalent to the standard @code{INT}
7254 intrinsic with an optional argument of @code{KIND=4}, and is only
7255 included for backwards compatibility.
7257 @item @emph{Standard}:
7263 @item @emph{Syntax}:
7264 @code{RESULT = LONG(A)}
7266 @item @emph{Arguments}:
7267 @multitable @columnfractions .15 .70
7268 @item @var{A} @tab Shall be of type @code{INTEGER},
7269 @code{REAL}, or @code{COMPLEX}.
7272 @item @emph{Return value}:
7273 The return value is a @code{INTEGER(4)} variable.
7275 @item @emph{See also}:
7276 @ref{INT}, @ref{INT2}, @ref{INT8}
7282 @section @code{LSHIFT} --- Left shift bits
7284 @cindex bits, shift left
7287 @item @emph{Description}:
7288 @code{LSHIFT} returns a value corresponding to @var{I} with all of the
7289 bits shifted left by @var{SHIFT} places. If the absolute value of
7290 @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the value is undefined.
7291 Bits shifted out from the left end are lost; zeros are shifted in from
7294 This function has been superseded by the @code{ISHFT} intrinsic, which
7295 is standard in Fortran 95 and later.
7297 @item @emph{Standard}:
7303 @item @emph{Syntax}:
7304 @code{RESULT = LSHIFT(I, SHIFT)}
7306 @item @emph{Arguments}:
7307 @multitable @columnfractions .15 .70
7308 @item @var{I} @tab The type shall be @code{INTEGER}.
7309 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
7312 @item @emph{Return value}:
7313 The return value is of type @code{INTEGER} and of the same kind as
7316 @item @emph{See also}:
7317 @ref{ISHFT}, @ref{ISHFTC}, @ref{RSHIFT}
7324 @section @code{LSTAT} --- Get file status
7326 @cindex file system, file status
7329 @item @emph{Description}:
7330 @code{LSTAT} is identical to @ref{STAT}, except that if path is a
7331 symbolic link, then the link itself is statted, not the file that it
7334 The elements in @code{VALUES} are the same as described by @ref{STAT}.
7336 This intrinsic is provided in both subroutine and function forms;
7337 however, only one form can be used in any given program unit.
7339 @item @emph{Standard}:
7343 Subroutine, function
7345 @item @emph{Syntax}:
7346 @code{CALL LSTAT(NAME, VALUES [, STATUS])}
7348 @item @emph{Arguments}:
7349 @multitable @columnfractions .15 .70
7350 @item @var{NAME} @tab The type shall be @code{CHARACTER} of the default
7351 kind, a valid path within the file system.
7352 @item @var{VALUES} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
7353 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}.
7354 Returns 0 on success and a system specific error code otherwise.
7357 @item @emph{Example}:
7358 See @ref{STAT} for an example.
7360 @item @emph{See also}:
7361 To stat an open file: @ref{FSTAT}, to stat a file: @ref{STAT}
7367 @section @code{LTIME} --- Convert time to local time info
7369 @cindex time, conversion to local time info
7372 @item @emph{Description}:
7373 Given a system time value @var{TIME} (as provided by the @code{TIME8()}
7374 intrinsic), fills @var{VALUES} with values extracted from it appropriate
7375 to the local time zone using @code{localtime(3)}.
7377 @item @emph{Standard}:
7383 @item @emph{Syntax}:
7384 @code{CALL LTIME(TIME, VALUES)}
7386 @item @emph{Arguments}:
7387 @multitable @columnfractions .15 .70
7388 @item @var{TIME} @tab An @code{INTEGER} scalar expression
7389 corresponding to a system time, with @code{INTENT(IN)}.
7390 @item @var{VALUES} @tab A default @code{INTEGER} array with 9 elements,
7391 with @code{INTENT(OUT)}.
7394 @item @emph{Return value}:
7395 The elements of @var{VALUES} are assigned as follows:
7397 @item Seconds after the minute, range 0--59 or 0--61 to allow for leap
7399 @item Minutes after the hour, range 0--59
7400 @item Hours past midnight, range 0--23
7401 @item Day of month, range 0--31
7402 @item Number of months since January, range 0--12
7403 @item Years since 1900
7404 @item Number of days since Sunday, range 0--6
7405 @item Days since January 1
7406 @item Daylight savings indicator: positive if daylight savings is in
7407 effect, zero if not, and negative if the information is not available.
7410 @item @emph{See also}:
7411 @ref{CTIME}, @ref{GMTIME}, @ref{TIME}, @ref{TIME8}
7418 @section @code{MALLOC} --- Allocate dynamic memory
7420 @cindex pointer, cray
7423 @item @emph{Description}:
7424 @code{MALLOC(SIZE)} allocates @var{SIZE} bytes of dynamic memory and
7425 returns the address of the allocated memory. The @code{MALLOC} intrinsic
7426 is an extension intended to be used with Cray pointers, and is provided
7427 in GNU Fortran to allow the user to compile legacy code. For new code
7428 using Fortran 95 pointers, the memory allocation intrinsic is
7431 @item @emph{Standard}:
7437 @item @emph{Syntax}:
7438 @code{PTR = MALLOC(SIZE)}
7440 @item @emph{Arguments}:
7441 @multitable @columnfractions .15 .70
7442 @item @var{SIZE} @tab The type shall be @code{INTEGER}.
7445 @item @emph{Return value}:
7446 The return value is of type @code{INTEGER(K)}, with @var{K} such that
7447 variables of type @code{INTEGER(K)} have the same size as
7448 C pointers (@code{sizeof(void *)}).
7450 @item @emph{Example}:
7451 The following example demonstrates the use of @code{MALLOC} and
7452 @code{FREE} with Cray pointers.
7461 ptr_x = malloc(20*8)
7463 x(i) = sqrt(1.0d0 / i)
7471 end program test_malloc
7474 @item @emph{See also}:
7481 @section @code{MATMUL} --- matrix multiplication
7483 @cindex matrix multiplication
7484 @cindex product, matrix
7487 @item @emph{Description}:
7488 Performs a matrix multiplication on numeric or logical arguments.
7490 @item @emph{Standard}:
7491 Fortran 95 and later
7494 Transformational function
7496 @item @emph{Syntax}:
7497 @code{RESULT = MATMUL(MATRIX_A, MATRIX_B)}
7499 @item @emph{Arguments}:
7500 @multitable @columnfractions .15 .70
7501 @item @var{MATRIX_A} @tab An array of @code{INTEGER},
7502 @code{REAL}, @code{COMPLEX}, or @code{LOGICAL} type, with a rank of
7504 @item @var{MATRIX_B} @tab An array of @code{INTEGER},
7505 @code{REAL}, or @code{COMPLEX} type if @var{MATRIX_A} is of a numeric
7506 type; otherwise, an array of @code{LOGICAL} type. The rank shall be one
7507 or two, and the first (or only) dimension of @var{MATRIX_B} shall be
7508 equal to the last (or only) dimension of @var{MATRIX_A}.
7511 @item @emph{Return value}:
7512 The matrix product of @var{MATRIX_A} and @var{MATRIX_B}. The type and
7513 kind of the result follow the usual type and kind promotion rules, as
7514 for the @code{*} or @code{.AND.} operators.
7516 @item @emph{See also}:
7522 @section @code{MAX} --- Maximum value of an argument list
7529 @cindex maximum value
7532 @item @emph{Description}:
7533 Returns the argument with the largest (most positive) value.
7535 @item @emph{Standard}:
7536 Fortran 77 and later
7541 @item @emph{Syntax}:
7542 @code{RESULT = MAX(A1, A2 [, A3 [, ...]])}
7544 @item @emph{Arguments}:
7545 @multitable @columnfractions .15 .70
7546 @item @var{A1} @tab The type shall be @code{INTEGER} or
7548 @item @var{A2}, @var{A3}, ... @tab An expression of the same type and kind
7549 as @var{A1}. (As a GNU extension, arguments of different kinds are
7553 @item @emph{Return value}:
7554 The return value corresponds to the maximum value among the arguments,
7555 and has the same type and kind as the first argument.
7557 @item @emph{Specific names}:
7558 @multitable @columnfractions .20 .20 .20 .25
7559 @item Name @tab Argument @tab Return type @tab Standard
7560 @item @code{MAX0(I)} @tab @code{INTEGER(4) I} @tab @code{INTEGER(4)} @tab Fortran 77 and later
7561 @item @code{AMAX0(I)} @tab @code{INTEGER(4) I} @tab @code{REAL(MAX(X))} @tab Fortran 77 and later
7562 @item @code{MAX1(X)} @tab @code{REAL X} @tab @code{INT(MAX(X))} @tab Fortran 77 and later
7563 @item @code{AMAX1(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
7564 @item @code{DMAX1(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
7567 @item @emph{See also}:
7568 @ref{MAXLOC} @ref{MAXVAL}, @ref{MIN}
7575 @section @code{MAXEXPONENT} --- Maximum exponent of a real kind
7576 @fnindex MAXEXPONENT
7577 @cindex model representation, maximum exponent
7580 @item @emph{Description}:
7581 @code{MAXEXPONENT(X)} returns the maximum exponent in the model of the
7584 @item @emph{Standard}:
7585 Fortran 95 and later
7590 @item @emph{Syntax}:
7591 @code{RESULT = MAXEXPONENT(X)}
7593 @item @emph{Arguments}:
7594 @multitable @columnfractions .15 .70
7595 @item @var{X} @tab Shall be of type @code{REAL}.
7598 @item @emph{Return value}:
7599 The return value is of type @code{INTEGER} and of the default integer
7602 @item @emph{Example}:
7608 print *, minexponent(x), maxexponent(x)
7609 print *, minexponent(y), maxexponent(y)
7610 end program exponents
7617 @section @code{MAXLOC} --- Location of the maximum value within an array
7619 @cindex array, location of maximum element
7622 @item @emph{Description}:
7623 Determines the location of the element in the array with the maximum
7624 value, or, if the @var{DIM} argument is supplied, determines the
7625 locations of the maximum element along each row of the array in the
7626 @var{DIM} direction. If @var{MASK} is present, only the elements for
7627 which @var{MASK} is @code{.TRUE.} are considered. If more than one
7628 element in the array has the maximum value, the location returned is
7629 that of the first such element in array element order. If the array has
7630 zero size, or all of the elements of @var{MASK} are @code{.FALSE.}, then
7631 the result is an array of zeroes. Similarly, if @var{DIM} is supplied
7632 and all of the elements of @var{MASK} along a given row are zero, the
7633 result value for that row is zero.
7635 @item @emph{Standard}:
7636 Fortran 95 and later
7639 Transformational function
7641 @item @emph{Syntax}:
7642 @multitable @columnfractions .80
7643 @item @code{RESULT = MAXLOC(ARRAY, DIM [, MASK])}
7644 @item @code{RESULT = MAXLOC(ARRAY [, MASK])}
7647 @item @emph{Arguments}:
7648 @multitable @columnfractions .15 .70
7649 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER} or
7651 @item @var{DIM} @tab (Optional) Shall be a scalar of type
7652 @code{INTEGER}, with a value between one and the rank of @var{ARRAY},
7653 inclusive. It may not be an optional dummy argument.
7654 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL},
7655 and conformable with @var{ARRAY}.
7658 @item @emph{Return value}:
7659 If @var{DIM} is absent, the result is a rank-one array with a length
7660 equal to the rank of @var{ARRAY}. If @var{DIM} is present, the result
7661 is an array with a rank one less than the rank of @var{ARRAY}, and a
7662 size corresponding to the size of @var{ARRAY} with the @var{DIM}
7663 dimension removed. If @var{DIM} is present and @var{ARRAY} has a rank
7664 of one, the result is a scalar. In all cases, the result is of default
7665 @code{INTEGER} type.
7667 @item @emph{See also}:
7668 @ref{MAX}, @ref{MAXVAL}
7675 @section @code{MAXVAL} --- Maximum value of an array
7677 @cindex array, maximum value
7678 @cindex maximum value
7681 @item @emph{Description}:
7682 Determines the maximum value of the elements in an array value, or, if
7683 the @var{DIM} argument is supplied, determines the maximum value along
7684 each row of the array in the @var{DIM} direction. If @var{MASK} is
7685 present, only the elements for which @var{MASK} is @code{.TRUE.} are
7686 considered. If the array has zero size, or all of the elements of
7687 @var{MASK} are @code{.FALSE.}, then the result is @code{-HUGE(ARRAY)}
7688 if @var{ARRAY} is numeric, or a string of nulls if @var{ARRAY} is of character
7691 @item @emph{Standard}:
7692 Fortran 95 and later
7695 Transformational function
7697 @item @emph{Syntax}:
7698 @multitable @columnfractions .80
7699 @item @code{RESULT = MAXVAL(ARRAY, DIM [, MASK])}
7700 @item @code{RESULT = MAXVAL(ARRAY [, MASK])}
7703 @item @emph{Arguments}:
7704 @multitable @columnfractions .15 .70
7705 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER} or
7707 @item @var{DIM} @tab (Optional) Shall be a scalar of type
7708 @code{INTEGER}, with a value between one and the rank of @var{ARRAY},
7709 inclusive. It may not be an optional dummy argument.
7710 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL},
7711 and conformable with @var{ARRAY}.
7714 @item @emph{Return value}:
7715 If @var{DIM} is absent, or if @var{ARRAY} has a rank of one, the result
7716 is a scalar. If @var{DIM} is present, the result is an array with a
7717 rank one less than the rank of @var{ARRAY}, and a size corresponding to
7718 the size of @var{ARRAY} with the @var{DIM} dimension removed. In all
7719 cases, the result is of the same type and kind as @var{ARRAY}.
7721 @item @emph{See also}:
7722 @ref{MAX}, @ref{MAXLOC}
7728 @section @code{MCLOCK} --- Time function
7730 @cindex time, clock ticks
7734 @item @emph{Description}:
7735 Returns the number of clock ticks since the start of the process, based
7736 on the UNIX function @code{clock(3)}.
7738 This intrinsic is not fully portable, such as to systems with 32-bit
7739 @code{INTEGER} types but supporting times wider than 32 bits. Therefore,
7740 the values returned by this intrinsic might be, or become, negative, or
7741 numerically less than previous values, during a single run of the
7744 @item @emph{Standard}:
7750 @item @emph{Syntax}:
7751 @code{RESULT = MCLOCK()}
7753 @item @emph{Return value}:
7754 The return value is a scalar of type @code{INTEGER(4)}, equal to the
7755 number of clock ticks since the start of the process, or @code{-1} if
7756 the system does not support @code{clock(3)}.
7758 @item @emph{See also}:
7759 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK}, @ref{TIME}
7766 @section @code{MCLOCK8} --- Time function (64-bit)
7768 @cindex time, clock ticks
7772 @item @emph{Description}:
7773 Returns the number of clock ticks since the start of the process, based
7774 on the UNIX function @code{clock(3)}.
7776 @emph{Warning:} this intrinsic does not increase the range of the timing
7777 values over that returned by @code{clock(3)}. On a system with a 32-bit
7778 @code{clock(3)}, @code{MCLOCK8()} will return a 32-bit value, even though
7779 it is converted to a 64-bit @code{INTEGER(8)} value. That means
7780 overflows of the 32-bit value can still occur. Therefore, the values
7781 returned by this intrinsic might be or become negative or numerically
7782 less than previous values during a single run of the compiled program.
7784 @item @emph{Standard}:
7790 @item @emph{Syntax}:
7791 @code{RESULT = MCLOCK8()}
7793 @item @emph{Return value}:
7794 The return value is a scalar of type @code{INTEGER(8)}, equal to the
7795 number of clock ticks since the start of the process, or @code{-1} if
7796 the system does not support @code{clock(3)}.
7798 @item @emph{See also}:
7799 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK}, @ref{TIME8}
7806 @section @code{MERGE} --- Merge variables
7808 @cindex array, merge arrays
7809 @cindex array, combine arrays
7812 @item @emph{Description}:
7813 Select values from two arrays according to a logical mask. The result
7814 is equal to @var{TSOURCE} if @var{MASK} is @code{.TRUE.}, or equal to
7815 @var{FSOURCE} if it is @code{.FALSE.}.
7817 @item @emph{Standard}:
7818 Fortran 95 and later
7823 @item @emph{Syntax}:
7824 @code{RESULT = MERGE(TSOURCE, FSOURCE, MASK)}
7826 @item @emph{Arguments}:
7827 @multitable @columnfractions .15 .70
7828 @item @var{TSOURCE} @tab May be of any type.
7829 @item @var{FSOURCE} @tab Shall be of the same type and type parameters
7831 @item @var{MASK} @tab Shall be of type @code{LOGICAL}.
7834 @item @emph{Return value}:
7835 The result is of the same type and type parameters as @var{TSOURCE}.
7842 @section @code{MIN} --- Minimum value of an argument list
7849 @cindex minimum value
7852 @item @emph{Description}:
7853 Returns the argument with the smallest (most negative) value.
7855 @item @emph{Standard}:
7856 Fortran 77 and later
7861 @item @emph{Syntax}:
7862 @code{RESULT = MIN(A1, A2 [, A3, ...])}
7864 @item @emph{Arguments}:
7865 @multitable @columnfractions .15 .70
7866 @item @var{A1} @tab The type shall be @code{INTEGER} or
7868 @item @var{A2}, @var{A3}, ... @tab An expression of the same type and kind
7869 as @var{A1}. (As a GNU extension, arguments of different kinds are
7873 @item @emph{Return value}:
7874 The return value corresponds to the maximum value among the arguments,
7875 and has the same type and kind as the first argument.
7877 @item @emph{Specific names}:
7878 @multitable @columnfractions .20 .20 .20 .25
7879 @item Name @tab Argument @tab Return type @tab Standard
7880 @item @code{MIN0(I)} @tab @code{INTEGER(4) I} @tab @code{INTEGER(4)} @tab Fortran 77 and later
7881 @item @code{AMIN0(I)} @tab @code{INTEGER(4) I} @tab @code{REAL(MIN(X))} @tab Fortran 77 and later
7882 @item @code{MIN1(X)} @tab @code{REAL X} @tab @code{INT(MIN(X))} @tab Fortran 77 and later
7883 @item @code{AMIN1(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab Fortran 77 and later
7884 @item @code{DMIN1(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 77 and later
7887 @item @emph{See also}:
7888 @ref{MAX}, @ref{MINLOC}, @ref{MINVAL}
7894 @section @code{MINEXPONENT} --- Minimum exponent of a real kind
7895 @fnindex MINEXPONENT
7896 @cindex model representation, minimum exponent
7899 @item @emph{Description}:
7900 @code{MINEXPONENT(X)} returns the minimum exponent in the model of the
7903 @item @emph{Standard}:
7904 Fortran 95 and later
7909 @item @emph{Syntax}:
7910 @code{RESULT = MINEXPONENT(X)}
7912 @item @emph{Arguments}:
7913 @multitable @columnfractions .15 .70
7914 @item @var{X} @tab Shall be of type @code{REAL}.
7917 @item @emph{Return value}:
7918 The return value is of type @code{INTEGER} and of the default integer
7921 @item @emph{Example}:
7922 See @code{MAXEXPONENT} for an example.
7928 @section @code{MINLOC} --- Location of the minimum value within an array
7930 @cindex array, location of minimum element
7933 @item @emph{Description}:
7934 Determines the location of the element in the array with the minimum
7935 value, or, if the @var{DIM} argument is supplied, determines the
7936 locations of the minimum element along each row of the array in the
7937 @var{DIM} direction. If @var{MASK} is present, only the elements for
7938 which @var{MASK} is @code{.TRUE.} are considered. If more than one
7939 element in the array has the minimum value, the location returned is
7940 that of the first such element in array element order. If the array has
7941 zero size, or all of the elements of @var{MASK} are @code{.FALSE.}, then
7942 the result is an array of zeroes. Similarly, if @var{DIM} is supplied
7943 and all of the elements of @var{MASK} along a given row are zero, the
7944 result value for that row is zero.
7946 @item @emph{Standard}:
7947 Fortran 95 and later
7950 Transformational function
7952 @item @emph{Syntax}:
7953 @multitable @columnfractions .80
7954 @item @code{RESULT = MINLOC(ARRAY, DIM [, MASK])}
7955 @item @code{RESULT = MINLOC(ARRAY [, MASK])}
7958 @item @emph{Arguments}:
7959 @multitable @columnfractions .15 .70
7960 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER} or
7962 @item @var{DIM} @tab (Optional) Shall be a scalar of type
7963 @code{INTEGER}, with a value between one and the rank of @var{ARRAY},
7964 inclusive. It may not be an optional dummy argument.
7965 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL},
7966 and conformable with @var{ARRAY}.
7969 @item @emph{Return value}:
7970 If @var{DIM} is absent, the result is a rank-one array with a length
7971 equal to the rank of @var{ARRAY}. If @var{DIM} is present, the result
7972 is an array with a rank one less than the rank of @var{ARRAY}, and a
7973 size corresponding to the size of @var{ARRAY} with the @var{DIM}
7974 dimension removed. If @var{DIM} is present and @var{ARRAY} has a rank
7975 of one, the result is a scalar. In all cases, the result is of default
7976 @code{INTEGER} type.
7978 @item @emph{See also}:
7979 @ref{MIN}, @ref{MINVAL}
7986 @section @code{MINVAL} --- Minimum value of an array
7988 @cindex array, minimum value
7989 @cindex minimum value
7992 @item @emph{Description}:
7993 Determines the minimum value of the elements in an array value, or, if
7994 the @var{DIM} argument is supplied, determines the minimum value along
7995 each row of the array in the @var{DIM} direction. If @var{MASK} is
7996 present, only the elements for which @var{MASK} is @code{.TRUE.} are
7997 considered. If the array has zero size, or all of the elements of
7998 @var{MASK} are @code{.FALSE.}, then the result is @code{HUGE(ARRAY)} if
7999 @var{ARRAY} is numeric, or a string of @code{CHAR(255)} characters if
8000 @var{ARRAY} is of character type.
8002 @item @emph{Standard}:
8003 Fortran 95 and later
8006 Transformational function
8008 @item @emph{Syntax}:
8009 @multitable @columnfractions .80
8010 @item @code{RESULT = MINVAL(ARRAY, DIM [, MASK])}
8011 @item @code{RESULT = MINVAL(ARRAY [, MASK])}
8014 @item @emph{Arguments}:
8015 @multitable @columnfractions .15 .70
8016 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER} or
8018 @item @var{DIM} @tab (Optional) Shall be a scalar of type
8019 @code{INTEGER}, with a value between one and the rank of @var{ARRAY},
8020 inclusive. It may not be an optional dummy argument.
8021 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL},
8022 and conformable with @var{ARRAY}.
8025 @item @emph{Return value}:
8026 If @var{DIM} is absent, or if @var{ARRAY} has a rank of one, the result
8027 is a scalar. If @var{DIM} is present, the result is an array with a
8028 rank one less than the rank of @var{ARRAY}, and a size corresponding to
8029 the size of @var{ARRAY} with the @var{DIM} dimension removed. In all
8030 cases, the result is of the same type and kind as @var{ARRAY}.
8032 @item @emph{See also}:
8033 @ref{MIN}, @ref{MINLOC}
8040 @section @code{MOD} --- Remainder function
8045 @cindex division, remainder
8048 @item @emph{Description}:
8049 @code{MOD(A,P)} computes the remainder of the division of A by P@. It is
8050 calculated as @code{A - (INT(A/P) * P)}.
8052 @item @emph{Standard}:
8053 Fortran 77 and later
8058 @item @emph{Syntax}:
8059 @code{RESULT = MOD(A, P)}
8061 @item @emph{Arguments}:
8062 @multitable @columnfractions .15 .70
8063 @item @var{A} @tab Shall be a scalar of type @code{INTEGER} or @code{REAL}
8064 @item @var{P} @tab Shall be a scalar of the same type as @var{A} and not
8068 @item @emph{Return value}:
8069 The kind of the return value is the result of cross-promoting
8070 the kinds of the arguments.
8072 @item @emph{Example}:
8076 print *, mod(17.5,5.5)
8077 print *, mod(17.5d0,5.5)
8078 print *, mod(17.5,5.5d0)
8081 print *, mod(-17.5,5.5)
8082 print *, mod(-17.5d0,5.5)
8083 print *, mod(-17.5,5.5d0)
8086 print *, mod(17.5,-5.5)
8087 print *, mod(17.5d0,-5.5)
8088 print *, mod(17.5,-5.5d0)
8089 end program test_mod
8092 @item @emph{Specific names}:
8093 @multitable @columnfractions .20 .20 .20 .25
8094 @item Name @tab Arguments @tab Return type @tab Standard
8095 @item @code{AMOD(A,P)} @tab @code{REAL(4)} @tab @code{REAL(4)} @tab Fortran 95 and later
8096 @item @code{DMOD(A,P)} @tab @code{REAL(8)} @tab @code{REAL(8)} @tab Fortran 95 and later
8103 @section @code{MODULO} --- Modulo function
8106 @cindex division, modulo
8109 @item @emph{Description}:
8110 @code{MODULO(A,P)} computes the @var{A} modulo @var{P}.
8112 @item @emph{Standard}:
8113 Fortran 95 and later
8118 @item @emph{Syntax}:
8119 @code{RESULT = MODULO(A, P)}
8121 @item @emph{Arguments}:
8122 @multitable @columnfractions .15 .70
8123 @item @var{A} @tab Shall be a scalar of type @code{INTEGER} or @code{REAL}
8124 @item @var{P} @tab Shall be a scalar of the same type and kind as @var{A}
8127 @item @emph{Return value}:
8128 The type and kind of the result are those of the arguments.
8130 @item If @var{A} and @var{P} are of type @code{INTEGER}:
8131 @code{MODULO(A,P)} has the value @var{R} such that @code{A=Q*P+R}, where
8132 @var{Q} is an integer and @var{R} is between 0 (inclusive) and @var{P}
8134 @item If @var{A} and @var{P} are of type @code{REAL}:
8135 @code{MODULO(A,P)} has the value of @code{A - FLOOR (A / P) * P}.
8137 In all cases, if @var{P} is zero the result is processor-dependent.
8139 @item @emph{Example}:
8142 print *, modulo(17,3)
8143 print *, modulo(17.5,5.5)
8145 print *, modulo(-17,3)
8146 print *, modulo(-17.5,5.5)
8148 print *, modulo(17,-3)
8149 print *, modulo(17.5,-5.5)
8158 @section @code{MOVE_ALLOC} --- Move allocation from one object to another
8160 @cindex moving allocation
8161 @cindex allocation, moving
8164 @item @emph{Description}:
8165 @code{MOVE_ALLOC(FROM, TO)} moves the allocation from @var{FROM} to
8166 @var{TO}. @var{FROM} will become deallocated in the process.
8168 @item @emph{Standard}:
8169 Fortran 2003 and later
8174 @item @emph{Syntax}:
8175 @code{CALL MOVE_ALLOC(FROM, TO)}
8177 @item @emph{Arguments}:
8178 @multitable @columnfractions .15 .70
8179 @item @var{FROM} @tab @code{ALLOCATABLE}, @code{INTENT(INOUT)}, may be
8180 of any type and kind.
8181 @item @var{TO} @tab @code{ALLOCATABLE}, @code{INTENT(OUT)}, shall be
8182 of the same type, kind and rank as @var{FROM}.
8185 @item @emph{Return value}:
8188 @item @emph{Example}:
8190 program test_move_alloc
8191 integer, allocatable :: a(:), b(:)
8195 call move_alloc(a, b)
8196 print *, allocated(a), allocated(b)
8198 end program test_move_alloc
8205 @section @code{MVBITS} --- Move bits from one integer to another
8210 @item @emph{Description}:
8211 Moves @var{LEN} bits from positions @var{FROMPOS} through
8212 @code{FROMPOS+LEN-1} of @var{FROM} to positions @var{TOPOS} through
8213 @code{TOPOS+LEN-1} of @var{TO}. The portion of argument @var{TO} not
8214 affected by the movement of bits is unchanged. The values of
8215 @code{FROMPOS+LEN-1} and @code{TOPOS+LEN-1} must be less than
8216 @code{BIT_SIZE(FROM)}.
8218 @item @emph{Standard}:
8219 Fortran 95 and later
8222 Elemental subroutine
8224 @item @emph{Syntax}:
8225 @code{CALL MVBITS(FROM, FROMPOS, LEN, TO, TOPOS)}
8227 @item @emph{Arguments}:
8228 @multitable @columnfractions .15 .70
8229 @item @var{FROM} @tab The type shall be @code{INTEGER}.
8230 @item @var{FROMPOS} @tab The type shall be @code{INTEGER}.
8231 @item @var{LEN} @tab The type shall be @code{INTEGER}.
8232 @item @var{TO} @tab The type shall be @code{INTEGER}, of the
8233 same kind as @var{FROM}.
8234 @item @var{TOPOS} @tab The type shall be @code{INTEGER}.
8237 @item @emph{See also}:
8238 @ref{IBCLR}, @ref{IBSET}, @ref{IBITS}, @ref{IAND}, @ref{IOR}, @ref{IEOR}
8244 @section @code{NEAREST} --- Nearest representable number
8246 @cindex real number, nearest different
8247 @cindex floating point, nearest different
8250 @item @emph{Description}:
8251 @code{NEAREST(X, S)} returns the processor-representable number nearest
8252 to @code{X} in the direction indicated by the sign of @code{S}.
8254 @item @emph{Standard}:
8255 Fortran 95 and later
8260 @item @emph{Syntax}:
8261 @code{RESULT = NEAREST(X, S)}
8263 @item @emph{Arguments}:
8264 @multitable @columnfractions .15 .70
8265 @item @var{X} @tab Shall be of type @code{REAL}.
8266 @item @var{S} @tab (Optional) shall be of type @code{REAL} and
8270 @item @emph{Return value}:
8271 The return value is of the same type as @code{X}. If @code{S} is
8272 positive, @code{NEAREST} returns the processor-representable number
8273 greater than @code{X} and nearest to it. If @code{S} is negative,
8274 @code{NEAREST} returns the processor-representable number smaller than
8275 @code{X} and nearest to it.
8277 @item @emph{Example}:
8279 program test_nearest
8281 x = nearest(42.0, 1.0)
8282 y = nearest(42.0, -1.0)
8283 write (*,"(3(G20.15))") x, y, x - y
8284 end program test_nearest
8291 @section @code{NEW_LINE} --- New line character
8294 @cindex output, newline
8297 @item @emph{Description}:
8298 @code{NEW_LINE(C)} returns the new-line character.
8300 @item @emph{Standard}:
8301 Fortran 2003 and later
8306 @item @emph{Syntax}:
8307 @code{RESULT = NEW_LINE(C)}
8309 @item @emph{Arguments}:
8310 @multitable @columnfractions .15 .70
8311 @item @var{C} @tab The argument shall be a scalar or array of the
8312 type @code{CHARACTER}.
8315 @item @emph{Return value}:
8316 Returns a @var{CHARACTER} scalar of length one with the new-line character of
8317 the same kind as parameter @var{C}.
8319 @item @emph{Example}:
8323 write(*,'(A)') 'This is record 1.'//NEW_LINE('A')//'This is record 2.'
8331 @section @code{NINT} --- Nearest whole number
8334 @cindex rounding, nearest whole number
8337 @item @emph{Description}:
8338 @code{NINT(A)} rounds its argument to the nearest whole number.
8340 @item @emph{Standard}:
8341 Fortran 77 and later, with @var{KIND} argument Fortran 90 and later
8346 @item @emph{Syntax}:
8347 @code{RESULT = NINT(A [, KIND])}
8349 @item @emph{Arguments}:
8350 @multitable @columnfractions .15 .70
8351 @item @var{A} @tab The type of the argument shall be @code{REAL}.
8352 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
8353 expression indicating the kind parameter of the result.
8356 @item @emph{Return value}:
8357 Returns @var{A} with the fractional portion of its magnitude eliminated by
8358 rounding to the nearest whole number and with its sign preserved,
8359 converted to an @code{INTEGER} of the default kind.
8361 @item @emph{Example}:
8368 print *, nint(x4), idnint(x8)
8369 end program test_nint
8372 @item @emph{Specific names}:
8373 @multitable @columnfractions .25 .25 .25
8374 @item Name @tab Argument @tab Standard
8375 @item @code{IDNINT(X)} @tab @code{REAL(8)} @tab Fortran 95 and later
8378 @item @emph{See also}:
8379 @ref{CEILING}, @ref{FLOOR}
8386 @section @code{NOT} --- Logical negation
8388 @cindex bits, negate
8389 @cindex bitwise logical not
8390 @cindex logical not, bitwise
8393 @item @emph{Description}:
8394 @code{NOT} returns the bitwise boolean inverse of @var{I}.
8396 @item @emph{Standard}:
8397 Fortran 95 and later
8402 @item @emph{Syntax}:
8403 @code{RESULT = NOT(I)}
8405 @item @emph{Arguments}:
8406 @multitable @columnfractions .15 .70
8407 @item @var{I} @tab The type shall be @code{INTEGER}.
8410 @item @emph{Return value}:
8411 The return type is @code{INTEGER}, of the same kind as the
8414 @item @emph{See also}:
8415 @ref{IAND}, @ref{IEOR}, @ref{IOR}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}
8422 @section @code{NULL} --- Function that returns an disassociated pointer
8424 @cindex pointer, status
8425 @cindex pointer, disassociated
8428 @item @emph{Description}:
8429 Returns a disassociated pointer.
8431 If @var{MOLD} is present, a dissassociated pointer of the same type is
8432 returned, otherwise the type is determined by context.
8434 In Fortran 95, @var{MOLD} is optional. Please note that Fortran 2003
8435 includes cases where it is required.
8437 @item @emph{Standard}:
8438 Fortran 95 and later
8441 Transformational function
8443 @item @emph{Syntax}:
8444 @code{PTR => NULL([MOLD])}
8446 @item @emph{Arguments}:
8447 @multitable @columnfractions .15 .70
8448 @item @var{MOLD} @tab (Optional) shall be a pointer of any association
8449 status and of any type.
8452 @item @emph{Return value}:
8453 A disassociated pointer.
8455 @item @emph{Example}:
8457 REAL, POINTER, DIMENSION(:) :: VEC => NULL ()
8460 @item @emph{See also}:
8467 @section @code{NUM_IMAGES} --- Function that returns the number of images
8469 @cindex coarray, NUM_IMAGES
8470 @cindex images, number of
8473 @item @emph{Description}:
8474 Returns the number of images.
8476 @item @emph{Standard}:
8477 Fortran 2008 and later
8480 Transformational function
8482 @item @emph{Syntax}:
8483 @code{RESULT = NUM_IMAGES()}
8485 @item @emph{Arguments}: None.
8487 @item @emph{Return value}:
8488 Scalar default-kind integer.
8490 @item @emph{Example}:
8494 value = THIS_IMAGE()
8496 IF (THIS_IMAGE() == 1) THEN
8497 DO i = 1, NUM_IMAGES()
8498 WRITE(*,'(2(a,i0))') 'value[', i, '] is ', value[i]
8503 @item @emph{See also}:
8504 @ref{THIS_IMAGE}, @ref{IMAGE_INDEX}
8510 @section @code{OR} --- Bitwise logical OR
8512 @cindex bitwise logical or
8513 @cindex logical or, bitwise
8516 @item @emph{Description}:
8517 Bitwise logical @code{OR}.
8519 This intrinsic routine is provided for backwards compatibility with
8520 GNU Fortran 77. For integer arguments, programmers should consider
8521 the use of the @ref{IOR} intrinsic defined by the Fortran standard.
8523 @item @emph{Standard}:
8529 @item @emph{Syntax}:
8530 @code{RESULT = OR(I, J)}
8532 @item @emph{Arguments}:
8533 @multitable @columnfractions .15 .70
8534 @item @var{I} @tab The type shall be either a scalar @code{INTEGER}
8535 type or a scalar @code{LOGICAL} type.
8536 @item @var{J} @tab The type shall be the same as the type of @var{J}.
8539 @item @emph{Return value}:
8540 The return type is either a scalar @code{INTEGER} or a scalar
8541 @code{LOGICAL}. If the kind type parameters differ, then the
8542 smaller kind type is implicitly converted to larger kind, and the
8543 return has the larger kind.
8545 @item @emph{Example}:
8548 LOGICAL :: T = .TRUE., F = .FALSE.
8550 DATA a / Z'F' /, b / Z'3' /
8552 WRITE (*,*) OR(T, T), OR(T, F), OR(F, T), OR(F, F)
8553 WRITE (*,*) OR(a, b)
8557 @item @emph{See also}:
8558 Fortran 95 elemental function: @ref{IOR}
8564 @section @code{PACK} --- Pack an array into an array of rank one
8566 @cindex array, packing
8567 @cindex array, reduce dimension
8568 @cindex array, gather elements
8571 @item @emph{Description}:
8572 Stores the elements of @var{ARRAY} in an array of rank one.
8574 The beginning of the resulting array is made up of elements whose @var{MASK}
8575 equals @code{TRUE}. Afterwards, positions are filled with elements taken from
8578 @item @emph{Standard}:
8579 Fortran 95 and later
8582 Transformational function
8584 @item @emph{Syntax}:
8585 @code{RESULT = PACK(ARRAY, MASK[,VECTOR]}
8587 @item @emph{Arguments}:
8588 @multitable @columnfractions .15 .70
8589 @item @var{ARRAY} @tab Shall be an array of any type.
8590 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL} and
8591 of the same size as @var{ARRAY}. Alternatively, it may be a @code{LOGICAL}
8593 @item @var{VECTOR} @tab (Optional) shall be an array of the same type
8594 as @var{ARRAY} and of rank one. If present, the number of elements in
8595 @var{VECTOR} shall be equal to or greater than the number of true elements
8596 in @var{MASK}. If @var{MASK} is scalar, the number of elements in
8597 @var{VECTOR} shall be equal to or greater than the number of elements in
8601 @item @emph{Return value}:
8602 The result is an array of rank one and the same type as that of @var{ARRAY}.
8603 If @var{VECTOR} is present, the result size is that of @var{VECTOR}, the
8604 number of @code{TRUE} values in @var{MASK} otherwise.
8606 @item @emph{Example}:
8607 Gathering nonzero elements from an array:
8611 m = (/ 1, 0, 0, 0, 5, 0 /)
8612 WRITE(*, FMT="(6(I0, ' '))") pack(m, m /= 0) ! "1 5"
8616 Gathering nonzero elements from an array and appending elements from @var{VECTOR}:
8620 m = (/ 1, 0, 0, 2 /)
8621 WRITE(*, FMT="(4(I0, ' '))") pack(m, m /= 0, (/ 0, 0, 3, 4 /)) ! "1 2 3 4"
8625 @item @emph{See also}:
8632 @section @code{PERROR} --- Print system error message
8634 @cindex system, error handling
8637 @item @emph{Description}:
8638 Prints (on the C @code{stderr} stream) a newline-terminated error
8639 message corresponding to the last system error. This is prefixed by
8640 @var{STRING}, a colon and a space. See @code{perror(3)}.
8642 @item @emph{Standard}:
8648 @item @emph{Syntax}:
8649 @code{CALL PERROR(STRING)}
8651 @item @emph{Arguments}:
8652 @multitable @columnfractions .15 .70
8653 @item @var{STRING} @tab A scalar of type @code{CHARACTER} and of the
8657 @item @emph{See also}:
8664 @section @code{PRECISION} --- Decimal precision of a real kind
8666 @cindex model representation, precision
8669 @item @emph{Description}:
8670 @code{PRECISION(X)} returns the decimal precision in the model of the
8673 @item @emph{Standard}:
8674 Fortran 95 and later
8679 @item @emph{Syntax}:
8680 @code{RESULT = PRECISION(X)}
8682 @item @emph{Arguments}:
8683 @multitable @columnfractions .15 .70
8684 @item @var{X} @tab Shall be of type @code{REAL} or @code{COMPLEX}.
8687 @item @emph{Return value}:
8688 The return value is of type @code{INTEGER} and of the default integer
8691 @item @emph{Example}:
8693 program prec_and_range
8694 real(kind=4) :: x(2)
8695 complex(kind=8) :: y
8697 print *, precision(x), range(x)
8698 print *, precision(y), range(y)
8699 end program prec_and_range
8706 @section @code{PRESENT} --- Determine whether an optional dummy argument is specified
8710 @item @emph{Description}:
8711 Determines whether an optional dummy argument is present.
8713 @item @emph{Standard}:
8714 Fortran 95 and later
8719 @item @emph{Syntax}:
8720 @code{RESULT = PRESENT(A)}
8722 @item @emph{Arguments}:
8723 @multitable @columnfractions .15 .70
8724 @item @var{A} @tab May be of any type and may be a pointer, scalar or array
8725 value, or a dummy procedure. It shall be the name of an optional dummy argument
8726 accessible within the current subroutine or function.
8729 @item @emph{Return value}:
8730 Returns either @code{TRUE} if the optional argument @var{A} is present, or
8731 @code{FALSE} otherwise.
8733 @item @emph{Example}:
8735 PROGRAM test_present
8736 WRITE(*,*) f(), f(42) ! "F T"
8738 LOGICAL FUNCTION f(x)
8739 INTEGER, INTENT(IN), OPTIONAL :: x
8749 @section @code{PRODUCT} --- Product of array elements
8751 @cindex array, product
8752 @cindex array, multiply elements
8753 @cindex array, conditionally multiply elements
8754 @cindex multiply array elements
8757 @item @emph{Description}:
8758 Multiplies the elements of @var{ARRAY} along dimension @var{DIM} if
8759 the corresponding element in @var{MASK} is @code{TRUE}.
8761 @item @emph{Standard}:
8762 Fortran 95 and later
8765 Transformational function
8767 @item @emph{Syntax}:
8768 @multitable @columnfractions .80
8769 @item @code{RESULT = PRODUCT(ARRAY[, MASK])}
8770 @item @code{RESULT = PRODUCT(ARRAY, DIM[, MASK])}
8773 @item @emph{Arguments}:
8774 @multitable @columnfractions .15 .70
8775 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER},
8776 @code{REAL} or @code{COMPLEX}.
8777 @item @var{DIM} @tab (Optional) shall be a scalar of type
8778 @code{INTEGER} with a value in the range from 1 to n, where n
8779 equals the rank of @var{ARRAY}.
8780 @item @var{MASK} @tab (Optional) shall be of type @code{LOGICAL}
8781 and either be a scalar or an array of the same shape as @var{ARRAY}.
8784 @item @emph{Return value}:
8785 The result is of the same type as @var{ARRAY}.
8787 If @var{DIM} is absent, a scalar with the product of all elements in
8788 @var{ARRAY} is returned. Otherwise, an array of rank n-1, where n equals
8789 the rank of @var{ARRAY}, and a shape similar to that of @var{ARRAY} with
8790 dimension @var{DIM} dropped is returned.
8793 @item @emph{Example}:
8795 PROGRAM test_product
8796 INTEGER :: x(5) = (/ 1, 2, 3, 4 ,5 /)
8797 print *, PRODUCT(x) ! all elements, product = 120
8798 print *, PRODUCT(x, MASK=MOD(x, 2)==1) ! odd elements, product = 15
8802 @item @emph{See also}:
8809 @section @code{RADIX} --- Base of a model number
8811 @cindex model representation, base
8812 @cindex model representation, radix
8815 @item @emph{Description}:
8816 @code{RADIX(X)} returns the base of the model representing the entity @var{X}.
8818 @item @emph{Standard}:
8819 Fortran 95 and later
8824 @item @emph{Syntax}:
8825 @code{RESULT = RADIX(X)}
8827 @item @emph{Arguments}:
8828 @multitable @columnfractions .15 .70
8829 @item @var{X} @tab Shall be of type @code{INTEGER} or @code{REAL}
8832 @item @emph{Return value}:
8833 The return value is a scalar of type @code{INTEGER} and of the default
8836 @item @emph{Example}:
8839 print *, "The radix for the default integer kind is", radix(0)
8840 print *, "The radix for the default real kind is", radix(0.0)
8841 end program test_radix
8849 @section @code{RAN} --- Real pseudo-random number
8851 @cindex random number generation
8854 @item @emph{Description}:
8855 For compatibility with HP FORTRAN 77/iX, the @code{RAN} intrinsic is
8856 provided as an alias for @code{RAND}. See @ref{RAND} for complete
8859 @item @emph{Standard}:
8865 @item @emph{See also}:
8866 @ref{RAND}, @ref{RANDOM_NUMBER}
8872 @section @code{RAND} --- Real pseudo-random number
8874 @cindex random number generation
8877 @item @emph{Description}:
8878 @code{RAND(FLAG)} returns a pseudo-random number from a uniform
8879 distribution between 0 and 1. If @var{FLAG} is 0, the next number
8880 in the current sequence is returned; if @var{FLAG} is 1, the generator
8881 is restarted by @code{CALL SRAND(0)}; if @var{FLAG} has any other value,
8882 it is used as a new seed with @code{SRAND}.
8884 This intrinsic routine is provided for backwards compatibility with
8885 GNU Fortran 77. It implements a simple modulo generator as provided
8886 by @command{g77}. For new code, one should consider the use of
8887 @ref{RANDOM_NUMBER} as it implements a superior algorithm.
8889 @item @emph{Standard}:
8895 @item @emph{Syntax}:
8896 @code{RESULT = RAND(I)}
8898 @item @emph{Arguments}:
8899 @multitable @columnfractions .15 .70
8900 @item @var{I} @tab Shall be a scalar @code{INTEGER} of kind 4.
8903 @item @emph{Return value}:
8904 The return value is of @code{REAL} type and the default kind.
8906 @item @emph{Example}:
8909 integer,parameter :: seed = 86456
8912 print *, rand(), rand(), rand(), rand()
8913 print *, rand(seed), rand(), rand(), rand()
8914 end program test_rand
8917 @item @emph{See also}:
8918 @ref{SRAND}, @ref{RANDOM_NUMBER}
8925 @section @code{RANDOM_NUMBER} --- Pseudo-random number
8926 @fnindex RANDOM_NUMBER
8927 @cindex random number generation
8930 @item @emph{Description}:
8931 Returns a single pseudorandom number or an array of pseudorandom numbers
8932 from the uniform distribution over the range @math{ 0 \leq x < 1}.
8934 The runtime-library implements George Marsaglia's KISS (Keep It Simple
8935 Stupid) random number generator (RNG). This RNG combines:
8937 @item The congruential generator @math{x(n) = 69069 \cdot x(n-1) + 1327217885}
8938 with a period of @math{2^{32}},
8939 @item A 3-shift shift-register generator with a period of @math{2^{32} - 1},
8940 @item Two 16-bit multiply-with-carry generators with a period of
8941 @math{597273182964842497 > 2^{59}}.
8943 The overall period exceeds @math{2^{123}}.
8945 Please note, this RNG is thread safe if used within OpenMP directives,
8946 i.e., its state will be consistent while called from multiple threads.
8947 However, the KISS generator does not create random numbers in parallel
8948 from multiple sources, but in sequence from a single source. If an
8949 OpenMP-enabled application heavily relies on random numbers, one should
8950 consider employing a dedicated parallel random number generator instead.
8952 @item @emph{Standard}:
8953 Fortran 95 and later
8958 @item @emph{Syntax}:
8959 @code{RANDOM_NUMBER(HARVEST)}
8961 @item @emph{Arguments}:
8962 @multitable @columnfractions .15 .70
8963 @item @var{HARVEST} @tab Shall be a scalar or an array of type @code{REAL}.
8966 @item @emph{Example}:
8968 program test_random_number
8970 CALL init_random_seed() ! see example of RANDOM_SEED
8971 CALL RANDOM_NUMBER(r)
8975 @item @emph{See also}:
8982 @section @code{RANDOM_SEED} --- Initialize a pseudo-random number sequence
8983 @fnindex RANDOM_SEED
8984 @cindex random number generation, seeding
8985 @cindex seeding a random number generator
8988 @item @emph{Description}:
8989 Restarts or queries the state of the pseudorandom number generator used by
8990 @code{RANDOM_NUMBER}.
8992 If @code{RANDOM_SEED} is called without arguments, it is initialized to
8993 a default state. The example below shows how to initialize the random
8994 seed based on the system's time.
8996 @item @emph{Standard}:
8997 Fortran 95 and later
9002 @item @emph{Syntax}:
9003 @code{CALL RANDOM_SEED([SIZE, PUT, GET])}
9005 @item @emph{Arguments}:
9006 @multitable @columnfractions .15 .70
9007 @item @var{SIZE} @tab (Optional) Shall be a scalar and of type default
9008 @code{INTEGER}, with @code{INTENT(OUT)}. It specifies the minimum size
9009 of the arrays used with the @var{PUT} and @var{GET} arguments.
9010 @item @var{PUT} @tab (Optional) Shall be an array of type default
9011 @code{INTEGER} and rank one. It is @code{INTENT(IN)} and the size of
9012 the array must be larger than or equal to the number returned by the
9013 @var{SIZE} argument.
9014 @item @var{GET} @tab (Optional) Shall be an array of type default
9015 @code{INTEGER} and rank one. It is @code{INTENT(OUT)} and the size
9016 of the array must be larger than or equal to the number returned by
9017 the @var{SIZE} argument.
9020 @item @emph{Example}:
9022 SUBROUTINE init_random_seed()
9023 INTEGER :: i, n, clock
9024 INTEGER, DIMENSION(:), ALLOCATABLE :: seed
9026 CALL RANDOM_SEED(size = n)
9029 CALL SYSTEM_CLOCK(COUNT=clock)
9031 seed = clock + 37 * (/ (i - 1, i = 1, n) /)
9032 CALL RANDOM_SEED(PUT = seed)
9038 @item @emph{See also}:
9045 @section @code{RANGE} --- Decimal exponent range
9047 @cindex model representation, range
9050 @item @emph{Description}:
9051 @code{RANGE(X)} returns the decimal exponent range in the model of the
9054 @item @emph{Standard}:
9055 Fortran 95 and later
9060 @item @emph{Syntax}:
9061 @code{RESULT = RANGE(X)}
9063 @item @emph{Arguments}:
9064 @multitable @columnfractions .15 .70
9065 @item @var{X} @tab Shall be of type @code{INTEGER}, @code{REAL}
9069 @item @emph{Return value}:
9070 The return value is of type @code{INTEGER} and of the default integer
9073 @item @emph{Example}:
9074 See @code{PRECISION} for an example.
9080 @section @code{REAL} --- Convert to real type
9083 @cindex conversion, to real
9084 @cindex complex numbers, real part
9087 @item @emph{Description}:
9088 @code{REAL(A [, KIND])} converts its argument @var{A} to a real type. The
9089 @code{REALPART} function is provided for compatibility with @command{g77},
9090 and its use is strongly discouraged.
9092 @item @emph{Standard}:
9093 Fortran 77 and later
9098 @item @emph{Syntax}:
9099 @multitable @columnfractions .80
9100 @item @code{RESULT = REAL(A [, KIND])}
9101 @item @code{RESULT = REALPART(Z)}
9104 @item @emph{Arguments}:
9105 @multitable @columnfractions .15 .70
9106 @item @var{A} @tab Shall be @code{INTEGER}, @code{REAL}, or
9108 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
9109 expression indicating the kind parameter of the result.
9112 @item @emph{Return value}:
9113 These functions return a @code{REAL} variable or array under
9114 the following rules:
9118 @code{REAL(A)} is converted to a default real type if @var{A} is an
9119 integer or real variable.
9121 @code{REAL(A)} is converted to a real type with the kind type parameter
9122 of @var{A} if @var{A} is a complex variable.
9124 @code{REAL(A, KIND)} is converted to a real type with kind type
9125 parameter @var{KIND} if @var{A} is a complex, integer, or real
9129 @item @emph{Example}:
9132 complex :: x = (1.0, 2.0)
9133 print *, real(x), real(x,8), realpart(x)
9134 end program test_real
9137 @item @emph{See also}:
9138 @ref{DBLE}, @ref{DFLOAT}, @ref{FLOAT}
9145 @section @code{RENAME} --- Rename a file
9147 @cindex file system, rename file
9150 @item @emph{Description}:
9151 Renames a file from file @var{PATH1} to @var{PATH2}. A null
9152 character (@code{CHAR(0)}) can be used to mark the end of the names in
9153 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
9154 names are ignored. If the @var{STATUS} argument is supplied, it
9155 contains 0 on success or a nonzero error code upon return; see
9158 This intrinsic is provided in both subroutine and function forms;
9159 however, only one form can be used in any given program unit.
9161 @item @emph{Standard}:
9165 Subroutine, function
9167 @item @emph{Syntax}:
9168 @multitable @columnfractions .80
9169 @item @code{CALL RENAME(PATH1, PATH2 [, STATUS])}
9170 @item @code{STATUS = RENAME(PATH1, PATH2)}
9173 @item @emph{Arguments}:
9174 @multitable @columnfractions .15 .70
9175 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
9176 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
9177 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
9180 @item @emph{See also}:
9188 @section @code{REPEAT} --- Repeated string concatenation
9190 @cindex string, repeat
9191 @cindex string, concatenate
9194 @item @emph{Description}:
9195 Concatenates @var{NCOPIES} copies of a string.
9197 @item @emph{Standard}:
9198 Fortran 95 and later
9201 Transformational function
9203 @item @emph{Syntax}:
9204 @code{RESULT = REPEAT(STRING, NCOPIES)}
9206 @item @emph{Arguments}:
9207 @multitable @columnfractions .15 .70
9208 @item @var{STRING} @tab Shall be scalar and of type @code{CHARACTER}.
9209 @item @var{NCOPIES} @tab Shall be scalar and of type @code{INTEGER}.
9212 @item @emph{Return value}:
9213 A new scalar of type @code{CHARACTER} built up from @var{NCOPIES} copies
9216 @item @emph{Example}:
9219 write(*,*) repeat("x", 5) ! "xxxxx"
9227 @section @code{RESHAPE} --- Function to reshape an array
9229 @cindex array, change dimensions
9230 @cindex array, transmogrify
9233 @item @emph{Description}:
9234 Reshapes @var{SOURCE} to correspond to @var{SHAPE}. If necessary,
9235 the new array may be padded with elements from @var{PAD} or permuted
9236 as defined by @var{ORDER}.
9238 @item @emph{Standard}:
9239 Fortran 95 and later
9242 Transformational function
9244 @item @emph{Syntax}:
9245 @code{RESULT = RESHAPE(SOURCE, SHAPE[, PAD, ORDER])}
9247 @item @emph{Arguments}:
9248 @multitable @columnfractions .15 .70
9249 @item @var{SOURCE} @tab Shall be an array of any type.
9250 @item @var{SHAPE} @tab Shall be of type @code{INTEGER} and an
9251 array of rank one. Its values must be positive or zero.
9252 @item @var{PAD} @tab (Optional) shall be an array of the same
9253 type as @var{SOURCE}.
9254 @item @var{ORDER} @tab (Optional) shall be of type @code{INTEGER}
9255 and an array of the same shape as @var{SHAPE}. Its values shall
9256 be a permutation of the numbers from 1 to n, where n is the size of
9257 @var{SHAPE}. If @var{ORDER} is absent, the natural ordering shall
9261 @item @emph{Return value}:
9262 The result is an array of shape @var{SHAPE} with the same type as
9265 @item @emph{Example}:
9267 PROGRAM test_reshape
9268 INTEGER, DIMENSION(4) :: x
9269 WRITE(*,*) SHAPE(x) ! prints "4"
9270 WRITE(*,*) SHAPE(RESHAPE(x, (/2, 2/))) ! prints "2 2"
9274 @item @emph{See also}:
9281 @section @code{RRSPACING} --- Reciprocal of the relative spacing
9283 @cindex real number, relative spacing
9284 @cindex floating point, relative spacing
9288 @item @emph{Description}:
9289 @code{RRSPACING(X)} returns the reciprocal of the relative spacing of
9290 model numbers near @var{X}.
9292 @item @emph{Standard}:
9293 Fortran 95 and later
9298 @item @emph{Syntax}:
9299 @code{RESULT = RRSPACING(X)}
9301 @item @emph{Arguments}:
9302 @multitable @columnfractions .15 .70
9303 @item @var{X} @tab Shall be of type @code{REAL}.
9306 @item @emph{Return value}:
9307 The return value is of the same type and kind as @var{X}.
9308 The value returned is equal to
9309 @code{ABS(FRACTION(X)) * FLOAT(RADIX(X))**DIGITS(X)}.
9311 @item @emph{See also}:
9318 @section @code{RSHIFT} --- Right shift bits
9320 @cindex bits, shift right
9323 @item @emph{Description}:
9324 @code{RSHIFT} returns a value corresponding to @var{I} with all of the
9325 bits shifted right by @var{SHIFT} places. If the absolute value of
9326 @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the value is undefined.
9327 Bits shifted out from the left end are lost; zeros are shifted in from
9330 This function has been superseded by the @code{ISHFT} intrinsic, which
9331 is standard in Fortran 95 and later.
9333 @item @emph{Standard}:
9339 @item @emph{Syntax}:
9340 @code{RESULT = RSHIFT(I, SHIFT)}
9342 @item @emph{Arguments}:
9343 @multitable @columnfractions .15 .70
9344 @item @var{I} @tab The type shall be @code{INTEGER}.
9345 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
9348 @item @emph{Return value}:
9349 The return value is of type @code{INTEGER} and of the same kind as
9352 @item @emph{See also}:
9353 @ref{ISHFT}, @ref{ISHFTC}, @ref{LSHIFT}
9360 @section @code{SCALE} --- Scale a real value
9362 @cindex real number, scale
9363 @cindex floating point, scale
9366 @item @emph{Description}:
9367 @code{SCALE(X,I)} returns @code{X * RADIX(X)**I}.
9369 @item @emph{Standard}:
9370 Fortran 95 and later
9375 @item @emph{Syntax}:
9376 @code{RESULT = SCALE(X, I)}
9378 @item @emph{Arguments}:
9379 @multitable @columnfractions .15 .70
9380 @item @var{X} @tab The type of the argument shall be a @code{REAL}.
9381 @item @var{I} @tab The type of the argument shall be a @code{INTEGER}.
9384 @item @emph{Return value}:
9385 The return value is of the same type and kind as @var{X}.
9386 Its value is @code{X * RADIX(X)**I}.
9388 @item @emph{Example}:
9391 real :: x = 178.1387e-4
9393 print *, scale(x,i), x*radix(x)**i
9394 end program test_scale
9402 @section @code{SCAN} --- Scan a string for the presence of a set of characters
9404 @cindex string, find subset
9407 @item @emph{Description}:
9408 Scans a @var{STRING} for any of the characters in a @var{SET}
9411 If @var{BACK} is either absent or equals @code{FALSE}, this function
9412 returns the position of the leftmost character of @var{STRING} that is
9413 in @var{SET}. If @var{BACK} equals @code{TRUE}, the rightmost position
9414 is returned. If no character of @var{SET} is found in @var{STRING}, the
9417 @item @emph{Standard}:
9418 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
9423 @item @emph{Syntax}:
9424 @code{RESULT = SCAN(STRING, SET[, BACK [, KIND]])}
9426 @item @emph{Arguments}:
9427 @multitable @columnfractions .15 .70
9428 @item @var{STRING} @tab Shall be of type @code{CHARACTER}.
9429 @item @var{SET} @tab Shall be of type @code{CHARACTER}.
9430 @item @var{BACK} @tab (Optional) shall be of type @code{LOGICAL}.
9431 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
9432 expression indicating the kind parameter of the result.
9435 @item @emph{Return value}:
9436 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
9437 @var{KIND} is absent, the return value is of default integer kind.
9439 @item @emph{Example}:
9442 WRITE(*,*) SCAN("FORTRAN", "AO") ! 2, found 'O'
9443 WRITE(*,*) SCAN("FORTRAN", "AO", .TRUE.) ! 6, found 'A'
9444 WRITE(*,*) SCAN("FORTRAN", "C++") ! 0, found none
9448 @item @emph{See also}:
9449 @ref{INDEX intrinsic}, @ref{VERIFY}
9455 @section @code{SECNDS} --- Time function
9457 @cindex time, elapsed
9458 @cindex elapsed time
9461 @item @emph{Description}:
9462 @code{SECNDS(X)} gets the time in seconds from the real-time system clock.
9463 @var{X} is a reference time, also in seconds. If this is zero, the time in
9464 seconds from midnight is returned. This function is non-standard and its
9467 @item @emph{Standard}:
9473 @item @emph{Syntax}:
9474 @code{RESULT = SECNDS (X)}
9476 @item @emph{Arguments}:
9477 @multitable @columnfractions .15 .70
9478 @item @var{T} @tab Shall be of type @code{REAL(4)}.
9479 @item @var{X} @tab Shall be of type @code{REAL(4)}.
9482 @item @emph{Return value}:
9485 @item @emph{Example}:
9490 print *, secnds (0.0) ! seconds since midnight
9491 t1 = secnds (0.0) ! reference time
9492 do i = 1, 10000000 ! do something
9494 t2 = secnds (t1) ! elapsed time
9495 print *, "Something took ", t2, " seconds."
9496 end program test_secnds
9503 @section @code{SECOND} --- CPU time function
9505 @cindex time, elapsed
9506 @cindex elapsed time
9509 @item @emph{Description}:
9510 Returns a @code{REAL(4)} value representing the elapsed CPU time in
9511 seconds. This provides the same functionality as the standard
9512 @code{CPU_TIME} intrinsic, and is only included for backwards
9515 This intrinsic is provided in both subroutine and function forms;
9516 however, only one form can be used in any given program unit.
9518 @item @emph{Standard}:
9522 Subroutine, function
9524 @item @emph{Syntax}:
9525 @multitable @columnfractions .80
9526 @item @code{CALL SECOND(TIME)}
9527 @item @code{TIME = SECOND()}
9530 @item @emph{Arguments}:
9531 @multitable @columnfractions .15 .70
9532 @item @var{TIME} @tab Shall be of type @code{REAL(4)}.
9535 @item @emph{Return value}:
9536 In either syntax, @var{TIME} is set to the process's current runtime in
9539 @item @emph{See also}:
9546 @node SELECTED_CHAR_KIND
9547 @section @code{SELECTED_CHAR_KIND} --- Choose character kind
9548 @fnindex SELECTED_CHAR_KIND
9549 @cindex character kind
9550 @cindex kind, character
9553 @item @emph{Description}:
9555 @code{SELECTED_CHAR_KIND(NAME)} returns the kind value for the character
9556 set named @var{NAME}, if a character set with such a name is supported,
9557 or @math{-1} otherwise. Currently, supported character sets include
9558 ``ASCII'' and ``DEFAULT'', which are equivalent.
9560 @item @emph{Standard}:
9561 Fortran 2003 and later
9564 Transformational function
9566 @item @emph{Syntax}:
9567 @code{RESULT = SELECTED_CHAR_KIND(NAME)}
9569 @item @emph{Arguments}:
9570 @multitable @columnfractions .15 .70
9571 @item @var{NAME} @tab Shall be a scalar and of the default character type.
9574 @item @emph{Example}:
9577 integer,parameter :: ascii = selected_char_kind("ascii")
9578 character(kind=ascii, len=26) :: s
9580 s = ascii_"abcdefghijklmnopqrstuvwxyz"
9582 end program ascii_kind
9588 @node SELECTED_INT_KIND
9589 @section @code{SELECTED_INT_KIND} --- Choose integer kind
9590 @fnindex SELECTED_INT_KIND
9591 @cindex integer kind
9592 @cindex kind, integer
9595 @item @emph{Description}:
9596 @code{SELECTED_INT_KIND(R)} return the kind value of the smallest integer
9597 type that can represent all values ranging from @math{-10^R} (exclusive)
9598 to @math{10^R} (exclusive). If there is no integer kind that accommodates
9599 this range, @code{SELECTED_INT_KIND} returns @math{-1}.
9601 @item @emph{Standard}:
9602 Fortran 95 and later
9605 Transformational function
9607 @item @emph{Syntax}:
9608 @code{RESULT = SELECTED_INT_KIND(R)}
9610 @item @emph{Arguments}:
9611 @multitable @columnfractions .15 .70
9612 @item @var{R} @tab Shall be a scalar and of type @code{INTEGER}.
9615 @item @emph{Example}:
9617 program large_integers
9618 integer,parameter :: k5 = selected_int_kind(5)
9619 integer,parameter :: k15 = selected_int_kind(15)
9620 integer(kind=k5) :: i5
9621 integer(kind=k15) :: i15
9623 print *, huge(i5), huge(i15)
9625 ! The following inequalities are always true
9626 print *, huge(i5) >= 10_k5**5-1
9627 print *, huge(i15) >= 10_k15**15-1
9628 end program large_integers
9634 @node SELECTED_REAL_KIND
9635 @section @code{SELECTED_REAL_KIND} --- Choose real kind
9636 @fnindex SELECTED_REAL_KIND
9641 @item @emph{Description}:
9642 @code{SELECTED_REAL_KIND(P,R)} returns the kind value of a real data type
9643 with decimal precision of at least @code{P} digits and exponent
9644 range greater at least @code{R}.
9646 @item @emph{Standard}:
9647 Fortran 95 and later
9650 Transformational function
9652 @item @emph{Syntax}:
9653 @code{RESULT = SELECTED_REAL_KIND([P, R])}
9655 @item @emph{Arguments}:
9656 @multitable @columnfractions .15 .70
9657 @item @var{P} @tab (Optional) shall be a scalar and of type @code{INTEGER}.
9658 @item @var{R} @tab (Optional) shall be a scalar and of type @code{INTEGER}.
9660 At least one argument shall be present.
9662 @item @emph{Return value}:
9664 @code{SELECTED_REAL_KIND} returns the value of the kind type parameter of
9665 a real data type with decimal precision of at least @code{P} digits and a
9666 decimal exponent range of at least @code{R}. If more than one real data
9667 type meet the criteria, the kind of the data type with the smallest
9668 decimal precision is returned. If no real data type matches the criteria,
9671 @item -1 if the processor does not support a real data type with a
9672 precision greater than or equal to @code{P}
9673 @item -2 if the processor does not support a real type with an exponent
9674 range greater than or equal to @code{R}
9675 @item -3 if neither is supported.
9678 @item @emph{Example}:
9681 integer,parameter :: p6 = selected_real_kind(6)
9682 integer,parameter :: p10r100 = selected_real_kind(10,100)
9683 integer,parameter :: r400 = selected_real_kind(r=400)
9685 real(kind=p10r100) :: y
9686 real(kind=r400) :: z
9688 print *, precision(x), range(x)
9689 print *, precision(y), range(y)
9690 print *, precision(z), range(z)
9691 end program real_kinds
9698 @section @code{SET_EXPONENT} --- Set the exponent of the model
9699 @fnindex SET_EXPONENT
9700 @cindex real number, set exponent
9701 @cindex floating point, set exponent
9704 @item @emph{Description}:
9705 @code{SET_EXPONENT(X, I)} returns the real number whose fractional part
9706 is that that of @var{X} and whose exponent part is @var{I}.
9708 @item @emph{Standard}:
9709 Fortran 95 and later
9714 @item @emph{Syntax}:
9715 @code{RESULT = SET_EXPONENT(X, I)}
9717 @item @emph{Arguments}:
9718 @multitable @columnfractions .15 .70
9719 @item @var{X} @tab Shall be of type @code{REAL}.
9720 @item @var{I} @tab Shall be of type @code{INTEGER}.
9723 @item @emph{Return value}:
9724 The return value is of the same type and kind as @var{X}.
9725 The real number whose fractional part
9726 is that that of @var{X} and whose exponent part if @var{I} is returned;
9727 it is @code{FRACTION(X) * RADIX(X)**I}.
9729 @item @emph{Example}:
9732 REAL :: x = 178.1387e-4
9734 PRINT *, SET_EXPONENT(x, i), FRACTION(x) * RADIX(x)**i
9743 @section @code{SHAPE} --- Determine the shape of an array
9745 @cindex array, shape
9748 @item @emph{Description}:
9749 Determines the shape of an array.
9751 @item @emph{Standard}:
9752 Fortran 95 and later
9757 @item @emph{Syntax}:
9758 @code{RESULT = SHAPE(SOURCE)}
9760 @item @emph{Arguments}:
9761 @multitable @columnfractions .15 .70
9762 @item @var{SOURCE} @tab Shall be an array or scalar of any type.
9763 If @var{SOURCE} is a pointer it must be associated and allocatable
9764 arrays must be allocated.
9767 @item @emph{Return value}:
9768 An @code{INTEGER} array of rank one with as many elements as @var{SOURCE}
9769 has dimensions. The elements of the resulting array correspond to the extend
9770 of @var{SOURCE} along the respective dimensions. If @var{SOURCE} is a scalar,
9771 the result is the rank one array of size zero.
9773 @item @emph{Example}:
9776 INTEGER, DIMENSION(-1:1, -1:2) :: A
9777 WRITE(*,*) SHAPE(A) ! (/ 3, 4 /)
9778 WRITE(*,*) SIZE(SHAPE(42)) ! (/ /)
9782 @item @emph{See also}:
9783 @ref{RESHAPE}, @ref{SIZE}
9789 @section @code{SIGN} --- Sign copying function
9793 @cindex sign copying
9796 @item @emph{Description}:
9797 @code{SIGN(A,B)} returns the value of @var{A} with the sign of @var{B}.
9799 @item @emph{Standard}:
9800 Fortran 77 and later
9805 @item @emph{Syntax}:
9806 @code{RESULT = SIGN(A, B)}
9808 @item @emph{Arguments}:
9809 @multitable @columnfractions .15 .70
9810 @item @var{A} @tab Shall be of type @code{INTEGER} or @code{REAL}
9811 @item @var{B} @tab Shall be of the same type and kind as @var{A}
9814 @item @emph{Return value}:
9815 The kind of the return value is that of @var{A} and @var{B}.
9816 If @math{B\ge 0} then the result is @code{ABS(A)}, else
9817 it is @code{-ABS(A)}.
9819 @item @emph{Example}:
9822 print *, sign(-12,1)
9823 print *, sign(-12,0)
9824 print *, sign(-12,-1)
9826 print *, sign(-12.,1.)
9827 print *, sign(-12.,0.)
9828 print *, sign(-12.,-1.)
9829 end program test_sign
9832 @item @emph{Specific names}:
9833 @multitable @columnfractions .20 .20 .20 .25
9834 @item Name @tab Arguments @tab Return type @tab Standard
9835 @item @code{ISIGN(A,P)} @tab @code{INTEGER(4)} @tab @code{INTEGER(4)} @tab f95, gnu
9836 @item @code{DSIGN(A,P)} @tab @code{REAL(8)} @tab @code{REAL(8)} @tab f95, gnu
9843 @section @code{SIGNAL} --- Signal handling subroutine (or function)
9845 @cindex system, signal handling
9848 @item @emph{Description}:
9849 @code{SIGNAL(NUMBER, HANDLER [, STATUS])} causes external subroutine
9850 @var{HANDLER} to be executed with a single integer argument when signal
9851 @var{NUMBER} occurs. If @var{HANDLER} is an integer, it can be used to
9852 turn off handling of signal @var{NUMBER} or revert to its default
9853 action. See @code{signal(2)}.
9855 If @code{SIGNAL} is called as a subroutine and the @var{STATUS} argument
9856 is supplied, it is set to the value returned by @code{signal(2)}.
9858 @item @emph{Standard}:
9862 Subroutine, function
9864 @item @emph{Syntax}:
9865 @multitable @columnfractions .80
9866 @item @code{CALL SIGNAL(NUMBER, HANDLER [, STATUS])}
9867 @item @code{STATUS = SIGNAL(NUMBER, HANDLER)}
9870 @item @emph{Arguments}:
9871 @multitable @columnfractions .15 .70
9872 @item @var{NUMBER} @tab Shall be a scalar integer, with @code{INTENT(IN)}
9873 @item @var{HANDLER}@tab Signal handler (@code{INTEGER FUNCTION} or
9874 @code{SUBROUTINE}) or dummy/global @code{INTEGER} scalar.
9875 @code{INTEGER}. It is @code{INTENT(IN)}.
9876 @item @var{STATUS} @tab (Optional) @var{STATUS} shall be a scalar
9877 integer. It has @code{INTENT(OUT)}.
9879 @c TODO: What should the interface of the handler be? Does it take arguments?
9881 @item @emph{Return value}:
9882 The @code{SIGNAL} function returns the value returned by @code{signal(2)}.
9884 @item @emph{Example}:
9888 external handler_print
9890 call signal (12, handler_print)
9894 end program test_signal
9901 @section @code{SIN} --- Sine function
9907 @cindex trigonometric function, sine
9911 @item @emph{Description}:
9912 @code{SIN(X)} computes the sine of @var{X}.
9914 @item @emph{Standard}:
9915 Fortran 77 and later
9920 @item @emph{Syntax}:
9921 @code{RESULT = SIN(X)}
9923 @item @emph{Arguments}:
9924 @multitable @columnfractions .15 .70
9925 @item @var{X} @tab The type shall be @code{REAL} or
9929 @item @emph{Return value}:
9930 The return value has same type and kind as @var{X}.
9932 @item @emph{Example}:
9937 end program test_sin
9940 @item @emph{Specific names}:
9941 @multitable @columnfractions .20 .20 .20 .25
9942 @item Name @tab Argument @tab Return type @tab Standard
9943 @item @code{DSIN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab f95, gnu
9944 @item @code{CSIN(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab f95, gnu
9945 @item @code{ZSIN(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
9946 @item @code{CDSIN(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
9949 @item @emph{See also}:
9956 @section @code{SINH} --- Hyperbolic sine function
9959 @cindex hyperbolic sine
9960 @cindex hyperbolic function, sine
9961 @cindex sine, hyperbolic
9964 @item @emph{Description}:
9965 @code{SINH(X)} computes the hyperbolic sine of @var{X}.
9967 @item @emph{Standard}:
9968 Fortran 95 and later, for a complex argument Fortran 2008 or later
9973 @item @emph{Syntax}:
9974 @code{RESULT = SINH(X)}
9976 @item @emph{Arguments}:
9977 @multitable @columnfractions .15 .70
9978 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
9981 @item @emph{Return value}:
9982 The return value has same type and kind as @var{X}.
9984 @item @emph{Example}:
9987 real(8) :: x = - 1.0_8
9989 end program test_sinh
9992 @item @emph{Specific names}:
9993 @multitable @columnfractions .20 .20 .20 .25
9994 @item Name @tab Argument @tab Return type @tab Standard
9995 @item @code{DSINH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 95 and later
9998 @item @emph{See also}:
10005 @section @code{SIZE} --- Determine the size of an array
10007 @cindex array, size
10008 @cindex array, number of elements
10009 @cindex array, count elements
10012 @item @emph{Description}:
10013 Determine the extent of @var{ARRAY} along a specified dimension @var{DIM},
10014 or the total number of elements in @var{ARRAY} if @var{DIM} is absent.
10016 @item @emph{Standard}:
10017 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
10019 @item @emph{Class}:
10022 @item @emph{Syntax}:
10023 @code{RESULT = SIZE(ARRAY[, DIM [, KIND]])}
10025 @item @emph{Arguments}:
10026 @multitable @columnfractions .15 .70
10027 @item @var{ARRAY} @tab Shall be an array of any type. If @var{ARRAY} is
10028 a pointer it must be associated and allocatable arrays must be allocated.
10029 @item @var{DIM} @tab (Optional) shall be a scalar of type @code{INTEGER}
10030 and its value shall be in the range from 1 to n, where n equals the rank
10032 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
10033 expression indicating the kind parameter of the result.
10036 @item @emph{Return value}:
10037 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
10038 @var{KIND} is absent, the return value is of default integer kind.
10040 @item @emph{Example}:
10043 WRITE(*,*) SIZE((/ 1, 2 /)) ! 2
10047 @item @emph{See also}:
10048 @ref{SHAPE}, @ref{RESHAPE}
10053 @section @code{SIZEOF} --- Size in bytes of an expression
10055 @cindex expression size
10056 @cindex size of an expression
10059 @item @emph{Description}:
10060 @code{SIZEOF(X)} calculates the number of bytes of storage the
10061 expression @code{X} occupies.
10063 @item @emph{Standard}:
10066 @item @emph{Class}:
10069 @item @emph{Syntax}:
10070 @code{N = SIZEOF(X)}
10072 @item @emph{Arguments}:
10073 @multitable @columnfractions .15 .70
10074 @item @var{X} @tab The argument shall be of any type, rank or shape.
10077 @item @emph{Return value}:
10078 The return value is of type integer and of the system-dependent kind
10079 @var{C_SIZE_T} (from the @var{ISO_C_BINDING} module). Its value is the
10080 number of bytes occupied by the argument. If the argument has the
10081 @code{POINTER} attribute, the number of bytes of the storage area pointed
10082 to is returned. If the argument is of a derived type with @code{POINTER}
10083 or @code{ALLOCATABLE} components, the return value doesn't account for
10084 the sizes of the data pointed to by these components.
10086 @item @emph{Example}:
10090 print *, (sizeof(s)/sizeof(r) == 5)
10093 The example will print @code{.TRUE.} unless you are using a platform
10094 where default @code{REAL} variables are unusually padded.
10096 @item @emph{See also}:
10102 @section @code{SLEEP} --- Sleep for the specified number of seconds
10104 @cindex delayed execution
10107 @item @emph{Description}:
10108 Calling this subroutine causes the process to pause for @var{SECONDS} seconds.
10110 @item @emph{Standard}:
10113 @item @emph{Class}:
10116 @item @emph{Syntax}:
10117 @code{CALL SLEEP(SECONDS)}
10119 @item @emph{Arguments}:
10120 @multitable @columnfractions .15 .70
10121 @item @var{SECONDS} @tab The type shall be of default @code{INTEGER}.
10124 @item @emph{Example}:
10135 @section @code{SNGL} --- Convert double precision real to default real
10137 @cindex conversion, to real
10140 @item @emph{Description}:
10141 @code{SNGL(A)} converts the double precision real @var{A}
10142 to a default real value. This is an archaic form of @code{REAL}
10143 that is specific to one type for @var{A}.
10145 @item @emph{Standard}:
10146 Fortran 77 and later
10148 @item @emph{Class}:
10151 @item @emph{Syntax}:
10152 @code{RESULT = SNGL(A)}
10154 @item @emph{Arguments}:
10155 @multitable @columnfractions .15 .70
10156 @item @var{A} @tab The type shall be a double precision @code{REAL}.
10159 @item @emph{Return value}:
10160 The return value is of type default @code{REAL}.
10162 @item @emph{See also}:
10169 @section @code{SPACING} --- Smallest distance between two numbers of a given type
10171 @cindex real number, relative spacing
10172 @cindex floating point, relative spacing
10175 @item @emph{Description}:
10176 Determines the distance between the argument @var{X} and the nearest
10177 adjacent number of the same type.
10179 @item @emph{Standard}:
10180 Fortran 95 and later
10182 @item @emph{Class}:
10185 @item @emph{Syntax}:
10186 @code{RESULT = SPACING(X)}
10188 @item @emph{Arguments}:
10189 @multitable @columnfractions .15 .70
10190 @item @var{X} @tab Shall be of type @code{REAL}.
10193 @item @emph{Return value}:
10194 The result is of the same type as the input argument @var{X}.
10196 @item @emph{Example}:
10198 PROGRAM test_spacing
10199 INTEGER, PARAMETER :: SGL = SELECTED_REAL_KIND(p=6, r=37)
10200 INTEGER, PARAMETER :: DBL = SELECTED_REAL_KIND(p=13, r=200)
10202 WRITE(*,*) spacing(1.0_SGL) ! "1.1920929E-07" on i686
10203 WRITE(*,*) spacing(1.0_DBL) ! "2.220446049250313E-016" on i686
10207 @item @emph{See also}:
10214 @section @code{SPREAD} --- Add a dimension to an array
10216 @cindex array, increase dimension
10217 @cindex array, duplicate elements
10218 @cindex array, duplicate dimensions
10221 @item @emph{Description}:
10222 Replicates a @var{SOURCE} array @var{NCOPIES} times along a specified
10223 dimension @var{DIM}.
10225 @item @emph{Standard}:
10226 Fortran 95 and later
10228 @item @emph{Class}:
10229 Transformational function
10231 @item @emph{Syntax}:
10232 @code{RESULT = SPREAD(SOURCE, DIM, NCOPIES)}
10234 @item @emph{Arguments}:
10235 @multitable @columnfractions .15 .70
10236 @item @var{SOURCE} @tab Shall be a scalar or an array of any type and
10237 a rank less than seven.
10238 @item @var{DIM} @tab Shall be a scalar of type @code{INTEGER} with a
10239 value in the range from 1 to n+1, where n equals the rank of @var{SOURCE}.
10240 @item @var{NCOPIES} @tab Shall be a scalar of type @code{INTEGER}.
10243 @item @emph{Return value}:
10244 The result is an array of the same type as @var{SOURCE} and has rank n+1
10245 where n equals the rank of @var{SOURCE}.
10247 @item @emph{Example}:
10249 PROGRAM test_spread
10250 INTEGER :: a = 1, b(2) = (/ 1, 2 /)
10251 WRITE(*,*) SPREAD(A, 1, 2) ! "1 1"
10252 WRITE(*,*) SPREAD(B, 1, 2) ! "1 1 2 2"
10256 @item @emph{See also}:
10263 @section @code{SQRT} --- Square-root function
10270 @cindex square-root
10273 @item @emph{Description}:
10274 @code{SQRT(X)} computes the square root of @var{X}.
10276 @item @emph{Standard}:
10277 Fortran 77 and later
10279 @item @emph{Class}:
10282 @item @emph{Syntax}:
10283 @code{RESULT = SQRT(X)}
10285 @item @emph{Arguments}:
10286 @multitable @columnfractions .15 .70
10287 @item @var{X} @tab The type shall be @code{REAL} or
10291 @item @emph{Return value}:
10292 The return value is of type @code{REAL} or @code{COMPLEX}.
10293 The kind type parameter is the same as @var{X}.
10295 @item @emph{Example}:
10298 real(8) :: x = 2.0_8
10299 complex :: z = (1.0, 2.0)
10302 end program test_sqrt
10305 @item @emph{Specific names}:
10306 @multitable @columnfractions .20 .20 .20 .25
10307 @item Name @tab Argument @tab Return type @tab Standard
10308 @item @code{DSQRT(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 95 and later
10309 @item @code{CSQRT(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab Fortran 95 and later
10310 @item @code{ZSQRT(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
10311 @item @code{CDSQRT(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
10318 @section @code{SRAND} --- Reinitialize the random number generator
10320 @cindex random number generation, seeding
10321 @cindex seeding a random number generator
10324 @item @emph{Description}:
10325 @code{SRAND} reinitializes the pseudo-random number generator
10326 called by @code{RAND} and @code{IRAND}. The new seed used by the
10327 generator is specified by the required argument @var{SEED}.
10329 @item @emph{Standard}:
10332 @item @emph{Class}:
10335 @item @emph{Syntax}:
10336 @code{CALL SRAND(SEED)}
10338 @item @emph{Arguments}:
10339 @multitable @columnfractions .15 .70
10340 @item @var{SEED} @tab Shall be a scalar @code{INTEGER(kind=4)}.
10343 @item @emph{Return value}:
10344 Does not return anything.
10346 @item @emph{Example}:
10347 See @code{RAND} and @code{IRAND} for examples.
10349 @item @emph{Notes}:
10350 The Fortran 2003 standard specifies the intrinsic @code{RANDOM_SEED} to
10351 initialize the pseudo-random numbers generator and @code{RANDOM_NUMBER}
10352 to generate pseudo-random numbers. Please note that in
10353 GNU Fortran, these two sets of intrinsics (@code{RAND},
10354 @code{IRAND} and @code{SRAND} on the one hand, @code{RANDOM_NUMBER} and
10355 @code{RANDOM_SEED} on the other hand) access two independent
10356 pseudo-random number generators.
10358 @item @emph{See also}:
10359 @ref{RAND}, @ref{RANDOM_SEED}, @ref{RANDOM_NUMBER}
10366 @section @code{STAT} --- Get file status
10368 @cindex file system, file status
10371 @item @emph{Description}:
10372 This function returns information about a file. No permissions are required on
10373 the file itself, but execute (search) permission is required on all of the
10374 directories in path that lead to the file.
10376 The elements that are obtained and stored in the array @code{VALUES}:
10377 @multitable @columnfractions .15 .70
10378 @item @code{VALUES(1)} @tab Device ID
10379 @item @code{VALUES(2)} @tab Inode number
10380 @item @code{VALUES(3)} @tab File mode
10381 @item @code{VALUES(4)} @tab Number of links
10382 @item @code{VALUES(5)} @tab Owner's uid
10383 @item @code{VALUES(6)} @tab Owner's gid
10384 @item @code{VALUES(7)} @tab ID of device containing directory entry for file (0 if not available)
10385 @item @code{VALUES(8)} @tab File size (bytes)
10386 @item @code{VALUES(9)} @tab Last access time
10387 @item @code{VALUES(10)} @tab Last modification time
10388 @item @code{VALUES(11)} @tab Last file status change time
10389 @item @code{VALUES(12)} @tab Preferred I/O block size (-1 if not available)
10390 @item @code{VALUES(13)} @tab Number of blocks allocated (-1 if not available)
10393 Not all these elements are relevant on all systems.
10394 If an element is not relevant, it is returned as 0.
10396 This intrinsic is provided in both subroutine and function forms; however,
10397 only one form can be used in any given program unit.
10399 @item @emph{Standard}:
10402 @item @emph{Class}:
10403 Subroutine, function
10405 @item @emph{Syntax}:
10406 @code{CALL STAT(NAME, VALUES [, STATUS])}
10408 @item @emph{Arguments}:
10409 @multitable @columnfractions .15 .70
10410 @item @var{NAME} @tab The type shall be @code{CHARACTER}, of the
10411 default kind and a valid path within the file system.
10412 @item @var{VALUES} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
10413 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}. Returns 0
10414 on success and a system specific error code otherwise.
10417 @item @emph{Example}:
10420 INTEGER, DIMENSION(13) :: buff
10423 CALL STAT("/etc/passwd", buff, status)
10425 IF (status == 0) THEN
10426 WRITE (*, FMT="('Device ID:', T30, I19)") buff(1)
10427 WRITE (*, FMT="('Inode number:', T30, I19)") buff(2)
10428 WRITE (*, FMT="('File mode (octal):', T30, O19)") buff(3)
10429 WRITE (*, FMT="('Number of links:', T30, I19)") buff(4)
10430 WRITE (*, FMT="('Owner''s uid:', T30, I19)") buff(5)
10431 WRITE (*, FMT="('Owner''s gid:', T30, I19)") buff(6)
10432 WRITE (*, FMT="('Device where located:', T30, I19)") buff(7)
10433 WRITE (*, FMT="('File size:', T30, I19)") buff(8)
10434 WRITE (*, FMT="('Last access time:', T30, A19)") CTIME(buff(9))
10435 WRITE (*, FMT="('Last modification time', T30, A19)") CTIME(buff(10))
10436 WRITE (*, FMT="('Last status change time:', T30, A19)") CTIME(buff(11))
10437 WRITE (*, FMT="('Preferred block size:', T30, I19)") buff(12)
10438 WRITE (*, FMT="('No. of blocks allocated:', T30, I19)") buff(13)
10443 @item @emph{See also}:
10444 To stat an open file: @ref{FSTAT}, to stat a link: @ref{LSTAT}
10450 @section @code{SUM} --- Sum of array elements
10453 @cindex array, add elements
10454 @cindex array, conditionally add elements
10455 @cindex sum array elements
10458 @item @emph{Description}:
10459 Adds the elements of @var{ARRAY} along dimension @var{DIM} if
10460 the corresponding element in @var{MASK} is @code{TRUE}.
10462 @item @emph{Standard}:
10463 Fortran 95 and later
10465 @item @emph{Class}:
10466 Transformational function
10468 @item @emph{Syntax}:
10469 @multitable @columnfractions .80
10470 @item @code{RESULT = SUM(ARRAY[, MASK])}
10471 @item @code{RESULT = SUM(ARRAY, DIM[, MASK])}
10474 @item @emph{Arguments}:
10475 @multitable @columnfractions .15 .70
10476 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER},
10477 @code{REAL} or @code{COMPLEX}.
10478 @item @var{DIM} @tab (Optional) shall be a scalar of type
10479 @code{INTEGER} with a value in the range from 1 to n, where n
10480 equals the rank of @var{ARRAY}.
10481 @item @var{MASK} @tab (Optional) shall be of type @code{LOGICAL}
10482 and either be a scalar or an array of the same shape as @var{ARRAY}.
10485 @item @emph{Return value}:
10486 The result is of the same type as @var{ARRAY}.
10488 If @var{DIM} is absent, a scalar with the sum of all elements in @var{ARRAY}
10489 is returned. Otherwise, an array of rank n-1, where n equals the rank of
10490 @var{ARRAY},and a shape similar to that of @var{ARRAY} with dimension @var{DIM}
10491 dropped is returned.
10493 @item @emph{Example}:
10496 INTEGER :: x(5) = (/ 1, 2, 3, 4 ,5 /)
10497 print *, SUM(x) ! all elements, sum = 15
10498 print *, SUM(x, MASK=MOD(x, 2)==1) ! odd elements, sum = 9
10502 @item @emph{See also}:
10509 @section @code{SYMLNK} --- Create a symbolic link
10511 @cindex file system, create link
10512 @cindex file system, soft link
10515 @item @emph{Description}:
10516 Makes a symbolic link from file @var{PATH1} to @var{PATH2}. A null
10517 character (@code{CHAR(0)}) can be used to mark the end of the names in
10518 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
10519 names are ignored. If the @var{STATUS} argument is supplied, it
10520 contains 0 on success or a nonzero error code upon return; see
10521 @code{symlink(2)}. If the system does not supply @code{symlink(2)},
10522 @code{ENOSYS} is returned.
10524 This intrinsic is provided in both subroutine and function forms;
10525 however, only one form can be used in any given program unit.
10527 @item @emph{Standard}:
10530 @item @emph{Class}:
10531 Subroutine, function
10533 @item @emph{Syntax}:
10534 @multitable @columnfractions .80
10535 @item @code{CALL SYMLNK(PATH1, PATH2 [, STATUS])}
10536 @item @code{STATUS = SYMLNK(PATH1, PATH2)}
10539 @item @emph{Arguments}:
10540 @multitable @columnfractions .15 .70
10541 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
10542 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
10543 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
10546 @item @emph{See also}:
10547 @ref{LINK}, @ref{UNLINK}
10554 @section @code{SYSTEM} --- Execute a shell command
10556 @cindex system, system call
10559 @item @emph{Description}:
10560 Passes the command @var{COMMAND} to a shell (see @code{system(3)}). If
10561 argument @var{STATUS} is present, it contains the value returned by
10562 @code{system(3)}, which is presumably 0 if the shell command succeeded.
10563 Note that which shell is used to invoke the command is system-dependent
10564 and environment-dependent.
10566 This intrinsic is provided in both subroutine and function forms;
10567 however, only one form can be used in any given program unit.
10569 @item @emph{Standard}:
10572 @item @emph{Class}:
10573 Subroutine, function
10575 @item @emph{Syntax}:
10576 @multitable @columnfractions .80
10577 @item @code{CALL SYSTEM(COMMAND [, STATUS])}
10578 @item @code{STATUS = SYSTEM(COMMAND)}
10581 @item @emph{Arguments}:
10582 @multitable @columnfractions .15 .70
10583 @item @var{COMMAND} @tab Shall be of default @code{CHARACTER} type.
10584 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
10587 @item @emph{See also}:
10593 @section @code{SYSTEM_CLOCK} --- Time function
10594 @fnindex SYSTEM_CLOCK
10595 @cindex time, clock ticks
10596 @cindex clock ticks
10599 @item @emph{Description}:
10600 Determines the @var{COUNT} of milliseconds of wall clock time since
10601 the Epoch (00:00:00 UTC, January 1, 1970) modulo @var{COUNT_MAX},
10602 @var{COUNT_RATE} determines the number of clock ticks per second.
10603 @var{COUNT_RATE} and @var{COUNT_MAX} are constant and specific to
10604 @command{gfortran}.
10606 If there is no clock, @var{COUNT} is set to @code{-HUGE(COUNT)}, and
10607 @var{COUNT_RATE} and @var{COUNT_MAX} are set to zero
10609 @item @emph{Standard}:
10610 Fortran 95 and later
10612 @item @emph{Class}:
10615 @item @emph{Syntax}:
10616 @code{CALL SYSTEM_CLOCK([COUNT, COUNT_RATE, COUNT_MAX])}
10618 @item @emph{Arguments}:
10619 @item @emph{Arguments}:
10620 @multitable @columnfractions .15 .70
10621 @item @var{COUNT} @tab (Optional) shall be a scalar of type default
10622 @code{INTEGER} with @code{INTENT(OUT)}.
10623 @item @var{COUNT_RATE} @tab (Optional) shall be a scalar of type default
10624 @code{INTEGER} with @code{INTENT(OUT)}.
10625 @item @var{COUNT_MAX} @tab (Optional) shall be a scalar of type default
10626 @code{INTEGER} with @code{INTENT(OUT)}.
10629 @item @emph{Example}:
10631 PROGRAM test_system_clock
10632 INTEGER :: count, count_rate, count_max
10633 CALL SYSTEM_CLOCK(count, count_rate, count_max)
10634 WRITE(*,*) count, count_rate, count_max
10638 @item @emph{See also}:
10639 @ref{DATE_AND_TIME}, @ref{CPU_TIME}
10645 @section @code{TAN} --- Tangent function
10648 @cindex trigonometric function, tangent
10652 @item @emph{Description}:
10653 @code{TAN(X)} computes the tangent of @var{X}.
10655 @item @emph{Standard}:
10656 Fortran 77 and later, for a complex argument Fortran 2008 or later
10658 @item @emph{Class}:
10661 @item @emph{Syntax}:
10662 @code{RESULT = TAN(X)}
10664 @item @emph{Arguments}:
10665 @multitable @columnfractions .15 .70
10666 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
10669 @item @emph{Return value}:
10670 The return value has same type and kind as @var{X}.
10672 @item @emph{Example}:
10675 real(8) :: x = 0.165_8
10677 end program test_tan
10680 @item @emph{Specific names}:
10681 @multitable @columnfractions .20 .20 .20 .25
10682 @item Name @tab Argument @tab Return type @tab Standard
10683 @item @code{DTAN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 95 and later
10686 @item @emph{See also}:
10693 @section @code{TANH} --- Hyperbolic tangent function
10696 @cindex hyperbolic tangent
10697 @cindex hyperbolic function, tangent
10698 @cindex tangent, hyperbolic
10701 @item @emph{Description}:
10702 @code{TANH(X)} computes the hyperbolic tangent of @var{X}.
10704 @item @emph{Standard}:
10705 Fortran 77 and later, for a complex argument Fortran 2008 or later
10707 @item @emph{Class}:
10710 @item @emph{Syntax}:
10713 @item @emph{Arguments}:
10714 @multitable @columnfractions .15 .70
10715 @item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
10718 @item @emph{Return value}:
10719 The return value has same type and kind as @var{X}. If @var{X} is
10720 complex, the imaginary part of the result is in radians. If @var{X}
10721 is @code{REAL}, the return value lies in the range
10722 @math{ - 1 \leq tanh(x) \leq 1 }.
10724 @item @emph{Example}:
10727 real(8) :: x = 2.1_8
10729 end program test_tanh
10732 @item @emph{Specific names}:
10733 @multitable @columnfractions .20 .20 .20 .25
10734 @item Name @tab Argument @tab Return type @tab Standard
10735 @item @code{DTANH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab Fortran 95 and later
10738 @item @emph{See also}:
10745 @section @code{THIS_IMAGE} --- Function that returns the cosubscript index of this image
10746 @fnindex THIS_IMAGE
10747 @cindex coarray, THIS_IMAGE
10748 @cindex images, index of this image
10751 @item @emph{Description}:
10752 Returns the cosubscript for this image.
10754 @item @emph{Standard}:
10755 Fortran 2008 and later
10757 @item @emph{Class}:
10758 Transformational function
10760 @item @emph{Syntax}:
10761 @multitable @columnfractions .80
10762 @item @code{RESULT = THIS_IMAGE()}
10763 @item @code{RESULT = THIS_IMAGE(COARRAY [, DIM])}
10766 @item @emph{Arguments}:
10767 @multitable @columnfractions .15 .70
10768 @item @var{COARRAY} @tab Coarray of any type (optional; if @var{DIM}
10769 present, required).
10770 @item @var{DIM} @tab default integer scalar (optional). If present,
10771 @var{DIM} shall be between one and the corank of @var{COARRAY}.
10775 @item @emph{Return value}:
10776 Default integer. If @var{COARRAY} is not present, it is scalar and its value
10777 is the index of the invoking image. Otherwise, if @var{DIM} is not present,
10778 a rank-1 array with corank elements is returned, containing the cosubscripts
10779 for @var{COARRAY} specifying the invoking image. If @var{DIM} is present,
10780 a scalar is returned, with the value of the @var{DIM} element of
10781 @code{THIS_IMAGE(COARRAY)}.
10783 @item @emph{Example}:
10785 INTEGER :: value[*]
10787 value = THIS_IMAGE()
10789 IF (THIS_IMAGE() == 1) THEN
10790 DO i = 1, NUM_IMAGES()
10791 WRITE(*,'(2(a,i0))') 'value[', i, '] is ', value[i]
10796 @item @emph{See also}:
10797 @ref{NUM_IMAGES}, @ref{IMAGE_INDEX}
10803 @section @code{TIME} --- Time function
10805 @cindex time, current
10806 @cindex current time
10809 @item @emph{Description}:
10810 Returns the current time encoded as an integer (in the manner of the
10811 UNIX function @code{time(3)}). This value is suitable for passing to
10812 @code{CTIME()}, @code{GMTIME()}, and @code{LTIME()}.
10814 This intrinsic is not fully portable, such as to systems with 32-bit
10815 @code{INTEGER} types but supporting times wider than 32 bits. Therefore,
10816 the values returned by this intrinsic might be, or become, negative, or
10817 numerically less than previous values, during a single run of the
10820 See @ref{TIME8}, for information on a similar intrinsic that might be
10821 portable to more GNU Fortran implementations, though to fewer Fortran
10824 @item @emph{Standard}:
10827 @item @emph{Class}:
10830 @item @emph{Syntax}:
10831 @code{RESULT = TIME()}
10833 @item @emph{Return value}:
10834 The return value is a scalar of type @code{INTEGER(4)}.
10836 @item @emph{See also}:
10837 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK}, @ref{TIME8}
10844 @section @code{TIME8} --- Time function (64-bit)
10846 @cindex time, current
10847 @cindex current time
10850 @item @emph{Description}:
10851 Returns the current time encoded as an integer (in the manner of the
10852 UNIX function @code{time(3)}). This value is suitable for passing to
10853 @code{CTIME()}, @code{GMTIME()}, and @code{LTIME()}.
10855 @emph{Warning:} this intrinsic does not increase the range of the timing
10856 values over that returned by @code{time(3)}. On a system with a 32-bit
10857 @code{time(3)}, @code{TIME8()} will return a 32-bit value, even though
10858 it is converted to a 64-bit @code{INTEGER(8)} value. That means
10859 overflows of the 32-bit value can still occur. Therefore, the values
10860 returned by this intrinsic might be or become negative or numerically
10861 less than previous values during a single run of the compiled program.
10863 @item @emph{Standard}:
10866 @item @emph{Class}:
10869 @item @emph{Syntax}:
10870 @code{RESULT = TIME8()}
10872 @item @emph{Return value}:
10873 The return value is a scalar of type @code{INTEGER(8)}.
10875 @item @emph{See also}:
10876 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK8}, @ref{TIME}
10883 @section @code{TINY} --- Smallest positive number of a real kind
10885 @cindex limits, smallest number
10886 @cindex model representation, smallest number
10889 @item @emph{Description}:
10890 @code{TINY(X)} returns the smallest positive (non zero) number
10891 in the model of the type of @code{X}.
10893 @item @emph{Standard}:
10894 Fortran 95 and later
10896 @item @emph{Class}:
10899 @item @emph{Syntax}:
10900 @code{RESULT = TINY(X)}
10902 @item @emph{Arguments}:
10903 @multitable @columnfractions .15 .70
10904 @item @var{X} @tab Shall be of type @code{REAL}.
10907 @item @emph{Return value}:
10908 The return value is of the same type and kind as @var{X}
10910 @item @emph{Example}:
10911 See @code{HUGE} for an example.
10917 @section @code{TRAILZ} --- Number of trailing zero bits of an integer
10922 @item @emph{Description}:
10923 @code{TRAILZ} returns the number of trailing zero bits of an integer.
10925 @item @emph{Standard}:
10926 Fortran 2008 and later
10928 @item @emph{Class}:
10931 @item @emph{Syntax}:
10932 @code{RESULT = TRAILZ(I)}
10934 @item @emph{Arguments}:
10935 @multitable @columnfractions .15 .70
10936 @item @var{I} @tab Shall be of type @code{INTEGER}.
10939 @item @emph{Return value}:
10940 The type of the return value is the default @code{INTEGER}.
10941 If all the bits of @code{I} are zero, the result value is @code{BIT_SIZE(I)}.
10943 @item @emph{Example}:
10945 PROGRAM test_trailz
10946 WRITE (*,*) TRAILZ(8) ! prints 3
10950 @item @emph{See also}:
10951 @ref{BIT_SIZE}, @ref{LEADZ}
10957 @section @code{TRANSFER} --- Transfer bit patterns
10963 @item @emph{Description}:
10964 Interprets the bitwise representation of @var{SOURCE} in memory as if it
10965 is the representation of a variable or array of the same type and type
10966 parameters as @var{MOLD}.
10968 This is approximately equivalent to the C concept of @emph{casting} one
10971 @item @emph{Standard}:
10972 Fortran 95 and later
10974 @item @emph{Class}:
10975 Transformational function
10977 @item @emph{Syntax}:
10978 @code{RESULT = TRANSFER(SOURCE, MOLD[, SIZE])}
10980 @item @emph{Arguments}:
10981 @multitable @columnfractions .15 .70
10982 @item @var{SOURCE} @tab Shall be a scalar or an array of any type.
10983 @item @var{MOLD} @tab Shall be a scalar or an array of any type.
10984 @item @var{SIZE} @tab (Optional) shall be a scalar of type
10988 @item @emph{Return value}:
10989 The result has the same type as @var{MOLD}, with the bit level
10990 representation of @var{SOURCE}. If @var{SIZE} is present, the result is
10991 a one-dimensional array of length @var{SIZE}. If @var{SIZE} is absent
10992 but @var{MOLD} is an array (of any size or shape), the result is a one-
10993 dimensional array of the minimum length needed to contain the entirety
10994 of the bitwise representation of @var{SOURCE}. If @var{SIZE} is absent
10995 and @var{MOLD} is a scalar, the result is a scalar.
10997 If the bitwise representation of the result is longer than that of
10998 @var{SOURCE}, then the leading bits of the result correspond to those of
10999 @var{SOURCE} and any trailing bits are filled arbitrarily.
11001 When the resulting bit representation does not correspond to a valid
11002 representation of a variable of the same type as @var{MOLD}, the results
11003 are undefined, and subsequent operations on the result cannot be
11004 guaranteed to produce sensible behavior. For example, it is possible to
11005 create @code{LOGICAL} variables for which @code{@var{VAR}} and
11006 @code{.NOT.@var{VAR}} both appear to be true.
11008 @item @emph{Example}:
11010 PROGRAM test_transfer
11011 integer :: x = 2143289344
11012 print *, transfer(x, 1.0) ! prints "NaN" on i686
11020 @section @code{TRANSPOSE} --- Transpose an array of rank two
11022 @cindex array, transpose
11023 @cindex matrix, transpose
11027 @item @emph{Description}:
11028 Transpose an array of rank two. Element (i, j) of the result has the value
11029 @code{MATRIX(j, i)}, for all i, j.
11031 @item @emph{Standard}:
11032 Fortran 95 and later
11034 @item @emph{Class}:
11035 Transformational function
11037 @item @emph{Syntax}:
11038 @code{RESULT = TRANSPOSE(MATRIX)}
11040 @item @emph{Arguments}:
11041 @multitable @columnfractions .15 .70
11042 @item @var{MATRIX} @tab Shall be an array of any type and have a rank of two.
11045 @item @emph{Return value}:
11046 The result has the same type as @var{MATRIX}, and has shape
11047 @code{(/ m, n /)} if @var{MATRIX} has shape @code{(/ n, m /)}.
11053 @section @code{TRIM} --- Remove trailing blank characters of a string
11055 @cindex string, remove trailing whitespace
11058 @item @emph{Description}:
11059 Removes trailing blank characters of a string.
11061 @item @emph{Standard}:
11062 Fortran 95 and later
11064 @item @emph{Class}:
11065 Transformational function
11067 @item @emph{Syntax}:
11068 @code{RESULT = TRIM(STRING)}
11070 @item @emph{Arguments}:
11071 @multitable @columnfractions .15 .70
11072 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER}.
11075 @item @emph{Return value}:
11076 A scalar of type @code{CHARACTER} which length is that of @var{STRING}
11077 less the number of trailing blanks.
11079 @item @emph{Example}:
11082 CHARACTER(len=10), PARAMETER :: s = "GFORTRAN "
11083 WRITE(*,*) LEN(s), LEN(TRIM(s)) ! "10 8", with/without trailing blanks
11087 @item @emph{See also}:
11088 @ref{ADJUSTL}, @ref{ADJUSTR}
11094 @section @code{TTYNAM} --- Get the name of a terminal device.
11096 @cindex system, terminal
11099 @item @emph{Description}:
11100 Get the name of a terminal device. For more information,
11101 see @code{ttyname(3)}.
11103 This intrinsic is provided in both subroutine and function forms;
11104 however, only one form can be used in any given program unit.
11106 @item @emph{Standard}:
11109 @item @emph{Class}:
11110 Subroutine, function
11112 @item @emph{Syntax}:
11113 @multitable @columnfractions .80
11114 @item @code{CALL TTYNAM(UNIT, NAME)}
11115 @item @code{NAME = TTYNAM(UNIT)}
11118 @item @emph{Arguments}:
11119 @multitable @columnfractions .15 .70
11120 @item @var{UNIT} @tab Shall be a scalar @code{INTEGER}.
11121 @item @var{NAME} @tab Shall be of type @code{CHARACTER}.
11124 @item @emph{Example}:
11126 PROGRAM test_ttynam
11129 IF (isatty(unit=unit)) write(*,*) ttynam(unit)
11134 @item @emph{See also}:
11141 @section @code{UBOUND} --- Upper dimension bounds of an array
11143 @cindex array, upper bound
11146 @item @emph{Description}:
11147 Returns the upper bounds of an array, or a single upper bound
11148 along the @var{DIM} dimension.
11149 @item @emph{Standard}:
11150 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
11152 @item @emph{Class}:
11155 @item @emph{Syntax}:
11156 @code{RESULT = UBOUND(ARRAY [, DIM [, KIND]])}
11158 @item @emph{Arguments}:
11159 @multitable @columnfractions .15 .70
11160 @item @var{ARRAY} @tab Shall be an array, of any type.
11161 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER}.
11162 @item @var{KIND}@tab (Optional) An @code{INTEGER} initialization
11163 expression indicating the kind parameter of the result.
11166 @item @emph{Return value}:
11167 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
11168 @var{KIND} is absent, the return value is of default integer kind.
11169 If @var{DIM} is absent, the result is an array of the upper bounds of
11170 @var{ARRAY}. If @var{DIM} is present, the result is a scalar
11171 corresponding to the upper bound of the array along that dimension. If
11172 @var{ARRAY} is an expression rather than a whole array or array
11173 structure component, or if it has a zero extent along the relevant
11174 dimension, the upper bound is taken to be the number of elements along
11175 the relevant dimension.
11177 @item @emph{See also}:
11178 @ref{LBOUND}, @ref{LCOBOUND}
11184 @section @code{UCOBOUND} --- Upper codimension bounds of an array
11186 @cindex coarray, upper bound
11189 @item @emph{Description}:
11190 Returns the upper cobounds of a coarray, or a single upper cobound
11191 along the @var{DIM} codimension.
11192 @item @emph{Standard}:
11193 Fortran 2008 and later
11195 @item @emph{Class}:
11198 @item @emph{Syntax}:
11199 @code{RESULT = UCOBOUND(COARRAY [, DIM [, KIND]])}
11201 @item @emph{Arguments}:
11202 @multitable @columnfractions .15 .70
11203 @item @var{ARRAY} @tab Shall be an coarray, of any type.
11204 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER}.
11205 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
11206 expression indicating the kind parameter of the result.
11209 @item @emph{Return value}:
11210 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
11211 @var{KIND} is absent, the return value is of default integer kind.
11212 If @var{DIM} is absent, the result is an array of the lower cobounds of
11213 @var{COARRAY}. If @var{DIM} is present, the result is a scalar
11214 corresponding to the lower cobound of the array along that codimension.
11216 @item @emph{See also}:
11217 @ref{LCOBOUND}, @ref{LBOUND}
11223 @section @code{UMASK} --- Set the file creation mask
11225 @cindex file system, file creation mask
11228 @item @emph{Description}:
11229 Sets the file creation mask to @var{MASK}. If called as a function, it
11230 returns the old value. If called as a subroutine and argument @var{OLD}
11231 if it is supplied, it is set to the old value. See @code{umask(2)}.
11233 @item @emph{Standard}:
11236 @item @emph{Class}:
11237 Subroutine, function
11239 @item @emph{Syntax}:
11240 @code{CALL UMASK(MASK [, OLD])}
11241 @code{OLD = UMASK(MASK)}
11243 @item @emph{Arguments}:
11244 @multitable @columnfractions .15 .70
11245 @item @var{MASK} @tab Shall be a scalar of type @code{INTEGER}.
11246 @item @var{OLD} @tab (Optional) Shall be a scalar of type
11255 @section @code{UNLINK} --- Remove a file from the file system
11257 @cindex file system, remove file
11260 @item @emph{Description}:
11261 Unlinks the file @var{PATH}. A null character (@code{CHAR(0)}) can be
11262 used to mark the end of the name in @var{PATH}; otherwise, trailing
11263 blanks in the file name are ignored. If the @var{STATUS} argument is
11264 supplied, it contains 0 on success or a nonzero error code upon return;
11265 see @code{unlink(2)}.
11267 This intrinsic is provided in both subroutine and function forms;
11268 however, only one form can be used in any given program unit.
11270 @item @emph{Standard}:
11273 @item @emph{Class}:
11274 Subroutine, function
11276 @item @emph{Syntax}:
11277 @multitable @columnfractions .80
11278 @item @code{CALL UNLINK(PATH [, STATUS])}
11279 @item @code{STATUS = UNLINK(PATH)}
11282 @item @emph{Arguments}:
11283 @multitable @columnfractions .15 .70
11284 @item @var{PATH} @tab Shall be of default @code{CHARACTER} type.
11285 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
11288 @item @emph{See also}:
11289 @ref{LINK}, @ref{SYMLNK}
11295 @section @code{UNPACK} --- Unpack an array of rank one into an array
11297 @cindex array, unpacking
11298 @cindex array, increase dimension
11299 @cindex array, scatter elements
11302 @item @emph{Description}:
11303 Store the elements of @var{VECTOR} in an array of higher rank.
11305 @item @emph{Standard}:
11306 Fortran 95 and later
11308 @item @emph{Class}:
11309 Transformational function
11311 @item @emph{Syntax}:
11312 @code{RESULT = UNPACK(VECTOR, MASK, FIELD)}
11314 @item @emph{Arguments}:
11315 @multitable @columnfractions .15 .70
11316 @item @var{VECTOR} @tab Shall be an array of any type and rank one. It
11317 shall have at least as many elements as @var{MASK} has @code{TRUE} values.
11318 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL}.
11319 @item @var{FIELD} @tab Shall be of the same type as @var{VECTOR} and have
11320 the same shape as @var{MASK}.
11323 @item @emph{Return value}:
11324 The resulting array corresponds to @var{FIELD} with @code{TRUE} elements
11325 of @var{MASK} replaced by values from @var{VECTOR} in array element order.
11327 @item @emph{Example}:
11329 PROGRAM test_unpack
11330 integer :: vector(2) = (/1,1/)
11331 logical :: mask(4) = (/ .TRUE., .FALSE., .FALSE., .TRUE. /)
11332 integer :: field(2,2) = 0, unity(2,2)
11334 ! result: unity matrix
11335 unity = unpack(vector, reshape(mask, (/2,2/)), field)
11339 @item @emph{See also}:
11340 @ref{PACK}, @ref{SPREAD}
11346 @section @code{VERIFY} --- Scan a string for the absence of a set of characters
11348 @cindex string, find missing set
11351 @item @emph{Description}:
11352 Verifies that all the characters in a @var{SET} are present in a @var{STRING}.
11354 If @var{BACK} is either absent or equals @code{FALSE}, this function
11355 returns the position of the leftmost character of @var{STRING} that is
11356 not in @var{SET}. If @var{BACK} equals @code{TRUE}, the rightmost position
11357 is returned. If all characters of @var{SET} are found in @var{STRING}, the
11360 @item @emph{Standard}:
11361 Fortran 95 and later, with @var{KIND} argument Fortran 2003 and later
11363 @item @emph{Class}:
11366 @item @emph{Syntax}:
11367 @code{RESULT = VERIFY(STRING, SET[, BACK [, KIND]])}
11369 @item @emph{Arguments}:
11370 @multitable @columnfractions .15 .70
11371 @item @var{STRING} @tab Shall be of type @code{CHARACTER}.
11372 @item @var{SET} @tab Shall be of type @code{CHARACTER}.
11373 @item @var{BACK} @tab (Optional) shall be of type @code{LOGICAL}.
11374 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
11375 expression indicating the kind parameter of the result.
11378 @item @emph{Return value}:
11379 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
11380 @var{KIND} is absent, the return value is of default integer kind.
11382 @item @emph{Example}:
11384 PROGRAM test_verify
11385 WRITE(*,*) VERIFY("FORTRAN", "AO") ! 1, found 'F'
11386 WRITE(*,*) VERIFY("FORTRAN", "FOO") ! 3, found 'R'
11387 WRITE(*,*) VERIFY("FORTRAN", "C++") ! 1, found 'F'
11388 WRITE(*,*) VERIFY("FORTRAN", "C++", .TRUE.) ! 7, found 'N'
11389 WRITE(*,*) VERIFY("FORTRAN", "FORTRAN") ! 0' found none
11393 @item @emph{See also}:
11394 @ref{SCAN}, @ref{INDEX intrinsic}
11400 @section @code{XOR} --- Bitwise logical exclusive OR
11402 @cindex bitwise logical exclusive or
11403 @cindex logical exclusive or, bitwise
11406 @item @emph{Description}:
11407 Bitwise logical exclusive or.
11409 This intrinsic routine is provided for backwards compatibility with
11410 GNU Fortran 77. For integer arguments, programmers should consider
11411 the use of the @ref{IEOR} intrinsic and for logical arguments the
11412 @code{.NEQV.} operator, which are both defined by the Fortran standard.
11414 @item @emph{Standard}:
11417 @item @emph{Class}:
11420 @item @emph{Syntax}:
11421 @code{RESULT = XOR(I, J)}
11423 @item @emph{Arguments}:
11424 @multitable @columnfractions .15 .70
11425 @item @var{I} @tab The type shall be either a scalar @code{INTEGER}
11426 type or a scalar @code{LOGICAL} type.
11427 @item @var{J} @tab The type shall be the same as the type of @var{I}.
11430 @item @emph{Return value}:
11431 The return type is either a scalar @code{INTEGER} or a scalar
11432 @code{LOGICAL}. If the kind type parameters differ, then the
11433 smaller kind type is implicitly converted to larger kind, and the
11434 return has the larger kind.
11436 @item @emph{Example}:
11439 LOGICAL :: T = .TRUE., F = .FALSE.
11441 DATA a / Z'F' /, b / Z'3' /
11443 WRITE (*,*) XOR(T, T), XOR(T, F), XOR(F, T), XOR(F, F)
11444 WRITE (*,*) XOR(a, b)
11448 @item @emph{See also}:
11449 Fortran 95 elemental function: @ref{IEOR}
11454 @node Intrinsic Modules
11455 @chapter Intrinsic Modules
11456 @cindex intrinsic Modules
11459 * ISO_FORTRAN_ENV::
11461 * OpenMP Modules OMP_LIB and OMP_LIB_KINDS::
11464 @node ISO_FORTRAN_ENV
11465 @section @code{ISO_FORTRAN_ENV}
11467 @item @emph{Standard}:
11468 Fortran 2003 and later, except when otherwise noted
11471 The @code{ISO_FORTRAN_ENV} module provides the following scalar default-integer
11475 @item @code{ATOMIC_INT_KIND}:
11476 Default-kind integer constant to be used as kind parameter when defining
11477 integer variables used in atomic operations. (Fortran 2008 or later.)
11479 @item @code{ATOMIC_LOGICAL_KIND}:
11480 Default-kind integer constant to be used as kind parameter when defining
11481 logical variables used in atomic operations. (Fortran 2008 or later.)
11483 @item @code{CHARACTER_STORAGE_SIZE}:
11484 Size in bits of the character storage unit.
11486 @item @code{ERROR_UNIT}:
11487 Identifies the preconnected unit used for error reporting.
11489 @item @code{FILE_STORAGE_SIZE}:
11490 Size in bits of the file-storage unit.
11492 @item @code{INPUT_UNIT}:
11493 Identifies the preconnected unit identified by the asterisk
11494 (@code{*}) in @code{READ} statement.
11496 @item @code{INT8}, @code{INT16}, @code{INT32}, @code{INT64}:
11497 Kind type parameters to specify an INTEGER type with a storage
11498 size of 16, 32, and 64 bits. It is negative if a target platform
11499 does not support the particular kind. (Fortran 2008 or later.)
11501 @item @code{IOSTAT_END}:
11502 The value assigned to the variable passed to the IOSTAT= specifier of
11503 an input/output statement if an end-of-file condition occurred.
11505 @item @code{IOSTAT_EOR}:
11506 The value assigned to the variable passed to the IOSTAT= specifier of
11507 an input/output statement if an end-of-record condition occurred.
11509 @item @code{IOSTAT_INQUIRE_INTERNAL_UNIT}:
11510 Scalar default-integer constant, used by @code{INQUIRE} for the
11511 IOSTAT= specifier to denote an that a unit number identifies an
11512 internal unit. (Fortran 2008 or later.)
11514 @item @code{NUMERIC_STORAGE_SIZE}:
11515 The size in bits of the numeric storage unit.
11517 @item @code{OUTPUT_UNIT}:
11518 Identifies the preconnected unit identified by the asterisk
11519 (@code{*}) in @code{WRITE} statement.
11521 @item @code{REAL32}, @code{REAL64}, @code{REAL128}:
11522 Kind type parameters to specify a REAL type with a storage
11523 size of 32, 64, and 128 bits. It is negative if a target platform
11524 does not support the particular kind. (Fortran 2008 or later.)
11526 @item @code{STAT_LOCKED}:
11527 Scalar default-integer constant used as STAT= return value by @code{LOCK} to
11528 denote that the lock variable is locked by the executing image. (Fortran 2008
11531 @item @code{STAT_LOCKED_OTHER_IMAGE}:
11532 Scalar default-integer constant used as STAT= return value by @code{UNLOCK} to
11533 denote that the lock variable is locked by another image. (Fortran 2008 or
11536 @item @code{STAT_STOPPED_IMAGE}:
11537 Positive, scalar default-integer constant used as STAT= return value if the
11538 argument in the statement requires synchronisation with an image, which has
11539 initiated the termination of the execution. (Fortran 2008 or later.)
11541 @item @code{STAT_UNLOCKED}:
11542 Scalar default-integer constant used as STAT= return value by @code{UNLOCK} to
11543 denote that the lock variable is unlocked. (Fortran 2008 or later.)
11548 @node ISO_C_BINDING
11549 @section @code{ISO_C_BINDING}
11551 @item @emph{Standard}:
11552 Fortran 2003 and later, GNU extensions
11555 The following intrinsic procedures are provided by the module; their
11556 definition can be found in the section Intrinsic Procedures of this
11560 @item @code{C_ASSOCIATED}
11561 @item @code{C_F_POINTER}
11562 @item @code{C_F_PROCPOINTER}
11563 @item @code{C_FUNLOC}
11566 @c TODO: Vertical spacing between C_FUNLOC and C_LOC wrong in PDF,
11567 @c don't really know why.
11569 The @code{ISO_C_BINDING} module provides the following named constants of
11570 type default integer, which can be used as KIND type parameters.
11572 In addition to the integer named constants required by the Fortran 2003
11573 standard, GNU Fortran provides as an extension named constants for the
11574 128-bit integer types supported by the C compiler: @code{C_INT128_T,
11575 C_INT_LEAST128_T, C_INT_FAST128_T}.
11577 @multitable @columnfractions .15 .35 .35 .35
11578 @item Fortran Type @tab Named constant @tab C type @tab Extension
11579 @item @code{INTEGER}@tab @code{C_INT} @tab @code{int}
11580 @item @code{INTEGER}@tab @code{C_SHORT} @tab @code{short int}
11581 @item @code{INTEGER}@tab @code{C_LONG} @tab @code{long int}
11582 @item @code{INTEGER}@tab @code{C_LONG_LONG} @tab @code{long long int}
11583 @item @code{INTEGER}@tab @code{C_SIGNED_CHAR} @tab @code{signed char}/@code{unsigned char}
11584 @item @code{INTEGER}@tab @code{C_SIZE_T} @tab @code{size_t}
11585 @item @code{INTEGER}@tab @code{C_INT8_T} @tab @code{int8_t}
11586 @item @code{INTEGER}@tab @code{C_INT16_T} @tab @code{int16_t}
11587 @item @code{INTEGER}@tab @code{C_INT32_T} @tab @code{int32_t}
11588 @item @code{INTEGER}@tab @code{C_INT64_T} @tab @code{int64_t}
11589 @item @code{INTEGER}@tab @code{C_INT128_T} @tab @code{int128_t} @tab Ext.
11590 @item @code{INTEGER}@tab @code{C_INT_LEAST8_T} @tab @code{int_least8_t}
11591 @item @code{INTEGER}@tab @code{C_INT_LEAST16_T} @tab @code{int_least16_t}
11592 @item @code{INTEGER}@tab @code{C_INT_LEAST32_T} @tab @code{int_least32_t}
11593 @item @code{INTEGER}@tab @code{C_INT_LEAST64_T} @tab @code{int_least64_t}
11594 @item @code{INTEGER}@tab @code{C_INT_LEAST128_T}@tab @code{int_least128_t} @tab Ext.
11595 @item @code{INTEGER}@tab @code{C_INT_FAST8_T} @tab @code{int_fast8_t}
11596 @item @code{INTEGER}@tab @code{C_INT_FAST16_T} @tab @code{int_fast16_t}
11597 @item @code{INTEGER}@tab @code{C_INT_FAST32_T} @tab @code{int_fast32_t}
11598 @item @code{INTEGER}@tab @code{C_INT_FAST64_T} @tab @code{int_fast64_t}
11599 @item @code{INTEGER}@tab @code{C_INT_FAST128_T} @tab @code{int_fast128_t} @tab Ext.
11600 @item @code{INTEGER}@tab @code{C_INTMAX_T} @tab @code{intmax_t}
11601 @item @code{INTEGER}@tab @code{C_INTPTR_T} @tab @code{intptr_t}
11602 @item @code{REAL} @tab @code{C_FLOAT} @tab @code{float}
11603 @item @code{REAL} @tab @code{C_DOUBLE} @tab @code{double}
11604 @item @code{REAL} @tab @code{C_LONG_DOUBLE} @tab @code{long double}
11605 @item @code{COMPLEX}@tab @code{C_FLOAT_COMPLEX} @tab @code{float _Complex}
11606 @item @code{COMPLEX}@tab @code{C_DOUBLE_COMPLEX}@tab @code{double _Complex}
11607 @item @code{COMPLEX}@tab @code{C_LONG_DOUBLE_COMPLEX}@tab @code{long double _Complex}
11608 @item @code{LOGICAL}@tab @code{C_BOOL} @tab @code{_Bool}
11609 @item @code{CHARACTER}@tab @code{C_CHAR} @tab @code{char}
11612 Additionally, the following parameters of type @code{CHARACTER(KIND=C_CHAR)}
11615 @multitable @columnfractions .20 .45 .15
11616 @item Name @tab C definition @tab Value
11617 @item @code{C_NULL_CHAR} @tab null character @tab @code{'\0'}
11618 @item @code{C_ALERT} @tab alert @tab @code{'\a'}
11619 @item @code{C_BACKSPACE} @tab backspace @tab @code{'\b'}
11620 @item @code{C_FORM_FEED} @tab form feed @tab @code{'\f'}
11621 @item @code{C_NEW_LINE} @tab new line @tab @code{'\n'}
11622 @item @code{C_CARRIAGE_RETURN} @tab carriage return @tab @code{'\r'}
11623 @item @code{C_HORIZONTAL_TAB} @tab horizontal tab @tab @code{'\t'}
11624 @item @code{C_VERTICAL_TAB} @tab vertical tab @tab @code{'\v'}
11627 @node OpenMP Modules OMP_LIB and OMP_LIB_KINDS
11628 @section OpenMP Modules @code{OMP_LIB} and @code{OMP_LIB_KINDS}
11630 @item @emph{Standard}:
11631 OpenMP Application Program Interface v3.0
11635 The OpenMP Fortran runtime library routines are provided both in
11636 a form of two Fortran 90 modules, named @code{OMP_LIB} and
11637 @code{OMP_LIB_KINDS}, and in a form of a Fortran @code{include} file named
11638 @file{omp_lib.h}. The procedures provided by @code{OMP_LIB} can be found
11639 in the @ref{Top,,Introduction,libgomp,GNU OpenMP runtime library} manual,
11640 the named constants defined in the @code{OMP_LIB_KINDS} module are listed
11643 For details refer to the actual
11644 @uref{http://www.openmp.org/mp-documents/spec30.pdf,
11645 OpenMP Application Program Interface v3.0}.
11647 @code{OMP_LIB_KINDS} provides the following scalar default-integer
11651 @item @code{omp_integer_kind}
11652 @item @code{omp_logical_kind}
11653 @item @code{omp_lock_kind}
11654 @item @code{omp_nest_lock_kind}
11655 @item @code{omp_sched_kind}