2 Copyright (C) 2005, 2006, 2007
3 Free Software Foundation, Inc.
4 This is part of the GNU Fortran manual.
5 For copying conditions, see the file gfortran.texi.
7 Permission is granted to copy, distribute and/or modify this document
8 under the terms of the GNU Free Documentation License, Version 1.2 or
9 any later version published by the Free Software Foundation; with the
10 Invariant Sections being ``GNU General Public License'' and ``Funding
11 Free Software'', the Front-Cover texts being (a) (see below), and with
12 the Back-Cover Texts being (b) (see below). A copy of the license is
13 included in the gfdl(7) man page.
16 Some basic guidelines for editing this document:
18 (1) The intrinsic procedures are to be listed in alphabetical order.
19 (2) The generic name is to be used.
20 (3) The specific names are included in the function index and in a
21 table at the end of the node (See ABS entry).
22 (4) Try to maintain the same style for each entry.
28 \gdef\acos{\mathop{\rm acos}\nolimits}
29 \gdef\asin{\mathop{\rm asin}\nolimits}
30 \gdef\atan{\mathop{\rm atan}\nolimits}
31 \gdef\acosh{\mathop{\rm acosh}\nolimits}
32 \gdef\asinh{\mathop{\rm asinh}\nolimits}
33 \gdef\atanh{\mathop{\rm atanh}\nolimits}
37 @node Intrinsic Procedures
38 @chapter Intrinsic Procedures
39 @cindex intrinsic procedures
42 * Introduction: Introduction to Intrinsics
43 * @code{ABORT}: ABORT, Abort the program
44 * @code{ABS}: ABS, Absolute value
45 * @code{ACCESS}: ACCESS, Checks file access modes
46 * @code{ACHAR}: ACHAR, Character in @acronym{ASCII} collating sequence
47 * @code{ACOS}: ACOS, Arccosine function
48 * @code{ACOSH}: ACOSH, Hyperbolic arccosine function
49 * @code{ADJUSTL}: ADJUSTL, Left adjust a string
50 * @code{ADJUSTR}: ADJUSTR, Right adjust a string
51 * @code{AIMAG}: AIMAG, Imaginary part of complex number
52 * @code{AINT}: AINT, Truncate to a whole number
53 * @code{ALARM}: ALARM, Set an alarm clock
54 * @code{ALL}: ALL, Determine if all values are true
55 * @code{ALLOCATED}: ALLOCATED, Status of allocatable entity
56 * @code{AND}: AND, Bitwise logical AND
57 * @code{ANINT}: ANINT, Nearest whole number
58 * @code{ANY}: ANY, Determine if any values are true
59 * @code{ASIN}: ASIN, Arcsine function
60 * @code{ASINH}: ASINH, Hyperbolic arcsine function
61 * @code{ASSOCIATED}: ASSOCIATED, Status of a pointer or pointer/target pair
62 * @code{ATAN}: ATAN, Arctangent function
63 * @code{ATAN2}: ATAN2, Arctangent function
64 * @code{ATANH}: ATANH, Hyperbolic arctangent function
65 * @code{BESJ0}: BESJ0, Bessel function of the first kind of order 0
66 * @code{BESJ1}: BESJ1, Bessel function of the first kind of order 1
67 * @code{BESJN}: BESJN, Bessel function of the first kind
68 * @code{BESY0}: BESY0, Bessel function of the second kind of order 0
69 * @code{BESY1}: BESY1, Bessel function of the second kind of order 1
70 * @code{BESYN}: BESYN, Bessel function of the second kind
71 * @code{BIT_SIZE}: BIT_SIZE, Bit size inquiry function
72 * @code{BTEST}: BTEST, Bit test function
73 * @code{C_ASSOCIATED}: C_ASSOCIATED, Status of a C pointer
74 * @code{C_F_POINTER}: C_F_POINTER, Convert C into Fortran pointer
75 * @code{C_F_PROCPOINTER}: C_F_PROCPOINTER, Convert C into Fortran procedure pointer
76 * @code{C_FUNLOC}: C_FUNLOC, Obtain the C address of a procedure
77 * @code{C_LOC}: C_LOC, Obtain the C address of an object
78 * @code{CEILING}: CEILING, Integer ceiling function
79 * @code{CHAR}: CHAR, Integer-to-character conversion function
80 * @code{CHDIR}: CHDIR, Change working directory
81 * @code{CHMOD}: CHMOD, Change access permissions of files
82 * @code{CMPLX}: CMPLX, Complex conversion function
83 * @code{COMMAND_ARGUMENT_COUNT}: COMMAND_ARGUMENT_COUNT, Get number of command line arguments
84 * @code{COMPLEX}: COMPLEX, Complex conversion function
85 * @code{CONJG}: CONJG, Complex conjugate function
86 * @code{COS}: COS, Cosine function
87 * @code{COSH}: COSH, Hyperbolic cosine function
88 * @code{COUNT}: COUNT, Count occurrences of TRUE in an array
89 * @code{CPU_TIME}: CPU_TIME, CPU time subroutine
90 * @code{CSHIFT}: CSHIFT, Circular shift elements of an array
91 * @code{CTIME}: CTIME, Subroutine (or function) to convert a time into a string
92 * @code{DATE_AND_TIME}: DATE_AND_TIME, Date and time subroutine
93 * @code{DBLE}: DBLE, Double precision conversion function
94 * @code{DCMPLX}: DCMPLX, Double complex conversion function
95 * @code{DFLOAT}: DFLOAT, Double precision conversion function
96 * @code{DIGITS}: DIGITS, Significant digits function
97 * @code{DIM}: DIM, Positive difference
98 * @code{DOT_PRODUCT}: DOT_PRODUCT, Dot product function
99 * @code{DPROD}: DPROD, Double product function
100 * @code{DREAL}: DREAL, Double real part function
101 * @code{DTIME}: DTIME, Execution time subroutine (or function)
102 * @code{EOSHIFT}: EOSHIFT, End-off shift elements of an array
103 * @code{EPSILON}: EPSILON, Epsilon function
104 * @code{ERF}: ERF, Error function
105 * @code{ERFC}: ERFC, Complementary error function
106 * @code{ETIME}: ETIME, Execution time subroutine (or function)
107 * @code{EXIT}: EXIT, Exit the program with status.
108 * @code{EXP}: EXP, Exponential function
109 * @code{EXPONENT}: EXPONENT, Exponent function
110 * @code{FDATE}: FDATE, Subroutine (or function) to get the current time as a string
111 * @code{FGET}: FGET, Read a single character in stream mode from stdin
112 * @code{FGETC}: FGETC, Read a single character in stream mode
113 * @code{FLOAT}: FLOAT, Convert integer to default real
114 * @code{FLOOR}: FLOOR, Integer floor function
115 * @code{FLUSH}: FLUSH, Flush I/O unit(s)
116 * @code{FNUM}: FNUM, File number function
117 * @code{FPUT}: FPUT, Write a single character in stream mode to stdout
118 * @code{FPUTC}: FPUTC, Write a single character in stream mode
119 * @code{FRACTION}: FRACTION, Fractional part of the model representation
120 * @code{FREE}: FREE, Memory de-allocation subroutine
121 * @code{FSEEK}: FSEEK, Low level file positioning subroutine
122 * @code{FSTAT}: FSTAT, Get file status
123 * @code{FTELL}: FTELL, Current stream position
124 * @code{GERROR}: GERROR, Get last system error message
125 * @code{GETARG}: GETARG, Get command line arguments
126 * @code{GET_COMMAND}: GET_COMMAND, Get the entire command line
127 * @code{GET_COMMAND_ARGUMENT}: GET_COMMAND_ARGUMENT, Get command line arguments
128 * @code{GETCWD}: GETCWD, Get current working directory
129 * @code{GETENV}: GETENV, Get an environmental variable
130 * @code{GET_ENVIRONMENT_VARIABLE}: GET_ENVIRONMENT_VARIABLE, Get an environmental variable
131 * @code{GETGID}: GETGID, Group ID function
132 * @code{GETLOG}: GETLOG, Get login name
133 * @code{GETPID}: GETPID, Process ID function
134 * @code{GETUID}: GETUID, User ID function
135 * @code{GMTIME}: GMTIME, Convert time to GMT info
136 * @code{HOSTNM}: HOSTNM, Get system host name
137 * @code{HUGE}: HUGE, Largest number of a kind
138 * @code{IACHAR}: IACHAR, Code in @acronym{ASCII} collating sequence
139 * @code{IAND}: IAND, Bitwise logical and
140 * @code{IARGC}: IARGC, Get the number of command line arguments
141 * @code{IBCLR}: IBCLR, Clear bit
142 * @code{IBITS}: IBITS, Bit extraction
143 * @code{IBSET}: IBSET, Set bit
144 * @code{ICHAR}: ICHAR, Character-to-integer conversion function
145 * @code{IDATE}: IDATE, Current local time (day/month/year)
146 * @code{IEOR}: IEOR, Bitwise logical exclusive or
147 * @code{IERRNO}: IERRNO, Function to get the last system error number
148 * @code{INDEX}: INDEX, Position of a substring within a string
149 * @code{INT}: INT, Convert to integer type
150 * @code{INT2}: INT2, Convert to 16-bit integer type
151 * @code{INT8}: INT8, Convert to 64-bit integer type
152 * @code{IOR}: IOR, Bitwise logical or
153 * @code{IRAND}: IRAND, Integer pseudo-random number
154 * @code{ISATTY}: ISATTY, Whether a unit is a terminal device
155 * @code{ISHFT}: ISHFT, Shift bits
156 * @code{ISHFTC}: ISHFTC, Shift bits circularly
157 * @code{ISNAN}: ISNAN, Tests for a NaN
158 * @code{ITIME}: ITIME, Current local time (hour/minutes/seconds)
159 * @code{KILL}: KILL, Send a signal to a process
160 * @code{KIND}: KIND, Kind of an entity
161 * @code{LBOUND}: LBOUND, Lower dimension bounds of an array
162 * @code{LEN}: LEN, Length of a character entity
163 * @code{LEN_TRIM}: LEN_TRIM, Length of a character entity without trailing blank characters
164 * @code{LGE}: LGE, Lexical greater than or equal
165 * @code{LGT}: LGT, Lexical greater than
166 * @code{LINK}: LINK, Create a hard link
167 * @code{LLE}: LLE, Lexical less than or equal
168 * @code{LLT}: LLT, Lexical less than
169 * @code{LNBLNK}: LNBLNK, Index of the last non-blank character in a string
170 * @code{LOC}: LOC, Returns the address of a variable
171 * @code{LOG}: LOG, Logarithm function
172 * @code{LOG10}: LOG10, Base 10 logarithm function
173 * @code{LOGICAL}: LOGICAL, Convert to logical type
174 * @code{LONG}: LONG, Convert to integer type
175 * @code{LSHIFT}: LSHIFT, Left shift bits
176 * @code{LSTAT}: LSTAT, Get file status
177 * @code{LTIME}: LTIME, Convert time to local time info
178 * @code{MALLOC}: MALLOC, Dynamic memory allocation function
179 * @code{MATMUL}: MATMUL, matrix multiplication
180 * @code{MAX}: MAX, Maximum value of an argument list
181 * @code{MAXEXPONENT}: MAXEXPONENT, Maximum exponent of a real kind
182 * @code{MAXLOC}: MAXLOC, Location of the maximum value within an array
183 * @code{MAXVAL}: MAXVAL, Maximum value of an array
184 * @code{MCLOCK}: MCLOCK, Time function
185 * @code{MCLOCK8}: MCLOCK8, Time function (64-bit)
186 * @code{MERGE}: MERGE, Merge arrays
187 * @code{MIN}: MIN, Minimum value of an argument list
188 * @code{MINEXPONENT}: MINEXPONENT, Minimum exponent of a real kind
189 * @code{MINLOC}: MINLOC, Location of the minimum value within an array
190 * @code{MINVAL}: MINVAL, Minimum value of an array
191 * @code{MOD}: MOD, Remainder function
192 * @code{MODULO}: MODULO, Modulo function
193 * @code{MOVE_ALLOC}: MOVE_ALLOC, Move allocation from one object to another
194 * @code{MVBITS}: MVBITS, Move bits from one integer to another
195 * @code{NEAREST}: NEAREST, Nearest representable number
196 * @code{NEW_LINE}: NEW_LINE, New line character
197 * @code{NINT}: NINT, Nearest whole number
198 * @code{NOT}: NOT, Logical negation
199 * @code{NULL}: NULL, Function that returns an disassociated pointer
200 * @code{OR}: OR, Bitwise logical OR
201 * @code{PACK}: PACK, Pack an array into an array of rank one
202 * @code{PERROR}: PERROR, Print system error message
203 * @code{PRECISION}: PRECISION, Decimal precision of a real kind
204 * @code{PRESENT}: PRESENT, Determine whether an optional dummy argument is specified
205 * @code{PRODUCT}: PRODUCT, Product of array elements
206 * @code{RADIX}: RADIX, Base of a data model
207 * @code{RANDOM_NUMBER}: RANDOM_NUMBER, Pseudo-random number
208 * @code{RANDOM_SEED}: RANDOM_SEED, Initialize a pseudo-random number sequence
209 * @code{RAND}: RAND, Real pseudo-random number
210 * @code{RANGE}: RANGE, Decimal exponent range of a real kind
211 * @code{RAN}: RAN, Real pseudo-random number
212 * @code{REAL}: REAL, Convert to real type
213 * @code{RENAME}: RENAME, Rename a file
214 * @code{REPEAT}: REPEAT, Repeated string concatenation
215 * @code{RESHAPE}: RESHAPE, Function to reshape an array
216 * @code{RRSPACING}: RRSPACING, Reciprocal of the relative spacing
217 * @code{RSHIFT}: RSHIFT, Right shift bits
218 * @code{SCALE}: SCALE, Scale a real value
219 * @code{SCAN}: SCAN, Scan a string for the presence of a set of characters
220 * @code{SECNDS}: SECNDS, Time function
221 * @code{SECOND}: SECOND, CPU time function
222 * @code{SELECTED_INT_KIND}: SELECTED_INT_KIND, Choose integer kind
223 * @code{SELECTED_REAL_KIND}: SELECTED_REAL_KIND, Choose real kind
224 * @code{SET_EXPONENT}: SET_EXPONENT, Set the exponent of the model
225 * @code{SHAPE}: SHAPE, Determine the shape of an array
226 * @code{SIGN}: SIGN, Sign copying function
227 * @code{SIGNAL}: SIGNAL, Signal handling subroutine (or function)
228 * @code{SIN}: SIN, Sine function
229 * @code{SINH}: SINH, Hyperbolic sine function
230 * @code{SIZE}: SIZE, Function to determine the size of an array
231 * @code{SIZEOF}: SIZEOF, Determine the size in bytes of an expression
232 * @code{SLEEP}: SLEEP, Sleep for the specified number of seconds
233 * @code{SNGL}: SNGL, Convert double precision real to default real
234 * @code{SPACING}: SPACING, Smallest distance between two numbers of a given type
235 * @code{SPREAD}: SPREAD, Add a dimension to an array
236 * @code{SQRT}: SQRT, Square-root function
237 * @code{SRAND}: SRAND, Reinitialize the random number generator
238 * @code{STAT}: STAT, Get file status
239 * @code{SUM}: SUM, Sum of array elements
240 * @code{SYMLNK}: SYMLNK, Create a symbolic link
241 * @code{SYSTEM}: SYSTEM, Execute a shell command
242 * @code{SYSTEM_CLOCK}: SYSTEM_CLOCK, Time function
243 * @code{TAN}: TAN, Tangent function
244 * @code{TANH}: TANH, Hyperbolic tangent function
245 * @code{TIME}: TIME, Time function
246 * @code{TIME8}: TIME8, Time function (64-bit)
247 * @code{TINY}: TINY, Smallest positive number of a real kind
248 * @code{TRANSFER}: TRANSFER, Transfer bit patterns
249 * @code{TRANSPOSE}: TRANSPOSE, Transpose an array of rank two
250 * @code{TRIM}: TRIM, Remove trailing blank characters of a string
251 * @code{TTYNAM}: TTYNAM, Get the name of a terminal device.
252 * @code{UBOUND}: UBOUND, Upper dimension bounds of an array
253 * @code{UMASK}: UMASK, Set the file creation mask
254 * @code{UNLINK}: UNLINK, Remove a file from the file system
255 * @code{UNPACK}: UNPACK, Unpack an array of rank one into an array
256 * @code{VERIFY}: VERIFY, Scan a string for the absence of a set of characters
257 * @code{XOR}: XOR, Bitwise logical exclusive or
260 @node Introduction to Intrinsics
261 @section Introduction to intrinsic procedures
263 The intrinsic procedures provided by GNU Fortran include all of the
264 intrinsic procedures required by the Fortran 95 standard, a set of
265 intrinsic procedures for backwards compatibility with G77, and a small
266 selection of intrinsic procedures from the Fortran 2003 standard. Any
267 conflict between a description here and a description in either the
268 Fortran 95 standard or the Fortran 2003 standard is unintentional, and
269 the standard(s) should be considered authoritative.
271 The enumeration of the @code{KIND} type parameter is processor defined in
272 the Fortran 95 standard. GNU Fortran defines the default integer type and
273 default real type by @code{INTEGER(KIND=4)} and @code{REAL(KIND=4)},
274 respectively. The standard mandates that both data types shall have
275 another kind, which have more precision. On typical target architectures
276 supported by @command{gfortran}, this kind type parameter is @code{KIND=8}.
277 Hence, @code{REAL(KIND=8)} and @code{DOUBLE PRECISION} are equivalent.
278 In the description of generic intrinsic procedures, the kind type parameter
279 will be specified by @code{KIND=*}, and in the description of specific
280 names for an intrinsic procedure the kind type parameter will be explicitly
281 given (e.g., @code{REAL(KIND=4)} or @code{REAL(KIND=8)}). Finally, for
282 brevity the optional @code{KIND=} syntax will be omitted.
284 Many of the intrinsic procedures take one or more optional arguments.
285 This document follows the convention used in the Fortran 95 standard,
286 and denotes such arguments by square brackets.
288 GNU Fortran offers the @option{-std=f95} and @option{-std=gnu} options,
289 which can be used to restrict the set of intrinsic procedures to a
290 given standard. By default, @command{gfortran} sets the @option{-std=gnu}
291 option, and so all intrinsic procedures described here are accepted. There
292 is one caveat. For a select group of intrinsic procedures, @command{g77}
293 implemented both a function and a subroutine. Both classes
294 have been implemented in @command{gfortran} for backwards compatibility
295 with @command{g77}. It is noted here that these functions and subroutines
296 cannot be intermixed in a given subprogram. In the descriptions that follow,
297 the applicable standard for each intrinsic procedure is noted.
302 @section @code{ABORT} --- Abort the program
304 @cindex program termination, with core dump
305 @cindex terminate program, with core dump
309 @item @emph{Description}:
310 @code{ABORT} causes immediate termination of the program. On operating
311 systems that support a core dump, @code{ABORT} will produce a core dump,
312 which is suitable for debugging purposes.
314 @item @emph{Standard}:
323 @item @emph{Return value}:
326 @item @emph{Example}:
329 integer :: i = 1, j = 2
330 if (i /= j) call abort
331 end program test_abort
334 @item @emph{See also}:
335 @ref{EXIT}, @ref{KILL}
342 @section @code{ABS} --- Absolute value
349 @cindex absolute value
352 @item @emph{Description}:
353 @code{ABS(X)} computes the absolute value of @code{X}.
355 @item @emph{Standard}:
356 F77 and later, has overloads that are GNU extensions
362 @code{RESULT = ABS(X)}
364 @item @emph{Arguments}:
365 @multitable @columnfractions .15 .70
366 @item @var{X} @tab The type of the argument shall be an @code{INTEGER(*)},
367 @code{REAL(*)}, or @code{COMPLEX(*)}.
370 @item @emph{Return value}:
371 The return value is of the same type and
372 kind as the argument except the return value is @code{REAL(*)} for a
373 @code{COMPLEX(*)} argument.
375 @item @emph{Example}:
380 complex :: z = (-1.e0,0.e0)
387 @item @emph{Specific names}:
388 @multitable @columnfractions .20 .20 .20 .25
389 @item Name @tab Argument @tab Return type @tab Standard
390 @item @code{CABS(Z)} @tab @code{COMPLEX(4) Z} @tab @code{REAL(4)} @tab F77 and later
391 @item @code{DABS(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F77 and later
392 @item @code{IABS(I)} @tab @code{INTEGER(4) I} @tab @code{INTEGER(4)} @tab F77 and later
393 @item @code{ZABS(Z)} @tab @code{COMPLEX(8) Z} @tab @code{COMPLEX(8)} @tab GNU extension
394 @item @code{CDABS(Z)} @tab @code{COMPLEX(8) Z} @tab @code{COMPLEX(8)} @tab GNU extension
401 @section @code{ACCESS} --- Checks file access modes
403 @cindex file system, access mode
406 @item @emph{Description}:
407 @code{ACCESS(NAME, MODE)} checks whether the file @var{NAME}
408 exists, is readable, writable or executable. Except for the
409 executable check, @code{ACCESS} can be replaced by
410 Fortran 95's @code{INQUIRE}.
412 @item @emph{Standard}:
419 @code{RESULT = ACCESS(NAME, MODE)}
421 @item @emph{Arguments}:
422 @multitable @columnfractions .15 .70
423 @item @var{NAME} @tab Scalar @code{CHARACTER} with the file name.
424 Tailing blank are ignored unless the character @code{achar(0)} is
425 present, then all characters up to and excluding @code{achar(0)} are
427 @item @var{MODE} @tab Scalar @code{CHARACTER} with the file access mode,
428 may be any concatenation of @code{"r"} (readable), @code{"w"} (writable)
429 and @code{"x"} (executable), or @code{" "} to check for existence.
432 @item @emph{Return value}:
433 Returns a scalar @code{INTEGER}, which is @code{0} if the file is
434 accessible in the given mode; otherwise or if an invalid argument
435 has been given for @code{MODE} the value @code{1} is returned.
437 @item @emph{Example}:
441 character(len=*), parameter :: file = 'test.dat'
442 character(len=*), parameter :: file2 = 'test.dat '//achar(0)
443 if(access(file,' ') == 0) print *, trim(file),' is exists'
444 if(access(file,'r') == 0) print *, trim(file),' is readable'
445 if(access(file,'w') == 0) print *, trim(file),' is writable'
446 if(access(file,'x') == 0) print *, trim(file),' is executable'
447 if(access(file2,'rwx') == 0) &
448 print *, trim(file2),' is readable, writable and executable'
449 end program access_test
451 @item @emph{Specific names}:
452 @item @emph{See also}:
459 @section @code{ACHAR} --- Character in @acronym{ASCII} collating sequence
461 @cindex @acronym{ASCII} collating sequence
462 @cindex collating sequence, @acronym{ASCII}
465 @item @emph{Description}:
466 @code{ACHAR(I)} returns the character located at position @code{I}
467 in the @acronym{ASCII} collating sequence.
469 @item @emph{Standard}:
476 @code{RESULT = ACHAR(I)}
478 @item @emph{Arguments}:
479 @multitable @columnfractions .15 .70
480 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
483 @item @emph{Return value}:
484 The return value is of type @code{CHARACTER} with a length of one. The
485 kind type parameter is the same as @code{KIND('A')}.
487 @item @emph{Example}:
492 end program test_achar
496 See @ref{ICHAR} for a discussion of converting between numerical values
497 and formatted string representations.
499 @item @emph{See also}:
500 @ref{CHAR}, @ref{IACHAR}, @ref{ICHAR}
507 @section @code{ACOS} --- Arccosine function
510 @cindex trigonometric function, cosine, inverse
511 @cindex cosine, inverse
514 @item @emph{Description}:
515 @code{ACOS(X)} computes the arccosine of @var{X} (inverse of @code{COS(X)}).
517 @item @emph{Standard}:
524 @code{RESULT = ACOS(X)}
526 @item @emph{Arguments}:
527 @multitable @columnfractions .15 .70
528 @item @var{X} @tab The type shall be @code{REAL(*)} with a magnitude that is
532 @item @emph{Return value}:
533 The return value is of type @code{REAL(*)} and it lies in the
534 range @math{ 0 \leq \acos(x) \leq \pi}. The kind type parameter
535 is the same as @var{X}.
537 @item @emph{Example}:
540 real(8) :: x = 0.866_8
542 end program test_acos
545 @item @emph{Specific names}:
546 @multitable @columnfractions .20 .20 .20 .25
547 @item Name @tab Argument @tab Return type @tab Standard
548 @item @code{DACOS(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F77 and later
551 @item @emph{See also}:
552 Inverse function: @ref{COS}
559 @section @code{ACOSH} --- Hyperbolic arccosine function
562 @cindex area hyperbolic cosine
563 @cindex hyperbolic arccosine
564 @cindex hyperbolic function, cosine, inverse
565 @cindex cosine, hyperbolic, inverse
568 @item @emph{Description}:
569 @code{ACOSH(X)} computes the hyperbolic arccosine of @var{X} (inverse of
572 @item @emph{Standard}:
579 @code{RESULT = ACOSH(X)}
581 @item @emph{Arguments}:
582 @multitable @columnfractions .15 .70
583 @item @var{X} @tab The type shall be @code{REAL(*)} with a magnitude that is
584 greater or equal to one.
587 @item @emph{Return value}:
588 The return value is of type @code{REAL(*)} and it lies in the
589 range @math{0 \leq \acosh (x) \leq \infty}.
591 @item @emph{Example}:
594 REAL(8), DIMENSION(3) :: x = (/ 1.0, 2.0, 3.0 /)
599 @item @emph{Specific names}:
600 @multitable @columnfractions .20 .20 .20 .25
601 @item Name @tab Argument @tab Return type @tab Standard
602 @item @code{DACOSH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
605 @item @emph{See also}:
606 Inverse function: @ref{COSH}
612 @section @code{ADJUSTL} --- Left adjust a string
614 @cindex string, adjust left
615 @cindex adjust string
618 @item @emph{Description}:
619 @code{ADJUSTL(STR)} will left adjust a string by removing leading spaces.
620 Spaces are inserted at the end of the string as needed.
622 @item @emph{Standard}:
629 @code{RESULT = ADJUSTL(STR)}
631 @item @emph{Arguments}:
632 @multitable @columnfractions .15 .70
633 @item @var{STR} @tab The type shall be @code{CHARACTER}.
636 @item @emph{Return value}:
637 The return value is of type @code{CHARACTER} where leading spaces
638 are removed and the same number of spaces are inserted on the end
641 @item @emph{Example}:
644 character(len=20) :: str = ' gfortran'
647 end program test_adjustl
650 @item @emph{See also}:
651 @ref{ADJUSTR}, @ref{TRIM}
657 @section @code{ADJUSTR} --- Right adjust a string
659 @cindex string, adjust right
660 @cindex adjust string
663 @item @emph{Description}:
664 @code{ADJUSTR(STR)} will right adjust a string by removing trailing spaces.
665 Spaces are inserted at the start of the string as needed.
667 @item @emph{Standard}:
674 @code{RESULT = ADJUSTR(STR)}
676 @item @emph{Arguments}:
677 @multitable @columnfractions .15 .70
678 @item @var{STR} @tab The type shall be @code{CHARACTER}.
681 @item @emph{Return value}:
682 The return value is of type @code{CHARACTER} where trailing spaces
683 are removed and the same number of spaces are inserted at the start
686 @item @emph{Example}:
689 character(len=20) :: str = 'gfortran'
692 end program test_adjustr
695 @item @emph{See also}:
696 @ref{ADJUSTL}, @ref{TRIM}
702 @section @code{AIMAG} --- Imaginary part of complex number
707 @cindex complex numbers, imaginary part
710 @item @emph{Description}:
711 @code{AIMAG(Z)} yields the imaginary part of complex argument @code{Z}.
712 The @code{IMAG(Z)} and @code{IMAGPART(Z)} intrinsic functions are provided
713 for compatibility with @command{g77}, and their use in new code is
714 strongly discouraged.
716 @item @emph{Standard}:
717 F77 and later, has overloads that are GNU extensions
723 @code{RESULT = AIMAG(Z)}
725 @item @emph{Arguments}:
726 @multitable @columnfractions .15 .70
727 @item @var{Z} @tab The type of the argument shall be @code{COMPLEX(*)}.
730 @item @emph{Return value}:
731 The return value is of type real with the
732 kind type parameter of the argument.
734 @item @emph{Example}:
739 z4 = cmplx(1.e0_4, 0.e0_4)
740 z8 = cmplx(0.e0_8, 1.e0_8)
741 print *, aimag(z4), dimag(z8)
742 end program test_aimag
745 @item @emph{Specific names}:
746 @multitable @columnfractions .20 .20 .20 .25
747 @item Name @tab Argument @tab Return type @tab Standard
748 @item @code{DIMAG(Z)} @tab @code{COMPLEX(8) Z} @tab @code{REAL(8)} @tab GNU extension
749 @item @code{IMAG(Z)} @tab @code{COMPLEX(*) Z} @tab @code{REAL(*)} @tab GNU extension
750 @item @code{IMAGPART(Z)} @tab @code{COMPLEX(*) Z} @tab @code{REAL(*)} @tab GNU extension
757 @section @code{AINT} --- Truncate to a whole number
761 @cindex rounding, floor
764 @item @emph{Description}:
765 @code{AINT(X [, KIND])} truncates its argument to a whole number.
767 @item @emph{Standard}:
774 @code{RESULT = AINT(X [, KIND])}
776 @item @emph{Arguments}:
777 @multitable @columnfractions .15 .70
778 @item @var{X} @tab The type of the argument shall be @code{REAL(*)}.
779 @item @var{KIND} @tab (Optional) An @code{INTEGER(*)} initialization
780 expression indicating the kind parameter of
784 @item @emph{Return value}:
785 The return value is of type real with the kind type parameter of the
786 argument if the optional @var{KIND} is absent; otherwise, the kind
787 type parameter will be given by @var{KIND}. If the magnitude of
788 @var{X} is less than one, then @code{AINT(X)} returns zero. If the
789 magnitude is equal to or greater than one, then it returns the largest
790 whole number that does not exceed its magnitude. The sign is the same
791 as the sign of @var{X}.
793 @item @emph{Example}:
800 print *, aint(x4), dint(x8)
802 end program test_aint
805 @item @emph{Specific names}:
806 @multitable @columnfractions .20 .20 .20 .25
807 @item Name @tab Argument @tab Return type @tab Standard
808 @item @code{DINT(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F77 and later
815 @section @code{ALARM} --- Execute a routine after a given delay
817 @cindex delayed execution
820 @item @emph{Description}:
821 @code{ALARM(SECONDS, HANDLER [, STATUS])} causes external subroutine @var{HANDLER}
822 to be executed after a delay of @var{SECONDS} by using @code{alarm(2)} to
823 set up a signal and @code{signal(2)} to catch it. If @var{STATUS} is
824 supplied, it will be returned with the number of seconds remaining until
825 any previously scheduled alarm was due to be delivered, or zero if there
826 was no previously scheduled alarm.
828 @item @emph{Standard}:
835 @code{CALL ALARM(SECONDS, HANDLER [, STATUS])}
837 @item @emph{Arguments}:
838 @multitable @columnfractions .15 .70
839 @item @var{SECONDS} @tab The type of the argument shall be a scalar
840 @code{INTEGER}. It is @code{INTENT(IN)}.
841 @item @var{HANDLER} @tab Signal handler (@code{INTEGER FUNCTION} or
842 @code{SUBROUTINE}) or dummy/global @code{INTEGER} scalar. The scalar
843 values may be either @code{SIG_IGN=1} to ignore the alarm generated
844 or @code{SIG_DFL=0} to set the default action. It is @code{INTENT(IN)}.
845 @item @var{STATUS} @tab (Optional) @var{STATUS} shall be a scalar
846 variable of the default @code{INTEGER} kind. It is @code{INTENT(OUT)}.
849 @item @emph{Example}:
852 external handler_print
854 call alarm (3, handler_print, i)
857 end program test_alarm
859 This will cause the external routine @var{handler_print} to be called
866 @section @code{ALL} --- All values in @var{MASK} along @var{DIM} are true
868 @cindex array, apply condition
869 @cindex array, condition testing
872 @item @emph{Description}:
873 @code{ALL(MASK [, DIM])} determines if all the values are true in @var{MASK}
874 in the array along dimension @var{DIM}.
876 @item @emph{Standard}:
880 Transformational function
883 @code{RESULT = ALL(MASK [, DIM])}
885 @item @emph{Arguments}:
886 @multitable @columnfractions .15 .70
887 @item @var{MASK} @tab The type of the argument shall be @code{LOGICAL(*)} and
888 it shall not be scalar.
889 @item @var{DIM} @tab (Optional) @var{DIM} shall be a scalar integer
890 with a value that lies between one and the rank of @var{MASK}.
893 @item @emph{Return value}:
894 @code{ALL(MASK)} returns a scalar value of type @code{LOGICAL(*)} where
895 the kind type parameter is the same as the kind type parameter of
896 @var{MASK}. If @var{DIM} is present, then @code{ALL(MASK, DIM)} returns
897 an array with the rank of @var{MASK} minus 1. The shape is determined from
898 the shape of @var{MASK} where the @var{DIM} dimension is elided.
902 @code{ALL(MASK)} is true if all elements of @var{MASK} are true.
903 It also is true if @var{MASK} has zero size; otherwise, it is false.
905 If the rank of @var{MASK} is one, then @code{ALL(MASK,DIM)} is equivalent
906 to @code{ALL(MASK)}. If the rank is greater than one, then @code{ALL(MASK,DIM)}
907 is determined by applying @code{ALL} to the array sections.
910 @item @emph{Example}:
914 l = all((/.true., .true., .true./))
919 integer a(2,3), b(2,3)
923 print *, all(a .eq. b, 1)
924 print *, all(a .eq. b, 2)
925 end subroutine section
933 @section @code{ALLOCATED} --- Status of an allocatable entity
935 @cindex allocation, status
938 @item @emph{Description}:
939 @code{ALLOCATED(X)} checks the status of whether @var{X} is allocated.
941 @item @emph{Standard}:
948 @code{RESULT = ALLOCATED(X)}
950 @item @emph{Arguments}:
951 @multitable @columnfractions .15 .70
952 @item @var{X} @tab The argument shall be an @code{ALLOCATABLE} array.
955 @item @emph{Return value}:
956 The return value is a scalar @code{LOGICAL} with the default logical
957 kind type parameter. If @var{X} is allocated, @code{ALLOCATED(X)}
958 is @code{.TRUE.}; otherwise, it returns the @code{.TRUE.}
960 @item @emph{Example}:
962 program test_allocated
964 real(4), allocatable :: x(:)
965 if (allocated(x) .eqv. .false.) allocate(x(i))
966 end program test_allocated
973 @section @code{AND} --- Bitwise logical AND
975 @cindex bitwise logical and
976 @cindex logical and, bitwise
979 @item @emph{Description}:
980 Bitwise logical @code{AND}.
982 This intrinsic routine is provided for backwards compatibility with
983 GNU Fortran 77. For integer arguments, programmers should consider
984 the use of the @ref{IAND} intrinsic defined by the Fortran standard.
986 @item @emph{Standard}:
993 @code{RESULT = AND(I, J)}
995 @item @emph{Arguments}:
996 @multitable @columnfractions .15 .70
997 @item @var{I} @tab The type shall be either @code{INTEGER(*)} or @code{LOGICAL}.
998 @item @var{J} @tab The type shall be either @code{INTEGER(*)} or @code{LOGICAL}.
1001 @item @emph{Return value}:
1002 The return type is either @code{INTEGER(*)} or @code{LOGICAL} after
1003 cross-promotion of the arguments.
1005 @item @emph{Example}:
1008 LOGICAL :: T = .TRUE., F = .FALSE.
1010 DATA a / Z'F' /, b / Z'3' /
1012 WRITE (*,*) AND(T, T), AND(T, F), AND(F, T), AND(F, F)
1013 WRITE (*,*) AND(a, b)
1017 @item @emph{See also}:
1018 F95 elemental function: @ref{IAND}
1024 @section @code{ANINT} --- Nearest whole number
1028 @cindex rounding, ceiling
1031 @item @emph{Description}:
1032 @code{ANINT(X [, KIND])} rounds its argument to the nearest whole number.
1034 @item @emph{Standard}:
1040 @item @emph{Syntax}:
1041 @code{RESULT = ANINT(X [, KIND])}
1043 @item @emph{Arguments}:
1044 @multitable @columnfractions .15 .70
1045 @item @var{X} @tab The type of the argument shall be @code{REAL(*)}.
1046 @item @var{KIND} @tab (Optional) An @code{INTEGER(*)} initialization
1047 expression indicating the kind parameter of
1051 @item @emph{Return value}:
1052 The return value is of type real with the kind type parameter of the
1053 argument if the optional @var{KIND} is absent; otherwise, the kind
1054 type parameter will be given by @var{KIND}. If @var{X} is greater than
1055 zero, then @code{ANINT(X)} returns @code{AINT(X+0.5)}. If @var{X} is
1056 less than or equal to zero, then it returns @code{AINT(X-0.5)}.
1058 @item @emph{Example}:
1065 print *, anint(x4), dnint(x8)
1067 end program test_anint
1070 @item @emph{Specific names}:
1071 @multitable @columnfractions .20 .20 .20 .25
1072 @item Name @tab Argument @tab Return type @tab Standard
1073 @item @code{DNINT(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F77 and later
1080 @section @code{ANY} --- Any value in @var{MASK} along @var{DIM} is true
1082 @cindex array, apply condition
1083 @cindex array, condition testing
1086 @item @emph{Description}:
1087 @code{ANY(MASK [, DIM])} determines if any of the values in the logical array
1088 @var{MASK} along dimension @var{DIM} are @code{.TRUE.}.
1090 @item @emph{Standard}:
1094 Transformational function
1096 @item @emph{Syntax}:
1097 @code{RESULT = ANY(MASK [, DIM])}
1099 @item @emph{Arguments}:
1100 @multitable @columnfractions .15 .70
1101 @item @var{MASK} @tab The type of the argument shall be @code{LOGICAL(*)} and
1102 it shall not be scalar.
1103 @item @var{DIM} @tab (Optional) @var{DIM} shall be a scalar integer
1104 with a value that lies between one and the rank of @var{MASK}.
1107 @item @emph{Return value}:
1108 @code{ANY(MASK)} returns a scalar value of type @code{LOGICAL(*)} where
1109 the kind type parameter is the same as the kind type parameter of
1110 @var{MASK}. If @var{DIM} is present, then @code{ANY(MASK, DIM)} returns
1111 an array with the rank of @var{MASK} minus 1. The shape is determined from
1112 the shape of @var{MASK} where the @var{DIM} dimension is elided.
1116 @code{ANY(MASK)} is true if any element of @var{MASK} is true;
1117 otherwise, it is false. It also is false if @var{MASK} has zero size.
1119 If the rank of @var{MASK} is one, then @code{ANY(MASK,DIM)} is equivalent
1120 to @code{ANY(MASK)}. If the rank is greater than one, then @code{ANY(MASK,DIM)}
1121 is determined by applying @code{ANY} to the array sections.
1124 @item @emph{Example}:
1128 l = any((/.true., .true., .true./))
1133 integer a(2,3), b(2,3)
1137 print *, any(a .eq. b, 1)
1138 print *, any(a .eq. b, 2)
1139 end subroutine section
1140 end program test_any
1147 @section @code{ASIN} --- Arcsine function
1150 @cindex trigonometric function, sine, inverse
1151 @cindex sine, inverse
1154 @item @emph{Description}:
1155 @code{ASIN(X)} computes the arcsine of its @var{X} (inverse of @code{SIN(X)}).
1157 @item @emph{Standard}:
1163 @item @emph{Syntax}:
1164 @code{RESULT = ASIN(X)}
1166 @item @emph{Arguments}:
1167 @multitable @columnfractions .15 .70
1168 @item @var{X} @tab The type shall be @code{REAL(*)}, and a magnitude that is
1172 @item @emph{Return value}:
1173 The return value is of type @code{REAL(*)} and it lies in the
1174 range @math{-\pi / 2 \leq \asin (x) \leq \pi / 2}. The kind type
1175 parameter is the same as @var{X}.
1177 @item @emph{Example}:
1180 real(8) :: x = 0.866_8
1182 end program test_asin
1185 @item @emph{Specific names}:
1186 @multitable @columnfractions .20 .20 .20 .25
1187 @item Name @tab Argument @tab Return type @tab Standard
1188 @item @code{DASIN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F77 and later
1191 @item @emph{See also}:
1192 Inverse function: @ref{SIN}
1199 @section @code{ASINH} --- Hyperbolic arcsine function
1202 @cindex area hyperbolic sine
1203 @cindex hyperbolic arcsine
1204 @cindex hyperbolic function, sine, inverse
1205 @cindex sine, hyperbolic, inverse
1208 @item @emph{Description}:
1209 @code{ASINH(X)} computes the hyperbolic arcsine of @var{X} (inverse of @code{SINH(X)}).
1211 @item @emph{Standard}:
1217 @item @emph{Syntax}:
1218 @code{RESULT = ASINH(X)}
1220 @item @emph{Arguments}:
1221 @multitable @columnfractions .15 .70
1222 @item @var{X} @tab The type shall be @code{REAL(*)}, with @var{X} a real number.
1225 @item @emph{Return value}:
1226 The return value is of type @code{REAL(*)} and it lies in the
1227 range @math{-\infty \leq \asinh (x) \leq \infty}.
1229 @item @emph{Example}:
1232 REAL(8), DIMENSION(3) :: x = (/ -1.0, 0.0, 1.0 /)
1233 WRITE (*,*) ASINH(x)
1237 @item @emph{Specific names}:
1238 @multitable @columnfractions .20 .20 .20 .25
1239 @item Name @tab Argument @tab Return type @tab Standard
1240 @item @code{DASINH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension.
1243 @item @emph{See also}:
1244 Inverse function: @ref{SINH}
1250 @section @code{ASSOCIATED} --- Status of a pointer or pointer/target pair
1252 @cindex pointer, status
1253 @cindex association status
1256 @item @emph{Description}:
1257 @code{ASSOCIATED(PTR [, TGT])} determines the status of the pointer @var{PTR}
1258 or if @var{PTR} is associated with the target @var{TGT}.
1260 @item @emph{Standard}:
1266 @item @emph{Syntax}:
1267 @code{RESULT = ASSOCIATED(PTR [, TGT])}
1269 @item @emph{Arguments}:
1270 @multitable @columnfractions .15 .70
1271 @item @var{PTR} @tab @var{PTR} shall have the @code{POINTER} attribute and
1272 it can be of any type.
1273 @item @var{TGT} @tab (Optional) @var{TGT} shall be a @code{POINTER} or
1274 a @code{TARGET}. It must have the same type, kind type parameter, and
1275 array rank as @var{PTR}.
1277 The status of neither @var{PTR} nor @var{TGT} can be undefined.
1279 @item @emph{Return value}:
1280 @code{ASSOCIATED(PTR)} returns a scalar value of type @code{LOGICAL(4)}.
1281 There are several cases:
1283 @item (A) If the optional @var{TGT} is not present, then @code{ASSOCIATED(PTR)}
1284 is true if @var{PTR} is associated with a target; otherwise, it returns false.
1285 @item (B) If @var{TGT} is present and a scalar target, the result is true if
1287 is not a 0 sized storage sequence and the target associated with @var{PTR}
1288 occupies the same storage units. If @var{PTR} is disassociated, then the
1290 @item (C) If @var{TGT} is present and an array target, the result is true if
1291 @var{TGT} and @var{PTR} have the same shape, are not 0 sized arrays, are
1292 arrays whose elements are not 0 sized storage sequences, and @var{TGT} and
1293 @var{PTR} occupy the same storage units in array element order.
1294 As in case(B), the result is false, if @var{PTR} is disassociated.
1295 @item (D) If @var{TGT} is present and an scalar pointer, the result is true if
1296 target associated with @var{PTR} and the target associated with @var{TGT}
1297 are not 0 sized storage sequences and occupy the same storage units.
1298 The result is false, if either @var{TGT} or @var{PTR} is disassociated.
1299 @item (E) If @var{TGT} is present and an array pointer, the result is true if
1300 target associated with @var{PTR} and the target associated with @var{TGT}
1301 have the same shape, are not 0 sized arrays, are arrays whose elements are
1302 not 0 sized storage sequences, and @var{TGT} and @var{PTR} occupy the same
1303 storage units in array element order.
1304 The result is false, if either @var{TGT} or @var{PTR} is disassociated.
1307 @item @emph{Example}:
1309 program test_associated
1311 real, target :: tgt(2) = (/1., 2./)
1312 real, pointer :: ptr(:)
1314 if (associated(ptr) .eqv. .false.) call abort
1315 if (associated(ptr,tgt) .eqv. .false.) call abort
1316 end program test_associated
1319 @item @emph{See also}:
1326 @section @code{ATAN} --- Arctangent function
1329 @cindex trigonometric function, tangent, inverse
1330 @cindex tangent, inverse
1333 @item @emph{Description}:
1334 @code{ATAN(X)} computes the arctangent of @var{X}.
1336 @item @emph{Standard}:
1342 @item @emph{Syntax}:
1343 @code{RESULT = ATAN(X)}
1345 @item @emph{Arguments}:
1346 @multitable @columnfractions .15 .70
1347 @item @var{X} @tab The type shall be @code{REAL(*)}.
1350 @item @emph{Return value}:
1351 The return value is of type @code{REAL(*)} and it lies in the
1352 range @math{ - \pi / 2 \leq \atan (x) \leq \pi / 2}.
1354 @item @emph{Example}:
1357 real(8) :: x = 2.866_8
1359 end program test_atan
1362 @item @emph{Specific names}:
1363 @multitable @columnfractions .20 .20 .20 .25
1364 @item Name @tab Argument @tab Return type @tab Standard
1365 @item @code{DATAN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F77 and later
1368 @item @emph{See also}:
1369 Inverse function: @ref{TAN}
1376 @section @code{ATAN2} --- Arctangent function
1379 @cindex trigonometric function, tangent, inverse
1380 @cindex tangent, inverse
1383 @item @emph{Description}:
1384 @code{ATAN2(Y,X)} computes the arctangent of the complex number
1387 @item @emph{Standard}:
1393 @item @emph{Syntax}:
1394 @code{RESULT = ATAN2(Y,X)}
1396 @item @emph{Arguments}:
1397 @multitable @columnfractions .15 .70
1398 @item @var{Y} @tab The type shall be @code{REAL(*)}.
1399 @item @var{X} @tab The type and kind type parameter shall be the same as @var{Y}.
1400 If @var{Y} is zero, then @var{X} must be nonzero.
1403 @item @emph{Return value}:
1404 The return value has the same type and kind type parameter as @var{Y}.
1405 It is the principal value of the complex number @math{X + i Y}. If
1406 @var{X} is nonzero, then it lies in the range @math{-\pi \le \atan (x) \leq \pi}.
1407 The sign is positive if @var{Y} is positive. If @var{Y} is zero, then
1408 the return value is zero if @var{X} is positive and @math{\pi} if @var{X}
1409 is negative. Finally, if @var{X} is zero, then the magnitude of the result
1412 @item @emph{Example}:
1415 real(4) :: x = 1.e0_4, y = 0.5e0_4
1417 end program test_atan2
1420 @item @emph{Specific names}:
1421 @multitable @columnfractions .20 .20 .20 .25
1422 @item Name @tab Argument @tab Return type @tab Standard
1423 @item @code{DATAN2(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F77 and later
1430 @section @code{ATANH} --- Hyperbolic arctangent function
1433 @cindex area hyperbolic tangent
1434 @cindex hyperbolic arctangent
1435 @cindex hyperbolic function, tangent, inverse
1436 @cindex tangent, hyperbolic, inverse
1439 @item @emph{Description}:
1440 @code{ATANH(X)} computes the hyperbolic arctangent of @var{X} (inverse
1443 @item @emph{Standard}:
1449 @item @emph{Syntax}:
1450 @code{RESULT = ATANH(X)}
1452 @item @emph{Arguments}:
1453 @multitable @columnfractions .15 .70
1454 @item @var{X} @tab The type shall be @code{REAL(*)} with a magnitude
1455 that is less than or equal to one.
1458 @item @emph{Return value}:
1459 The return value is of type @code{REAL(*)} and it lies in the
1460 range @math{-\infty \leq \atanh(x) \leq \infty}.
1462 @item @emph{Example}:
1465 REAL, DIMENSION(3) :: x = (/ -1.0, 0.0, 1.0 /)
1466 WRITE (*,*) ATANH(x)
1470 @item @emph{Specific names}:
1471 @multitable @columnfractions .20 .20 .20 .25
1472 @item Name @tab Argument @tab Return type @tab Standard
1473 @item @code{DATANH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1476 @item @emph{See also}:
1477 Inverse function: @ref{TANH}
1483 @section @code{BESJ0} --- Bessel function of the first kind of order 0
1486 @cindex Bessel function, first kind
1489 @item @emph{Description}:
1490 @code{BESJ0(X)} computes the Bessel function of the first kind of order 0
1493 @item @emph{Standard}:
1499 @item @emph{Syntax}:
1500 @code{RESULT = BESJ0(X)}
1502 @item @emph{Arguments}:
1503 @multitable @columnfractions .15 .70
1504 @item @var{X} @tab The type shall be @code{REAL(*)}, and it shall be scalar.
1507 @item @emph{Return value}:
1508 The return value is of type @code{REAL(*)} and it lies in the
1509 range @math{ - 0.4027... \leq Bessel (0,x) \leq 1}.
1511 @item @emph{Example}:
1514 real(8) :: x = 0.0_8
1516 end program test_besj0
1519 @item @emph{Specific names}:
1520 @multitable @columnfractions .20 .20 .20 .25
1521 @item Name @tab Argument @tab Return type @tab Standard
1522 @item @code{DBESJ0(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1529 @section @code{BESJ1} --- Bessel function of the first kind of order 1
1532 @cindex Bessel function, first kind
1535 @item @emph{Description}:
1536 @code{BESJ1(X)} computes the Bessel function of the first kind of order 1
1539 @item @emph{Standard}:
1545 @item @emph{Syntax}:
1546 @code{RESULT = BESJ1(X)}
1548 @item @emph{Arguments}:
1549 @multitable @columnfractions .15 .70
1550 @item @var{X} @tab The type shall be @code{REAL(*)}, and it shall be scalar.
1553 @item @emph{Return value}:
1554 The return value is of type @code{REAL(*)} and it lies in the
1555 range @math{ - 0.5818... \leq Bessel (0,x) \leq 0.5818 }.
1557 @item @emph{Example}:
1560 real(8) :: x = 1.0_8
1562 end program test_besj1
1565 @item @emph{Specific names}:
1566 @multitable @columnfractions .20 .20 .20 .25
1567 @item Name @tab Argument @tab Return type @tab Standard
1568 @item @code{DBESJ1(X)}@tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1575 @section @code{BESJN} --- Bessel function of the first kind
1578 @cindex Bessel function, first kind
1581 @item @emph{Description}:
1582 @code{BESJN(N, X)} computes the Bessel function of the first kind of order
1585 If both arguments are arrays, their ranks and shapes shall conform.
1587 @item @emph{Standard}:
1593 @item @emph{Syntax}:
1594 @code{RESULT = BESJN(N, X)}
1596 @item @emph{Arguments}:
1597 @multitable @columnfractions .15 .70
1598 @item @var{N} @tab Shall be a scalar or an array of type @code{INTEGER(*)}.
1599 @item @var{X} @tab Shall be a scalar or an array of type @code{REAL(*)}.
1602 @item @emph{Return value}:
1603 The return value is a scalar of type @code{REAL(*)}.
1605 @item @emph{Example}:
1608 real(8) :: x = 1.0_8
1610 end program test_besjn
1613 @item @emph{Specific names}:
1614 @multitable @columnfractions .20 .20 .20 .25
1615 @item Name @tab Argument @tab Return type @tab Standard
1616 @item @code{DBESJN(X)} @tab @code{INTEGER(*) N} @tab @code{REAL(8)} @tab GNU extension
1617 @item @tab @code{REAL(8) X} @tab @tab
1624 @section @code{BESY0} --- Bessel function of the second kind of order 0
1627 @cindex Bessel function, second kind
1630 @item @emph{Description}:
1631 @code{BESY0(X)} computes the Bessel function of the second kind of order 0
1634 @item @emph{Standard}:
1640 @item @emph{Syntax}:
1641 @code{RESULT = BESY0(X)}
1643 @item @emph{Arguments}:
1644 @multitable @columnfractions .15 .70
1645 @item @var{X} @tab The type shall be @code{REAL(*)}, and it shall be scalar.
1648 @item @emph{Return value}:
1649 The return value is a scalar of type @code{REAL(*)}.
1651 @item @emph{Example}:
1654 real(8) :: x = 0.0_8
1656 end program test_besy0
1659 @item @emph{Specific names}:
1660 @multitable @columnfractions .20 .20 .20 .25
1661 @item Name @tab Argument @tab Return type @tab Standard
1662 @item @code{DBESY0(X)}@tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1669 @section @code{BESY1} --- Bessel function of the second kind of order 1
1672 @cindex Bessel function, second kind
1675 @item @emph{Description}:
1676 @code{BESY1(X)} computes the Bessel function of the second kind of order 1
1679 @item @emph{Standard}:
1685 @item @emph{Syntax}:
1686 @code{RESULT = BESY1(X)}
1688 @item @emph{Arguments}:
1689 @multitable @columnfractions .15 .70
1690 @item @var{X} @tab The type shall be @code{REAL(*)}, and it shall be scalar.
1693 @item @emph{Return value}:
1694 The return value is a scalar of type @code{REAL(*)}.
1696 @item @emph{Example}:
1699 real(8) :: x = 1.0_8
1701 end program test_besy1
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{DBESY1(X)}@tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
1714 @section @code{BESYN} --- Bessel function of the second kind
1717 @cindex Bessel function, second kind
1720 @item @emph{Description}:
1721 @code{BESYN(N, X)} computes the Bessel function of the second kind of order
1724 If both arguments are arrays, their ranks and shapes shall conform.
1726 @item @emph{Standard}:
1732 @item @emph{Syntax}:
1733 @code{RESULT = BESYN(N, X)}
1735 @item @emph{Arguments}:
1736 @multitable @columnfractions .15 .70
1737 @item @var{N} @tab Shall be a scalar or an array of type @code{INTEGER(*)}.
1738 @item @var{X} @tab Shall be a scalar or an array of type @code{REAL(*)}.
1741 @item @emph{Return value}:
1742 The return value is a scalar of type @code{REAL(*)}.
1744 @item @emph{Example}:
1747 real(8) :: x = 1.0_8
1749 end program test_besyn
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{DBESYN(N,X)} @tab @code{INTEGER(*) N} @tab @code{REAL(8)} @tab GNU extension
1756 @item @tab @code{REAL(8) X} @tab @tab
1763 @section @code{BIT_SIZE} --- Bit size inquiry function
1765 @cindex bits, number of
1766 @cindex size of a variable, in bits
1769 @item @emph{Description}:
1770 @code{BIT_SIZE(I)} returns the number of bits (integer precision plus sign bit)
1771 represented by the type of @var{I}.
1773 @item @emph{Standard}:
1779 @item @emph{Syntax}:
1780 @code{RESULT = BIT_SIZE(I)}
1782 @item @emph{Arguments}:
1783 @multitable @columnfractions .15 .70
1784 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
1787 @item @emph{Return value}:
1788 The return value is of type @code{INTEGER(*)}
1790 @item @emph{Example}:
1792 program test_bit_size
1797 end program test_bit_size
1804 @section @code{BTEST} --- Bit test function
1806 @cindex bits, testing
1809 @item @emph{Description}:
1810 @code{BTEST(I,POS)} returns logical @code{.TRUE.} if the bit at @var{POS}
1813 @item @emph{Standard}:
1819 @item @emph{Syntax}:
1820 @code{RESULT = BTEST(I, POS)}
1822 @item @emph{Arguments}:
1823 @multitable @columnfractions .15 .70
1824 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
1825 @item @var{POS} @tab The type shall be @code{INTEGER(*)}.
1828 @item @emph{Return value}:
1829 The return value is of type @code{LOGICAL}
1831 @item @emph{Example}:
1834 integer :: i = 32768 + 1024 + 64
1838 bool = btest(i, pos)
1841 end program test_btest
1847 @section @code{C_ASSOCIATED} --- Status of a C pointer
1848 @fnindex C_ASSOCIATED
1849 @cindex association status, C pointer
1850 @cindex pointer, C association status
1853 @item @emph{Description}:
1854 @code{C_ASSOICATED(c_prt1[, c_ptr2])} determines the status of the C pointer @var{c_ptr1}
1855 or if @var{c_ptr1} is associated with the target @var{c_ptr2}.
1857 @item @emph{Standard}:
1863 @item @emph{Syntax}:
1864 @code{RESULT = C_ASSOICATED(c_prt1[, c_ptr2])}
1866 @item @emph{Arguments}:
1867 @multitable @columnfractions .15 .70
1868 @item @var{c_ptr1} @tab Scalar of the type @code{C_PTR} or @code{C_FUNPTR}.
1869 @item @var{c_ptr2} @tab (Optional) Scalar of the same type as @var{c_ptr1}.
1872 @item @emph{Return value}:
1873 The return value is of type @code{LOGICAL}; it is @code{.false.} if either
1874 @var{c_ptr1} is a C NULL pointer or if @var{c_ptr1} and @var{c_ptr2}
1875 point to different addresses.
1877 @item @emph{Example}:
1879 subroutine association_test(a,b)
1880 use iso_c_binding, only: c_associated, c_loc, c_ptr
1884 if(c_associated(b, c_loc(a))) &
1885 stop 'b and a do not point to same target'
1886 end subroutine association_test
1889 @item @emph{See also}:
1890 @ref{C_LOC}, @ref{C_FUNLOC}
1895 @section @code{C_FUNLOC} --- Obtain the C address of a procedure
1897 @cindex pointer, C address of procedures
1900 @item @emph{Description}:
1901 @code{C_FUNLOC(x)} determines the C address of the argument.
1903 @item @emph{Standard}:
1909 @item @emph{Syntax}:
1910 @code{RESULT = C_FUNLOC(x)}
1912 @item @emph{Arguments}:
1913 @multitable @columnfractions .15 .70
1914 @item @var{x} @tab Interoperable function or pointer to such function.
1917 @item @emph{Return value}:
1918 The return value is of type @code{C_FUNPTR} and contains the C address
1921 @item @emph{Example}:
1927 subroutine sub(a) bind(c)
1937 subroutine my_routine(p) bind(c,name='myC_func')
1939 type(c_funptr), intent(in) :: p
1942 call my_routine(c_funloc(sub))
1946 @item @emph{See also}:
1947 @ref{C_ASSOCIATED}, @ref{C_LOC}, @ref{C_F_POINTER}, @ref{C_F_PROCPOINTER}
1951 @node C_F_PROCPOINTER
1952 @section @code{C_F_PROCPOINTER} --- Convert C into Fortran procedure pointer
1953 @fnindex C_F_PROCPOINTER
1954 @cindex pointer, C address of pointers
1957 @item @emph{Description}:
1958 @code{C_F_PROCPOINTER(cptr, fptr)} Assign the target of the C function pointer
1959 @var{cptr} to the Fortran procedure pointer @var{fptr}.
1961 Note: Due to the currently lacking support of procedure pointers in GNU Fortran
1962 this function is not fully operable.
1964 @item @emph{Standard}:
1970 @item @emph{Syntax}:
1971 @code{CALL C_F_PROCPOINTER(cptr, fptr)}
1973 @item @emph{Arguments}:
1974 @multitable @columnfractions .15 .70
1975 @item @var{cptr} @tab scalar of the type @code{C_FUNPTR}. It is
1977 @item @var{fptr} @tab procedure pointer interoperable with @var{cptr}. It is
1981 @item @emph{Example}:
1989 real(c_float), intent(in) :: a
1990 real(c_float) :: func
1994 function getIterFunc() bind(c,name="getIterFunc")
1996 type(c_funptr) :: getIterFunc
1999 type(c_funptr) :: cfunptr
2000 procedure(func), pointer :: myFunc
2001 cfunptr = getIterFunc()
2002 call c_f_procpointer(cfunptr, myFunc)
2006 @item @emph{See also}:
2007 @ref{C_LOC}, @ref{C_F_POINTER}
2012 @section @code{C_F_POINTER} --- Convert C into Fortran pointer
2013 @fnindex C_F_POINTER
2014 @cindex pointer, convert C to Fortran
2017 @item @emph{Description}:
2018 @code{C_F_POINTER(cptr, fptr[, shape])} Assign the target the C pointer
2019 @var{cptr} to the Fortran pointer @var{fptr} and specify its
2022 @item @emph{Standard}:
2028 @item @emph{Syntax}:
2029 @code{CALL C_F_POINTER(cptr, fptr[, shape])}
2031 @item @emph{Arguments}:
2032 @multitable @columnfractions .15 .70
2033 @item @var{cptr} @tab scalar of the type @code{C_PTR}. It is
2035 @item @var{fptr} @tab pointer interoperable with @var{cptr}. It is
2037 @item @var{shape} @tab (Optional) Rank-one array of type @code{INTEGER}
2038 with @code{INTENT(IN)}. It shall be present
2039 if and only if @var{fptr} is an array. The size
2040 must be equal to the rank of @var{fptr}.
2043 @item @emph{Example}:
2049 subroutine my_routine(p) bind(c,name='myC_func')
2051 type(c_ptr), intent(out) :: p
2055 real,pointer :: a(:)
2056 call my_routine(cptr)
2057 call c_f_pointer(cptr, a, [12])
2061 @item @emph{See also}:
2062 @ref{C_LOC}, @ref{C_F_PROCPOINTER}
2067 @section @code{C_LOC} --- Obtain the C address of an object
2069 @cindex procedure pointer, convert C to Fortran
2072 @item @emph{Description}:
2073 @code{C_LOC(x)} determines the C address of the argument.
2075 @item @emph{Standard}:
2081 @item @emph{Syntax}:
2082 @code{RESULT = C_LOC(x)}
2084 @item @emph{Arguments}:
2085 @multitable @columnfractions .15 .70
2086 @item @var{x} @tab Associated scalar pointer or interoperable scalar
2087 or allocated allocatable variable with @code{TARGET}
2091 @item @emph{Return value}:
2092 The return value is of type @code{C_PTR} and contains the C address
2095 @item @emph{Example}:
2097 subroutine association_test(a,b)
2098 use iso_c_binding, only: c_associated, c_loc, c_ptr
2102 if(c_associated(b, c_loc(a))) &
2103 stop 'b and a do not point to same target'
2104 end subroutine association_test
2107 @item @emph{See also}:
2108 @ref{C_ASSOCIATED}, @ref{C_FUNLOC}, @ref{C_F_POINTER}, @ref{C_F_PROCPOINTER}
2113 @section @code{CEILING} --- Integer ceiling function
2116 @cindex rounding, ceiling
2119 @item @emph{Description}:
2120 @code{CEILING(X)} returns the least integer greater than or equal to @var{X}.
2122 @item @emph{Standard}:
2128 @item @emph{Syntax}:
2129 @code{RESULT = CEILING(X [, KIND])}
2131 @item @emph{Arguments}:
2132 @multitable @columnfractions .15 .70
2133 @item @var{X} @tab The type shall be @code{REAL(*)}.
2134 @item @var{KIND} @tab (Optional) An @code{INTEGER(*)} initialization
2135 expression indicating the kind parameter of
2139 @item @emph{Return value}:
2140 The return value is of type @code{INTEGER(KIND)}
2142 @item @emph{Example}:
2144 program test_ceiling
2147 print *, ceiling(x) ! returns 64
2148 print *, ceiling(y) ! returns -63
2149 end program test_ceiling
2152 @item @emph{See also}:
2153 @ref{FLOOR}, @ref{NINT}
2160 @section @code{CHAR} --- Character conversion function
2162 @cindex conversion, to character
2165 @item @emph{Description}:
2166 @code{CHAR(I [, KIND])} returns the character represented by the integer @var{I}.
2168 @item @emph{Standard}:
2174 @item @emph{Syntax}:
2175 @code{RESULT = CHAR(I [, KIND])}
2177 @item @emph{Arguments}:
2178 @multitable @columnfractions .15 .70
2179 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
2180 @item @var{KIND} @tab (Optional) An @code{INTEGER(*)} initialization
2181 expression indicating the kind parameter of
2185 @item @emph{Return value}:
2186 The return value is of type @code{CHARACTER(1)}
2188 @item @emph{Example}:
2194 print *, i, c ! returns 'J'
2195 end program test_char
2199 See @ref{ICHAR} for a discussion of converting between numerical values
2200 and formatted string representations.
2202 @item @emph{See also}:
2203 @ref{ACHAR}, @ref{IACHAR}, @ref{ICHAR}
2210 @section @code{CHDIR} --- Change working directory
2212 @cindex system, working directory
2215 @item @emph{Description}:
2216 Change current working directory to a specified path.
2218 This intrinsic is provided in both subroutine and function forms; however,
2219 only one form can be used in any given program unit.
2221 @item @emph{Standard}:
2225 Subroutine, function
2227 @item @emph{Syntax}:
2228 @multitable @columnfractions .80
2229 @item @code{CALL CHDIR(NAME [, STATUS])}
2230 @item @code{STATUS = CHDIR(NAME)}
2233 @item @emph{Arguments}:
2234 @multitable @columnfractions .15 .70
2235 @item @var{NAME} @tab The type shall be @code{CHARACTER(*)} and shall
2236 specify a valid path within the file system.
2237 @item @var{STATUS} @tab (Optional) @code{INTEGER} status flag of the default
2238 kind. Returns 0 on success, and a system specific
2239 and nonzero error code otherwise.
2242 @item @emph{Example}:
2245 CHARACTER(len=255) :: path
2247 WRITE(*,*) TRIM(path)
2250 WRITE(*,*) TRIM(path)
2254 @item @emph{See also}:
2261 @section @code{CHMOD} --- Change access permissions of files
2263 @cindex file system, change access mode
2266 @item @emph{Description}:
2267 @code{CHMOD} changes the permissions of a file. This function invokes
2268 @code{/bin/chmod} and might therefore not work on all platforms.
2270 This intrinsic is provided in both subroutine and function forms; however,
2271 only one form can be used in any given program unit.
2273 @item @emph{Standard}:
2277 Subroutine, function
2279 @item @emph{Syntax}:
2280 @multitable @columnfractions .80
2281 @item @code{CALL CHMOD(NAME, MODE[, STATUS])}
2282 @item @code{STATUS = CHMOD(NAME, MODE)}
2285 @item @emph{Arguments}:
2286 @multitable @columnfractions .15 .70
2287 @item @var{NAME} @tab Scalar @code{CHARACTER} with the file name.
2288 Trailing blanks are ignored unless the character @code{achar(0)} is
2289 present, then all characters up to and excluding @code{achar(0)} are
2290 used as the file name.
2292 @item @var{MODE} @tab Scalar @code{CHARACTER} giving the file permission.
2293 @var{MODE} uses the same syntax as the @var{MODE} argument of
2296 @item @var{STATUS} @tab (optional) scalar @code{INTEGER}, which is
2297 @code{0} on success and nonzero otherwise.
2300 @item @emph{Return value}:
2301 In either syntax, @var{STATUS} is set to @code{0} on success and nonzero
2304 @item @emph{Example}:
2305 @code{CHMOD} as subroutine
2310 call chmod('test.dat','u+x',status)
2311 print *, 'Status: ', status
2312 end program chmod_test
2314 @code{CHMOD} as function:
2319 status = chmod('test.dat','u+x')
2320 print *, 'Status: ', status
2321 end program chmod_test
2329 @section @code{CMPLX} --- Complex conversion function
2331 @cindex complex numbers, conversion to
2332 @cindex conversion, to complex
2335 @item @emph{Description}:
2336 @code{CMPLX(X [, Y [, KIND]])} returns a complex number where @var{X} is converted to
2337 the real component. If @var{Y} is present it is converted to the imaginary
2338 component. If @var{Y} is not present then the imaginary component is set to
2339 0.0. If @var{X} is complex then @var{Y} must not be present.
2341 @item @emph{Standard}:
2347 @item @emph{Syntax}:
2348 @code{RESULT = CMPLX(X [, Y [, KIND]])}
2350 @item @emph{Arguments}:
2351 @multitable @columnfractions .15 .70
2352 @item @var{X} @tab The type may be @code{INTEGER(*)}, @code{REAL(*)},
2353 or @code{COMPLEX(*)}.
2354 @item @var{Y} @tab (Optional; only allowed if @var{X} is not
2355 @code{COMPLEX(*)}.) May be @code{INTEGER(*)}
2357 @item @var{KIND} @tab (Optional) An @code{INTEGER(*)} initialization
2358 expression indicating the kind parameter of
2362 @item @emph{Return value}:
2363 The return value is of @code{COMPLEX} type, with a kind equal to
2364 @var{KIND} if it is specified. If @var{KIND} is not specified, the
2365 result is of the default @code{COMPLEX} kind, regardless of the kinds of
2366 @var{X} and @var{Y}.
2368 @item @emph{Example}:
2375 print *, z, cmplx(x)
2376 end program test_cmplx
2379 @item @emph{See also}:
2385 @node COMMAND_ARGUMENT_COUNT
2386 @section @code{COMMAND_ARGUMENT_COUNT} --- Get number of command line arguments
2387 @fnindex COMMAND_ARGUMENT_COUNT
2388 @cindex command-line arguments
2389 @cindex command-line arguments, number of
2390 @cindex arguments, to program
2393 @item @emph{Description}:
2394 @code{COMMAND_ARGUMENT_COUNT()} returns the number of arguments passed on the
2395 command line when the containing program was invoked.
2397 @item @emph{Standard}:
2403 @item @emph{Syntax}:
2404 @code{RESULT = COMMAND_ARGUMENT_COUNT()}
2406 @item @emph{Arguments}:
2407 @multitable @columnfractions .15 .70
2411 @item @emph{Return value}:
2412 The return value is of type @code{INTEGER(4)}
2414 @item @emph{Example}:
2416 program test_command_argument_count
2418 count = command_argument_count()
2420 end program test_command_argument_count
2423 @item @emph{See also}:
2424 @ref{GET_COMMAND}, @ref{GET_COMMAND_ARGUMENT}
2430 @section @code{COMPLEX} --- Complex conversion function
2432 @cindex complex numbers, conversion to
2433 @cindex conversion, to complex
2436 @item @emph{Description}:
2437 @code{COMPLEX(X, Y)} returns a complex number where @var{X} is converted
2438 to the real component and @var{Y} is converted to the imaginary
2441 @item @emph{Standard}:
2447 @item @emph{Syntax}:
2448 @code{RESULT = COMPLEX(X, Y)}
2450 @item @emph{Arguments}:
2451 @multitable @columnfractions .15 .70
2452 @item @var{X} @tab The type may be @code{INTEGER(*)} or @code{REAL(*)}.
2453 @item @var{Y} @tab The type may be @code{INTEGER(*)} or @code{REAL(*)}.
2456 @item @emph{Return value}:
2457 If @var{X} and @var{Y} are both of @code{INTEGER} type, then the return
2458 value is of default @code{COMPLEX} type.
2460 If @var{X} and @var{Y} are of @code{REAL} type, or one is of @code{REAL}
2461 type and one is of @code{INTEGER} type, then the return value is of
2462 @code{COMPLEX} type with a kind equal to that of the @code{REAL}
2463 argument with the highest precision.
2465 @item @emph{Example}:
2467 program test_complex
2470 print *, complex(i, x)
2471 end program test_complex
2474 @item @emph{See also}:
2481 @section @code{CONJG} --- Complex conjugate function
2484 @cindex complex conjugate
2487 @item @emph{Description}:
2488 @code{CONJG(Z)} returns the conjugate of @var{Z}. If @var{Z} is @code{(x, y)}
2489 then the result is @code{(x, -y)}
2491 @item @emph{Standard}:
2492 F77 and later, has overloads that are GNU extensions
2497 @item @emph{Syntax}:
2500 @item @emph{Arguments}:
2501 @multitable @columnfractions .15 .70
2502 @item @var{Z} @tab The type shall be @code{COMPLEX(*)}.
2505 @item @emph{Return value}:
2506 The return value is of type @code{COMPLEX(*)}.
2508 @item @emph{Example}:
2511 complex :: z = (2.0, 3.0)
2512 complex(8) :: dz = (2.71_8, -3.14_8)
2517 end program test_conjg
2520 @item @emph{Specific names}:
2521 @multitable @columnfractions .20 .20 .20 .25
2522 @item Name @tab Argument @tab Return type @tab Standard
2523 @item @code{DCONJG(Z)} @tab @code{COMPLEX(8) Z} @tab @code{COMPLEX(8)} @tab GNU extension
2530 @section @code{COS} --- Cosine function
2536 @cindex trigonometric function, cosine
2540 @item @emph{Description}:
2541 @code{COS(X)} computes the cosine of @var{X}.
2543 @item @emph{Standard}:
2544 F77 and later, has overloads that are GNU extensions
2549 @item @emph{Syntax}:
2550 @code{RESULT = COS(X)}
2552 @item @emph{Arguments}:
2553 @multitable @columnfractions .15 .70
2554 @item @var{X} @tab The type shall be @code{REAL(*)} or
2558 @item @emph{Return value}:
2559 The return value is of type @code{REAL(*)} and it lies in the
2560 range @math{ -1 \leq \cos (x) \leq 1}. The kind type
2561 parameter is the same as @var{X}.
2563 @item @emph{Example}:
2568 end program test_cos
2571 @item @emph{Specific names}:
2572 @multitable @columnfractions .20 .20 .20 .25
2573 @item Name @tab Argument @tab Return type @tab Standard
2574 @item @code{DCOS(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F77 and later
2575 @item @code{CCOS(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab F77 and later
2576 @item @code{ZCOS(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
2577 @item @code{CDCOS(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
2580 @item @emph{See also}:
2581 Inverse function: @ref{ACOS}
2588 @section @code{COSH} --- Hyperbolic cosine function
2591 @cindex hyperbolic cosine
2592 @cindex hyperbolic function, cosine
2593 @cindex cosine, hyperbolic
2596 @item @emph{Description}:
2597 @code{COSH(X)} computes the hyperbolic cosine of @var{X}.
2599 @item @emph{Standard}:
2605 @item @emph{Syntax}:
2608 @item @emph{Arguments}:
2609 @multitable @columnfractions .15 .70
2610 @item @var{X} @tab The type shall be @code{REAL(*)}.
2613 @item @emph{Return value}:
2614 The return value is of type @code{REAL(*)} and it is positive
2615 (@math{ \cosh (x) \geq 0 }.
2617 @item @emph{Example}:
2620 real(8) :: x = 1.0_8
2622 end program test_cosh
2625 @item @emph{Specific names}:
2626 @multitable @columnfractions .20 .20 .20 .25
2627 @item Name @tab Argument @tab Return type @tab Standard
2628 @item @code{DCOSH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F77 and later
2631 @item @emph{See also}:
2632 Inverse function: @ref{ACOSH}
2639 @section @code{COUNT} --- Count function
2641 @cindex array, conditionally count elements
2642 @cindex array, element counting
2643 @cindex array, number of elements
2646 @item @emph{Description}:
2647 @code{COUNT(MASK [, DIM])} counts the number of @code{.TRUE.} elements of
2648 @var{MASK} along the dimension of @var{DIM}. If @var{DIM} is omitted it is
2649 taken to be @code{1}. @var{DIM} is a scaler of type @code{INTEGER} in the
2650 range of @math{1 /leq DIM /leq n)} where @math{n} is the rank of @var{MASK}.
2652 @item @emph{Standard}:
2656 Transformational function
2658 @item @emph{Syntax}:
2659 @code{RESULT = COUNT(MASK [, DIM])}
2661 @item @emph{Arguments}:
2662 @multitable @columnfractions .15 .70
2663 @item @var{MASK} @tab The type shall be @code{LOGICAL}.
2664 @item @var{DIM} @tab The type shall be @code{INTEGER}.
2667 @item @emph{Return value}:
2668 The return value is of type @code{INTEGER} with rank equal to that of
2671 @item @emph{Example}:
2674 integer, dimension(2,3) :: a, b
2675 logical, dimension(2,3) :: mask
2676 a = reshape( (/ 1, 2, 3, 4, 5, 6 /), (/ 2, 3 /))
2677 b = reshape( (/ 0, 7, 3, 4, 5, 8 /), (/ 2, 3 /))
2678 print '(3i3)', a(1,:)
2679 print '(3i3)', a(2,:)
2681 print '(3i3)', b(1,:)
2682 print '(3i3)', b(2,:)
2685 print '(3l3)', mask(1,:)
2686 print '(3l3)', mask(2,:)
2688 print '(3i3)', count(mask)
2690 print '(3i3)', count(mask, 1)
2692 print '(3i3)', count(mask, 2)
2693 end program test_count
2700 @section @code{CPU_TIME} --- CPU elapsed time in seconds
2702 @cindex time, elapsed
2705 @item @emph{Description}:
2706 Returns a @code{REAL(*)} value representing the elapsed CPU time in
2707 seconds. This is useful for testing segments of code to determine
2710 @item @emph{Standard}:
2716 @item @emph{Syntax}:
2717 @code{CALL CPU_TIME(TIME)}
2719 @item @emph{Arguments}:
2720 @multitable @columnfractions .15 .70
2721 @item @var{TIME} @tab The type shall be @code{REAL(*)} with @code{INTENT(OUT)}.
2724 @item @emph{Return value}:
2727 @item @emph{Example}:
2729 program test_cpu_time
2730 real :: start, finish
2731 call cpu_time(start)
2732 ! put code to test here
2733 call cpu_time(finish)
2734 print '("Time = ",f6.3," seconds.")',finish-start
2735 end program test_cpu_time
2738 @item @emph{See also}:
2739 @ref{SYSTEM_CLOCK}, @ref{DATE_AND_TIME}
2745 @section @code{CSHIFT} --- Circular shift elements of an array
2747 @cindex array, shift circularly
2748 @cindex array, permutation
2749 @cindex array, rotate
2752 @item @emph{Description}:
2753 @code{CSHIFT(ARRAY, SHIFT [, DIM])} performs a circular shift on elements of
2754 @var{ARRAY} along the dimension of @var{DIM}. If @var{DIM} is omitted it is
2755 taken to be @code{1}. @var{DIM} is a scaler of type @code{INTEGER} in the
2756 range of @math{1 /leq DIM /leq n)} where @math{n} is the rank of @var{ARRAY}.
2757 If the rank of @var{ARRAY} is one, then all elements of @var{ARRAY} are shifted
2758 by @var{SHIFT} places. If rank is greater than one, then all complete rank one
2759 sections of @var{ARRAY} along the given dimension are shifted. Elements
2760 shifted out one end of each rank one section are shifted back in the other end.
2762 @item @emph{Standard}:
2766 Transformational function
2768 @item @emph{Syntax}:
2769 @code{RESULT = CSHIFT(ARRAY, SHIFT [, DIM])}
2771 @item @emph{Arguments}:
2772 @multitable @columnfractions .15 .70
2773 @item @var{ARRAY} @tab Shall be an array of any type.
2774 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
2775 @item @var{DIM} @tab The type shall be @code{INTEGER}.
2778 @item @emph{Return value}:
2779 Returns an array of same type and rank as the @var{ARRAY} argument.
2781 @item @emph{Example}:
2784 integer, dimension(3,3) :: a
2785 a = reshape( (/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /), (/ 3, 3 /))
2786 print '(3i3)', a(1,:)
2787 print '(3i3)', a(2,:)
2788 print '(3i3)', a(3,:)
2789 a = cshift(a, SHIFT=(/1, 2, -1/), DIM=2)
2791 print '(3i3)', a(1,:)
2792 print '(3i3)', a(2,:)
2793 print '(3i3)', a(3,:)
2794 end program test_cshift
2801 @section @code{CTIME} --- Convert a time into a string
2803 @cindex time, conversion to string
2804 @cindex conversion, to string
2807 @item @emph{Description}:
2808 @code{CTIME} converts a system time value, such as returned by
2809 @code{TIME8()}, to a string of the form @samp{Sat Aug 19 18:13:14 1995}.
2811 This intrinsic is provided in both subroutine and function forms; however,
2812 only one form can be used in any given program unit.
2814 @item @emph{Standard}:
2818 Subroutine, function
2820 @item @emph{Syntax}:
2821 @multitable @columnfractions .80
2822 @item @code{CALL CTIME(TIME, RESULT)}.
2823 @item @code{RESULT = CTIME(TIME)}, (not recommended).
2826 @item @emph{Arguments}:
2827 @multitable @columnfractions .15 .70
2828 @item @var{TIME} @tab The type shall be of type @code{INTEGER(KIND=8)}.
2829 @item @var{RESULT} @tab The type shall be of type @code{CHARACTER}.
2832 @item @emph{Return value}:
2833 The converted date and time as a string.
2835 @item @emph{Example}:
2839 character(len=30) :: date
2842 ! Do something, main part of the program
2845 print *, 'Program was started on ', date
2846 end program test_ctime
2849 @item @emph{See Also}:
2850 @ref{GMTIME}, @ref{LTIME}, @ref{TIME}, @ref{TIME8}
2856 @section @code{DATE_AND_TIME} --- Date and time subroutine
2857 @fnindex DATE_AND_TIME
2858 @cindex date, current
2859 @cindex current date
2860 @cindex time, current
2861 @cindex current time
2864 @item @emph{Description}:
2865 @code{DATE_AND_TIME(DATE, TIME, ZONE, VALUES)} gets the corresponding date and
2866 time information from the real-time system clock. @var{DATE} is
2867 @code{INTENT(OUT)} and has form ccyymmdd. @var{TIME} is @code{INTENT(OUT)} and
2868 has form hhmmss.sss. @var{ZONE} is @code{INTENT(OUT)} and has form (+-)hhmm,
2869 representing the difference with respect to Coordinated Universal Time (UTC).
2870 Unavailable time and date parameters return blanks.
2872 @var{VALUES} is @code{INTENT(OUT)} and provides the following:
2874 @multitable @columnfractions .15 .30 .40
2875 @item @tab @code{VALUE(1)}: @tab The year
2876 @item @tab @code{VALUE(2)}: @tab The month
2877 @item @tab @code{VALUE(3)}: @tab The day of the month
2878 @item @tab @code{VALUE(4)}: @tab Time difference with UTC in minutes
2879 @item @tab @code{VALUE(5)}: @tab The hour of the day
2880 @item @tab @code{VALUE(6)}: @tab The minutes of the hour
2881 @item @tab @code{VALUE(7)}: @tab The seconds of the minute
2882 @item @tab @code{VALUE(8)}: @tab The milliseconds of the second
2885 @item @emph{Standard}:
2891 @item @emph{Syntax}:
2892 @code{CALL DATE_AND_TIME([DATE, TIME, ZONE, VALUES])}
2894 @item @emph{Arguments}:
2895 @multitable @columnfractions .15 .70
2896 @item @var{DATE} @tab (Optional) The type shall be @code{CHARACTER(8)} or larger.
2897 @item @var{TIME} @tab (Optional) The type shall be @code{CHARACTER(10)} or larger.
2898 @item @var{ZONE} @tab (Optional) The type shall be @code{CHARACTER(5)} or larger.
2899 @item @var{VALUES}@tab (Optional) The type shall be @code{INTEGER(8)}.
2902 @item @emph{Return value}:
2905 @item @emph{Example}:
2907 program test_time_and_date
2908 character(8) :: date
2909 character(10) :: time
2910 character(5) :: zone
2911 integer,dimension(8) :: values
2912 ! using keyword arguments
2913 call date_and_time(date,time,zone,values)
2914 call date_and_time(DATE=date,ZONE=zone)
2915 call date_and_time(TIME=time)
2916 call date_and_time(VALUES=values)
2917 print '(a,2x,a,2x,a)', date, time, zone
2918 print '(8i5))', values
2919 end program test_time_and_date
2922 @item @emph{See also}:
2923 @ref{CPU_TIME}, @ref{SYSTEM_CLOCK}
2929 @section @code{DBLE} --- Double conversion function
2931 @cindex conversion, to real
2934 @item @emph{Description}:
2935 @code{DBLE(X)} Converts @var{X} to double precision real type.
2937 @item @emph{Standard}:
2943 @item @emph{Syntax}:
2944 @code{RESULT = DBLE(X)}
2946 @item @emph{Arguments}:
2947 @multitable @columnfractions .15 .70
2948 @item @var{X} @tab The type shall be @code{INTEGER(*)}, @code{REAL(*)},
2949 or @code{COMPLEX(*)}.
2952 @item @emph{Return value}:
2953 The return value is of type double precision real.
2955 @item @emph{Example}:
2960 complex :: z = (2.3,1.14)
2961 print *, dble(x), dble(i), dble(z)
2962 end program test_dble
2965 @item @emph{See also}:
2966 @ref{DFLOAT}, @ref{FLOAT}, @ref{REAL}
2972 @section @code{DCMPLX} --- Double complex conversion function
2974 @cindex complex numbers, conversion to
2975 @cindex conversion, to complex
2978 @item @emph{Description}:
2979 @code{DCMPLX(X [,Y])} returns a double complex number where @var{X} is
2980 converted to the real component. If @var{Y} is present it is converted to the
2981 imaginary component. If @var{Y} is not present then the imaginary component is
2982 set to 0.0. If @var{X} is complex then @var{Y} must not be present.
2984 @item @emph{Standard}:
2990 @item @emph{Syntax}:
2991 @code{RESULT = DCMPLX(X [, Y])}
2993 @item @emph{Arguments}:
2994 @multitable @columnfractions .15 .70
2995 @item @var{X} @tab The type may be @code{INTEGER(*)}, @code{REAL(*)},
2996 or @code{COMPLEX(*)}.
2997 @item @var{Y} @tab (Optional if @var{X} is not @code{COMPLEX(*)}.) May be
2998 @code{INTEGER(*)} or @code{REAL(*)}.
3001 @item @emph{Return value}:
3002 The return value is of type @code{COMPLEX(8)}
3004 @item @emph{Example}:
3014 print *, dcmplx(x,i)
3015 end program test_dcmplx
3022 @section @code{DFLOAT} --- Double conversion function
3024 @cindex conversion, to real
3027 @item @emph{Description}:
3028 @code{DFLOAT(X)} Converts @var{X} to double precision real type.
3030 @item @emph{Standard}:
3036 @item @emph{Syntax}:
3037 @code{RESULT = DFLOAT(X)}
3039 @item @emph{Arguments}:
3040 @multitable @columnfractions .15 .70
3041 @item @var{X} @tab The type shall be @code{INTEGER(*)}.
3044 @item @emph{Return value}:
3045 The return value is of type double precision real.
3047 @item @emph{Example}:
3052 end program test_dfloat
3055 @item @emph{See also}:
3056 @ref{DBLE}, @ref{FLOAT}, @ref{REAL}
3062 @section @code{DIGITS} --- Significant digits function
3064 @cindex model representation, significant digits
3067 @item @emph{Description}:
3068 @code{DIGITS(X)} returns the number of significant digits of the internal model
3069 representation of @var{X}. For example, on a system using a 32-bit
3070 floating point representation, a default real number would likely return 24.
3072 @item @emph{Standard}:
3078 @item @emph{Syntax}:
3079 @code{RESULT = DIGITS(X)}
3081 @item @emph{Arguments}:
3082 @multitable @columnfractions .15 .70
3083 @item @var{X} @tab The type may be @code{INTEGER(*)} or @code{REAL(*)}.
3086 @item @emph{Return value}:
3087 The return value is of type @code{INTEGER}.
3089 @item @emph{Example}:
3092 integer :: i = 12345
3098 end program test_digits
3105 @section @code{DIM} --- Positive difference
3109 @cindex positive difference
3112 @item @emph{Description}:
3113 @code{DIM(X,Y)} returns the difference @code{X-Y} if the result is positive;
3114 otherwise returns zero.
3116 @item @emph{Standard}:
3122 @item @emph{Syntax}:
3123 @code{RESULT = DIM(X, Y)}
3125 @item @emph{Arguments}:
3126 @multitable @columnfractions .15 .70
3127 @item @var{X} @tab The type shall be @code{INTEGER(*)} or @code{REAL(*)}
3128 @item @var{Y} @tab The type shall be the same type and kind as @var{X}.
3131 @item @emph{Return value}:
3132 The return value is of type @code{INTEGER(*)} or @code{REAL(*)}.
3134 @item @emph{Example}:
3140 x = dim(4.345_8, 2.111_8)
3143 end program test_dim
3146 @item @emph{Specific names}:
3147 @multitable @columnfractions .20 .20 .20 .25
3148 @item Name @tab Argument @tab Return type @tab Standard
3149 @item @code{IDIM(X,Y)} @tab @code{INTEGER(4) X,Y} @tab @code{INTEGER(4)} @tab F77 and later
3150 @item @code{DDIM(X,Y)} @tab @code{REAL(8) X,Y} @tab @code{REAL(8)} @tab F77 and later
3157 @section @code{DOT_PRODUCT} --- Dot product function
3158 @fnindex DOT_PRODUCT
3160 @cindex vector product
3161 @cindex product, vector
3164 @item @emph{Description}:
3165 @code{DOT_PRODUCT(X,Y)} computes the dot product multiplication of two vectors
3166 @var{X} and @var{Y}. The two vectors may be either numeric or logical
3167 and must be arrays of rank one and of equal size. If the vectors are
3168 @code{INTEGER(*)} or @code{REAL(*)}, the result is @code{SUM(X*Y)}. If the
3169 vectors are @code{COMPLEX(*)}, the result is @code{SUM(CONJG(X)*Y)}. If the
3170 vectors are @code{LOGICAL}, the result is @code{ANY(X.AND.Y)}.
3172 @item @emph{Standard}:
3176 Transformational function
3178 @item @emph{Syntax}:
3179 @code{RESULT = DOT_PRODUCT(X, Y)}
3181 @item @emph{Arguments}:
3182 @multitable @columnfractions .15 .70
3183 @item @var{X} @tab The type shall be numeric or @code{LOGICAL}, rank 1.
3184 @item @var{Y} @tab The type shall be numeric or @code{LOGICAL}, rank 1.
3187 @item @emph{Return value}:
3188 If the arguments are numeric, the return value is a scaler of numeric type,
3189 @code{INTEGER(*)}, @code{REAL(*)}, or @code{COMPLEX(*)}. If the arguments are
3190 @code{LOGICAL}, the return value is @code{.TRUE.} or @code{.FALSE.}.
3192 @item @emph{Example}:
3194 program test_dot_prod
3195 integer, dimension(3) :: a, b
3202 print *, dot_product(a,b)
3203 end program test_dot_prod
3210 @section @code{DPROD} --- Double product function
3212 @cindex product, double-precision
3215 @item @emph{Description}:
3216 @code{DPROD(X,Y)} returns the product @code{X*Y}.
3218 @item @emph{Standard}:
3224 @item @emph{Syntax}:
3225 @code{RESULT = DPROD(X, Y)}
3227 @item @emph{Arguments}:
3228 @multitable @columnfractions .15 .70
3229 @item @var{X} @tab The type shall be @code{REAL}.
3230 @item @var{Y} @tab The type shall be @code{REAL}.
3233 @item @emph{Return value}:
3234 The return value is of type @code{REAL(8)}.
3236 @item @emph{Example}:
3244 end program test_dprod
3251 @section @code{DREAL} --- Double real part function
3253 @cindex complex numbers, real part
3256 @item @emph{Description}:
3257 @code{DREAL(Z)} returns the real part of complex variable @var{Z}.
3259 @item @emph{Standard}:
3265 @item @emph{Syntax}:
3266 @code{RESULT = DREAL(Z)}
3268 @item @emph{Arguments}:
3269 @multitable @columnfractions .15 .70
3270 @item @var{Z} @tab The type shall be @code{COMPLEX(8)}.
3273 @item @emph{Return value}:
3274 The return value is of type @code{REAL(8)}.
3276 @item @emph{Example}:
3279 complex(8) :: z = (1.3_8,7.2_8)
3281 end program test_dreal
3284 @item @emph{See also}:
3292 @section @code{DTIME} --- Execution time subroutine (or function)
3294 @cindex time, elapsed
3295 @cindex elapsed time
3298 @item @emph{Description}:
3299 @code{DTIME(TARRAY, RESULT)} initially returns the number of seconds of runtime
3300 since the start of the process's execution in @var{RESULT}. @var{TARRAY}
3301 returns the user and system components of this time in @code{TARRAY(1)} and
3302 @code{TARRAY(2)} respectively. @var{RESULT} is equal to @code{TARRAY(1) +
3305 Subsequent invocations of @code{DTIME} return values accumulated since the
3306 previous invocation.
3308 On some systems, the underlying timings are represented using types with
3309 sufficiently small limits that overflows (wrap around) are possible, such as
3310 32-bit types. Therefore, the values returned by this intrinsic might be, or
3311 become, negative, or numerically less than previous values, during a single
3312 run of the compiled program.
3314 This intrinsic is provided in both subroutine and function forms; however,
3315 only one form can be used in any given program unit.
3317 @var{TARRAY} and @var{RESULT} are @code{INTENT(OUT)} and provide the following:
3319 @multitable @columnfractions .15 .30 .40
3320 @item @tab @code{TARRAY(1)}: @tab User time in seconds.
3321 @item @tab @code{TARRAY(2)}: @tab System time in seconds.
3322 @item @tab @code{RESULT}: @tab Run time since start in seconds.
3325 @item @emph{Standard}:
3329 Subroutine, function
3331 @item @emph{Syntax}:
3332 @multitable @columnfractions .80
3333 @item @code{CALL DTIME(TARRAY, RESULT)}.
3334 @item @code{RESULT = DTIME(TARRAY)}, (not recommended).
3337 @item @emph{Arguments}:
3338 @multitable @columnfractions .15 .70
3339 @item @var{TARRAY}@tab The type shall be @code{REAL, DIMENSION(2)}.
3340 @item @var{RESULT}@tab The type shall be @code{REAL}.
3343 @item @emph{Return value}:
3344 Elapsed time in seconds since the start of program execution.
3346 @item @emph{Example}:
3350 real, dimension(2) :: tarray
3352 call dtime(tarray, result)
3356 do i=1,100000000 ! Just a delay
3359 call dtime(tarray, result)
3363 end program test_dtime
3370 @section @code{EOSHIFT} --- End-off shift elements of an array
3372 @cindex array, shift
3375 @item @emph{Description}:
3376 @code{EOSHIFT(ARRAY, SHIFT[,BOUNDARY, DIM])} performs an end-off shift on
3377 elements of @var{ARRAY} along the dimension of @var{DIM}. If @var{DIM} is
3378 omitted it is taken to be @code{1}. @var{DIM} is a scaler of type
3379 @code{INTEGER} in the range of @math{1 /leq DIM /leq n)} where @math{n} is the
3380 rank of @var{ARRAY}. If the rank of @var{ARRAY} is one, then all elements of
3381 @var{ARRAY} are shifted by @var{SHIFT} places. If rank is greater than one,
3382 then all complete rank one sections of @var{ARRAY} along the given dimension are
3383 shifted. Elements shifted out one end of each rank one section are dropped. If
3384 @var{BOUNDARY} is present then the corresponding value of from @var{BOUNDARY}
3385 is copied back in the other end. If @var{BOUNDARY} is not present then the
3386 following are copied in depending on the type of @var{ARRAY}.
3388 @multitable @columnfractions .15 .80
3389 @item @emph{Array Type} @tab @emph{Boundary Value}
3390 @item Numeric @tab 0 of the type and kind of @var{ARRAY}.
3391 @item Logical @tab @code{.FALSE.}.
3392 @item Character(@var{len}) @tab @var{len} blanks.
3395 @item @emph{Standard}:
3399 Transformational function
3401 @item @emph{Syntax}:
3402 @code{RESULT = EOSHIFT(ARRAY, SHIFT [, BOUNDARY, DIM])}
3404 @item @emph{Arguments}:
3405 @multitable @columnfractions .15 .70
3406 @item @var{ARRAY} @tab May be any type, not scaler.
3407 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
3408 @item @var{BOUNDARY} @tab Same type as @var{ARRAY}.
3409 @item @var{DIM} @tab The type shall be @code{INTEGER}.
3412 @item @emph{Return value}:
3413 Returns an array of same type and rank as the @var{ARRAY} argument.
3415 @item @emph{Example}:
3417 program test_eoshift
3418 integer, dimension(3,3) :: a
3419 a = reshape( (/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /), (/ 3, 3 /))
3420 print '(3i3)', a(1,:)
3421 print '(3i3)', a(2,:)
3422 print '(3i3)', a(3,:)
3423 a = EOSHIFT(a, SHIFT=(/1, 2, 1/), BOUNDARY=-5, DIM=2)
3425 print '(3i3)', a(1,:)
3426 print '(3i3)', a(2,:)
3427 print '(3i3)', a(3,:)
3428 end program test_eoshift
3435 @section @code{EPSILON} --- Epsilon function
3437 @cindex model representation, epsilon
3440 @item @emph{Description}:
3441 @code{EPSILON(X)} returns a nearly negligible number relative to @code{1}.
3443 @item @emph{Standard}:
3449 @item @emph{Syntax}:
3450 @code{RESULT = EPSILON(X)}
3452 @item @emph{Arguments}:
3453 @multitable @columnfractions .15 .70
3454 @item @var{X} @tab The type shall be @code{REAL(*)}.
3457 @item @emph{Return value}:
3458 The return value is of same type as the argument.
3460 @item @emph{Example}:
3462 program test_epsilon
3467 end program test_epsilon
3474 @section @code{ERF} --- Error function
3476 @cindex error function
3479 @item @emph{Description}:
3480 @code{ERF(X)} computes the error function of @var{X}.
3482 @item @emph{Standard}:
3488 @item @emph{Syntax}:
3489 @code{RESULT = ERF(X)}
3491 @item @emph{Arguments}:
3492 @multitable @columnfractions .15 .70
3493 @item @var{X} @tab The type shall be @code{REAL(*)}, and it shall be scalar.
3496 @item @emph{Return value}:
3497 The return value is a scalar of type @code{REAL(*)} and it is positive
3498 (@math{ - 1 \leq erf (x) \leq 1 }.
3500 @item @emph{Example}:
3503 real(8) :: x = 0.17_8
3505 end program test_erf
3508 @item @emph{Specific names}:
3509 @multitable @columnfractions .20 .20 .20 .25
3510 @item Name @tab Argument @tab Return type @tab Standard
3511 @item @code{DERF(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
3518 @section @code{ERFC} --- Error function
3520 @cindex error function, complementary
3523 @item @emph{Description}:
3524 @code{ERFC(X)} computes the complementary error function of @var{X}.
3526 @item @emph{Standard}:
3532 @item @emph{Syntax}:
3533 @code{RESULT = ERFC(X)}
3535 @item @emph{Arguments}:
3536 @multitable @columnfractions .15 .70
3537 @item @var{X} @tab The type shall be @code{REAL(*)}, and it shall be scalar.
3540 @item @emph{Return value}:
3541 The return value is a scalar of type @code{REAL(*)} and it is positive
3542 (@math{ 0 \leq erfc (x) \leq 2 }.
3544 @item @emph{Example}:
3547 real(8) :: x = 0.17_8
3549 end program test_erfc
3552 @item @emph{Specific names}:
3553 @multitable @columnfractions .20 .20 .20 .25
3554 @item Name @tab Argument @tab Return type @tab Standard
3555 @item @code{DERFC(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
3562 @section @code{ETIME} --- Execution time subroutine (or function)
3564 @cindex time, elapsed
3567 @item @emph{Description}:
3568 @code{ETIME(TARRAY, RESULT)} returns the number of seconds of runtime
3569 since the start of the process's execution in @var{RESULT}. @var{TARRAY}
3570 returns the user and system components of this time in @code{TARRAY(1)} and
3571 @code{TARRAY(2)} respectively. @var{RESULT} is equal to @code{TARRAY(1) + TARRAY(2)}.
3573 On some systems, the underlying timings are represented using types with
3574 sufficiently small limits that overflows (wrap around) are possible, such as
3575 32-bit types. Therefore, the values returned by this intrinsic might be, or
3576 become, negative, or numerically less than previous values, during a single
3577 run of the compiled program.
3579 This intrinsic is provided in both subroutine and function forms; however,
3580 only one form can be used in any given program unit.
3582 @var{TARRAY} and @var{RESULT} are @code{INTENT(OUT)} and provide the following:
3584 @multitable @columnfractions .15 .30 .60
3585 @item @tab @code{TARRAY(1)}: @tab User time in seconds.
3586 @item @tab @code{TARRAY(2)}: @tab System time in seconds.
3587 @item @tab @code{RESULT}: @tab Run time since start in seconds.
3590 @item @emph{Standard}:
3594 Subroutine, function
3596 @item @emph{Syntax}:
3597 @multitable @columnfractions .80
3598 @item @code{CALL ETIME(TARRAY, RESULT)}.
3599 @item @code{RESULT = ETIME(TARRAY)}, (not recommended).
3602 @item @emph{Arguments}:
3603 @multitable @columnfractions .15 .70
3604 @item @var{TARRAY}@tab The type shall be @code{REAL, DIMENSION(2)}.
3605 @item @var{RESULT}@tab The type shall be @code{REAL}.
3608 @item @emph{Return value}:
3609 Elapsed time in seconds since the start of program execution.
3611 @item @emph{Example}:
3615 real, dimension(2) :: tarray
3617 call ETIME(tarray, result)
3621 do i=1,100000000 ! Just a delay
3624 call ETIME(tarray, result)
3628 end program test_etime
3631 @item @emph{See also}:
3639 @section @code{EXIT} --- Exit the program with status.
3641 @cindex program termination
3642 @cindex terminate program
3645 @item @emph{Description}:
3646 @code{EXIT} causes immediate termination of the program with status. If status
3647 is omitted it returns the canonical @emph{success} for the system. All Fortran
3648 I/O units are closed.
3650 @item @emph{Standard}:
3656 @item @emph{Syntax}:
3657 @code{CALL EXIT([STATUS])}
3659 @item @emph{Arguments}:
3660 @multitable @columnfractions .15 .70
3661 @item @var{STATUS} @tab Shall be an @code{INTEGER} of the default kind.
3664 @item @emph{Return value}:
3665 @code{STATUS} is passed to the parent process on exit.
3667 @item @emph{Example}:
3670 integer :: STATUS = 0
3671 print *, 'This program is going to exit.'
3673 end program test_exit
3676 @item @emph{See also}:
3677 @ref{ABORT}, @ref{KILL}
3683 @section @code{EXP} --- Exponential function
3689 @cindex exponential function
3690 @cindex logarithmic function, inverse
3693 @item @emph{Description}:
3694 @code{EXP(X)} computes the base @math{e} exponential of @var{X}.
3696 @item @emph{Standard}:
3697 F77 and later, has overloads that are GNU extensions
3702 @item @emph{Syntax}:
3703 @code{RESULT = EXP(X)}
3705 @item @emph{Arguments}:
3706 @multitable @columnfractions .15 .70
3707 @item @var{X} @tab The type shall be @code{REAL(*)} or
3711 @item @emph{Return value}:
3712 The return value has same type and kind as @var{X}.
3714 @item @emph{Example}:
3719 end program test_exp
3722 @item @emph{Specific names}:
3723 @multitable @columnfractions .20 .20 .20 .25
3724 @item Name @tab Argument @tab Return type @tab Standard
3725 @item @code{DEXP(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F77 and later
3726 @item @code{CEXP(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab F77 and later
3727 @item @code{ZEXP(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
3728 @item @code{CDEXP(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
3735 @section @code{EXPONENT} --- Exponent function
3737 @cindex real number, exponent
3738 @cindex floating point, exponent
3741 @item @emph{Description}:
3742 @code{EXPONENT(X)} returns the value of the exponent part of @var{X}. If @var{X}
3743 is zero the value returned is zero.
3745 @item @emph{Standard}:
3751 @item @emph{Syntax}:
3752 @code{RESULT = EXPONENT(X)}
3754 @item @emph{Arguments}:
3755 @multitable @columnfractions .15 .70
3756 @item @var{X} @tab The type shall be @code{REAL(*)}.
3759 @item @emph{Return value}:
3760 The return value is of type default @code{INTEGER}.
3762 @item @emph{Example}:
3764 program test_exponent
3769 print *, exponent(0.0)
3770 end program test_exponent
3777 @section @code{FDATE} --- Get the current time as a string
3779 @cindex time, current
3780 @cindex current time
3781 @cindex date, current
3782 @cindex current date
3785 @item @emph{Description}:
3786 @code{FDATE(DATE)} returns the current date (using the same format as
3787 @code{CTIME}) in @var{DATE}. It is equivalent to @code{CALL CTIME(DATE,
3790 This intrinsic is provided in both subroutine and function forms; however,
3791 only one form can be used in any given program unit.
3793 @var{DATE} is an @code{INTENT(OUT)} @code{CHARACTER} variable.
3795 @item @emph{Standard}:
3799 Subroutine, function
3801 @item @emph{Syntax}:
3802 @multitable @columnfractions .80
3803 @item @code{CALL FDATE(DATE)}.
3804 @item @code{DATE = FDATE()}, (not recommended).
3807 @item @emph{Arguments}:
3808 @multitable @columnfractions .15 .70
3809 @item @var{DATE}@tab The type shall be of type @code{CHARACTER}.
3812 @item @emph{Return value}:
3813 The current date as a string.
3815 @item @emph{Example}:
3819 character(len=30) :: date
3821 print *, 'Program started on ', date
3822 do i = 1, 100000000 ! Just a delay
3826 print *, 'Program ended on ', date
3827 end program test_fdate
3834 @section @code{FLOAT} --- Convert integer to default real
3836 @cindex conversion, to real
3839 @item @emph{Description}:
3840 @code{FLOAT(I)} converts the integer @var{I} to a default real value.
3842 @item @emph{Standard}:
3848 @item @emph{Syntax}:
3849 @code{RESULT = FLOAT(I)}
3851 @item @emph{Arguments}:
3852 @multitable @columnfractions .15 .70
3853 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
3856 @item @emph{Return value}:
3857 The return value is of type default @code{REAL}.
3859 @item @emph{Example}:
3863 if (float(i) /= 1.) call abort
3864 end program test_float
3867 @item @emph{See also}:
3868 @ref{DBLE}, @ref{DFLOAT}, @ref{REAL}
3874 @section @code{FGET} --- Read a single character in stream mode from stdin
3876 @cindex read character, stream mode
3877 @cindex stream mode, read character
3878 @cindex file operation, read character
3881 @item @emph{Description}:
3882 Read a single character in stream mode from stdin by bypassing normal
3883 formatted output. Stream I/O should not be mixed with normal record-oriented
3884 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
3886 This intrinsic is provided in both subroutine and function forms; however,
3887 only one form can be used in any given program unit.
3889 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
3890 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
3891 Programmers should consider the use of new stream IO feature in new code
3892 for future portability. See also @ref{Fortran 2003 status}.
3894 @item @emph{Standard}:
3898 Subroutine, function
3900 @item @emph{Syntax}:
3901 @code{CALL FGET(C [, STATUS])}
3903 @item @emph{Arguments}:
3904 @multitable @columnfractions .15 .70
3905 @item @var{C} @tab The type shall be @code{CHARACTER}.
3906 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
3907 Returns 0 on success, -1 on end-of-file, and a
3908 system specific positive error code otherwise.
3911 @item @emph{Example}:
3914 INTEGER, PARAMETER :: strlen = 100
3915 INTEGER :: status, i = 1
3916 CHARACTER(len=strlen) :: str = ""
3918 WRITE (*,*) 'Enter text:'
3920 CALL fget(str(i:i), status)
3921 if (status /= 0 .OR. i > strlen) exit
3924 WRITE (*,*) TRIM(str)
3928 @item @emph{See also}:
3929 @ref{FGETC}, @ref{FPUT}, @ref{FPUTC}
3935 @section @code{FGETC} --- Read a single character in stream mode
3937 @cindex read character, stream mode
3938 @cindex stream mode, read character
3939 @cindex file operation, read character
3942 @item @emph{Description}:
3943 Read a single character in stream mode by bypassing normal formatted output.
3944 Stream I/O should not be mixed with normal record-oriented (formatted or
3945 unformatted) I/O on the same unit; the results are unpredictable.
3947 This intrinsic is provided in both subroutine and function forms; however,
3948 only one form can be used in any given program unit.
3950 Note that the @code{FGET} intrinsic is provided for backwards compatibility
3951 with @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
3952 Programmers should consider the use of new stream IO feature in new code
3953 for future portability. See also @ref{Fortran 2003 status}.
3955 @item @emph{Standard}:
3959 Subroutine, function
3961 @item @emph{Syntax}:
3962 @code{CALL FGETC(UNIT, C [, STATUS])}
3964 @item @emph{Arguments}:
3965 @multitable @columnfractions .15 .70
3966 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
3967 @item @var{C} @tab The type shall be @code{CHARACTER}.
3968 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}. Returns 0 on success,
3969 -1 on end-of-file and a system specific positive error code otherwise.
3972 @item @emph{Example}:
3975 INTEGER :: fd = 42, status
3978 OPEN(UNIT=fd, FILE="/etc/passwd", ACTION="READ", STATUS = "OLD")
3980 CALL fgetc(fd, c, status)
3981 IF (status /= 0) EXIT
3988 @item @emph{See also}:
3989 @ref{FGET}, @ref{FPUT}, @ref{FPUTC}
3995 @section @code{FLOOR} --- Integer floor function
3998 @cindex rounding, floor
4001 @item @emph{Description}:
4002 @code{FLOOR(X)} returns the greatest integer less than or equal to @var{X}.
4004 @item @emph{Standard}:
4010 @item @emph{Syntax}:
4011 @code{RESULT = FLOOR(X [, KIND])}
4013 @item @emph{Arguments}:
4014 @multitable @columnfractions .15 .70
4015 @item @var{X} @tab The type shall be @code{REAL(*)}.
4016 @item @var{KIND} @tab (Optional) An @code{INTEGER(*)} initialization
4017 expression indicating the kind parameter of
4021 @item @emph{Return value}:
4022 The return value is of type @code{INTEGER(KIND)}
4024 @item @emph{Example}:
4029 print *, floor(x) ! returns 63
4030 print *, floor(y) ! returns -64
4031 end program test_floor
4034 @item @emph{See also}:
4035 @ref{CEILING}, @ref{NINT}
4042 @section @code{FLUSH} --- Flush I/O unit(s)
4044 @cindex file operation, flush
4047 @item @emph{Description}:
4048 Flushes Fortran unit(s) currently open for output. Without the optional
4049 argument, all units are flushed, otherwise just the unit specified.
4051 @item @emph{Standard}:
4057 @item @emph{Syntax}:
4058 @code{CALL FLUSH(UNIT)}
4060 @item @emph{Arguments}:
4061 @multitable @columnfractions .15 .70
4062 @item @var{UNIT} @tab (Optional) The type shall be @code{INTEGER}.
4066 Beginning with the Fortran 2003 standard, there is a @code{FLUSH}
4067 statement that should be preferred over the @code{FLUSH} intrinsic.
4074 @section @code{FNUM} --- File number function
4076 @cindex file operation, file number
4079 @item @emph{Description}:
4080 @code{FNUM(UNIT)} returns the POSIX file descriptor number corresponding to the
4081 open Fortran I/O unit @code{UNIT}.
4083 @item @emph{Standard}:
4089 @item @emph{Syntax}:
4090 @code{RESULT = FNUM(UNIT)}
4092 @item @emph{Arguments}:
4093 @multitable @columnfractions .15 .70
4094 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
4097 @item @emph{Return value}:
4098 The return value is of type @code{INTEGER}
4100 @item @emph{Example}:
4104 open (unit=10, status = "scratch")
4108 end program test_fnum
4115 @section @code{FPUT} --- Write a single character in stream mode to stdout
4117 @cindex write character, stream mode
4118 @cindex stream mode, write character
4119 @cindex file operation, write character
4122 @item @emph{Description}:
4123 Write a single character in stream mode to stdout by bypassing normal
4124 formatted output. Stream I/O should not be mixed with normal record-oriented
4125 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
4127 This intrinsic is provided in both subroutine and function forms; however,
4128 only one form can be used in any given program unit.
4130 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
4131 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
4132 Programmers should consider the use of new stream IO feature in new code
4133 for future portability. See also @ref{Fortran 2003 status}.
4135 @item @emph{Standard}:
4139 Subroutine, function
4141 @item @emph{Syntax}:
4142 @code{CALL FPUT(C [, STATUS])}
4144 @item @emph{Arguments}:
4145 @multitable @columnfractions .15 .70
4146 @item @var{C} @tab The type shall be @code{CHARACTER}.
4147 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}. Returns 0 on success,
4148 -1 on end-of-file and a system specific positive error code otherwise.
4151 @item @emph{Example}:
4154 CHARACTER(len=10) :: str = "gfortran"
4156 DO i = 1, len_trim(str)
4162 @item @emph{See also}:
4163 @ref{FPUTC}, @ref{FGET}, @ref{FGETC}
4169 @section @code{FPUTC} --- Write a single character in stream mode
4171 @cindex write character, stream mode
4172 @cindex stream mode, write character
4173 @cindex file operation, write character
4176 @item @emph{Description}:
4177 Write a single character in stream mode by bypassing normal formatted
4178 output. Stream I/O should not be mixed with normal record-oriented
4179 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
4181 This intrinsic is provided in both subroutine and function forms; however,
4182 only one form can be used in any given program unit.
4184 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
4185 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
4186 Programmers should consider the use of new stream IO feature in new code
4187 for future portability. See also @ref{Fortran 2003 status}.
4189 @item @emph{Standard}:
4193 Subroutine, function
4195 @item @emph{Syntax}:
4196 @code{CALL FPUTC(UNIT, C [, STATUS])}
4198 @item @emph{Arguments}:
4199 @multitable @columnfractions .15 .70
4200 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
4201 @item @var{C} @tab The type shall be @code{CHARACTER}.
4202 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}. Returns 0 on success,
4203 -1 on end-of-file and a system specific positive error code otherwise.
4206 @item @emph{Example}:
4209 CHARACTER(len=10) :: str = "gfortran"
4210 INTEGER :: fd = 42, i
4212 OPEN(UNIT = fd, FILE = "out", ACTION = "WRITE", STATUS="NEW")
4213 DO i = 1, len_trim(str)
4214 CALL fputc(fd, str(i:i))
4220 @item @emph{See also}:
4221 @ref{FPUT}, @ref{FGET}, @ref{FGETC}
4227 @section @code{FRACTION} --- Fractional part of the model representation
4229 @cindex real number, fraction
4230 @cindex floating point, fraction
4233 @item @emph{Description}:
4234 @code{FRACTION(X)} returns the fractional part of the model
4235 representation of @code{X}.
4237 @item @emph{Standard}:
4243 @item @emph{Syntax}:
4244 @code{Y = FRACTION(X)}
4246 @item @emph{Arguments}:
4247 @multitable @columnfractions .15 .70
4248 @item @var{X} @tab The type of the argument shall be a @code{REAL}.
4251 @item @emph{Return value}:
4252 The return value is of the same type and kind as the argument.
4253 The fractional part of the model representation of @code{X} is returned;
4254 it is @code{X * RADIX(X)**(-EXPONENT(X))}.
4256 @item @emph{Example}:
4258 program test_fraction
4261 print *, fraction(x), x * radix(x)**(-exponent(x))
4262 end program test_fraction
4270 @section @code{FREE} --- Frees memory
4272 @cindex pointer, cray
4275 @item @emph{Description}:
4276 Frees memory previously allocated by @code{MALLOC()}. The @code{FREE}
4277 intrinsic is an extension intended to be used with Cray pointers, and is
4278 provided in GNU Fortran to allow user to compile legacy code. For
4279 new code using Fortran 95 pointers, the memory de-allocation intrinsic is
4282 @item @emph{Standard}:
4288 @item @emph{Syntax}:
4289 @code{CALL FREE(PTR)}
4291 @item @emph{Arguments}:
4292 @multitable @columnfractions .15 .70
4293 @item @var{PTR} @tab The type shall be @code{INTEGER}. It represents the
4294 location of the memory that should be de-allocated.
4297 @item @emph{Return value}:
4300 @item @emph{Example}:
4301 See @code{MALLOC} for an example.
4303 @item @emph{See also}:
4310 @section @code{FSEEK} --- Low level file positioning subroutine
4312 @cindex file operation, seek
4313 @cindex file operation, position
4316 @item @emph{Description}:
4317 Moves @var{UNIT} to the specified @var{OFFSET}. If @var{WHENCE}
4318 is set to 0, the @var{OFFSET} is taken as an absolute value @code{SEEK_SET},
4319 if set to 1, @var{OFFSET} is taken to be relative to the current position
4320 @code{SEEK_CUR}, and if set to 2 relative to the end of the file @code{SEEK_END}.
4321 On error, @var{STATUS} is set to a nonzero value. If @var{STATUS} the seek
4324 This intrinsic routine is not fully backwards compatible with @command{g77}.
4325 In @command{g77}, the @code{FSEEK} takes a statement label instead of a
4326 @var{STATUS} variable. If FSEEK is used in old code, change
4328 CALL FSEEK(UNIT, OFFSET, WHENCE, *label)
4333 CALL FSEEK(UNIT, OFFSET, WHENCE, status)
4334 IF (status /= 0) GOTO label
4337 Please note that GNU Fortran provides the Fortran 2003 Stream facility.
4338 Programmers should consider the use of new stream IO feature in new code
4339 for future portability. See also @ref{Fortran 2003 status}.
4341 @item @emph{Standard}:
4347 @item @emph{Syntax}:
4348 @code{CALL FSEEK(UNIT, OFFSET, WHENCE[, STATUS])}
4350 @item @emph{Arguments}:
4351 @multitable @columnfractions .15 .70
4352 @item @var{UNIT} @tab Shall be a scalar of type @code{INTEGER}.
4353 @item @var{OFFSET} @tab Shall be a scalar of type @code{INTEGER}.
4354 @item @var{WHENCE} @tab Shall be a scalar of type @code{INTEGER}.
4355 Its value shall be either 0, 1 or 2.
4356 @item @var{STATUS} @tab (Optional) shall be a scalar of type
4360 @item @emph{Example}:
4363 INTEGER, PARAMETER :: SEEK_SET = 0, SEEK_CUR = 1, SEEK_END = 2
4364 INTEGER :: fd, offset, ierr
4370 OPEN(UNIT=fd, FILE="fseek.test")
4371 CALL FSEEK(fd, offset, SEEK_SET, ierr) ! move to OFFSET
4372 print *, FTELL(fd), ierr
4374 CALL FSEEK(fd, 0, SEEK_END, ierr) ! move to end
4375 print *, FTELL(fd), ierr
4377 CALL FSEEK(fd, 0, SEEK_SET, ierr) ! move to beginning
4378 print *, FTELL(fd), ierr
4384 @item @emph{See also}:
4391 @section @code{FSTAT} --- Get file status
4393 @cindex file system, file status
4396 @item @emph{Description}:
4397 @code{FSTAT} is identical to @ref{STAT}, except that information about an
4398 already opened file is obtained.
4400 The elements in @code{BUFF} are the same as described by @ref{STAT}.
4402 This intrinsic is provided in both subroutine and function forms; however,
4403 only one form can be used in any given program unit.
4405 @item @emph{Standard}:
4409 Subroutine, function
4411 @item @emph{Syntax}:
4412 @code{CALL FSTAT(UNIT, BUFF [, STATUS])}
4414 @item @emph{Arguments}:
4415 @multitable @columnfractions .15 .70
4416 @item @var{UNIT} @tab An open I/O unit number of type @code{INTEGER}.
4417 @item @var{BUFF} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
4418 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}. Returns 0
4419 on success and a system specific error code otherwise.
4422 @item @emph{Example}:
4423 See @ref{STAT} for an example.
4425 @item @emph{See also}:
4426 To stat a link: @ref{LSTAT}, to stat a file: @ref{STAT}
4432 @section @code{FTELL} --- Current stream position
4434 @cindex file operation, position
4437 @item @emph{Description}:
4438 Retrieves the current position within an open file.
4440 This intrinsic is provided in both subroutine and function forms; however,
4441 only one form can be used in any given program unit.
4443 @item @emph{Standard}:
4447 Subroutine, function
4449 @item @emph{Syntax}:
4450 @multitable @columnfractions .80
4451 @item @code{CALL FTELL(UNIT, OFFSET)}
4452 @item @code{OFFSET = FTELL(UNIT)}
4455 @item @emph{Arguments}:
4456 @multitable @columnfractions .15 .70
4457 @item @var{OFFSET} @tab Shall of type @code{INTEGER}.
4458 @item @var{UNIT} @tab Shall of type @code{INTEGER}.
4461 @item @emph{Return value}:
4462 In either syntax, @var{OFFSET} is set to the current offset of unit
4463 number @var{UNIT}, or to @math{-1} if the unit is not currently open.
4465 @item @emph{Example}:
4469 OPEN(10, FILE="temp.dat")
4475 @item @emph{See also}:
4482 @section @code{GERROR} --- Get last system error message
4484 @cindex system, error handling
4487 @item @emph{Description}:
4488 Returns the system error message corresponding to the last system error.
4489 This resembles the functionality of @code{strerror(3)} in C.
4491 @item @emph{Standard}:
4497 @item @emph{Syntax}:
4498 @code{CALL GERROR(RESULT)}
4500 @item @emph{Arguments}:
4501 @multitable @columnfractions .15 .70
4502 @item @var{RESULT} @tab Shall of type @code{CHARACTER(*)}.
4505 @item @emph{Example}:
4508 CHARACTER(len=100) :: msg
4514 @item @emph{See also}:
4515 @ref{IERRNO}, @ref{PERROR}
4521 @section @code{GETARG} --- Get command line arguments
4523 @cindex command-line arguments
4524 @cindex arguments, to program
4527 @item @emph{Description}:
4528 Retrieve the @var{N}th argument that was passed on the
4529 command line when the containing program was invoked.
4531 This intrinsic routine is provided for backwards compatibility with
4532 GNU Fortran 77. In new code, programmers should consider the use of
4533 the @ref{GET_COMMAND_ARGUMENT} intrinsic defined by the Fortran 2003
4536 @item @emph{Standard}:
4542 @item @emph{Syntax}:
4543 @code{CALL GETARG(N, ARG)}
4545 @item @emph{Arguments}:
4546 @multitable @columnfractions .15 .70
4547 @item @var{N} @tab Shall be of type @code{INTEGER(4)}, @math{@var{N} \geq 0}
4548 @item @var{ARG} @tab Shall be of type @code{CHARACTER(*)}.
4551 @item @emph{Return value}:
4552 After @code{GETARG} returns, the @var{ARG} argument holds the @var{N}th
4553 command line argument. If @var{ARG} can not hold the argument, it is
4554 truncated to fit the length of @var{ARG}. If there are less than @var{N}
4555 arguments specified at the command line, @var{ARG} will be filled with blanks.
4556 If @math{@var{N} = 0}, @var{ARG} is set to the name of the program (on systems
4557 that support this feature).
4559 @item @emph{Example}:
4563 CHARACTER(len=32) :: arg
4572 @item @emph{See also}:
4573 GNU Fortran 77 compatibility function: @ref{IARGC}
4575 F2003 functions and subroutines: @ref{GET_COMMAND}, @ref{GET_COMMAND_ARGUMENT},
4576 @ref{COMMAND_ARGUMENT_COUNT}
4582 @section @code{GET_COMMAND} --- Get the entire command line
4583 @fnindex GET_COMMAND
4584 @cindex command-line arguments
4585 @cindex arguments, to program
4588 @item @emph{Description}:
4589 Retrieve the entire command line that was used to invoke the program.
4591 @item @emph{Standard}:
4597 @item @emph{Syntax}:
4598 @code{CALL GET_COMMAND(CMD)}
4600 @item @emph{Arguments}:
4601 @multitable @columnfractions .15 .70
4602 @item @var{CMD} @tab Shall be of type @code{CHARACTER(*)}.
4605 @item @emph{Return value}:
4606 Stores the entire command line that was used to invoke the program in @var{ARG}.
4607 If @var{ARG} is not large enough, the command will be truncated.
4609 @item @emph{Example}:
4611 PROGRAM test_get_command
4612 CHARACTER(len=255) :: cmd
4613 CALL get_command(cmd)
4614 WRITE (*,*) TRIM(cmd)
4618 @item @emph{See also}:
4619 @ref{GET_COMMAND_ARGUMENT}, @ref{COMMAND_ARGUMENT_COUNT}
4624 @node GET_COMMAND_ARGUMENT
4625 @section @code{GET_COMMAND_ARGUMENT} --- Get command line arguments
4626 @fnindex GET_COMMAND_ARGUMENT
4627 @cindex command-line arguments
4628 @cindex arguments, to program
4631 @item @emph{Description}:
4632 Retrieve the @var{N}th argument that was passed on the
4633 command line when the containing program was invoked.
4635 @item @emph{Standard}:
4641 @item @emph{Syntax}:
4642 @code{CALL GET_COMMAND_ARGUMENT(N, ARG)}
4644 @item @emph{Arguments}:
4645 @multitable @columnfractions .15 .70
4646 @item @var{N} @tab Shall be of type @code{INTEGER(4)}, @math{@var{N} \geq 0}
4647 @item @var{ARG} @tab Shall be of type @code{CHARACTER(*)}.
4650 @item @emph{Return value}:
4651 After @code{GET_COMMAND_ARGUMENT} returns, the @var{ARG} argument holds the
4652 @var{N}th command line argument. If @var{ARG} can not hold the argument, it is
4653 truncated to fit the length of @var{ARG}. If there are less than @var{N}
4654 arguments specified at the command line, @var{ARG} will be filled with blanks.
4655 If @math{@var{N} = 0}, @var{ARG} is set to the name of the program (on systems
4656 that support this feature).
4658 @item @emph{Example}:
4660 PROGRAM test_get_command_argument
4662 CHARACTER(len=32) :: arg
4666 CALL get_command_argument(i, arg)
4667 IF (LEN_TRIM(arg) == 0) EXIT
4669 WRITE (*,*) TRIM(arg)
4675 @item @emph{See also}:
4676 @ref{GET_COMMAND}, @ref{COMMAND_ARGUMENT_COUNT}
4682 @section @code{GETCWD} --- Get current working directory
4684 @cindex system, working directory
4687 @item @emph{Description}:
4688 Get current working directory.
4690 This intrinsic is provided in both subroutine and function forms; however,
4691 only one form can be used in any given program unit.
4693 @item @emph{Standard}:
4697 Subroutine, function
4699 @item @emph{Syntax}:
4700 @code{CALL GETCWD(CWD [, STATUS])}
4702 @item @emph{Arguments}:
4703 @multitable @columnfractions .15 .70
4704 @item @var{CWD} @tab The type shall be @code{CHARACTER(*)}.
4705 @item @var{STATUS} @tab (Optional) status flag. Returns 0 on success,
4706 a system specific and nonzero error code otherwise.
4709 @item @emph{Example}:
4712 CHARACTER(len=255) :: cwd
4714 WRITE(*,*) TRIM(cwd)
4718 @item @emph{See also}:
4725 @section @code{GETENV} --- Get an environmental variable
4727 @cindex environment variable
4730 @item @emph{Description}:
4731 Get the @var{VALUE} of the environmental variable @var{ENVVAR}.
4733 This intrinsic routine is provided for backwards compatibility with
4734 GNU Fortran 77. In new code, programmers should consider the use of
4735 the @ref{GET_ENVIRONMENT_VARIABLE} intrinsic defined by the Fortran
4738 @item @emph{Standard}:
4744 @item @emph{Syntax}:
4745 @code{CALL GETENV(ENVVAR, VALUE)}
4747 @item @emph{Arguments}:
4748 @multitable @columnfractions .15 .70
4749 @item @var{ENVVAR} @tab Shall be of type @code{CHARACTER(*)}.
4750 @item @var{VALUE} @tab Shall be of type @code{CHARACTER(*)}.
4753 @item @emph{Return value}:
4754 Stores the value of @var{ENVVAR} in @var{VALUE}. If @var{VALUE} is
4755 not large enough to hold the data, it is truncated. If @var{ENVVAR}
4756 is not set, @var{VALUE} will be filled with blanks.
4758 @item @emph{Example}:
4761 CHARACTER(len=255) :: homedir
4762 CALL getenv("HOME", homedir)
4763 WRITE (*,*) TRIM(homedir)
4767 @item @emph{See also}:
4768 @ref{GET_ENVIRONMENT_VARIABLE}
4773 @node GET_ENVIRONMENT_VARIABLE
4774 @section @code{GET_ENVIRONMENT_VARIABLE} --- Get an environmental variable
4775 @fnindex GET_ENVIRONMENT_VARIABLE
4776 @cindex environment variable
4779 @item @emph{Description}:
4780 Get the @var{VALUE} of the environmental variable @var{ENVVAR}.
4782 @item @emph{Standard}:
4788 @item @emph{Syntax}:
4789 @code{CALL GET_ENVIRONMENT_VARIABLE(ENVVAR, VALUE)}
4791 @item @emph{Arguments}:
4792 @multitable @columnfractions .15 .70
4793 @item @var{ENVVAR} @tab Shall be of type @code{CHARACTER(*)}.
4794 @item @var{VALUE} @tab Shall be of type @code{CHARACTER(*)}.
4797 @item @emph{Return value}:
4798 Stores the value of @var{ENVVAR} in @var{VALUE}. If @var{VALUE} is
4799 not large enough to hold the data, it is truncated. If @var{ENVVAR}
4800 is not set, @var{VALUE} will be filled with blanks.
4802 @item @emph{Example}:
4805 CHARACTER(len=255) :: homedir
4806 CALL get_environment_variable("HOME", homedir)
4807 WRITE (*,*) TRIM(homedir)
4815 @section @code{GETGID} --- Group ID function
4817 @cindex system, group id
4820 @item @emph{Description}:
4821 Returns the numerical group ID of the current process.
4823 @item @emph{Standard}:
4829 @item @emph{Syntax}:
4830 @code{RESULT = GETGID()}
4832 @item @emph{Return value}:
4833 The return value of @code{GETGID} is an @code{INTEGER} of the default
4837 @item @emph{Example}:
4838 See @code{GETPID} for an example.
4840 @item @emph{See also}:
4841 @ref{GETPID}, @ref{GETUID}
4847 @section @code{GETLOG} --- Get login name
4849 @cindex system, login name
4853 @item @emph{Description}:
4854 Gets the username under which the program is running.
4856 @item @emph{Standard}:
4862 @item @emph{Syntax}:
4863 @code{CALL GETLOG(LOGIN)}
4865 @item @emph{Arguments}:
4866 @multitable @columnfractions .15 .70
4867 @item @var{LOGIN} @tab Shall be of type @code{CHARACTER(*)}.
4870 @item @emph{Return value}:
4871 Stores the current user name in @var{LOGIN}. (On systems where POSIX
4872 functions @code{geteuid} and @code{getpwuid} are not available, and
4873 the @code{getlogin} function is not implemented either, this will
4874 return a blank string.)
4876 @item @emph{Example}:
4879 CHARACTER(32) :: login
4885 @item @emph{See also}:
4892 @section @code{GETPID} --- Process ID function
4894 @cindex system, process id
4898 @item @emph{Description}:
4899 Returns the numerical process identifier of the current process.
4901 @item @emph{Standard}:
4907 @item @emph{Syntax}:
4908 @code{RESULT = GETPID()}
4910 @item @emph{Return value}:
4911 The return value of @code{GETPID} is an @code{INTEGER} of the default
4915 @item @emph{Example}:
4918 print *, "The current process ID is ", getpid()
4919 print *, "Your numerical user ID is ", getuid()
4920 print *, "Your numerical group ID is ", getgid()
4924 @item @emph{See also}:
4925 @ref{GETGID}, @ref{GETUID}
4931 @section @code{GETUID} --- User ID function
4933 @cindex system, user id
4937 @item @emph{Description}:
4938 Returns the numerical user ID of the current process.
4940 @item @emph{Standard}:
4946 @item @emph{Syntax}:
4947 @code{RESULT = GETUID()}
4949 @item @emph{Return value}:
4950 The return value of @code{GETUID} is an @code{INTEGER} of the default
4954 @item @emph{Example}:
4955 See @code{GETPID} for an example.
4957 @item @emph{See also}:
4958 @ref{GETPID}, @ref{GETLOG}
4964 @section @code{GMTIME} --- Convert time to GMT info
4966 @cindex time, conversion to GMT info
4969 @item @emph{Description}:
4970 Given a system time value @var{STIME} (as provided by the @code{TIME8()}
4971 intrinsic), fills @var{TARRAY} with values extracted from it appropriate
4972 to the UTC time zone (Universal Coordinated Time, also known in some
4973 countries as GMT, Greenwich Mean Time), using @code{gmtime(3)}.
4975 @item @emph{Standard}:
4981 @item @emph{Syntax}:
4982 @code{CALL GMTIME(STIME, TARRAY)}
4984 @item @emph{Arguments}:
4985 @multitable @columnfractions .15 .70
4986 @item @var{STIME} @tab An @code{INTEGER(*)} scalar expression
4987 corresponding to a system time, with
4989 @item @var{TARRAY} @tab A default @code{INTEGER} array with 9 elements,
4990 with @code{INTENT(OUT)}.
4993 @item @emph{Return value}:
4994 The elements of @var{TARRAY} are assigned as follows:
4996 @item Seconds after the minute, range 0--59 or 0--61 to allow for leap
4998 @item Minutes after the hour, range 0--59
4999 @item Hours past midnight, range 0--23
5000 @item Day of month, range 0--31
5001 @item Number of months since January, range 0--12
5002 @item Years since 1900
5003 @item Number of days since Sunday, range 0--6
5004 @item Days since January 1
5005 @item Daylight savings indicator: positive if daylight savings is in
5006 effect, zero if not, and negative if the information is not
5010 @item @emph{See also}:
5011 @ref{CTIME}, @ref{LTIME}, @ref{TIME}, @ref{TIME8}
5018 @section @code{HOSTNM} --- Get system host name
5020 @cindex system, host name
5023 @item @emph{Description}:
5024 Retrieves the host name of the system on which the program is running.
5026 This intrinsic is provided in both subroutine and function forms; however,
5027 only one form can be used in any given program unit.
5029 @item @emph{Standard}:
5033 Subroutine, function
5035 @item @emph{Syntax}:
5036 @multitable @columnfractions .80
5037 @item @code{CALL HOSTNM(NAME[, STATUS])}
5038 @item @code{STATUS = HOSTNM(NAME)}
5041 @item @emph{Arguments}:
5042 @multitable @columnfractions .15 .70
5043 @item @var{NAME} @tab Shall of type @code{CHARACTER(*)}.
5044 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
5045 Returns 0 on success, or a system specific error
5049 @item @emph{Return value}:
5050 In either syntax, @var{NAME} is set to the current hostname if it can
5051 be obtained, or to a blank string otherwise.
5058 @section @code{HUGE} --- Largest number of a kind
5060 @cindex limits, largest number
5061 @cindex model representation, largest number
5064 @item @emph{Description}:
5065 @code{HUGE(X)} returns the largest number that is not an infinity in
5066 the model of the type of @code{X}.
5068 @item @emph{Standard}:
5074 @item @emph{Syntax}:
5075 @code{RESULT = HUGE(X)}
5077 @item @emph{Arguments}:
5078 @multitable @columnfractions .15 .70
5079 @item @var{X} @tab Shall be of type @code{REAL} or @code{INTEGER}.
5082 @item @emph{Return value}:
5083 The return value is of the same type and kind as @var{X}
5085 @item @emph{Example}:
5087 program test_huge_tiny
5088 print *, huge(0), huge(0.0), huge(0.0d0)
5089 print *, tiny(0.0), tiny(0.0d0)
5090 end program test_huge_tiny
5097 @section @code{IACHAR} --- Code in @acronym{ASCII} collating sequence
5099 @cindex @acronym{ASCII} collating sequence
5100 @cindex collating sequence, @acronym{ASCII}
5101 @cindex conversion, to integer
5104 @item @emph{Description}:
5105 @code{IACHAR(C)} returns the code for the @acronym{ASCII} character
5106 in the first character position of @code{C}.
5108 @item @emph{Standard}:
5114 @item @emph{Syntax}:
5115 @code{RESULT = IACHAR(C)}
5117 @item @emph{Arguments}:
5118 @multitable @columnfractions .15 .70
5119 @item @var{C} @tab Shall be a scalar @code{CHARACTER}, with @code{INTENT(IN)}
5122 @item @emph{Return value}:
5123 The return value is of type @code{INTEGER} and of the default integer
5126 @item @emph{Example}:
5131 end program test_iachar
5135 See @ref{ICHAR} for a discussion of converting between numerical values
5136 and formatted string representations.
5138 @item @emph{See also}:
5139 @ref{ACHAR}, @ref{CHAR}, @ref{ICHAR}
5146 @section @code{IAND} --- Bitwise logical and
5148 @cindex bitwise logical and
5149 @cindex logical and, bitwise
5152 @item @emph{Description}:
5153 Bitwise logical @code{AND}.
5155 @item @emph{Standard}:
5161 @item @emph{Syntax}:
5162 @code{RESULT = IAND(I, J)}
5164 @item @emph{Arguments}:
5165 @multitable @columnfractions .15 .70
5166 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
5167 @item @var{J} @tab The type shall be @code{INTEGER(*)}, of the same
5168 kind as @var{I}. (As a GNU extension, different kinds are also
5172 @item @emph{Return value}:
5173 The return type is @code{INTEGER(*)}, of the same kind as the
5174 arguments. (If the argument kinds differ, it is of the same kind as
5175 the larger argument.)
5177 @item @emph{Example}:
5181 DATA a / Z'F' /, b / Z'3' /
5182 WRITE (*,*) IAND(a, b)
5186 @item @emph{See also}:
5187 @ref{IOR}, @ref{IEOR}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}, @ref{NOT}
5194 @section @code{IARGC} --- Get the number of command line arguments
5196 @cindex command-line arguments
5197 @cindex command-line arguments, number of
5198 @cindex arguments, to program
5201 @item @emph{Description}:
5202 @code{IARGC()} returns the number of arguments passed on the
5203 command line when the containing program was invoked.
5205 This intrinsic routine is provided for backwards compatibility with
5206 GNU Fortran 77. In new code, programmers should consider the use of
5207 the @ref{COMMAND_ARGUMENT_COUNT} intrinsic defined by the Fortran 2003
5210 @item @emph{Standard}:
5216 @item @emph{Syntax}:
5217 @code{RESULT = IARGC()}
5219 @item @emph{Arguments}:
5222 @item @emph{Return value}:
5223 The number of command line arguments, type @code{INTEGER(4)}.
5225 @item @emph{Example}:
5228 @item @emph{See also}:
5229 GNU Fortran 77 compatibility subroutine: @ref{GETARG}
5231 F2003 functions and subroutines: @ref{GET_COMMAND}, @ref{GET_COMMAND_ARGUMENT},
5232 @ref{COMMAND_ARGUMENT_COUNT}
5238 @section @code{IBCLR} --- Clear bit
5244 @item @emph{Description}:
5245 @code{IBCLR} returns the value of @var{I} with the bit at position
5246 @var{POS} set to zero.
5248 @item @emph{Standard}:
5254 @item @emph{Syntax}:
5255 @code{RESULT = IBCLR(I, POS)}
5257 @item @emph{Arguments}:
5258 @multitable @columnfractions .15 .70
5259 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
5260 @item @var{POS} @tab The type shall be @code{INTEGER(*)}.
5263 @item @emph{Return value}:
5264 The return value is of type @code{INTEGER(*)} and of the same kind as
5267 @item @emph{See also}:
5268 @ref{IBITS}, @ref{IBSET}, @ref{IAND}, @ref{IOR}, @ref{IEOR}, @ref{MVBITS}
5275 @section @code{IBITS} --- Bit extraction
5278 @cindex bits, extract
5281 @item @emph{Description}:
5282 @code{IBITS} extracts a field of length @var{LEN} from @var{I},
5283 starting from bit position @var{POS} and extending left for @var{LEN}
5284 bits. The result is right-justified and the remaining bits are
5285 zeroed. The value of @code{POS+LEN} must be less than or equal to the
5286 value @code{BIT_SIZE(I)}.
5288 @item @emph{Standard}:
5294 @item @emph{Syntax}:
5295 @code{RESULT = IBITS(I, POS, LEN)}
5297 @item @emph{Arguments}:
5298 @multitable @columnfractions .15 .70
5299 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
5300 @item @var{POS} @tab The type shall be @code{INTEGER(*)}.
5301 @item @var{LEN} @tab The type shall be @code{INTEGER(*)}.
5304 @item @emph{Return value}:
5305 The return value is of type @code{INTEGER(*)} and of the same kind as
5308 @item @emph{See also}:
5309 @ref{BIT_SIZE}, @ref{IBCLR}, @ref{IBSET}, @ref{IAND}, @ref{IOR}, @ref{IEOR}
5315 @section @code{IBSET} --- Set bit
5320 @item @emph{Description}:
5321 @code{IBSET} returns the value of @var{I} with the bit at position
5322 @var{POS} set to one.
5324 @item @emph{Standard}:
5330 @item @emph{Syntax}:
5331 @code{RESULT = IBSET(I, POS)}
5333 @item @emph{Arguments}:
5334 @multitable @columnfractions .15 .70
5335 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
5336 @item @var{POS} @tab The type shall be @code{INTEGER(*)}.
5339 @item @emph{Return value}:
5340 The return value is of type @code{INTEGER(*)} and of the same kind as
5343 @item @emph{See also}:
5344 @ref{IBCLR}, @ref{IBITS}, @ref{IAND}, @ref{IOR}, @ref{IEOR}, @ref{MVBITS}
5351 @section @code{ICHAR} --- Character-to-integer conversion function
5353 @cindex conversion, to integer
5356 @item @emph{Description}:
5357 @code{ICHAR(C)} returns the code for the character in the first character
5358 position of @code{C} in the system's native character set.
5359 The correspondence between characters and their codes is not necessarily
5360 the same across different GNU Fortran implementations.
5362 @item @emph{Standard}:
5368 @item @emph{Syntax}:
5369 @code{RESULT = ICHAR(C)}
5371 @item @emph{Arguments}:
5372 @multitable @columnfractions .15 .70
5373 @item @var{C} @tab Shall be a scalar @code{CHARACTER}, with @code{INTENT(IN)}
5376 @item @emph{Return value}:
5377 The return value is of type @code{INTEGER} and of the default integer
5380 @item @emph{Example}:
5385 end program test_ichar
5389 No intrinsic exists to convert between a numeric value and a formatted
5390 character string representation -- for instance, given the
5391 @code{CHARACTER} value @code{'154'}, obtaining an @code{INTEGER} or
5392 @code{REAL} value with the value 154, or vice versa. Instead, this
5393 functionality is provided by internal-file I/O, as in the following
5398 character(len=10) string, string2
5401 ! Convert a string to a numeric value
5402 read (string,'(I10)') value
5405 ! Convert a value to a formatted string
5406 write (string2,'(I10)') value
5408 end program read_val
5411 @item @emph{See also}:
5412 @ref{ACHAR}, @ref{CHAR}, @ref{IACHAR}
5419 @section @code{IDATE} --- Get current local time subroutine (day/month/year)
5421 @cindex date, current
5422 @cindex current date
5425 @item @emph{Description}:
5426 @code{IDATE(TARRAY)} Fills @var{TARRAY} with the numerical values at the
5427 current local time. The day (in the range 1-31), month (in the range 1-12),
5428 and year appear in elements 1, 2, and 3 of @var{TARRAY}, respectively.
5429 The year has four significant digits.
5431 @item @emph{Standard}:
5437 @item @emph{Syntax}:
5438 @code{CALL IDATE(TARRAY)}
5440 @item @emph{Arguments}:
5441 @multitable @columnfractions .15 .70
5442 @item @var{TARRAY} @tab The type shall be @code{INTEGER, DIMENSION(3)} and
5443 the kind shall be the default integer kind.
5446 @item @emph{Return value}:
5449 @item @emph{Example}:
5452 integer, dimension(3) :: tarray
5457 end program test_idate
5464 @section @code{IEOR} --- Bitwise logical exclusive or
5466 @cindex bitwise logical exclusive or
5467 @cindex logical exclusive or, bitwise
5470 @item @emph{Description}:
5471 @code{IEOR} returns the bitwise boolean exclusive-OR of @var{I} and
5474 @item @emph{Standard}:
5480 @item @emph{Syntax}:
5481 @code{RESULT = IEOR(I, J)}
5483 @item @emph{Arguments}:
5484 @multitable @columnfractions .15 .70
5485 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
5486 @item @var{J} @tab The type shall be @code{INTEGER(*)}, of the same
5487 kind as @var{I}. (As a GNU extension, different kinds are also
5491 @item @emph{Return value}:
5492 The return type is @code{INTEGER(*)}, of the same kind as the
5493 arguments. (If the argument kinds differ, it is of the same kind as
5494 the larger argument.)
5496 @item @emph{See also}:
5497 @ref{IOR}, @ref{IAND}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}, @ref{NOT}
5503 @section @code{IERRNO} --- Get the last system error number
5505 @cindex system, error handling
5508 @item @emph{Description}:
5509 Returns the last system error number, as given by the C @code{errno()}
5512 @item @emph{Standard}:
5518 @item @emph{Syntax}:
5519 @code{RESULT = IERRNO()}
5521 @item @emph{Arguments}:
5524 @item @emph{Return value}:
5525 The return value is of type @code{INTEGER} and of the default integer
5528 @item @emph{See also}:
5535 @section @code{INDEX} --- Position of a substring within a string
5537 @cindex substring position
5538 @cindex string, find substring
5541 @item @emph{Description}:
5542 Returns the position of the start of the first occurrence of string
5543 @var{SUBSTRING} as a substring in @var{STRING}, counting from one. If
5544 @var{SUBSTRING} is not present in @var{STRING}, zero is returned. If
5545 the @var{BACK} argument is present and true, the return value is the
5546 start of the last occurrence rather than the first.
5548 @item @emph{Standard}:
5554 @item @emph{Syntax}:
5555 @code{RESULT = INDEX(STRING, SUBSTRING [, BACK])}
5557 @item @emph{Arguments}:
5558 @multitable @columnfractions .15 .70
5559 @item @var{STRING} @tab Shall be a scalar @code{CHARACTER(*)}, with
5561 @item @var{SUBSTRING} @tab Shall be a scalar @code{CHARACTER(*)}, with
5563 @item @var{BACK} @tab (Optional) Shall be a scalar @code{LOGICAL(*)}, with
5567 @item @emph{Return value}:
5568 The return value is of type @code{INTEGER} and of the default integer
5571 @item @emph{See also}:
5572 @ref{SCAN}, @ref{VERIFY}
5578 @section @code{INT} --- Convert to integer type
5582 @cindex conversion, to integer
5585 @item @emph{Description}:
5586 Convert to integer type
5588 @item @emph{Standard}:
5594 @item @emph{Syntax}:
5595 @code{RESULT = INT(A [, KIND))}
5597 @item @emph{Arguments}:
5598 @multitable @columnfractions .15 .70
5599 @item @var{A} @tab Shall be of type @code{INTEGER(*)},
5600 @code{REAL(*)}, or @code{COMPLEX(*)}.
5601 @item @var{KIND} @tab (Optional) An @code{INTEGER(*)} initialization
5602 expression indicating the kind parameter of
5606 @item @emph{Return value}:
5607 These functions return a @code{INTEGER(*)} variable or array under
5608 the following rules:
5612 If @var{A} is of type @code{INTEGER(*)}, @code{INT(A) = A}
5614 If @var{A} is of type @code{REAL(*)} and @math{|A| < 1}, @code{INT(A)} equals @code{0}.
5615 If @math{|A| \geq 1}, then @code{INT(A)} equals the largest integer that does not exceed
5616 the range of @var{A} and whose sign is the same as the sign of @var{A}.
5618 If @var{A} is of type @code{COMPLEX(*)}, rule B is applied to the real part of @var{A}.
5621 @item @emph{Example}:
5625 complex :: z = (-3.7, 1.0)
5627 print *, int(z), int(z,8)
5631 @item @emph{Specific names}:
5632 @multitable @columnfractions .20 .20 .20 .25
5633 @item Name @tab Argument @tab Return type @tab Standard
5634 @item @code{IFIX(A)} @tab @code{REAL(4) A} @tab @code{INTEGER} @tab F77 and later
5635 @item @code{IDINT(A)} @tab @code{REAL(8) A} @tab @code{INTEGER} @tab F77 and later
5643 @section @code{INT2} --- Convert to 16-bit integer type
5646 @cindex conversion, to integer
5649 @item @emph{Description}:
5650 Convert to a @code{KIND=2} integer type. This is equivalent to the
5651 standard @code{INT} intrinsic with an optional argument of
5652 @code{KIND=2}, and is only included for backwards compatibility.
5654 The @code{SHORT} intrinsic is equivalent to @code{INT2}.
5656 @item @emph{Standard}:
5662 @item @emph{Syntax}:
5663 @code{RESULT = INT2(A)}
5665 @item @emph{Arguments}:
5666 @multitable @columnfractions .15 .70
5667 @item @var{A} @tab Shall be of type @code{INTEGER(*)},
5668 @code{REAL(*)}, or @code{COMPLEX(*)}.
5671 @item @emph{Return value}:
5672 The return value is a @code{INTEGER(2)} variable.
5674 @item @emph{See also}:
5675 @ref{INT}, @ref{INT8}, @ref{LONG}
5681 @section @code{INT8} --- Convert to 64-bit integer type
5683 @cindex conversion, to integer
5686 @item @emph{Description}:
5687 Convert to a @code{KIND=8} integer type. This is equivalent to the
5688 standard @code{INT} intrinsic with an optional argument of
5689 @code{KIND=8}, and is only included for backwards compatibility.
5691 @item @emph{Standard}:
5697 @item @emph{Syntax}:
5698 @code{RESULT = INT8(A)}
5700 @item @emph{Arguments}:
5701 @multitable @columnfractions .15 .70
5702 @item @var{A} @tab Shall be of type @code{INTEGER(*)},
5703 @code{REAL(*)}, or @code{COMPLEX(*)}.
5706 @item @emph{Return value}:
5707 The return value is a @code{INTEGER(8)} variable.
5709 @item @emph{See also}:
5710 @ref{INT}, @ref{INT2}, @ref{LONG}
5716 @section @code{IOR} --- Bitwise logical or
5718 @cindex bitwise logical or
5719 @cindex logical or, bitwise
5722 @item @emph{Description}:
5723 @code{IEOR} returns the bitwise boolean OR of @var{I} and
5726 @item @emph{Standard}:
5732 @item @emph{Syntax}:
5733 @code{RESULT = IEOR(I, J)}
5735 @item @emph{Arguments}:
5736 @multitable @columnfractions .15 .70
5737 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
5738 @item @var{J} @tab The type shall be @code{INTEGER(*)}, of the same
5739 kind as @var{I}. (As a GNU extension, different kinds are also
5743 @item @emph{Return value}:
5744 The return type is @code{INTEGER(*)}, of the same kind as the
5745 arguments. (If the argument kinds differ, it is of the same kind as
5746 the larger argument.)
5748 @item @emph{See also}:
5749 @ref{IEOR}, @ref{IAND}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}, @ref{NOT}
5755 @section @code{IRAND} --- Integer pseudo-random number
5757 @cindex random number generation
5760 @item @emph{Description}:
5761 @code{IRAND(FLAG)} returns a pseudo-random number from a uniform
5762 distribution between 0 and a system-dependent limit (which is in most
5763 cases 2147483647). If @var{FLAG} is 0, the next number
5764 in the current sequence is returned; if @var{FLAG} is 1, the generator
5765 is restarted by @code{CALL SRAND(0)}; if @var{FLAG} has any other value,
5766 it is used as a new seed with @code{SRAND}.
5768 This intrinsic routine is provided for backwards compatibility with
5769 GNU Fortran 77. It implements a simple modulo generator as provided
5770 by @command{g77}. For new code, one should consider the use of
5771 @ref{RANDOM_NUMBER} as it implements a superior algorithm.
5773 @item @emph{Standard}:
5779 @item @emph{Syntax}:
5780 @code{RESULT = IRAND(FLAG)}
5782 @item @emph{Arguments}:
5783 @multitable @columnfractions .15 .70
5784 @item @var{FLAG} @tab Shall be a scalar @code{INTEGER} of kind 4.
5787 @item @emph{Return value}:
5788 The return value is of @code{INTEGER(kind=4)} type.
5790 @item @emph{Example}:
5793 integer,parameter :: seed = 86456
5796 print *, irand(), irand(), irand(), irand()
5797 print *, irand(seed), irand(), irand(), irand()
5798 end program test_irand
5806 @section @code{ISATTY} --- Whether a unit is a terminal device.
5808 @cindex system, terminal
5811 @item @emph{Description}:
5812 Determine whether a unit is connected to a terminal device.
5814 @item @emph{Standard}:
5820 @item @emph{Syntax}:
5821 @code{RESULT = ISATTY(UNIT)}
5823 @item @emph{Arguments}:
5824 @multitable @columnfractions .15 .70
5825 @item @var{UNIT} @tab Shall be a scalar @code{INTEGER(*)}.
5828 @item @emph{Return value}:
5829 Returns @code{.TRUE.} if the @var{UNIT} is connected to a terminal
5830 device, @code{.FALSE.} otherwise.
5832 @item @emph{Example}:
5835 INTEGER(kind=1) :: unit
5837 write(*,*) isatty(unit=unit)
5841 @item @emph{See also}:
5848 @section @code{ISHFT} --- Shift bits
5853 @item @emph{Description}:
5854 @code{ISHFT} returns a value corresponding to @var{I} with all of the
5855 bits shifted @var{SHIFT} places. A value of @var{SHIFT} greater than
5856 zero corresponds to a left shift, a value of zero corresponds to no
5857 shift, and a value less than zero corresponds to a right shift. If the
5858 absolute value of @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the
5859 value is undefined. Bits shifted out from the left end or right end are
5860 lost; zeros are shifted in from the opposite end.
5862 @item @emph{Standard}:
5868 @item @emph{Syntax}:
5869 @code{RESULT = ISHFT(I, SHIFT)}
5871 @item @emph{Arguments}:
5872 @multitable @columnfractions .15 .70
5873 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
5874 @item @var{SHIFT} @tab The type shall be @code{INTEGER(*)}.
5877 @item @emph{Return value}:
5878 The return value is of type @code{INTEGER(*)} and of the same kind as
5881 @item @emph{See also}:
5888 @section @code{ISHFTC} --- Shift bits circularly
5890 @cindex bits, shift circular
5893 @item @emph{Description}:
5894 @code{ISHFTC} returns a value corresponding to @var{I} with the
5895 rightmost @var{SIZE} bits shifted circularly @var{SHIFT} places; that
5896 is, bits shifted out one end are shifted into the opposite end. A value
5897 of @var{SHIFT} greater than zero corresponds to a left shift, a value of
5898 zero corresponds to no shift, and a value less than zero corresponds to
5899 a right shift. The absolute value of @var{SHIFT} must be less than
5900 @var{SIZE}. If the @var{SIZE} argument is omitted, it is taken to be
5901 equivalent to @code{BIT_SIZE(I)}.
5903 @item @emph{Standard}:
5909 @item @emph{Syntax}:
5910 @code{RESULT = ISHFTC(I, SHIFT [, SIZE])}
5912 @item @emph{Arguments}:
5913 @multitable @columnfractions .15 .70
5914 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
5915 @item @var{SHIFT} @tab The type shall be @code{INTEGER(*)}.
5916 @item @var{SIZE} @tab (Optional) The type shall be @code{INTEGER(*)};
5917 the value must be greater than zero and less than or equal to
5921 @item @emph{Return value}:
5922 The return value is of type @code{INTEGER(*)} and of the same kind as
5925 @item @emph{See also}:
5932 @section @code{ISNAN} --- Test for a NaN
5937 @item @emph{Description}:
5938 @code{ISNAN} tests whether a floating-point value is an IEEE
5940 @item @emph{Standard}:
5946 @item @emph{Syntax}:
5949 @item @emph{Arguments}:
5950 @multitable @columnfractions .15 .70
5951 @item @var{X} @tab Variable of the type @code{REAL}.
5955 @item @emph{Return value}:
5956 Returns a default-kind @code{LOGICAL}. The returned value is @code{TRUE}
5957 if @var{X} is a NaN and @code{FALSE} otherwise.
5959 @item @emph{Example}:
5966 if (isnan(x)) stop '"x" is a NaN'
5967 end program test_nan
5974 @section @code{ITIME} --- Get current local time subroutine (hour/minutes/seconds)
5976 @cindex time, current
5977 @cindex current time
5980 @item @emph{Description}:
5981 @code{IDATE(TARRAY)} Fills @var{TARRAY} with the numerical values at the
5982 current local time. The hour (in the range 1-24), minute (in the range 1-60),
5983 and seconds (in the range 1-60) appear in elements 1, 2, and 3 of @var{TARRAY},
5986 @item @emph{Standard}:
5992 @item @emph{Syntax}:
5993 @code{CALL ITIME(TARRAY)}
5995 @item @emph{Arguments}:
5996 @multitable @columnfractions .15 .70
5997 @item @var{TARRAY} @tab The type shall be @code{INTEGER, DIMENSION(3)}
5998 and the kind shall be the default integer kind.
6001 @item @emph{Return value}:
6005 @item @emph{Example}:
6008 integer, dimension(3) :: tarray
6013 end program test_itime
6020 @section @code{KILL} --- Send a signal to a process
6024 @item @emph{Description}:
6025 @item @emph{Standard}:
6026 Sends the signal specified by @var{SIGNAL} to the process @var{PID}.
6029 This intrinsic is provided in both subroutine and function forms; however,
6030 only one form can be used in any given program unit.
6033 Subroutine, function
6035 @item @emph{Syntax}:
6036 @code{CALL KILL(PID, SIGNAL [, STATUS])}
6038 @item @emph{Arguments}:
6039 @multitable @columnfractions .15 .70
6040 @item @var{PID} @tab Shall be a scalar @code{INTEGER}, with
6042 @item @var{SIGNAL} @tab Shall be a scalar @code{INTEGER}, with
6044 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)} or
6045 @code{INTEGER(8)}. Returns 0 on success, or a
6046 system-specific error code otherwise.
6049 @item @emph{See also}:
6050 @ref{ABORT}, @ref{EXIT}
6056 @section @code{KIND} --- Kind of an entity
6061 @item @emph{Description}:
6062 @code{KIND(X)} returns the kind value of the entity @var{X}.
6064 @item @emph{Standard}:
6070 @item @emph{Syntax}:
6073 @item @emph{Arguments}:
6074 @multitable @columnfractions .15 .70
6075 @item @var{X} @tab Shall be of type @code{LOGICAL}, @code{INTEGER},
6076 @code{REAL}, @code{COMPLEX} or @code{CHARACTER}.
6079 @item @emph{Return value}:
6080 The return value is a scalar of type @code{INTEGER} and of the default
6083 @item @emph{Example}:
6086 integer,parameter :: kc = kind(' ')
6087 integer,parameter :: kl = kind(.true.)
6089 print *, "The default character kind is ", kc
6090 print *, "The default logical kind is ", kl
6091 end program test_kind
6099 @section @code{LBOUND} --- Lower dimension bounds of an array
6101 @cindex array, lower bound
6104 @item @emph{Description}:
6105 Returns the lower bounds of an array, or a single lower bound
6106 along the @var{DIM} dimension.
6107 @item @emph{Standard}:
6113 @item @emph{Syntax}:
6114 @code{RESULT = LBOUND(ARRAY [, DIM])}
6116 @item @emph{Arguments}:
6117 @multitable @columnfractions .15 .70
6118 @item @var{ARRAY} @tab Shall be an array, of any type.
6119 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER(*)}.
6122 @item @emph{Return value}:
6123 If @var{DIM} is absent, the result is an array of the lower bounds of
6124 @var{ARRAY}. If @var{DIM} is present, the result is a scalar
6125 corresponding to the lower bound of the array along that dimension. If
6126 @var{ARRAY} is an expression rather than a whole array or array
6127 structure component, or if it has a zero extent along the relevant
6128 dimension, the lower bound is taken to be 1.
6130 @item @emph{See also}:
6137 @section @code{LEN} --- Length of a character entity
6139 @cindex string, length
6142 @item @emph{Description}:
6143 Returns the length of a character string. If @var{STRING} is an array,
6144 the length of an element of @var{STRING} is returned. Note that
6145 @var{STRING} need not be defined when this intrinsic is invoked, since
6146 only the length, not the content, of @var{STRING} is needed.
6148 @item @emph{Standard}:
6154 @item @emph{Syntax}:
6155 @code{L = LEN(STRING)}
6157 @item @emph{Arguments}:
6158 @multitable @columnfractions .15 .70
6159 @item @var{STRING} @tab Shall be a scalar or array of type
6160 @code{CHARACTER(*)}, with @code{INTENT(IN)}
6163 @item @emph{Return value}:
6164 The return value is an @code{INTEGER} of the default kind.
6166 @item @emph{See also}:
6167 @ref{LEN_TRIM}, @ref{ADJUSTL}, @ref{ADJUSTR}
6173 @section @code{LEN_TRIM} --- Length of a character entity without trailing blank characters
6175 @cindex string, length, without trailing whitespace
6178 @item @emph{Description}:
6179 Returns the length of a character string, ignoring any trailing blanks.
6181 @item @emph{Standard}:
6187 @item @emph{Syntax}:
6188 @code{RESULT = LEN_TRIM(STRING)}
6190 @item @emph{Arguments}:
6191 @multitable @columnfractions .15 .70
6192 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER(*)},
6193 with @code{INTENT(IN)}
6196 @item @emph{Return value}:
6197 The return value is an @code{INTEGER} of the default kind.
6199 @item @emph{See also}:
6200 @ref{LEN}, @ref{ADJUSTL}, @ref{ADJUSTR}
6206 @section @code{LGE} --- Lexical greater than or equal
6208 @cindex lexical comparison of strings
6209 @cindex string, comparison
6212 @item @emph{Description}:
6213 Determines whether one string is lexically greater than or equal to
6214 another string, where the two strings are interpreted as containing
6215 ASCII character codes. If the String A and String B are not the same
6216 length, the shorter is compared as if spaces were appended to it to form
6217 a value that has the same length as the longer.
6219 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
6220 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
6221 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
6222 that the latter use the processor's character ordering (which is not
6223 ASCII on some targets), whereas the former always use the ASCII
6226 @item @emph{Standard}:
6232 @item @emph{Syntax}:
6233 @code{RESULT = LGE(STRING_A, STRING_B)}
6235 @item @emph{Arguments}:
6236 @multitable @columnfractions .15 .70
6237 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
6238 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
6241 @item @emph{Return value}:
6242 Returns @code{.TRUE.} if @code{STRING_A >= STRING_B}, and @code{.FALSE.}
6243 otherwise, based on the ASCII ordering.
6245 @item @emph{See also}:
6246 @ref{LGT}, @ref{LLE}, @ref{LLT}
6252 @section @code{LGT} --- Lexical greater than
6254 @cindex lexical comparison of strings
6255 @cindex string, comparison
6258 @item @emph{Description}:
6259 Determines whether one string is lexically greater than another string,
6260 where the two strings are interpreted as containing ASCII character
6261 codes. If the String A and String B are not the same length, the
6262 shorter is compared as if spaces were appended to it to form a value
6263 that has the same length as the longer.
6265 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
6266 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
6267 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
6268 that the latter use the processor's character ordering (which is not
6269 ASCII on some targets), whereas the former always use the ASCII
6272 @item @emph{Standard}:
6278 @item @emph{Syntax}:
6279 @code{RESULT = LGT(STRING_A, STRING_B)}
6281 @item @emph{Arguments}:
6282 @multitable @columnfractions .15 .70
6283 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
6284 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
6287 @item @emph{Return value}:
6288 Returns @code{.TRUE.} if @code{STRING_A > STRING_B}, and @code{.FALSE.}
6289 otherwise, based on the ASCII ordering.
6291 @item @emph{See also}:
6292 @ref{LGE}, @ref{LLE}, @ref{LLT}
6298 @section @code{LINK} --- Create a hard link
6300 @cindex file system, create link
6301 @cindex file system, hard link
6304 @item @emph{Description}:
6305 Makes a (hard) link from file @var{PATH1} to @var{PATH2}. A null
6306 character (@code{CHAR(0)}) can be used to mark the end of the names in
6307 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
6308 names are ignored. If the @var{STATUS} argument is supplied, it
6309 contains 0 on success or a nonzero error code upon return; see
6312 This intrinsic is provided in both subroutine and function forms;
6313 however, only one form can be used in any given program unit.
6315 @item @emph{Standard}:
6319 Subroutine, function
6321 @item @emph{Syntax}:
6322 @multitable @columnfractions .80
6323 @item @code{CALL LINK(PATH1, PATH2 [, STATUS])}
6324 @item @code{STATUS = LINK(PATH1, PATH2)}
6327 @item @emph{Arguments}:
6328 @multitable @columnfractions .15 .70
6329 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
6330 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
6331 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
6334 @item @emph{See also}:
6335 @ref{SYMLNK}, @ref{UNLINK}
6341 @section @code{LLE} --- Lexical less than or equal
6343 @cindex lexical comparison of strings
6344 @cindex string, comparison
6347 @item @emph{Description}:
6348 Determines whether one string is lexically less than or equal to another
6349 string, where the two strings are interpreted as containing ASCII
6350 character codes. If the String A and String B are not the same length,
6351 the shorter is compared as if spaces were appended to it to form a value
6352 that has the same length as the longer.
6354 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
6355 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
6356 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
6357 that the latter use the processor's character ordering (which is not
6358 ASCII on some targets), whereas the former always use the ASCII
6361 @item @emph{Standard}:
6367 @item @emph{Syntax}:
6368 @code{RESULT = LLE(STRING_A, STRING_B)}
6370 @item @emph{Arguments}:
6371 @multitable @columnfractions .15 .70
6372 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
6373 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
6376 @item @emph{Return value}:
6377 Returns @code{.TRUE.} if @code{STRING_A <= STRING_B}, and @code{.FALSE.}
6378 otherwise, based on the ASCII ordering.
6380 @item @emph{See also}:
6381 @ref{LGE}, @ref{LGT}, @ref{LLT}
6387 @section @code{LLT} --- Lexical less than
6389 @cindex lexical comparison of strings
6390 @cindex string, comparison
6393 @item @emph{Description}:
6394 Determines whether one string is lexically less than another string,
6395 where the two strings are interpreted as containing ASCII character
6396 codes. If the String A and String B are not the same length, the
6397 shorter is compared as if spaces were appended to it to form a value
6398 that has the same length as the longer.
6400 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
6401 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
6402 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
6403 that the latter use the processor's character ordering (which is not
6404 ASCII on some targets), whereas the former always use the ASCII
6407 @item @emph{Standard}:
6413 @item @emph{Syntax}:
6414 @code{RESULT = LLT(STRING_A, STRING_B)}
6416 @item @emph{Arguments}:
6417 @multitable @columnfractions .15 .70
6418 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
6419 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
6422 @item @emph{Return value}:
6423 Returns @code{.TRUE.} if @code{STRING_A < STRING_B}, and @code{.FALSE.}
6424 otherwise, based on the ASCII ordering.
6426 @item @emph{See also}:
6427 @ref{LGE}, @ref{LGT}, @ref{LLE}
6433 @section @code{LNBLNK} --- Index of the last non-blank character in a string
6435 @cindex string, find non-blank character
6438 @item @emph{Description}:
6439 Returns the length of a character string, ignoring any trailing blanks.
6440 This is identical to the standard @code{LEN_TRIM} intrinsic, and is only
6441 included for backwards compatibility.
6443 @item @emph{Standard}:
6449 @item @emph{Syntax}:
6450 @code{RESULT = LNBLNK(STRING)}
6452 @item @emph{Arguments}:
6453 @multitable @columnfractions .15 .70
6454 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER(*)},
6455 with @code{INTENT(IN)}
6458 @item @emph{Return value}:
6459 The return value is of @code{INTEGER(kind=4)} type.
6461 @item @emph{See also}:
6462 @ref{INDEX}, @ref{LEN_TRIM}
6468 @section @code{LOC} --- Returns the address of a variable
6470 @cindex location of a variable in memory
6473 @item @emph{Description}:
6474 @code{LOC(X)} returns the address of @var{X} as an integer.
6476 @item @emph{Standard}:
6482 @item @emph{Syntax}:
6483 @code{RESULT = LOC(X)}
6485 @item @emph{Arguments}:
6486 @multitable @columnfractions .15 .70
6487 @item @var{X} @tab Variable of any type.
6490 @item @emph{Return value}:
6491 The return value is of type @code{INTEGER}, with a @code{KIND}
6492 corresponding to the size (in bytes) of a memory address on the target
6495 @item @emph{Example}:
6502 end program test_loc
6509 @section @code{LOG} --- Logarithm function
6516 @cindex exponential function, inverse
6517 @cindex logarithmic function
6520 @item @emph{Description}:
6521 @code{LOG(X)} computes the logarithm of @var{X}.
6523 @item @emph{Standard}:
6529 @item @emph{Syntax}:
6530 @code{RESULT = LOG(X)}
6532 @item @emph{Arguments}:
6533 @multitable @columnfractions .15 .70
6534 @item @var{X} @tab The type shall be @code{REAL(*)} or
6538 @item @emph{Return value}:
6539 The return value is of type @code{REAL(*)} or @code{COMPLEX(*)}.
6540 The kind type parameter is the same as @var{X}.
6542 @item @emph{Example}:
6545 real(8) :: x = 1.0_8
6546 complex :: z = (1.0, 2.0)
6549 end program test_log
6552 @item @emph{Specific names}:
6553 @multitable @columnfractions .20 .20 .20 .25
6554 @item Name @tab Argument @tab Return type @tab Standard
6555 @item @code{ALOG(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab f95, gnu
6556 @item @code{DLOG(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab f95, gnu
6557 @item @code{CLOG(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab f95, gnu
6558 @item @code{ZLOG(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
6559 @item @code{CDLOG(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
6566 @section @code{LOG10} --- Base 10 logarithm function
6570 @cindex exponential function, inverse
6571 @cindex logarithmic function
6574 @item @emph{Description}:
6575 @code{LOG10(X)} computes the base 10 logarithm of @var{X}.
6577 @item @emph{Standard}:
6583 @item @emph{Syntax}:
6584 @code{RESULT = LOG10(X)}
6586 @item @emph{Arguments}:
6587 @multitable @columnfractions .15 .70
6588 @item @var{X} @tab The type shall be @code{REAL(*)}.
6591 @item @emph{Return value}:
6592 The return value is of type @code{REAL(*)} or @code{COMPLEX(*)}.
6593 The kind type parameter is the same as @var{X}.
6595 @item @emph{Example}:
6598 real(8) :: x = 10.0_8
6600 end program test_log10
6603 @item @emph{Specific names}:
6604 @multitable @columnfractions .20 .20 .20 .25
6605 @item Name @tab Argument @tab Return type @tab Standard
6606 @item @code{ALOG10(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab F95 and later
6607 @item @code{DLOG10(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F95 and later
6614 @section @code{LOGICAL} --- Convert to logical type
6616 @cindex conversion, to logical
6619 @item @emph{Description}:
6620 Converts one kind of @code{LOGICAL} variable to another.
6622 @item @emph{Standard}:
6628 @item @emph{Syntax}:
6629 @code{RESULT = LOGICAL(L [, KIND])}
6631 @item @emph{Arguments}:
6632 @multitable @columnfractions .15 .70
6633 @item @var{L} @tab The type shall be @code{LOGICAL(*)}.
6634 @item @var{KIND} @tab (Optional) An @code{INTEGER(*)} initialization
6635 expression indicating the kind parameter of
6639 @item @emph{Return value}:
6640 The return value is a @code{LOGICAL} value equal to @var{L}, with a
6641 kind corresponding to @var{KIND}, or of the default logical kind if
6642 @var{KIND} is not given.
6644 @item @emph{See also}:
6645 @ref{INT}, @ref{REAL}, @ref{CMPLX}
6651 @section @code{LONG} --- Convert to integer type
6653 @cindex conversion, to integer
6656 @item @emph{Description}:
6657 Convert to a @code{KIND=4} integer type, which is the same size as a C
6658 @code{long} integer. This is equivalent to the standard @code{INT}
6659 intrinsic with an optional argument of @code{KIND=4}, and is only
6660 included for backwards compatibility.
6662 @item @emph{Standard}:
6668 @item @emph{Syntax}:
6669 @code{RESULT = LONG(A)}
6671 @item @emph{Arguments}:
6672 @multitable @columnfractions .15 .70
6673 @item @var{A} @tab Shall be of type @code{INTEGER(*)},
6674 @code{REAL(*)}, or @code{COMPLEX(*)}.
6677 @item @emph{Return value}:
6678 The return value is a @code{INTEGER(4)} variable.
6680 @item @emph{See also}:
6681 @ref{INT}, @ref{INT2}, @ref{INT8}
6687 @section @code{LSHIFT} --- Left shift bits
6689 @cindex bits, shift left
6692 @item @emph{Description}:
6693 @code{LSHIFT} returns a value corresponding to @var{I} with all of the
6694 bits shifted left by @var{SHIFT} places. If the absolute value of
6695 @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the value is undefined.
6696 Bits shifted out from the left end are lost; zeros are shifted in from
6699 This function has been superseded by the @code{ISHFT} intrinsic, which
6700 is standard in Fortran 95 and later.
6702 @item @emph{Standard}:
6708 @item @emph{Syntax}:
6709 @code{RESULT = LSHIFT(I, SHIFT)}
6711 @item @emph{Arguments}:
6712 @multitable @columnfractions .15 .70
6713 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
6714 @item @var{SHIFT} @tab The type shall be @code{INTEGER(*)}.
6717 @item @emph{Return value}:
6718 The return value is of type @code{INTEGER(*)} and of the same kind as
6721 @item @emph{See also}:
6722 @ref{ISHFT}, @ref{ISHFTC}, @ref{RSHIFT}
6729 @section @code{LSTAT} --- Get file status
6731 @cindex file system, file status
6734 @item @emph{Description}:
6735 @code{LSTAT} is identical to @ref{STAT}, except that if path is a symbolic link,
6736 then the link itself is statted, not the file that it refers to.
6738 The elements in @code{BUFF} are the same as described by @ref{STAT}.
6740 This intrinsic is provided in both subroutine and function forms; however,
6741 only one form can be used in any given program unit.
6743 @item @emph{Standard}:
6747 Subroutine, function
6749 @item @emph{Syntax}:
6750 @code{CALL LSTAT(FILE, BUFF [, STATUS])}
6752 @item @emph{Arguments}:
6753 @multitable @columnfractions .15 .70
6754 @item @var{FILE} @tab The type shall be @code{CHARACTER(*)}, a valid path within the file system.
6755 @item @var{BUFF} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
6756 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}. Returns 0
6757 on success and a system specific error code otherwise.
6760 @item @emph{Example}:
6761 See @ref{STAT} for an example.
6763 @item @emph{See also}:
6764 To stat an open file: @ref{FSTAT}, to stat a file: @ref{STAT}
6770 @section @code{LTIME} --- Convert time to local time info
6772 @cindex time, conversion to local time info
6775 @item @emph{Description}:
6776 Given a system time value @var{STIME} (as provided by the @code{TIME8()}
6777 intrinsic), fills @var{TARRAY} with values extracted from it appropriate
6778 to the local time zone using @code{localtime(3)}.
6780 @item @emph{Standard}:
6786 @item @emph{Syntax}:
6787 @code{CALL LTIME(STIME, TARRAY)}
6789 @item @emph{Arguments}:
6790 @multitable @columnfractions .15 .70
6791 @item @var{STIME} @tab An @code{INTEGER(*)} scalar expression
6792 corresponding to a system time, with
6794 @item @var{TARRAY} @tab A default @code{INTEGER} array with 9 elements,
6795 with @code{INTENT(OUT)}.
6798 @item @emph{Return value}:
6799 The elements of @var{TARRAY} are assigned as follows:
6801 @item Seconds after the minute, range 0--59 or 0--61 to allow for leap
6803 @item Minutes after the hour, range 0--59
6804 @item Hours past midnight, range 0--23
6805 @item Day of month, range 0--31
6806 @item Number of months since January, range 0--12
6807 @item Years since 1900
6808 @item Number of days since Sunday, range 0--6
6809 @item Days since January 1
6810 @item Daylight savings indicator: positive if daylight savings is in
6811 effect, zero if not, and negative if the information is not
6815 @item @emph{See also}:
6816 @ref{CTIME}, @ref{GMTIME}, @ref{TIME}, @ref{TIME8}
6823 @section @code{MALLOC} --- Allocate dynamic memory
6825 @cindex pointer, cray
6828 @item @emph{Description}:
6829 @code{MALLOC(SIZE)} allocates @var{SIZE} bytes of dynamic memory and
6830 returns the address of the allocated memory. The @code{MALLOC} intrinsic
6831 is an extension intended to be used with Cray pointers, and is provided
6832 in GNU Fortran to allow the user to compile legacy code. For new code
6833 using Fortran 95 pointers, the memory allocation intrinsic is
6836 @item @emph{Standard}:
6842 @item @emph{Syntax}:
6843 @code{PTR = MALLOC(SIZE)}
6845 @item @emph{Arguments}:
6846 @multitable @columnfractions .15 .70
6847 @item @var{SIZE} @tab The type shall be @code{INTEGER(*)}.
6850 @item @emph{Return value}:
6851 The return value is of type @code{INTEGER(K)}, with @var{K} such that
6852 variables of type @code{INTEGER(K)} have the same size as
6853 C pointers (@code{sizeof(void *)}).
6855 @item @emph{Example}:
6856 The following example demonstrates the use of @code{MALLOC} and
6857 @code{FREE} with Cray pointers. This example is intended to run on
6858 32-bit systems, where the default integer kind is suitable to store
6859 pointers; on 64-bit systems, ptr_x would need to be declared as
6860 @code{integer(kind=8)}.
6869 ptr_x = malloc(20*8)
6871 x(i) = sqrt(1.0d0 / i)
6879 end program test_malloc
6882 @item @emph{See also}:
6889 @section @code{MATMUL} --- matrix multiplication
6891 @cindex matrix multiplication
6892 @cindex product, matrix
6895 @item @emph{Description}:
6896 Performs a matrix multiplication on numeric or logical arguments.
6898 @item @emph{Standard}:
6902 Transformational function
6904 @item @emph{Syntax}:
6905 @code{RESULT = MATMUL(MATRIX_A, MATRIX_B)}
6907 @item @emph{Arguments}:
6908 @multitable @columnfractions .15 .70
6909 @item @var{MATRIX_A} @tab An array of @code{INTEGER(*)},
6910 @code{REAL(*)}, @code{COMPLEX(*)}, or
6911 @code{LOGICAL(*)} type, with a rank of
6913 @item @var{MATRIX_B} @tab An array of @code{INTEGER(*)},
6914 @code{REAL(*)}, or @code{COMPLEX(*)} type if
6915 @var{MATRIX_A} is of a numeric type;
6916 otherwise, an array of @code{LOGICAL(*)}
6917 type. The rank shall be one or two, and the
6918 first (or only) dimension of @var{MATRIX_B}
6919 shall be equal to the last (or only)
6920 dimension of @var{MATRIX_A}.
6923 @item @emph{Return value}:
6924 The matrix product of @var{MATRIX_A} and @var{MATRIX_B}. The type and
6925 kind of the result follow the usual type and kind promotion rules, as
6926 for the @code{*} or @code{.AND.} operators.
6928 @item @emph{See also}:
6934 @section @code{MAX} --- Maximum value of an argument list
6941 @cindex maximum value
6944 @item @emph{Description}:
6945 Returns the argument with the largest (most positive) value.
6947 @item @emph{Standard}:
6953 @item @emph{Syntax}:
6954 @code{RESULT = MAX(A1, A2 [, A3 [, ...]])}
6956 @item @emph{Arguments}:
6957 @multitable @columnfractions .15 .70
6958 @item @var{A1} @tab The type shall be @code{INTEGER(*)} or
6960 @item @var{A2}, @var{A3}, ... @tab An expression of the same type and kind
6961 as @var{A1}. (As a GNU extension,
6962 arguments of different kinds are
6966 @item @emph{Return value}:
6967 The return value corresponds to the maximum value among the arguments,
6968 and has the same type and kind as the first argument.
6970 @item @emph{Specific names}:
6971 @multitable @columnfractions .20 .20 .20 .25
6972 @item Name @tab Argument @tab Return type @tab Standard
6973 @item @code{MAX0(I)} @tab @code{INTEGER(4) I} @tab @code{INTEGER(4)} @tab F77 and later
6974 @item @code{AMAX0(I)} @tab @code{INTEGER(4) I} @tab @code{REAL(MAX(X))} @tab F77 and later
6975 @item @code{MAX1(X)} @tab @code{REAL(*) X} @tab @code{INT(MAX(X))} @tab F77 and later
6976 @item @code{AMAX1(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab F77 and later
6977 @item @code{DMAX1(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F77 and later
6980 @item @emph{See also}:
6981 @ref{MAXLOC} @ref{MAXVAL}, @ref{MIN}
6988 @section @code{MAXEXPONENT} --- Maximum exponent of a real kind
6989 @fnindex MAXEXPONENT
6990 @cindex model representation, maximum exponent
6993 @item @emph{Description}:
6994 @code{MAXEXPONENT(X)} returns the maximum exponent in the model of the
6997 @item @emph{Standard}:
7003 @item @emph{Syntax}:
7004 @code{RESULT = MAXEXPONENT(X)}
7006 @item @emph{Arguments}:
7007 @multitable @columnfractions .15 .70
7008 @item @var{X} @tab Shall be of type @code{REAL}.
7011 @item @emph{Return value}:
7012 The return value is of type @code{INTEGER} and of the default integer
7015 @item @emph{Example}:
7021 print *, minexponent(x), maxexponent(x)
7022 print *, minexponent(y), maxexponent(y)
7023 end program exponents
7030 @section @code{MAXLOC} --- Location of the maximum value within an array
7032 @cindex array, location of maximum element
7035 @item @emph{Description}:
7036 Determines the location of the element in the array with the maximum
7037 value, or, if the @var{DIM} argument is supplied, determines the
7038 locations of the maximum element along each row of the array in the
7039 @var{DIM} direction. If @var{MASK} is present, only the elements for
7040 which @var{MASK} is @code{.TRUE.} are considered. If more than one
7041 element in the array has the maximum value, the location returned is
7042 that of the first such element in array element order. If the array has
7043 zero size, or all of the elements of @var{MASK} are @code{.FALSE.}, then
7044 the result is an array of zeroes. Similarly, if @var{DIM} is supplied
7045 and all of the elements of @var{MASK} along a given row are zero, the
7046 result value for that row is zero.
7048 @item @emph{Standard}:
7052 Transformational function
7054 @item @emph{Syntax}:
7055 @multitable @columnfractions .80
7056 @item @code{RESULT = MAXLOC(ARRAY, DIM [, MASK])}
7057 @item @code{RESULT = MAXLOC(ARRAY [, MASK])}
7060 @item @emph{Arguments}:
7061 @multitable @columnfractions .15 .70
7062 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER(*)},
7063 @code{REAL(*)}, or @code{CHARACTER(*)}.
7064 @item @var{DIM} @tab (Optional) Shall be a scalar of type
7065 @code{INTEGER(*)}, with a value between one
7066 and the rank of @var{ARRAY}, inclusive. It
7067 may not be an optional dummy argument.
7068 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL(*)},
7069 and conformable with @var{ARRAY}.
7072 @item @emph{Return value}:
7073 If @var{DIM} is absent, the result is a rank-one array with a length
7074 equal to the rank of @var{ARRAY}. If @var{DIM} is present, the result
7075 is an array with a rank one less than the rank of @var{ARRAY}, and a
7076 size corresponding to the size of @var{ARRAY} with the @var{DIM}
7077 dimension removed. If @var{DIM} is present and @var{ARRAY} has a rank
7078 of one, the result is a scalar. In all cases, the result is of default
7079 @code{INTEGER} type.
7081 @item @emph{See also}:
7082 @ref{MAX}, @ref{MAXVAL}
7089 @section @code{MAXVAL} --- Maximum value of an array
7091 @cindex array, maximum value
7092 @cindex maximum value
7095 @item @emph{Description}:
7096 Determines the maximum value of the elements in an array value, or, if
7097 the @var{DIM} argument is supplied, determines the maximum value along
7098 each row of the array in the @var{DIM} direction. If @var{MASK} is
7099 present, only the elements for which @var{MASK} is @code{.TRUE.} are
7100 considered. If the array has zero size, or all of the elements of
7101 @var{MASK} are @code{.FALSE.}, then the result is the most negative
7102 number of the type and kind of @var{ARRAY} if @var{ARRAY} is numeric, or
7103 a string of nulls if @var{ARRAY} is of character type.
7105 @item @emph{Standard}:
7109 Transformational function
7111 @item @emph{Syntax}:
7112 @multitable @columnfractions .80
7113 @item @code{RESULT = MAXVAL(ARRAY, DIM [, MASK])}
7114 @item @code{RESULT = MAXVAL(ARRAY [, MASK])}
7117 @item @emph{Arguments}:
7118 @multitable @columnfractions .15 .70
7119 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER(*)},
7120 @code{REAL(*)}, or @code{CHARACTER(*)}.
7121 @item @var{DIM} @tab (Optional) Shall be a scalar of type
7122 @code{INTEGER(*)}, with a value between one
7123 and the rank of @var{ARRAY}, inclusive. It
7124 may not be an optional dummy argument.
7125 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL(*)},
7126 and conformable with @var{ARRAY}.
7129 @item @emph{Return value}:
7130 If @var{DIM} is absent, or if @var{ARRAY} has a rank of one, the result
7131 is a scalar. If @var{DIM} is present, the result is an array with a
7132 rank one less than the rank of @var{ARRAY}, and a size corresponding to
7133 the size of @var{ARRAY} with the @var{DIM} dimension removed. In all
7134 cases, the result is of the same type and kind as @var{ARRAY}.
7136 @item @emph{See also}:
7137 @ref{MAX}, @ref{MAXLOC}
7143 @section @code{MCLOCK} --- Time function
7145 @cindex time, clock ticks
7149 @item @emph{Description}:
7150 Returns the number of clock ticks since the start of the process, based
7151 on the UNIX function @code{clock(3)}.
7153 This intrinsic is not fully portable, such as to systems with 32-bit
7154 @code{INTEGER} types but supporting times wider than 32 bits. Therefore,
7155 the values returned by this intrinsic might be, or become, negative, or
7156 numerically less than previous values, during a single run of the
7159 @item @emph{Standard}:
7165 @item @emph{Syntax}:
7166 @code{RESULT = MCLOCK()}
7168 @item @emph{Return value}:
7169 The return value is a scalar of type @code{INTEGER(4)}, equal to the
7170 number of clock ticks since the start of the process, or @code{-1} if
7171 the system does not support @code{clock(3)}.
7173 @item @emph{See also}:
7174 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK}, @ref{TIME}
7181 @section @code{MCLOCK8} --- Time function (64-bit)
7183 @cindex time, clock ticks
7187 @item @emph{Description}:
7188 Returns the number of clock ticks since the start of the process, based
7189 on the UNIX function @code{clock(3)}.
7191 @emph{Warning:} this intrinsic does not increase the range of the timing
7192 values over that returned by @code{clock(3)}. On a system with a 32-bit
7193 @code{clock(3)}, @code{MCLOCK8()} will return a 32-bit value, even though
7194 it is converted to a 64-bit @code{INTEGER(8)} value. That means
7195 overflows of the 32-bit value can still occur. Therefore, the values
7196 returned by this intrinsic might be or become negative or numerically
7197 less than previous values during a single run of the compiled program.
7199 @item @emph{Standard}:
7205 @item @emph{Syntax}:
7206 @code{RESULT = MCLOCK8()}
7208 @item @emph{Return value}:
7209 The return value is a scalar of type @code{INTEGER(8)}, equal to the
7210 number of clock ticks since the start of the process, or @code{-1} if
7211 the system does not support @code{clock(3)}.
7213 @item @emph{See also}:
7214 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK}, @ref{TIME8}
7221 @section @code{MERGE} --- Merge variables
7223 @cindex array, merge arrays
7224 @cindex array, combine arrays
7227 @item @emph{Description}:
7228 Select values from two arrays according to a logical mask. The result
7229 is equal to @var{TSOURCE} if @var{MASK} is @code{.TRUE.}, or equal to
7230 @var{FSOURCE} if it is @code{.FALSE.}.
7232 @item @emph{Standard}:
7238 @item @emph{Syntax}:
7239 @code{RESULT = MERGE(TSOURCE, FSOURCE, MASK)}
7241 @item @emph{Arguments}:
7242 @multitable @columnfractions .15 .70
7243 @item @var{TSOURCE} @tab May be of any type.
7244 @item @var{FSOURCE} @tab Shall be of the same type and type parameters
7246 @item @var{MASK} @tab Shall be of type @code{LOGICAL(*)}.
7249 @item @emph{Return value}:
7250 The result is of the same type and type parameters as @var{TSOURCE}.
7257 @section @code{MIN} --- Minimum value of an argument list
7264 @cindex minimum value
7267 @item @emph{Description}:
7268 Returns the argument with the smallest (most negative) value.
7270 @item @emph{Standard}:
7276 @item @emph{Syntax}:
7277 @code{RESULT = MIN(A1, A2 [, A3, ...])}
7279 @item @emph{Arguments}:
7280 @multitable @columnfractions .15 .70
7281 @item @var{A1} @tab The type shall be @code{INTEGER(*)} or
7283 @item @var{A2}, @var{A3}, ... @tab An expression of the same type and kind
7284 as @var{A1}. (As a GNU extension,
7285 arguments of different kinds are
7289 @item @emph{Return value}:
7290 The return value corresponds to the maximum value among the arguments,
7291 and has the same type and kind as the first argument.
7293 @item @emph{Specific names}:
7294 @multitable @columnfractions .20 .20 .20 .25
7295 @item Name @tab Argument @tab Return type @tab Standard
7296 @item @code{MIN0(I)} @tab @code{INTEGER(4) I} @tab @code{INTEGER(4)} @tab F77 and later
7297 @item @code{AMIN0(I)} @tab @code{INTEGER(4) I} @tab @code{REAL(MIN(X))} @tab F77 and later
7298 @item @code{MIN1(X)} @tab @code{REAL(*) X} @tab @code{INT(MIN(X))} @tab F77 and later
7299 @item @code{AMIN1(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab F77 and later
7300 @item @code{DMIN1(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F77 and later
7303 @item @emph{See also}:
7304 @ref{MAX}, @ref{MINLOC}, @ref{MINVAL}
7310 @section @code{MINEXPONENT} --- Minimum exponent of a real kind
7311 @fnindex MINEXPONENT
7312 @cindex model representation, minimum exponent
7315 @item @emph{Description}:
7316 @code{MINEXPONENT(X)} returns the minimum exponent in the model of the
7319 @item @emph{Standard}:
7325 @item @emph{Syntax}:
7326 @code{RESULT = MINEXPONENT(X)}
7328 @item @emph{Arguments}:
7329 @multitable @columnfractions .15 .70
7330 @item @var{X} @tab Shall be of type @code{REAL}.
7333 @item @emph{Return value}:
7334 The return value is of type @code{INTEGER} and of the default integer
7337 @item @emph{Example}:
7338 See @code{MAXEXPONENT} for an example.
7344 @section @code{MINLOC} --- Location of the minimum value within an array
7346 @cindex array, location of minimum element
7349 @item @emph{Description}:
7350 Determines the location of the element in the array with the minimum
7351 value, or, if the @var{DIM} argument is supplied, determines the
7352 locations of the minimum element along each row of the array in the
7353 @var{DIM} direction. If @var{MASK} is present, only the elements for
7354 which @var{MASK} is @code{.TRUE.} are considered. If more than one
7355 element in the array has the minimum value, the location returned is
7356 that of the first such element in array element order. If the array has
7357 zero size, or all of the elements of @var{MASK} are @code{.FALSE.}, then
7358 the result is an array of zeroes. Similarly, if @var{DIM} is supplied
7359 and all of the elements of @var{MASK} along a given row are zero, the
7360 result value for that row is zero.
7362 @item @emph{Standard}:
7366 Transformational function
7368 @item @emph{Syntax}:
7369 @multitable @columnfractions .80
7370 @item @code{RESULT = MINLOC(ARRAY, DIM [, MASK])}
7371 @item @code{RESULT = MINLOC(ARRAY [, MASK])}
7374 @item @emph{Arguments}:
7375 @multitable @columnfractions .15 .70
7376 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER(*)},
7377 @code{REAL(*)}, or @code{CHARACTER(*)}.
7378 @item @var{DIM} @tab (Optional) Shall be a scalar of type
7379 @code{INTEGER(*)}, with a value between one
7380 and the rank of @var{ARRAY}, inclusive. It
7381 may not be an optional dummy argument.
7382 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL(*)},
7383 and conformable with @var{ARRAY}.
7386 @item @emph{Return value}:
7387 If @var{DIM} is absent, the result is a rank-one array with a length
7388 equal to the rank of @var{ARRAY}. If @var{DIM} is present, the result
7389 is an array with a rank one less than the rank of @var{ARRAY}, and a
7390 size corresponding to the size of @var{ARRAY} with the @var{DIM}
7391 dimension removed. If @var{DIM} is present and @var{ARRAY} has a rank
7392 of one, the result is a scalar. In all cases, the result is of default
7393 @code{INTEGER} type.
7395 @item @emph{See also}:
7396 @ref{MIN}, @ref{MINVAL}
7403 @section @code{MINVAL} --- Minimum value of an array
7405 @cindex array, minimum value
7406 @cindex minimum value
7409 @item @emph{Description}:
7410 Determines the minimum value of the elements in an array value, or, if
7411 the @var{DIM} argument is supplied, determines the minimum value along
7412 each row of the array in the @var{DIM} direction. If @var{MASK} is
7413 present, only the elements for which @var{MASK} is @code{.TRUE.} are
7414 considered. If the array has zero size, or all of the elements of
7415 @var{MASK} are @code{.FALSE.}, then the result is @code{HUGE(ARRAY)} if
7416 @var{ARRAY} is numeric, or a string of @code{CHAR(255)} characters if
7417 @var{ARRAY} is of character type.
7419 @item @emph{Standard}:
7423 Transformational function
7425 @item @emph{Syntax}:
7426 @multitable @columnfractions .80
7427 @item @code{RESULT = MINVAL(ARRAY, DIM [, MASK])}
7428 @item @code{RESULT = MINVAL(ARRAY [, MASK])}
7431 @item @emph{Arguments}:
7432 @multitable @columnfractions .15 .70
7433 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER(*)},
7434 @code{REAL(*)}, or @code{CHARACTER(*)}.
7435 @item @var{DIM} @tab (Optional) Shall be a scalar of type
7436 @code{INTEGER(*)}, with a value between one
7437 and the rank of @var{ARRAY}, inclusive. It
7438 may not be an optional dummy argument.
7439 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL(*)},
7440 and conformable with @var{ARRAY}.
7443 @item @emph{Return value}:
7444 If @var{DIM} is absent, or if @var{ARRAY} has a rank of one, the result
7445 is a scalar. If @var{DIM} is present, the result is an array with a
7446 rank one less than the rank of @var{ARRAY}, and a size corresponding to
7447 the size of @var{ARRAY} with the @var{DIM} dimension removed. In all
7448 cases, the result is of the same type and kind as @var{ARRAY}.
7450 @item @emph{See also}:
7451 @ref{MIN}, @ref{MINLOC}
7458 @section @code{MOD} --- Remainder function
7463 @cindex division, remainder
7466 @item @emph{Description}:
7467 @code{MOD(A,P)} computes the remainder of the division of A by P. It is
7468 calculated as @code{A - (INT(A/P) * P)}.
7470 @item @emph{Standard}:
7476 @item @emph{Syntax}:
7477 @code{RESULT = MOD(A, P)}
7479 @item @emph{Arguments}:
7480 @multitable @columnfractions .15 .70
7481 @item @var{A} @tab Shall be a scalar of type @code{INTEGER} or @code{REAL}
7482 @item @var{P} @tab Shall be a scalar of the same type as @var{A} and not
7486 @item @emph{Return value}:
7487 The kind of the return value is the result of cross-promoting
7488 the kinds of the arguments.
7490 @item @emph{Example}:
7494 print *, mod(17.5,5.5)
7495 print *, mod(17.5d0,5.5)
7496 print *, mod(17.5,5.5d0)
7499 print *, mod(-17.5,5.5)
7500 print *, mod(-17.5d0,5.5)
7501 print *, mod(-17.5,5.5d0)
7504 print *, mod(17.5,-5.5)
7505 print *, mod(17.5d0,-5.5)
7506 print *, mod(17.5,-5.5d0)
7507 end program test_mod
7510 @item @emph{Specific names}:
7511 @multitable @columnfractions .20 .20 .20 .25
7512 @item Name @tab Arguments @tab Return type @tab Standard
7513 @item @code{AMOD(A,P)} @tab @code{REAL(4)} @tab @code{REAL(4)} @tab F95 and later
7514 @item @code{DMOD(A,P)} @tab @code{REAL(8)} @tab @code{REAL(8)} @tab F95 and later
7521 @section @code{MODULO} --- Modulo function
7524 @cindex division, modulo
7527 @item @emph{Description}:
7528 @code{MODULO(A,P)} computes the @var{A} modulo @var{P}.
7530 @item @emph{Standard}:
7536 @item @emph{Syntax}:
7537 @code{RESULT = MODULO(A, P)}
7539 @item @emph{Arguments}:
7540 @multitable @columnfractions .15 .70
7541 @item @var{A} @tab Shall be a scalar of type @code{INTEGER} or @code{REAL}
7542 @item @var{P} @tab Shall be a scalar of the same type and kind as @var{A}
7545 @item @emph{Return value}:
7546 The type and kind of the result are those of the arguments.
7548 @item If @var{A} and @var{P} are of type @code{INTEGER}:
7549 @code{MODULO(A,P)} has the value @var{R} such that @code{A=Q*P+R}, where
7550 @var{Q} is an integer and @var{R} is between 0 (inclusive) and @var{P}
7552 @item If @var{A} and @var{P} are of type @code{REAL}:
7553 @code{MODULO(A,P)} has the value of @code{A - FLOOR (A / P) * P}.
7555 In all cases, if @var{P} is zero the result is processor-dependent.
7557 @item @emph{Example}:
7560 print *, modulo(17,3)
7561 print *, modulo(17.5,5.5)
7563 print *, modulo(-17,3)
7564 print *, modulo(-17.5,5.5)
7566 print *, modulo(17,-3)
7567 print *, modulo(17.5,-5.5)
7576 @section @code{MOVE_ALLOC} --- Move allocation from one object to another
7578 @cindex moving allocation
7579 @cindex allocation, moving
7582 @item @emph{Description}:
7583 @code{MOVE_ALLOC(SRC, DEST)} moves the allocation from @var{SRC} to
7584 @var{DEST}. @var{SRC} will become deallocated in the process.
7586 @item @emph{Standard}:
7592 @item @emph{Syntax}:
7593 @code{CALL MOVE_ALLOC(SRC, DEST)}
7595 @item @emph{Arguments}:
7596 @multitable @columnfractions .15 .70
7597 @item @var{SRC} @tab @code{ALLOCATABLE}, @code{INTENT(INOUT)}, may be
7598 of any type and kind.
7599 @item @var{DEST} @tab @code{ALLOCATABLE}, @code{INTENT(OUT)}, shall be
7600 of the same type, kind and rank as @var{SRC}
7603 @item @emph{Return value}:
7606 @item @emph{Example}:
7608 program test_move_alloc
7609 integer, allocatable :: a(:), b(:)
7613 call move_alloc(a, b)
7614 print *, allocated(a), allocated(b)
7616 end program test_move_alloc
7623 @section @code{MVBITS} --- Move bits from one integer to another
7628 @item @emph{Description}:
7629 Moves @var{LEN} bits from positions @var{FROMPOS} through
7630 @code{FROMPOS+LEN-1} of @var{FROM} to positions @var{TOPOS} through
7631 @code{TOPOS+LEN-1} of @var{TO}. The portion of argument @var{TO} not
7632 affected by the movement of bits is unchanged. The values of
7633 @code{FROMPOS+LEN-1} and @code{TOPOS+LEN-1} must be less than
7634 @code{BIT_SIZE(FROM)}.
7636 @item @emph{Standard}:
7640 Elemental subroutine
7642 @item @emph{Syntax}:
7643 @code{CALL MVBITS(FROM, FROMPOS, LEN, TO, TOPOS)}
7645 @item @emph{Arguments}:
7646 @multitable @columnfractions .15 .70
7647 @item @var{FROM} @tab The type shall be @code{INTEGER(*)}.
7648 @item @var{FROMPOS} @tab The type shall be @code{INTEGER(*)}.
7649 @item @var{LEN} @tab The type shall be @code{INTEGER(*)}.
7650 @item @var{TO} @tab The type shall be @code{INTEGER(*)}, of the
7651 same kind as @var{FROM}.
7652 @item @var{TOPOS} @tab The type shall be @code{INTEGER(*)}.
7655 @item @emph{See also}:
7656 @ref{IBCLR}, @ref{IBSET}, @ref{IBITS}, @ref{IAND}, @ref{IOR}, @ref{IEOR}
7662 @section @code{NEAREST} --- Nearest representable number
7664 @cindex real number, nearest different
7665 @cindex floating point, nearest different
7668 @item @emph{Description}:
7669 @code{NEAREST(X, S)} returns the processor-representable number nearest
7670 to @code{X} in the direction indicated by the sign of @code{S}.
7672 @item @emph{Standard}:
7678 @item @emph{Syntax}:
7679 @code{RESULT = NEAREST(X, S)}
7681 @item @emph{Arguments}:
7682 @multitable @columnfractions .15 .70
7683 @item @var{X} @tab Shall be of type @code{REAL}.
7684 @item @var{S} @tab (Optional) shall be of type @code{REAL} and
7688 @item @emph{Return value}:
7689 The return value is of the same type as @code{X}. If @code{S} is
7690 positive, @code{NEAREST} returns the processor-representable number
7691 greater than @code{X} and nearest to it. If @code{S} is negative,
7692 @code{NEAREST} returns the processor-representable number smaller than
7693 @code{X} and nearest to it.
7695 @item @emph{Example}:
7697 program test_nearest
7699 x = nearest(42.0, 1.0)
7700 y = nearest(42.0, -1.0)
7701 write (*,"(3(G20.15))") x, y, x - y
7702 end program test_nearest
7709 @section @code{NEW_LINE} --- New line character
7712 @cindex output, newline
7715 @item @emph{Description}:
7716 @code{NEW_LINE(C)} returns the new-line character.
7718 @item @emph{Standard}:
7724 @item @emph{Syntax}:
7725 @code{RESULT = NEW_LINE(C)}
7727 @item @emph{Arguments}:
7728 @multitable @columnfractions .15 .70
7729 @item @var{C} @tab The argument shall be a scalar or array of the
7730 type @code{CHARACTER}.
7733 @item @emph{Return value}:
7734 Returns a @var{CHARACTER} scalar of length one with the new-line character of
7735 the same kind as parameter @var{C}.
7737 @item @emph{Example}:
7741 write(*,'(A)') 'This is record 1.'//NEW_LINE('A')//'This is record 2.'
7749 @section @code{NINT} --- Nearest whole number
7752 @cindex rounding, nearest whole number
7755 @item @emph{Description}:
7756 @code{NINT(X)} rounds its argument to the nearest whole number.
7758 @item @emph{Standard}:
7764 @item @emph{Syntax}:
7765 @code{RESULT = NINT(X)}
7767 @item @emph{Arguments}:
7768 @multitable @columnfractions .15 .70
7769 @item @var{X} @tab The type of the argument shall be @code{REAL}.
7772 @item @emph{Return value}:
7773 Returns @var{A} with the fractional portion of its magnitude eliminated by
7774 rounding to the nearest whole number and with its sign preserved,
7775 converted to an @code{INTEGER} of the default kind.
7777 @item @emph{Example}:
7784 print *, nint(x4), idnint(x8)
7785 end program test_nint
7788 @item @emph{Specific names}:
7789 @multitable @columnfractions .25 .25 .25
7790 @item Name @tab Argument @tab Standard
7791 @item @code{IDNINT(X)} @tab @code{REAL(8)} @tab F95 and later
7794 @item @emph{See also}:
7795 @ref{CEILING}, @ref{FLOOR}
7802 @section @code{NOT} --- Logical negation
7804 @cindex bits, negate
7805 @cindex bitwise logical not
7806 @cindex logical not, bitwise
7809 @item @emph{Description}:
7810 @code{NOT} returns the bitwise boolean inverse of @var{I}.
7812 @item @emph{Standard}:
7818 @item @emph{Syntax}:
7819 @code{RESULT = NOT(I)}
7821 @item @emph{Arguments}:
7822 @multitable @columnfractions .15 .70
7823 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
7826 @item @emph{Return value}:
7827 The return type is @code{INTEGER(*)}, of the same kind as the
7830 @item @emph{See also}:
7831 @ref{IAND}, @ref{IEOR}, @ref{IOR}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}
7838 @section @code{NULL} --- Function that returns an disassociated pointer
7840 @cindex pointer, status
7841 @cindex pointer, disassociated
7844 @item @emph{Description}:
7845 Returns a disassociated pointer.
7847 If @var{MOLD} is present, a dissassociated pointer of the same type is
7848 returned, otherwise the type is determined by context.
7850 In Fortran 95, @var{MOLD} is optional. Please note that F2003 includes
7851 cases where it is required.
7853 @item @emph{Standard}:
7857 Transformational function
7859 @item @emph{Syntax}:
7860 @code{PTR => NULL([MOLD])}
7862 @item @emph{Arguments}:
7863 @multitable @columnfractions .15 .70
7864 @item @var{MOLD} @tab (Optional) shall be a pointer of any association
7865 status and of any type.
7868 @item @emph{Return value}:
7869 A disassociated pointer.
7871 @item @emph{Example}:
7873 REAL, POINTER, DIMENSION(:) :: VEC => NULL ()
7876 @item @emph{See also}:
7883 @section @code{OR} --- Bitwise logical OR
7885 @cindex bitwise logical or
7886 @cindex logical or, bitwise
7889 @item @emph{Description}:
7890 Bitwise logical @code{OR}.
7892 This intrinsic routine is provided for backwards compatibility with
7893 GNU Fortran 77. For integer arguments, programmers should consider
7894 the use of the @ref{IOR} intrinsic defined by the Fortran standard.
7896 @item @emph{Standard}:
7902 @item @emph{Syntax}:
7903 @code{RESULT = OR(X, Y)}
7905 @item @emph{Arguments}:
7906 @multitable @columnfractions .15 .70
7907 @item @var{X} @tab The type shall be either @code{INTEGER(*)} or @code{LOGICAL}.
7908 @item @var{Y} @tab The type shall be either @code{INTEGER(*)} or @code{LOGICAL}.
7911 @item @emph{Return value}:
7912 The return type is either @code{INTEGER(*)} or @code{LOGICAL}
7913 after cross-promotion of the arguments.
7915 @item @emph{Example}:
7918 LOGICAL :: T = .TRUE., F = .FALSE.
7920 DATA a / Z'F' /, b / Z'3' /
7922 WRITE (*,*) OR(T, T), OR(T, F), OR(F, T), OR(F, F)
7923 WRITE (*,*) OR(a, b)
7927 @item @emph{See also}:
7928 F95 elemental function: @ref{IOR}
7934 @section @code{PACK} --- Pack an array into an array of rank one
7936 @cindex array, packing
7937 @cindex array, reduce dimension
7938 @cindex array, gather elements
7941 @item @emph{Description}:
7942 Stores the elements of @var{ARRAY} in an array of rank one.
7944 The beginning of the resulting array is made up of elements whose @var{MASK}
7945 equals @code{TRUE}. Afterwards, positions are filled with elements taken from
7948 @item @emph{Standard}:
7952 Transformational function
7954 @item @emph{Syntax}:
7955 @code{RESULT = PACK(ARRAY, MASK[,VECTOR]}
7957 @item @emph{Arguments}:
7958 @multitable @columnfractions .15 .70
7959 @item @var{ARRAY} @tab Shall be an array of any type.
7960 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL} and
7961 of the same size as @var{ARRAY}. Alternatively, it may be a @code{LOGICAL}
7963 @item @var{VECTOR} @tab (Optional) shall be an array of the same type
7964 as @var{ARRAY} and of rank one. If present, the number of elements in
7965 @var{VECTOR} shall be equal to or greater than the number of true elements
7966 in @var{MASK}. If @var{MASK} is scalar, the number of elements in
7967 @var{VECTOR} shall be equal to or greater than the number of elements in
7971 @item @emph{Return value}:
7972 The result is an array of rank one and the same type as that of @var{ARRAY}.
7973 If @var{VECTOR} is present, the result size is that of @var{VECTOR}, the
7974 number of @code{TRUE} values in @var{MASK} otherwise.
7976 @item @emph{Example}:
7977 Gathering nonzero elements from an array:
7981 m = (/ 1, 0, 0, 0, 5, 0 /)
7982 WRITE(*, FMT="(6(I0, ' '))") pack(m, m /= 0) ! "1 5"
7986 Gathering nonzero elements from an array and appending elements from @var{VECTOR}:
7990 m = (/ 1, 0, 0, 2 /)
7991 WRITE(*, FMT="(4(I0, ' '))") pack(m, m /= 0, (/ 0, 0, 3, 4 /)) ! "1 2 3 4"
7995 @item @emph{See also}:
8002 @section @code{PERROR} --- Print system error message
8004 @cindex system, error handling
8007 @item @emph{Description}:
8008 Prints (on the C @code{stderr} stream) a newline-terminated error
8009 message corresponding to the last system error. This is prefixed by
8010 @var{STRING}, a colon and a space. See @code{perror(3)}.
8012 @item @emph{Standard}:
8018 @item @emph{Syntax}:
8019 @code{CALL PERROR(STRING)}
8021 @item @emph{Arguments}:
8022 @multitable @columnfractions .15 .70
8023 @item @var{STRING} @tab A scalar of default @code{CHARACTER} type.
8026 @item @emph{See also}:
8033 @section @code{PRECISION} --- Decimal precision of a real kind
8035 @cindex model representation, precision
8038 @item @emph{Description}:
8039 @code{PRECISION(X)} returns the decimal precision in the model of the
8042 @item @emph{Standard}:
8048 @item @emph{Syntax}:
8049 @code{RESULT = PRECISION(X)}
8051 @item @emph{Arguments}:
8052 @multitable @columnfractions .15 .70
8053 @item @var{X} @tab Shall be of type @code{REAL} or @code{COMPLEX}.
8056 @item @emph{Return value}:
8057 The return value is of type @code{INTEGER} and of the default integer
8060 @item @emph{Example}:
8062 program prec_and_range
8063 real(kind=4) :: x(2)
8064 complex(kind=8) :: y
8066 print *, precision(x), range(x)
8067 print *, precision(y), range(y)
8068 end program prec_and_range
8075 @section @code{PRESENT} --- Determine whether an optional dummy argument is specified
8079 @item @emph{Description}:
8080 Determines whether an optional dummy argument is present.
8082 @item @emph{Standard}:
8088 @item @emph{Syntax}:
8089 @code{RESULT = PRESENT(A)}
8091 @item @emph{Arguments}:
8092 @multitable @columnfractions .15 .70
8093 @item @var{A} @tab May be of any type and may be a pointer, scalar or array
8094 value, or a dummy procedure. It shall be the name of an optional dummy argument
8095 accessible within the current subroutine or function.
8098 @item @emph{Return value}:
8099 Returns either @code{TRUE} if the optional argument @var{A} is present, or
8100 @code{FALSE} otherwise.
8102 @item @emph{Example}:
8104 PROGRAM test_present
8105 WRITE(*,*) f(), f(42) ! "F T"
8107 LOGICAL FUNCTION f(x)
8108 INTEGER, INTENT(IN), OPTIONAL :: x
8118 @section @code{PRODUCT} --- Product of array elements
8120 @cindex array, product
8121 @cindex array, multiply elements
8122 @cindex array, conditionally multiply elements
8123 @cindex multiply array elements
8126 @item @emph{Description}:
8127 Multiplies the elements of @var{ARRAY} along dimension @var{DIM} if
8128 the corresponding element in @var{MASK} is @code{TRUE}.
8130 @item @emph{Standard}:
8134 Transformational function
8136 @item @emph{Syntax}:
8137 @code{RESULT = PRODUCT(ARRAY[, MASK])}
8138 @code{RESULT = PRODUCT(ARRAY, DIM[, MASK])}
8140 @item @emph{Arguments}:
8141 @multitable @columnfractions .15 .70
8142 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER(*)},
8143 @code{REAL(*)} or @code{COMPLEX(*)}.
8144 @item @var{DIM} @tab (Optional) shall be a scalar of type
8145 @code{INTEGER} with a value in the range from 1 to n, where n
8146 equals the rank of @var{ARRAY}.
8147 @item @var{MASK} @tab (Optional) shall be of type @code{LOGICAL}
8148 and either be a scalar or an array of the same shape as @var{ARRAY}.
8151 @item @emph{Return value}:
8152 The result is of the same type as @var{ARRAY}.
8154 If @var{DIM} is absent, a scalar with the product of all elements in
8155 @var{ARRAY} is returned. Otherwise, an array of rank n-1, where n equals
8156 the rank of @var{ARRAY}, and a shape similar to that of @var{ARRAY} with
8157 dimension @var{DIM} dropped is returned.
8160 @item @emph{Example}:
8162 PROGRAM test_product
8163 INTEGER :: x(5) = (/ 1, 2, 3, 4 ,5 /)
8164 print *, PRODUCT(x) ! all elements, product = 120
8165 print *, PRODUCT(x, MASK=MOD(x, 2)==1) ! odd elements, product = 15
8169 @item @emph{See also}:
8176 @section @code{RADIX} --- Base of a model number
8178 @cindex model representation, base
8179 @cindex model representation, radix
8182 @item @emph{Description}:
8183 @code{RADIX(X)} returns the base of the model representing the entity @var{X}.
8185 @item @emph{Standard}:
8191 @item @emph{Syntax}:
8192 @code{RESULT = RADIX(X)}
8194 @item @emph{Arguments}:
8195 @multitable @columnfractions .15 .70
8196 @item @var{X} @tab Shall be of type @code{INTEGER} or @code{REAL}
8199 @item @emph{Return value}:
8200 The return value is a scalar of type @code{INTEGER} and of the default
8203 @item @emph{Example}:
8206 print *, "The radix for the default integer kind is", radix(0)
8207 print *, "The radix for the default real kind is", radix(0.0)
8208 end program test_radix
8216 @section @code{RAN} --- Real pseudo-random number
8218 @cindex random number generation
8221 @item @emph{Description}:
8222 For compatibility with HP FORTRAN 77/iX, the @code{RAN} intrinsic is
8223 provided as an alias for @code{RAND}. See @ref{RAND} for complete
8226 @item @emph{Standard}:
8232 @item @emph{See also}:
8233 @ref{RAND}, @ref{RANDOM_NUMBER}
8239 @section @code{RAND} --- Real pseudo-random number
8241 @cindex random number generation
8244 @item @emph{Description}:
8245 @code{RAND(FLAG)} returns a pseudo-random number from a uniform
8246 distribution between 0 and 1. If @var{FLAG} is 0, the next number
8247 in the current sequence is returned; if @var{FLAG} is 1, the generator
8248 is restarted by @code{CALL SRAND(0)}; if @var{FLAG} has any other value,
8249 it is used as a new seed with @code{SRAND}.
8251 This intrinsic routine is provided for backwards compatibility with
8252 GNU Fortran 77. It implements a simple modulo generator as provided
8253 by @command{g77}. For new code, one should consider the use of
8254 @ref{RANDOM_NUMBER} as it implements a superior algorithm.
8256 @item @emph{Standard}:
8262 @item @emph{Syntax}:
8263 @code{RESULT = RAND(FLAG)}
8265 @item @emph{Arguments}:
8266 @multitable @columnfractions .15 .70
8267 @item @var{FLAG} @tab Shall be a scalar @code{INTEGER} of kind 4.
8270 @item @emph{Return value}:
8271 The return value is of @code{REAL} type and the default kind.
8273 @item @emph{Example}:
8276 integer,parameter :: seed = 86456
8279 print *, rand(), rand(), rand(), rand()
8280 print *, rand(seed), rand(), rand(), rand()
8281 end program test_rand
8284 @item @emph{See also}:
8285 @ref{SRAND}, @ref{RANDOM_NUMBER}
8292 @section @code{RANDOM_NUMBER} --- Pseudo-random number
8293 @fnindex RANDOM_NUMBER
8294 @cindex random number generation
8297 @item @emph{Description}:
8298 Returns a single pseudorandom number or an array of pseudorandom numbers
8299 from the uniform distribution over the range @math{ 0 \leq x < 1}.
8301 The runtime-library implements George Marsaglia's KISS (Keep It Simple
8302 Stupid) random number generator (RNG). This RNG combines:
8304 @item The congruential generator @math{x(n) = 69069 \cdot x(n-1) + 1327217885}
8305 with a period of @math{2^{32}},
8306 @item A 3-shift shift-register generator with a period of @math{2^{32} - 1},
8307 @item Two 16-bit multiply-with-carry generators with a period of
8308 @math{597273182964842497 > 2^{59}}.
8310 The overall period exceeds @math{2^{123}}.
8312 Please note, this RNG is thread safe if used within OpenMP directives,
8313 i. e. its state will be consistent while called from multiple threads.
8314 However, the KISS generator does not create random numbers in parallel
8315 from multiple sources, but in sequence from a single source. If an
8316 OpenMP-enabled application heavily relies on random numbers, one should
8317 consider employing a dedicated parallel random number generator instead.
8319 @item @emph{Standard}:
8325 @item @emph{Syntax}:
8326 @code{RANDOM_NUMBER(HARVEST)}
8328 @item @emph{Arguments}:
8329 @multitable @columnfractions .15 .70
8330 @item @var{HARVEST} @tab Shall be a scalar or an array of type @code{REAL(*)}.
8333 @item @emph{Example}:
8335 program test_random_number
8337 CALL init_random_seed() ! see example of RANDOM_SEED
8338 CALL RANDOM_NUMBER(r)
8342 @item @emph{See also}:
8349 @section @code{RANDOM_SEED} --- Initialize a pseudo-random number sequence
8350 @fnindex RANDOM_SEED
8351 @cindex random number generation, seeding
8352 @cindex seeding a random number generator
8355 @item @emph{Description}:
8356 Restarts or queries the state of the pseudorandom number generator used by
8357 @code{RANDOM_NUMBER}.
8359 If @code{RANDOM_SEED} is called without arguments, it is initialized to
8360 a default state. The example below shows how to initialize the random
8361 seed based on the system's time.
8363 @item @emph{Standard}:
8369 @item @emph{Syntax}:
8370 @code{CALL RANDOM_SEED(SIZE, PUT, GET)}
8372 @item @emph{Arguments}:
8373 @multitable @columnfractions .15 .70
8374 @item @var{SIZE} @tab (Optional) Shall be a scalar and of type default
8375 @code{INTEGER}, with @code{INTENT(OUT)}. It specifies the minimum size
8376 of the arrays used with the @var{PUT} and @var{GET} arguments.
8377 @item @var{PUT} @tab (Optional) Shall be an array of type default
8378 @code{INTEGER} and rank one. It is @code{INTENT(IN)} and the size of
8379 the array must be larger than or equal to the number returned by the
8380 @var{SIZE} argument.
8381 @item @var{GET} @tab (Optional) Shall be an array of type default
8382 @code{INTEGER} and rank one. It is @code{INTENT(OUT)} and the size
8383 of the array must be larger than or equal to the number returned by
8384 the @var{SIZE} argument.
8387 @item @emph{Example}:
8389 SUBROUTINE init_random_seed()
8390 INTEGER :: i, n, clock
8391 INTEGER, DIMENSION(:), ALLOCATABLE :: seed
8393 CALL RANDOM_SEED(size = n)
8396 CALL SYSTEM_CLOCK(COUNT=clock)
8398 seed = clock + 37 * (/ (i - 1, i = 1, n) /)
8399 CALL RANDOM_SEED(PUT = seed)
8405 @item @emph{See also}:
8412 @section @code{RANGE} --- Decimal exponent range of a real kind
8414 @cindex model representation, range
8417 @item @emph{Description}:
8418 @code{RANGE(X)} returns the decimal exponent range in the model of the
8421 @item @emph{Standard}:
8427 @item @emph{Syntax}:
8428 @code{RESULT = RANGE(X)}
8430 @item @emph{Arguments}:
8431 @multitable @columnfractions .15 .70
8432 @item @var{X} @tab Shall be of type @code{REAL} or @code{COMPLEX}.
8435 @item @emph{Return value}:
8436 The return value is of type @code{INTEGER} and of the default integer
8439 @item @emph{Example}:
8440 See @code{PRECISION} for an example.
8446 @section @code{REAL} --- Convert to real type
8449 @cindex conversion, to real
8450 @cindex complex numbers, real part
8453 @item @emph{Description}:
8454 @code{REAL(X [, KIND])} converts its argument @var{X} to a real type. The
8455 @code{REALPART(X)} function is provided for compatibility with @command{g77},
8456 and its use is strongly discouraged.
8458 @item @emph{Standard}:
8464 @item @emph{Syntax}:
8465 @multitable @columnfractions .80
8466 @item @code{RESULT = REAL(X [, KIND])}
8467 @item @code{RESULT = REALPART(Z)}
8470 @item @emph{Arguments}:
8471 @multitable @columnfractions .15 .70
8472 @item @var{X} @tab Shall be @code{INTEGER(*)}, @code{REAL(*)}, or
8474 @item @var{KIND} @tab (Optional) An @code{INTEGER(*)} initialization
8475 expression indicating the kind parameter of
8479 @item @emph{Return value}:
8480 These functions return a @code{REAL(*)} variable or array under
8481 the following rules:
8485 @code{REAL(X)} is converted to a default real type if @var{X} is an
8486 integer or real variable.
8488 @code{REAL(X)} is converted to a real type with the kind type parameter
8489 of @var{X} if @var{X} is a complex variable.
8491 @code{REAL(X, KIND)} is converted to a real type with kind type
8492 parameter @var{KIND} if @var{X} is a complex, integer, or real
8496 @item @emph{Example}:
8499 complex :: x = (1.0, 2.0)
8500 print *, real(x), real(x,8), realpart(x)
8501 end program test_real
8504 @item @emph{See also}:
8505 @ref{DBLE}, @ref{DFLOAT}, @ref{FLOAT}
8512 @section @code{RENAME} --- Rename a file
8514 @cindex file system, rename file
8517 @item @emph{Description}:
8518 Renames a file from file @var{PATH1} to @var{PATH2}. A null
8519 character (@code{CHAR(0)}) can be used to mark the end of the names in
8520 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
8521 names are ignored. If the @var{STATUS} argument is supplied, it
8522 contains 0 on success or a nonzero error code upon return; see
8525 This intrinsic is provided in both subroutine and function forms;
8526 however, only one form can be used in any given program unit.
8528 @item @emph{Standard}:
8532 Subroutine, function
8534 @item @emph{Syntax}:
8535 @multitable @columnfractions .80
8536 @item @code{CALL RENAME(PATH1, PATH2 [, STATUS])}
8537 @item @code{STATUS = RENAME(PATH1, PATH2)}
8540 @item @emph{Arguments}:
8541 @multitable @columnfractions .15 .70
8542 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
8543 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
8544 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
8547 @item @emph{See also}:
8555 @section @code{REPEAT} --- Repeated string concatenation
8557 @cindex string, repeat
8558 @cindex string, concatenate
8561 @item @emph{Description}:
8562 Concatenates @var{NCOPIES} copies of a string.
8564 @item @emph{Standard}:
8568 Transformational function
8570 @item @emph{Syntax}:
8571 @code{RESULT = REPEAT(STRING, NCOPIES)}
8573 @item @emph{Arguments}:
8574 @multitable @columnfractions .15 .70
8575 @item @var{STRING} @tab Shall be scalar and of type @code{CHARACTER(*)}.
8576 @item @var{NCOPIES} @tab Shall be scalar and of type @code{INTEGER(*)}.
8579 @item @emph{Return value}:
8580 A new scalar of type @code{CHARACTER} built up from @var{NCOPIES} copies
8583 @item @emph{Example}:
8586 write(*,*) repeat("x", 5) ! "xxxxx"
8594 @section @code{RESHAPE} --- Function to reshape an array
8596 @cindex array, change dimensions
8597 @cindex array, transmogrify
8600 @item @emph{Description}:
8601 Reshapes @var{SOURCE} to correspond to @var{SHAPE}. If necessary,
8602 the new array may be padded with elements from @var{PAD} or permuted
8603 as defined by @var{ORDER}.
8605 @item @emph{Standard}:
8609 Transformational function
8611 @item @emph{Syntax}:
8612 @code{RESULT = RESHAPE(SOURCE, SHAPE[, PAD, ORDER])}
8614 @item @emph{Arguments}:
8615 @multitable @columnfractions .15 .70
8616 @item @var{SOURCE} @tab Shall be an array of any type.
8617 @item @var{SHAPE} @tab Shall be of type @code{INTEGER} and an
8618 array of rank one. Its values must be positive or zero.
8619 @item @var{PAD} @tab (Optional) shall be an array of the same
8620 type as @var{SOURCE}.
8621 @item @var{ORDER} @tab (Optional) shall be of type @code{INTEGER}
8622 and an array of the same shape as @var{SHAPE}. Its values shall
8623 be a permutation of the numbers from 1 to n, where n is the size of
8624 @var{SHAPE}. If @var{ORDER} is absent, the natural ordering shall
8628 @item @emph{Return value}:
8629 The result is an array of shape @var{SHAPE} with the same type as
8632 @item @emph{Example}:
8634 PROGRAM test_reshape
8635 INTEGER, DIMENSION(4) :: x
8636 WRITE(*,*) SHAPE(x) ! prints "4"
8637 WRITE(*,*) SHAPE(RESHAPE(x, (/2, 2/))) ! prints "2 2"
8641 @item @emph{See also}:
8648 @section @code{RRSPACING} --- Reciprocal of the relative spacing
8650 @cindex real number, relative spacing
8651 @cindex floating point, relative spacing
8655 @item @emph{Description}:
8656 @code{RRSPACING(X)} returns the reciprocal of the relative spacing of
8657 model numbers near @var{X}.
8659 @item @emph{Standard}:
8665 @item @emph{Syntax}:
8666 @code{RESULT = RRSPACING(X)}
8668 @item @emph{Arguments}:
8669 @multitable @columnfractions .15 .70
8670 @item @var{X} @tab Shall be of type @code{REAL}.
8673 @item @emph{Return value}:
8674 The return value is of the same type and kind as @var{X}.
8675 The value returned is equal to
8676 @code{ABS(FRACTION(X)) * FLOAT(RADIX(X))**DIGITS(X)}.
8678 @item @emph{See also}:
8685 @section @code{RSHIFT} --- Right shift bits
8687 @cindex bits, shift right
8690 @item @emph{Description}:
8691 @code{RSHIFT} returns a value corresponding to @var{I} with all of the
8692 bits shifted right by @var{SHIFT} places. If the absolute value of
8693 @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the value is undefined.
8694 Bits shifted out from the left end are lost; zeros are shifted in from
8697 This function has been superseded by the @code{ISHFT} intrinsic, which
8698 is standard in Fortran 95 and later.
8700 @item @emph{Standard}:
8706 @item @emph{Syntax}:
8707 @code{RESULT = RSHIFT(I, SHIFT)}
8709 @item @emph{Arguments}:
8710 @multitable @columnfractions .15 .70
8711 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
8712 @item @var{SHIFT} @tab The type shall be @code{INTEGER(*)}.
8715 @item @emph{Return value}:
8716 The return value is of type @code{INTEGER(*)} and of the same kind as
8719 @item @emph{See also}:
8720 @ref{ISHFT}, @ref{ISHFTC}, @ref{LSHIFT}
8727 @section @code{SCALE} --- Scale a real value
8729 @cindex real number, scale
8730 @cindex floating point, scale
8733 @item @emph{Description}:
8734 @code{SCALE(X,I)} returns @code{X * RADIX(X)**I}.
8736 @item @emph{Standard}:
8742 @item @emph{Syntax}:
8743 @code{RESULT = SCALE(X, I)}
8745 @item @emph{Arguments}:
8746 @multitable @columnfractions .15 .70
8747 @item @var{X} @tab The type of the argument shall be a @code{REAL}.
8748 @item @var{I} @tab The type of the argument shall be a @code{INTEGER}.
8751 @item @emph{Return value}:
8752 The return value is of the same type and kind as @var{X}.
8753 Its value is @code{X * RADIX(X)**I}.
8755 @item @emph{Example}:
8758 real :: x = 178.1387e-4
8760 print *, scale(x,i), x*radix(x)**i
8761 end program test_scale
8769 @section @code{SCAN} --- Scan a string for the presence of a set of characters
8771 @cindex string, find subset
8774 @item @emph{Description}:
8775 Scans a @var{STRING} for any of the characters in a @var{SET}
8778 If @var{BACK} is either absent or equals @code{FALSE}, this function
8779 returns the position of the leftmost character of @var{STRING} that is
8780 in @var{SET}. If @var{BACK} equals @code{TRUE}, the rightmost position
8781 is returned. If no character of @var{SET} is found in @var{STRING}, the
8784 @item @emph{Standard}:
8790 @item @emph{Syntax}:
8791 @code{RESULT = SCAN(STRING, SET[, BACK])}
8793 @item @emph{Arguments}:
8794 @multitable @columnfractions .15 .70
8795 @item @var{STRING} @tab Shall be of type @code{CHARACTER(*)}.
8796 @item @var{SET} @tab Shall be of type @code{CHARACTER(*)}.
8797 @item @var{BACK} @tab (Optional) shall be of type @code{LOGICAL}.
8800 @item @emph{Return value}:
8801 The return value is of type @code{INTEGER} and of the default
8804 @item @emph{Example}:
8807 WRITE(*,*) SCAN("FORTRAN", "AO") ! 2, found 'O'
8808 WRITE(*,*) SCAN("FORTRAN", "AO", .TRUE.) ! 6, found 'A'
8809 WRITE(*,*) SCAN("FORTRAN", "C++") ! 0, found none
8813 @item @emph{See also}:
8814 @ref{INDEX}, @ref{VERIFY}
8820 @section @code{SECNDS} --- Time function
8822 @cindex time, elapsed
8823 @cindex elapsed time
8826 @item @emph{Description}:
8827 @code{SECNDS(X)} gets the time in seconds from the real-time system clock.
8828 @var{X} is a reference time, also in seconds. If this is zero, the time in
8829 seconds from midnight is returned. This function is non-standard and its
8832 @item @emph{Standard}:
8838 @item @emph{Syntax}:
8839 @code{RESULT = SECNDS (X)}
8841 @item @emph{Arguments}:
8842 @multitable @columnfractions .15 .70
8843 @item @var{T} @tab Shall be of type @code{REAL(4)}.
8844 @item @var{X} @tab Shall be of type @code{REAL(4)}.
8847 @item @emph{Return value}:
8850 @item @emph{Example}:
8855 print *, secnds (0.0) ! seconds since midnight
8856 t1 = secnds (0.0) ! reference time
8857 do i = 1, 10000000 ! do something
8859 t2 = secnds (t1) ! elapsed time
8860 print *, "Something took ", t2, " seconds."
8861 end program test_secnds
8868 @section @code{SECOND} --- CPU time function
8870 @cindex time, elapsed
8871 @cindex elapsed time
8874 @item @emph{Description}:
8875 Returns a @code{REAL(4)} value representing the elapsed CPU time in
8876 seconds. This provides the same functionality as the standard
8877 @code{CPU_TIME} intrinsic, and is only included for backwards
8880 This intrinsic is provided in both subroutine and function forms;
8881 however, only one form can be used in any given program unit.
8883 @item @emph{Standard}:
8887 Subroutine, function
8889 @item @emph{Syntax}:
8890 @multitable @columnfractions .80
8891 @item @code{CALL SECOND(TIME)}
8892 @item @code{TIME = SECOND()}
8895 @item @emph{Arguments}:
8896 @multitable @columnfractions .15 .70
8897 @item @var{TIME} @tab Shall be of type @code{REAL(4)}.
8900 @item @emph{Return value}:
8901 In either syntax, @var{TIME} is set to the process's current runtime in
8904 @item @emph{See also}:
8911 @node SELECTED_INT_KIND
8912 @section @code{SELECTED_INT_KIND} --- Choose integer kind
8913 @fnindex SELECTED_INT_KIND
8914 @cindex integer kind
8915 @cindex kind, integer
8918 @item @emph{Description}:
8919 @code{SELECTED_INT_KIND(I)} return the kind value of the smallest integer
8920 type that can represent all values ranging from @math{-10^I} (exclusive)
8921 to @math{10^I} (exclusive). If there is no integer kind that accommodates
8922 this range, @code{SELECTED_INT_KIND} returns @math{-1}.
8924 @item @emph{Standard}:
8928 Transformational function
8930 @item @emph{Syntax}:
8931 @code{RESULT = SELECTED_INT_KIND(I)}
8933 @item @emph{Arguments}:
8934 @multitable @columnfractions .15 .70
8935 @item @var{I} @tab Shall be a scalar and of type @code{INTEGER}.
8938 @item @emph{Example}:
8940 program large_integers
8941 integer,parameter :: k5 = selected_int_kind(5)
8942 integer,parameter :: k15 = selected_int_kind(15)
8943 integer(kind=k5) :: i5
8944 integer(kind=k15) :: i15
8946 print *, huge(i5), huge(i15)
8948 ! The following inequalities are always true
8949 print *, huge(i5) >= 10_k5**5-1
8950 print *, huge(i15) >= 10_k15**15-1
8951 end program large_integers
8957 @node SELECTED_REAL_KIND
8958 @section @code{SELECTED_REAL_KIND} --- Choose real kind
8959 @fnindex SELECTED_REAL_KIND
8964 @item @emph{Description}:
8965 @code{SELECTED_REAL_KIND(P,R)} return the kind value of a real data type
8966 with decimal precision greater of at least @code{P} digits and exponent
8967 range greater at least @code{R}.
8969 @item @emph{Standard}:
8973 Transformational function
8975 @item @emph{Syntax}:
8976 @code{RESULT = SELECTED_REAL_KIND(P, R)}
8978 @item @emph{Arguments}:
8979 @multitable @columnfractions .15 .70
8980 @item @var{P} @tab (Optional) shall be a scalar and of type @code{INTEGER}.
8981 @item @var{R} @tab (Optional) shall be a scalar and of type @code{INTEGER}.
8983 At least one argument shall be present.
8985 @item @emph{Return value}:
8987 @code{SELECTED_REAL_KIND} returns the value of the kind type parameter of
8988 a real data type with decimal precision of at least @code{P} digits and a
8989 decimal exponent range of at least @code{R}. If more than one real data
8990 type meet the criteria, the kind of the data type with the smallest
8991 decimal precision is returned. If no real data type matches the criteria,
8994 @item -1 if the processor does not support a real data type with a
8995 precision greater than or equal to @code{P}
8996 @item -2 if the processor does not support a real type with an exponent
8997 range greater than or equal to @code{R}
8998 @item -3 if neither is supported.
9001 @item @emph{Example}:
9004 integer,parameter :: p6 = selected_real_kind(6)
9005 integer,parameter :: p10r100 = selected_real_kind(10,100)
9006 integer,parameter :: r400 = selected_real_kind(r=400)
9008 real(kind=p10r100) :: y
9009 real(kind=r400) :: z
9011 print *, precision(x), range(x)
9012 print *, precision(y), range(y)
9013 print *, precision(z), range(z)
9014 end program real_kinds
9021 @section @code{SET_EXPONENT} --- Set the exponent of the model
9022 @fnindex SET_EXPONENT
9023 @cindex real number, set exponent
9024 @cindex floating point, set exponent
9027 @item @emph{Description}:
9028 @code{SET_EXPONENT(X, I)} returns the real number whose fractional part
9029 is that that of @var{X} and whose exponent part is @var{I}.
9031 @item @emph{Standard}:
9037 @item @emph{Syntax}:
9038 @code{RESULT = SET_EXPONENT(X, I)}
9040 @item @emph{Arguments}:
9041 @multitable @columnfractions .15 .70
9042 @item @var{X} @tab Shall be of type @code{REAL}.
9043 @item @var{I} @tab Shall be of type @code{INTEGER}.
9046 @item @emph{Return value}:
9047 The return value is of the same type and kind as @var{X}.
9048 The real number whose fractional part
9049 is that that of @var{X} and whose exponent part if @var{I} is returned;
9050 it is @code{FRACTION(X) * RADIX(X)**I}.
9052 @item @emph{Example}:
9055 REAL :: x = 178.1387e-4
9057 PRINT *, SET_EXPONENT(x, i), FRACTION(x) * RADIX(x)**i
9066 @section @code{SHAPE} --- Determine the shape of an array
9068 @cindex array, shape
9071 @item @emph{Description}:
9072 Determines the shape of an array.
9074 @item @emph{Standard}:
9080 @item @emph{Syntax}:
9081 @code{RESULT = SHAPE(SOURCE)}
9083 @item @emph{Arguments}:
9084 @multitable @columnfractions .15 .70
9085 @item @var{SOURCE} @tab Shall be an array or scalar of any type.
9086 If @var{SOURCE} is a pointer it must be associated and allocatable
9087 arrays must be allocated.
9090 @item @emph{Return value}:
9091 An @code{INTEGER} array of rank one with as many elements as @var{SOURCE}
9092 has dimensions. The elements of the resulting array correspond to the extend
9093 of @var{SOURCE} along the respective dimensions. If @var{SOURCE} is a scalar,
9094 the result is the rank one array of size zero.
9096 @item @emph{Example}:
9099 INTEGER, DIMENSION(-1:1, -1:2) :: A
9100 WRITE(*,*) SHAPE(A) ! (/ 3, 4 /)
9101 WRITE(*,*) SIZE(SHAPE(42)) ! (/ /)
9105 @item @emph{See also}:
9106 @ref{RESHAPE}, @ref{SIZE}
9112 @section @code{SIGN} --- Sign copying function
9116 @cindex sign copying
9119 @item @emph{Description}:
9120 @code{SIGN(A,B)} returns the value of @var{A} with the sign of @var{B}.
9122 @item @emph{Standard}:
9128 @item @emph{Syntax}:
9129 @code{RESULT = SIGN(A, B)}
9131 @item @emph{Arguments}:
9132 @multitable @columnfractions .15 .70
9133 @item @var{A} @tab Shall be of type @code{INTEGER} or @code{REAL}
9134 @item @var{B} @tab Shall be of the same type and kind as @var{A}
9137 @item @emph{Return value}:
9138 The kind of the return value is that of @var{A} and @var{B}.
9139 If @math{B\ge 0} then the result is @code{ABS(A)}, else
9140 it is @code{-ABS(A)}.
9142 @item @emph{Example}:
9145 print *, sign(-12,1)
9146 print *, sign(-12,0)
9147 print *, sign(-12,-1)
9149 print *, sign(-12.,1.)
9150 print *, sign(-12.,0.)
9151 print *, sign(-12.,-1.)
9152 end program test_sign
9155 @item @emph{Specific names}:
9156 @multitable @columnfractions .20 .20 .20 .25
9157 @item Name @tab Arguments @tab Return type @tab Standard
9158 @item @code{ISIGN(A,P)} @tab @code{INTEGER(4)} @tab @code{INTEGER(4)} @tab f95, gnu
9159 @item @code{DSIGN(A,P)} @tab @code{REAL(8)} @tab @code{REAL(8)} @tab f95, gnu
9166 @section @code{SIGNAL} --- Signal handling subroutine (or function)
9168 @cindex system, signal handling
9171 @item @emph{Description}:
9172 @code{SIGNAL(NUMBER, HANDLER [, STATUS])} causes external subroutine
9173 @var{HANDLER} to be executed with a single integer argument when signal
9174 @var{NUMBER} occurs. If @var{HANDLER} is an integer, it can be used to
9175 turn off handling of signal @var{NUMBER} or revert to its default
9176 action. See @code{signal(2)}.
9178 If @code{SIGNAL} is called as a subroutine and the @var{STATUS} argument
9179 is supplied, it is set to the value returned by @code{signal(2)}.
9181 @item @emph{Standard}:
9185 Subroutine, function
9187 @item @emph{Syntax}:
9188 @multitable @columnfractions .80
9189 @item @code{CALL SIGNAL(NUMBER, HANDLER [, STATUS])}
9190 @item @code{STATUS = SIGNAL(NUMBER, HANDLER)}
9193 @item @emph{Arguments}:
9194 @multitable @columnfractions .15 .70
9195 @item @var{NUMBER} @tab Shall be a scalar integer, with @code{INTENT(IN)}
9196 @item @var{HANDLER}@tab Signal handler (@code{INTEGER FUNCTION} or
9197 @code{SUBROUTINE}) or dummy/global @code{INTEGER} scalar.
9198 @code{INTEGER}. It is @code{INTENT(IN)}.
9199 @item @var{STATUS} @tab (Optional) @var{STATUS} shall be a scalar
9200 integer. It has @code{INTENT(OUT)}.
9203 @item @emph{Return value}:
9204 The @code{SIGNAL} function returns the value returned by @code{signal(2)}.
9206 @item @emph{Example}:
9210 external handler_print
9212 call signal (12, handler_print)
9216 end program test_signal
9223 @section @code{SIN} --- Sine function
9229 @cindex trigonometric function, sine
9233 @item @emph{Description}:
9234 @code{SIN(X)} computes the sine of @var{X}.
9236 @item @emph{Standard}:
9242 @item @emph{Syntax}:
9243 @code{RESULT = SIN(X)}
9245 @item @emph{Arguments}:
9246 @multitable @columnfractions .15 .70
9247 @item @var{X} @tab The type shall be @code{REAL(*)} or
9251 @item @emph{Return value}:
9252 The return value has same type and kind as @var{X}.
9254 @item @emph{Example}:
9259 end program test_sin
9262 @item @emph{Specific names}:
9263 @multitable @columnfractions .20 .20 .20 .25
9264 @item Name @tab Argument @tab Return type @tab Standard
9265 @item @code{DSIN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab f95, gnu
9266 @item @code{CSIN(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab f95, gnu
9267 @item @code{ZSIN(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
9268 @item @code{CDSIN(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
9271 @item @emph{See also}:
9278 @section @code{SINH} --- Hyperbolic sine function
9281 @cindex hyperbolic sine
9282 @cindex hyperbolic function, sine
9283 @cindex sine, hyperbolic
9286 @item @emph{Description}:
9287 @code{SINH(X)} computes the hyperbolic sine of @var{X}.
9289 @item @emph{Standard}:
9295 @item @emph{Syntax}:
9296 @code{RESULT = SINH(X)}
9298 @item @emph{Arguments}:
9299 @multitable @columnfractions .15 .70
9300 @item @var{X} @tab The type shall be @code{REAL(*)}.
9303 @item @emph{Return value}:
9304 The return value is of type @code{REAL(*)}.
9306 @item @emph{Example}:
9309 real(8) :: x = - 1.0_8
9311 end program test_sinh
9314 @item @emph{Specific names}:
9315 @multitable @columnfractions .20 .20 .20 .25
9316 @item Name @tab Argument @tab Return type @tab Standard
9317 @item @code{DSINH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F95 and later
9320 @item @emph{See also}:
9327 @section @code{SIZE} --- Determine the size of an array
9330 @cindex array, number of elements
9331 @cindex array, count elements
9334 @item @emph{Description}:
9335 Determine the extent of @var{ARRAY} along a specified dimension @var{DIM},
9336 or the total number of elements in @var{ARRAY} if @var{DIM} is absent.
9338 @item @emph{Standard}:
9344 @item @emph{Syntax}:
9345 @code{RESULT = SIZE(ARRAY[, DIM])}
9347 @item @emph{Arguments}:
9348 @multitable @columnfractions .15 .70
9349 @item @var{ARRAY} @tab Shall be an array of any type. If @var{ARRAY} is
9350 a pointer it must be associated and allocatable arrays must be allocated.
9351 @item @var{DIM} @tab (Optional) shall be a scalar of type @code{INTEGER}
9352 and its value shall be in the range from 1 to n, where n equals the rank
9356 @item @emph{Return value}:
9357 The return value is of type @code{INTEGER} and of the default
9360 @item @emph{Example}:
9363 WRITE(*,*) SIZE((/ 1, 2 /)) ! 2
9367 @item @emph{See also}:
9368 @ref{SHAPE}, @ref{RESHAPE}
9373 @section @code{SIZEOF} --- Size in bytes of an expression
9375 @cindex expression size
9376 @cindex size of an expression
9379 @item @emph{Description}:
9380 @code{SIZEOF(X)} calculates the number of bytes of storage the
9381 expression @code{X} occupies.
9383 @item @emph{Standard}:
9389 @item @emph{Syntax}:
9390 @code{N = SIZEOF(X)}
9392 @item @emph{Arguments}:
9393 @multitable @columnfractions .15 .70
9394 @item @var{X} @tab The argument shall be of any type, rank or shape.
9397 @item @emph{Return value}:
9398 The return value is of type integer and of the system-dependent kind
9399 @var{C_SIZE_T} (from the @var{ISO_C_BINDING} module). Its value is the
9400 number of bytes occupied by the argument. If the argument has the
9401 @code{POINTER} attribute, the number of bytes of the storage area pointed
9402 to is returned. If the argument is of a derived type with @code{POINTER}
9403 or @code{ALLOCATABLE} components, the return value doesn't account for
9404 the sizes of the data pointed to by these components.
9406 @item @emph{Example}:
9410 print *, (sizeof(s)/sizeof(r) == 5)
9413 The example will print @code{.TRUE.} unless you are using a platform
9414 where default @code{REAL} variables are unusually padded.
9418 @section @code{SLEEP} --- Sleep for the specified number of seconds
9420 @cindex delayed execution
9423 @item @emph{Description}:
9424 Calling this subroutine causes the process to pause for @var{SECONDS} seconds.
9426 @item @emph{Standard}:
9432 @item @emph{Syntax}:
9433 @code{CALL SLEEP(SECONDS)}
9435 @item @emph{Arguments}:
9436 @multitable @columnfractions .15 .70
9437 @item @var{SECONDS} @tab The type shall be of default @code{INTEGER}.
9440 @item @emph{Example}:
9451 @section @code{SNGL} --- Convert double precision real to default real
9453 @cindex conversion, to real
9456 @item @emph{Description}:
9457 @code{SNGL(A)} converts the double precision real @var{A}
9458 to a default real value. This is an archaic form of @code{REAL}
9459 that is specific to one type for @var{A}.
9461 @item @emph{Standard}:
9467 @item @emph{Syntax}:
9468 @code{RESULT = SNGL(A)}
9470 @item @emph{Arguments}:
9471 @multitable @columnfractions .15 .70
9472 @item @var{A} @tab The type shall be a double precision @code{REAL}.
9475 @item @emph{Return value}:
9476 The return value is of type default @code{REAL}.
9478 @item @emph{See also}:
9485 @section @code{SPACING} --- Smallest distance between two numbers of a given type
9487 @cindex real number, relative spacing
9488 @cindex floating point, relative spacing
9491 @item @emph{Description}:
9492 Determines the distance between the argument @var{X} and the nearest
9493 adjacent number of the same type.
9495 @item @emph{Standard}:
9501 @item @emph{Syntax}:
9502 @code{RESULT = SPACING(X)}
9504 @item @emph{Arguments}:
9505 @multitable @columnfractions .15 .70
9506 @item @var{X} @tab Shall be of type @code{REAL(*)}.
9509 @item @emph{Return value}:
9510 The result is of the same type as the input argument @var{X}.
9512 @item @emph{Example}:
9514 PROGRAM test_spacing
9515 INTEGER, PARAMETER :: SGL = SELECTED_REAL_KIND(p=6, r=37)
9516 INTEGER, PARAMETER :: DBL = SELECTED_REAL_KIND(p=13, r=200)
9518 WRITE(*,*) spacing(1.0_SGL) ! "1.1920929E-07" on i686
9519 WRITE(*,*) spacing(1.0_DBL) ! "2.220446049250313E-016" on i686
9523 @item @emph{See also}:
9530 @section @code{SPREAD} --- Add a dimension to an array
9532 @cindex array, increase dimension
9533 @cindex array, duplicate elements
9534 @cindex array, duplicate dimensions
9537 @item @emph{Description}:
9538 Replicates a @var{SOURCE} array @var{NCOPIES} times along a specified
9539 dimension @var{DIM}.
9541 @item @emph{Standard}:
9545 Transformational function
9547 @item @emph{Syntax}:
9548 @code{RESULT = SPREAD(SOURCE, DIM, NCOPIES)}
9550 @item @emph{Arguments}:
9551 @multitable @columnfractions .15 .70
9552 @item @var{SOURCE} @tab Shall be a scalar or an array of any type and
9553 a rank less than seven.
9554 @item @var{DIM} @tab Shall be a scalar of type @code{INTEGER} with a
9555 value in the range from 1 to n+1, where n equals the rank of @var{SOURCE}.
9556 @item @var{NCOPIES} @tab Shall be a scalar of type @code{INTEGER}.
9559 @item @emph{Return value}:
9560 The result is an array of the same type as @var{SOURCE} and has rank n+1
9561 where n equals the rank of @var{SOURCE}.
9563 @item @emph{Example}:
9566 INTEGER :: a = 1, b(2) = (/ 1, 2 /)
9567 WRITE(*,*) SPREAD(A, 1, 2) ! "1 1"
9568 WRITE(*,*) SPREAD(B, 1, 2) ! "1 1 2 2"
9572 @item @emph{See also}:
9579 @section @code{SQRT} --- Square-root function
9589 @item @emph{Description}:
9590 @code{SQRT(X)} computes the square root of @var{X}.
9592 @item @emph{Standard}:
9598 @item @emph{Syntax}:
9599 @code{RESULT = SQRT(X)}
9601 @item @emph{Arguments}:
9602 @multitable @columnfractions .15 .70
9603 @item @var{X} @tab The type shall be @code{REAL(*)} or
9607 @item @emph{Return value}:
9608 The return value is of type @code{REAL(*)} or @code{COMPLEX(*)}.
9609 The kind type parameter is the same as @var{X}.
9611 @item @emph{Example}:
9614 real(8) :: x = 2.0_8
9615 complex :: z = (1.0, 2.0)
9618 end program test_sqrt
9621 @item @emph{Specific names}:
9622 @multitable @columnfractions .20 .20 .20 .25
9623 @item Name @tab Argument @tab Return type @tab Standard
9624 @item @code{DSQRT(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F95 and later
9625 @item @code{CSQRT(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab F95 and later
9626 @item @code{ZSQRT(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
9627 @item @code{CDSQRT(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
9634 @section @code{SRAND} --- Reinitialize the random number generator
9636 @cindex random number generation, seeding
9637 @cindex seeding a random number generator
9640 @item @emph{Description}:
9641 @code{SRAND} reinitializes the pseudo-random number generator
9642 called by @code{RAND} and @code{IRAND}. The new seed used by the
9643 generator is specified by the required argument @var{SEED}.
9645 @item @emph{Standard}:
9651 @item @emph{Syntax}:
9652 @code{CALL SRAND(SEED)}
9654 @item @emph{Arguments}:
9655 @multitable @columnfractions .15 .70
9656 @item @var{SEED} @tab Shall be a scalar @code{INTEGER(kind=4)}.
9659 @item @emph{Return value}:
9662 @item @emph{Example}:
9663 See @code{RAND} and @code{IRAND} for examples.
9666 The Fortran 2003 standard specifies the intrinsic @code{RANDOM_SEED} to
9667 initialize the pseudo-random numbers generator and @code{RANDOM_NUMBER}
9668 to generate pseudo-random numbers. Please note that in
9669 GNU Fortran, these two sets of intrinsics (@code{RAND},
9670 @code{IRAND} and @code{SRAND} on the one hand, @code{RANDOM_NUMBER} and
9671 @code{RANDOM_SEED} on the other hand) access two independent
9672 pseudo-random number generators.
9674 @item @emph{See also}:
9675 @ref{RAND}, @ref{RANDOM_SEED}, @ref{RANDOM_NUMBER}
9682 @section @code{STAT} --- Get file status
9684 @cindex file system, file status
9687 @item @emph{Description}:
9688 This function returns information about a file. No permissions are required on
9689 the file itself, but execute (search) permission is required on all of the
9690 directories in path that lead to the file.
9692 The elements that are obtained and stored in the array @code{BUFF}:
9693 @multitable @columnfractions .15 .70
9694 @item @code{buff(1)} @tab Device ID
9695 @item @code{buff(2)} @tab Inode number
9696 @item @code{buff(3)} @tab File mode
9697 @item @code{buff(4)} @tab Number of links
9698 @item @code{buff(5)} @tab Owner's uid
9699 @item @code{buff(6)} @tab Owner's gid
9700 @item @code{buff(7)} @tab ID of device containing directory entry for file (0 if not available)
9701 @item @code{buff(8)} @tab File size (bytes)
9702 @item @code{buff(9)} @tab Last access time
9703 @item @code{buff(10)} @tab Last modification time
9704 @item @code{buff(11)} @tab Last file status change time
9705 @item @code{buff(12)} @tab Preferred I/O block size (-1 if not available)
9706 @item @code{buff(13)} @tab Number of blocks allocated (-1 if not available)
9709 Not all these elements are relevant on all systems.
9710 If an element is not relevant, it is returned as 0.
9712 This intrinsic is provided in both subroutine and function forms; however,
9713 only one form can be used in any given program unit.
9715 @item @emph{Standard}:
9719 Subroutine, function
9721 @item @emph{Syntax}:
9722 @code{CALL STAT(FILE,BUFF[,STATUS])}
9724 @item @emph{Arguments}:
9725 @multitable @columnfractions .15 .70
9726 @item @var{FILE} @tab The type shall be @code{CHARACTER(*)}, a valid path within the file system.
9727 @item @var{BUFF} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
9728 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}. Returns 0
9729 on success and a system specific error code otherwise.
9732 @item @emph{Example}:
9735 INTEGER, DIMENSION(13) :: buff
9738 CALL STAT("/etc/passwd", buff, status)
9740 IF (status == 0) THEN
9741 WRITE (*, FMT="('Device ID:', T30, I19)") buff(1)
9742 WRITE (*, FMT="('Inode number:', T30, I19)") buff(2)
9743 WRITE (*, FMT="('File mode (octal):', T30, O19)") buff(3)
9744 WRITE (*, FMT="('Number of links:', T30, I19)") buff(4)
9745 WRITE (*, FMT="('Owner''s uid:', T30, I19)") buff(5)
9746 WRITE (*, FMT="('Owner''s gid:', T30, I19)") buff(6)
9747 WRITE (*, FMT="('Device where located:', T30, I19)") buff(7)
9748 WRITE (*, FMT="('File size:', T30, I19)") buff(8)
9749 WRITE (*, FMT="('Last access time:', T30, A19)") CTIME(buff(9))
9750 WRITE (*, FMT="('Last modification time', T30, A19)") CTIME(buff(10))
9751 WRITE (*, FMT="('Last status change time:', T30, A19)") CTIME(buff(11))
9752 WRITE (*, FMT="('Preferred block size:', T30, I19)") buff(12)
9753 WRITE (*, FMT="('No. of blocks allocated:', T30, I19)") buff(13)
9758 @item @emph{See also}:
9759 To stat an open file: @ref{FSTAT}, to stat a link: @ref{LSTAT}
9765 @section @code{SUM} --- Sum of array elements
9768 @cindex array, add elements
9769 @cindex array, conditionally add elements
9770 @cindex sum array elements
9773 @item @emph{Description}:
9774 Adds the elements of @var{ARRAY} along dimension @var{DIM} if
9775 the corresponding element in @var{MASK} is @code{TRUE}.
9777 @item @emph{Standard}:
9781 Transformational function
9783 @item @emph{Syntax}:
9784 @code{RESULT = SUM(ARRAY[, MASK])}
9785 @code{RESULT = SUM(ARRAY, DIM[, MASK])}
9787 @item @emph{Arguments}:
9788 @multitable @columnfractions .15 .70
9789 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER(*)},
9790 @code{REAL(*)} or @code{COMPLEX(*)}.
9791 @item @var{DIM} @tab (Optional) shall be a scalar of type
9792 @code{INTEGER} with a value in the range from 1 to n, where n
9793 equals the rank of @var{ARRAY}.
9794 @item @var{MASK} @tab (Optional) shall be of type @code{LOGICAL}
9795 and either be a scalar or an array of the same shape as @var{ARRAY}.
9798 @item @emph{Return value}:
9799 The result is of the same type as @var{ARRAY}.
9801 If @var{DIM} is absent, a scalar with the sum of all elements in @var{ARRAY}
9802 is returned. Otherwise, an array of rank n-1, where n equals the rank of
9803 @var{ARRAY},and a shape similar to that of @var{ARRAY} with dimension @var{DIM}
9804 dropped is returned.
9806 @item @emph{Example}:
9809 INTEGER :: x(5) = (/ 1, 2, 3, 4 ,5 /)
9810 print *, SUM(x) ! all elements, sum = 15
9811 print *, SUM(x, MASK=MOD(x, 2)==1) ! odd elements, sum = 9
9815 @item @emph{See also}:
9822 @section @code{SYMLNK} --- Create a symbolic link
9824 @cindex file system, create link
9825 @cindex file system, soft link
9828 @item @emph{Description}:
9829 Makes a symbolic link from file @var{PATH1} to @var{PATH2}. A null
9830 character (@code{CHAR(0)}) can be used to mark the end of the names in
9831 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
9832 names are ignored. If the @var{STATUS} argument is supplied, it
9833 contains 0 on success or a nonzero error code upon return; see
9834 @code{symlink(2)}. If the system does not supply @code{symlink(2)},
9835 @code{ENOSYS} is returned.
9837 This intrinsic is provided in both subroutine and function forms;
9838 however, only one form can be used in any given program unit.
9840 @item @emph{Standard}:
9844 Subroutine, function
9846 @item @emph{Syntax}:
9847 @multitable @columnfractions .80
9848 @item @code{CALL SYMLNK(PATH1, PATH2 [, STATUS])}
9849 @item @code{STATUS = SYMLNK(PATH1, PATH2)}
9852 @item @emph{Arguments}:
9853 @multitable @columnfractions .15 .70
9854 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
9855 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
9856 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
9859 @item @emph{See also}:
9860 @ref{LINK}, @ref{UNLINK}
9867 @section @code{SYSTEM} --- Execute a shell command
9869 @cindex system, system call
9872 @item @emph{Description}:
9873 Passes the command @var{COMMAND} to a shell (see @code{system(3)}). If
9874 argument @var{STATUS} is present, it contains the value returned by
9875 @code{system(3)}, which is presumably 0 if the shell command succeeded.
9876 Note that which shell is used to invoke the command is system-dependent
9877 and environment-dependent.
9879 This intrinsic is provided in both subroutine and function forms;
9880 however, only one form can be used in any given program unit.
9882 @item @emph{Standard}:
9886 Subroutine, function
9888 @item @emph{Syntax}:
9889 @multitable @columnfractions .80
9890 @item @code{CALL SYSTEM(COMMAND [, STATUS])}
9891 @item @code{STATUS = SYSTEM(COMMAND)}
9894 @item @emph{Arguments}:
9895 @multitable @columnfractions .15 .70
9896 @item @var{COMMAND} @tab Shall be of default @code{CHARACTER} type.
9897 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
9900 @item @emph{See also}:
9906 @section @code{SYSTEM_CLOCK} --- Time function
9907 @fnindex SYSTEM_CLOCK
9908 @cindex time, clock ticks
9912 @item @emph{Description}:
9913 Determines the @var{COUNT} of milliseconds of wall clock time since
9914 the Epoch (00:00:00 UTC, January 1, 1970) modulo @var{COUNT_MAX},
9915 @var{COUNT_RATE} determines the number of clock ticks per second.
9916 @var{COUNT_RATE} and @var{COUNT_MAX} are constant and specific to
9919 If there is no clock, @var{COUNT} is set to @code{-HUGE(COUNT)}, and
9920 @var{COUNT_RATE} and @var{COUNT_MAX} are set to zero
9922 @item @emph{Standard}:
9928 @item @emph{Syntax}:
9929 @code{CALL SYSTEM_CLOCK([COUNT, COUNT_RATE, COUNT_MAX])}
9931 @item @emph{Arguments}:
9932 @item @emph{Arguments}:
9933 @multitable @columnfractions .15 .70
9934 @item @var{COUNT} @tab (Optional) shall be a scalar of type default
9935 @code{INTEGER} with @code{INTENT(OUT)}.
9936 @item @var{COUNT_RATE} @tab (Optional) shall be a scalar of type default
9937 @code{INTEGER} with @code{INTENT(OUT)}.
9938 @item @var{COUNT_MAX} @tab (Optional) shall be a scalar of type default
9939 @code{INTEGER} with @code{INTENT(OUT)}.
9942 @item @emph{Example}:
9944 PROGRAM test_system_clock
9945 INTEGER :: count, count_rate, count_max
9946 CALL SYSTEM_CLOCK(count, count_rate, count_max)
9947 WRITE(*,*) count, count_rate, count_max
9951 @item @emph{See also}:
9952 @ref{DATE_AND_TIME}, @ref{CPU_TIME}
9958 @section @code{TAN} --- Tangent function
9961 @cindex trigonometric function, tangent
9965 @item @emph{Description}:
9966 @code{TAN(X)} computes the tangent of @var{X}.
9968 @item @emph{Standard}:
9974 @item @emph{Syntax}:
9975 @code{RESULT = TAN(X)}
9977 @item @emph{Arguments}:
9978 @multitable @columnfractions .15 .70
9979 @item @var{X} @tab The type shall be @code{REAL(*)}.
9982 @item @emph{Return value}:
9983 The return value is of type @code{REAL(*)}. The kind type parameter is
9984 the same as @var{X}.
9986 @item @emph{Example}:
9989 real(8) :: x = 0.165_8
9991 end program test_tan
9994 @item @emph{Specific names}:
9995 @multitable @columnfractions .20 .20 .20 .25
9996 @item Name @tab Argument @tab Return type @tab Standard
9997 @item @code{DTAN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F95 and later
10000 @item @emph{See also}:
10007 @section @code{TANH} --- Hyperbolic tangent function
10010 @cindex hyperbolic tangent
10011 @cindex hyperbolic function, tangent
10012 @cindex tangent, hyperbolic
10015 @item @emph{Description}:
10016 @code{TANH(X)} computes the hyperbolic tangent of @var{X}.
10018 @item @emph{Standard}:
10021 @item @emph{Class}:
10024 @item @emph{Syntax}:
10027 @item @emph{Arguments}:
10028 @multitable @columnfractions .15 .70
10029 @item @var{X} @tab The type shall be @code{REAL(*)}.
10032 @item @emph{Return value}:
10033 The return value is of type @code{REAL(*)} and lies in the range
10034 @math{ - 1 \leq tanh(x) \leq 1 }.
10036 @item @emph{Example}:
10039 real(8) :: x = 2.1_8
10041 end program test_tanh
10044 @item @emph{Specific names}:
10045 @multitable @columnfractions .20 .20 .20 .25
10046 @item Name @tab Argument @tab Return type @tab Standard
10047 @item @code{DTANH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F95 and later
10050 @item @emph{See also}:
10057 @section @code{TIME} --- Time function
10059 @cindex time, current
10060 @cindex current time
10063 @item @emph{Description}:
10064 Returns the current time encoded as an integer (in the manner of the
10065 UNIX function @code{time(3)}). This value is suitable for passing to
10066 @code{CTIME()}, @code{GMTIME()}, and @code{LTIME()}.
10068 This intrinsic is not fully portable, such as to systems with 32-bit
10069 @code{INTEGER} types but supporting times wider than 32 bits. Therefore,
10070 the values returned by this intrinsic might be, or become, negative, or
10071 numerically less than previous values, during a single run of the
10074 See @ref{TIME8}, for information on a similar intrinsic that might be
10075 portable to more GNU Fortran implementations, though to fewer Fortran
10078 @item @emph{Standard}:
10081 @item @emph{Class}:
10084 @item @emph{Syntax}:
10085 @code{RESULT = TIME()}
10087 @item @emph{Return value}:
10088 The return value is a scalar of type @code{INTEGER(4)}.
10090 @item @emph{See also}:
10091 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK}, @ref{TIME8}
10098 @section @code{TIME8} --- Time function (64-bit)
10100 @cindex time, current
10101 @cindex current time
10104 @item @emph{Description}:
10105 Returns the current time encoded as an integer (in the manner of the
10106 UNIX function @code{time(3)}). This value is suitable for passing to
10107 @code{CTIME()}, @code{GMTIME()}, and @code{LTIME()}.
10109 @emph{Warning:} this intrinsic does not increase the range of the timing
10110 values over that returned by @code{time(3)}. On a system with a 32-bit
10111 @code{time(3)}, @code{TIME8()} will return a 32-bit value, even though
10112 it is converted to a 64-bit @code{INTEGER(8)} value. That means
10113 overflows of the 32-bit value can still occur. Therefore, the values
10114 returned by this intrinsic might be or become negative or numerically
10115 less than previous values during a single run of the compiled program.
10117 @item @emph{Standard}:
10120 @item @emph{Class}:
10123 @item @emph{Syntax}:
10124 @code{RESULT = TIME8()}
10126 @item @emph{Return value}:
10127 The return value is a scalar of type @code{INTEGER(8)}.
10129 @item @emph{See also}:
10130 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK8}, @ref{TIME}
10137 @section @code{TINY} --- Smallest positive number of a real kind
10139 @cindex limits, smallest number
10140 @cindex model representation, smallest number
10143 @item @emph{Description}:
10144 @code{TINY(X)} returns the smallest positive (non zero) number
10145 in the model of the type of @code{X}.
10147 @item @emph{Standard}:
10150 @item @emph{Class}:
10153 @item @emph{Syntax}:
10154 @code{RESULT = TINY(X)}
10156 @item @emph{Arguments}:
10157 @multitable @columnfractions .15 .70
10158 @item @var{X} @tab Shall be of type @code{REAL}.
10161 @item @emph{Return value}:
10162 The return value is of the same type and kind as @var{X}
10164 @item @emph{Example}:
10165 See @code{HUGE} for an example.
10171 @section @code{TRANSFER} --- Transfer bit patterns
10177 @item @emph{Description}:
10178 Interprets the bitwise representation of @var{SOURCE} in memory as if it
10179 is the representation of a variable or array of the same type and type
10180 parameters as @var{MOLD}.
10182 This is approximately equivalent to the C concept of @emph{casting} one
10185 @item @emph{Standard}:
10188 @item @emph{Class}:
10189 Transformational function
10191 @item @emph{Syntax}:
10192 @code{RESULT = TRANSFER(SOURCE, MOLD[, SIZE])}
10194 @item @emph{Arguments}:
10195 @multitable @columnfractions .15 .70
10196 @item @var{SOURCE} @tab Shall be a scalar or an array of any type.
10197 @item @var{MOLD} @tab Shall be a scalar or an array of any type.
10198 @item @var{SIZE} @tab (Optional) shall be a scalar of type
10202 @item @emph{Return value}:
10203 The result has the same type as @var{MOLD}, with the bit level
10204 representation of @var{SOURCE}. If @var{SIZE} is present, the result is
10205 a one-dimensional array of length @var{SIZE}. If @var{SIZE} is absent
10206 but @var{MOLD} is an array (of any size or shape), the result is a one-
10207 dimensional array of the minimum length needed to contain the entirety
10208 of the bitwise representation of @var{SOURCE}. If @var{SIZE} is absent
10209 and @var{MOLD} is a scalar, the result is a scalar.
10211 If the bitwise representation of the result is longer than that of
10212 @var{SOURCE}, then the leading bits of the result correspond to those of
10213 @var{SOURCE} and any trailing bits are filled arbitrarily.
10215 When the resulting bit representation does not correspond to a valid
10216 representation of a variable of the same type as @var{MOLD}, the results
10217 are undefined, and subsequent operations on the result cannot be
10218 guaranteed to produce sensible behavior. For example, it is possible to
10219 create @code{LOGICAL} variables for which @code{@var{VAR}} and
10220 @code{.NOT.@var{VAR}} both appear to be true.
10222 @item @emph{Example}:
10224 PROGRAM test_transfer
10225 integer :: x = 2143289344
10226 print *, transfer(x, 1.0) ! prints "NaN" on i686
10234 @section @code{TRANSPOSE} --- Transpose an array of rank two
10236 @cindex array, transpose
10237 @cindex matrix, transpose
10241 @item @emph{Description}:
10242 Transpose an array of rank two. Element (i, j) of the result has the value
10243 @code{MATRIX(j, i)}, for all i, j.
10245 @item @emph{Standard}:
10248 @item @emph{Class}:
10249 Transformational function
10251 @item @emph{Syntax}:
10252 @code{RESULT = TRANSPOSE(MATRIX)}
10254 @item @emph{Arguments}:
10255 @multitable @columnfractions .15 .70
10256 @item @var{MATRIX} @tab Shall be an array of any type and have a rank of two.
10259 @item @emph{Return value}:
10260 The result has the the same type as @var{MATRIX}, and has shape
10261 @code{(/ m, n /)} if @var{MATRIX} has shape @code{(/ n, m /)}.
10267 @section @code{TRIM} --- Remove trailing blank characters of a string
10269 @cindex string, remove trailing whitespace
10272 @item @emph{Description}:
10273 Removes trailing blank characters of a string.
10275 @item @emph{Standard}:
10278 @item @emph{Class}:
10279 Transformational function
10281 @item @emph{Syntax}:
10282 @code{RESULT = TRIM(STRING)}
10284 @item @emph{Arguments}:
10285 @multitable @columnfractions .15 .70
10286 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER(*)}.
10289 @item @emph{Return value}:
10290 A scalar of type @code{CHARACTER(*)} which length is that of @var{STRING}
10291 less the number of trailing blanks.
10293 @item @emph{Example}:
10296 CHARACTER(len=10), PARAMETER :: s = "GFORTRAN "
10297 WRITE(*,*) LEN(s), LEN(TRIM(s)) ! "10 8", with/without trailing blanks
10301 @item @emph{See also}:
10302 @ref{ADJUSTL}, @ref{ADJUSTR}
10308 @section @code{TTYNAM} --- Get the name of a terminal device.
10310 @cindex system, terminal
10313 @item @emph{Description}:
10314 Get the name of a terminal device. For more information,
10315 see @code{ttyname(3)}.
10317 This intrinsic is provided in both subroutine and function forms;
10318 however, only one form can be used in any given program unit.
10320 @item @emph{Standard}:
10323 @item @emph{Class}:
10324 Subroutine, function
10326 @item @emph{Syntax}:
10327 @multitable @columnfractions .80
10328 @item @code{CALL TTYNAM(UNIT, NAME)}
10329 @item @code{NAME = TTYNAM(UNIT)}
10332 @item @emph{Arguments}:
10333 @multitable @columnfractions .15 .70
10334 @item @var{UNIT} @tab Shall be a scalar @code{INTEGER(*)}.
10335 @item @var{NAME} @tab Shall be of type @code{CHARACTER(*)}.
10338 @item @emph{Example}:
10340 PROGRAM test_ttynam
10343 IF (isatty(unit=unit)) write(*,*) ttynam(unit)
10348 @item @emph{See also}:
10355 @section @code{UBOUND} --- Upper dimension bounds of an array
10357 @cindex array, upper bound
10360 @item @emph{Description}:
10361 Returns the upper bounds of an array, or a single upper bound
10362 along the @var{DIM} dimension.
10363 @item @emph{Standard}:
10366 @item @emph{Class}:
10369 @item @emph{Syntax}:
10370 @code{RESULT = UBOUND(ARRAY [, DIM])}
10372 @item @emph{Arguments}:
10373 @multitable @columnfractions .15 .70
10374 @item @var{ARRAY} @tab Shall be an array, of any type.
10375 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER(*)}.
10378 @item @emph{Return value}:
10379 If @var{DIM} is absent, the result is an array of the upper bounds of
10380 @var{ARRAY}. If @var{DIM} is present, the result is a scalar
10381 corresponding to the upper bound of the array along that dimension. If
10382 @var{ARRAY} is an expression rather than a whole array or array
10383 structure component, or if it has a zero extent along the relevant
10384 dimension, the upper bound is taken to be the number of elements along
10385 the relevant dimension.
10387 @item @emph{See also}:
10394 @section @code{UMASK} --- Set the file creation mask
10396 @cindex file system, file creation mask
10399 @item @emph{Description}:
10400 Sets the file creation mask to @var{MASK} and returns the old value in
10401 argument @var{OLD} if it is supplied. See @code{umask(2)}.
10403 @item @emph{Standard}:
10406 @item @emph{Class}:
10409 @item @emph{Syntax}:
10410 @code{CALL UMASK(MASK [, OLD])}
10412 @item @emph{Arguments}:
10413 @multitable @columnfractions .15 .70
10414 @item @var{MASK} @tab Shall be a scalar of type @code{INTEGER(*)}.
10415 @item @var{MASK} @tab (Optional) Shall be a scalar of type
10424 @section @code{UNLINK} --- Remove a file from the file system
10426 @cindex file system, remove file
10429 @item @emph{Description}:
10430 Unlinks the file @var{PATH}. A null character (@code{CHAR(0)}) can be
10431 used to mark the end of the name in @var{PATH}; otherwise, trailing
10432 blanks in the file name are ignored. If the @var{STATUS} argument is
10433 supplied, it contains 0 on success or a nonzero error code upon return;
10434 see @code{unlink(2)}.
10436 This intrinsic is provided in both subroutine and function forms;
10437 however, only one form can be used in any given program unit.
10439 @item @emph{Standard}:
10442 @item @emph{Class}:
10443 Subroutine, function
10445 @item @emph{Syntax}:
10446 @multitable @columnfractions .80
10447 @item @code{CALL UNLINK(PATH [, STATUS])}
10448 @item @code{STATUS = UNLINK(PATH)}
10451 @item @emph{Arguments}:
10452 @multitable @columnfractions .15 .70
10453 @item @var{PATH} @tab Shall be of default @code{CHARACTER} type.
10454 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
10457 @item @emph{See also}:
10458 @ref{LINK}, @ref{SYMLNK}
10464 @section @code{UNPACK} --- Unpack an array of rank one into an array
10466 @cindex array, unpacking
10467 @cindex array, increase dimension
10468 @cindex array, scatter elements
10471 @item @emph{Description}:
10472 Store the elements of @var{VECTOR} in an array of higher rank.
10474 @item @emph{Standard}:
10477 @item @emph{Class}:
10478 Transformational function
10480 @item @emph{Syntax}:
10481 @code{RESULT = UNPACK(VECTOR, MASK, FIELD)}
10483 @item @emph{Arguments}:
10484 @multitable @columnfractions .15 .70
10485 @item @var{VECTOR} @tab Shall be an array of any type and rank one. It
10486 shall have at least as many elements as @var{MASK} has @code{TRUE} values.
10487 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL}.
10488 @item @var{FIELD} @tab Shall be of the sam type as @var{VECTOR} and have
10489 the same shape as @var{MASK}.
10492 @item @emph{Return value}:
10493 The resulting array corresponds to @var{FIELD} with @code{TRUE} elements
10494 of @var{MASK} replaced by values from @var{VECTOR} in array element order.
10496 @item @emph{Example}:
10498 PROGRAM test_unpack
10499 integer :: vector(2) = (/1,1/)
10500 logical :: mask(4) = (/ .TRUE., .FALSE., .FALSE., .TRUE. /)
10501 integer :: field(2,2) = 0, unity(2,2)
10503 ! result: unity matrix
10504 unity = unpack(vector, reshape(mask, (/2,2/)), field)
10508 @item @emph{See also}:
10509 @ref{PACK}, @ref{SPREAD}
10515 @section @code{VERIFY} --- Scan a string for the absence of a set of characters
10517 @cindex string, find missing set
10520 @item @emph{Description}:
10521 Verifies that all the characters in a @var{SET} are present in a @var{STRING}.
10523 If @var{BACK} is either absent or equals @code{FALSE}, this function
10524 returns the position of the leftmost character of @var{STRING} that is
10525 not in @var{SET}. If @var{BACK} equals @code{TRUE}, the rightmost position
10526 is returned. If all characters of @var{SET} are found in @var{STRING}, the
10529 @item @emph{Standard}:
10532 @item @emph{Class}:
10535 @item @emph{Syntax}:
10536 @code{RESULT = VERIFY(STRING, SET[, BACK])}
10538 @item @emph{Arguments}:
10539 @multitable @columnfractions .15 .70
10540 @item @var{STRING} @tab Shall be of type @code{CHARACTER(*)}.
10541 @item @var{SET} @tab Shall be of type @code{CHARACTER(*)}.
10542 @item @var{BACK} @tab (Optional) shall be of type @code{LOGICAL}.
10545 @item @emph{Return value}:
10546 The return value is of type @code{INTEGER} and of the default
10549 @item @emph{Example}:
10551 PROGRAM test_verify
10552 WRITE(*,*) VERIFY("FORTRAN", "AO") ! 1, found 'F'
10553 WRITE(*,*) VERIFY("FORTRAN", "FOO") ! 3, found 'R'
10554 WRITE(*,*) VERIFY("FORTRAN", "C++") ! 1, found 'F'
10555 WRITE(*,*) VERIFY("FORTRAN", "C++", .TRUE.) ! 7, found 'N'
10556 WRITE(*,*) VERIFY("FORTRAN", "FORTRAN") ! 0' found none
10560 @item @emph{See also}:
10561 @ref{SCAN}, @ref{INDEX}
10567 @section @code{XOR} --- Bitwise logical exclusive OR
10569 @cindex bitwise logical exclusive or
10570 @cindex logical exclusive or, bitwise
10573 @item @emph{Description}:
10574 Bitwise logical exclusive or.
10576 This intrinsic routine is provided for backwards compatibility with
10577 GNU Fortran 77. For integer arguments, programmers should consider
10578 the use of the @ref{IEOR} intrinsic defined by the Fortran standard.
10580 @item @emph{Standard}:
10583 @item @emph{Class}:
10586 @item @emph{Syntax}:
10587 @code{RESULT = XOR(X, Y)}
10589 @item @emph{Arguments}:
10590 @multitable @columnfractions .15 .70
10591 @item @var{X} @tab The type shall be either @code{INTEGER(*)} or @code{LOGICAL}.
10592 @item @var{Y} @tab The type shall be either @code{INTEGER(*)} or @code{LOGICAL}.
10595 @item @emph{Return value}:
10596 The return type is either @code{INTEGER(*)} or @code{LOGICAL}
10597 after cross-promotion of the arguments.
10599 @item @emph{Example}:
10602 LOGICAL :: T = .TRUE., F = .FALSE.
10604 DATA a / Z'F' /, b / Z'3' /
10606 WRITE (*,*) XOR(T, T), XOR(T, F), XOR(F, T), XOR(F, F)
10607 WRITE (*,*) XOR(a, b)
10611 @item @emph{See also}:
10612 F95 elemental function: @ref{IEOR}