]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/fortran/intrinsic.texi
re PR fortran/29600 ([F03] MINLOC and MAXLOC take an optional KIND argument)
[thirdparty/gcc.git] / gcc / fortran / intrinsic.texi
1 @ignore
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.
6
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.
14
15
16 Some basic guidelines for editing this document:
17
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.
23
24
25 @end ignore
26
27 @tex
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}
34 @end tex
35
36
37 @node Intrinsic Procedures
38 @chapter Intrinsic Procedures
39 @cindex intrinsic procedures
40
41 @menu
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
258 @end menu
259
260 @node Introduction to Intrinsics
261 @section Introduction to intrinsic procedures
262
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.
270
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.
283
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.
287
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.
298
299
300
301 @node ABORT
302 @section @code{ABORT} --- Abort the program
303 @fnindex ABORT
304 @cindex program termination, with core dump
305 @cindex terminate program, with core dump
306 @cindex core, dump
307
308 @table @asis
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.
313
314 @item @emph{Standard}:
315 GNU extension
316
317 @item @emph{Class}:
318 Subroutine
319
320 @item @emph{Syntax}:
321 @code{CALL ABORT}
322
323 @item @emph{Return value}:
324 Does not return.
325
326 @item @emph{Example}:
327 @smallexample
328 program test_abort
329 integer :: i = 1, j = 2
330 if (i /= j) call abort
331 end program test_abort
332 @end smallexample
333
334 @item @emph{See also}:
335 @ref{EXIT}, @ref{KILL}
336
337 @end table
338
339
340
341 @node ABS
342 @section @code{ABS} --- Absolute value
343 @fnindex ABS
344 @fnindex CABS
345 @fnindex DABS
346 @fnindex IABS
347 @fnindex ZABS
348 @fnindex CDABS
349 @cindex absolute value
350
351 @table @asis
352 @item @emph{Description}:
353 @code{ABS(X)} computes the absolute value of @code{X}.
354
355 @item @emph{Standard}:
356 F77 and later, has overloads that are GNU extensions
357
358 @item @emph{Class}:
359 Elemental function
360
361 @item @emph{Syntax}:
362 @code{RESULT = ABS(X)}
363
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(*)}.
368 @end multitable
369
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.
374
375 @item @emph{Example}:
376 @smallexample
377 program test_abs
378 integer :: i = -1
379 real :: x = -1.e0
380 complex :: z = (-1.e0,0.e0)
381 i = abs(i)
382 x = abs(x)
383 x = abs(z)
384 end program test_abs
385 @end smallexample
386
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
395 @end multitable
396 @end table
397
398
399
400 @node ACCESS
401 @section @code{ACCESS} --- Checks file access modes
402 @fnindex ACCESS
403 @cindex file system, access mode
404
405 @table @asis
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}.
411
412 @item @emph{Standard}:
413 GNU extension
414
415 @item @emph{Class}:
416 Inquiry function
417
418 @item @emph{Syntax}:
419 @code{RESULT = ACCESS(NAME, MODE)}
420
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
426 used as file name.
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.
430 @end multitable
431
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.
436
437 @item @emph{Example}:
438 @smallexample
439 program access_test
440 implicit none
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
450 @end smallexample
451 @item @emph{Specific names}:
452 @item @emph{See also}:
453
454 @end table
455
456
457
458 @node ACHAR
459 @section @code{ACHAR} --- Character in @acronym{ASCII} collating sequence
460 @fnindex ACHAR
461 @cindex @acronym{ASCII} collating sequence
462 @cindex collating sequence, @acronym{ASCII}
463
464 @table @asis
465 @item @emph{Description}:
466 @code{ACHAR(I)} returns the character located at position @code{I}
467 in the @acronym{ASCII} collating sequence.
468
469 @item @emph{Standard}:
470 F77 and later
471
472 @item @emph{Class}:
473 Elemental function
474
475 @item @emph{Syntax}:
476 @code{RESULT = ACHAR(I)}
477
478 @item @emph{Arguments}:
479 @multitable @columnfractions .15 .70
480 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
481 @end multitable
482
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')}.
486
487 @item @emph{Example}:
488 @smallexample
489 program test_achar
490 character c
491 c = achar(32)
492 end program test_achar
493 @end smallexample
494
495 @item @emph{Note}:
496 See @ref{ICHAR} for a discussion of converting between numerical values
497 and formatted string representations.
498
499 @item @emph{See also}:
500 @ref{CHAR}, @ref{IACHAR}, @ref{ICHAR}
501
502 @end table
503
504
505
506 @node ACOS
507 @section @code{ACOS} --- Arccosine function
508 @fnindex ACOS
509 @fnindex DACOS
510 @cindex trigonometric function, cosine, inverse
511 @cindex cosine, inverse
512
513 @table @asis
514 @item @emph{Description}:
515 @code{ACOS(X)} computes the arccosine of @var{X} (inverse of @code{COS(X)}).
516
517 @item @emph{Standard}:
518 F77 and later
519
520 @item @emph{Class}:
521 Elemental function
522
523 @item @emph{Syntax}:
524 @code{RESULT = ACOS(X)}
525
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
529 less than one.
530 @end multitable
531
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}.
536
537 @item @emph{Example}:
538 @smallexample
539 program test_acos
540 real(8) :: x = 0.866_8
541 x = acos(x)
542 end program test_acos
543 @end smallexample
544
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
549 @end multitable
550
551 @item @emph{See also}:
552 Inverse function: @ref{COS}
553
554 @end table
555
556
557
558 @node ACOSH
559 @section @code{ACOSH} --- Hyperbolic arccosine function
560 @fnindex ACOSH
561 @fnindex DACOSH
562 @cindex area hyperbolic cosine
563 @cindex hyperbolic arccosine
564 @cindex hyperbolic function, cosine, inverse
565 @cindex cosine, hyperbolic, inverse
566
567 @table @asis
568 @item @emph{Description}:
569 @code{ACOSH(X)} computes the hyperbolic arccosine of @var{X} (inverse of
570 @code{COSH(X)}).
571
572 @item @emph{Standard}:
573 GNU extension
574
575 @item @emph{Class}:
576 Elemental function
577
578 @item @emph{Syntax}:
579 @code{RESULT = ACOSH(X)}
580
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.
585 @end multitable
586
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}.
590
591 @item @emph{Example}:
592 @smallexample
593 PROGRAM test_acosh
594 REAL(8), DIMENSION(3) :: x = (/ 1.0, 2.0, 3.0 /)
595 WRITE (*,*) ACOSH(x)
596 END PROGRAM
597 @end smallexample
598
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
603 @end multitable
604
605 @item @emph{See also}:
606 Inverse function: @ref{COSH}
607 @end table
608
609
610
611 @node ADJUSTL
612 @section @code{ADJUSTL} --- Left adjust a string
613 @fnindex ADJUSTL
614 @cindex string, adjust left
615 @cindex adjust string
616
617 @table @asis
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.
621
622 @item @emph{Standard}:
623 F95 and later
624
625 @item @emph{Class}:
626 Elemental function
627
628 @item @emph{Syntax}:
629 @code{RESULT = ADJUSTL(STR)}
630
631 @item @emph{Arguments}:
632 @multitable @columnfractions .15 .70
633 @item @var{STR} @tab The type shall be @code{CHARACTER}.
634 @end multitable
635
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
639 of @var{STR}.
640
641 @item @emph{Example}:
642 @smallexample
643 program test_adjustl
644 character(len=20) :: str = ' gfortran'
645 str = adjustl(str)
646 print *, str
647 end program test_adjustl
648 @end smallexample
649
650 @item @emph{See also}:
651 @ref{ADJUSTR}, @ref{TRIM}
652 @end table
653
654
655
656 @node ADJUSTR
657 @section @code{ADJUSTR} --- Right adjust a string
658 @fnindex ADJUSTR
659 @cindex string, adjust right
660 @cindex adjust string
661
662 @table @asis
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.
666
667 @item @emph{Standard}:
668 F95 and later
669
670 @item @emph{Class}:
671 Elemental function
672
673 @item @emph{Syntax}:
674 @code{RESULT = ADJUSTR(STR)}
675
676 @item @emph{Arguments}:
677 @multitable @columnfractions .15 .70
678 @item @var{STR} @tab The type shall be @code{CHARACTER}.
679 @end multitable
680
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
684 of @var{STR}.
685
686 @item @emph{Example}:
687 @smallexample
688 program test_adjustr
689 character(len=20) :: str = 'gfortran'
690 str = adjustr(str)
691 print *, str
692 end program test_adjustr
693 @end smallexample
694
695 @item @emph{See also}:
696 @ref{ADJUSTL}, @ref{TRIM}
697 @end table
698
699
700
701 @node AIMAG
702 @section @code{AIMAG} --- Imaginary part of complex number
703 @fnindex AIMAG
704 @fnindex DIMAG
705 @fnindex IMAG
706 @fnindex IMAGPART
707 @cindex complex numbers, imaginary part
708
709 @table @asis
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.
715
716 @item @emph{Standard}:
717 F77 and later, has overloads that are GNU extensions
718
719 @item @emph{Class}:
720 Elemental function
721
722 @item @emph{Syntax}:
723 @code{RESULT = AIMAG(Z)}
724
725 @item @emph{Arguments}:
726 @multitable @columnfractions .15 .70
727 @item @var{Z} @tab The type of the argument shall be @code{COMPLEX(*)}.
728 @end multitable
729
730 @item @emph{Return value}:
731 The return value is of type real with the
732 kind type parameter of the argument.
733
734 @item @emph{Example}:
735 @smallexample
736 program test_aimag
737 complex(4) z4
738 complex(8) z8
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
743 @end smallexample
744
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
751 @end multitable
752 @end table
753
754
755
756 @node AINT
757 @section @code{AINT} --- Truncate to a whole number
758 @fnindex AINT
759 @fnindex DINT
760 @cindex floor
761 @cindex rounding, floor
762
763 @table @asis
764 @item @emph{Description}:
765 @code{AINT(X [, KIND])} truncates its argument to a whole number.
766
767 @item @emph{Standard}:
768 F77 and later
769
770 @item @emph{Class}:
771 Elemental function
772
773 @item @emph{Syntax}:
774 @code{RESULT = AINT(X [, KIND])}
775
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
781 the result.
782 @end multitable
783
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}.
792
793 @item @emph{Example}:
794 @smallexample
795 program test_aint
796 real(4) x4
797 real(8) x8
798 x4 = 1.234E0_4
799 x8 = 4.321_8
800 print *, aint(x4), dint(x8)
801 x8 = aint(x4,8)
802 end program test_aint
803 @end smallexample
804
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
809 @end multitable
810 @end table
811
812
813
814 @node ALARM
815 @section @code{ALARM} --- Execute a routine after a given delay
816 @fnindex ALARM
817 @cindex delayed execution
818
819 @table @asis
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.
827
828 @item @emph{Standard}:
829 GNU extension
830
831 @item @emph{Class}:
832 Subroutine
833
834 @item @emph{Syntax}:
835 @code{CALL ALARM(SECONDS, HANDLER [, STATUS])}
836
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)}.
847 @end multitable
848
849 @item @emph{Example}:
850 @smallexample
851 program test_alarm
852 external handler_print
853 integer i
854 call alarm (3, handler_print, i)
855 print *, i
856 call sleep(10)
857 end program test_alarm
858 @end smallexample
859 This will cause the external routine @var{handler_print} to be called
860 after 3 seconds.
861 @end table
862
863
864
865 @node ALL
866 @section @code{ALL} --- All values in @var{MASK} along @var{DIM} are true
867 @fnindex ALL
868 @cindex array, apply condition
869 @cindex array, condition testing
870
871 @table @asis
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}.
875
876 @item @emph{Standard}:
877 F95 and later
878
879 @item @emph{Class}:
880 Transformational function
881
882 @item @emph{Syntax}:
883 @code{RESULT = ALL(MASK [, DIM])}
884
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}.
891 @end multitable
892
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.
899
900 @table @asis
901 @item (A)
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.
904 @item (B)
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.
908 @end table
909
910 @item @emph{Example}:
911 @smallexample
912 program test_all
913 logical l
914 l = all((/.true., .true., .true./))
915 print *, l
916 call section
917 contains
918 subroutine section
919 integer a(2,3), b(2,3)
920 a = 1
921 b = 1
922 b(2,2) = 2
923 print *, all(a .eq. b, 1)
924 print *, all(a .eq. b, 2)
925 end subroutine section
926 end program test_all
927 @end smallexample
928 @end table
929
930
931
932 @node ALLOCATED
933 @section @code{ALLOCATED} --- Status of an allocatable entity
934 @fnindex ALLOCATED
935 @cindex allocation, status
936
937 @table @asis
938 @item @emph{Description}:
939 @code{ALLOCATED(X)} checks the status of whether @var{X} is allocated.
940
941 @item @emph{Standard}:
942 F95 and later
943
944 @item @emph{Class}:
945 Inquiry function
946
947 @item @emph{Syntax}:
948 @code{RESULT = ALLOCATED(X)}
949
950 @item @emph{Arguments}:
951 @multitable @columnfractions .15 .70
952 @item @var{X} @tab The argument shall be an @code{ALLOCATABLE} array.
953 @end multitable
954
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.}
959
960 @item @emph{Example}:
961 @smallexample
962 program test_allocated
963 integer :: i = 4
964 real(4), allocatable :: x(:)
965 if (allocated(x) .eqv. .false.) allocate(x(i))
966 end program test_allocated
967 @end smallexample
968 @end table
969
970
971
972 @node AND
973 @section @code{AND} --- Bitwise logical AND
974 @fnindex AND
975 @cindex bitwise logical and
976 @cindex logical and, bitwise
977
978 @table @asis
979 @item @emph{Description}:
980 Bitwise logical @code{AND}.
981
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.
985
986 @item @emph{Standard}:
987 GNU extension
988
989 @item @emph{Class}:
990 Function
991
992 @item @emph{Syntax}:
993 @code{RESULT = AND(I, J)}
994
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}.
999 @end multitable
1000
1001 @item @emph{Return value}:
1002 The return type is either @code{INTEGER(*)} or @code{LOGICAL} after
1003 cross-promotion of the arguments.
1004
1005 @item @emph{Example}:
1006 @smallexample
1007 PROGRAM test_and
1008 LOGICAL :: T = .TRUE., F = .FALSE.
1009 INTEGER :: a, b
1010 DATA a / Z'F' /, b / Z'3' /
1011
1012 WRITE (*,*) AND(T, T), AND(T, F), AND(F, T), AND(F, F)
1013 WRITE (*,*) AND(a, b)
1014 END PROGRAM
1015 @end smallexample
1016
1017 @item @emph{See also}:
1018 F95 elemental function: @ref{IAND}
1019 @end table
1020
1021
1022
1023 @node ANINT
1024 @section @code{ANINT} --- Nearest whole number
1025 @fnindex ANINT
1026 @fnindex DNINT
1027 @cindex ceiling
1028 @cindex rounding, ceiling
1029
1030 @table @asis
1031 @item @emph{Description}:
1032 @code{ANINT(X [, KIND])} rounds its argument to the nearest whole number.
1033
1034 @item @emph{Standard}:
1035 F77 and later
1036
1037 @item @emph{Class}:
1038 Elemental function
1039
1040 @item @emph{Syntax}:
1041 @code{RESULT = ANINT(X [, KIND])}
1042
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
1048 the result.
1049 @end multitable
1050
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)}.
1057
1058 @item @emph{Example}:
1059 @smallexample
1060 program test_anint
1061 real(4) x4
1062 real(8) x8
1063 x4 = 1.234E0_4
1064 x8 = 4.321_8
1065 print *, anint(x4), dnint(x8)
1066 x8 = anint(x4,8)
1067 end program test_anint
1068 @end smallexample
1069
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
1074 @end multitable
1075 @end table
1076
1077
1078
1079 @node ANY
1080 @section @code{ANY} --- Any value in @var{MASK} along @var{DIM} is true
1081 @fnindex ANY
1082 @cindex array, apply condition
1083 @cindex array, condition testing
1084
1085 @table @asis
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.}.
1089
1090 @item @emph{Standard}:
1091 F95 and later
1092
1093 @item @emph{Class}:
1094 Transformational function
1095
1096 @item @emph{Syntax}:
1097 @code{RESULT = ANY(MASK [, DIM])}
1098
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}.
1105 @end multitable
1106
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.
1113
1114 @table @asis
1115 @item (A)
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.
1118 @item (B)
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.
1122 @end table
1123
1124 @item @emph{Example}:
1125 @smallexample
1126 program test_any
1127 logical l
1128 l = any((/.true., .true., .true./))
1129 print *, l
1130 call section
1131 contains
1132 subroutine section
1133 integer a(2,3), b(2,3)
1134 a = 1
1135 b = 1
1136 b(2,2) = 2
1137 print *, any(a .eq. b, 1)
1138 print *, any(a .eq. b, 2)
1139 end subroutine section
1140 end program test_any
1141 @end smallexample
1142 @end table
1143
1144
1145
1146 @node ASIN
1147 @section @code{ASIN} --- Arcsine function
1148 @fnindex ASIN
1149 @fnindex DASIN
1150 @cindex trigonometric function, sine, inverse
1151 @cindex sine, inverse
1152
1153 @table @asis
1154 @item @emph{Description}:
1155 @code{ASIN(X)} computes the arcsine of its @var{X} (inverse of @code{SIN(X)}).
1156
1157 @item @emph{Standard}:
1158 F77 and later
1159
1160 @item @emph{Class}:
1161 Elemental function
1162
1163 @item @emph{Syntax}:
1164 @code{RESULT = ASIN(X)}
1165
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
1169 less than one.
1170 @end multitable
1171
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}.
1176
1177 @item @emph{Example}:
1178 @smallexample
1179 program test_asin
1180 real(8) :: x = 0.866_8
1181 x = asin(x)
1182 end program test_asin
1183 @end smallexample
1184
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
1189 @end multitable
1190
1191 @item @emph{See also}:
1192 Inverse function: @ref{SIN}
1193
1194 @end table
1195
1196
1197
1198 @node ASINH
1199 @section @code{ASINH} --- Hyperbolic arcsine function
1200 @fnindex ASINH
1201 @fnindex DASINH
1202 @cindex area hyperbolic sine
1203 @cindex hyperbolic arcsine
1204 @cindex hyperbolic function, sine, inverse
1205 @cindex sine, hyperbolic, inverse
1206
1207 @table @asis
1208 @item @emph{Description}:
1209 @code{ASINH(X)} computes the hyperbolic arcsine of @var{X} (inverse of @code{SINH(X)}).
1210
1211 @item @emph{Standard}:
1212 GNU extension
1213
1214 @item @emph{Class}:
1215 Elemental function
1216
1217 @item @emph{Syntax}:
1218 @code{RESULT = ASINH(X)}
1219
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.
1223 @end multitable
1224
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}.
1228
1229 @item @emph{Example}:
1230 @smallexample
1231 PROGRAM test_asinh
1232 REAL(8), DIMENSION(3) :: x = (/ -1.0, 0.0, 1.0 /)
1233 WRITE (*,*) ASINH(x)
1234 END PROGRAM
1235 @end smallexample
1236
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.
1241 @end multitable
1242
1243 @item @emph{See also}:
1244 Inverse function: @ref{SINH}
1245 @end table
1246
1247
1248
1249 @node ASSOCIATED
1250 @section @code{ASSOCIATED} --- Status of a pointer or pointer/target pair
1251 @fnindex ASSOCIATED
1252 @cindex pointer, status
1253 @cindex association status
1254
1255 @table @asis
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}.
1259
1260 @item @emph{Standard}:
1261 F95 and later
1262
1263 @item @emph{Class}:
1264 Inquiry function
1265
1266 @item @emph{Syntax}:
1267 @code{RESULT = ASSOCIATED(PTR [, TGT])}
1268
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}.
1276 @end multitable
1277 The status of neither @var{PTR} nor @var{TGT} can be undefined.
1278
1279 @item @emph{Return value}:
1280 @code{ASSOCIATED(PTR)} returns a scalar value of type @code{LOGICAL(4)}.
1281 There are several cases:
1282 @table @asis
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
1286 @var{TGT}
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
1289 result is false.
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.
1305 @end table
1306
1307 @item @emph{Example}:
1308 @smallexample
1309 program test_associated
1310 implicit none
1311 real, target :: tgt(2) = (/1., 2./)
1312 real, pointer :: ptr(:)
1313 ptr => tgt
1314 if (associated(ptr) .eqv. .false.) call abort
1315 if (associated(ptr,tgt) .eqv. .false.) call abort
1316 end program test_associated
1317 @end smallexample
1318
1319 @item @emph{See also}:
1320 @ref{NULL}
1321 @end table
1322
1323
1324
1325 @node ATAN
1326 @section @code{ATAN} --- Arctangent function
1327 @fnindex ATAN
1328 @fnindex DATAN
1329 @cindex trigonometric function, tangent, inverse
1330 @cindex tangent, inverse
1331
1332 @table @asis
1333 @item @emph{Description}:
1334 @code{ATAN(X)} computes the arctangent of @var{X}.
1335
1336 @item @emph{Standard}:
1337 F77 and later
1338
1339 @item @emph{Class}:
1340 Elemental function
1341
1342 @item @emph{Syntax}:
1343 @code{RESULT = ATAN(X)}
1344
1345 @item @emph{Arguments}:
1346 @multitable @columnfractions .15 .70
1347 @item @var{X} @tab The type shall be @code{REAL(*)}.
1348 @end multitable
1349
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}.
1353
1354 @item @emph{Example}:
1355 @smallexample
1356 program test_atan
1357 real(8) :: x = 2.866_8
1358 x = atan(x)
1359 end program test_atan
1360 @end smallexample
1361
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
1366 @end multitable
1367
1368 @item @emph{See also}:
1369 Inverse function: @ref{TAN}
1370
1371 @end table
1372
1373
1374
1375 @node ATAN2
1376 @section @code{ATAN2} --- Arctangent function
1377 @fnindex ATAN2
1378 @fnindex DATAN2
1379 @cindex trigonometric function, tangent, inverse
1380 @cindex tangent, inverse
1381
1382 @table @asis
1383 @item @emph{Description}:
1384 @code{ATAN2(Y,X)} computes the arctangent of the complex number
1385 @math{X + i Y}.
1386
1387 @item @emph{Standard}:
1388 F77 and later
1389
1390 @item @emph{Class}:
1391 Elemental function
1392
1393 @item @emph{Syntax}:
1394 @code{RESULT = ATAN2(Y,X)}
1395
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.
1401 @end multitable
1402
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
1410 is @math{\pi/2}.
1411
1412 @item @emph{Example}:
1413 @smallexample
1414 program test_atan2
1415 real(4) :: x = 1.e0_4, y = 0.5e0_4
1416 x = atan2(y,x)
1417 end program test_atan2
1418 @end smallexample
1419
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
1424 @end multitable
1425 @end table
1426
1427
1428
1429 @node ATANH
1430 @section @code{ATANH} --- Hyperbolic arctangent function
1431 @fnindex ASINH
1432 @fnindex DASINH
1433 @cindex area hyperbolic tangent
1434 @cindex hyperbolic arctangent
1435 @cindex hyperbolic function, tangent, inverse
1436 @cindex tangent, hyperbolic, inverse
1437
1438 @table @asis
1439 @item @emph{Description}:
1440 @code{ATANH(X)} computes the hyperbolic arctangent of @var{X} (inverse
1441 of @code{TANH(X)}).
1442
1443 @item @emph{Standard}:
1444 GNU extension
1445
1446 @item @emph{Class}:
1447 Elemental function
1448
1449 @item @emph{Syntax}:
1450 @code{RESULT = ATANH(X)}
1451
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.
1456 @end multitable
1457
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}.
1461
1462 @item @emph{Example}:
1463 @smallexample
1464 PROGRAM test_atanh
1465 REAL, DIMENSION(3) :: x = (/ -1.0, 0.0, 1.0 /)
1466 WRITE (*,*) ATANH(x)
1467 END PROGRAM
1468 @end smallexample
1469
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
1474 @end multitable
1475
1476 @item @emph{See also}:
1477 Inverse function: @ref{TANH}
1478 @end table
1479
1480
1481
1482 @node BESJ0
1483 @section @code{BESJ0} --- Bessel function of the first kind of order 0
1484 @fnindex BESJ0
1485 @fnindex DBESJ0
1486 @cindex Bessel function, first kind
1487
1488 @table @asis
1489 @item @emph{Description}:
1490 @code{BESJ0(X)} computes the Bessel function of the first kind of order 0
1491 of @var{X}.
1492
1493 @item @emph{Standard}:
1494 GNU extension
1495
1496 @item @emph{Class}:
1497 Elemental function
1498
1499 @item @emph{Syntax}:
1500 @code{RESULT = BESJ0(X)}
1501
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.
1505 @end multitable
1506
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}.
1510
1511 @item @emph{Example}:
1512 @smallexample
1513 program test_besj0
1514 real(8) :: x = 0.0_8
1515 x = besj0(x)
1516 end program test_besj0
1517 @end smallexample
1518
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
1523 @end multitable
1524 @end table
1525
1526
1527
1528 @node BESJ1
1529 @section @code{BESJ1} --- Bessel function of the first kind of order 1
1530 @fnindex BESJ1
1531 @fnindex DBESJ1
1532 @cindex Bessel function, first kind
1533
1534 @table @asis
1535 @item @emph{Description}:
1536 @code{BESJ1(X)} computes the Bessel function of the first kind of order 1
1537 of @var{X}.
1538
1539 @item @emph{Standard}:
1540 GNU extension
1541
1542 @item @emph{Class}:
1543 Elemental function
1544
1545 @item @emph{Syntax}:
1546 @code{RESULT = BESJ1(X)}
1547
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.
1551 @end multitable
1552
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 }.
1556
1557 @item @emph{Example}:
1558 @smallexample
1559 program test_besj1
1560 real(8) :: x = 1.0_8
1561 x = besj1(x)
1562 end program test_besj1
1563 @end smallexample
1564
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
1569 @end multitable
1570 @end table
1571
1572
1573
1574 @node BESJN
1575 @section @code{BESJN} --- Bessel function of the first kind
1576 @fnindex BESJN
1577 @fnindex DBESJN
1578 @cindex Bessel function, first kind
1579
1580 @table @asis
1581 @item @emph{Description}:
1582 @code{BESJN(N, X)} computes the Bessel function of the first kind of order
1583 @var{N} of @var{X}.
1584
1585 If both arguments are arrays, their ranks and shapes shall conform.
1586
1587 @item @emph{Standard}:
1588 GNU extension
1589
1590 @item @emph{Class}:
1591 Elemental function
1592
1593 @item @emph{Syntax}:
1594 @code{RESULT = BESJN(N, X)}
1595
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(*)}.
1600 @end multitable
1601
1602 @item @emph{Return value}:
1603 The return value is a scalar of type @code{REAL(*)}.
1604
1605 @item @emph{Example}:
1606 @smallexample
1607 program test_besjn
1608 real(8) :: x = 1.0_8
1609 x = besjn(5,x)
1610 end program test_besjn
1611 @end smallexample
1612
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
1618 @end multitable
1619 @end table
1620
1621
1622
1623 @node BESY0
1624 @section @code{BESY0} --- Bessel function of the second kind of order 0
1625 @fnindex BESY0
1626 @fnindex DBESY0
1627 @cindex Bessel function, second kind
1628
1629 @table @asis
1630 @item @emph{Description}:
1631 @code{BESY0(X)} computes the Bessel function of the second kind of order 0
1632 of @var{X}.
1633
1634 @item @emph{Standard}:
1635 GNU extension
1636
1637 @item @emph{Class}:
1638 Elemental function
1639
1640 @item @emph{Syntax}:
1641 @code{RESULT = BESY0(X)}
1642
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.
1646 @end multitable
1647
1648 @item @emph{Return value}:
1649 The return value is a scalar of type @code{REAL(*)}.
1650
1651 @item @emph{Example}:
1652 @smallexample
1653 program test_besy0
1654 real(8) :: x = 0.0_8
1655 x = besy0(x)
1656 end program test_besy0
1657 @end smallexample
1658
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
1663 @end multitable
1664 @end table
1665
1666
1667
1668 @node BESY1
1669 @section @code{BESY1} --- Bessel function of the second kind of order 1
1670 @fnindex BESY1
1671 @fnindex DBESY1
1672 @cindex Bessel function, second kind
1673
1674 @table @asis
1675 @item @emph{Description}:
1676 @code{BESY1(X)} computes the Bessel function of the second kind of order 1
1677 of @var{X}.
1678
1679 @item @emph{Standard}:
1680 GNU extension
1681
1682 @item @emph{Class}:
1683 Elemental function
1684
1685 @item @emph{Syntax}:
1686 @code{RESULT = BESY1(X)}
1687
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.
1691 @end multitable
1692
1693 @item @emph{Return value}:
1694 The return value is a scalar of type @code{REAL(*)}.
1695
1696 @item @emph{Example}:
1697 @smallexample
1698 program test_besy1
1699 real(8) :: x = 1.0_8
1700 x = besy1(x)
1701 end program test_besy1
1702 @end smallexample
1703
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
1708 @end multitable
1709 @end table
1710
1711
1712
1713 @node BESYN
1714 @section @code{BESYN} --- Bessel function of the second kind
1715 @fnindex BESYN
1716 @fnindex DBESYN
1717 @cindex Bessel function, second kind
1718
1719 @table @asis
1720 @item @emph{Description}:
1721 @code{BESYN(N, X)} computes the Bessel function of the second kind of order
1722 @var{N} of @var{X}.
1723
1724 If both arguments are arrays, their ranks and shapes shall conform.
1725
1726 @item @emph{Standard}:
1727 GNU extension
1728
1729 @item @emph{Class}:
1730 Elemental function
1731
1732 @item @emph{Syntax}:
1733 @code{RESULT = BESYN(N, X)}
1734
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(*)}.
1739 @end multitable
1740
1741 @item @emph{Return value}:
1742 The return value is a scalar of type @code{REAL(*)}.
1743
1744 @item @emph{Example}:
1745 @smallexample
1746 program test_besyn
1747 real(8) :: x = 1.0_8
1748 x = besyn(5,x)
1749 end program test_besyn
1750 @end smallexample
1751
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
1757 @end multitable
1758 @end table
1759
1760
1761
1762 @node BIT_SIZE
1763 @section @code{BIT_SIZE} --- Bit size inquiry function
1764 @fnindex BIT_SIZE
1765 @cindex bits, number of
1766 @cindex size of a variable, in bits
1767
1768 @table @asis
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}.
1772
1773 @item @emph{Standard}:
1774 F95 and later
1775
1776 @item @emph{Class}:
1777 Inquiry function
1778
1779 @item @emph{Syntax}:
1780 @code{RESULT = BIT_SIZE(I)}
1781
1782 @item @emph{Arguments}:
1783 @multitable @columnfractions .15 .70
1784 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
1785 @end multitable
1786
1787 @item @emph{Return value}:
1788 The return value is of type @code{INTEGER(*)}
1789
1790 @item @emph{Example}:
1791 @smallexample
1792 program test_bit_size
1793 integer :: i = 123
1794 integer :: size
1795 size = bit_size(i)
1796 print *, size
1797 end program test_bit_size
1798 @end smallexample
1799 @end table
1800
1801
1802
1803 @node BTEST
1804 @section @code{BTEST} --- Bit test function
1805 @fnindex BTEST
1806 @cindex bits, testing
1807
1808 @table @asis
1809 @item @emph{Description}:
1810 @code{BTEST(I,POS)} returns logical @code{.TRUE.} if the bit at @var{POS}
1811 in @var{I} is set.
1812
1813 @item @emph{Standard}:
1814 F95 and later
1815
1816 @item @emph{Class}:
1817 Elemental function
1818
1819 @item @emph{Syntax}:
1820 @code{RESULT = BTEST(I, POS)}
1821
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(*)}.
1826 @end multitable
1827
1828 @item @emph{Return value}:
1829 The return value is of type @code{LOGICAL}
1830
1831 @item @emph{Example}:
1832 @smallexample
1833 program test_btest
1834 integer :: i = 32768 + 1024 + 64
1835 integer :: pos
1836 logical :: bool
1837 do pos=0,16
1838 bool = btest(i, pos)
1839 print *, pos, bool
1840 end do
1841 end program test_btest
1842 @end smallexample
1843 @end table
1844
1845
1846 @node C_ASSOCIATED
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
1851
1852 @table @asis
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}.
1856
1857 @item @emph{Standard}:
1858 F2003 and later
1859
1860 @item @emph{Class}:
1861 Inquiry function
1862
1863 @item @emph{Syntax}:
1864 @code{RESULT = C_ASSOICATED(c_prt1[, c_ptr2])}
1865
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}.
1870 @end multitable
1871
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.
1876
1877 @item @emph{Example}:
1878 @smallexample
1879 subroutine association_test(a,b)
1880 use iso_c_binding, only: c_associated, c_loc, c_ptr
1881 implicit none
1882 real, pointer :: a
1883 type(c_ptr) :: b
1884 if(c_associated(b, c_loc(a))) &
1885 stop 'b and a do not point to same target'
1886 end subroutine association_test
1887 @end smallexample
1888
1889 @item @emph{See also}:
1890 @ref{C_LOC}, @ref{C_FUNLOC}
1891 @end table
1892
1893
1894 @node C_FUNLOC
1895 @section @code{C_FUNLOC} --- Obtain the C address of a procedure
1896 @fnindex C_FUNLOC
1897 @cindex pointer, C address of procedures
1898
1899 @table @asis
1900 @item @emph{Description}:
1901 @code{C_FUNLOC(x)} determines the C address of the argument.
1902
1903 @item @emph{Standard}:
1904 F2003 and later
1905
1906 @item @emph{Class}:
1907 Inquiry function
1908
1909 @item @emph{Syntax}:
1910 @code{RESULT = C_FUNLOC(x)}
1911
1912 @item @emph{Arguments}:
1913 @multitable @columnfractions .15 .70
1914 @item @var{x} @tab Interoperable function or pointer to such function.
1915 @end multitable
1916
1917 @item @emph{Return value}:
1918 The return value is of type @code{C_FUNPTR} and contains the C address
1919 of the argument.
1920
1921 @item @emph{Example}:
1922 @smallexample
1923 module x
1924 use iso_c_binding
1925 implicit none
1926 contains
1927 subroutine sub(a) bind(c)
1928 real(c_float) :: a
1929 a = sqrt(a)+5.0
1930 end subroutine sub
1931 end module x
1932 program main
1933 use iso_c_binding
1934 use x
1935 implicit none
1936 interface
1937 subroutine my_routine(p) bind(c,name='myC_func')
1938 import :: c_funptr
1939 type(c_funptr), intent(in) :: p
1940 end subroutine
1941 end interface
1942 call my_routine(c_funloc(sub))
1943 end program main
1944 @end smallexample
1945
1946 @item @emph{See also}:
1947 @ref{C_ASSOCIATED}, @ref{C_LOC}, @ref{C_F_POINTER}, @ref{C_F_PROCPOINTER}
1948 @end table
1949
1950
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
1955
1956 @table @asis
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}.
1960
1961 Note: Due to the currently lacking support of procedure pointers in GNU Fortran
1962 this function is not fully operable.
1963
1964 @item @emph{Standard}:
1965 F2003 and later
1966
1967 @item @emph{Class}:
1968 Subroutine
1969
1970 @item @emph{Syntax}:
1971 @code{CALL C_F_PROCPOINTER(cptr, fptr)}
1972
1973 @item @emph{Arguments}:
1974 @multitable @columnfractions .15 .70
1975 @item @var{cptr} @tab scalar of the type @code{C_FUNPTR}. It is
1976 @code{INTENT(IN)}.
1977 @item @var{fptr} @tab procedure pointer interoperable with @var{cptr}. It is
1978 @code{INTENT(OUT)}.
1979 @end multitable
1980
1981 @item @emph{Example}:
1982 @smallexample
1983 program main
1984 use iso_c_binding
1985 implicit none
1986 abstract interface
1987 function func(a)
1988 import :: c_float
1989 real(c_float), intent(in) :: a
1990 real(c_float) :: func
1991 end function
1992 end interface
1993 interface
1994 function getIterFunc() bind(c,name="getIterFunc")
1995 import :: c_funptr
1996 type(c_funptr) :: getIterFunc
1997 end function
1998 end interface
1999 type(c_funptr) :: cfunptr
2000 procedure(func), pointer :: myFunc
2001 cfunptr = getIterFunc()
2002 call c_f_procpointer(cfunptr, myFunc)
2003 end program main
2004 @end smallexample
2005
2006 @item @emph{See also}:
2007 @ref{C_LOC}, @ref{C_F_POINTER}
2008 @end table
2009
2010
2011 @node 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
2015
2016 @table @asis
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
2020 shape.
2021
2022 @item @emph{Standard}:
2023 F2003 and later
2024
2025 @item @emph{Class}:
2026 Subroutine
2027
2028 @item @emph{Syntax}:
2029 @code{CALL C_F_POINTER(cptr, fptr[, shape])}
2030
2031 @item @emph{Arguments}:
2032 @multitable @columnfractions .15 .70
2033 @item @var{cptr} @tab scalar of the type @code{C_PTR}. It is
2034 @code{INTENT(IN)}.
2035 @item @var{fptr} @tab pointer interoperable with @var{cptr}. It is
2036 @code{INTENT(OUT)}.
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}.
2041 @end multitable
2042
2043 @item @emph{Example}:
2044 @smallexample
2045 program main
2046 use iso_c_binding
2047 implicit none
2048 interface
2049 subroutine my_routine(p) bind(c,name='myC_func')
2050 import :: c_ptr
2051 type(c_ptr), intent(out) :: p
2052 end subroutine
2053 end interface
2054 type(c_ptr) :: cptr
2055 real,pointer :: a(:)
2056 call my_routine(cptr)
2057 call c_f_pointer(cptr, a, [12])
2058 end program main
2059 @end smallexample
2060
2061 @item @emph{See also}:
2062 @ref{C_LOC}, @ref{C_F_PROCPOINTER}
2063 @end table
2064
2065
2066 @node C_LOC
2067 @section @code{C_LOC} --- Obtain the C address of an object
2068 @fnindex C_LOC
2069 @cindex procedure pointer, convert C to Fortran
2070
2071 @table @asis
2072 @item @emph{Description}:
2073 @code{C_LOC(x)} determines the C address of the argument.
2074
2075 @item @emph{Standard}:
2076 F2003 and later
2077
2078 @item @emph{Class}:
2079 Inquiry function
2080
2081 @item @emph{Syntax}:
2082 @code{RESULT = C_LOC(x)}
2083
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}
2088 attribute.
2089 @end multitable
2090
2091 @item @emph{Return value}:
2092 The return value is of type @code{C_PTR} and contains the C address
2093 of the argument.
2094
2095 @item @emph{Example}:
2096 @smallexample
2097 subroutine association_test(a,b)
2098 use iso_c_binding, only: c_associated, c_loc, c_ptr
2099 implicit none
2100 real, pointer :: a
2101 type(c_ptr) :: b
2102 if(c_associated(b, c_loc(a))) &
2103 stop 'b and a do not point to same target'
2104 end subroutine association_test
2105 @end smallexample
2106
2107 @item @emph{See also}:
2108 @ref{C_ASSOCIATED}, @ref{C_FUNLOC}, @ref{C_F_POINTER}, @ref{C_F_PROCPOINTER}
2109 @end table
2110
2111
2112 @node CEILING
2113 @section @code{CEILING} --- Integer ceiling function
2114 @fnindex CEILING
2115 @cindex ceiling
2116 @cindex rounding, ceiling
2117
2118 @table @asis
2119 @item @emph{Description}:
2120 @code{CEILING(X)} returns the least integer greater than or equal to @var{X}.
2121
2122 @item @emph{Standard}:
2123 F95 and later
2124
2125 @item @emph{Class}:
2126 Elemental function
2127
2128 @item @emph{Syntax}:
2129 @code{RESULT = CEILING(X [, KIND])}
2130
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
2136 the result.
2137 @end multitable
2138
2139 @item @emph{Return value}:
2140 The return value is of type @code{INTEGER(KIND)}
2141
2142 @item @emph{Example}:
2143 @smallexample
2144 program test_ceiling
2145 real :: x = 63.29
2146 real :: y = -63.59
2147 print *, ceiling(x) ! returns 64
2148 print *, ceiling(y) ! returns -63
2149 end program test_ceiling
2150 @end smallexample
2151
2152 @item @emph{See also}:
2153 @ref{FLOOR}, @ref{NINT}
2154
2155 @end table
2156
2157
2158
2159 @node CHAR
2160 @section @code{CHAR} --- Character conversion function
2161 @fnindex CHAR
2162 @cindex conversion, to character
2163
2164 @table @asis
2165 @item @emph{Description}:
2166 @code{CHAR(I [, KIND])} returns the character represented by the integer @var{I}.
2167
2168 @item @emph{Standard}:
2169 F77 and later
2170
2171 @item @emph{Class}:
2172 Elemental function
2173
2174 @item @emph{Syntax}:
2175 @code{RESULT = CHAR(I [, KIND])}
2176
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
2182 the result.
2183 @end multitable
2184
2185 @item @emph{Return value}:
2186 The return value is of type @code{CHARACTER(1)}
2187
2188 @item @emph{Example}:
2189 @smallexample
2190 program test_char
2191 integer :: i = 74
2192 character(1) :: c
2193 c = char(i)
2194 print *, i, c ! returns 'J'
2195 end program test_char
2196 @end smallexample
2197
2198 @item @emph{Note}:
2199 See @ref{ICHAR} for a discussion of converting between numerical values
2200 and formatted string representations.
2201
2202 @item @emph{See also}:
2203 @ref{ACHAR}, @ref{IACHAR}, @ref{ICHAR}
2204
2205 @end table
2206
2207
2208
2209 @node CHDIR
2210 @section @code{CHDIR} --- Change working directory
2211 @fnindex CHDIR
2212 @cindex system, working directory
2213
2214 @table @asis
2215 @item @emph{Description}:
2216 Change current working directory to a specified path.
2217
2218 This intrinsic is provided in both subroutine and function forms; however,
2219 only one form can be used in any given program unit.
2220
2221 @item @emph{Standard}:
2222 GNU extension
2223
2224 @item @emph{Class}:
2225 Subroutine, function
2226
2227 @item @emph{Syntax}:
2228 @multitable @columnfractions .80
2229 @item @code{CALL CHDIR(NAME [, STATUS])}
2230 @item @code{STATUS = CHDIR(NAME)}
2231 @end multitable
2232
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.
2240 @end multitable
2241
2242 @item @emph{Example}:
2243 @smallexample
2244 PROGRAM test_chdir
2245 CHARACTER(len=255) :: path
2246 CALL getcwd(path)
2247 WRITE(*,*) TRIM(path)
2248 CALL chdir("/tmp")
2249 CALL getcwd(path)
2250 WRITE(*,*) TRIM(path)
2251 END PROGRAM
2252 @end smallexample
2253
2254 @item @emph{See also}:
2255 @ref{GETCWD}
2256 @end table
2257
2258
2259
2260 @node CHMOD
2261 @section @code{CHMOD} --- Change access permissions of files
2262 @fnindex CHMOD
2263 @cindex file system, change access mode
2264
2265 @table @asis
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.
2269
2270 This intrinsic is provided in both subroutine and function forms; however,
2271 only one form can be used in any given program unit.
2272
2273 @item @emph{Standard}:
2274 GNU extension
2275
2276 @item @emph{Class}:
2277 Subroutine, function
2278
2279 @item @emph{Syntax}:
2280 @multitable @columnfractions .80
2281 @item @code{CALL CHMOD(NAME, MODE[, STATUS])}
2282 @item @code{STATUS = CHMOD(NAME, MODE)}
2283 @end multitable
2284
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.
2291
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
2294 @code{/bin/chmod}.
2295
2296 @item @var{STATUS} @tab (optional) scalar @code{INTEGER}, which is
2297 @code{0} on success and nonzero otherwise.
2298 @end multitable
2299
2300 @item @emph{Return value}:
2301 In either syntax, @var{STATUS} is set to @code{0} on success and nonzero
2302 otherwise.
2303
2304 @item @emph{Example}:
2305 @code{CHMOD} as subroutine
2306 @smallexample
2307 program chmod_test
2308 implicit none
2309 integer :: status
2310 call chmod('test.dat','u+x',status)
2311 print *, 'Status: ', status
2312 end program chmod_test
2313 @end smallexample
2314 @code{CHMOD} as function:
2315 @smallexample
2316 program chmod_test
2317 implicit none
2318 integer :: status
2319 status = chmod('test.dat','u+x')
2320 print *, 'Status: ', status
2321 end program chmod_test
2322 @end smallexample
2323
2324 @end table
2325
2326
2327
2328 @node CMPLX
2329 @section @code{CMPLX} --- Complex conversion function
2330 @fnindex CMPLX
2331 @cindex complex numbers, conversion to
2332 @cindex conversion, to complex
2333
2334 @table @asis
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.
2340
2341 @item @emph{Standard}:
2342 F77 and later
2343
2344 @item @emph{Class}:
2345 Elemental function
2346
2347 @item @emph{Syntax}:
2348 @code{RESULT = CMPLX(X [, Y [, KIND]])}
2349
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(*)}
2356 or @code{REAL(*)}.
2357 @item @var{KIND} @tab (Optional) An @code{INTEGER(*)} initialization
2358 expression indicating the kind parameter of
2359 the result.
2360 @end multitable
2361
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}.
2367
2368 @item @emph{Example}:
2369 @smallexample
2370 program test_cmplx
2371 integer :: i = 42
2372 real :: x = 3.14
2373 complex :: z
2374 z = cmplx(i, x)
2375 print *, z, cmplx(x)
2376 end program test_cmplx
2377 @end smallexample
2378
2379 @item @emph{See also}:
2380 @ref{COMPLEX}
2381 @end table
2382
2383
2384
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
2391
2392 @table @asis
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.
2396
2397 @item @emph{Standard}:
2398 F2003
2399
2400 @item @emph{Class}:
2401 Inquiry function
2402
2403 @item @emph{Syntax}:
2404 @code{RESULT = COMMAND_ARGUMENT_COUNT()}
2405
2406 @item @emph{Arguments}:
2407 @multitable @columnfractions .15 .70
2408 @item None
2409 @end multitable
2410
2411 @item @emph{Return value}:
2412 The return value is of type @code{INTEGER(4)}
2413
2414 @item @emph{Example}:
2415 @smallexample
2416 program test_command_argument_count
2417 integer :: count
2418 count = command_argument_count()
2419 print *, count
2420 end program test_command_argument_count
2421 @end smallexample
2422
2423 @item @emph{See also}:
2424 @ref{GET_COMMAND}, @ref{GET_COMMAND_ARGUMENT}
2425 @end table
2426
2427
2428
2429 @node COMPLEX
2430 @section @code{COMPLEX} --- Complex conversion function
2431 @fnindex COMPLEX
2432 @cindex complex numbers, conversion to
2433 @cindex conversion, to complex
2434
2435 @table @asis
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
2439 component.
2440
2441 @item @emph{Standard}:
2442 GNU extension
2443
2444 @item @emph{Class}:
2445 Elemental function
2446
2447 @item @emph{Syntax}:
2448 @code{RESULT = COMPLEX(X, Y)}
2449
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(*)}.
2454 @end multitable
2455
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.
2459
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.
2464
2465 @item @emph{Example}:
2466 @smallexample
2467 program test_complex
2468 integer :: i = 42
2469 real :: x = 3.14
2470 print *, complex(i, x)
2471 end program test_complex
2472 @end smallexample
2473
2474 @item @emph{See also}:
2475 @ref{CMPLX}
2476 @end table
2477
2478
2479
2480 @node CONJG
2481 @section @code{CONJG} --- Complex conjugate function
2482 @fnindex CONJG
2483 @fnindex DCONJG
2484 @cindex complex conjugate
2485
2486 @table @asis
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)}
2490
2491 @item @emph{Standard}:
2492 F77 and later, has overloads that are GNU extensions
2493
2494 @item @emph{Class}:
2495 Elemental function
2496
2497 @item @emph{Syntax}:
2498 @code{Z = CONJG(Z)}
2499
2500 @item @emph{Arguments}:
2501 @multitable @columnfractions .15 .70
2502 @item @var{Z} @tab The type shall be @code{COMPLEX(*)}.
2503 @end multitable
2504
2505 @item @emph{Return value}:
2506 The return value is of type @code{COMPLEX(*)}.
2507
2508 @item @emph{Example}:
2509 @smallexample
2510 program test_conjg
2511 complex :: z = (2.0, 3.0)
2512 complex(8) :: dz = (2.71_8, -3.14_8)
2513 z= conjg(z)
2514 print *, z
2515 dz = dconjg(dz)
2516 print *, dz
2517 end program test_conjg
2518 @end smallexample
2519
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
2524 @end multitable
2525 @end table
2526
2527
2528
2529 @node COS
2530 @section @code{COS} --- Cosine function
2531 @fnindex COS
2532 @fnindex DCOS
2533 @fnindex CCOS
2534 @fnindex ZCOS
2535 @fnindex CDCOS
2536 @cindex trigonometric function, cosine
2537 @cindex cosine
2538
2539 @table @asis
2540 @item @emph{Description}:
2541 @code{COS(X)} computes the cosine of @var{X}.
2542
2543 @item @emph{Standard}:
2544 F77 and later, has overloads that are GNU extensions
2545
2546 @item @emph{Class}:
2547 Elemental function
2548
2549 @item @emph{Syntax}:
2550 @code{RESULT = COS(X)}
2551
2552 @item @emph{Arguments}:
2553 @multitable @columnfractions .15 .70
2554 @item @var{X} @tab The type shall be @code{REAL(*)} or
2555 @code{COMPLEX(*)}.
2556 @end multitable
2557
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}.
2562
2563 @item @emph{Example}:
2564 @smallexample
2565 program test_cos
2566 real :: x = 0.0
2567 x = cos(x)
2568 end program test_cos
2569 @end smallexample
2570
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
2578 @end multitable
2579
2580 @item @emph{See also}:
2581 Inverse function: @ref{ACOS}
2582
2583 @end table
2584
2585
2586
2587 @node COSH
2588 @section @code{COSH} --- Hyperbolic cosine function
2589 @fnindex COSH
2590 @fnindex DCOSH
2591 @cindex hyperbolic cosine
2592 @cindex hyperbolic function, cosine
2593 @cindex cosine, hyperbolic
2594
2595 @table @asis
2596 @item @emph{Description}:
2597 @code{COSH(X)} computes the hyperbolic cosine of @var{X}.
2598
2599 @item @emph{Standard}:
2600 F77 and later
2601
2602 @item @emph{Class}:
2603 Elemental function
2604
2605 @item @emph{Syntax}:
2606 @code{X = COSH(X)}
2607
2608 @item @emph{Arguments}:
2609 @multitable @columnfractions .15 .70
2610 @item @var{X} @tab The type shall be @code{REAL(*)}.
2611 @end multitable
2612
2613 @item @emph{Return value}:
2614 The return value is of type @code{REAL(*)} and it is positive
2615 (@math{ \cosh (x) \geq 0 }.
2616
2617 @item @emph{Example}:
2618 @smallexample
2619 program test_cosh
2620 real(8) :: x = 1.0_8
2621 x = cosh(x)
2622 end program test_cosh
2623 @end smallexample
2624
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
2629 @end multitable
2630
2631 @item @emph{See also}:
2632 Inverse function: @ref{ACOSH}
2633
2634 @end table
2635
2636
2637
2638 @node COUNT
2639 @section @code{COUNT} --- Count function
2640 @fnindex COUNT
2641 @cindex array, conditionally count elements
2642 @cindex array, element counting
2643 @cindex array, number of elements
2644
2645 @table @asis
2646 @item @emph{Description}:
2647
2648 @code{COUNT(MASK [, DIM [, KIND]])} counts the number of @code{.TRUE.}
2649 elements of @var{MASK} along the dimension of @var{DIM}. If @var{DIM} is
2650 omitted it is taken to be @code{1}. @var{DIM} is a scaler of type
2651 @code{INTEGER} in the range of @math{1 /leq DIM /leq n)} where @math{n}
2652 is the rank of @var{MASK}.
2653
2654 @item @emph{Standard}:
2655 F95 and later
2656
2657 @item @emph{Class}:
2658 Transformational function
2659
2660 @item @emph{Syntax}:
2661 @code{RESULT = COUNT(MASK [, DIM [, KIND]])}
2662
2663 @item @emph{Arguments}:
2664 @multitable @columnfractions .15 .70
2665 @item @var{MASK} @tab The type shall be @code{LOGICAL}.
2666 @item @var{DIM} @tab (Optional) The type shall be @code{INTEGER}.
2667 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
2668 expression indicating the kind parameter of
2669 the result.
2670 @end multitable
2671
2672 @item @emph{Return value}:
2673 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
2674 @var{KIND} is absent, the return value is of default integer kind.
2675 The result has a rank equal to that of @var{MASK}.
2676
2677 @item @emph{Example}:
2678 @smallexample
2679 program test_count
2680 integer, dimension(2,3) :: a, b
2681 logical, dimension(2,3) :: mask
2682 a = reshape( (/ 1, 2, 3, 4, 5, 6 /), (/ 2, 3 /))
2683 b = reshape( (/ 0, 7, 3, 4, 5, 8 /), (/ 2, 3 /))
2684 print '(3i3)', a(1,:)
2685 print '(3i3)', a(2,:)
2686 print *
2687 print '(3i3)', b(1,:)
2688 print '(3i3)', b(2,:)
2689 print *
2690 mask = a.ne.b
2691 print '(3l3)', mask(1,:)
2692 print '(3l3)', mask(2,:)
2693 print *
2694 print '(3i3)', count(mask)
2695 print *
2696 print '(3i3)', count(mask, 1)
2697 print *
2698 print '(3i3)', count(mask, 2)
2699 end program test_count
2700 @end smallexample
2701 @end table
2702
2703
2704
2705 @node CPU_TIME
2706 @section @code{CPU_TIME} --- CPU elapsed time in seconds
2707 @fnindex CPU_TIME
2708 @cindex time, elapsed
2709
2710 @table @asis
2711 @item @emph{Description}:
2712 Returns a @code{REAL(*)} value representing the elapsed CPU time in
2713 seconds. This is useful for testing segments of code to determine
2714 execution time.
2715
2716 @item @emph{Standard}:
2717 F95 and later
2718
2719 @item @emph{Class}:
2720 Subroutine
2721
2722 @item @emph{Syntax}:
2723 @code{CALL CPU_TIME(TIME)}
2724
2725 @item @emph{Arguments}:
2726 @multitable @columnfractions .15 .70
2727 @item @var{TIME} @tab The type shall be @code{REAL(*)} with @code{INTENT(OUT)}.
2728 @end multitable
2729
2730 @item @emph{Return value}:
2731 None
2732
2733 @item @emph{Example}:
2734 @smallexample
2735 program test_cpu_time
2736 real :: start, finish
2737 call cpu_time(start)
2738 ! put code to test here
2739 call cpu_time(finish)
2740 print '("Time = ",f6.3," seconds.")',finish-start
2741 end program test_cpu_time
2742 @end smallexample
2743
2744 @item @emph{See also}:
2745 @ref{SYSTEM_CLOCK}, @ref{DATE_AND_TIME}
2746 @end table
2747
2748
2749
2750 @node CSHIFT
2751 @section @code{CSHIFT} --- Circular shift elements of an array
2752 @fnindex CSHIFT
2753 @cindex array, shift circularly
2754 @cindex array, permutation
2755 @cindex array, rotate
2756
2757 @table @asis
2758 @item @emph{Description}:
2759 @code{CSHIFT(ARRAY, SHIFT [, DIM])} performs a circular shift on elements of
2760 @var{ARRAY} along the dimension of @var{DIM}. If @var{DIM} is omitted it is
2761 taken to be @code{1}. @var{DIM} is a scaler of type @code{INTEGER} in the
2762 range of @math{1 /leq DIM /leq n)} where @math{n} is the rank of @var{ARRAY}.
2763 If the rank of @var{ARRAY} is one, then all elements of @var{ARRAY} are shifted
2764 by @var{SHIFT} places. If rank is greater than one, then all complete rank one
2765 sections of @var{ARRAY} along the given dimension are shifted. Elements
2766 shifted out one end of each rank one section are shifted back in the other end.
2767
2768 @item @emph{Standard}:
2769 F95 and later
2770
2771 @item @emph{Class}:
2772 Transformational function
2773
2774 @item @emph{Syntax}:
2775 @code{RESULT = CSHIFT(ARRAY, SHIFT [, DIM])}
2776
2777 @item @emph{Arguments}:
2778 @multitable @columnfractions .15 .70
2779 @item @var{ARRAY} @tab Shall be an array of any type.
2780 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
2781 @item @var{DIM} @tab The type shall be @code{INTEGER}.
2782 @end multitable
2783
2784 @item @emph{Return value}:
2785 Returns an array of same type and rank as the @var{ARRAY} argument.
2786
2787 @item @emph{Example}:
2788 @smallexample
2789 program test_cshift
2790 integer, dimension(3,3) :: a
2791 a = reshape( (/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /), (/ 3, 3 /))
2792 print '(3i3)', a(1,:)
2793 print '(3i3)', a(2,:)
2794 print '(3i3)', a(3,:)
2795 a = cshift(a, SHIFT=(/1, 2, -1/), DIM=2)
2796 print *
2797 print '(3i3)', a(1,:)
2798 print '(3i3)', a(2,:)
2799 print '(3i3)', a(3,:)
2800 end program test_cshift
2801 @end smallexample
2802 @end table
2803
2804
2805
2806 @node CTIME
2807 @section @code{CTIME} --- Convert a time into a string
2808 @fnindex CTIME
2809 @cindex time, conversion to string
2810 @cindex conversion, to string
2811
2812 @table @asis
2813 @item @emph{Description}:
2814 @code{CTIME} converts a system time value, such as returned by
2815 @code{TIME8()}, to a string of the form @samp{Sat Aug 19 18:13:14 1995}.
2816
2817 This intrinsic is provided in both subroutine and function forms; however,
2818 only one form can be used in any given program unit.
2819
2820 @item @emph{Standard}:
2821 GNU extension
2822
2823 @item @emph{Class}:
2824 Subroutine, function
2825
2826 @item @emph{Syntax}:
2827 @multitable @columnfractions .80
2828 @item @code{CALL CTIME(TIME, RESULT)}.
2829 @item @code{RESULT = CTIME(TIME)}, (not recommended).
2830 @end multitable
2831
2832 @item @emph{Arguments}:
2833 @multitable @columnfractions .15 .70
2834 @item @var{TIME} @tab The type shall be of type @code{INTEGER(KIND=8)}.
2835 @item @var{RESULT} @tab The type shall be of type @code{CHARACTER}.
2836 @end multitable
2837
2838 @item @emph{Return value}:
2839 The converted date and time as a string.
2840
2841 @item @emph{Example}:
2842 @smallexample
2843 program test_ctime
2844 integer(8) :: i
2845 character(len=30) :: date
2846 i = time8()
2847
2848 ! Do something, main part of the program
2849
2850 call ctime(i,date)
2851 print *, 'Program was started on ', date
2852 end program test_ctime
2853 @end smallexample
2854
2855 @item @emph{See Also}:
2856 @ref{GMTIME}, @ref{LTIME}, @ref{TIME}, @ref{TIME8}
2857 @end table
2858
2859
2860
2861 @node DATE_AND_TIME
2862 @section @code{DATE_AND_TIME} --- Date and time subroutine
2863 @fnindex DATE_AND_TIME
2864 @cindex date, current
2865 @cindex current date
2866 @cindex time, current
2867 @cindex current time
2868
2869 @table @asis
2870 @item @emph{Description}:
2871 @code{DATE_AND_TIME(DATE, TIME, ZONE, VALUES)} gets the corresponding date and
2872 time information from the real-time system clock. @var{DATE} is
2873 @code{INTENT(OUT)} and has form ccyymmdd. @var{TIME} is @code{INTENT(OUT)} and
2874 has form hhmmss.sss. @var{ZONE} is @code{INTENT(OUT)} and has form (+-)hhmm,
2875 representing the difference with respect to Coordinated Universal Time (UTC).
2876 Unavailable time and date parameters return blanks.
2877
2878 @var{VALUES} is @code{INTENT(OUT)} and provides the following:
2879
2880 @multitable @columnfractions .15 .30 .40
2881 @item @tab @code{VALUE(1)}: @tab The year
2882 @item @tab @code{VALUE(2)}: @tab The month
2883 @item @tab @code{VALUE(3)}: @tab The day of the month
2884 @item @tab @code{VALUE(4)}: @tab Time difference with UTC in minutes
2885 @item @tab @code{VALUE(5)}: @tab The hour of the day
2886 @item @tab @code{VALUE(6)}: @tab The minutes of the hour
2887 @item @tab @code{VALUE(7)}: @tab The seconds of the minute
2888 @item @tab @code{VALUE(8)}: @tab The milliseconds of the second
2889 @end multitable
2890
2891 @item @emph{Standard}:
2892 F95 and later
2893
2894 @item @emph{Class}:
2895 Subroutine
2896
2897 @item @emph{Syntax}:
2898 @code{CALL DATE_AND_TIME([DATE, TIME, ZONE, VALUES])}
2899
2900 @item @emph{Arguments}:
2901 @multitable @columnfractions .15 .70
2902 @item @var{DATE} @tab (Optional) The type shall be @code{CHARACTER(8)} or larger.
2903 @item @var{TIME} @tab (Optional) The type shall be @code{CHARACTER(10)} or larger.
2904 @item @var{ZONE} @tab (Optional) The type shall be @code{CHARACTER(5)} or larger.
2905 @item @var{VALUES}@tab (Optional) The type shall be @code{INTEGER(8)}.
2906 @end multitable
2907
2908 @item @emph{Return value}:
2909 None
2910
2911 @item @emph{Example}:
2912 @smallexample
2913 program test_time_and_date
2914 character(8) :: date
2915 character(10) :: time
2916 character(5) :: zone
2917 integer,dimension(8) :: values
2918 ! using keyword arguments
2919 call date_and_time(date,time,zone,values)
2920 call date_and_time(DATE=date,ZONE=zone)
2921 call date_and_time(TIME=time)
2922 call date_and_time(VALUES=values)
2923 print '(a,2x,a,2x,a)', date, time, zone
2924 print '(8i5))', values
2925 end program test_time_and_date
2926 @end smallexample
2927
2928 @item @emph{See also}:
2929 @ref{CPU_TIME}, @ref{SYSTEM_CLOCK}
2930 @end table
2931
2932
2933
2934 @node DBLE
2935 @section @code{DBLE} --- Double conversion function
2936 @fnindex DBLE
2937 @cindex conversion, to real
2938
2939 @table @asis
2940 @item @emph{Description}:
2941 @code{DBLE(X)} Converts @var{X} to double precision real type.
2942
2943 @item @emph{Standard}:
2944 F77 and later
2945
2946 @item @emph{Class}:
2947 Elemental function
2948
2949 @item @emph{Syntax}:
2950 @code{RESULT = DBLE(X)}
2951
2952 @item @emph{Arguments}:
2953 @multitable @columnfractions .15 .70
2954 @item @var{X} @tab The type shall be @code{INTEGER(*)}, @code{REAL(*)},
2955 or @code{COMPLEX(*)}.
2956 @end multitable
2957
2958 @item @emph{Return value}:
2959 The return value is of type double precision real.
2960
2961 @item @emph{Example}:
2962 @smallexample
2963 program test_dble
2964 real :: x = 2.18
2965 integer :: i = 5
2966 complex :: z = (2.3,1.14)
2967 print *, dble(x), dble(i), dble(z)
2968 end program test_dble
2969 @end smallexample
2970
2971 @item @emph{See also}:
2972 @ref{DFLOAT}, @ref{FLOAT}, @ref{REAL}
2973 @end table
2974
2975
2976
2977 @node DCMPLX
2978 @section @code{DCMPLX} --- Double complex conversion function
2979 @fnindex DCMPLX
2980 @cindex complex numbers, conversion to
2981 @cindex conversion, to complex
2982
2983 @table @asis
2984 @item @emph{Description}:
2985 @code{DCMPLX(X [,Y])} returns a double complex number where @var{X} is
2986 converted to the real component. If @var{Y} is present it is converted to the
2987 imaginary component. If @var{Y} is not present then the imaginary component is
2988 set to 0.0. If @var{X} is complex then @var{Y} must not be present.
2989
2990 @item @emph{Standard}:
2991 GNU extension
2992
2993 @item @emph{Class}:
2994 Elemental function
2995
2996 @item @emph{Syntax}:
2997 @code{RESULT = DCMPLX(X [, Y])}
2998
2999 @item @emph{Arguments}:
3000 @multitable @columnfractions .15 .70
3001 @item @var{X} @tab The type may be @code{INTEGER(*)}, @code{REAL(*)},
3002 or @code{COMPLEX(*)}.
3003 @item @var{Y} @tab (Optional if @var{X} is not @code{COMPLEX(*)}.) May be
3004 @code{INTEGER(*)} or @code{REAL(*)}.
3005 @end multitable
3006
3007 @item @emph{Return value}:
3008 The return value is of type @code{COMPLEX(8)}
3009
3010 @item @emph{Example}:
3011 @smallexample
3012 program test_dcmplx
3013 integer :: i = 42
3014 real :: x = 3.14
3015 complex :: z
3016 z = cmplx(i, x)
3017 print *, dcmplx(i)
3018 print *, dcmplx(x)
3019 print *, dcmplx(z)
3020 print *, dcmplx(x,i)
3021 end program test_dcmplx
3022 @end smallexample
3023 @end table
3024
3025
3026
3027 @node DFLOAT
3028 @section @code{DFLOAT} --- Double conversion function
3029 @fnindex DFLOAT
3030 @cindex conversion, to real
3031
3032 @table @asis
3033 @item @emph{Description}:
3034 @code{DFLOAT(X)} Converts @var{X} to double precision real type.
3035
3036 @item @emph{Standard}:
3037 GNU extension
3038
3039 @item @emph{Class}:
3040 Elemental function
3041
3042 @item @emph{Syntax}:
3043 @code{RESULT = DFLOAT(X)}
3044
3045 @item @emph{Arguments}:
3046 @multitable @columnfractions .15 .70
3047 @item @var{X} @tab The type shall be @code{INTEGER(*)}.
3048 @end multitable
3049
3050 @item @emph{Return value}:
3051 The return value is of type double precision real.
3052
3053 @item @emph{Example}:
3054 @smallexample
3055 program test_dfloat
3056 integer :: i = 5
3057 print *, dfloat(i)
3058 end program test_dfloat
3059 @end smallexample
3060
3061 @item @emph{See also}:
3062 @ref{DBLE}, @ref{FLOAT}, @ref{REAL}
3063 @end table
3064
3065
3066
3067 @node DIGITS
3068 @section @code{DIGITS} --- Significant digits function
3069 @fnindex DIGITS
3070 @cindex model representation, significant digits
3071
3072 @table @asis
3073 @item @emph{Description}:
3074 @code{DIGITS(X)} returns the number of significant digits of the internal model
3075 representation of @var{X}. For example, on a system using a 32-bit
3076 floating point representation, a default real number would likely return 24.
3077
3078 @item @emph{Standard}:
3079 F95 and later
3080
3081 @item @emph{Class}:
3082 Inquiry function
3083
3084 @item @emph{Syntax}:
3085 @code{RESULT = DIGITS(X)}
3086
3087 @item @emph{Arguments}:
3088 @multitable @columnfractions .15 .70
3089 @item @var{X} @tab The type may be @code{INTEGER(*)} or @code{REAL(*)}.
3090 @end multitable
3091
3092 @item @emph{Return value}:
3093 The return value is of type @code{INTEGER}.
3094
3095 @item @emph{Example}:
3096 @smallexample
3097 program test_digits
3098 integer :: i = 12345
3099 real :: x = 3.143
3100 real(8) :: y = 2.33
3101 print *, digits(i)
3102 print *, digits(x)
3103 print *, digits(y)
3104 end program test_digits
3105 @end smallexample
3106 @end table
3107
3108
3109
3110 @node DIM
3111 @section @code{DIM} --- Positive difference
3112 @fnindex DIM
3113 @fnindex IDIM
3114 @fnindex DDIM
3115 @cindex positive difference
3116
3117 @table @asis
3118 @item @emph{Description}:
3119 @code{DIM(X,Y)} returns the difference @code{X-Y} if the result is positive;
3120 otherwise returns zero.
3121
3122 @item @emph{Standard}:
3123 F77 and later
3124
3125 @item @emph{Class}:
3126 Elemental function
3127
3128 @item @emph{Syntax}:
3129 @code{RESULT = DIM(X, Y)}
3130
3131 @item @emph{Arguments}:
3132 @multitable @columnfractions .15 .70
3133 @item @var{X} @tab The type shall be @code{INTEGER(*)} or @code{REAL(*)}
3134 @item @var{Y} @tab The type shall be the same type and kind as @var{X}.
3135 @end multitable
3136
3137 @item @emph{Return value}:
3138 The return value is of type @code{INTEGER(*)} or @code{REAL(*)}.
3139
3140 @item @emph{Example}:
3141 @smallexample
3142 program test_dim
3143 integer :: i
3144 real(8) :: x
3145 i = dim(4, 15)
3146 x = dim(4.345_8, 2.111_8)
3147 print *, i
3148 print *, x
3149 end program test_dim
3150 @end smallexample
3151
3152 @item @emph{Specific names}:
3153 @multitable @columnfractions .20 .20 .20 .25
3154 @item Name @tab Argument @tab Return type @tab Standard
3155 @item @code{IDIM(X,Y)} @tab @code{INTEGER(4) X,Y} @tab @code{INTEGER(4)} @tab F77 and later
3156 @item @code{DDIM(X,Y)} @tab @code{REAL(8) X,Y} @tab @code{REAL(8)} @tab F77 and later
3157 @end multitable
3158 @end table
3159
3160
3161
3162 @node DOT_PRODUCT
3163 @section @code{DOT_PRODUCT} --- Dot product function
3164 @fnindex DOT_PRODUCT
3165 @cindex dot product
3166 @cindex vector product
3167 @cindex product, vector
3168
3169 @table @asis
3170 @item @emph{Description}:
3171 @code{DOT_PRODUCT(X,Y)} computes the dot product multiplication of two vectors
3172 @var{X} and @var{Y}. The two vectors may be either numeric or logical
3173 and must be arrays of rank one and of equal size. If the vectors are
3174 @code{INTEGER(*)} or @code{REAL(*)}, the result is @code{SUM(X*Y)}. If the
3175 vectors are @code{COMPLEX(*)}, the result is @code{SUM(CONJG(X)*Y)}. If the
3176 vectors are @code{LOGICAL}, the result is @code{ANY(X.AND.Y)}.
3177
3178 @item @emph{Standard}:
3179 F95 and later
3180
3181 @item @emph{Class}:
3182 Transformational function
3183
3184 @item @emph{Syntax}:
3185 @code{RESULT = DOT_PRODUCT(X, Y)}
3186
3187 @item @emph{Arguments}:
3188 @multitable @columnfractions .15 .70
3189 @item @var{X} @tab The type shall be numeric or @code{LOGICAL}, rank 1.
3190 @item @var{Y} @tab The type shall be numeric or @code{LOGICAL}, rank 1.
3191 @end multitable
3192
3193 @item @emph{Return value}:
3194 If the arguments are numeric, the return value is a scaler of numeric type,
3195 @code{INTEGER(*)}, @code{REAL(*)}, or @code{COMPLEX(*)}. If the arguments are
3196 @code{LOGICAL}, the return value is @code{.TRUE.} or @code{.FALSE.}.
3197
3198 @item @emph{Example}:
3199 @smallexample
3200 program test_dot_prod
3201 integer, dimension(3) :: a, b
3202 a = (/ 1, 2, 3 /)
3203 b = (/ 4, 5, 6 /)
3204 print '(3i3)', a
3205 print *
3206 print '(3i3)', b
3207 print *
3208 print *, dot_product(a,b)
3209 end program test_dot_prod
3210 @end smallexample
3211 @end table
3212
3213
3214
3215 @node DPROD
3216 @section @code{DPROD} --- Double product function
3217 @fnindex DPROD
3218 @cindex product, double-precision
3219
3220 @table @asis
3221 @item @emph{Description}:
3222 @code{DPROD(X,Y)} returns the product @code{X*Y}.
3223
3224 @item @emph{Standard}:
3225 F77 and later
3226
3227 @item @emph{Class}:
3228 Elemental function
3229
3230 @item @emph{Syntax}:
3231 @code{RESULT = DPROD(X, Y)}
3232
3233 @item @emph{Arguments}:
3234 @multitable @columnfractions .15 .70
3235 @item @var{X} @tab The type shall be @code{REAL}.
3236 @item @var{Y} @tab The type shall be @code{REAL}.
3237 @end multitable
3238
3239 @item @emph{Return value}:
3240 The return value is of type @code{REAL(8)}.
3241
3242 @item @emph{Example}:
3243 @smallexample
3244 program test_dprod
3245 real :: x = 5.2
3246 real :: y = 2.3
3247 real(8) :: d
3248 d = dprod(x,y)
3249 print *, d
3250 end program test_dprod
3251 @end smallexample
3252 @end table
3253
3254
3255
3256 @node DREAL
3257 @section @code{DREAL} --- Double real part function
3258 @fnindex DREAL
3259 @cindex complex numbers, real part
3260
3261 @table @asis
3262 @item @emph{Description}:
3263 @code{DREAL(Z)} returns the real part of complex variable @var{Z}.
3264
3265 @item @emph{Standard}:
3266 GNU extension
3267
3268 @item @emph{Class}:
3269 Elemental function
3270
3271 @item @emph{Syntax}:
3272 @code{RESULT = DREAL(Z)}
3273
3274 @item @emph{Arguments}:
3275 @multitable @columnfractions .15 .70
3276 @item @var{Z} @tab The type shall be @code{COMPLEX(8)}.
3277 @end multitable
3278
3279 @item @emph{Return value}:
3280 The return value is of type @code{REAL(8)}.
3281
3282 @item @emph{Example}:
3283 @smallexample
3284 program test_dreal
3285 complex(8) :: z = (1.3_8,7.2_8)
3286 print *, dreal(z)
3287 end program test_dreal
3288 @end smallexample
3289
3290 @item @emph{See also}:
3291 @ref{AIMAG}
3292
3293 @end table
3294
3295
3296
3297 @node DTIME
3298 @section @code{DTIME} --- Execution time subroutine (or function)
3299 @fnindex DTIME
3300 @cindex time, elapsed
3301 @cindex elapsed time
3302
3303 @table @asis
3304 @item @emph{Description}:
3305 @code{DTIME(TARRAY, RESULT)} initially returns the number of seconds of runtime
3306 since the start of the process's execution in @var{RESULT}. @var{TARRAY}
3307 returns the user and system components of this time in @code{TARRAY(1)} and
3308 @code{TARRAY(2)} respectively. @var{RESULT} is equal to @code{TARRAY(1) +
3309 TARRAY(2)}.
3310
3311 Subsequent invocations of @code{DTIME} return values accumulated since the
3312 previous invocation.
3313
3314 On some systems, the underlying timings are represented using types with
3315 sufficiently small limits that overflows (wrap around) are possible, such as
3316 32-bit types. Therefore, the values returned by this intrinsic might be, or
3317 become, negative, or numerically less than previous values, during a single
3318 run of the compiled program.
3319
3320 This intrinsic is provided in both subroutine and function forms; however,
3321 only one form can be used in any given program unit.
3322
3323 @var{TARRAY} and @var{RESULT} are @code{INTENT(OUT)} and provide the following:
3324
3325 @multitable @columnfractions .15 .30 .40
3326 @item @tab @code{TARRAY(1)}: @tab User time in seconds.
3327 @item @tab @code{TARRAY(2)}: @tab System time in seconds.
3328 @item @tab @code{RESULT}: @tab Run time since start in seconds.
3329 @end multitable
3330
3331 @item @emph{Standard}:
3332 GNU extension
3333
3334 @item @emph{Class}:
3335 Subroutine, function
3336
3337 @item @emph{Syntax}:
3338 @multitable @columnfractions .80
3339 @item @code{CALL DTIME(TARRAY, RESULT)}.
3340 @item @code{RESULT = DTIME(TARRAY)}, (not recommended).
3341 @end multitable
3342
3343 @item @emph{Arguments}:
3344 @multitable @columnfractions .15 .70
3345 @item @var{TARRAY}@tab The type shall be @code{REAL, DIMENSION(2)}.
3346 @item @var{RESULT}@tab The type shall be @code{REAL}.
3347 @end multitable
3348
3349 @item @emph{Return value}:
3350 Elapsed time in seconds since the start of program execution.
3351
3352 @item @emph{Example}:
3353 @smallexample
3354 program test_dtime
3355 integer(8) :: i, j
3356 real, dimension(2) :: tarray
3357 real :: result
3358 call dtime(tarray, result)
3359 print *, result
3360 print *, tarray(1)
3361 print *, tarray(2)
3362 do i=1,100000000 ! Just a delay
3363 j = i * i - i
3364 end do
3365 call dtime(tarray, result)
3366 print *, result
3367 print *, tarray(1)
3368 print *, tarray(2)
3369 end program test_dtime
3370 @end smallexample
3371 @end table
3372
3373
3374
3375 @node EOSHIFT
3376 @section @code{EOSHIFT} --- End-off shift elements of an array
3377 @fnindex EOSHIFT
3378 @cindex array, shift
3379
3380 @table @asis
3381 @item @emph{Description}:
3382 @code{EOSHIFT(ARRAY, SHIFT[,BOUNDARY, DIM])} performs an end-off shift on
3383 elements of @var{ARRAY} along the dimension of @var{DIM}. If @var{DIM} is
3384 omitted it is taken to be @code{1}. @var{DIM} is a scaler of type
3385 @code{INTEGER} in the range of @math{1 /leq DIM /leq n)} where @math{n} is the
3386 rank of @var{ARRAY}. If the rank of @var{ARRAY} is one, then all elements of
3387 @var{ARRAY} are shifted by @var{SHIFT} places. If rank is greater than one,
3388 then all complete rank one sections of @var{ARRAY} along the given dimension are
3389 shifted. Elements shifted out one end of each rank one section are dropped. If
3390 @var{BOUNDARY} is present then the corresponding value of from @var{BOUNDARY}
3391 is copied back in the other end. If @var{BOUNDARY} is not present then the
3392 following are copied in depending on the type of @var{ARRAY}.
3393
3394 @multitable @columnfractions .15 .80
3395 @item @emph{Array Type} @tab @emph{Boundary Value}
3396 @item Numeric @tab 0 of the type and kind of @var{ARRAY}.
3397 @item Logical @tab @code{.FALSE.}.
3398 @item Character(@var{len}) @tab @var{len} blanks.
3399 @end multitable
3400
3401 @item @emph{Standard}:
3402 F95 and later
3403
3404 @item @emph{Class}:
3405 Transformational function
3406
3407 @item @emph{Syntax}:
3408 @code{RESULT = EOSHIFT(ARRAY, SHIFT [, BOUNDARY, DIM])}
3409
3410 @item @emph{Arguments}:
3411 @multitable @columnfractions .15 .70
3412 @item @var{ARRAY} @tab May be any type, not scaler.
3413 @item @var{SHIFT} @tab The type shall be @code{INTEGER}.
3414 @item @var{BOUNDARY} @tab Same type as @var{ARRAY}.
3415 @item @var{DIM} @tab The type shall be @code{INTEGER}.
3416 @end multitable
3417
3418 @item @emph{Return value}:
3419 Returns an array of same type and rank as the @var{ARRAY} argument.
3420
3421 @item @emph{Example}:
3422 @smallexample
3423 program test_eoshift
3424 integer, dimension(3,3) :: a
3425 a = reshape( (/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /), (/ 3, 3 /))
3426 print '(3i3)', a(1,:)
3427 print '(3i3)', a(2,:)
3428 print '(3i3)', a(3,:)
3429 a = EOSHIFT(a, SHIFT=(/1, 2, 1/), BOUNDARY=-5, DIM=2)
3430 print *
3431 print '(3i3)', a(1,:)
3432 print '(3i3)', a(2,:)
3433 print '(3i3)', a(3,:)
3434 end program test_eoshift
3435 @end smallexample
3436 @end table
3437
3438
3439
3440 @node EPSILON
3441 @section @code{EPSILON} --- Epsilon function
3442 @fnindex EPSILON
3443 @cindex model representation, epsilon
3444
3445 @table @asis
3446 @item @emph{Description}:
3447 @code{EPSILON(X)} returns a nearly negligible number relative to @code{1}.
3448
3449 @item @emph{Standard}:
3450 F95 and later
3451
3452 @item @emph{Class}:
3453 Inquiry function
3454
3455 @item @emph{Syntax}:
3456 @code{RESULT = EPSILON(X)}
3457
3458 @item @emph{Arguments}:
3459 @multitable @columnfractions .15 .70
3460 @item @var{X} @tab The type shall be @code{REAL(*)}.
3461 @end multitable
3462
3463 @item @emph{Return value}:
3464 The return value is of same type as the argument.
3465
3466 @item @emph{Example}:
3467 @smallexample
3468 program test_epsilon
3469 real :: x = 3.143
3470 real(8) :: y = 2.33
3471 print *, EPSILON(x)
3472 print *, EPSILON(y)
3473 end program test_epsilon
3474 @end smallexample
3475 @end table
3476
3477
3478
3479 @node ERF
3480 @section @code{ERF} --- Error function
3481 @fnindex ERF
3482 @cindex error function
3483
3484 @table @asis
3485 @item @emph{Description}:
3486 @code{ERF(X)} computes the error function of @var{X}.
3487
3488 @item @emph{Standard}:
3489 GNU Extension
3490
3491 @item @emph{Class}:
3492 Elemental function
3493
3494 @item @emph{Syntax}:
3495 @code{RESULT = ERF(X)}
3496
3497 @item @emph{Arguments}:
3498 @multitable @columnfractions .15 .70
3499 @item @var{X} @tab The type shall be @code{REAL(*)}, and it shall be scalar.
3500 @end multitable
3501
3502 @item @emph{Return value}:
3503 The return value is a scalar of type @code{REAL(*)} and it is positive
3504 (@math{ - 1 \leq erf (x) \leq 1 }.
3505
3506 @item @emph{Example}:
3507 @smallexample
3508 program test_erf
3509 real(8) :: x = 0.17_8
3510 x = erf(x)
3511 end program test_erf
3512 @end smallexample
3513
3514 @item @emph{Specific names}:
3515 @multitable @columnfractions .20 .20 .20 .25
3516 @item Name @tab Argument @tab Return type @tab Standard
3517 @item @code{DERF(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
3518 @end multitable
3519 @end table
3520
3521
3522
3523 @node ERFC
3524 @section @code{ERFC} --- Error function
3525 @fnindex ERFC
3526 @cindex error function, complementary
3527
3528 @table @asis
3529 @item @emph{Description}:
3530 @code{ERFC(X)} computes the complementary error function of @var{X}.
3531
3532 @item @emph{Standard}:
3533 GNU extension
3534
3535 @item @emph{Class}:
3536 Elemental function
3537
3538 @item @emph{Syntax}:
3539 @code{RESULT = ERFC(X)}
3540
3541 @item @emph{Arguments}:
3542 @multitable @columnfractions .15 .70
3543 @item @var{X} @tab The type shall be @code{REAL(*)}, and it shall be scalar.
3544 @end multitable
3545
3546 @item @emph{Return value}:
3547 The return value is a scalar of type @code{REAL(*)} and it is positive
3548 (@math{ 0 \leq erfc (x) \leq 2 }.
3549
3550 @item @emph{Example}:
3551 @smallexample
3552 program test_erfc
3553 real(8) :: x = 0.17_8
3554 x = erfc(x)
3555 end program test_erfc
3556 @end smallexample
3557
3558 @item @emph{Specific names}:
3559 @multitable @columnfractions .20 .20 .20 .25
3560 @item Name @tab Argument @tab Return type @tab Standard
3561 @item @code{DERFC(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab GNU extension
3562 @end multitable
3563 @end table
3564
3565
3566
3567 @node ETIME
3568 @section @code{ETIME} --- Execution time subroutine (or function)
3569 @fnindex ETIME
3570 @cindex time, elapsed
3571
3572 @table @asis
3573 @item @emph{Description}:
3574 @code{ETIME(TARRAY, RESULT)} returns the number of seconds of runtime
3575 since the start of the process's execution in @var{RESULT}. @var{TARRAY}
3576 returns the user and system components of this time in @code{TARRAY(1)} and
3577 @code{TARRAY(2)} respectively. @var{RESULT} is equal to @code{TARRAY(1) + TARRAY(2)}.
3578
3579 On some systems, the underlying timings are represented using types with
3580 sufficiently small limits that overflows (wrap around) are possible, such as
3581 32-bit types. Therefore, the values returned by this intrinsic might be, or
3582 become, negative, or numerically less than previous values, during a single
3583 run of the compiled program.
3584
3585 This intrinsic is provided in both subroutine and function forms; however,
3586 only one form can be used in any given program unit.
3587
3588 @var{TARRAY} and @var{RESULT} are @code{INTENT(OUT)} and provide the following:
3589
3590 @multitable @columnfractions .15 .30 .60
3591 @item @tab @code{TARRAY(1)}: @tab User time in seconds.
3592 @item @tab @code{TARRAY(2)}: @tab System time in seconds.
3593 @item @tab @code{RESULT}: @tab Run time since start in seconds.
3594 @end multitable
3595
3596 @item @emph{Standard}:
3597 GNU extension
3598
3599 @item @emph{Class}:
3600 Subroutine, function
3601
3602 @item @emph{Syntax}:
3603 @multitable @columnfractions .80
3604 @item @code{CALL ETIME(TARRAY, RESULT)}.
3605 @item @code{RESULT = ETIME(TARRAY)}, (not recommended).
3606 @end multitable
3607
3608 @item @emph{Arguments}:
3609 @multitable @columnfractions .15 .70
3610 @item @var{TARRAY}@tab The type shall be @code{REAL, DIMENSION(2)}.
3611 @item @var{RESULT}@tab The type shall be @code{REAL}.
3612 @end multitable
3613
3614 @item @emph{Return value}:
3615 Elapsed time in seconds since the start of program execution.
3616
3617 @item @emph{Example}:
3618 @smallexample
3619 program test_etime
3620 integer(8) :: i, j
3621 real, dimension(2) :: tarray
3622 real :: result
3623 call ETIME(tarray, result)
3624 print *, result
3625 print *, tarray(1)
3626 print *, tarray(2)
3627 do i=1,100000000 ! Just a delay
3628 j = i * i - i
3629 end do
3630 call ETIME(tarray, result)
3631 print *, result
3632 print *, tarray(1)
3633 print *, tarray(2)
3634 end program test_etime
3635 @end smallexample
3636
3637 @item @emph{See also}:
3638 @ref{CPU_TIME}
3639
3640 @end table
3641
3642
3643
3644 @node EXIT
3645 @section @code{EXIT} --- Exit the program with status.
3646 @fnindex EXIT
3647 @cindex program termination
3648 @cindex terminate program
3649
3650 @table @asis
3651 @item @emph{Description}:
3652 @code{EXIT} causes immediate termination of the program with status. If status
3653 is omitted it returns the canonical @emph{success} for the system. All Fortran
3654 I/O units are closed.
3655
3656 @item @emph{Standard}:
3657 GNU extension
3658
3659 @item @emph{Class}:
3660 Subroutine
3661
3662 @item @emph{Syntax}:
3663 @code{CALL EXIT([STATUS])}
3664
3665 @item @emph{Arguments}:
3666 @multitable @columnfractions .15 .70
3667 @item @var{STATUS} @tab Shall be an @code{INTEGER} of the default kind.
3668 @end multitable
3669
3670 @item @emph{Return value}:
3671 @code{STATUS} is passed to the parent process on exit.
3672
3673 @item @emph{Example}:
3674 @smallexample
3675 program test_exit
3676 integer :: STATUS = 0
3677 print *, 'This program is going to exit.'
3678 call EXIT(STATUS)
3679 end program test_exit
3680 @end smallexample
3681
3682 @item @emph{See also}:
3683 @ref{ABORT}, @ref{KILL}
3684 @end table
3685
3686
3687
3688 @node EXP
3689 @section @code{EXP} --- Exponential function
3690 @fnindex EXP
3691 @fnindex DEXP
3692 @fnindex CEXP
3693 @fnindex ZEXP
3694 @fnindex CDEXP
3695 @cindex exponential function
3696 @cindex logarithmic function, inverse
3697
3698 @table @asis
3699 @item @emph{Description}:
3700 @code{EXP(X)} computes the base @math{e} exponential of @var{X}.
3701
3702 @item @emph{Standard}:
3703 F77 and later, has overloads that are GNU extensions
3704
3705 @item @emph{Class}:
3706 Elemental function
3707
3708 @item @emph{Syntax}:
3709 @code{RESULT = EXP(X)}
3710
3711 @item @emph{Arguments}:
3712 @multitable @columnfractions .15 .70
3713 @item @var{X} @tab The type shall be @code{REAL(*)} or
3714 @code{COMPLEX(*)}.
3715 @end multitable
3716
3717 @item @emph{Return value}:
3718 The return value has same type and kind as @var{X}.
3719
3720 @item @emph{Example}:
3721 @smallexample
3722 program test_exp
3723 real :: x = 1.0
3724 x = exp(x)
3725 end program test_exp
3726 @end smallexample
3727
3728 @item @emph{Specific names}:
3729 @multitable @columnfractions .20 .20 .20 .25
3730 @item Name @tab Argument @tab Return type @tab Standard
3731 @item @code{DEXP(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F77 and later
3732 @item @code{CEXP(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab F77 and later
3733 @item @code{ZEXP(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
3734 @item @code{CDEXP(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
3735 @end multitable
3736 @end table
3737
3738
3739
3740 @node EXPONENT
3741 @section @code{EXPONENT} --- Exponent function
3742 @fnindex EXPONENT
3743 @cindex real number, exponent
3744 @cindex floating point, exponent
3745
3746 @table @asis
3747 @item @emph{Description}:
3748 @code{EXPONENT(X)} returns the value of the exponent part of @var{X}. If @var{X}
3749 is zero the value returned is zero.
3750
3751 @item @emph{Standard}:
3752 F95 and later
3753
3754 @item @emph{Class}:
3755 Elemental function
3756
3757 @item @emph{Syntax}:
3758 @code{RESULT = EXPONENT(X)}
3759
3760 @item @emph{Arguments}:
3761 @multitable @columnfractions .15 .70
3762 @item @var{X} @tab The type shall be @code{REAL(*)}.
3763 @end multitable
3764
3765 @item @emph{Return value}:
3766 The return value is of type default @code{INTEGER}.
3767
3768 @item @emph{Example}:
3769 @smallexample
3770 program test_exponent
3771 real :: x = 1.0
3772 integer :: i
3773 i = exponent(x)
3774 print *, i
3775 print *, exponent(0.0)
3776 end program test_exponent
3777 @end smallexample
3778 @end table
3779
3780
3781
3782 @node FDATE
3783 @section @code{FDATE} --- Get the current time as a string
3784 @fnindex FDATE
3785 @cindex time, current
3786 @cindex current time
3787 @cindex date, current
3788 @cindex current date
3789
3790 @table @asis
3791 @item @emph{Description}:
3792 @code{FDATE(DATE)} returns the current date (using the same format as
3793 @code{CTIME}) in @var{DATE}. It is equivalent to @code{CALL CTIME(DATE,
3794 TIME())}.
3795
3796 This intrinsic is provided in both subroutine and function forms; however,
3797 only one form can be used in any given program unit.
3798
3799 @var{DATE} is an @code{INTENT(OUT)} @code{CHARACTER} variable.
3800
3801 @item @emph{Standard}:
3802 GNU extension
3803
3804 @item @emph{Class}:
3805 Subroutine, function
3806
3807 @item @emph{Syntax}:
3808 @multitable @columnfractions .80
3809 @item @code{CALL FDATE(DATE)}.
3810 @item @code{DATE = FDATE()}, (not recommended).
3811 @end multitable
3812
3813 @item @emph{Arguments}:
3814 @multitable @columnfractions .15 .70
3815 @item @var{DATE}@tab The type shall be of type @code{CHARACTER}.
3816 @end multitable
3817
3818 @item @emph{Return value}:
3819 The current date as a string.
3820
3821 @item @emph{Example}:
3822 @smallexample
3823 program test_fdate
3824 integer(8) :: i, j
3825 character(len=30) :: date
3826 call fdate(date)
3827 print *, 'Program started on ', date
3828 do i = 1, 100000000 ! Just a delay
3829 j = i * i - i
3830 end do
3831 call fdate(date)
3832 print *, 'Program ended on ', date
3833 end program test_fdate
3834 @end smallexample
3835 @end table
3836
3837
3838
3839 @node FLOAT
3840 @section @code{FLOAT} --- Convert integer to default real
3841 @fnindex FLOAT
3842 @cindex conversion, to real
3843
3844 @table @asis
3845 @item @emph{Description}:
3846 @code{FLOAT(I)} converts the integer @var{I} to a default real value.
3847
3848 @item @emph{Standard}:
3849 GNU extension
3850
3851 @item @emph{Class}:
3852 Elemental function
3853
3854 @item @emph{Syntax}:
3855 @code{RESULT = FLOAT(I)}
3856
3857 @item @emph{Arguments}:
3858 @multitable @columnfractions .15 .70
3859 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
3860 @end multitable
3861
3862 @item @emph{Return value}:
3863 The return value is of type default @code{REAL}.
3864
3865 @item @emph{Example}:
3866 @smallexample
3867 program test_float
3868 integer :: i = 1
3869 if (float(i) /= 1.) call abort
3870 end program test_float
3871 @end smallexample
3872
3873 @item @emph{See also}:
3874 @ref{DBLE}, @ref{DFLOAT}, @ref{REAL}
3875 @end table
3876
3877
3878
3879 @node FGET
3880 @section @code{FGET} --- Read a single character in stream mode from stdin
3881 @fnindex FGET
3882 @cindex read character, stream mode
3883 @cindex stream mode, read character
3884 @cindex file operation, read character
3885
3886 @table @asis
3887 @item @emph{Description}:
3888 Read a single character in stream mode from stdin by bypassing normal
3889 formatted output. Stream I/O should not be mixed with normal record-oriented
3890 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
3891
3892 This intrinsic is provided in both subroutine and function forms; however,
3893 only one form can be used in any given program unit.
3894
3895 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
3896 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
3897 Programmers should consider the use of new stream IO feature in new code
3898 for future portability. See also @ref{Fortran 2003 status}.
3899
3900 @item @emph{Standard}:
3901 GNU extension
3902
3903 @item @emph{Class}:
3904 Subroutine, function
3905
3906 @item @emph{Syntax}:
3907 @code{CALL FGET(C [, STATUS])}
3908
3909 @item @emph{Arguments}:
3910 @multitable @columnfractions .15 .70
3911 @item @var{C} @tab The type shall be @code{CHARACTER}.
3912 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
3913 Returns 0 on success, -1 on end-of-file, and a
3914 system specific positive error code otherwise.
3915 @end multitable
3916
3917 @item @emph{Example}:
3918 @smallexample
3919 PROGRAM test_fget
3920 INTEGER, PARAMETER :: strlen = 100
3921 INTEGER :: status, i = 1
3922 CHARACTER(len=strlen) :: str = ""
3923
3924 WRITE (*,*) 'Enter text:'
3925 DO
3926 CALL fget(str(i:i), status)
3927 if (status /= 0 .OR. i > strlen) exit
3928 i = i + 1
3929 END DO
3930 WRITE (*,*) TRIM(str)
3931 END PROGRAM
3932 @end smallexample
3933
3934 @item @emph{See also}:
3935 @ref{FGETC}, @ref{FPUT}, @ref{FPUTC}
3936 @end table
3937
3938
3939
3940 @node FGETC
3941 @section @code{FGETC} --- Read a single character in stream mode
3942 @fnindex FGETC
3943 @cindex read character, stream mode
3944 @cindex stream mode, read character
3945 @cindex file operation, read character
3946
3947 @table @asis
3948 @item @emph{Description}:
3949 Read a single character in stream mode by bypassing normal formatted output.
3950 Stream I/O should not be mixed with normal record-oriented (formatted or
3951 unformatted) I/O on the same unit; the results are unpredictable.
3952
3953 This intrinsic is provided in both subroutine and function forms; however,
3954 only one form can be used in any given program unit.
3955
3956 Note that the @code{FGET} intrinsic is provided for backwards compatibility
3957 with @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
3958 Programmers should consider the use of new stream IO feature in new code
3959 for future portability. See also @ref{Fortran 2003 status}.
3960
3961 @item @emph{Standard}:
3962 GNU extension
3963
3964 @item @emph{Class}:
3965 Subroutine, function
3966
3967 @item @emph{Syntax}:
3968 @code{CALL FGETC(UNIT, C [, STATUS])}
3969
3970 @item @emph{Arguments}:
3971 @multitable @columnfractions .15 .70
3972 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
3973 @item @var{C} @tab The type shall be @code{CHARACTER}.
3974 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}. Returns 0 on success,
3975 -1 on end-of-file and a system specific positive error code otherwise.
3976 @end multitable
3977
3978 @item @emph{Example}:
3979 @smallexample
3980 PROGRAM test_fgetc
3981 INTEGER :: fd = 42, status
3982 CHARACTER :: c
3983
3984 OPEN(UNIT=fd, FILE="/etc/passwd", ACTION="READ", STATUS = "OLD")
3985 DO
3986 CALL fgetc(fd, c, status)
3987 IF (status /= 0) EXIT
3988 call fput(c)
3989 END DO
3990 CLOSE(UNIT=fd)
3991 END PROGRAM
3992 @end smallexample
3993
3994 @item @emph{See also}:
3995 @ref{FGET}, @ref{FPUT}, @ref{FPUTC}
3996 @end table
3997
3998
3999
4000 @node FLOOR
4001 @section @code{FLOOR} --- Integer floor function
4002 @fnindex FLOOR
4003 @cindex floor
4004 @cindex rounding, floor
4005
4006 @table @asis
4007 @item @emph{Description}:
4008 @code{FLOOR(X)} returns the greatest integer less than or equal to @var{X}.
4009
4010 @item @emph{Standard}:
4011 F95 and later
4012
4013 @item @emph{Class}:
4014 Elemental function
4015
4016 @item @emph{Syntax}:
4017 @code{RESULT = FLOOR(X [, KIND])}
4018
4019 @item @emph{Arguments}:
4020 @multitable @columnfractions .15 .70
4021 @item @var{X} @tab The type shall be @code{REAL(*)}.
4022 @item @var{KIND} @tab (Optional) An @code{INTEGER(*)} initialization
4023 expression indicating the kind parameter of
4024 the result.
4025 @end multitable
4026
4027 @item @emph{Return value}:
4028 The return value is of type @code{INTEGER(KIND)}
4029
4030 @item @emph{Example}:
4031 @smallexample
4032 program test_floor
4033 real :: x = 63.29
4034 real :: y = -63.59
4035 print *, floor(x) ! returns 63
4036 print *, floor(y) ! returns -64
4037 end program test_floor
4038 @end smallexample
4039
4040 @item @emph{See also}:
4041 @ref{CEILING}, @ref{NINT}
4042
4043 @end table
4044
4045
4046
4047 @node FLUSH
4048 @section @code{FLUSH} --- Flush I/O unit(s)
4049 @fnindex FLUSH
4050 @cindex file operation, flush
4051
4052 @table @asis
4053 @item @emph{Description}:
4054 Flushes Fortran unit(s) currently open for output. Without the optional
4055 argument, all units are flushed, otherwise just the unit specified.
4056
4057 @item @emph{Standard}:
4058 GNU extension
4059
4060 @item @emph{Class}:
4061 Subroutine
4062
4063 @item @emph{Syntax}:
4064 @code{CALL FLUSH(UNIT)}
4065
4066 @item @emph{Arguments}:
4067 @multitable @columnfractions .15 .70
4068 @item @var{UNIT} @tab (Optional) The type shall be @code{INTEGER}.
4069 @end multitable
4070
4071 @item @emph{Note}:
4072 Beginning with the Fortran 2003 standard, there is a @code{FLUSH}
4073 statement that should be preferred over the @code{FLUSH} intrinsic.
4074
4075 @end table
4076
4077
4078
4079 @node FNUM
4080 @section @code{FNUM} --- File number function
4081 @fnindex FNUM
4082 @cindex file operation, file number
4083
4084 @table @asis
4085 @item @emph{Description}:
4086 @code{FNUM(UNIT)} returns the POSIX file descriptor number corresponding to the
4087 open Fortran I/O unit @code{UNIT}.
4088
4089 @item @emph{Standard}:
4090 GNU extension
4091
4092 @item @emph{Class}:
4093 Function
4094
4095 @item @emph{Syntax}:
4096 @code{RESULT = FNUM(UNIT)}
4097
4098 @item @emph{Arguments}:
4099 @multitable @columnfractions .15 .70
4100 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
4101 @end multitable
4102
4103 @item @emph{Return value}:
4104 The return value is of type @code{INTEGER}
4105
4106 @item @emph{Example}:
4107 @smallexample
4108 program test_fnum
4109 integer :: i
4110 open (unit=10, status = "scratch")
4111 i = fnum(10)
4112 print *, i
4113 close (10)
4114 end program test_fnum
4115 @end smallexample
4116 @end table
4117
4118
4119
4120 @node FPUT
4121 @section @code{FPUT} --- Write a single character in stream mode to stdout
4122 @fnindex FPUT
4123 @cindex write character, stream mode
4124 @cindex stream mode, write character
4125 @cindex file operation, write character
4126
4127 @table @asis
4128 @item @emph{Description}:
4129 Write a single character in stream mode to stdout by bypassing normal
4130 formatted output. Stream I/O should not be mixed with normal record-oriented
4131 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
4132
4133 This intrinsic is provided in both subroutine and function forms; however,
4134 only one form can be used in any given program unit.
4135
4136 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
4137 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
4138 Programmers should consider the use of new stream IO feature in new code
4139 for future portability. See also @ref{Fortran 2003 status}.
4140
4141 @item @emph{Standard}:
4142 GNU extension
4143
4144 @item @emph{Class}:
4145 Subroutine, function
4146
4147 @item @emph{Syntax}:
4148 @code{CALL FPUT(C [, STATUS])}
4149
4150 @item @emph{Arguments}:
4151 @multitable @columnfractions .15 .70
4152 @item @var{C} @tab The type shall be @code{CHARACTER}.
4153 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}. Returns 0 on success,
4154 -1 on end-of-file and a system specific positive error code otherwise.
4155 @end multitable
4156
4157 @item @emph{Example}:
4158 @smallexample
4159 PROGRAM test_fput
4160 CHARACTER(len=10) :: str = "gfortran"
4161 INTEGER :: i
4162 DO i = 1, len_trim(str)
4163 CALL fput(str(i:i))
4164 END DO
4165 END PROGRAM
4166 @end smallexample
4167
4168 @item @emph{See also}:
4169 @ref{FPUTC}, @ref{FGET}, @ref{FGETC}
4170 @end table
4171
4172
4173
4174 @node FPUTC
4175 @section @code{FPUTC} --- Write a single character in stream mode
4176 @fnindex FPUTC
4177 @cindex write character, stream mode
4178 @cindex stream mode, write character
4179 @cindex file operation, write character
4180
4181 @table @asis
4182 @item @emph{Description}:
4183 Write a single character in stream mode by bypassing normal formatted
4184 output. Stream I/O should not be mixed with normal record-oriented
4185 (formatted or unformatted) I/O on the same unit; the results are unpredictable.
4186
4187 This intrinsic is provided in both subroutine and function forms; however,
4188 only one form can be used in any given program unit.
4189
4190 Note that the @code{FGET} intrinsic is provided for backwards compatibility with
4191 @command{g77}. GNU Fortran provides the Fortran 2003 Stream facility.
4192 Programmers should consider the use of new stream IO feature in new code
4193 for future portability. See also @ref{Fortran 2003 status}.
4194
4195 @item @emph{Standard}:
4196 GNU extension
4197
4198 @item @emph{Class}:
4199 Subroutine, function
4200
4201 @item @emph{Syntax}:
4202 @code{CALL FPUTC(UNIT, C [, STATUS])}
4203
4204 @item @emph{Arguments}:
4205 @multitable @columnfractions .15 .70
4206 @item @var{UNIT} @tab The type shall be @code{INTEGER}.
4207 @item @var{C} @tab The type shall be @code{CHARACTER}.
4208 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}. Returns 0 on success,
4209 -1 on end-of-file and a system specific positive error code otherwise.
4210 @end multitable
4211
4212 @item @emph{Example}:
4213 @smallexample
4214 PROGRAM test_fputc
4215 CHARACTER(len=10) :: str = "gfortran"
4216 INTEGER :: fd = 42, i
4217
4218 OPEN(UNIT = fd, FILE = "out", ACTION = "WRITE", STATUS="NEW")
4219 DO i = 1, len_trim(str)
4220 CALL fputc(fd, str(i:i))
4221 END DO
4222 CLOSE(fd)
4223 END PROGRAM
4224 @end smallexample
4225
4226 @item @emph{See also}:
4227 @ref{FPUT}, @ref{FGET}, @ref{FGETC}
4228 @end table
4229
4230
4231
4232 @node FRACTION
4233 @section @code{FRACTION} --- Fractional part of the model representation
4234 @fnindex FRACTION
4235 @cindex real number, fraction
4236 @cindex floating point, fraction
4237
4238 @table @asis
4239 @item @emph{Description}:
4240 @code{FRACTION(X)} returns the fractional part of the model
4241 representation of @code{X}.
4242
4243 @item @emph{Standard}:
4244 F95 and later
4245
4246 @item @emph{Class}:
4247 Elemental function
4248
4249 @item @emph{Syntax}:
4250 @code{Y = FRACTION(X)}
4251
4252 @item @emph{Arguments}:
4253 @multitable @columnfractions .15 .70
4254 @item @var{X} @tab The type of the argument shall be a @code{REAL}.
4255 @end multitable
4256
4257 @item @emph{Return value}:
4258 The return value is of the same type and kind as the argument.
4259 The fractional part of the model representation of @code{X} is returned;
4260 it is @code{X * RADIX(X)**(-EXPONENT(X))}.
4261
4262 @item @emph{Example}:
4263 @smallexample
4264 program test_fraction
4265 real :: x
4266 x = 178.1387e-4
4267 print *, fraction(x), x * radix(x)**(-exponent(x))
4268 end program test_fraction
4269 @end smallexample
4270
4271 @end table
4272
4273
4274
4275 @node FREE
4276 @section @code{FREE} --- Frees memory
4277 @fnindex FREE
4278 @cindex pointer, cray
4279
4280 @table @asis
4281 @item @emph{Description}:
4282 Frees memory previously allocated by @code{MALLOC()}. The @code{FREE}
4283 intrinsic is an extension intended to be used with Cray pointers, and is
4284 provided in GNU Fortran to allow user to compile legacy code. For
4285 new code using Fortran 95 pointers, the memory de-allocation intrinsic is
4286 @code{DEALLOCATE}.
4287
4288 @item @emph{Standard}:
4289 GNU extension
4290
4291 @item @emph{Class}:
4292 Subroutine
4293
4294 @item @emph{Syntax}:
4295 @code{CALL FREE(PTR)}
4296
4297 @item @emph{Arguments}:
4298 @multitable @columnfractions .15 .70
4299 @item @var{PTR} @tab The type shall be @code{INTEGER}. It represents the
4300 location of the memory that should be de-allocated.
4301 @end multitable
4302
4303 @item @emph{Return value}:
4304 None
4305
4306 @item @emph{Example}:
4307 See @code{MALLOC} for an example.
4308
4309 @item @emph{See also}:
4310 @ref{MALLOC}
4311 @end table
4312
4313
4314
4315 @node FSEEK
4316 @section @code{FSEEK} --- Low level file positioning subroutine
4317 @fnindex FSEEK
4318 @cindex file operation, seek
4319 @cindex file operation, position
4320
4321 @table @asis
4322 @item @emph{Description}:
4323 Moves @var{UNIT} to the specified @var{OFFSET}. If @var{WHENCE}
4324 is set to 0, the @var{OFFSET} is taken as an absolute value @code{SEEK_SET},
4325 if set to 1, @var{OFFSET} is taken to be relative to the current position
4326 @code{SEEK_CUR}, and if set to 2 relative to the end of the file @code{SEEK_END}.
4327 On error, @var{STATUS} is set to a nonzero value. If @var{STATUS} the seek
4328 fails silently.
4329
4330 This intrinsic routine is not fully backwards compatible with @command{g77}.
4331 In @command{g77}, the @code{FSEEK} takes a statement label instead of a
4332 @var{STATUS} variable. If FSEEK is used in old code, change
4333 @smallexample
4334 CALL FSEEK(UNIT, OFFSET, WHENCE, *label)
4335 @end smallexample
4336 to
4337 @smallexample
4338 INTEGER :: status
4339 CALL FSEEK(UNIT, OFFSET, WHENCE, status)
4340 IF (status /= 0) GOTO label
4341 @end smallexample
4342
4343 Please note that GNU Fortran provides the Fortran 2003 Stream facility.
4344 Programmers should consider the use of new stream IO feature in new code
4345 for future portability. See also @ref{Fortran 2003 status}.
4346
4347 @item @emph{Standard}:
4348 GNU extension
4349
4350 @item @emph{Class}:
4351 Subroutine
4352
4353 @item @emph{Syntax}:
4354 @code{CALL FSEEK(UNIT, OFFSET, WHENCE[, STATUS])}
4355
4356 @item @emph{Arguments}:
4357 @multitable @columnfractions .15 .70
4358 @item @var{UNIT} @tab Shall be a scalar of type @code{INTEGER}.
4359 @item @var{OFFSET} @tab Shall be a scalar of type @code{INTEGER}.
4360 @item @var{WHENCE} @tab Shall be a scalar of type @code{INTEGER}.
4361 Its value shall be either 0, 1 or 2.
4362 @item @var{STATUS} @tab (Optional) shall be a scalar of type
4363 @code{INTEGER(4)}.
4364 @end multitable
4365
4366 @item @emph{Example}:
4367 @smallexample
4368 PROGRAM test_fseek
4369 INTEGER, PARAMETER :: SEEK_SET = 0, SEEK_CUR = 1, SEEK_END = 2
4370 INTEGER :: fd, offset, ierr
4371
4372 ierr = 0
4373 offset = 5
4374 fd = 10
4375
4376 OPEN(UNIT=fd, FILE="fseek.test")
4377 CALL FSEEK(fd, offset, SEEK_SET, ierr) ! move to OFFSET
4378 print *, FTELL(fd), ierr
4379
4380 CALL FSEEK(fd, 0, SEEK_END, ierr) ! move to end
4381 print *, FTELL(fd), ierr
4382
4383 CALL FSEEK(fd, 0, SEEK_SET, ierr) ! move to beginning
4384 print *, FTELL(fd), ierr
4385
4386 CLOSE(UNIT=fd)
4387 END PROGRAM
4388 @end smallexample
4389
4390 @item @emph{See also}:
4391 @ref{FTELL}
4392 @end table
4393
4394
4395
4396 @node FSTAT
4397 @section @code{FSTAT} --- Get file status
4398 @fnindex FSTAT
4399 @cindex file system, file status
4400
4401 @table @asis
4402 @item @emph{Description}:
4403 @code{FSTAT} is identical to @ref{STAT}, except that information about an
4404 already opened file is obtained.
4405
4406 The elements in @code{BUFF} are the same as described by @ref{STAT}.
4407
4408 This intrinsic is provided in both subroutine and function forms; however,
4409 only one form can be used in any given program unit.
4410
4411 @item @emph{Standard}:
4412 GNU extension
4413
4414 @item @emph{Class}:
4415 Subroutine, function
4416
4417 @item @emph{Syntax}:
4418 @code{CALL FSTAT(UNIT, BUFF [, STATUS])}
4419
4420 @item @emph{Arguments}:
4421 @multitable @columnfractions .15 .70
4422 @item @var{UNIT} @tab An open I/O unit number of type @code{INTEGER}.
4423 @item @var{BUFF} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
4424 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}. Returns 0
4425 on success and a system specific error code otherwise.
4426 @end multitable
4427
4428 @item @emph{Example}:
4429 See @ref{STAT} for an example.
4430
4431 @item @emph{See also}:
4432 To stat a link: @ref{LSTAT}, to stat a file: @ref{STAT}
4433 @end table
4434
4435
4436
4437 @node FTELL
4438 @section @code{FTELL} --- Current stream position
4439 @fnindex FTELL
4440 @cindex file operation, position
4441
4442 @table @asis
4443 @item @emph{Description}:
4444 Retrieves the current position within an open file.
4445
4446 This intrinsic is provided in both subroutine and function forms; however,
4447 only one form can be used in any given program unit.
4448
4449 @item @emph{Standard}:
4450 GNU extension
4451
4452 @item @emph{Class}:
4453 Subroutine, function
4454
4455 @item @emph{Syntax}:
4456 @multitable @columnfractions .80
4457 @item @code{CALL FTELL(UNIT, OFFSET)}
4458 @item @code{OFFSET = FTELL(UNIT)}
4459 @end multitable
4460
4461 @item @emph{Arguments}:
4462 @multitable @columnfractions .15 .70
4463 @item @var{OFFSET} @tab Shall of type @code{INTEGER}.
4464 @item @var{UNIT} @tab Shall of type @code{INTEGER}.
4465 @end multitable
4466
4467 @item @emph{Return value}:
4468 In either syntax, @var{OFFSET} is set to the current offset of unit
4469 number @var{UNIT}, or to @math{-1} if the unit is not currently open.
4470
4471 @item @emph{Example}:
4472 @smallexample
4473 PROGRAM test_ftell
4474 INTEGER :: i
4475 OPEN(10, FILE="temp.dat")
4476 CALL ftell(10,i)
4477 WRITE(*,*) i
4478 END PROGRAM
4479 @end smallexample
4480
4481 @item @emph{See also}:
4482 @ref{FSEEK}
4483 @end table
4484
4485
4486
4487 @node GERROR
4488 @section @code{GERROR} --- Get last system error message
4489 @fnindex GERROR
4490 @cindex system, error handling
4491
4492 @table @asis
4493 @item @emph{Description}:
4494 Returns the system error message corresponding to the last system error.
4495 This resembles the functionality of @code{strerror(3)} in C.
4496
4497 @item @emph{Standard}:
4498 GNU extension
4499
4500 @item @emph{Class}:
4501 Subroutine
4502
4503 @item @emph{Syntax}:
4504 @code{CALL GERROR(RESULT)}
4505
4506 @item @emph{Arguments}:
4507 @multitable @columnfractions .15 .70
4508 @item @var{RESULT} @tab Shall of type @code{CHARACTER(*)}.
4509 @end multitable
4510
4511 @item @emph{Example}:
4512 @smallexample
4513 PROGRAM test_gerror
4514 CHARACTER(len=100) :: msg
4515 CALL gerror(msg)
4516 WRITE(*,*) msg
4517 END PROGRAM
4518 @end smallexample
4519
4520 @item @emph{See also}:
4521 @ref{IERRNO}, @ref{PERROR}
4522 @end table
4523
4524
4525
4526 @node GETARG
4527 @section @code{GETARG} --- Get command line arguments
4528 @fnindex GETARG
4529 @cindex command-line arguments
4530 @cindex arguments, to program
4531
4532 @table @asis
4533 @item @emph{Description}:
4534 Retrieve the @var{N}th argument that was passed on the
4535 command line when the containing program was invoked.
4536
4537 This intrinsic routine is provided for backwards compatibility with
4538 GNU Fortran 77. In new code, programmers should consider the use of
4539 the @ref{GET_COMMAND_ARGUMENT} intrinsic defined by the Fortran 2003
4540 standard.
4541
4542 @item @emph{Standard}:
4543 GNU extension
4544
4545 @item @emph{Class}:
4546 Subroutine
4547
4548 @item @emph{Syntax}:
4549 @code{CALL GETARG(N, ARG)}
4550
4551 @item @emph{Arguments}:
4552 @multitable @columnfractions .15 .70
4553 @item @var{N} @tab Shall be of type @code{INTEGER(4)}, @math{@var{N} \geq 0}
4554 @item @var{ARG} @tab Shall be of type @code{CHARACTER(*)}.
4555 @end multitable
4556
4557 @item @emph{Return value}:
4558 After @code{GETARG} returns, the @var{ARG} argument holds the @var{N}th
4559 command line argument. If @var{ARG} can not hold the argument, it is
4560 truncated to fit the length of @var{ARG}. If there are less than @var{N}
4561 arguments specified at the command line, @var{ARG} will be filled with blanks.
4562 If @math{@var{N} = 0}, @var{ARG} is set to the name of the program (on systems
4563 that support this feature).
4564
4565 @item @emph{Example}:
4566 @smallexample
4567 PROGRAM test_getarg
4568 INTEGER :: i
4569 CHARACTER(len=32) :: arg
4570
4571 DO i = 1, iargc()
4572 CALL getarg(i, arg)
4573 WRITE (*,*) arg
4574 END DO
4575 END PROGRAM
4576 @end smallexample
4577
4578 @item @emph{See also}:
4579 GNU Fortran 77 compatibility function: @ref{IARGC}
4580
4581 F2003 functions and subroutines: @ref{GET_COMMAND}, @ref{GET_COMMAND_ARGUMENT},
4582 @ref{COMMAND_ARGUMENT_COUNT}
4583 @end table
4584
4585
4586
4587 @node GET_COMMAND
4588 @section @code{GET_COMMAND} --- Get the entire command line
4589 @fnindex GET_COMMAND
4590 @cindex command-line arguments
4591 @cindex arguments, to program
4592
4593 @table @asis
4594 @item @emph{Description}:
4595 Retrieve the entire command line that was used to invoke the program.
4596
4597 @item @emph{Standard}:
4598 F2003
4599
4600 @item @emph{Class}:
4601 Subroutine
4602
4603 @item @emph{Syntax}:
4604 @code{CALL GET_COMMAND(CMD)}
4605
4606 @item @emph{Arguments}:
4607 @multitable @columnfractions .15 .70
4608 @item @var{CMD} @tab Shall be of type @code{CHARACTER(*)}.
4609 @end multitable
4610
4611 @item @emph{Return value}:
4612 Stores the entire command line that was used to invoke the program in @var{ARG}.
4613 If @var{ARG} is not large enough, the command will be truncated.
4614
4615 @item @emph{Example}:
4616 @smallexample
4617 PROGRAM test_get_command
4618 CHARACTER(len=255) :: cmd
4619 CALL get_command(cmd)
4620 WRITE (*,*) TRIM(cmd)
4621 END PROGRAM
4622 @end smallexample
4623
4624 @item @emph{See also}:
4625 @ref{GET_COMMAND_ARGUMENT}, @ref{COMMAND_ARGUMENT_COUNT}
4626 @end table
4627
4628
4629
4630 @node GET_COMMAND_ARGUMENT
4631 @section @code{GET_COMMAND_ARGUMENT} --- Get command line arguments
4632 @fnindex GET_COMMAND_ARGUMENT
4633 @cindex command-line arguments
4634 @cindex arguments, to program
4635
4636 @table @asis
4637 @item @emph{Description}:
4638 Retrieve the @var{N}th argument that was passed on the
4639 command line when the containing program was invoked.
4640
4641 @item @emph{Standard}:
4642 F2003
4643
4644 @item @emph{Class}:
4645 Subroutine
4646
4647 @item @emph{Syntax}:
4648 @code{CALL GET_COMMAND_ARGUMENT(N, ARG)}
4649
4650 @item @emph{Arguments}:
4651 @multitable @columnfractions .15 .70
4652 @item @var{N} @tab Shall be of type @code{INTEGER(4)}, @math{@var{N} \geq 0}
4653 @item @var{ARG} @tab Shall be of type @code{CHARACTER(*)}.
4654 @end multitable
4655
4656 @item @emph{Return value}:
4657 After @code{GET_COMMAND_ARGUMENT} returns, the @var{ARG} argument holds the
4658 @var{N}th command line argument. If @var{ARG} can not hold the argument, it is
4659 truncated to fit the length of @var{ARG}. If there are less than @var{N}
4660 arguments specified at the command line, @var{ARG} will be filled with blanks.
4661 If @math{@var{N} = 0}, @var{ARG} is set to the name of the program (on systems
4662 that support this feature).
4663
4664 @item @emph{Example}:
4665 @smallexample
4666 PROGRAM test_get_command_argument
4667 INTEGER :: i
4668 CHARACTER(len=32) :: arg
4669
4670 i = 0
4671 DO
4672 CALL get_command_argument(i, arg)
4673 IF (LEN_TRIM(arg) == 0) EXIT
4674
4675 WRITE (*,*) TRIM(arg)
4676 i = i+1
4677 END DO
4678 END PROGRAM
4679 @end smallexample
4680
4681 @item @emph{See also}:
4682 @ref{GET_COMMAND}, @ref{COMMAND_ARGUMENT_COUNT}
4683 @end table
4684
4685
4686
4687 @node GETCWD
4688 @section @code{GETCWD} --- Get current working directory
4689 @fnindex GETCWD
4690 @cindex system, working directory
4691
4692 @table @asis
4693 @item @emph{Description}:
4694 Get current working directory.
4695
4696 This intrinsic is provided in both subroutine and function forms; however,
4697 only one form can be used in any given program unit.
4698
4699 @item @emph{Standard}:
4700 GNU extension
4701
4702 @item @emph{Class}:
4703 Subroutine, function
4704
4705 @item @emph{Syntax}:
4706 @code{CALL GETCWD(CWD [, STATUS])}
4707
4708 @item @emph{Arguments}:
4709 @multitable @columnfractions .15 .70
4710 @item @var{CWD} @tab The type shall be @code{CHARACTER(*)}.
4711 @item @var{STATUS} @tab (Optional) status flag. Returns 0 on success,
4712 a system specific and nonzero error code otherwise.
4713 @end multitable
4714
4715 @item @emph{Example}:
4716 @smallexample
4717 PROGRAM test_getcwd
4718 CHARACTER(len=255) :: cwd
4719 CALL getcwd(cwd)
4720 WRITE(*,*) TRIM(cwd)
4721 END PROGRAM
4722 @end smallexample
4723
4724 @item @emph{See also}:
4725 @ref{CHDIR}
4726 @end table
4727
4728
4729
4730 @node GETENV
4731 @section @code{GETENV} --- Get an environmental variable
4732 @fnindex GETENV
4733 @cindex environment variable
4734
4735 @table @asis
4736 @item @emph{Description}:
4737 Get the @var{VALUE} of the environmental variable @var{ENVVAR}.
4738
4739 This intrinsic routine is provided for backwards compatibility with
4740 GNU Fortran 77. In new code, programmers should consider the use of
4741 the @ref{GET_ENVIRONMENT_VARIABLE} intrinsic defined by the Fortran
4742 2003 standard.
4743
4744 @item @emph{Standard}:
4745 GNU extension
4746
4747 @item @emph{Class}:
4748 Subroutine
4749
4750 @item @emph{Syntax}:
4751 @code{CALL GETENV(ENVVAR, VALUE)}
4752
4753 @item @emph{Arguments}:
4754 @multitable @columnfractions .15 .70
4755 @item @var{ENVVAR} @tab Shall be of type @code{CHARACTER(*)}.
4756 @item @var{VALUE} @tab Shall be of type @code{CHARACTER(*)}.
4757 @end multitable
4758
4759 @item @emph{Return value}:
4760 Stores the value of @var{ENVVAR} in @var{VALUE}. If @var{VALUE} is
4761 not large enough to hold the data, it is truncated. If @var{ENVVAR}
4762 is not set, @var{VALUE} will be filled with blanks.
4763
4764 @item @emph{Example}:
4765 @smallexample
4766 PROGRAM test_getenv
4767 CHARACTER(len=255) :: homedir
4768 CALL getenv("HOME", homedir)
4769 WRITE (*,*) TRIM(homedir)
4770 END PROGRAM
4771 @end smallexample
4772
4773 @item @emph{See also}:
4774 @ref{GET_ENVIRONMENT_VARIABLE}
4775 @end table
4776
4777
4778
4779 @node GET_ENVIRONMENT_VARIABLE
4780 @section @code{GET_ENVIRONMENT_VARIABLE} --- Get an environmental variable
4781 @fnindex GET_ENVIRONMENT_VARIABLE
4782 @cindex environment variable
4783
4784 @table @asis
4785 @item @emph{Description}:
4786 Get the @var{VALUE} of the environmental variable @var{ENVVAR}.
4787
4788 @item @emph{Standard}:
4789 F2003
4790
4791 @item @emph{Class}:
4792 Subroutine
4793
4794 @item @emph{Syntax}:
4795 @code{CALL GET_ENVIRONMENT_VARIABLE(ENVVAR, VALUE)}
4796
4797 @item @emph{Arguments}:
4798 @multitable @columnfractions .15 .70
4799 @item @var{ENVVAR} @tab Shall be of type @code{CHARACTER(*)}.
4800 @item @var{VALUE} @tab Shall be of type @code{CHARACTER(*)}.
4801 @end multitable
4802
4803 @item @emph{Return value}:
4804 Stores the value of @var{ENVVAR} in @var{VALUE}. If @var{VALUE} is
4805 not large enough to hold the data, it is truncated. If @var{ENVVAR}
4806 is not set, @var{VALUE} will be filled with blanks.
4807
4808 @item @emph{Example}:
4809 @smallexample
4810 PROGRAM test_getenv
4811 CHARACTER(len=255) :: homedir
4812 CALL get_environment_variable("HOME", homedir)
4813 WRITE (*,*) TRIM(homedir)
4814 END PROGRAM
4815 @end smallexample
4816 @end table
4817
4818
4819
4820 @node GETGID
4821 @section @code{GETGID} --- Group ID function
4822 @fnindex GETGID
4823 @cindex system, group id
4824
4825 @table @asis
4826 @item @emph{Description}:
4827 Returns the numerical group ID of the current process.
4828
4829 @item @emph{Standard}:
4830 GNU extension
4831
4832 @item @emph{Class}:
4833 Function
4834
4835 @item @emph{Syntax}:
4836 @code{RESULT = GETGID()}
4837
4838 @item @emph{Return value}:
4839 The return value of @code{GETGID} is an @code{INTEGER} of the default
4840 kind.
4841
4842
4843 @item @emph{Example}:
4844 See @code{GETPID} for an example.
4845
4846 @item @emph{See also}:
4847 @ref{GETPID}, @ref{GETUID}
4848 @end table
4849
4850
4851
4852 @node GETLOG
4853 @section @code{GETLOG} --- Get login name
4854 @fnindex GETLOG
4855 @cindex system, login name
4856 @cindex login name
4857
4858 @table @asis
4859 @item @emph{Description}:
4860 Gets the username under which the program is running.
4861
4862 @item @emph{Standard}:
4863 GNU extension
4864
4865 @item @emph{Class}:
4866 Subroutine
4867
4868 @item @emph{Syntax}:
4869 @code{CALL GETLOG(LOGIN)}
4870
4871 @item @emph{Arguments}:
4872 @multitable @columnfractions .15 .70
4873 @item @var{LOGIN} @tab Shall be of type @code{CHARACTER(*)}.
4874 @end multitable
4875
4876 @item @emph{Return value}:
4877 Stores the current user name in @var{LOGIN}. (On systems where POSIX
4878 functions @code{geteuid} and @code{getpwuid} are not available, and
4879 the @code{getlogin} function is not implemented either, this will
4880 return a blank string.)
4881
4882 @item @emph{Example}:
4883 @smallexample
4884 PROGRAM TEST_GETLOG
4885 CHARACTER(32) :: login
4886 CALL GETLOG(login)
4887 WRITE(*,*) login
4888 END PROGRAM
4889 @end smallexample
4890
4891 @item @emph{See also}:
4892 @ref{GETUID}
4893 @end table
4894
4895
4896
4897 @node GETPID
4898 @section @code{GETPID} --- Process ID function
4899 @fnindex GETPID
4900 @cindex system, process id
4901 @cindex process id
4902
4903 @table @asis
4904 @item @emph{Description}:
4905 Returns the numerical process identifier of the current process.
4906
4907 @item @emph{Standard}:
4908 GNU extension
4909
4910 @item @emph{Class}:
4911 Function
4912
4913 @item @emph{Syntax}:
4914 @code{RESULT = GETPID()}
4915
4916 @item @emph{Return value}:
4917 The return value of @code{GETPID} is an @code{INTEGER} of the default
4918 kind.
4919
4920
4921 @item @emph{Example}:
4922 @smallexample
4923 program info
4924 print *, "The current process ID is ", getpid()
4925 print *, "Your numerical user ID is ", getuid()
4926 print *, "Your numerical group ID is ", getgid()
4927 end program info
4928 @end smallexample
4929
4930 @item @emph{See also}:
4931 @ref{GETGID}, @ref{GETUID}
4932 @end table
4933
4934
4935
4936 @node GETUID
4937 @section @code{GETUID} --- User ID function
4938 @fnindex GETUID
4939 @cindex system, user id
4940 @cindex user id
4941
4942 @table @asis
4943 @item @emph{Description}:
4944 Returns the numerical user ID of the current process.
4945
4946 @item @emph{Standard}:
4947 GNU extension
4948
4949 @item @emph{Class}:
4950 Function
4951
4952 @item @emph{Syntax}:
4953 @code{RESULT = GETUID()}
4954
4955 @item @emph{Return value}:
4956 The return value of @code{GETUID} is an @code{INTEGER} of the default
4957 kind.
4958
4959
4960 @item @emph{Example}:
4961 See @code{GETPID} for an example.
4962
4963 @item @emph{See also}:
4964 @ref{GETPID}, @ref{GETLOG}
4965 @end table
4966
4967
4968
4969 @node GMTIME
4970 @section @code{GMTIME} --- Convert time to GMT info
4971 @fnindex GMTIME
4972 @cindex time, conversion to GMT info
4973
4974 @table @asis
4975 @item @emph{Description}:
4976 Given a system time value @var{STIME} (as provided by the @code{TIME8()}
4977 intrinsic), fills @var{TARRAY} with values extracted from it appropriate
4978 to the UTC time zone (Universal Coordinated Time, also known in some
4979 countries as GMT, Greenwich Mean Time), using @code{gmtime(3)}.
4980
4981 @item @emph{Standard}:
4982 GNU extension
4983
4984 @item @emph{Class}:
4985 Subroutine
4986
4987 @item @emph{Syntax}:
4988 @code{CALL GMTIME(STIME, TARRAY)}
4989
4990 @item @emph{Arguments}:
4991 @multitable @columnfractions .15 .70
4992 @item @var{STIME} @tab An @code{INTEGER(*)} scalar expression
4993 corresponding to a system time, with
4994 @code{INTENT(IN)}.
4995 @item @var{TARRAY} @tab A default @code{INTEGER} array with 9 elements,
4996 with @code{INTENT(OUT)}.
4997 @end multitable
4998
4999 @item @emph{Return value}:
5000 The elements of @var{TARRAY} are assigned as follows:
5001 @enumerate
5002 @item Seconds after the minute, range 0--59 or 0--61 to allow for leap
5003 seconds
5004 @item Minutes after the hour, range 0--59
5005 @item Hours past midnight, range 0--23
5006 @item Day of month, range 0--31
5007 @item Number of months since January, range 0--12
5008 @item Years since 1900
5009 @item Number of days since Sunday, range 0--6
5010 @item Days since January 1
5011 @item Daylight savings indicator: positive if daylight savings is in
5012 effect, zero if not, and negative if the information is not
5013 available.
5014 @end enumerate
5015
5016 @item @emph{See also}:
5017 @ref{CTIME}, @ref{LTIME}, @ref{TIME}, @ref{TIME8}
5018
5019 @end table
5020
5021
5022
5023 @node HOSTNM
5024 @section @code{HOSTNM} --- Get system host name
5025 @fnindex HOSTNM
5026 @cindex system, host name
5027
5028 @table @asis
5029 @item @emph{Description}:
5030 Retrieves the host name of the system on which the program is running.
5031
5032 This intrinsic is provided in both subroutine and function forms; however,
5033 only one form can be used in any given program unit.
5034
5035 @item @emph{Standard}:
5036 GNU extension
5037
5038 @item @emph{Class}:
5039 Subroutine, function
5040
5041 @item @emph{Syntax}:
5042 @multitable @columnfractions .80
5043 @item @code{CALL HOSTNM(NAME[, STATUS])}
5044 @item @code{STATUS = HOSTNM(NAME)}
5045 @end multitable
5046
5047 @item @emph{Arguments}:
5048 @multitable @columnfractions .15 .70
5049 @item @var{NAME} @tab Shall of type @code{CHARACTER(*)}.
5050 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER}.
5051 Returns 0 on success, or a system specific error
5052 code otherwise.
5053 @end multitable
5054
5055 @item @emph{Return value}:
5056 In either syntax, @var{NAME} is set to the current hostname if it can
5057 be obtained, or to a blank string otherwise.
5058
5059 @end table
5060
5061
5062
5063 @node HUGE
5064 @section @code{HUGE} --- Largest number of a kind
5065 @fnindex HUGE
5066 @cindex limits, largest number
5067 @cindex model representation, largest number
5068
5069 @table @asis
5070 @item @emph{Description}:
5071 @code{HUGE(X)} returns the largest number that is not an infinity in
5072 the model of the type of @code{X}.
5073
5074 @item @emph{Standard}:
5075 F95 and later
5076
5077 @item @emph{Class}:
5078 Inquiry function
5079
5080 @item @emph{Syntax}:
5081 @code{RESULT = HUGE(X)}
5082
5083 @item @emph{Arguments}:
5084 @multitable @columnfractions .15 .70
5085 @item @var{X} @tab Shall be of type @code{REAL} or @code{INTEGER}.
5086 @end multitable
5087
5088 @item @emph{Return value}:
5089 The return value is of the same type and kind as @var{X}
5090
5091 @item @emph{Example}:
5092 @smallexample
5093 program test_huge_tiny
5094 print *, huge(0), huge(0.0), huge(0.0d0)
5095 print *, tiny(0.0), tiny(0.0d0)
5096 end program test_huge_tiny
5097 @end smallexample
5098 @end table
5099
5100
5101
5102 @node IACHAR
5103 @section @code{IACHAR} --- Code in @acronym{ASCII} collating sequence
5104 @fnindex IACHAR
5105 @cindex @acronym{ASCII} collating sequence
5106 @cindex collating sequence, @acronym{ASCII}
5107 @cindex conversion, to integer
5108
5109 @table @asis
5110 @item @emph{Description}:
5111 @code{IACHAR(C)} returns the code for the @acronym{ASCII} character
5112 in the first character position of @code{C}.
5113
5114 @item @emph{Standard}:
5115 F95 and later
5116
5117 @item @emph{Class}:
5118 Elemental function
5119
5120 @item @emph{Syntax}:
5121 @code{RESULT = IACHAR(C [, KIND])}
5122
5123 @item @emph{Arguments}:
5124 @multitable @columnfractions .15 .70
5125 @item @var{C} @tab Shall be a scalar @code{CHARACTER}, with @code{INTENT(IN)}
5126 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
5127 expression indicating the kind parameter of
5128 the result.
5129 @end multitable
5130
5131 @item @emph{Return value}:
5132 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
5133 @var{KIND} is absent, the return value is of default integer kind.
5134
5135 @item @emph{Example}:
5136 @smallexample
5137 program test_iachar
5138 integer i
5139 i = iachar(' ')
5140 end program test_iachar
5141 @end smallexample
5142
5143 @item @emph{Note}:
5144 See @ref{ICHAR} for a discussion of converting between numerical values
5145 and formatted string representations.
5146
5147 @item @emph{See also}:
5148 @ref{ACHAR}, @ref{CHAR}, @ref{ICHAR}
5149
5150 @end table
5151
5152
5153
5154 @node IAND
5155 @section @code{IAND} --- Bitwise logical and
5156 @fnindex IAND
5157 @cindex bitwise logical and
5158 @cindex logical and, bitwise
5159
5160 @table @asis
5161 @item @emph{Description}:
5162 Bitwise logical @code{AND}.
5163
5164 @item @emph{Standard}:
5165 F95 and later
5166
5167 @item @emph{Class}:
5168 Elemental function
5169
5170 @item @emph{Syntax}:
5171 @code{RESULT = IAND(I, J)}
5172
5173 @item @emph{Arguments}:
5174 @multitable @columnfractions .15 .70
5175 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
5176 @item @var{J} @tab The type shall be @code{INTEGER(*)}, of the same
5177 kind as @var{I}. (As a GNU extension, different kinds are also
5178 permitted.)
5179 @end multitable
5180
5181 @item @emph{Return value}:
5182 The return type is @code{INTEGER(*)}, of the same kind as the
5183 arguments. (If the argument kinds differ, it is of the same kind as
5184 the larger argument.)
5185
5186 @item @emph{Example}:
5187 @smallexample
5188 PROGRAM test_iand
5189 INTEGER :: a, b
5190 DATA a / Z'F' /, b / Z'3' /
5191 WRITE (*,*) IAND(a, b)
5192 END PROGRAM
5193 @end smallexample
5194
5195 @item @emph{See also}:
5196 @ref{IOR}, @ref{IEOR}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}, @ref{NOT}
5197
5198 @end table
5199
5200
5201
5202 @node IARGC
5203 @section @code{IARGC} --- Get the number of command line arguments
5204 @fnindex IARGC
5205 @cindex command-line arguments
5206 @cindex command-line arguments, number of
5207 @cindex arguments, to program
5208
5209 @table @asis
5210 @item @emph{Description}:
5211 @code{IARGC()} returns the number of arguments passed on the
5212 command line when the containing program was invoked.
5213
5214 This intrinsic routine is provided for backwards compatibility with
5215 GNU Fortran 77. In new code, programmers should consider the use of
5216 the @ref{COMMAND_ARGUMENT_COUNT} intrinsic defined by the Fortran 2003
5217 standard.
5218
5219 @item @emph{Standard}:
5220 GNU extension
5221
5222 @item @emph{Class}:
5223 Function
5224
5225 @item @emph{Syntax}:
5226 @code{RESULT = IARGC()}
5227
5228 @item @emph{Arguments}:
5229 None.
5230
5231 @item @emph{Return value}:
5232 The number of command line arguments, type @code{INTEGER(4)}.
5233
5234 @item @emph{Example}:
5235 See @ref{GETARG}
5236
5237 @item @emph{See also}:
5238 GNU Fortran 77 compatibility subroutine: @ref{GETARG}
5239
5240 F2003 functions and subroutines: @ref{GET_COMMAND}, @ref{GET_COMMAND_ARGUMENT},
5241 @ref{COMMAND_ARGUMENT_COUNT}
5242 @end table
5243
5244
5245
5246 @node IBCLR
5247 @section @code{IBCLR} --- Clear bit
5248 @fnindex IBCLR
5249 @cindex bits, unset
5250 @cindex bits, clear
5251
5252 @table @asis
5253 @item @emph{Description}:
5254 @code{IBCLR} returns the value of @var{I} with the bit at position
5255 @var{POS} set to zero.
5256
5257 @item @emph{Standard}:
5258 F95 and later
5259
5260 @item @emph{Class}:
5261 Elemental function
5262
5263 @item @emph{Syntax}:
5264 @code{RESULT = IBCLR(I, POS)}
5265
5266 @item @emph{Arguments}:
5267 @multitable @columnfractions .15 .70
5268 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
5269 @item @var{POS} @tab The type shall be @code{INTEGER(*)}.
5270 @end multitable
5271
5272 @item @emph{Return value}:
5273 The return value is of type @code{INTEGER(*)} and of the same kind as
5274 @var{I}.
5275
5276 @item @emph{See also}:
5277 @ref{IBITS}, @ref{IBSET}, @ref{IAND}, @ref{IOR}, @ref{IEOR}, @ref{MVBITS}
5278
5279 @end table
5280
5281
5282
5283 @node IBITS
5284 @section @code{IBITS} --- Bit extraction
5285 @fnindex IBITS
5286 @cindex bits, get
5287 @cindex bits, extract
5288
5289 @table @asis
5290 @item @emph{Description}:
5291 @code{IBITS} extracts a field of length @var{LEN} from @var{I},
5292 starting from bit position @var{POS} and extending left for @var{LEN}
5293 bits. The result is right-justified and the remaining bits are
5294 zeroed. The value of @code{POS+LEN} must be less than or equal to the
5295 value @code{BIT_SIZE(I)}.
5296
5297 @item @emph{Standard}:
5298 F95 and later
5299
5300 @item @emph{Class}:
5301 Elemental function
5302
5303 @item @emph{Syntax}:
5304 @code{RESULT = IBITS(I, POS, LEN)}
5305
5306 @item @emph{Arguments}:
5307 @multitable @columnfractions .15 .70
5308 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
5309 @item @var{POS} @tab The type shall be @code{INTEGER(*)}.
5310 @item @var{LEN} @tab The type shall be @code{INTEGER(*)}.
5311 @end multitable
5312
5313 @item @emph{Return value}:
5314 The return value is of type @code{INTEGER(*)} and of the same kind as
5315 @var{I}.
5316
5317 @item @emph{See also}:
5318 @ref{BIT_SIZE}, @ref{IBCLR}, @ref{IBSET}, @ref{IAND}, @ref{IOR}, @ref{IEOR}
5319 @end table
5320
5321
5322
5323 @node IBSET
5324 @section @code{IBSET} --- Set bit
5325 @fnindex IBSET
5326 @cindex bits, set
5327
5328 @table @asis
5329 @item @emph{Description}:
5330 @code{IBSET} returns the value of @var{I} with the bit at position
5331 @var{POS} set to one.
5332
5333 @item @emph{Standard}:
5334 F95 and later
5335
5336 @item @emph{Class}:
5337 Elemental function
5338
5339 @item @emph{Syntax}:
5340 @code{RESULT = IBSET(I, POS)}
5341
5342 @item @emph{Arguments}:
5343 @multitable @columnfractions .15 .70
5344 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
5345 @item @var{POS} @tab The type shall be @code{INTEGER(*)}.
5346 @end multitable
5347
5348 @item @emph{Return value}:
5349 The return value is of type @code{INTEGER(*)} and of the same kind as
5350 @var{I}.
5351
5352 @item @emph{See also}:
5353 @ref{IBCLR}, @ref{IBITS}, @ref{IAND}, @ref{IOR}, @ref{IEOR}, @ref{MVBITS}
5354
5355 @end table
5356
5357
5358
5359 @node ICHAR
5360 @section @code{ICHAR} --- Character-to-integer conversion function
5361 @fnindex ICHAR
5362 @cindex conversion, to integer
5363
5364 @table @asis
5365 @item @emph{Description}:
5366 @code{ICHAR(C)} returns the code for the character in the first character
5367 position of @code{C} in the system's native character set.
5368 The correspondence between characters and their codes is not necessarily
5369 the same across different GNU Fortran implementations.
5370
5371 @item @emph{Standard}:
5372 F95 and later
5373
5374 @item @emph{Class}:
5375 Elemental function
5376
5377 @item @emph{Syntax}:
5378 @code{RESULT = ICHAR(C [, KIND])}
5379
5380 @item @emph{Arguments}:
5381 @multitable @columnfractions .15 .70
5382 @item @var{C} @tab Shall be a scalar @code{CHARACTER}, with @code{INTENT(IN)}
5383 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
5384 expression indicating the kind parameter of
5385 the result.
5386 @end multitable
5387
5388 @item @emph{Return value}:
5389 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
5390 @var{KIND} is absent, the return value is of default integer kind.
5391
5392 @item @emph{Example}:
5393 @smallexample
5394 program test_ichar
5395 integer i
5396 i = ichar(' ')
5397 end program test_ichar
5398 @end smallexample
5399
5400 @item @emph{Note}:
5401 No intrinsic exists to convert between a numeric value and a formatted
5402 character string representation -- for instance, given the
5403 @code{CHARACTER} value @code{'154'}, obtaining an @code{INTEGER} or
5404 @code{REAL} value with the value 154, or vice versa. Instead, this
5405 functionality is provided by internal-file I/O, as in the following
5406 example:
5407 @smallexample
5408 program read_val
5409 integer value
5410 character(len=10) string, string2
5411 string = '154'
5412
5413 ! Convert a string to a numeric value
5414 read (string,'(I10)') value
5415 print *, value
5416
5417 ! Convert a value to a formatted string
5418 write (string2,'(I10)') value
5419 print *, string2
5420 end program read_val
5421 @end smallexample
5422
5423 @item @emph{See also}:
5424 @ref{ACHAR}, @ref{CHAR}, @ref{IACHAR}
5425
5426 @end table
5427
5428
5429
5430 @node IDATE
5431 @section @code{IDATE} --- Get current local time subroutine (day/month/year)
5432 @fnindex IDATE
5433 @cindex date, current
5434 @cindex current date
5435
5436 @table @asis
5437 @item @emph{Description}:
5438 @code{IDATE(TARRAY)} Fills @var{TARRAY} with the numerical values at the
5439 current local time. The day (in the range 1-31), month (in the range 1-12),
5440 and year appear in elements 1, 2, and 3 of @var{TARRAY}, respectively.
5441 The year has four significant digits.
5442
5443 @item @emph{Standard}:
5444 GNU extension
5445
5446 @item @emph{Class}:
5447 Subroutine
5448
5449 @item @emph{Syntax}:
5450 @code{CALL IDATE(TARRAY)}
5451
5452 @item @emph{Arguments}:
5453 @multitable @columnfractions .15 .70
5454 @item @var{TARRAY} @tab The type shall be @code{INTEGER, DIMENSION(3)} and
5455 the kind shall be the default integer kind.
5456 @end multitable
5457
5458 @item @emph{Return value}:
5459 Does not return.
5460
5461 @item @emph{Example}:
5462 @smallexample
5463 program test_idate
5464 integer, dimension(3) :: tarray
5465 call idate(tarray)
5466 print *, tarray(1)
5467 print *, tarray(2)
5468 print *, tarray(3)
5469 end program test_idate
5470 @end smallexample
5471 @end table
5472
5473
5474
5475 @node IEOR
5476 @section @code{IEOR} --- Bitwise logical exclusive or
5477 @fnindex IEOR
5478 @cindex bitwise logical exclusive or
5479 @cindex logical exclusive or, bitwise
5480
5481 @table @asis
5482 @item @emph{Description}:
5483 @code{IEOR} returns the bitwise boolean exclusive-OR of @var{I} and
5484 @var{J}.
5485
5486 @item @emph{Standard}:
5487 F95 and later
5488
5489 @item @emph{Class}:
5490 Elemental function
5491
5492 @item @emph{Syntax}:
5493 @code{RESULT = IEOR(I, J)}
5494
5495 @item @emph{Arguments}:
5496 @multitable @columnfractions .15 .70
5497 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
5498 @item @var{J} @tab The type shall be @code{INTEGER(*)}, of the same
5499 kind as @var{I}. (As a GNU extension, different kinds are also
5500 permitted.)
5501 @end multitable
5502
5503 @item @emph{Return value}:
5504 The return type is @code{INTEGER(*)}, of the same kind as the
5505 arguments. (If the argument kinds differ, it is of the same kind as
5506 the larger argument.)
5507
5508 @item @emph{See also}:
5509 @ref{IOR}, @ref{IAND}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}, @ref{NOT}
5510 @end table
5511
5512
5513
5514 @node IERRNO
5515 @section @code{IERRNO} --- Get the last system error number
5516 @fnindex IERRNO
5517 @cindex system, error handling
5518
5519 @table @asis
5520 @item @emph{Description}:
5521 Returns the last system error number, as given by the C @code{errno()}
5522 function.
5523
5524 @item @emph{Standard}:
5525 GNU extension
5526
5527 @item @emph{Class}:
5528 Function
5529
5530 @item @emph{Syntax}:
5531 @code{RESULT = IERRNO()}
5532
5533 @item @emph{Arguments}:
5534 None.
5535
5536 @item @emph{Return value}:
5537 The return value is of type @code{INTEGER} and of the default integer
5538 kind.
5539
5540 @item @emph{See also}:
5541 @ref{PERROR}
5542 @end table
5543
5544
5545
5546 @node INDEX
5547 @section @code{INDEX} --- Position of a substring within a string
5548 @fnindex INDEX
5549 @cindex substring position
5550 @cindex string, find substring
5551
5552 @table @asis
5553 @item @emph{Description}:
5554 Returns the position of the start of the first occurrence of string
5555 @var{SUBSTRING} as a substring in @var{STRING}, counting from one. If
5556 @var{SUBSTRING} is not present in @var{STRING}, zero is returned. If
5557 the @var{BACK} argument is present and true, the return value is the
5558 start of the last occurrence rather than the first.
5559
5560 @item @emph{Standard}:
5561 F77 and later
5562
5563 @item @emph{Class}:
5564 Elemental function
5565
5566 @item @emph{Syntax}:
5567 @code{RESULT = INDEX(STRING, SUBSTRING [, BACK [, KIND]])}
5568
5569 @item @emph{Arguments}:
5570 @multitable @columnfractions .15 .70
5571 @item @var{STRING} @tab Shall be a scalar @code{CHARACTER(*)}, with
5572 @code{INTENT(IN)}
5573 @item @var{SUBSTRING} @tab Shall be a scalar @code{CHARACTER(*)}, with
5574 @code{INTENT(IN)}
5575 @item @var{BACK} @tab (Optional) Shall be a scalar @code{LOGICAL(*)}, with
5576 @code{INTENT(IN)}
5577 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
5578 expression indicating the kind parameter of
5579 the result.
5580 @end multitable
5581
5582 @item @emph{Return value}:
5583 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
5584 @var{KIND} is absent, the return value is of default integer kind.
5585
5586 @item @emph{See also}:
5587 @ref{SCAN}, @ref{VERIFY}
5588 @end table
5589
5590
5591
5592 @node INT
5593 @section @code{INT} --- Convert to integer type
5594 @fnindex INT
5595 @fnindex IFIX
5596 @fnindex IDINT
5597 @cindex conversion, to integer
5598
5599 @table @asis
5600 @item @emph{Description}:
5601 Convert to integer type
5602
5603 @item @emph{Standard}:
5604 F77 and later
5605
5606 @item @emph{Class}:
5607 Elemental function
5608
5609 @item @emph{Syntax}:
5610 @code{RESULT = INT(A [, KIND))}
5611
5612 @item @emph{Arguments}:
5613 @multitable @columnfractions .15 .70
5614 @item @var{A} @tab Shall be of type @code{INTEGER(*)},
5615 @code{REAL(*)}, or @code{COMPLEX(*)}.
5616 @item @var{KIND} @tab (Optional) An @code{INTEGER(*)} initialization
5617 expression indicating the kind parameter of
5618 the result.
5619 @end multitable
5620
5621 @item @emph{Return value}:
5622 These functions return a @code{INTEGER(*)} variable or array under
5623 the following rules:
5624
5625 @table @asis
5626 @item (A)
5627 If @var{A} is of type @code{INTEGER(*)}, @code{INT(A) = A}
5628 @item (B)
5629 If @var{A} is of type @code{REAL(*)} and @math{|A| < 1}, @code{INT(A)} equals @code{0}.
5630 If @math{|A| \geq 1}, then @code{INT(A)} equals the largest integer that does not exceed
5631 the range of @var{A} and whose sign is the same as the sign of @var{A}.
5632 @item (C)
5633 If @var{A} is of type @code{COMPLEX(*)}, rule B is applied to the real part of @var{A}.
5634 @end table
5635
5636 @item @emph{Example}:
5637 @smallexample
5638 program test_int
5639 integer :: i = 42
5640 complex :: z = (-3.7, 1.0)
5641 print *, int(i)
5642 print *, int(z), int(z,8)
5643 end program
5644 @end smallexample
5645
5646 @item @emph{Specific names}:
5647 @multitable @columnfractions .20 .20 .20 .25
5648 @item Name @tab Argument @tab Return type @tab Standard
5649 @item @code{IFIX(A)} @tab @code{REAL(4) A} @tab @code{INTEGER} @tab F77 and later
5650 @item @code{IDINT(A)} @tab @code{REAL(8) A} @tab @code{INTEGER} @tab F77 and later
5651 @end multitable
5652
5653 @end table
5654
5655
5656
5657 @node INT2
5658 @section @code{INT2} --- Convert to 16-bit integer type
5659 @fnindex INT2
5660 @fnindex SHORT
5661 @cindex conversion, to integer
5662
5663 @table @asis
5664 @item @emph{Description}:
5665 Convert to a @code{KIND=2} integer type. This is equivalent to the
5666 standard @code{INT} intrinsic with an optional argument of
5667 @code{KIND=2}, and is only included for backwards compatibility.
5668
5669 The @code{SHORT} intrinsic is equivalent to @code{INT2}.
5670
5671 @item @emph{Standard}:
5672 GNU extension.
5673
5674 @item @emph{Class}:
5675 Elemental function
5676
5677 @item @emph{Syntax}:
5678 @code{RESULT = INT2(A)}
5679
5680 @item @emph{Arguments}:
5681 @multitable @columnfractions .15 .70
5682 @item @var{A} @tab Shall be of type @code{INTEGER(*)},
5683 @code{REAL(*)}, or @code{COMPLEX(*)}.
5684 @end multitable
5685
5686 @item @emph{Return value}:
5687 The return value is a @code{INTEGER(2)} variable.
5688
5689 @item @emph{See also}:
5690 @ref{INT}, @ref{INT8}, @ref{LONG}
5691 @end table
5692
5693
5694
5695 @node INT8
5696 @section @code{INT8} --- Convert to 64-bit integer type
5697 @fnindex INT8
5698 @cindex conversion, to integer
5699
5700 @table @asis
5701 @item @emph{Description}:
5702 Convert to a @code{KIND=8} integer type. This is equivalent to the
5703 standard @code{INT} intrinsic with an optional argument of
5704 @code{KIND=8}, and is only included for backwards compatibility.
5705
5706 @item @emph{Standard}:
5707 GNU extension.
5708
5709 @item @emph{Class}:
5710 Elemental function
5711
5712 @item @emph{Syntax}:
5713 @code{RESULT = INT8(A)}
5714
5715 @item @emph{Arguments}:
5716 @multitable @columnfractions .15 .70
5717 @item @var{A} @tab Shall be of type @code{INTEGER(*)},
5718 @code{REAL(*)}, or @code{COMPLEX(*)}.
5719 @end multitable
5720
5721 @item @emph{Return value}:
5722 The return value is a @code{INTEGER(8)} variable.
5723
5724 @item @emph{See also}:
5725 @ref{INT}, @ref{INT2}, @ref{LONG}
5726 @end table
5727
5728
5729
5730 @node IOR
5731 @section @code{IOR} --- Bitwise logical or
5732 @fnindex IOR
5733 @cindex bitwise logical or
5734 @cindex logical or, bitwise
5735
5736 @table @asis
5737 @item @emph{Description}:
5738 @code{IEOR} returns the bitwise boolean OR of @var{I} and
5739 @var{J}.
5740
5741 @item @emph{Standard}:
5742 F95 and later
5743
5744 @item @emph{Class}:
5745 Elemental function
5746
5747 @item @emph{Syntax}:
5748 @code{RESULT = IEOR(I, J)}
5749
5750 @item @emph{Arguments}:
5751 @multitable @columnfractions .15 .70
5752 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
5753 @item @var{J} @tab The type shall be @code{INTEGER(*)}, of the same
5754 kind as @var{I}. (As a GNU extension, different kinds are also
5755 permitted.)
5756 @end multitable
5757
5758 @item @emph{Return value}:
5759 The return type is @code{INTEGER(*)}, of the same kind as the
5760 arguments. (If the argument kinds differ, it is of the same kind as
5761 the larger argument.)
5762
5763 @item @emph{See also}:
5764 @ref{IEOR}, @ref{IAND}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}, @ref{NOT}
5765 @end table
5766
5767
5768
5769 @node IRAND
5770 @section @code{IRAND} --- Integer pseudo-random number
5771 @fnindex IRAND
5772 @cindex random number generation
5773
5774 @table @asis
5775 @item @emph{Description}:
5776 @code{IRAND(FLAG)} returns a pseudo-random number from a uniform
5777 distribution between 0 and a system-dependent limit (which is in most
5778 cases 2147483647). If @var{FLAG} is 0, the next number
5779 in the current sequence is returned; if @var{FLAG} is 1, the generator
5780 is restarted by @code{CALL SRAND(0)}; if @var{FLAG} has any other value,
5781 it is used as a new seed with @code{SRAND}.
5782
5783 This intrinsic routine is provided for backwards compatibility with
5784 GNU Fortran 77. It implements a simple modulo generator as provided
5785 by @command{g77}. For new code, one should consider the use of
5786 @ref{RANDOM_NUMBER} as it implements a superior algorithm.
5787
5788 @item @emph{Standard}:
5789 GNU extension
5790
5791 @item @emph{Class}:
5792 Function
5793
5794 @item @emph{Syntax}:
5795 @code{RESULT = IRAND(FLAG)}
5796
5797 @item @emph{Arguments}:
5798 @multitable @columnfractions .15 .70
5799 @item @var{FLAG} @tab Shall be a scalar @code{INTEGER} of kind 4.
5800 @end multitable
5801
5802 @item @emph{Return value}:
5803 The return value is of @code{INTEGER(kind=4)} type.
5804
5805 @item @emph{Example}:
5806 @smallexample
5807 program test_irand
5808 integer,parameter :: seed = 86456
5809
5810 call srand(seed)
5811 print *, irand(), irand(), irand(), irand()
5812 print *, irand(seed), irand(), irand(), irand()
5813 end program test_irand
5814 @end smallexample
5815
5816 @end table
5817
5818
5819
5820 @node ISATTY
5821 @section @code{ISATTY} --- Whether a unit is a terminal device.
5822 @fnindex ISATTY
5823 @cindex system, terminal
5824
5825 @table @asis
5826 @item @emph{Description}:
5827 Determine whether a unit is connected to a terminal device.
5828
5829 @item @emph{Standard}:
5830 GNU extension.
5831
5832 @item @emph{Class}:
5833 Function
5834
5835 @item @emph{Syntax}:
5836 @code{RESULT = ISATTY(UNIT)}
5837
5838 @item @emph{Arguments}:
5839 @multitable @columnfractions .15 .70
5840 @item @var{UNIT} @tab Shall be a scalar @code{INTEGER(*)}.
5841 @end multitable
5842
5843 @item @emph{Return value}:
5844 Returns @code{.TRUE.} if the @var{UNIT} is connected to a terminal
5845 device, @code{.FALSE.} otherwise.
5846
5847 @item @emph{Example}:
5848 @smallexample
5849 PROGRAM test_isatty
5850 INTEGER(kind=1) :: unit
5851 DO unit = 1, 10
5852 write(*,*) isatty(unit=unit)
5853 END DO
5854 END PROGRAM
5855 @end smallexample
5856 @item @emph{See also}:
5857 @ref{TTYNAM}
5858 @end table
5859
5860
5861
5862 @node ISHFT
5863 @section @code{ISHFT} --- Shift bits
5864 @fnindex ISHFT
5865 @cindex bits, shift
5866
5867 @table @asis
5868 @item @emph{Description}:
5869 @code{ISHFT} returns a value corresponding to @var{I} with all of the
5870 bits shifted @var{SHIFT} places. A value of @var{SHIFT} greater than
5871 zero corresponds to a left shift, a value of zero corresponds to no
5872 shift, and a value less than zero corresponds to a right shift. If the
5873 absolute value of @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the
5874 value is undefined. Bits shifted out from the left end or right end are
5875 lost; zeros are shifted in from the opposite end.
5876
5877 @item @emph{Standard}:
5878 F95 and later
5879
5880 @item @emph{Class}:
5881 Elemental function
5882
5883 @item @emph{Syntax}:
5884 @code{RESULT = ISHFT(I, SHIFT)}
5885
5886 @item @emph{Arguments}:
5887 @multitable @columnfractions .15 .70
5888 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
5889 @item @var{SHIFT} @tab The type shall be @code{INTEGER(*)}.
5890 @end multitable
5891
5892 @item @emph{Return value}:
5893 The return value is of type @code{INTEGER(*)} and of the same kind as
5894 @var{I}.
5895
5896 @item @emph{See also}:
5897 @ref{ISHFTC}
5898 @end table
5899
5900
5901
5902 @node ISHFTC
5903 @section @code{ISHFTC} --- Shift bits circularly
5904 @fnindex ISHFTC
5905 @cindex bits, shift circular
5906
5907 @table @asis
5908 @item @emph{Description}:
5909 @code{ISHFTC} returns a value corresponding to @var{I} with the
5910 rightmost @var{SIZE} bits shifted circularly @var{SHIFT} places; that
5911 is, bits shifted out one end are shifted into the opposite end. A value
5912 of @var{SHIFT} greater than zero corresponds to a left shift, a value of
5913 zero corresponds to no shift, and a value less than zero corresponds to
5914 a right shift. The absolute value of @var{SHIFT} must be less than
5915 @var{SIZE}. If the @var{SIZE} argument is omitted, it is taken to be
5916 equivalent to @code{BIT_SIZE(I)}.
5917
5918 @item @emph{Standard}:
5919 F95 and later
5920
5921 @item @emph{Class}:
5922 Elemental function
5923
5924 @item @emph{Syntax}:
5925 @code{RESULT = ISHFTC(I, SHIFT [, SIZE])}
5926
5927 @item @emph{Arguments}:
5928 @multitable @columnfractions .15 .70
5929 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
5930 @item @var{SHIFT} @tab The type shall be @code{INTEGER(*)}.
5931 @item @var{SIZE} @tab (Optional) The type shall be @code{INTEGER(*)};
5932 the value must be greater than zero and less than or equal to
5933 @code{BIT_SIZE(I)}.
5934 @end multitable
5935
5936 @item @emph{Return value}:
5937 The return value is of type @code{INTEGER(*)} and of the same kind as
5938 @var{I}.
5939
5940 @item @emph{See also}:
5941 @ref{ISHFT}
5942 @end table
5943
5944
5945
5946 @node ISNAN
5947 @section @code{ISNAN} --- Test for a NaN
5948 @fnindex ISNAN
5949 @cindex IEEE, ISNAN
5950
5951 @table @asis
5952 @item @emph{Description}:
5953 @code{ISNAN} tests whether a floating-point value is an IEEE
5954 Not-a-Number (NaN).
5955 @item @emph{Standard}:
5956 GNU extension
5957
5958 @item @emph{Class}:
5959 Elemental function
5960
5961 @item @emph{Syntax}:
5962 @code{ISNAN(X)}
5963
5964 @item @emph{Arguments}:
5965 @multitable @columnfractions .15 .70
5966 @item @var{X} @tab Variable of the type @code{REAL}.
5967
5968 @end multitable
5969
5970 @item @emph{Return value}:
5971 Returns a default-kind @code{LOGICAL}. The returned value is @code{TRUE}
5972 if @var{X} is a NaN and @code{FALSE} otherwise.
5973
5974 @item @emph{Example}:
5975 @smallexample
5976 program test_nan
5977 implicit none
5978 real :: x
5979 x = -1.0
5980 x = sqrt(x)
5981 if (isnan(x)) stop '"x" is a NaN'
5982 end program test_nan
5983 @end smallexample
5984 @end table
5985
5986
5987
5988 @node ITIME
5989 @section @code{ITIME} --- Get current local time subroutine (hour/minutes/seconds)
5990 @fnindex ITIME
5991 @cindex time, current
5992 @cindex current time
5993
5994 @table @asis
5995 @item @emph{Description}:
5996 @code{IDATE(TARRAY)} Fills @var{TARRAY} with the numerical values at the
5997 current local time. The hour (in the range 1-24), minute (in the range 1-60),
5998 and seconds (in the range 1-60) appear in elements 1, 2, and 3 of @var{TARRAY},
5999 respectively.
6000
6001 @item @emph{Standard}:
6002 GNU extension
6003
6004 @item @emph{Class}:
6005 Subroutine
6006
6007 @item @emph{Syntax}:
6008 @code{CALL ITIME(TARRAY)}
6009
6010 @item @emph{Arguments}:
6011 @multitable @columnfractions .15 .70
6012 @item @var{TARRAY} @tab The type shall be @code{INTEGER, DIMENSION(3)}
6013 and the kind shall be the default integer kind.
6014 @end multitable
6015
6016 @item @emph{Return value}:
6017 Does not return.
6018
6019
6020 @item @emph{Example}:
6021 @smallexample
6022 program test_itime
6023 integer, dimension(3) :: tarray
6024 call itime(tarray)
6025 print *, tarray(1)
6026 print *, tarray(2)
6027 print *, tarray(3)
6028 end program test_itime
6029 @end smallexample
6030 @end table
6031
6032
6033
6034 @node KILL
6035 @section @code{KILL} --- Send a signal to a process
6036 @fnindex KILL
6037
6038 @table @asis
6039 @item @emph{Description}:
6040 @item @emph{Standard}:
6041 Sends the signal specified by @var{SIGNAL} to the process @var{PID}.
6042 See @code{kill(2)}.
6043
6044 This intrinsic is provided in both subroutine and function forms; however,
6045 only one form can be used in any given program unit.
6046
6047 @item @emph{Class}:
6048 Subroutine, function
6049
6050 @item @emph{Syntax}:
6051 @code{CALL KILL(PID, SIGNAL [, STATUS])}
6052
6053 @item @emph{Arguments}:
6054 @multitable @columnfractions .15 .70
6055 @item @var{PID} @tab Shall be a scalar @code{INTEGER}, with
6056 @code{INTENT(IN)}
6057 @item @var{SIGNAL} @tab Shall be a scalar @code{INTEGER}, with
6058 @code{INTENT(IN)}
6059 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)} or
6060 @code{INTEGER(8)}. Returns 0 on success, or a
6061 system-specific error code otherwise.
6062 @end multitable
6063
6064 @item @emph{See also}:
6065 @ref{ABORT}, @ref{EXIT}
6066 @end table
6067
6068
6069
6070 @node KIND
6071 @section @code{KIND} --- Kind of an entity
6072 @fnindex KIND
6073 @cindex kind
6074
6075 @table @asis
6076 @item @emph{Description}:
6077 @code{KIND(X)} returns the kind value of the entity @var{X}.
6078
6079 @item @emph{Standard}:
6080 F95 and later
6081
6082 @item @emph{Class}:
6083 Inquiry function
6084
6085 @item @emph{Syntax}:
6086 @code{K = KIND(X)}
6087
6088 @item @emph{Arguments}:
6089 @multitable @columnfractions .15 .70
6090 @item @var{X} @tab Shall be of type @code{LOGICAL}, @code{INTEGER},
6091 @code{REAL}, @code{COMPLEX} or @code{CHARACTER}.
6092 @end multitable
6093
6094 @item @emph{Return value}:
6095 The return value is a scalar of type @code{INTEGER} and of the default
6096 integer kind.
6097
6098 @item @emph{Example}:
6099 @smallexample
6100 program test_kind
6101 integer,parameter :: kc = kind(' ')
6102 integer,parameter :: kl = kind(.true.)
6103
6104 print *, "The default character kind is ", kc
6105 print *, "The default logical kind is ", kl
6106 end program test_kind
6107 @end smallexample
6108
6109 @end table
6110
6111
6112
6113 @node LBOUND
6114 @section @code{LBOUND} --- Lower dimension bounds of an array
6115 @fnindex LBOUND
6116 @cindex array, lower bound
6117
6118 @table @asis
6119 @item @emph{Description}:
6120 Returns the lower bounds of an array, or a single lower bound
6121 along the @var{DIM} dimension.
6122 @item @emph{Standard}:
6123 F95 and later
6124
6125 @item @emph{Class}:
6126 Inquiry function
6127
6128 @item @emph{Syntax}:
6129 @code{RESULT = LBOUND(ARRAY [, DIM [, KIND]])}
6130
6131 @item @emph{Arguments}:
6132 @multitable @columnfractions .15 .70
6133 @item @var{ARRAY} @tab Shall be an array, of any type.
6134 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER(*)}.
6135 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
6136 expression indicating the kind parameter of
6137 the result.
6138 @end multitable
6139
6140 @item @emph{Return value}:
6141 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
6142 @var{KIND} is absent, the return value is of default integer kind.
6143 If @var{DIM} is absent, the result is an array of the lower bounds of
6144 @var{ARRAY}. If @var{DIM} is present, the result is a scalar
6145 corresponding to the lower bound of the array along that dimension. If
6146 @var{ARRAY} is an expression rather than a whole array or array
6147 structure component, or if it has a zero extent along the relevant
6148 dimension, the lower bound is taken to be 1.
6149
6150 @item @emph{See also}:
6151 @ref{UBOUND}
6152 @end table
6153
6154
6155
6156 @node LEN
6157 @section @code{LEN} --- Length of a character entity
6158 @fnindex LEN
6159 @cindex string, length
6160
6161 @table @asis
6162 @item @emph{Description}:
6163 Returns the length of a character string. If @var{STRING} is an array,
6164 the length of an element of @var{STRING} is returned. Note that
6165 @var{STRING} need not be defined when this intrinsic is invoked, since
6166 only the length, not the content, of @var{STRING} is needed.
6167
6168 @item @emph{Standard}:
6169 F77 and later
6170
6171 @item @emph{Class}:
6172 Inquiry function
6173
6174 @item @emph{Syntax}:
6175 @code{L = LEN(STRING [, KIND])}
6176
6177 @item @emph{Arguments}:
6178 @multitable @columnfractions .15 .70
6179 @item @var{STRING} @tab Shall be a scalar or array of type
6180 @code{CHARACTER(*)}, with @code{INTENT(IN)}
6181 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
6182 expression indicating the kind parameter of
6183 the result.
6184 @end multitable
6185
6186 @item @emph{Return value}:
6187 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
6188 @var{KIND} is absent, the return value is of default integer kind.
6189
6190 @item @emph{See also}:
6191 @ref{LEN_TRIM}, @ref{ADJUSTL}, @ref{ADJUSTR}
6192 @end table
6193
6194
6195
6196 @node LEN_TRIM
6197 @section @code{LEN_TRIM} --- Length of a character entity without trailing blank characters
6198 @fnindex LEN_TRIM
6199 @cindex string, length, without trailing whitespace
6200
6201 @table @asis
6202 @item @emph{Description}:
6203 Returns the length of a character string, ignoring any trailing blanks.
6204
6205 @item @emph{Standard}:
6206 F95 and later
6207
6208 @item @emph{Class}:
6209 Elemental function
6210
6211 @item @emph{Syntax}:
6212 @code{RESULT = LEN_TRIM(STRING [, KIND])}
6213
6214 @item @emph{Arguments}:
6215 @multitable @columnfractions .15 .70
6216 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER(*)},
6217 with @code{INTENT(IN)}
6218 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
6219 expression indicating the kind parameter of
6220 the result.
6221 @end multitable
6222
6223 @item @emph{Return value}:
6224 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
6225 @var{KIND} is absent, the return value is of default integer kind.
6226
6227 @item @emph{See also}:
6228 @ref{LEN}, @ref{ADJUSTL}, @ref{ADJUSTR}
6229 @end table
6230
6231
6232
6233 @node LGE
6234 @section @code{LGE} --- Lexical greater than or equal
6235 @fnindex LGE
6236 @cindex lexical comparison of strings
6237 @cindex string, comparison
6238
6239 @table @asis
6240 @item @emph{Description}:
6241 Determines whether one string is lexically greater than or equal to
6242 another string, where the two strings are interpreted as containing
6243 ASCII character codes. If the String A and String B are not the same
6244 length, the shorter is compared as if spaces were appended to it to form
6245 a value that has the same length as the longer.
6246
6247 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
6248 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
6249 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
6250 that the latter use the processor's character ordering (which is not
6251 ASCII on some targets), whereas the former always use the ASCII
6252 ordering.
6253
6254 @item @emph{Standard}:
6255 F77 and later
6256
6257 @item @emph{Class}:
6258 Elemental function
6259
6260 @item @emph{Syntax}:
6261 @code{RESULT = LGE(STRING_A, STRING_B)}
6262
6263 @item @emph{Arguments}:
6264 @multitable @columnfractions .15 .70
6265 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
6266 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
6267 @end multitable
6268
6269 @item @emph{Return value}:
6270 Returns @code{.TRUE.} if @code{STRING_A >= STRING_B}, and @code{.FALSE.}
6271 otherwise, based on the ASCII ordering.
6272
6273 @item @emph{See also}:
6274 @ref{LGT}, @ref{LLE}, @ref{LLT}
6275 @end table
6276
6277
6278
6279 @node LGT
6280 @section @code{LGT} --- Lexical greater than
6281 @fnindex LGT
6282 @cindex lexical comparison of strings
6283 @cindex string, comparison
6284
6285 @table @asis
6286 @item @emph{Description}:
6287 Determines whether one string is lexically greater than another string,
6288 where the two strings are interpreted as containing ASCII character
6289 codes. If the String A and String B are not the same length, the
6290 shorter is compared as if spaces were appended to it to form a value
6291 that has the same length as the longer.
6292
6293 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
6294 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
6295 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
6296 that the latter use the processor's character ordering (which is not
6297 ASCII on some targets), whereas the former always use the ASCII
6298 ordering.
6299
6300 @item @emph{Standard}:
6301 F77 and later
6302
6303 @item @emph{Class}:
6304 Elemental function
6305
6306 @item @emph{Syntax}:
6307 @code{RESULT = LGT(STRING_A, STRING_B)}
6308
6309 @item @emph{Arguments}:
6310 @multitable @columnfractions .15 .70
6311 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
6312 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
6313 @end multitable
6314
6315 @item @emph{Return value}:
6316 Returns @code{.TRUE.} if @code{STRING_A > STRING_B}, and @code{.FALSE.}
6317 otherwise, based on the ASCII ordering.
6318
6319 @item @emph{See also}:
6320 @ref{LGE}, @ref{LLE}, @ref{LLT}
6321 @end table
6322
6323
6324
6325 @node LINK
6326 @section @code{LINK} --- Create a hard link
6327 @fnindex LINK
6328 @cindex file system, create link
6329 @cindex file system, hard link
6330
6331 @table @asis
6332 @item @emph{Description}:
6333 Makes a (hard) link from file @var{PATH1} to @var{PATH2}. A null
6334 character (@code{CHAR(0)}) can be used to mark the end of the names in
6335 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
6336 names are ignored. If the @var{STATUS} argument is supplied, it
6337 contains 0 on success or a nonzero error code upon return; see
6338 @code{link(2)}.
6339
6340 This intrinsic is provided in both subroutine and function forms;
6341 however, only one form can be used in any given program unit.
6342
6343 @item @emph{Standard}:
6344 GNU extension
6345
6346 @item @emph{Class}:
6347 Subroutine, function
6348
6349 @item @emph{Syntax}:
6350 @multitable @columnfractions .80
6351 @item @code{CALL LINK(PATH1, PATH2 [, STATUS])}
6352 @item @code{STATUS = LINK(PATH1, PATH2)}
6353 @end multitable
6354
6355 @item @emph{Arguments}:
6356 @multitable @columnfractions .15 .70
6357 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
6358 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
6359 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
6360 @end multitable
6361
6362 @item @emph{See also}:
6363 @ref{SYMLNK}, @ref{UNLINK}
6364 @end table
6365
6366
6367
6368 @node LLE
6369 @section @code{LLE} --- Lexical less than or equal
6370 @fnindex LLE
6371 @cindex lexical comparison of strings
6372 @cindex string, comparison
6373
6374 @table @asis
6375 @item @emph{Description}:
6376 Determines whether one string is lexically less than or equal to another
6377 string, where the two strings are interpreted as containing ASCII
6378 character codes. If the String A and String B are not the same length,
6379 the shorter is compared as if spaces were appended to it to form a value
6380 that has the same length as the longer.
6381
6382 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
6383 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
6384 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
6385 that the latter use the processor's character ordering (which is not
6386 ASCII on some targets), whereas the former always use the ASCII
6387 ordering.
6388
6389 @item @emph{Standard}:
6390 F77 and later
6391
6392 @item @emph{Class}:
6393 Elemental function
6394
6395 @item @emph{Syntax}:
6396 @code{RESULT = LLE(STRING_A, STRING_B)}
6397
6398 @item @emph{Arguments}:
6399 @multitable @columnfractions .15 .70
6400 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
6401 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
6402 @end multitable
6403
6404 @item @emph{Return value}:
6405 Returns @code{.TRUE.} if @code{STRING_A <= STRING_B}, and @code{.FALSE.}
6406 otherwise, based on the ASCII ordering.
6407
6408 @item @emph{See also}:
6409 @ref{LGE}, @ref{LGT}, @ref{LLT}
6410 @end table
6411
6412
6413
6414 @node LLT
6415 @section @code{LLT} --- Lexical less than
6416 @fnindex LLT
6417 @cindex lexical comparison of strings
6418 @cindex string, comparison
6419
6420 @table @asis
6421 @item @emph{Description}:
6422 Determines whether one string is lexically less than another string,
6423 where the two strings are interpreted as containing ASCII character
6424 codes. If the String A and String B are not the same length, the
6425 shorter is compared as if spaces were appended to it to form a value
6426 that has the same length as the longer.
6427
6428 In general, the lexical comparison intrinsics @code{LGE}, @code{LGT},
6429 @code{LLE}, and @code{LLT} differ from the corresponding intrinsic
6430 operators @code{.GE.}, @code{.GT.}, @code{.LE.}, and @code{.LT.}, in
6431 that the latter use the processor's character ordering (which is not
6432 ASCII on some targets), whereas the former always use the ASCII
6433 ordering.
6434
6435 @item @emph{Standard}:
6436 F77 and later
6437
6438 @item @emph{Class}:
6439 Elemental function
6440
6441 @item @emph{Syntax}:
6442 @code{RESULT = LLT(STRING_A, STRING_B)}
6443
6444 @item @emph{Arguments}:
6445 @multitable @columnfractions .15 .70
6446 @item @var{STRING_A} @tab Shall be of default @code{CHARACTER} type.
6447 @item @var{STRING_B} @tab Shall be of default @code{CHARACTER} type.
6448 @end multitable
6449
6450 @item @emph{Return value}:
6451 Returns @code{.TRUE.} if @code{STRING_A < STRING_B}, and @code{.FALSE.}
6452 otherwise, based on the ASCII ordering.
6453
6454 @item @emph{See also}:
6455 @ref{LGE}, @ref{LGT}, @ref{LLE}
6456 @end table
6457
6458
6459
6460 @node LNBLNK
6461 @section @code{LNBLNK} --- Index of the last non-blank character in a string
6462 @fnindex LNBLNK
6463 @cindex string, find non-blank character
6464
6465 @table @asis
6466 @item @emph{Description}:
6467 Returns the length of a character string, ignoring any trailing blanks.
6468 This is identical to the standard @code{LEN_TRIM} intrinsic, and is only
6469 included for backwards compatibility.
6470
6471 @item @emph{Standard}:
6472 GNU extension
6473
6474 @item @emph{Class}:
6475 Elemental function
6476
6477 @item @emph{Syntax}:
6478 @code{RESULT = LNBLNK(STRING)}
6479
6480 @item @emph{Arguments}:
6481 @multitable @columnfractions .15 .70
6482 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER(*)},
6483 with @code{INTENT(IN)}
6484 @end multitable
6485
6486 @item @emph{Return value}:
6487 The return value is of @code{INTEGER(kind=4)} type.
6488
6489 @item @emph{See also}:
6490 @ref{INDEX}, @ref{LEN_TRIM}
6491 @end table
6492
6493
6494
6495 @node LOC
6496 @section @code{LOC} --- Returns the address of a variable
6497 @fnindex LOC
6498 @cindex location of a variable in memory
6499
6500 @table @asis
6501 @item @emph{Description}:
6502 @code{LOC(X)} returns the address of @var{X} as an integer.
6503
6504 @item @emph{Standard}:
6505 GNU extension
6506
6507 @item @emph{Class}:
6508 Inquiry function
6509
6510 @item @emph{Syntax}:
6511 @code{RESULT = LOC(X)}
6512
6513 @item @emph{Arguments}:
6514 @multitable @columnfractions .15 .70
6515 @item @var{X} @tab Variable of any type.
6516 @end multitable
6517
6518 @item @emph{Return value}:
6519 The return value is of type @code{INTEGER}, with a @code{KIND}
6520 corresponding to the size (in bytes) of a memory address on the target
6521 machine.
6522
6523 @item @emph{Example}:
6524 @smallexample
6525 program test_loc
6526 integer :: i
6527 real :: r
6528 i = loc(r)
6529 print *, i
6530 end program test_loc
6531 @end smallexample
6532 @end table
6533
6534
6535
6536 @node LOG
6537 @section @code{LOG} --- Logarithm function
6538 @fnindex LOG
6539 @fnindex ALOG
6540 @fnindex DLOG
6541 @fnindex CLOG
6542 @fnindex ZLOG
6543 @fnindex CDLOG
6544 @cindex exponential function, inverse
6545 @cindex logarithmic function
6546
6547 @table @asis
6548 @item @emph{Description}:
6549 @code{LOG(X)} computes the logarithm of @var{X}.
6550
6551 @item @emph{Standard}:
6552 F77 and later
6553
6554 @item @emph{Class}:
6555 Elemental function
6556
6557 @item @emph{Syntax}:
6558 @code{RESULT = LOG(X)}
6559
6560 @item @emph{Arguments}:
6561 @multitable @columnfractions .15 .70
6562 @item @var{X} @tab The type shall be @code{REAL(*)} or
6563 @code{COMPLEX(*)}.
6564 @end multitable
6565
6566 @item @emph{Return value}:
6567 The return value is of type @code{REAL(*)} or @code{COMPLEX(*)}.
6568 The kind type parameter is the same as @var{X}.
6569
6570 @item @emph{Example}:
6571 @smallexample
6572 program test_log
6573 real(8) :: x = 1.0_8
6574 complex :: z = (1.0, 2.0)
6575 x = log(x)
6576 z = log(z)
6577 end program test_log
6578 @end smallexample
6579
6580 @item @emph{Specific names}:
6581 @multitable @columnfractions .20 .20 .20 .25
6582 @item Name @tab Argument @tab Return type @tab Standard
6583 @item @code{ALOG(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab f95, gnu
6584 @item @code{DLOG(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab f95, gnu
6585 @item @code{CLOG(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab f95, gnu
6586 @item @code{ZLOG(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
6587 @item @code{CDLOG(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
6588 @end multitable
6589 @end table
6590
6591
6592
6593 @node LOG10
6594 @section @code{LOG10} --- Base 10 logarithm function
6595 @fnindex LOG10
6596 @fnindex ALOG10
6597 @fnindex DLOG10
6598 @cindex exponential function, inverse
6599 @cindex logarithmic function
6600
6601 @table @asis
6602 @item @emph{Description}:
6603 @code{LOG10(X)} computes the base 10 logarithm of @var{X}.
6604
6605 @item @emph{Standard}:
6606 F77 and later
6607
6608 @item @emph{Class}:
6609 Elemental function
6610
6611 @item @emph{Syntax}:
6612 @code{RESULT = LOG10(X)}
6613
6614 @item @emph{Arguments}:
6615 @multitable @columnfractions .15 .70
6616 @item @var{X} @tab The type shall be @code{REAL(*)}.
6617 @end multitable
6618
6619 @item @emph{Return value}:
6620 The return value is of type @code{REAL(*)} or @code{COMPLEX(*)}.
6621 The kind type parameter is the same as @var{X}.
6622
6623 @item @emph{Example}:
6624 @smallexample
6625 program test_log10
6626 real(8) :: x = 10.0_8
6627 x = log10(x)
6628 end program test_log10
6629 @end smallexample
6630
6631 @item @emph{Specific names}:
6632 @multitable @columnfractions .20 .20 .20 .25
6633 @item Name @tab Argument @tab Return type @tab Standard
6634 @item @code{ALOG10(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab F95 and later
6635 @item @code{DLOG10(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F95 and later
6636 @end multitable
6637 @end table
6638
6639
6640
6641 @node LOGICAL
6642 @section @code{LOGICAL} --- Convert to logical type
6643 @fnindex LOGICAL
6644 @cindex conversion, to logical
6645
6646 @table @asis
6647 @item @emph{Description}:
6648 Converts one kind of @code{LOGICAL} variable to another.
6649
6650 @item @emph{Standard}:
6651 F95 and later
6652
6653 @item @emph{Class}:
6654 Elemental function
6655
6656 @item @emph{Syntax}:
6657 @code{RESULT = LOGICAL(L [, KIND])}
6658
6659 @item @emph{Arguments}:
6660 @multitable @columnfractions .15 .70
6661 @item @var{L} @tab The type shall be @code{LOGICAL(*)}.
6662 @item @var{KIND} @tab (Optional) An @code{INTEGER(*)} initialization
6663 expression indicating the kind parameter of
6664 the result.
6665 @end multitable
6666
6667 @item @emph{Return value}:
6668 The return value is a @code{LOGICAL} value equal to @var{L}, with a
6669 kind corresponding to @var{KIND}, or of the default logical kind if
6670 @var{KIND} is not given.
6671
6672 @item @emph{See also}:
6673 @ref{INT}, @ref{REAL}, @ref{CMPLX}
6674 @end table
6675
6676
6677
6678 @node LONG
6679 @section @code{LONG} --- Convert to integer type
6680 @fnindex LONG
6681 @cindex conversion, to integer
6682
6683 @table @asis
6684 @item @emph{Description}:
6685 Convert to a @code{KIND=4} integer type, which is the same size as a C
6686 @code{long} integer. This is equivalent to the standard @code{INT}
6687 intrinsic with an optional argument of @code{KIND=4}, and is only
6688 included for backwards compatibility.
6689
6690 @item @emph{Standard}:
6691 GNU extension.
6692
6693 @item @emph{Class}:
6694 Elemental function
6695
6696 @item @emph{Syntax}:
6697 @code{RESULT = LONG(A)}
6698
6699 @item @emph{Arguments}:
6700 @multitable @columnfractions .15 .70
6701 @item @var{A} @tab Shall be of type @code{INTEGER(*)},
6702 @code{REAL(*)}, or @code{COMPLEX(*)}.
6703 @end multitable
6704
6705 @item @emph{Return value}:
6706 The return value is a @code{INTEGER(4)} variable.
6707
6708 @item @emph{See also}:
6709 @ref{INT}, @ref{INT2}, @ref{INT8}
6710 @end table
6711
6712
6713
6714 @node LSHIFT
6715 @section @code{LSHIFT} --- Left shift bits
6716 @fnindex LSHIFT
6717 @cindex bits, shift left
6718
6719 @table @asis
6720 @item @emph{Description}:
6721 @code{LSHIFT} returns a value corresponding to @var{I} with all of the
6722 bits shifted left by @var{SHIFT} places. If the absolute value of
6723 @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the value is undefined.
6724 Bits shifted out from the left end are lost; zeros are shifted in from
6725 the opposite end.
6726
6727 This function has been superseded by the @code{ISHFT} intrinsic, which
6728 is standard in Fortran 95 and later.
6729
6730 @item @emph{Standard}:
6731 GNU extension
6732
6733 @item @emph{Class}:
6734 Elemental function
6735
6736 @item @emph{Syntax}:
6737 @code{RESULT = LSHIFT(I, SHIFT)}
6738
6739 @item @emph{Arguments}:
6740 @multitable @columnfractions .15 .70
6741 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
6742 @item @var{SHIFT} @tab The type shall be @code{INTEGER(*)}.
6743 @end multitable
6744
6745 @item @emph{Return value}:
6746 The return value is of type @code{INTEGER(*)} and of the same kind as
6747 @var{I}.
6748
6749 @item @emph{See also}:
6750 @ref{ISHFT}, @ref{ISHFTC}, @ref{RSHIFT}
6751
6752 @end table
6753
6754
6755
6756 @node LSTAT
6757 @section @code{LSTAT} --- Get file status
6758 @fnindex LSTAT
6759 @cindex file system, file status
6760
6761 @table @asis
6762 @item @emph{Description}:
6763 @code{LSTAT} is identical to @ref{STAT}, except that if path is a symbolic link,
6764 then the link itself is statted, not the file that it refers to.
6765
6766 The elements in @code{BUFF} are the same as described by @ref{STAT}.
6767
6768 This intrinsic is provided in both subroutine and function forms; however,
6769 only one form can be used in any given program unit.
6770
6771 @item @emph{Standard}:
6772 GNU extension
6773
6774 @item @emph{Class}:
6775 Subroutine, function
6776
6777 @item @emph{Syntax}:
6778 @code{CALL LSTAT(FILE, BUFF [, STATUS])}
6779
6780 @item @emph{Arguments}:
6781 @multitable @columnfractions .15 .70
6782 @item @var{FILE} @tab The type shall be @code{CHARACTER(*)}, a valid path within the file system.
6783 @item @var{BUFF} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
6784 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}. Returns 0
6785 on success and a system specific error code otherwise.
6786 @end multitable
6787
6788 @item @emph{Example}:
6789 See @ref{STAT} for an example.
6790
6791 @item @emph{See also}:
6792 To stat an open file: @ref{FSTAT}, to stat a file: @ref{STAT}
6793 @end table
6794
6795
6796
6797 @node LTIME
6798 @section @code{LTIME} --- Convert time to local time info
6799 @fnindex LTIME
6800 @cindex time, conversion to local time info
6801
6802 @table @asis
6803 @item @emph{Description}:
6804 Given a system time value @var{STIME} (as provided by the @code{TIME8()}
6805 intrinsic), fills @var{TARRAY} with values extracted from it appropriate
6806 to the local time zone using @code{localtime(3)}.
6807
6808 @item @emph{Standard}:
6809 GNU extension
6810
6811 @item @emph{Class}:
6812 Subroutine
6813
6814 @item @emph{Syntax}:
6815 @code{CALL LTIME(STIME, TARRAY)}
6816
6817 @item @emph{Arguments}:
6818 @multitable @columnfractions .15 .70
6819 @item @var{STIME} @tab An @code{INTEGER(*)} scalar expression
6820 corresponding to a system time, with
6821 @code{INTENT(IN)}.
6822 @item @var{TARRAY} @tab A default @code{INTEGER} array with 9 elements,
6823 with @code{INTENT(OUT)}.
6824 @end multitable
6825
6826 @item @emph{Return value}:
6827 The elements of @var{TARRAY} are assigned as follows:
6828 @enumerate
6829 @item Seconds after the minute, range 0--59 or 0--61 to allow for leap
6830 seconds
6831 @item Minutes after the hour, range 0--59
6832 @item Hours past midnight, range 0--23
6833 @item Day of month, range 0--31
6834 @item Number of months since January, range 0--12
6835 @item Years since 1900
6836 @item Number of days since Sunday, range 0--6
6837 @item Days since January 1
6838 @item Daylight savings indicator: positive if daylight savings is in
6839 effect, zero if not, and negative if the information is not
6840 available.
6841 @end enumerate
6842
6843 @item @emph{See also}:
6844 @ref{CTIME}, @ref{GMTIME}, @ref{TIME}, @ref{TIME8}
6845
6846 @end table
6847
6848
6849
6850 @node MALLOC
6851 @section @code{MALLOC} --- Allocate dynamic memory
6852 @fnindex MALLOC
6853 @cindex pointer, cray
6854
6855 @table @asis
6856 @item @emph{Description}:
6857 @code{MALLOC(SIZE)} allocates @var{SIZE} bytes of dynamic memory and
6858 returns the address of the allocated memory. The @code{MALLOC} intrinsic
6859 is an extension intended to be used with Cray pointers, and is provided
6860 in GNU Fortran to allow the user to compile legacy code. For new code
6861 using Fortran 95 pointers, the memory allocation intrinsic is
6862 @code{ALLOCATE}.
6863
6864 @item @emph{Standard}:
6865 GNU extension
6866
6867 @item @emph{Class}:
6868 Function
6869
6870 @item @emph{Syntax}:
6871 @code{PTR = MALLOC(SIZE)}
6872
6873 @item @emph{Arguments}:
6874 @multitable @columnfractions .15 .70
6875 @item @var{SIZE} @tab The type shall be @code{INTEGER(*)}.
6876 @end multitable
6877
6878 @item @emph{Return value}:
6879 The return value is of type @code{INTEGER(K)}, with @var{K} such that
6880 variables of type @code{INTEGER(K)} have the same size as
6881 C pointers (@code{sizeof(void *)}).
6882
6883 @item @emph{Example}:
6884 The following example demonstrates the use of @code{MALLOC} and
6885 @code{FREE} with Cray pointers. This example is intended to run on
6886 32-bit systems, where the default integer kind is suitable to store
6887 pointers; on 64-bit systems, ptr_x would need to be declared as
6888 @code{integer(kind=8)}.
6889
6890 @smallexample
6891 program test_malloc
6892 integer i
6893 integer ptr_x
6894 real*8 x(*), z
6895 pointer(ptr_x,x)
6896
6897 ptr_x = malloc(20*8)
6898 do i = 1, 20
6899 x(i) = sqrt(1.0d0 / i)
6900 end do
6901 z = 0
6902 do i = 1, 20
6903 z = z + x(i)
6904 print *, z
6905 end do
6906 call free(ptr_x)
6907 end program test_malloc
6908 @end smallexample
6909
6910 @item @emph{See also}:
6911 @ref{FREE}
6912 @end table
6913
6914
6915
6916 @node MATMUL
6917 @section @code{MATMUL} --- matrix multiplication
6918 @fnindex MATMUL
6919 @cindex matrix multiplication
6920 @cindex product, matrix
6921
6922 @table @asis
6923 @item @emph{Description}:
6924 Performs a matrix multiplication on numeric or logical arguments.
6925
6926 @item @emph{Standard}:
6927 F95 and later
6928
6929 @item @emph{Class}:
6930 Transformational function
6931
6932 @item @emph{Syntax}:
6933 @code{RESULT = MATMUL(MATRIX_A, MATRIX_B)}
6934
6935 @item @emph{Arguments}:
6936 @multitable @columnfractions .15 .70
6937 @item @var{MATRIX_A} @tab An array of @code{INTEGER(*)},
6938 @code{REAL(*)}, @code{COMPLEX(*)}, or
6939 @code{LOGICAL(*)} type, with a rank of
6940 one or two.
6941 @item @var{MATRIX_B} @tab An array of @code{INTEGER(*)},
6942 @code{REAL(*)}, or @code{COMPLEX(*)} type if
6943 @var{MATRIX_A} is of a numeric type;
6944 otherwise, an array of @code{LOGICAL(*)}
6945 type. The rank shall be one or two, and the
6946 first (or only) dimension of @var{MATRIX_B}
6947 shall be equal to the last (or only)
6948 dimension of @var{MATRIX_A}.
6949 @end multitable
6950
6951 @item @emph{Return value}:
6952 The matrix product of @var{MATRIX_A} and @var{MATRIX_B}. The type and
6953 kind of the result follow the usual type and kind promotion rules, as
6954 for the @code{*} or @code{.AND.} operators.
6955
6956 @item @emph{See also}:
6957 @end table
6958
6959
6960
6961 @node MAX
6962 @section @code{MAX} --- Maximum value of an argument list
6963 @fnindex MAX
6964 @fnindex MAX0
6965 @fnindex AMAX0
6966 @fnindex MAX1
6967 @fnindex AMAX1
6968 @fnindex DMAX1
6969 @cindex maximum value
6970
6971 @table @asis
6972 @item @emph{Description}:
6973 Returns the argument with the largest (most positive) value.
6974
6975 @item @emph{Standard}:
6976 F77 and later
6977
6978 @item @emph{Class}:
6979 Elemental function
6980
6981 @item @emph{Syntax}:
6982 @code{RESULT = MAX(A1, A2 [, A3 [, ...]])}
6983
6984 @item @emph{Arguments}:
6985 @multitable @columnfractions .15 .70
6986 @item @var{A1} @tab The type shall be @code{INTEGER(*)} or
6987 @code{REAL(*)}.
6988 @item @var{A2}, @var{A3}, ... @tab An expression of the same type and kind
6989 as @var{A1}. (As a GNU extension,
6990 arguments of different kinds are
6991 permitted.)
6992 @end multitable
6993
6994 @item @emph{Return value}:
6995 The return value corresponds to the maximum value among the arguments,
6996 and has the same type and kind as the first argument.
6997
6998 @item @emph{Specific names}:
6999 @multitable @columnfractions .20 .20 .20 .25
7000 @item Name @tab Argument @tab Return type @tab Standard
7001 @item @code{MAX0(I)} @tab @code{INTEGER(4) I} @tab @code{INTEGER(4)} @tab F77 and later
7002 @item @code{AMAX0(I)} @tab @code{INTEGER(4) I} @tab @code{REAL(MAX(X))} @tab F77 and later
7003 @item @code{MAX1(X)} @tab @code{REAL(*) X} @tab @code{INT(MAX(X))} @tab F77 and later
7004 @item @code{AMAX1(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab F77 and later
7005 @item @code{DMAX1(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F77 and later
7006 @end multitable
7007
7008 @item @emph{See also}:
7009 @ref{MAXLOC} @ref{MAXVAL}, @ref{MIN}
7010
7011 @end table
7012
7013
7014
7015 @node MAXEXPONENT
7016 @section @code{MAXEXPONENT} --- Maximum exponent of a real kind
7017 @fnindex MAXEXPONENT
7018 @cindex model representation, maximum exponent
7019
7020 @table @asis
7021 @item @emph{Description}:
7022 @code{MAXEXPONENT(X)} returns the maximum exponent in the model of the
7023 type of @code{X}.
7024
7025 @item @emph{Standard}:
7026 F95 and later
7027
7028 @item @emph{Class}:
7029 Inquiry function
7030
7031 @item @emph{Syntax}:
7032 @code{RESULT = MAXEXPONENT(X)}
7033
7034 @item @emph{Arguments}:
7035 @multitable @columnfractions .15 .70
7036 @item @var{X} @tab Shall be of type @code{REAL}.
7037 @end multitable
7038
7039 @item @emph{Return value}:
7040 The return value is of type @code{INTEGER} and of the default integer
7041 kind.
7042
7043 @item @emph{Example}:
7044 @smallexample
7045 program exponents
7046 real(kind=4) :: x
7047 real(kind=8) :: y
7048
7049 print *, minexponent(x), maxexponent(x)
7050 print *, minexponent(y), maxexponent(y)
7051 end program exponents
7052 @end smallexample
7053 @end table
7054
7055
7056
7057 @node MAXLOC
7058 @section @code{MAXLOC} --- Location of the maximum value within an array
7059 @fnindex MAXLOC
7060 @cindex array, location of maximum element
7061
7062 @table @asis
7063 @item @emph{Description}:
7064 Determines the location of the element in the array with the maximum
7065 value, or, if the @var{DIM} argument is supplied, determines the
7066 locations of the maximum element along each row of the array in the
7067 @var{DIM} direction. If @var{MASK} is present, only the elements for
7068 which @var{MASK} is @code{.TRUE.} are considered. If more than one
7069 element in the array has the maximum value, the location returned is
7070 that of the first such element in array element order. If the array has
7071 zero size, or all of the elements of @var{MASK} are @code{.FALSE.}, then
7072 the result is an array of zeroes. Similarly, if @var{DIM} is supplied
7073 and all of the elements of @var{MASK} along a given row are zero, the
7074 result value for that row is zero.
7075
7076 @item @emph{Standard}:
7077 F95 and later
7078
7079 @item @emph{Class}:
7080 Transformational function
7081
7082 @item @emph{Syntax}:
7083 @multitable @columnfractions .80
7084 @item @code{RESULT = MAXLOC(ARRAY, DIM [, MASK])}
7085 @item @code{RESULT = MAXLOC(ARRAY [, MASK])}
7086 @end multitable
7087
7088 @item @emph{Arguments}:
7089 @multitable @columnfractions .15 .70
7090 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER(*)},
7091 @code{REAL(*)}, or @code{CHARACTER(*)}.
7092 @item @var{DIM} @tab (Optional) Shall be a scalar of type
7093 @code{INTEGER(*)}, with a value between one
7094 and the rank of @var{ARRAY}, inclusive. It
7095 may not be an optional dummy argument.
7096 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL(*)},
7097 and conformable with @var{ARRAY}.
7098 @end multitable
7099
7100 @item @emph{Return value}:
7101 If @var{DIM} is absent, the result is a rank-one array with a length
7102 equal to the rank of @var{ARRAY}. If @var{DIM} is present, the result
7103 is an array with a rank one less than the rank of @var{ARRAY}, and a
7104 size corresponding to the size of @var{ARRAY} with the @var{DIM}
7105 dimension removed. If @var{DIM} is present and @var{ARRAY} has a rank
7106 of one, the result is a scalar. In all cases, the result is of default
7107 @code{INTEGER} type.
7108
7109 @item @emph{See also}:
7110 @ref{MAX}, @ref{MAXVAL}
7111
7112 @end table
7113
7114
7115
7116 @node MAXVAL
7117 @section @code{MAXVAL} --- Maximum value of an array
7118 @fnindex MAXVAL
7119 @cindex array, maximum value
7120 @cindex maximum value
7121
7122 @table @asis
7123 @item @emph{Description}:
7124 Determines the maximum value of the elements in an array value, or, if
7125 the @var{DIM} argument is supplied, determines the maximum value along
7126 each row of the array in the @var{DIM} direction. If @var{MASK} is
7127 present, only the elements for which @var{MASK} is @code{.TRUE.} are
7128 considered. If the array has zero size, or all of the elements of
7129 @var{MASK} are @code{.FALSE.}, then the result is the most negative
7130 number of the type and kind of @var{ARRAY} if @var{ARRAY} is numeric, or
7131 a string of nulls if @var{ARRAY} is of character type.
7132
7133 @item @emph{Standard}:
7134 F95 and later
7135
7136 @item @emph{Class}:
7137 Transformational function
7138
7139 @item @emph{Syntax}:
7140 @multitable @columnfractions .80
7141 @item @code{RESULT = MAXVAL(ARRAY, DIM [, MASK])}
7142 @item @code{RESULT = MAXVAL(ARRAY [, MASK])}
7143 @end multitable
7144
7145 @item @emph{Arguments}:
7146 @multitable @columnfractions .15 .70
7147 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER(*)},
7148 @code{REAL(*)}, or @code{CHARACTER(*)}.
7149 @item @var{DIM} @tab (Optional) Shall be a scalar of type
7150 @code{INTEGER(*)}, with a value between one
7151 and the rank of @var{ARRAY}, inclusive. It
7152 may not be an optional dummy argument.
7153 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL(*)},
7154 and conformable with @var{ARRAY}.
7155 @end multitable
7156
7157 @item @emph{Return value}:
7158 If @var{DIM} is absent, or if @var{ARRAY} has a rank of one, the result
7159 is a scalar. If @var{DIM} is present, the result is an array with a
7160 rank one less than the rank of @var{ARRAY}, and a size corresponding to
7161 the size of @var{ARRAY} with the @var{DIM} dimension removed. In all
7162 cases, the result is of the same type and kind as @var{ARRAY}.
7163
7164 @item @emph{See also}:
7165 @ref{MAX}, @ref{MAXLOC}
7166 @end table
7167
7168
7169
7170 @node MCLOCK
7171 @section @code{MCLOCK} --- Time function
7172 @fnindex MCLOCK
7173 @cindex time, clock ticks
7174 @cindex clock ticks
7175
7176 @table @asis
7177 @item @emph{Description}:
7178 Returns the number of clock ticks since the start of the process, based
7179 on the UNIX function @code{clock(3)}.
7180
7181 This intrinsic is not fully portable, such as to systems with 32-bit
7182 @code{INTEGER} types but supporting times wider than 32 bits. Therefore,
7183 the values returned by this intrinsic might be, or become, negative, or
7184 numerically less than previous values, during a single run of the
7185 compiled program.
7186
7187 @item @emph{Standard}:
7188 GNU extension
7189
7190 @item @emph{Class}:
7191 Function
7192
7193 @item @emph{Syntax}:
7194 @code{RESULT = MCLOCK()}
7195
7196 @item @emph{Return value}:
7197 The return value is a scalar of type @code{INTEGER(4)}, equal to the
7198 number of clock ticks since the start of the process, or @code{-1} if
7199 the system does not support @code{clock(3)}.
7200
7201 @item @emph{See also}:
7202 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK}, @ref{TIME}
7203
7204 @end table
7205
7206
7207
7208 @node MCLOCK8
7209 @section @code{MCLOCK8} --- Time function (64-bit)
7210 @fnindex MCLOCK8
7211 @cindex time, clock ticks
7212 @cindex clock ticks
7213
7214 @table @asis
7215 @item @emph{Description}:
7216 Returns the number of clock ticks since the start of the process, based
7217 on the UNIX function @code{clock(3)}.
7218
7219 @emph{Warning:} this intrinsic does not increase the range of the timing
7220 values over that returned by @code{clock(3)}. On a system with a 32-bit
7221 @code{clock(3)}, @code{MCLOCK8()} will return a 32-bit value, even though
7222 it is converted to a 64-bit @code{INTEGER(8)} value. That means
7223 overflows of the 32-bit value can still occur. Therefore, the values
7224 returned by this intrinsic might be or become negative or numerically
7225 less than previous values during a single run of the compiled program.
7226
7227 @item @emph{Standard}:
7228 GNU extension
7229
7230 @item @emph{Class}:
7231 Function
7232
7233 @item @emph{Syntax}:
7234 @code{RESULT = MCLOCK8()}
7235
7236 @item @emph{Return value}:
7237 The return value is a scalar of type @code{INTEGER(8)}, equal to the
7238 number of clock ticks since the start of the process, or @code{-1} if
7239 the system does not support @code{clock(3)}.
7240
7241 @item @emph{See also}:
7242 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK}, @ref{TIME8}
7243
7244 @end table
7245
7246
7247
7248 @node MERGE
7249 @section @code{MERGE} --- Merge variables
7250 @fnindex MERGE
7251 @cindex array, merge arrays
7252 @cindex array, combine arrays
7253
7254 @table @asis
7255 @item @emph{Description}:
7256 Select values from two arrays according to a logical mask. The result
7257 is equal to @var{TSOURCE} if @var{MASK} is @code{.TRUE.}, or equal to
7258 @var{FSOURCE} if it is @code{.FALSE.}.
7259
7260 @item @emph{Standard}:
7261 F95 and later
7262
7263 @item @emph{Class}:
7264 Elemental function
7265
7266 @item @emph{Syntax}:
7267 @code{RESULT = MERGE(TSOURCE, FSOURCE, MASK)}
7268
7269 @item @emph{Arguments}:
7270 @multitable @columnfractions .15 .70
7271 @item @var{TSOURCE} @tab May be of any type.
7272 @item @var{FSOURCE} @tab Shall be of the same type and type parameters
7273 as @var{TSOURCE}.
7274 @item @var{MASK} @tab Shall be of type @code{LOGICAL(*)}.
7275 @end multitable
7276
7277 @item @emph{Return value}:
7278 The result is of the same type and type parameters as @var{TSOURCE}.
7279
7280 @end table
7281
7282
7283
7284 @node MIN
7285 @section @code{MIN} --- Minimum value of an argument list
7286 @fnindex MIN
7287 @fnindex MIN0
7288 @fnindex AMIN0
7289 @fnindex MIN1
7290 @fnindex AMIN1
7291 @fnindex DMIN1
7292 @cindex minimum value
7293
7294 @table @asis
7295 @item @emph{Description}:
7296 Returns the argument with the smallest (most negative) value.
7297
7298 @item @emph{Standard}:
7299 F77 and later
7300
7301 @item @emph{Class}:
7302 Elemental function
7303
7304 @item @emph{Syntax}:
7305 @code{RESULT = MIN(A1, A2 [, A3, ...])}
7306
7307 @item @emph{Arguments}:
7308 @multitable @columnfractions .15 .70
7309 @item @var{A1} @tab The type shall be @code{INTEGER(*)} or
7310 @code{REAL(*)}.
7311 @item @var{A2}, @var{A3}, ... @tab An expression of the same type and kind
7312 as @var{A1}. (As a GNU extension,
7313 arguments of different kinds are
7314 permitted.)
7315 @end multitable
7316
7317 @item @emph{Return value}:
7318 The return value corresponds to the maximum value among the arguments,
7319 and has the same type and kind as the first argument.
7320
7321 @item @emph{Specific names}:
7322 @multitable @columnfractions .20 .20 .20 .25
7323 @item Name @tab Argument @tab Return type @tab Standard
7324 @item @code{MIN0(I)} @tab @code{INTEGER(4) I} @tab @code{INTEGER(4)} @tab F77 and later
7325 @item @code{AMIN0(I)} @tab @code{INTEGER(4) I} @tab @code{REAL(MIN(X))} @tab F77 and later
7326 @item @code{MIN1(X)} @tab @code{REAL(*) X} @tab @code{INT(MIN(X))} @tab F77 and later
7327 @item @code{AMIN1(X)} @tab @code{REAL(4) X} @tab @code{REAL(4)} @tab F77 and later
7328 @item @code{DMIN1(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F77 and later
7329 @end multitable
7330
7331 @item @emph{See also}:
7332 @ref{MAX}, @ref{MINLOC}, @ref{MINVAL}
7333 @end table
7334
7335
7336
7337 @node MINEXPONENT
7338 @section @code{MINEXPONENT} --- Minimum exponent of a real kind
7339 @fnindex MINEXPONENT
7340 @cindex model representation, minimum exponent
7341
7342 @table @asis
7343 @item @emph{Description}:
7344 @code{MINEXPONENT(X)} returns the minimum exponent in the model of the
7345 type of @code{X}.
7346
7347 @item @emph{Standard}:
7348 F95 and later
7349
7350 @item @emph{Class}:
7351 Inquiry function
7352
7353 @item @emph{Syntax}:
7354 @code{RESULT = MINEXPONENT(X)}
7355
7356 @item @emph{Arguments}:
7357 @multitable @columnfractions .15 .70
7358 @item @var{X} @tab Shall be of type @code{REAL}.
7359 @end multitable
7360
7361 @item @emph{Return value}:
7362 The return value is of type @code{INTEGER} and of the default integer
7363 kind.
7364
7365 @item @emph{Example}:
7366 See @code{MAXEXPONENT} for an example.
7367 @end table
7368
7369
7370
7371 @node MINLOC
7372 @section @code{MINLOC} --- Location of the minimum value within an array
7373 @fnindex MINLOC
7374 @cindex array, location of minimum element
7375
7376 @table @asis
7377 @item @emph{Description}:
7378 Determines the location of the element in the array with the minimum
7379 value, or, if the @var{DIM} argument is supplied, determines the
7380 locations of the minimum element along each row of the array in the
7381 @var{DIM} direction. If @var{MASK} is present, only the elements for
7382 which @var{MASK} is @code{.TRUE.} are considered. If more than one
7383 element in the array has the minimum value, the location returned is
7384 that of the first such element in array element order. If the array has
7385 zero size, or all of the elements of @var{MASK} are @code{.FALSE.}, then
7386 the result is an array of zeroes. Similarly, if @var{DIM} is supplied
7387 and all of the elements of @var{MASK} along a given row are zero, the
7388 result value for that row is zero.
7389
7390 @item @emph{Standard}:
7391 F95 and later
7392
7393 @item @emph{Class}:
7394 Transformational function
7395
7396 @item @emph{Syntax}:
7397 @multitable @columnfractions .80
7398 @item @code{RESULT = MINLOC(ARRAY, DIM [, MASK])}
7399 @item @code{RESULT = MINLOC(ARRAY [, MASK])}
7400 @end multitable
7401
7402 @item @emph{Arguments}:
7403 @multitable @columnfractions .15 .70
7404 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER(*)},
7405 @code{REAL(*)}, or @code{CHARACTER(*)}.
7406 @item @var{DIM} @tab (Optional) Shall be a scalar of type
7407 @code{INTEGER(*)}, with a value between one
7408 and the rank of @var{ARRAY}, inclusive. It
7409 may not be an optional dummy argument.
7410 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL(*)},
7411 and conformable with @var{ARRAY}.
7412 @end multitable
7413
7414 @item @emph{Return value}:
7415 If @var{DIM} is absent, the result is a rank-one array with a length
7416 equal to the rank of @var{ARRAY}. If @var{DIM} is present, the result
7417 is an array with a rank one less than the rank of @var{ARRAY}, and a
7418 size corresponding to the size of @var{ARRAY} with the @var{DIM}
7419 dimension removed. If @var{DIM} is present and @var{ARRAY} has a rank
7420 of one, the result is a scalar. In all cases, the result is of default
7421 @code{INTEGER} type.
7422
7423 @item @emph{See also}:
7424 @ref{MIN}, @ref{MINVAL}
7425
7426 @end table
7427
7428
7429
7430 @node MINVAL
7431 @section @code{MINVAL} --- Minimum value of an array
7432 @fnindex MINVAL
7433 @cindex array, minimum value
7434 @cindex minimum value
7435
7436 @table @asis
7437 @item @emph{Description}:
7438 Determines the minimum value of the elements in an array value, or, if
7439 the @var{DIM} argument is supplied, determines the minimum value along
7440 each row of the array in the @var{DIM} direction. If @var{MASK} is
7441 present, only the elements for which @var{MASK} is @code{.TRUE.} are
7442 considered. If the array has zero size, or all of the elements of
7443 @var{MASK} are @code{.FALSE.}, then the result is @code{HUGE(ARRAY)} if
7444 @var{ARRAY} is numeric, or a string of @code{CHAR(255)} characters if
7445 @var{ARRAY} is of character type.
7446
7447 @item @emph{Standard}:
7448 F95 and later
7449
7450 @item @emph{Class}:
7451 Transformational function
7452
7453 @item @emph{Syntax}:
7454 @multitable @columnfractions .80
7455 @item @code{RESULT = MINVAL(ARRAY, DIM [, MASK])}
7456 @item @code{RESULT = MINVAL(ARRAY [, MASK])}
7457 @end multitable
7458
7459 @item @emph{Arguments}:
7460 @multitable @columnfractions .15 .70
7461 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER(*)},
7462 @code{REAL(*)}, or @code{CHARACTER(*)}.
7463 @item @var{DIM} @tab (Optional) Shall be a scalar of type
7464 @code{INTEGER(*)}, with a value between one
7465 and the rank of @var{ARRAY}, inclusive. It
7466 may not be an optional dummy argument.
7467 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL(*)},
7468 and conformable with @var{ARRAY}.
7469 @end multitable
7470
7471 @item @emph{Return value}:
7472 If @var{DIM} is absent, or if @var{ARRAY} has a rank of one, the result
7473 is a scalar. If @var{DIM} is present, the result is an array with a
7474 rank one less than the rank of @var{ARRAY}, and a size corresponding to
7475 the size of @var{ARRAY} with the @var{DIM} dimension removed. In all
7476 cases, the result is of the same type and kind as @var{ARRAY}.
7477
7478 @item @emph{See also}:
7479 @ref{MIN}, @ref{MINLOC}
7480
7481 @end table
7482
7483
7484
7485 @node MOD
7486 @section @code{MOD} --- Remainder function
7487 @fnindex MOD
7488 @fnindex AMOD
7489 @fnindex DMOD
7490 @cindex remainder
7491 @cindex division, remainder
7492
7493 @table @asis
7494 @item @emph{Description}:
7495 @code{MOD(A,P)} computes the remainder of the division of A by P. It is
7496 calculated as @code{A - (INT(A/P) * P)}.
7497
7498 @item @emph{Standard}:
7499 F77 and later
7500
7501 @item @emph{Class}:
7502 Elemental function
7503
7504 @item @emph{Syntax}:
7505 @code{RESULT = MOD(A, P)}
7506
7507 @item @emph{Arguments}:
7508 @multitable @columnfractions .15 .70
7509 @item @var{A} @tab Shall be a scalar of type @code{INTEGER} or @code{REAL}
7510 @item @var{P} @tab Shall be a scalar of the same type as @var{A} and not
7511 equal to zero
7512 @end multitable
7513
7514 @item @emph{Return value}:
7515 The kind of the return value is the result of cross-promoting
7516 the kinds of the arguments.
7517
7518 @item @emph{Example}:
7519 @smallexample
7520 program test_mod
7521 print *, mod(17,3)
7522 print *, mod(17.5,5.5)
7523 print *, mod(17.5d0,5.5)
7524 print *, mod(17.5,5.5d0)
7525
7526 print *, mod(-17,3)
7527 print *, mod(-17.5,5.5)
7528 print *, mod(-17.5d0,5.5)
7529 print *, mod(-17.5,5.5d0)
7530
7531 print *, mod(17,-3)
7532 print *, mod(17.5,-5.5)
7533 print *, mod(17.5d0,-5.5)
7534 print *, mod(17.5,-5.5d0)
7535 end program test_mod
7536 @end smallexample
7537
7538 @item @emph{Specific names}:
7539 @multitable @columnfractions .20 .20 .20 .25
7540 @item Name @tab Arguments @tab Return type @tab Standard
7541 @item @code{AMOD(A,P)} @tab @code{REAL(4)} @tab @code{REAL(4)} @tab F95 and later
7542 @item @code{DMOD(A,P)} @tab @code{REAL(8)} @tab @code{REAL(8)} @tab F95 and later
7543 @end multitable
7544 @end table
7545
7546
7547
7548 @node MODULO
7549 @section @code{MODULO} --- Modulo function
7550 @fnindex MODULO
7551 @cindex modulo
7552 @cindex division, modulo
7553
7554 @table @asis
7555 @item @emph{Description}:
7556 @code{MODULO(A,P)} computes the @var{A} modulo @var{P}.
7557
7558 @item @emph{Standard}:
7559 F95 and later
7560
7561 @item @emph{Class}:
7562 Elemental function
7563
7564 @item @emph{Syntax}:
7565 @code{RESULT = MODULO(A, P)}
7566
7567 @item @emph{Arguments}:
7568 @multitable @columnfractions .15 .70
7569 @item @var{A} @tab Shall be a scalar of type @code{INTEGER} or @code{REAL}
7570 @item @var{P} @tab Shall be a scalar of the same type and kind as @var{A}
7571 @end multitable
7572
7573 @item @emph{Return value}:
7574 The type and kind of the result are those of the arguments.
7575 @table @asis
7576 @item If @var{A} and @var{P} are of type @code{INTEGER}:
7577 @code{MODULO(A,P)} has the value @var{R} such that @code{A=Q*P+R}, where
7578 @var{Q} is an integer and @var{R} is between 0 (inclusive) and @var{P}
7579 (exclusive).
7580 @item If @var{A} and @var{P} are of type @code{REAL}:
7581 @code{MODULO(A,P)} has the value of @code{A - FLOOR (A / P) * P}.
7582 @end table
7583 In all cases, if @var{P} is zero the result is processor-dependent.
7584
7585 @item @emph{Example}:
7586 @smallexample
7587 program test_modulo
7588 print *, modulo(17,3)
7589 print *, modulo(17.5,5.5)
7590
7591 print *, modulo(-17,3)
7592 print *, modulo(-17.5,5.5)
7593
7594 print *, modulo(17,-3)
7595 print *, modulo(17.5,-5.5)
7596 end program
7597 @end smallexample
7598
7599 @end table
7600
7601
7602
7603 @node MOVE_ALLOC
7604 @section @code{MOVE_ALLOC} --- Move allocation from one object to another
7605 @fnindex MOVE_ALLOC
7606 @cindex moving allocation
7607 @cindex allocation, moving
7608
7609 @table @asis
7610 @item @emph{Description}:
7611 @code{MOVE_ALLOC(SRC, DEST)} moves the allocation from @var{SRC} to
7612 @var{DEST}. @var{SRC} will become deallocated in the process.
7613
7614 @item @emph{Standard}:
7615 F2003 and later
7616
7617 @item @emph{Class}:
7618 Subroutine
7619
7620 @item @emph{Syntax}:
7621 @code{CALL MOVE_ALLOC(SRC, DEST)}
7622
7623 @item @emph{Arguments}:
7624 @multitable @columnfractions .15 .70
7625 @item @var{SRC} @tab @code{ALLOCATABLE}, @code{INTENT(INOUT)}, may be
7626 of any type and kind.
7627 @item @var{DEST} @tab @code{ALLOCATABLE}, @code{INTENT(OUT)}, shall be
7628 of the same type, kind and rank as @var{SRC}
7629 @end multitable
7630
7631 @item @emph{Return value}:
7632 None
7633
7634 @item @emph{Example}:
7635 @smallexample
7636 program test_move_alloc
7637 integer, allocatable :: a(:), b(:)
7638
7639 allocate(a(3))
7640 a = [ 1, 2, 3 ]
7641 call move_alloc(a, b)
7642 print *, allocated(a), allocated(b)
7643 print *, b
7644 end program test_move_alloc
7645 @end smallexample
7646 @end table
7647
7648
7649
7650 @node MVBITS
7651 @section @code{MVBITS} --- Move bits from one integer to another
7652 @fnindex MVBITS
7653 @cindex bits, move
7654
7655 @table @asis
7656 @item @emph{Description}:
7657 Moves @var{LEN} bits from positions @var{FROMPOS} through
7658 @code{FROMPOS+LEN-1} of @var{FROM} to positions @var{TOPOS} through
7659 @code{TOPOS+LEN-1} of @var{TO}. The portion of argument @var{TO} not
7660 affected by the movement of bits is unchanged. The values of
7661 @code{FROMPOS+LEN-1} and @code{TOPOS+LEN-1} must be less than
7662 @code{BIT_SIZE(FROM)}.
7663
7664 @item @emph{Standard}:
7665 F95 and later
7666
7667 @item @emph{Class}:
7668 Elemental subroutine
7669
7670 @item @emph{Syntax}:
7671 @code{CALL MVBITS(FROM, FROMPOS, LEN, TO, TOPOS)}
7672
7673 @item @emph{Arguments}:
7674 @multitable @columnfractions .15 .70
7675 @item @var{FROM} @tab The type shall be @code{INTEGER(*)}.
7676 @item @var{FROMPOS} @tab The type shall be @code{INTEGER(*)}.
7677 @item @var{LEN} @tab The type shall be @code{INTEGER(*)}.
7678 @item @var{TO} @tab The type shall be @code{INTEGER(*)}, of the
7679 same kind as @var{FROM}.
7680 @item @var{TOPOS} @tab The type shall be @code{INTEGER(*)}.
7681 @end multitable
7682
7683 @item @emph{See also}:
7684 @ref{IBCLR}, @ref{IBSET}, @ref{IBITS}, @ref{IAND}, @ref{IOR}, @ref{IEOR}
7685 @end table
7686
7687
7688
7689 @node NEAREST
7690 @section @code{NEAREST} --- Nearest representable number
7691 @fnindex NEAREST
7692 @cindex real number, nearest different
7693 @cindex floating point, nearest different
7694
7695 @table @asis
7696 @item @emph{Description}:
7697 @code{NEAREST(X, S)} returns the processor-representable number nearest
7698 to @code{X} in the direction indicated by the sign of @code{S}.
7699
7700 @item @emph{Standard}:
7701 F95 and later
7702
7703 @item @emph{Class}:
7704 Elemental function
7705
7706 @item @emph{Syntax}:
7707 @code{RESULT = NEAREST(X, S)}
7708
7709 @item @emph{Arguments}:
7710 @multitable @columnfractions .15 .70
7711 @item @var{X} @tab Shall be of type @code{REAL}.
7712 @item @var{S} @tab (Optional) shall be of type @code{REAL} and
7713 not equal to zero.
7714 @end multitable
7715
7716 @item @emph{Return value}:
7717 The return value is of the same type as @code{X}. If @code{S} is
7718 positive, @code{NEAREST} returns the processor-representable number
7719 greater than @code{X} and nearest to it. If @code{S} is negative,
7720 @code{NEAREST} returns the processor-representable number smaller than
7721 @code{X} and nearest to it.
7722
7723 @item @emph{Example}:
7724 @smallexample
7725 program test_nearest
7726 real :: x, y
7727 x = nearest(42.0, 1.0)
7728 y = nearest(42.0, -1.0)
7729 write (*,"(3(G20.15))") x, y, x - y
7730 end program test_nearest
7731 @end smallexample
7732 @end table
7733
7734
7735
7736 @node NEW_LINE
7737 @section @code{NEW_LINE} --- New line character
7738 @fnindex NEW_LINE
7739 @cindex newline
7740 @cindex output, newline
7741
7742 @table @asis
7743 @item @emph{Description}:
7744 @code{NEW_LINE(C)} returns the new-line character.
7745
7746 @item @emph{Standard}:
7747 F2003 and later
7748
7749 @item @emph{Class}:
7750 Inquiry function
7751
7752 @item @emph{Syntax}:
7753 @code{RESULT = NEW_LINE(C)}
7754
7755 @item @emph{Arguments}:
7756 @multitable @columnfractions .15 .70
7757 @item @var{C} @tab The argument shall be a scalar or array of the
7758 type @code{CHARACTER}.
7759 @end multitable
7760
7761 @item @emph{Return value}:
7762 Returns a @var{CHARACTER} scalar of length one with the new-line character of
7763 the same kind as parameter @var{C}.
7764
7765 @item @emph{Example}:
7766 @smallexample
7767 program newline
7768 implicit none
7769 write(*,'(A)') 'This is record 1.'//NEW_LINE('A')//'This is record 2.'
7770 end program newline
7771 @end smallexample
7772 @end table
7773
7774
7775
7776 @node NINT
7777 @section @code{NINT} --- Nearest whole number
7778 @fnindex NINT
7779 @fnindex IDNINT
7780 @cindex rounding, nearest whole number
7781
7782 @table @asis
7783 @item @emph{Description}:
7784 @code{NINT(X)} rounds its argument to the nearest whole number.
7785
7786 @item @emph{Standard}:
7787 F77 and later
7788
7789 @item @emph{Class}:
7790 Elemental function
7791
7792 @item @emph{Syntax}:
7793 @code{RESULT = NINT(X)}
7794
7795 @item @emph{Arguments}:
7796 @multitable @columnfractions .15 .70
7797 @item @var{X} @tab The type of the argument shall be @code{REAL}.
7798 @end multitable
7799
7800 @item @emph{Return value}:
7801 Returns @var{A} with the fractional portion of its magnitude eliminated by
7802 rounding to the nearest whole number and with its sign preserved,
7803 converted to an @code{INTEGER} of the default kind.
7804
7805 @item @emph{Example}:
7806 @smallexample
7807 program test_nint
7808 real(4) x4
7809 real(8) x8
7810 x4 = 1.234E0_4
7811 x8 = 4.321_8
7812 print *, nint(x4), idnint(x8)
7813 end program test_nint
7814 @end smallexample
7815
7816 @item @emph{Specific names}:
7817 @multitable @columnfractions .25 .25 .25
7818 @item Name @tab Argument @tab Standard
7819 @item @code{IDNINT(X)} @tab @code{REAL(8)} @tab F95 and later
7820 @end multitable
7821
7822 @item @emph{See also}:
7823 @ref{CEILING}, @ref{FLOOR}
7824
7825 @end table
7826
7827
7828
7829 @node NOT
7830 @section @code{NOT} --- Logical negation
7831 @fnindex NOT
7832 @cindex bits, negate
7833 @cindex bitwise logical not
7834 @cindex logical not, bitwise
7835
7836 @table @asis
7837 @item @emph{Description}:
7838 @code{NOT} returns the bitwise boolean inverse of @var{I}.
7839
7840 @item @emph{Standard}:
7841 F95 and later
7842
7843 @item @emph{Class}:
7844 Elemental function
7845
7846 @item @emph{Syntax}:
7847 @code{RESULT = NOT(I)}
7848
7849 @item @emph{Arguments}:
7850 @multitable @columnfractions .15 .70
7851 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
7852 @end multitable
7853
7854 @item @emph{Return value}:
7855 The return type is @code{INTEGER(*)}, of the same kind as the
7856 argument.
7857
7858 @item @emph{See also}:
7859 @ref{IAND}, @ref{IEOR}, @ref{IOR}, @ref{IBITS}, @ref{IBSET}, @ref{IBCLR}
7860
7861 @end table
7862
7863
7864
7865 @node NULL
7866 @section @code{NULL} --- Function that returns an disassociated pointer
7867 @fnindex NULL
7868 @cindex pointer, status
7869 @cindex pointer, disassociated
7870
7871 @table @asis
7872 @item @emph{Description}:
7873 Returns a disassociated pointer.
7874
7875 If @var{MOLD} is present, a dissassociated pointer of the same type is
7876 returned, otherwise the type is determined by context.
7877
7878 In Fortran 95, @var{MOLD} is optional. Please note that F2003 includes
7879 cases where it is required.
7880
7881 @item @emph{Standard}:
7882 F95 and later
7883
7884 @item @emph{Class}:
7885 Transformational function
7886
7887 @item @emph{Syntax}:
7888 @code{PTR => NULL([MOLD])}
7889
7890 @item @emph{Arguments}:
7891 @multitable @columnfractions .15 .70
7892 @item @var{MOLD} @tab (Optional) shall be a pointer of any association
7893 status and of any type.
7894 @end multitable
7895
7896 @item @emph{Return value}:
7897 A disassociated pointer.
7898
7899 @item @emph{Example}:
7900 @smallexample
7901 REAL, POINTER, DIMENSION(:) :: VEC => NULL ()
7902 @end smallexample
7903
7904 @item @emph{See also}:
7905 @ref{ASSOCIATED}
7906 @end table
7907
7908
7909
7910 @node OR
7911 @section @code{OR} --- Bitwise logical OR
7912 @fnindex OR
7913 @cindex bitwise logical or
7914 @cindex logical or, bitwise
7915
7916 @table @asis
7917 @item @emph{Description}:
7918 Bitwise logical @code{OR}.
7919
7920 This intrinsic routine is provided for backwards compatibility with
7921 GNU Fortran 77. For integer arguments, programmers should consider
7922 the use of the @ref{IOR} intrinsic defined by the Fortran standard.
7923
7924 @item @emph{Standard}:
7925 GNU extension
7926
7927 @item @emph{Class}:
7928 Function
7929
7930 @item @emph{Syntax}:
7931 @code{RESULT = OR(X, Y)}
7932
7933 @item @emph{Arguments}:
7934 @multitable @columnfractions .15 .70
7935 @item @var{X} @tab The type shall be either @code{INTEGER(*)} or @code{LOGICAL}.
7936 @item @var{Y} @tab The type shall be either @code{INTEGER(*)} or @code{LOGICAL}.
7937 @end multitable
7938
7939 @item @emph{Return value}:
7940 The return type is either @code{INTEGER(*)} or @code{LOGICAL}
7941 after cross-promotion of the arguments.
7942
7943 @item @emph{Example}:
7944 @smallexample
7945 PROGRAM test_or
7946 LOGICAL :: T = .TRUE., F = .FALSE.
7947 INTEGER :: a, b
7948 DATA a / Z'F' /, b / Z'3' /
7949
7950 WRITE (*,*) OR(T, T), OR(T, F), OR(F, T), OR(F, F)
7951 WRITE (*,*) OR(a, b)
7952 END PROGRAM
7953 @end smallexample
7954
7955 @item @emph{See also}:
7956 F95 elemental function: @ref{IOR}
7957 @end table
7958
7959
7960
7961 @node PACK
7962 @section @code{PACK} --- Pack an array into an array of rank one
7963 @fnindex PACK
7964 @cindex array, packing
7965 @cindex array, reduce dimension
7966 @cindex array, gather elements
7967
7968 @table @asis
7969 @item @emph{Description}:
7970 Stores the elements of @var{ARRAY} in an array of rank one.
7971
7972 The beginning of the resulting array is made up of elements whose @var{MASK}
7973 equals @code{TRUE}. Afterwards, positions are filled with elements taken from
7974 @var{VECTOR}.
7975
7976 @item @emph{Standard}:
7977 F95 and later
7978
7979 @item @emph{Class}:
7980 Transformational function
7981
7982 @item @emph{Syntax}:
7983 @code{RESULT = PACK(ARRAY, MASK[,VECTOR]}
7984
7985 @item @emph{Arguments}:
7986 @multitable @columnfractions .15 .70
7987 @item @var{ARRAY} @tab Shall be an array of any type.
7988 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL} and
7989 of the same size as @var{ARRAY}. Alternatively, it may be a @code{LOGICAL}
7990 scalar.
7991 @item @var{VECTOR} @tab (Optional) shall be an array of the same type
7992 as @var{ARRAY} and of rank one. If present, the number of elements in
7993 @var{VECTOR} shall be equal to or greater than the number of true elements
7994 in @var{MASK}. If @var{MASK} is scalar, the number of elements in
7995 @var{VECTOR} shall be equal to or greater than the number of elements in
7996 @var{ARRAY}.
7997 @end multitable
7998
7999 @item @emph{Return value}:
8000 The result is an array of rank one and the same type as that of @var{ARRAY}.
8001 If @var{VECTOR} is present, the result size is that of @var{VECTOR}, the
8002 number of @code{TRUE} values in @var{MASK} otherwise.
8003
8004 @item @emph{Example}:
8005 Gathering nonzero elements from an array:
8006 @smallexample
8007 PROGRAM test_pack_1
8008 INTEGER :: m(6)
8009 m = (/ 1, 0, 0, 0, 5, 0 /)
8010 WRITE(*, FMT="(6(I0, ' '))") pack(m, m /= 0) ! "1 5"
8011 END PROGRAM
8012 @end smallexample
8013
8014 Gathering nonzero elements from an array and appending elements from @var{VECTOR}:
8015 @smallexample
8016 PROGRAM test_pack_2
8017 INTEGER :: m(4)
8018 m = (/ 1, 0, 0, 2 /)
8019 WRITE(*, FMT="(4(I0, ' '))") pack(m, m /= 0, (/ 0, 0, 3, 4 /)) ! "1 2 3 4"
8020 END PROGRAM
8021 @end smallexample
8022
8023 @item @emph{See also}:
8024 @ref{UNPACK}
8025 @end table
8026
8027
8028
8029 @node PERROR
8030 @section @code{PERROR} --- Print system error message
8031 @fnindex PERROR
8032 @cindex system, error handling
8033
8034 @table @asis
8035 @item @emph{Description}:
8036 Prints (on the C @code{stderr} stream) a newline-terminated error
8037 message corresponding to the last system error. This is prefixed by
8038 @var{STRING}, a colon and a space. See @code{perror(3)}.
8039
8040 @item @emph{Standard}:
8041 GNU extension
8042
8043 @item @emph{Class}:
8044 Subroutine
8045
8046 @item @emph{Syntax}:
8047 @code{CALL PERROR(STRING)}
8048
8049 @item @emph{Arguments}:
8050 @multitable @columnfractions .15 .70
8051 @item @var{STRING} @tab A scalar of default @code{CHARACTER} type.
8052 @end multitable
8053
8054 @item @emph{See also}:
8055 @ref{IERRNO}
8056 @end table
8057
8058
8059
8060 @node PRECISION
8061 @section @code{PRECISION} --- Decimal precision of a real kind
8062 @fnindex PRECISION
8063 @cindex model representation, precision
8064
8065 @table @asis
8066 @item @emph{Description}:
8067 @code{PRECISION(X)} returns the decimal precision in the model of the
8068 type of @code{X}.
8069
8070 @item @emph{Standard}:
8071 F95 and later
8072
8073 @item @emph{Class}:
8074 Inquiry function
8075
8076 @item @emph{Syntax}:
8077 @code{RESULT = PRECISION(X)}
8078
8079 @item @emph{Arguments}:
8080 @multitable @columnfractions .15 .70
8081 @item @var{X} @tab Shall be of type @code{REAL} or @code{COMPLEX}.
8082 @end multitable
8083
8084 @item @emph{Return value}:
8085 The return value is of type @code{INTEGER} and of the default integer
8086 kind.
8087
8088 @item @emph{Example}:
8089 @smallexample
8090 program prec_and_range
8091 real(kind=4) :: x(2)
8092 complex(kind=8) :: y
8093
8094 print *, precision(x), range(x)
8095 print *, precision(y), range(y)
8096 end program prec_and_range
8097 @end smallexample
8098 @end table
8099
8100
8101
8102 @node PRESENT
8103 @section @code{PRESENT} --- Determine whether an optional dummy argument is specified
8104 @fnindex PRESENT
8105
8106 @table @asis
8107 @item @emph{Description}:
8108 Determines whether an optional dummy argument is present.
8109
8110 @item @emph{Standard}:
8111 F95 and later
8112
8113 @item @emph{Class}:
8114 Inquiry function
8115
8116 @item @emph{Syntax}:
8117 @code{RESULT = PRESENT(A)}
8118
8119 @item @emph{Arguments}:
8120 @multitable @columnfractions .15 .70
8121 @item @var{A} @tab May be of any type and may be a pointer, scalar or array
8122 value, or a dummy procedure. It shall be the name of an optional dummy argument
8123 accessible within the current subroutine or function.
8124 @end multitable
8125
8126 @item @emph{Return value}:
8127 Returns either @code{TRUE} if the optional argument @var{A} is present, or
8128 @code{FALSE} otherwise.
8129
8130 @item @emph{Example}:
8131 @smallexample
8132 PROGRAM test_present
8133 WRITE(*,*) f(), f(42) ! "F T"
8134 CONTAINS
8135 LOGICAL FUNCTION f(x)
8136 INTEGER, INTENT(IN), OPTIONAL :: x
8137 f = PRESENT(x)
8138 END FUNCTION
8139 END PROGRAM
8140 @end smallexample
8141 @end table
8142
8143
8144
8145 @node PRODUCT
8146 @section @code{PRODUCT} --- Product of array elements
8147 @fnindex PRODUCT
8148 @cindex array, product
8149 @cindex array, multiply elements
8150 @cindex array, conditionally multiply elements
8151 @cindex multiply array elements
8152
8153 @table @asis
8154 @item @emph{Description}:
8155 Multiplies the elements of @var{ARRAY} along dimension @var{DIM} if
8156 the corresponding element in @var{MASK} is @code{TRUE}.
8157
8158 @item @emph{Standard}:
8159 F95 and later
8160
8161 @item @emph{Class}:
8162 Transformational function
8163
8164 @item @emph{Syntax}:
8165 @code{RESULT = PRODUCT(ARRAY[, MASK])}
8166 @code{RESULT = PRODUCT(ARRAY, DIM[, MASK])}
8167
8168 @item @emph{Arguments}:
8169 @multitable @columnfractions .15 .70
8170 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER(*)},
8171 @code{REAL(*)} or @code{COMPLEX(*)}.
8172 @item @var{DIM} @tab (Optional) shall be a scalar of type
8173 @code{INTEGER} with a value in the range from 1 to n, where n
8174 equals the rank of @var{ARRAY}.
8175 @item @var{MASK} @tab (Optional) shall be of type @code{LOGICAL}
8176 and either be a scalar or an array of the same shape as @var{ARRAY}.
8177 @end multitable
8178
8179 @item @emph{Return value}:
8180 The result is of the same type as @var{ARRAY}.
8181
8182 If @var{DIM} is absent, a scalar with the product of all elements in
8183 @var{ARRAY} is returned. Otherwise, an array of rank n-1, where n equals
8184 the rank of @var{ARRAY}, and a shape similar to that of @var{ARRAY} with
8185 dimension @var{DIM} dropped is returned.
8186
8187
8188 @item @emph{Example}:
8189 @smallexample
8190 PROGRAM test_product
8191 INTEGER :: x(5) = (/ 1, 2, 3, 4 ,5 /)
8192 print *, PRODUCT(x) ! all elements, product = 120
8193 print *, PRODUCT(x, MASK=MOD(x, 2)==1) ! odd elements, product = 15
8194 END PROGRAM
8195 @end smallexample
8196
8197 @item @emph{See also}:
8198 @ref{SUM}
8199 @end table
8200
8201
8202
8203 @node RADIX
8204 @section @code{RADIX} --- Base of a model number
8205 @fnindex RADIX
8206 @cindex model representation, base
8207 @cindex model representation, radix
8208
8209 @table @asis
8210 @item @emph{Description}:
8211 @code{RADIX(X)} returns the base of the model representing the entity @var{X}.
8212
8213 @item @emph{Standard}:
8214 F95 and later
8215
8216 @item @emph{Class}:
8217 Inquiry function
8218
8219 @item @emph{Syntax}:
8220 @code{RESULT = RADIX(X)}
8221
8222 @item @emph{Arguments}:
8223 @multitable @columnfractions .15 .70
8224 @item @var{X} @tab Shall be of type @code{INTEGER} or @code{REAL}
8225 @end multitable
8226
8227 @item @emph{Return value}:
8228 The return value is a scalar of type @code{INTEGER} and of the default
8229 integer kind.
8230
8231 @item @emph{Example}:
8232 @smallexample
8233 program test_radix
8234 print *, "The radix for the default integer kind is", radix(0)
8235 print *, "The radix for the default real kind is", radix(0.0)
8236 end program test_radix
8237 @end smallexample
8238
8239 @end table
8240
8241
8242
8243 @node RAN
8244 @section @code{RAN} --- Real pseudo-random number
8245 @fnindex RAN
8246 @cindex random number generation
8247
8248 @table @asis
8249 @item @emph{Description}:
8250 For compatibility with HP FORTRAN 77/iX, the @code{RAN} intrinsic is
8251 provided as an alias for @code{RAND}. See @ref{RAND} for complete
8252 documentation.
8253
8254 @item @emph{Standard}:
8255 GNU extension
8256
8257 @item @emph{Class}:
8258 Function
8259
8260 @item @emph{See also}:
8261 @ref{RAND}, @ref{RANDOM_NUMBER}
8262 @end table
8263
8264
8265
8266 @node RAND
8267 @section @code{RAND} --- Real pseudo-random number
8268 @fnindex RAND
8269 @cindex random number generation
8270
8271 @table @asis
8272 @item @emph{Description}:
8273 @code{RAND(FLAG)} returns a pseudo-random number from a uniform
8274 distribution between 0 and 1. If @var{FLAG} is 0, the next number
8275 in the current sequence is returned; if @var{FLAG} is 1, the generator
8276 is restarted by @code{CALL SRAND(0)}; if @var{FLAG} has any other value,
8277 it is used as a new seed with @code{SRAND}.
8278
8279 This intrinsic routine is provided for backwards compatibility with
8280 GNU Fortran 77. It implements a simple modulo generator as provided
8281 by @command{g77}. For new code, one should consider the use of
8282 @ref{RANDOM_NUMBER} as it implements a superior algorithm.
8283
8284 @item @emph{Standard}:
8285 GNU extension
8286
8287 @item @emph{Class}:
8288 Function
8289
8290 @item @emph{Syntax}:
8291 @code{RESULT = RAND(FLAG)}
8292
8293 @item @emph{Arguments}:
8294 @multitable @columnfractions .15 .70
8295 @item @var{FLAG} @tab Shall be a scalar @code{INTEGER} of kind 4.
8296 @end multitable
8297
8298 @item @emph{Return value}:
8299 The return value is of @code{REAL} type and the default kind.
8300
8301 @item @emph{Example}:
8302 @smallexample
8303 program test_rand
8304 integer,parameter :: seed = 86456
8305
8306 call srand(seed)
8307 print *, rand(), rand(), rand(), rand()
8308 print *, rand(seed), rand(), rand(), rand()
8309 end program test_rand
8310 @end smallexample
8311
8312 @item @emph{See also}:
8313 @ref{SRAND}, @ref{RANDOM_NUMBER}
8314
8315 @end table
8316
8317
8318
8319 @node RANDOM_NUMBER
8320 @section @code{RANDOM_NUMBER} --- Pseudo-random number
8321 @fnindex RANDOM_NUMBER
8322 @cindex random number generation
8323
8324 @table @asis
8325 @item @emph{Description}:
8326 Returns a single pseudorandom number or an array of pseudorandom numbers
8327 from the uniform distribution over the range @math{ 0 \leq x < 1}.
8328
8329 The runtime-library implements George Marsaglia's KISS (Keep It Simple
8330 Stupid) random number generator (RNG). This RNG combines:
8331 @enumerate
8332 @item The congruential generator @math{x(n) = 69069 \cdot x(n-1) + 1327217885}
8333 with a period of @math{2^{32}},
8334 @item A 3-shift shift-register generator with a period of @math{2^{32} - 1},
8335 @item Two 16-bit multiply-with-carry generators with a period of
8336 @math{597273182964842497 > 2^{59}}.
8337 @end enumerate
8338 The overall period exceeds @math{2^{123}}.
8339
8340 Please note, this RNG is thread safe if used within OpenMP directives,
8341 i. e. its state will be consistent while called from multiple threads.
8342 However, the KISS generator does not create random numbers in parallel
8343 from multiple sources, but in sequence from a single source. If an
8344 OpenMP-enabled application heavily relies on random numbers, one should
8345 consider employing a dedicated parallel random number generator instead.
8346
8347 @item @emph{Standard}:
8348 F95 and later
8349
8350 @item @emph{Class}:
8351 Subroutine
8352
8353 @item @emph{Syntax}:
8354 @code{RANDOM_NUMBER(HARVEST)}
8355
8356 @item @emph{Arguments}:
8357 @multitable @columnfractions .15 .70
8358 @item @var{HARVEST} @tab Shall be a scalar or an array of type @code{REAL(*)}.
8359 @end multitable
8360
8361 @item @emph{Example}:
8362 @smallexample
8363 program test_random_number
8364 REAL :: r(5,5)
8365 CALL init_random_seed() ! see example of RANDOM_SEED
8366 CALL RANDOM_NUMBER(r)
8367 end program
8368 @end smallexample
8369
8370 @item @emph{See also}:
8371 @ref{RANDOM_SEED}
8372 @end table
8373
8374
8375
8376 @node RANDOM_SEED
8377 @section @code{RANDOM_SEED} --- Initialize a pseudo-random number sequence
8378 @fnindex RANDOM_SEED
8379 @cindex random number generation, seeding
8380 @cindex seeding a random number generator
8381
8382 @table @asis
8383 @item @emph{Description}:
8384 Restarts or queries the state of the pseudorandom number generator used by
8385 @code{RANDOM_NUMBER}.
8386
8387 If @code{RANDOM_SEED} is called without arguments, it is initialized to
8388 a default state. The example below shows how to initialize the random
8389 seed based on the system's time.
8390
8391 @item @emph{Standard}:
8392 F95 and later
8393
8394 @item @emph{Class}:
8395 Subroutine
8396
8397 @item @emph{Syntax}:
8398 @code{CALL RANDOM_SEED(SIZE, PUT, GET)}
8399
8400 @item @emph{Arguments}:
8401 @multitable @columnfractions .15 .70
8402 @item @var{SIZE} @tab (Optional) Shall be a scalar and of type default
8403 @code{INTEGER}, with @code{INTENT(OUT)}. It specifies the minimum size
8404 of the arrays used with the @var{PUT} and @var{GET} arguments.
8405 @item @var{PUT} @tab (Optional) Shall be an array of type default
8406 @code{INTEGER} and rank one. It is @code{INTENT(IN)} and the size of
8407 the array must be larger than or equal to the number returned by the
8408 @var{SIZE} argument.
8409 @item @var{GET} @tab (Optional) Shall be an array of type default
8410 @code{INTEGER} and rank one. It is @code{INTENT(OUT)} and the size
8411 of the array must be larger than or equal to the number returned by
8412 the @var{SIZE} argument.
8413 @end multitable
8414
8415 @item @emph{Example}:
8416 @smallexample
8417 SUBROUTINE init_random_seed()
8418 INTEGER :: i, n, clock
8419 INTEGER, DIMENSION(:), ALLOCATABLE :: seed
8420
8421 CALL RANDOM_SEED(size = n)
8422 ALLOCATE(seed(n))
8423
8424 CALL SYSTEM_CLOCK(COUNT=clock)
8425
8426 seed = clock + 37 * (/ (i - 1, i = 1, n) /)
8427 CALL RANDOM_SEED(PUT = seed)
8428
8429 DEALLOCATE(seed)
8430 END SUBROUTINE
8431 @end smallexample
8432
8433 @item @emph{See also}:
8434 @ref{RANDOM_NUMBER}
8435 @end table
8436
8437
8438
8439 @node RANGE
8440 @section @code{RANGE} --- Decimal exponent range of a real kind
8441 @fnindex RANGE
8442 @cindex model representation, range
8443
8444 @table @asis
8445 @item @emph{Description}:
8446 @code{RANGE(X)} returns the decimal exponent range in the model of the
8447 type of @code{X}.
8448
8449 @item @emph{Standard}:
8450 F95 and later
8451
8452 @item @emph{Class}:
8453 Inquiry function
8454
8455 @item @emph{Syntax}:
8456 @code{RESULT = RANGE(X)}
8457
8458 @item @emph{Arguments}:
8459 @multitable @columnfractions .15 .70
8460 @item @var{X} @tab Shall be of type @code{REAL} or @code{COMPLEX}.
8461 @end multitable
8462
8463 @item @emph{Return value}:
8464 The return value is of type @code{INTEGER} and of the default integer
8465 kind.
8466
8467 @item @emph{Example}:
8468 See @code{PRECISION} for an example.
8469 @end table
8470
8471
8472
8473 @node REAL
8474 @section @code{REAL} --- Convert to real type
8475 @fnindex REAL
8476 @fnindex REALPART
8477 @cindex conversion, to real
8478 @cindex complex numbers, real part
8479
8480 @table @asis
8481 @item @emph{Description}:
8482 @code{REAL(X [, KIND])} converts its argument @var{X} to a real type. The
8483 @code{REALPART(X)} function is provided for compatibility with @command{g77},
8484 and its use is strongly discouraged.
8485
8486 @item @emph{Standard}:
8487 F77 and later
8488
8489 @item @emph{Class}:
8490 Elemental function
8491
8492 @item @emph{Syntax}:
8493 @multitable @columnfractions .80
8494 @item @code{RESULT = REAL(X [, KIND])}
8495 @item @code{RESULT = REALPART(Z)}
8496 @end multitable
8497
8498 @item @emph{Arguments}:
8499 @multitable @columnfractions .15 .70
8500 @item @var{X} @tab Shall be @code{INTEGER(*)}, @code{REAL(*)}, or
8501 @code{COMPLEX(*)}.
8502 @item @var{KIND} @tab (Optional) An @code{INTEGER(*)} initialization
8503 expression indicating the kind parameter of
8504 the result.
8505 @end multitable
8506
8507 @item @emph{Return value}:
8508 These functions return a @code{REAL(*)} variable or array under
8509 the following rules:
8510
8511 @table @asis
8512 @item (A)
8513 @code{REAL(X)} is converted to a default real type if @var{X} is an
8514 integer or real variable.
8515 @item (B)
8516 @code{REAL(X)} is converted to a real type with the kind type parameter
8517 of @var{X} if @var{X} is a complex variable.
8518 @item (C)
8519 @code{REAL(X, KIND)} is converted to a real type with kind type
8520 parameter @var{KIND} if @var{X} is a complex, integer, or real
8521 variable.
8522 @end table
8523
8524 @item @emph{Example}:
8525 @smallexample
8526 program test_real
8527 complex :: x = (1.0, 2.0)
8528 print *, real(x), real(x,8), realpart(x)
8529 end program test_real
8530 @end smallexample
8531
8532 @item @emph{See also}:
8533 @ref{DBLE}, @ref{DFLOAT}, @ref{FLOAT}
8534
8535 @end table
8536
8537
8538
8539 @node RENAME
8540 @section @code{RENAME} --- Rename a file
8541 @fnindex RENAME
8542 @cindex file system, rename file
8543
8544 @table @asis
8545 @item @emph{Description}:
8546 Renames a file from file @var{PATH1} to @var{PATH2}. A null
8547 character (@code{CHAR(0)}) can be used to mark the end of the names in
8548 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
8549 names are ignored. If the @var{STATUS} argument is supplied, it
8550 contains 0 on success or a nonzero error code upon return; see
8551 @code{rename(2)}.
8552
8553 This intrinsic is provided in both subroutine and function forms;
8554 however, only one form can be used in any given program unit.
8555
8556 @item @emph{Standard}:
8557 GNU extension
8558
8559 @item @emph{Class}:
8560 Subroutine, function
8561
8562 @item @emph{Syntax}:
8563 @multitable @columnfractions .80
8564 @item @code{CALL RENAME(PATH1, PATH2 [, STATUS])}
8565 @item @code{STATUS = RENAME(PATH1, PATH2)}
8566 @end multitable
8567
8568 @item @emph{Arguments}:
8569 @multitable @columnfractions .15 .70
8570 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
8571 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
8572 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
8573 @end multitable
8574
8575 @item @emph{See also}:
8576 @ref{LINK}
8577
8578 @end table
8579
8580
8581
8582 @node REPEAT
8583 @section @code{REPEAT} --- Repeated string concatenation
8584 @fnindex REPEAT
8585 @cindex string, repeat
8586 @cindex string, concatenate
8587
8588 @table @asis
8589 @item @emph{Description}:
8590 Concatenates @var{NCOPIES} copies of a string.
8591
8592 @item @emph{Standard}:
8593 F95 and later
8594
8595 @item @emph{Class}:
8596 Transformational function
8597
8598 @item @emph{Syntax}:
8599 @code{RESULT = REPEAT(STRING, NCOPIES)}
8600
8601 @item @emph{Arguments}:
8602 @multitable @columnfractions .15 .70
8603 @item @var{STRING} @tab Shall be scalar and of type @code{CHARACTER(*)}.
8604 @item @var{NCOPIES} @tab Shall be scalar and of type @code{INTEGER(*)}.
8605 @end multitable
8606
8607 @item @emph{Return value}:
8608 A new scalar of type @code{CHARACTER} built up from @var{NCOPIES} copies
8609 of @var{STRING}.
8610
8611 @item @emph{Example}:
8612 @smallexample
8613 program test_repeat
8614 write(*,*) repeat("x", 5) ! "xxxxx"
8615 end program
8616 @end smallexample
8617 @end table
8618
8619
8620
8621 @node RESHAPE
8622 @section @code{RESHAPE} --- Function to reshape an array
8623 @fnindex RESHAPE
8624 @cindex array, change dimensions
8625 @cindex array, transmogrify
8626
8627 @table @asis
8628 @item @emph{Description}:
8629 Reshapes @var{SOURCE} to correspond to @var{SHAPE}. If necessary,
8630 the new array may be padded with elements from @var{PAD} or permuted
8631 as defined by @var{ORDER}.
8632
8633 @item @emph{Standard}:
8634 F95 and later
8635
8636 @item @emph{Class}:
8637 Transformational function
8638
8639 @item @emph{Syntax}:
8640 @code{RESULT = RESHAPE(SOURCE, SHAPE[, PAD, ORDER])}
8641
8642 @item @emph{Arguments}:
8643 @multitable @columnfractions .15 .70
8644 @item @var{SOURCE} @tab Shall be an array of any type.
8645 @item @var{SHAPE} @tab Shall be of type @code{INTEGER} and an
8646 array of rank one. Its values must be positive or zero.
8647 @item @var{PAD} @tab (Optional) shall be an array of the same
8648 type as @var{SOURCE}.
8649 @item @var{ORDER} @tab (Optional) shall be of type @code{INTEGER}
8650 and an array of the same shape as @var{SHAPE}. Its values shall
8651 be a permutation of the numbers from 1 to n, where n is the size of
8652 @var{SHAPE}. If @var{ORDER} is absent, the natural ordering shall
8653 be assumed.
8654 @end multitable
8655
8656 @item @emph{Return value}:
8657 The result is an array of shape @var{SHAPE} with the same type as
8658 @var{SOURCE}.
8659
8660 @item @emph{Example}:
8661 @smallexample
8662 PROGRAM test_reshape
8663 INTEGER, DIMENSION(4) :: x
8664 WRITE(*,*) SHAPE(x) ! prints "4"
8665 WRITE(*,*) SHAPE(RESHAPE(x, (/2, 2/))) ! prints "2 2"
8666 END PROGRAM
8667 @end smallexample
8668
8669 @item @emph{See also}:
8670 @ref{SHAPE}
8671 @end table
8672
8673
8674
8675 @node RRSPACING
8676 @section @code{RRSPACING} --- Reciprocal of the relative spacing
8677 @fnindex RRSPACING
8678 @cindex real number, relative spacing
8679 @cindex floating point, relative spacing
8680
8681
8682 @table @asis
8683 @item @emph{Description}:
8684 @code{RRSPACING(X)} returns the reciprocal of the relative spacing of
8685 model numbers near @var{X}.
8686
8687 @item @emph{Standard}:
8688 F95 and later
8689
8690 @item @emph{Class}:
8691 Elemental function
8692
8693 @item @emph{Syntax}:
8694 @code{RESULT = RRSPACING(X)}
8695
8696 @item @emph{Arguments}:
8697 @multitable @columnfractions .15 .70
8698 @item @var{X} @tab Shall be of type @code{REAL}.
8699 @end multitable
8700
8701 @item @emph{Return value}:
8702 The return value is of the same type and kind as @var{X}.
8703 The value returned is equal to
8704 @code{ABS(FRACTION(X)) * FLOAT(RADIX(X))**DIGITS(X)}.
8705
8706 @item @emph{See also}:
8707 @ref{SPACING}
8708 @end table
8709
8710
8711
8712 @node RSHIFT
8713 @section @code{RSHIFT} --- Right shift bits
8714 @fnindex RSHIFT
8715 @cindex bits, shift right
8716
8717 @table @asis
8718 @item @emph{Description}:
8719 @code{RSHIFT} returns a value corresponding to @var{I} with all of the
8720 bits shifted right by @var{SHIFT} places. If the absolute value of
8721 @var{SHIFT} is greater than @code{BIT_SIZE(I)}, the value is undefined.
8722 Bits shifted out from the left end are lost; zeros are shifted in from
8723 the opposite end.
8724
8725 This function has been superseded by the @code{ISHFT} intrinsic, which
8726 is standard in Fortran 95 and later.
8727
8728 @item @emph{Standard}:
8729 GNU extension
8730
8731 @item @emph{Class}:
8732 Elemental function
8733
8734 @item @emph{Syntax}:
8735 @code{RESULT = RSHIFT(I, SHIFT)}
8736
8737 @item @emph{Arguments}:
8738 @multitable @columnfractions .15 .70
8739 @item @var{I} @tab The type shall be @code{INTEGER(*)}.
8740 @item @var{SHIFT} @tab The type shall be @code{INTEGER(*)}.
8741 @end multitable
8742
8743 @item @emph{Return value}:
8744 The return value is of type @code{INTEGER(*)} and of the same kind as
8745 @var{I}.
8746
8747 @item @emph{See also}:
8748 @ref{ISHFT}, @ref{ISHFTC}, @ref{LSHIFT}
8749
8750 @end table
8751
8752
8753
8754 @node SCALE
8755 @section @code{SCALE} --- Scale a real value
8756 @fnindex SCALE
8757 @cindex real number, scale
8758 @cindex floating point, scale
8759
8760 @table @asis
8761 @item @emph{Description}:
8762 @code{SCALE(X,I)} returns @code{X * RADIX(X)**I}.
8763
8764 @item @emph{Standard}:
8765 F95 and later
8766
8767 @item @emph{Class}:
8768 Elemental function
8769
8770 @item @emph{Syntax}:
8771 @code{RESULT = SCALE(X, I)}
8772
8773 @item @emph{Arguments}:
8774 @multitable @columnfractions .15 .70
8775 @item @var{X} @tab The type of the argument shall be a @code{REAL}.
8776 @item @var{I} @tab The type of the argument shall be a @code{INTEGER}.
8777 @end multitable
8778
8779 @item @emph{Return value}:
8780 The return value is of the same type and kind as @var{X}.
8781 Its value is @code{X * RADIX(X)**I}.
8782
8783 @item @emph{Example}:
8784 @smallexample
8785 program test_scale
8786 real :: x = 178.1387e-4
8787 integer :: i = 5
8788 print *, scale(x,i), x*radix(x)**i
8789 end program test_scale
8790 @end smallexample
8791
8792 @end table
8793
8794
8795
8796 @node SCAN
8797 @section @code{SCAN} --- Scan a string for the presence of a set of characters
8798 @fnindex SCAN
8799 @cindex string, find subset
8800
8801 @table @asis
8802 @item @emph{Description}:
8803 Scans a @var{STRING} for any of the characters in a @var{SET}
8804 of characters.
8805
8806 If @var{BACK} is either absent or equals @code{FALSE}, this function
8807 returns the position of the leftmost character of @var{STRING} that is
8808 in @var{SET}. If @var{BACK} equals @code{TRUE}, the rightmost position
8809 is returned. If no character of @var{SET} is found in @var{STRING}, the
8810 result is zero.
8811
8812 @item @emph{Standard}:
8813 F95 and later
8814
8815 @item @emph{Class}:
8816 Elemental function
8817
8818 @item @emph{Syntax}:
8819 @code{RESULT = SCAN(STRING, SET[, BACK [, KIND]])}
8820
8821 @item @emph{Arguments}:
8822 @multitable @columnfractions .15 .70
8823 @item @var{STRING} @tab Shall be of type @code{CHARACTER(*)}.
8824 @item @var{SET} @tab Shall be of type @code{CHARACTER(*)}.
8825 @item @var{BACK} @tab (Optional) shall be of type @code{LOGICAL}.
8826 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
8827 expression indicating the kind parameter of
8828 the result.
8829 @end multitable
8830
8831 @item @emph{Return value}:
8832 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
8833 @var{KIND} is absent, the return value is of default integer kind.
8834
8835 @item @emph{Example}:
8836 @smallexample
8837 PROGRAM test_scan
8838 WRITE(*,*) SCAN("FORTRAN", "AO") ! 2, found 'O'
8839 WRITE(*,*) SCAN("FORTRAN", "AO", .TRUE.) ! 6, found 'A'
8840 WRITE(*,*) SCAN("FORTRAN", "C++") ! 0, found none
8841 END PROGRAM
8842 @end smallexample
8843
8844 @item @emph{See also}:
8845 @ref{INDEX}, @ref{VERIFY}
8846 @end table
8847
8848
8849
8850 @node SECNDS
8851 @section @code{SECNDS} --- Time function
8852 @fnindex SECNDS
8853 @cindex time, elapsed
8854 @cindex elapsed time
8855
8856 @table @asis
8857 @item @emph{Description}:
8858 @code{SECNDS(X)} gets the time in seconds from the real-time system clock.
8859 @var{X} is a reference time, also in seconds. If this is zero, the time in
8860 seconds from midnight is returned. This function is non-standard and its
8861 use is discouraged.
8862
8863 @item @emph{Standard}:
8864 GNU extension
8865
8866 @item @emph{Class}:
8867 Function
8868
8869 @item @emph{Syntax}:
8870 @code{RESULT = SECNDS (X)}
8871
8872 @item @emph{Arguments}:
8873 @multitable @columnfractions .15 .70
8874 @item @var{T} @tab Shall be of type @code{REAL(4)}.
8875 @item @var{X} @tab Shall be of type @code{REAL(4)}.
8876 @end multitable
8877
8878 @item @emph{Return value}:
8879 None
8880
8881 @item @emph{Example}:
8882 @smallexample
8883 program test_secnds
8884 integer :: i
8885 real(4) :: t1, t2
8886 print *, secnds (0.0) ! seconds since midnight
8887 t1 = secnds (0.0) ! reference time
8888 do i = 1, 10000000 ! do something
8889 end do
8890 t2 = secnds (t1) ! elapsed time
8891 print *, "Something took ", t2, " seconds."
8892 end program test_secnds
8893 @end smallexample
8894 @end table
8895
8896
8897
8898 @node SECOND
8899 @section @code{SECOND} --- CPU time function
8900 @fnindex SECOND
8901 @cindex time, elapsed
8902 @cindex elapsed time
8903
8904 @table @asis
8905 @item @emph{Description}:
8906 Returns a @code{REAL(4)} value representing the elapsed CPU time in
8907 seconds. This provides the same functionality as the standard
8908 @code{CPU_TIME} intrinsic, and is only included for backwards
8909 compatibility.
8910
8911 This intrinsic is provided in both subroutine and function forms;
8912 however, only one form can be used in any given program unit.
8913
8914 @item @emph{Standard}:
8915 GNU extension
8916
8917 @item @emph{Class}:
8918 Subroutine, function
8919
8920 @item @emph{Syntax}:
8921 @multitable @columnfractions .80
8922 @item @code{CALL SECOND(TIME)}
8923 @item @code{TIME = SECOND()}
8924 @end multitable
8925
8926 @item @emph{Arguments}:
8927 @multitable @columnfractions .15 .70
8928 @item @var{TIME} @tab Shall be of type @code{REAL(4)}.
8929 @end multitable
8930
8931 @item @emph{Return value}:
8932 In either syntax, @var{TIME} is set to the process's current runtime in
8933 seconds.
8934
8935 @item @emph{See also}:
8936 @ref{CPU_TIME}
8937
8938 @end table
8939
8940
8941
8942 @node SELECTED_INT_KIND
8943 @section @code{SELECTED_INT_KIND} --- Choose integer kind
8944 @fnindex SELECTED_INT_KIND
8945 @cindex integer kind
8946 @cindex kind, integer
8947
8948 @table @asis
8949 @item @emph{Description}:
8950 @code{SELECTED_INT_KIND(I)} return the kind value of the smallest integer
8951 type that can represent all values ranging from @math{-10^I} (exclusive)
8952 to @math{10^I} (exclusive). If there is no integer kind that accommodates
8953 this range, @code{SELECTED_INT_KIND} returns @math{-1}.
8954
8955 @item @emph{Standard}:
8956 F95 and later
8957
8958 @item @emph{Class}:
8959 Transformational function
8960
8961 @item @emph{Syntax}:
8962 @code{RESULT = SELECTED_INT_KIND(I)}
8963
8964 @item @emph{Arguments}:
8965 @multitable @columnfractions .15 .70
8966 @item @var{I} @tab Shall be a scalar and of type @code{INTEGER}.
8967 @end multitable
8968
8969 @item @emph{Example}:
8970 @smallexample
8971 program large_integers
8972 integer,parameter :: k5 = selected_int_kind(5)
8973 integer,parameter :: k15 = selected_int_kind(15)
8974 integer(kind=k5) :: i5
8975 integer(kind=k15) :: i15
8976
8977 print *, huge(i5), huge(i15)
8978
8979 ! The following inequalities are always true
8980 print *, huge(i5) >= 10_k5**5-1
8981 print *, huge(i15) >= 10_k15**15-1
8982 end program large_integers
8983 @end smallexample
8984 @end table
8985
8986
8987
8988 @node SELECTED_REAL_KIND
8989 @section @code{SELECTED_REAL_KIND} --- Choose real kind
8990 @fnindex SELECTED_REAL_KIND
8991 @cindex real kind
8992 @cindex kind, real
8993
8994 @table @asis
8995 @item @emph{Description}:
8996 @code{SELECTED_REAL_KIND(P,R)} return the kind value of a real data type
8997 with decimal precision greater of at least @code{P} digits and exponent
8998 range greater at least @code{R}.
8999
9000 @item @emph{Standard}:
9001 F95 and later
9002
9003 @item @emph{Class}:
9004 Transformational function
9005
9006 @item @emph{Syntax}:
9007 @code{RESULT = SELECTED_REAL_KIND(P, R)}
9008
9009 @item @emph{Arguments}:
9010 @multitable @columnfractions .15 .70
9011 @item @var{P} @tab (Optional) shall be a scalar and of type @code{INTEGER}.
9012 @item @var{R} @tab (Optional) shall be a scalar and of type @code{INTEGER}.
9013 @end multitable
9014 At least one argument shall be present.
9015
9016 @item @emph{Return value}:
9017
9018 @code{SELECTED_REAL_KIND} returns the value of the kind type parameter of
9019 a real data type with decimal precision of at least @code{P} digits and a
9020 decimal exponent range of at least @code{R}. If more than one real data
9021 type meet the criteria, the kind of the data type with the smallest
9022 decimal precision is returned. If no real data type matches the criteria,
9023 the result is
9024 @table @asis
9025 @item -1 if the processor does not support a real data type with a
9026 precision greater than or equal to @code{P}
9027 @item -2 if the processor does not support a real type with an exponent
9028 range greater than or equal to @code{R}
9029 @item -3 if neither is supported.
9030 @end table
9031
9032 @item @emph{Example}:
9033 @smallexample
9034 program real_kinds
9035 integer,parameter :: p6 = selected_real_kind(6)
9036 integer,parameter :: p10r100 = selected_real_kind(10,100)
9037 integer,parameter :: r400 = selected_real_kind(r=400)
9038 real(kind=p6) :: x
9039 real(kind=p10r100) :: y
9040 real(kind=r400) :: z
9041
9042 print *, precision(x), range(x)
9043 print *, precision(y), range(y)
9044 print *, precision(z), range(z)
9045 end program real_kinds
9046 @end smallexample
9047 @end table
9048
9049
9050
9051 @node SET_EXPONENT
9052 @section @code{SET_EXPONENT} --- Set the exponent of the model
9053 @fnindex SET_EXPONENT
9054 @cindex real number, set exponent
9055 @cindex floating point, set exponent
9056
9057 @table @asis
9058 @item @emph{Description}:
9059 @code{SET_EXPONENT(X, I)} returns the real number whose fractional part
9060 is that that of @var{X} and whose exponent part is @var{I}.
9061
9062 @item @emph{Standard}:
9063 F95 and later
9064
9065 @item @emph{Class}:
9066 Elemental function
9067
9068 @item @emph{Syntax}:
9069 @code{RESULT = SET_EXPONENT(X, I)}
9070
9071 @item @emph{Arguments}:
9072 @multitable @columnfractions .15 .70
9073 @item @var{X} @tab Shall be of type @code{REAL}.
9074 @item @var{I} @tab Shall be of type @code{INTEGER}.
9075 @end multitable
9076
9077 @item @emph{Return value}:
9078 The return value is of the same type and kind as @var{X}.
9079 The real number whose fractional part
9080 is that that of @var{X} and whose exponent part if @var{I} is returned;
9081 it is @code{FRACTION(X) * RADIX(X)**I}.
9082
9083 @item @emph{Example}:
9084 @smallexample
9085 PROGRAM test_setexp
9086 REAL :: x = 178.1387e-4
9087 INTEGER :: i = 17
9088 PRINT *, SET_EXPONENT(x, i), FRACTION(x) * RADIX(x)**i
9089 END PROGRAM
9090 @end smallexample
9091
9092 @end table
9093
9094
9095
9096 @node SHAPE
9097 @section @code{SHAPE} --- Determine the shape of an array
9098 @fnindex SHAPE
9099 @cindex array, shape
9100
9101 @table @asis
9102 @item @emph{Description}:
9103 Determines the shape of an array.
9104
9105 @item @emph{Standard}:
9106 F95 and later
9107
9108 @item @emph{Class}:
9109 Inquiry function
9110
9111 @item @emph{Syntax}:
9112 @code{RESULT = SHAPE(SOURCE)}
9113
9114 @item @emph{Arguments}:
9115 @multitable @columnfractions .15 .70
9116 @item @var{SOURCE} @tab Shall be an array or scalar of any type.
9117 If @var{SOURCE} is a pointer it must be associated and allocatable
9118 arrays must be allocated.
9119 @end multitable
9120
9121 @item @emph{Return value}:
9122 An @code{INTEGER} array of rank one with as many elements as @var{SOURCE}
9123 has dimensions. The elements of the resulting array correspond to the extend
9124 of @var{SOURCE} along the respective dimensions. If @var{SOURCE} is a scalar,
9125 the result is the rank one array of size zero.
9126
9127 @item @emph{Example}:
9128 @smallexample
9129 PROGRAM test_shape
9130 INTEGER, DIMENSION(-1:1, -1:2) :: A
9131 WRITE(*,*) SHAPE(A) ! (/ 3, 4 /)
9132 WRITE(*,*) SIZE(SHAPE(42)) ! (/ /)
9133 END PROGRAM
9134 @end smallexample
9135
9136 @item @emph{See also}:
9137 @ref{RESHAPE}, @ref{SIZE}
9138 @end table
9139
9140
9141
9142 @node SIGN
9143 @section @code{SIGN} --- Sign copying function
9144 @fnindex SIGN
9145 @fnindex ISIGN
9146 @fnindex DSIGN
9147 @cindex sign copying
9148
9149 @table @asis
9150 @item @emph{Description}:
9151 @code{SIGN(A,B)} returns the value of @var{A} with the sign of @var{B}.
9152
9153 @item @emph{Standard}:
9154 F77 and later
9155
9156 @item @emph{Class}:
9157 Elemental function
9158
9159 @item @emph{Syntax}:
9160 @code{RESULT = SIGN(A, B)}
9161
9162 @item @emph{Arguments}:
9163 @multitable @columnfractions .15 .70
9164 @item @var{A} @tab Shall be of type @code{INTEGER} or @code{REAL}
9165 @item @var{B} @tab Shall be of the same type and kind as @var{A}
9166 @end multitable
9167
9168 @item @emph{Return value}:
9169 The kind of the return value is that of @var{A} and @var{B}.
9170 If @math{B\ge 0} then the result is @code{ABS(A)}, else
9171 it is @code{-ABS(A)}.
9172
9173 @item @emph{Example}:
9174 @smallexample
9175 program test_sign
9176 print *, sign(-12,1)
9177 print *, sign(-12,0)
9178 print *, sign(-12,-1)
9179
9180 print *, sign(-12.,1.)
9181 print *, sign(-12.,0.)
9182 print *, sign(-12.,-1.)
9183 end program test_sign
9184 @end smallexample
9185
9186 @item @emph{Specific names}:
9187 @multitable @columnfractions .20 .20 .20 .25
9188 @item Name @tab Arguments @tab Return type @tab Standard
9189 @item @code{ISIGN(A,P)} @tab @code{INTEGER(4)} @tab @code{INTEGER(4)} @tab f95, gnu
9190 @item @code{DSIGN(A,P)} @tab @code{REAL(8)} @tab @code{REAL(8)} @tab f95, gnu
9191 @end multitable
9192 @end table
9193
9194
9195
9196 @node SIGNAL
9197 @section @code{SIGNAL} --- Signal handling subroutine (or function)
9198 @fnindex SIGNAL
9199 @cindex system, signal handling
9200
9201 @table @asis
9202 @item @emph{Description}:
9203 @code{SIGNAL(NUMBER, HANDLER [, STATUS])} causes external subroutine
9204 @var{HANDLER} to be executed with a single integer argument when signal
9205 @var{NUMBER} occurs. If @var{HANDLER} is an integer, it can be used to
9206 turn off handling of signal @var{NUMBER} or revert to its default
9207 action. See @code{signal(2)}.
9208
9209 If @code{SIGNAL} is called as a subroutine and the @var{STATUS} argument
9210 is supplied, it is set to the value returned by @code{signal(2)}.
9211
9212 @item @emph{Standard}:
9213 GNU extension
9214
9215 @item @emph{Class}:
9216 Subroutine, function
9217
9218 @item @emph{Syntax}:
9219 @multitable @columnfractions .80
9220 @item @code{CALL SIGNAL(NUMBER, HANDLER [, STATUS])}
9221 @item @code{STATUS = SIGNAL(NUMBER, HANDLER)}
9222 @end multitable
9223
9224 @item @emph{Arguments}:
9225 @multitable @columnfractions .15 .70
9226 @item @var{NUMBER} @tab Shall be a scalar integer, with @code{INTENT(IN)}
9227 @item @var{HANDLER}@tab Signal handler (@code{INTEGER FUNCTION} or
9228 @code{SUBROUTINE}) or dummy/global @code{INTEGER} scalar.
9229 @code{INTEGER}. It is @code{INTENT(IN)}.
9230 @item @var{STATUS} @tab (Optional) @var{STATUS} shall be a scalar
9231 integer. It has @code{INTENT(OUT)}.
9232 @end multitable
9233
9234 @item @emph{Return value}:
9235 The @code{SIGNAL} function returns the value returned by @code{signal(2)}.
9236
9237 @item @emph{Example}:
9238 @smallexample
9239 program test_signal
9240 intrinsic signal
9241 external handler_print
9242
9243 call signal (12, handler_print)
9244 call signal (10, 1)
9245
9246 call sleep (30)
9247 end program test_signal
9248 @end smallexample
9249 @end table
9250
9251
9252
9253 @node SIN
9254 @section @code{SIN} --- Sine function
9255 @fnindex SIN
9256 @fnindex DSIN
9257 @fnindex CSIN
9258 @fnindex ZSIN
9259 @fnindex CDSIN
9260 @cindex trigonometric function, sine
9261 @cindex sine
9262
9263 @table @asis
9264 @item @emph{Description}:
9265 @code{SIN(X)} computes the sine of @var{X}.
9266
9267 @item @emph{Standard}:
9268 F77 and later
9269
9270 @item @emph{Class}:
9271 Elemental function
9272
9273 @item @emph{Syntax}:
9274 @code{RESULT = SIN(X)}
9275
9276 @item @emph{Arguments}:
9277 @multitable @columnfractions .15 .70
9278 @item @var{X} @tab The type shall be @code{REAL(*)} or
9279 @code{COMPLEX(*)}.
9280 @end multitable
9281
9282 @item @emph{Return value}:
9283 The return value has same type and kind as @var{X}.
9284
9285 @item @emph{Example}:
9286 @smallexample
9287 program test_sin
9288 real :: x = 0.0
9289 x = sin(x)
9290 end program test_sin
9291 @end smallexample
9292
9293 @item @emph{Specific names}:
9294 @multitable @columnfractions .20 .20 .20 .25
9295 @item Name @tab Argument @tab Return type @tab Standard
9296 @item @code{DSIN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab f95, gnu
9297 @item @code{CSIN(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab f95, gnu
9298 @item @code{ZSIN(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
9299 @item @code{CDSIN(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab f95, gnu
9300 @end multitable
9301
9302 @item @emph{See also}:
9303 @ref{ASIN}
9304 @end table
9305
9306
9307
9308 @node SINH
9309 @section @code{SINH} --- Hyperbolic sine function
9310 @fnindex SINH
9311 @fnindex DSINH
9312 @cindex hyperbolic sine
9313 @cindex hyperbolic function, sine
9314 @cindex sine, hyperbolic
9315
9316 @table @asis
9317 @item @emph{Description}:
9318 @code{SINH(X)} computes the hyperbolic sine of @var{X}.
9319
9320 @item @emph{Standard}:
9321 F95 and later
9322
9323 @item @emph{Class}:
9324 Elemental function
9325
9326 @item @emph{Syntax}:
9327 @code{RESULT = SINH(X)}
9328
9329 @item @emph{Arguments}:
9330 @multitable @columnfractions .15 .70
9331 @item @var{X} @tab The type shall be @code{REAL(*)}.
9332 @end multitable
9333
9334 @item @emph{Return value}:
9335 The return value is of type @code{REAL(*)}.
9336
9337 @item @emph{Example}:
9338 @smallexample
9339 program test_sinh
9340 real(8) :: x = - 1.0_8
9341 x = sinh(x)
9342 end program test_sinh
9343 @end smallexample
9344
9345 @item @emph{Specific names}:
9346 @multitable @columnfractions .20 .20 .20 .25
9347 @item Name @tab Argument @tab Return type @tab Standard
9348 @item @code{DSINH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F95 and later
9349 @end multitable
9350
9351 @item @emph{See also}:
9352 @ref{ASINH}
9353 @end table
9354
9355
9356
9357 @node SIZE
9358 @section @code{SIZE} --- Determine the size of an array
9359 @fnindex SIZE
9360 @cindex array, size
9361 @cindex array, number of elements
9362 @cindex array, count elements
9363
9364 @table @asis
9365 @item @emph{Description}:
9366 Determine the extent of @var{ARRAY} along a specified dimension @var{DIM},
9367 or the total number of elements in @var{ARRAY} if @var{DIM} is absent.
9368
9369 @item @emph{Standard}:
9370 F95 and later
9371
9372 @item @emph{Class}:
9373 Inquiry function
9374
9375 @item @emph{Syntax}:
9376 @code{RESULT = SIZE(ARRAY[, DIM [, KIND]])}
9377
9378 @item @emph{Arguments}:
9379 @multitable @columnfractions .15 .70
9380 @item @var{ARRAY} @tab Shall be an array of any type. If @var{ARRAY} is
9381 a pointer it must be associated and allocatable arrays must be allocated.
9382 @item @var{DIM} @tab (Optional) shall be a scalar of type @code{INTEGER}
9383 and its value shall be in the range from 1 to n, where n equals the rank
9384 of @var{ARRAY}.
9385 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
9386 expression indicating the kind parameter of
9387 the result.
9388 @end multitable
9389
9390 @item @emph{Return value}:
9391 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
9392 @var{KIND} is absent, the return value is of default integer kind.
9393
9394 @item @emph{Example}:
9395 @smallexample
9396 PROGRAM test_size
9397 WRITE(*,*) SIZE((/ 1, 2 /)) ! 2
9398 END PROGRAM
9399 @end smallexample
9400
9401 @item @emph{See also}:
9402 @ref{SHAPE}, @ref{RESHAPE}
9403 @end table
9404
9405
9406 @node SIZEOF
9407 @section @code{SIZEOF} --- Size in bytes of an expression
9408 @fnindex SIZEOF
9409 @cindex expression size
9410 @cindex size of an expression
9411
9412 @table @asis
9413 @item @emph{Description}:
9414 @code{SIZEOF(X)} calculates the number of bytes of storage the
9415 expression @code{X} occupies.
9416
9417 @item @emph{Standard}:
9418 GNU extension
9419
9420 @item @emph{Class}:
9421 Intrinsic function
9422
9423 @item @emph{Syntax}:
9424 @code{N = SIZEOF(X)}
9425
9426 @item @emph{Arguments}:
9427 @multitable @columnfractions .15 .70
9428 @item @var{X} @tab The argument shall be of any type, rank or shape.
9429 @end multitable
9430
9431 @item @emph{Return value}:
9432 The return value is of type integer and of the system-dependent kind
9433 @var{C_SIZE_T} (from the @var{ISO_C_BINDING} module). Its value is the
9434 number of bytes occupied by the argument. If the argument has the
9435 @code{POINTER} attribute, the number of bytes of the storage area pointed
9436 to is returned. If the argument is of a derived type with @code{POINTER}
9437 or @code{ALLOCATABLE} components, the return value doesn't account for
9438 the sizes of the data pointed to by these components.
9439
9440 @item @emph{Example}:
9441 @smallexample
9442 integer :: i
9443 real :: r, s(5)
9444 print *, (sizeof(s)/sizeof(r) == 5)
9445 end
9446 @end smallexample
9447 The example will print @code{.TRUE.} unless you are using a platform
9448 where default @code{REAL} variables are unusually padded.
9449 @end table
9450
9451 @node SLEEP
9452 @section @code{SLEEP} --- Sleep for the specified number of seconds
9453 @fnindex SLEEP
9454 @cindex delayed execution
9455
9456 @table @asis
9457 @item @emph{Description}:
9458 Calling this subroutine causes the process to pause for @var{SECONDS} seconds.
9459
9460 @item @emph{Standard}:
9461 GNU extension
9462
9463 @item @emph{Class}:
9464 Subroutine
9465
9466 @item @emph{Syntax}:
9467 @code{CALL SLEEP(SECONDS)}
9468
9469 @item @emph{Arguments}:
9470 @multitable @columnfractions .15 .70
9471 @item @var{SECONDS} @tab The type shall be of default @code{INTEGER}.
9472 @end multitable
9473
9474 @item @emph{Example}:
9475 @smallexample
9476 program test_sleep
9477 call sleep(5)
9478 end
9479 @end smallexample
9480 @end table
9481
9482
9483
9484 @node SNGL
9485 @section @code{SNGL} --- Convert double precision real to default real
9486 @fnindex SNGL
9487 @cindex conversion, to real
9488
9489 @table @asis
9490 @item @emph{Description}:
9491 @code{SNGL(A)} converts the double precision real @var{A}
9492 to a default real value. This is an archaic form of @code{REAL}
9493 that is specific to one type for @var{A}.
9494
9495 @item @emph{Standard}:
9496 GNU extension
9497
9498 @item @emph{Class}:
9499 Elemental function
9500
9501 @item @emph{Syntax}:
9502 @code{RESULT = SNGL(A)}
9503
9504 @item @emph{Arguments}:
9505 @multitable @columnfractions .15 .70
9506 @item @var{A} @tab The type shall be a double precision @code{REAL}.
9507 @end multitable
9508
9509 @item @emph{Return value}:
9510 The return value is of type default @code{REAL}.
9511
9512 @item @emph{See also}:
9513 @ref{DBLE}
9514 @end table
9515
9516
9517
9518 @node SPACING
9519 @section @code{SPACING} --- Smallest distance between two numbers of a given type
9520 @fnindex SPACING
9521 @cindex real number, relative spacing
9522 @cindex floating point, relative spacing
9523
9524 @table @asis
9525 @item @emph{Description}:
9526 Determines the distance between the argument @var{X} and the nearest
9527 adjacent number of the same type.
9528
9529 @item @emph{Standard}:
9530 F95 and later
9531
9532 @item @emph{Class}:
9533 Elemental function
9534
9535 @item @emph{Syntax}:
9536 @code{RESULT = SPACING(X)}
9537
9538 @item @emph{Arguments}:
9539 @multitable @columnfractions .15 .70
9540 @item @var{X} @tab Shall be of type @code{REAL(*)}.
9541 @end multitable
9542
9543 @item @emph{Return value}:
9544 The result is of the same type as the input argument @var{X}.
9545
9546 @item @emph{Example}:
9547 @smallexample
9548 PROGRAM test_spacing
9549 INTEGER, PARAMETER :: SGL = SELECTED_REAL_KIND(p=6, r=37)
9550 INTEGER, PARAMETER :: DBL = SELECTED_REAL_KIND(p=13, r=200)
9551
9552 WRITE(*,*) spacing(1.0_SGL) ! "1.1920929E-07" on i686
9553 WRITE(*,*) spacing(1.0_DBL) ! "2.220446049250313E-016" on i686
9554 END PROGRAM
9555 @end smallexample
9556
9557 @item @emph{See also}:
9558 @ref{RRSPACING}
9559 @end table
9560
9561
9562
9563 @node SPREAD
9564 @section @code{SPREAD} --- Add a dimension to an array
9565 @fnindex SPREAD
9566 @cindex array, increase dimension
9567 @cindex array, duplicate elements
9568 @cindex array, duplicate dimensions
9569
9570 @table @asis
9571 @item @emph{Description}:
9572 Replicates a @var{SOURCE} array @var{NCOPIES} times along a specified
9573 dimension @var{DIM}.
9574
9575 @item @emph{Standard}:
9576 F95 and later
9577
9578 @item @emph{Class}:
9579 Transformational function
9580
9581 @item @emph{Syntax}:
9582 @code{RESULT = SPREAD(SOURCE, DIM, NCOPIES)}
9583
9584 @item @emph{Arguments}:
9585 @multitable @columnfractions .15 .70
9586 @item @var{SOURCE} @tab Shall be a scalar or an array of any type and
9587 a rank less than seven.
9588 @item @var{DIM} @tab Shall be a scalar of type @code{INTEGER} with a
9589 value in the range from 1 to n+1, where n equals the rank of @var{SOURCE}.
9590 @item @var{NCOPIES} @tab Shall be a scalar of type @code{INTEGER}.
9591 @end multitable
9592
9593 @item @emph{Return value}:
9594 The result is an array of the same type as @var{SOURCE} and has rank n+1
9595 where n equals the rank of @var{SOURCE}.
9596
9597 @item @emph{Example}:
9598 @smallexample
9599 PROGRAM test_spread
9600 INTEGER :: a = 1, b(2) = (/ 1, 2 /)
9601 WRITE(*,*) SPREAD(A, 1, 2) ! "1 1"
9602 WRITE(*,*) SPREAD(B, 1, 2) ! "1 1 2 2"
9603 END PROGRAM
9604 @end smallexample
9605
9606 @item @emph{See also}:
9607 @ref{UNPACK}
9608 @end table
9609
9610
9611
9612 @node SQRT
9613 @section @code{SQRT} --- Square-root function
9614 @fnindex SQRT
9615 @fnindex DSQRT
9616 @fnindex CSQRT
9617 @fnindex ZSQRT
9618 @fnindex CDSQRT
9619 @cindex root
9620 @cindex square-root
9621
9622 @table @asis
9623 @item @emph{Description}:
9624 @code{SQRT(X)} computes the square root of @var{X}.
9625
9626 @item @emph{Standard}:
9627 F77 and later
9628
9629 @item @emph{Class}:
9630 Elemental function
9631
9632 @item @emph{Syntax}:
9633 @code{RESULT = SQRT(X)}
9634
9635 @item @emph{Arguments}:
9636 @multitable @columnfractions .15 .70
9637 @item @var{X} @tab The type shall be @code{REAL(*)} or
9638 @code{COMPLEX(*)}.
9639 @end multitable
9640
9641 @item @emph{Return value}:
9642 The return value is of type @code{REAL(*)} or @code{COMPLEX(*)}.
9643 The kind type parameter is the same as @var{X}.
9644
9645 @item @emph{Example}:
9646 @smallexample
9647 program test_sqrt
9648 real(8) :: x = 2.0_8
9649 complex :: z = (1.0, 2.0)
9650 x = sqrt(x)
9651 z = sqrt(z)
9652 end program test_sqrt
9653 @end smallexample
9654
9655 @item @emph{Specific names}:
9656 @multitable @columnfractions .20 .20 .20 .25
9657 @item Name @tab Argument @tab Return type @tab Standard
9658 @item @code{DSQRT(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F95 and later
9659 @item @code{CSQRT(X)} @tab @code{COMPLEX(4) X} @tab @code{COMPLEX(4)} @tab F95 and later
9660 @item @code{ZSQRT(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
9661 @item @code{CDSQRT(X)} @tab @code{COMPLEX(8) X} @tab @code{COMPLEX(8)} @tab GNU extension
9662 @end multitable
9663 @end table
9664
9665
9666
9667 @node SRAND
9668 @section @code{SRAND} --- Reinitialize the random number generator
9669 @fnindex SRAND
9670 @cindex random number generation, seeding
9671 @cindex seeding a random number generator
9672
9673 @table @asis
9674 @item @emph{Description}:
9675 @code{SRAND} reinitializes the pseudo-random number generator
9676 called by @code{RAND} and @code{IRAND}. The new seed used by the
9677 generator is specified by the required argument @var{SEED}.
9678
9679 @item @emph{Standard}:
9680 GNU extension
9681
9682 @item @emph{Class}:
9683 Subroutine
9684
9685 @item @emph{Syntax}:
9686 @code{CALL SRAND(SEED)}
9687
9688 @item @emph{Arguments}:
9689 @multitable @columnfractions .15 .70
9690 @item @var{SEED} @tab Shall be a scalar @code{INTEGER(kind=4)}.
9691 @end multitable
9692
9693 @item @emph{Return value}:
9694 Does not return.
9695
9696 @item @emph{Example}:
9697 See @code{RAND} and @code{IRAND} for examples.
9698
9699 @item @emph{Notes}:
9700 The Fortran 2003 standard specifies the intrinsic @code{RANDOM_SEED} to
9701 initialize the pseudo-random numbers generator and @code{RANDOM_NUMBER}
9702 to generate pseudo-random numbers. Please note that in
9703 GNU Fortran, these two sets of intrinsics (@code{RAND},
9704 @code{IRAND} and @code{SRAND} on the one hand, @code{RANDOM_NUMBER} and
9705 @code{RANDOM_SEED} on the other hand) access two independent
9706 pseudo-random number generators.
9707
9708 @item @emph{See also}:
9709 @ref{RAND}, @ref{RANDOM_SEED}, @ref{RANDOM_NUMBER}
9710
9711 @end table
9712
9713
9714
9715 @node STAT
9716 @section @code{STAT} --- Get file status
9717 @fnindex STAT
9718 @cindex file system, file status
9719
9720 @table @asis
9721 @item @emph{Description}:
9722 This function returns information about a file. No permissions are required on
9723 the file itself, but execute (search) permission is required on all of the
9724 directories in path that lead to the file.
9725
9726 The elements that are obtained and stored in the array @code{BUFF}:
9727 @multitable @columnfractions .15 .70
9728 @item @code{buff(1)} @tab Device ID
9729 @item @code{buff(2)} @tab Inode number
9730 @item @code{buff(3)} @tab File mode
9731 @item @code{buff(4)} @tab Number of links
9732 @item @code{buff(5)} @tab Owner's uid
9733 @item @code{buff(6)} @tab Owner's gid
9734 @item @code{buff(7)} @tab ID of device containing directory entry for file (0 if not available)
9735 @item @code{buff(8)} @tab File size (bytes)
9736 @item @code{buff(9)} @tab Last access time
9737 @item @code{buff(10)} @tab Last modification time
9738 @item @code{buff(11)} @tab Last file status change time
9739 @item @code{buff(12)} @tab Preferred I/O block size (-1 if not available)
9740 @item @code{buff(13)} @tab Number of blocks allocated (-1 if not available)
9741 @end multitable
9742
9743 Not all these elements are relevant on all systems.
9744 If an element is not relevant, it is returned as 0.
9745
9746 This intrinsic is provided in both subroutine and function forms; however,
9747 only one form can be used in any given program unit.
9748
9749 @item @emph{Standard}:
9750 GNU extension
9751
9752 @item @emph{Class}:
9753 Subroutine, function
9754
9755 @item @emph{Syntax}:
9756 @code{CALL STAT(FILE,BUFF[,STATUS])}
9757
9758 @item @emph{Arguments}:
9759 @multitable @columnfractions .15 .70
9760 @item @var{FILE} @tab The type shall be @code{CHARACTER(*)}, a valid path within the file system.
9761 @item @var{BUFF} @tab The type shall be @code{INTEGER(4), DIMENSION(13)}.
9762 @item @var{STATUS} @tab (Optional) status flag of type @code{INTEGER(4)}. Returns 0
9763 on success and a system specific error code otherwise.
9764 @end multitable
9765
9766 @item @emph{Example}:
9767 @smallexample
9768 PROGRAM test_stat
9769 INTEGER, DIMENSION(13) :: buff
9770 INTEGER :: status
9771
9772 CALL STAT("/etc/passwd", buff, status)
9773
9774 IF (status == 0) THEN
9775 WRITE (*, FMT="('Device ID:', T30, I19)") buff(1)
9776 WRITE (*, FMT="('Inode number:', T30, I19)") buff(2)
9777 WRITE (*, FMT="('File mode (octal):', T30, O19)") buff(3)
9778 WRITE (*, FMT="('Number of links:', T30, I19)") buff(4)
9779 WRITE (*, FMT="('Owner''s uid:', T30, I19)") buff(5)
9780 WRITE (*, FMT="('Owner''s gid:', T30, I19)") buff(6)
9781 WRITE (*, FMT="('Device where located:', T30, I19)") buff(7)
9782 WRITE (*, FMT="('File size:', T30, I19)") buff(8)
9783 WRITE (*, FMT="('Last access time:', T30, A19)") CTIME(buff(9))
9784 WRITE (*, FMT="('Last modification time', T30, A19)") CTIME(buff(10))
9785 WRITE (*, FMT="('Last status change time:', T30, A19)") CTIME(buff(11))
9786 WRITE (*, FMT="('Preferred block size:', T30, I19)") buff(12)
9787 WRITE (*, FMT="('No. of blocks allocated:', T30, I19)") buff(13)
9788 END IF
9789 END PROGRAM
9790 @end smallexample
9791
9792 @item @emph{See also}:
9793 To stat an open file: @ref{FSTAT}, to stat a link: @ref{LSTAT}
9794 @end table
9795
9796
9797
9798 @node SUM
9799 @section @code{SUM} --- Sum of array elements
9800 @fnindex SUM
9801 @cindex array, sum
9802 @cindex array, add elements
9803 @cindex array, conditionally add elements
9804 @cindex sum array elements
9805
9806 @table @asis
9807 @item @emph{Description}:
9808 Adds the elements of @var{ARRAY} along dimension @var{DIM} if
9809 the corresponding element in @var{MASK} is @code{TRUE}.
9810
9811 @item @emph{Standard}:
9812 F95 and later
9813
9814 @item @emph{Class}:
9815 Transformational function
9816
9817 @item @emph{Syntax}:
9818 @code{RESULT = SUM(ARRAY[, MASK])}
9819 @code{RESULT = SUM(ARRAY, DIM[, MASK])}
9820
9821 @item @emph{Arguments}:
9822 @multitable @columnfractions .15 .70
9823 @item @var{ARRAY} @tab Shall be an array of type @code{INTEGER(*)},
9824 @code{REAL(*)} or @code{COMPLEX(*)}.
9825 @item @var{DIM} @tab (Optional) shall be a scalar of type
9826 @code{INTEGER} with a value in the range from 1 to n, where n
9827 equals the rank of @var{ARRAY}.
9828 @item @var{MASK} @tab (Optional) shall be of type @code{LOGICAL}
9829 and either be a scalar or an array of the same shape as @var{ARRAY}.
9830 @end multitable
9831
9832 @item @emph{Return value}:
9833 The result is of the same type as @var{ARRAY}.
9834
9835 If @var{DIM} is absent, a scalar with the sum of all elements in @var{ARRAY}
9836 is returned. Otherwise, an array of rank n-1, where n equals the rank of
9837 @var{ARRAY},and a shape similar to that of @var{ARRAY} with dimension @var{DIM}
9838 dropped is returned.
9839
9840 @item @emph{Example}:
9841 @smallexample
9842 PROGRAM test_sum
9843 INTEGER :: x(5) = (/ 1, 2, 3, 4 ,5 /)
9844 print *, SUM(x) ! all elements, sum = 15
9845 print *, SUM(x, MASK=MOD(x, 2)==1) ! odd elements, sum = 9
9846 END PROGRAM
9847 @end smallexample
9848
9849 @item @emph{See also}:
9850 @ref{PRODUCT}
9851 @end table
9852
9853
9854
9855 @node SYMLNK
9856 @section @code{SYMLNK} --- Create a symbolic link
9857 @fnindex SYMLNK
9858 @cindex file system, create link
9859 @cindex file system, soft link
9860
9861 @table @asis
9862 @item @emph{Description}:
9863 Makes a symbolic link from file @var{PATH1} to @var{PATH2}. A null
9864 character (@code{CHAR(0)}) can be used to mark the end of the names in
9865 @var{PATH1} and @var{PATH2}; otherwise, trailing blanks in the file
9866 names are ignored. If the @var{STATUS} argument is supplied, it
9867 contains 0 on success or a nonzero error code upon return; see
9868 @code{symlink(2)}. If the system does not supply @code{symlink(2)},
9869 @code{ENOSYS} is returned.
9870
9871 This intrinsic is provided in both subroutine and function forms;
9872 however, only one form can be used in any given program unit.
9873
9874 @item @emph{Standard}:
9875 GNU extension
9876
9877 @item @emph{Class}:
9878 Subroutine, function
9879
9880 @item @emph{Syntax}:
9881 @multitable @columnfractions .80
9882 @item @code{CALL SYMLNK(PATH1, PATH2 [, STATUS])}
9883 @item @code{STATUS = SYMLNK(PATH1, PATH2)}
9884 @end multitable
9885
9886 @item @emph{Arguments}:
9887 @multitable @columnfractions .15 .70
9888 @item @var{PATH1} @tab Shall be of default @code{CHARACTER} type.
9889 @item @var{PATH2} @tab Shall be of default @code{CHARACTER} type.
9890 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
9891 @end multitable
9892
9893 @item @emph{See also}:
9894 @ref{LINK}, @ref{UNLINK}
9895
9896 @end table
9897
9898
9899
9900 @node SYSTEM
9901 @section @code{SYSTEM} --- Execute a shell command
9902 @fnindex SYSTEM
9903 @cindex system, system call
9904
9905 @table @asis
9906 @item @emph{Description}:
9907 Passes the command @var{COMMAND} to a shell (see @code{system(3)}). If
9908 argument @var{STATUS} is present, it contains the value returned by
9909 @code{system(3)}, which is presumably 0 if the shell command succeeded.
9910 Note that which shell is used to invoke the command is system-dependent
9911 and environment-dependent.
9912
9913 This intrinsic is provided in both subroutine and function forms;
9914 however, only one form can be used in any given program unit.
9915
9916 @item @emph{Standard}:
9917 GNU extension
9918
9919 @item @emph{Class}:
9920 Subroutine, function
9921
9922 @item @emph{Syntax}:
9923 @multitable @columnfractions .80
9924 @item @code{CALL SYSTEM(COMMAND [, STATUS])}
9925 @item @code{STATUS = SYSTEM(COMMAND)}
9926 @end multitable
9927
9928 @item @emph{Arguments}:
9929 @multitable @columnfractions .15 .70
9930 @item @var{COMMAND} @tab Shall be of default @code{CHARACTER} type.
9931 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
9932 @end multitable
9933
9934 @item @emph{See also}:
9935 @end table
9936
9937
9938
9939 @node SYSTEM_CLOCK
9940 @section @code{SYSTEM_CLOCK} --- Time function
9941 @fnindex SYSTEM_CLOCK
9942 @cindex time, clock ticks
9943 @cindex clock ticks
9944
9945 @table @asis
9946 @item @emph{Description}:
9947 Determines the @var{COUNT} of milliseconds of wall clock time since
9948 the Epoch (00:00:00 UTC, January 1, 1970) modulo @var{COUNT_MAX},
9949 @var{COUNT_RATE} determines the number of clock ticks per second.
9950 @var{COUNT_RATE} and @var{COUNT_MAX} are constant and specific to
9951 @command{gfortran}.
9952
9953 If there is no clock, @var{COUNT} is set to @code{-HUGE(COUNT)}, and
9954 @var{COUNT_RATE} and @var{COUNT_MAX} are set to zero
9955
9956 @item @emph{Standard}:
9957 F95 and later
9958
9959 @item @emph{Class}:
9960 Subroutine
9961
9962 @item @emph{Syntax}:
9963 @code{CALL SYSTEM_CLOCK([COUNT, COUNT_RATE, COUNT_MAX])}
9964
9965 @item @emph{Arguments}:
9966 @item @emph{Arguments}:
9967 @multitable @columnfractions .15 .70
9968 @item @var{COUNT} @tab (Optional) shall be a scalar of type default
9969 @code{INTEGER} with @code{INTENT(OUT)}.
9970 @item @var{COUNT_RATE} @tab (Optional) shall be a scalar of type default
9971 @code{INTEGER} with @code{INTENT(OUT)}.
9972 @item @var{COUNT_MAX} @tab (Optional) shall be a scalar of type default
9973 @code{INTEGER} with @code{INTENT(OUT)}.
9974 @end multitable
9975
9976 @item @emph{Example}:
9977 @smallexample
9978 PROGRAM test_system_clock
9979 INTEGER :: count, count_rate, count_max
9980 CALL SYSTEM_CLOCK(count, count_rate, count_max)
9981 WRITE(*,*) count, count_rate, count_max
9982 END PROGRAM
9983 @end smallexample
9984
9985 @item @emph{See also}:
9986 @ref{DATE_AND_TIME}, @ref{CPU_TIME}
9987 @end table
9988
9989
9990
9991 @node TAN
9992 @section @code{TAN} --- Tangent function
9993 @fnindex TAN
9994 @fnindex DTAN
9995 @cindex trigonometric function, tangent
9996 @cindex tangent
9997
9998 @table @asis
9999 @item @emph{Description}:
10000 @code{TAN(X)} computes the tangent of @var{X}.
10001
10002 @item @emph{Standard}:
10003 F77 and later
10004
10005 @item @emph{Class}:
10006 Elemental function
10007
10008 @item @emph{Syntax}:
10009 @code{RESULT = TAN(X)}
10010
10011 @item @emph{Arguments}:
10012 @multitable @columnfractions .15 .70
10013 @item @var{X} @tab The type shall be @code{REAL(*)}.
10014 @end multitable
10015
10016 @item @emph{Return value}:
10017 The return value is of type @code{REAL(*)}. The kind type parameter is
10018 the same as @var{X}.
10019
10020 @item @emph{Example}:
10021 @smallexample
10022 program test_tan
10023 real(8) :: x = 0.165_8
10024 x = tan(x)
10025 end program test_tan
10026 @end smallexample
10027
10028 @item @emph{Specific names}:
10029 @multitable @columnfractions .20 .20 .20 .25
10030 @item Name @tab Argument @tab Return type @tab Standard
10031 @item @code{DTAN(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F95 and later
10032 @end multitable
10033
10034 @item @emph{See also}:
10035 @ref{ATAN}
10036 @end table
10037
10038
10039
10040 @node TANH
10041 @section @code{TANH} --- Hyperbolic tangent function
10042 @fnindex TANH
10043 @fnindex DTANH
10044 @cindex hyperbolic tangent
10045 @cindex hyperbolic function, tangent
10046 @cindex tangent, hyperbolic
10047
10048 @table @asis
10049 @item @emph{Description}:
10050 @code{TANH(X)} computes the hyperbolic tangent of @var{X}.
10051
10052 @item @emph{Standard}:
10053 F77 and later
10054
10055 @item @emph{Class}:
10056 Elemental function
10057
10058 @item @emph{Syntax}:
10059 @code{X = TANH(X)}
10060
10061 @item @emph{Arguments}:
10062 @multitable @columnfractions .15 .70
10063 @item @var{X} @tab The type shall be @code{REAL(*)}.
10064 @end multitable
10065
10066 @item @emph{Return value}:
10067 The return value is of type @code{REAL(*)} and lies in the range
10068 @math{ - 1 \leq tanh(x) \leq 1 }.
10069
10070 @item @emph{Example}:
10071 @smallexample
10072 program test_tanh
10073 real(8) :: x = 2.1_8
10074 x = tanh(x)
10075 end program test_tanh
10076 @end smallexample
10077
10078 @item @emph{Specific names}:
10079 @multitable @columnfractions .20 .20 .20 .25
10080 @item Name @tab Argument @tab Return type @tab Standard
10081 @item @code{DTANH(X)} @tab @code{REAL(8) X} @tab @code{REAL(8)} @tab F95 and later
10082 @end multitable
10083
10084 @item @emph{See also}:
10085 @ref{ATANH}
10086 @end table
10087
10088
10089
10090 @node TIME
10091 @section @code{TIME} --- Time function
10092 @fnindex TIME
10093 @cindex time, current
10094 @cindex current time
10095
10096 @table @asis
10097 @item @emph{Description}:
10098 Returns the current time encoded as an integer (in the manner of the
10099 UNIX function @code{time(3)}). This value is suitable for passing to
10100 @code{CTIME()}, @code{GMTIME()}, and @code{LTIME()}.
10101
10102 This intrinsic is not fully portable, such as to systems with 32-bit
10103 @code{INTEGER} types but supporting times wider than 32 bits. Therefore,
10104 the values returned by this intrinsic might be, or become, negative, or
10105 numerically less than previous values, during a single run of the
10106 compiled program.
10107
10108 See @ref{TIME8}, for information on a similar intrinsic that might be
10109 portable to more GNU Fortran implementations, though to fewer Fortran
10110 compilers.
10111
10112 @item @emph{Standard}:
10113 GNU extension
10114
10115 @item @emph{Class}:
10116 Function
10117
10118 @item @emph{Syntax}:
10119 @code{RESULT = TIME()}
10120
10121 @item @emph{Return value}:
10122 The return value is a scalar of type @code{INTEGER(4)}.
10123
10124 @item @emph{See also}:
10125 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK}, @ref{TIME8}
10126
10127 @end table
10128
10129
10130
10131 @node TIME8
10132 @section @code{TIME8} --- Time function (64-bit)
10133 @fnindex TIME8
10134 @cindex time, current
10135 @cindex current time
10136
10137 @table @asis
10138 @item @emph{Description}:
10139 Returns the current time encoded as an integer (in the manner of the
10140 UNIX function @code{time(3)}). This value is suitable for passing to
10141 @code{CTIME()}, @code{GMTIME()}, and @code{LTIME()}.
10142
10143 @emph{Warning:} this intrinsic does not increase the range of the timing
10144 values over that returned by @code{time(3)}. On a system with a 32-bit
10145 @code{time(3)}, @code{TIME8()} will return a 32-bit value, even though
10146 it is converted to a 64-bit @code{INTEGER(8)} value. That means
10147 overflows of the 32-bit value can still occur. Therefore, the values
10148 returned by this intrinsic might be or become negative or numerically
10149 less than previous values during a single run of the compiled program.
10150
10151 @item @emph{Standard}:
10152 GNU extension
10153
10154 @item @emph{Class}:
10155 Function
10156
10157 @item @emph{Syntax}:
10158 @code{RESULT = TIME8()}
10159
10160 @item @emph{Return value}:
10161 The return value is a scalar of type @code{INTEGER(8)}.
10162
10163 @item @emph{See also}:
10164 @ref{CTIME}, @ref{GMTIME}, @ref{LTIME}, @ref{MCLOCK8}, @ref{TIME}
10165
10166 @end table
10167
10168
10169
10170 @node TINY
10171 @section @code{TINY} --- Smallest positive number of a real kind
10172 @fnindex TINY
10173 @cindex limits, smallest number
10174 @cindex model representation, smallest number
10175
10176 @table @asis
10177 @item @emph{Description}:
10178 @code{TINY(X)} returns the smallest positive (non zero) number
10179 in the model of the type of @code{X}.
10180
10181 @item @emph{Standard}:
10182 F95 and later
10183
10184 @item @emph{Class}:
10185 Inquiry function
10186
10187 @item @emph{Syntax}:
10188 @code{RESULT = TINY(X)}
10189
10190 @item @emph{Arguments}:
10191 @multitable @columnfractions .15 .70
10192 @item @var{X} @tab Shall be of type @code{REAL}.
10193 @end multitable
10194
10195 @item @emph{Return value}:
10196 The return value is of the same type and kind as @var{X}
10197
10198 @item @emph{Example}:
10199 See @code{HUGE} for an example.
10200 @end table
10201
10202
10203
10204 @node TRANSFER
10205 @section @code{TRANSFER} --- Transfer bit patterns
10206 @fnindex TRANSFER
10207 @cindex bits, move
10208 @cindex type cast
10209
10210 @table @asis
10211 @item @emph{Description}:
10212 Interprets the bitwise representation of @var{SOURCE} in memory as if it
10213 is the representation of a variable or array of the same type and type
10214 parameters as @var{MOLD}.
10215
10216 This is approximately equivalent to the C concept of @emph{casting} one
10217 type to another.
10218
10219 @item @emph{Standard}:
10220 F95 and later
10221
10222 @item @emph{Class}:
10223 Transformational function
10224
10225 @item @emph{Syntax}:
10226 @code{RESULT = TRANSFER(SOURCE, MOLD[, SIZE])}
10227
10228 @item @emph{Arguments}:
10229 @multitable @columnfractions .15 .70
10230 @item @var{SOURCE} @tab Shall be a scalar or an array of any type.
10231 @item @var{MOLD} @tab Shall be a scalar or an array of any type.
10232 @item @var{SIZE} @tab (Optional) shall be a scalar of type
10233 @code{INTEGER}.
10234 @end multitable
10235
10236 @item @emph{Return value}:
10237 The result has the same type as @var{MOLD}, with the bit level
10238 representation of @var{SOURCE}. If @var{SIZE} is present, the result is
10239 a one-dimensional array of length @var{SIZE}. If @var{SIZE} is absent
10240 but @var{MOLD} is an array (of any size or shape), the result is a one-
10241 dimensional array of the minimum length needed to contain the entirety
10242 of the bitwise representation of @var{SOURCE}. If @var{SIZE} is absent
10243 and @var{MOLD} is a scalar, the result is a scalar.
10244
10245 If the bitwise representation of the result is longer than that of
10246 @var{SOURCE}, then the leading bits of the result correspond to those of
10247 @var{SOURCE} and any trailing bits are filled arbitrarily.
10248
10249 When the resulting bit representation does not correspond to a valid
10250 representation of a variable of the same type as @var{MOLD}, the results
10251 are undefined, and subsequent operations on the result cannot be
10252 guaranteed to produce sensible behavior. For example, it is possible to
10253 create @code{LOGICAL} variables for which @code{@var{VAR}} and
10254 @code{.NOT.@var{VAR}} both appear to be true.
10255
10256 @item @emph{Example}:
10257 @smallexample
10258 PROGRAM test_transfer
10259 integer :: x = 2143289344
10260 print *, transfer(x, 1.0) ! prints "NaN" on i686
10261 END PROGRAM
10262 @end smallexample
10263 @end table
10264
10265
10266
10267 @node TRANSPOSE
10268 @section @code{TRANSPOSE} --- Transpose an array of rank two
10269 @fnindex TRANSPOSE
10270 @cindex array, transpose
10271 @cindex matrix, transpose
10272 @cindex transpose
10273
10274 @table @asis
10275 @item @emph{Description}:
10276 Transpose an array of rank two. Element (i, j) of the result has the value
10277 @code{MATRIX(j, i)}, for all i, j.
10278
10279 @item @emph{Standard}:
10280 F95 and later
10281
10282 @item @emph{Class}:
10283 Transformational function
10284
10285 @item @emph{Syntax}:
10286 @code{RESULT = TRANSPOSE(MATRIX)}
10287
10288 @item @emph{Arguments}:
10289 @multitable @columnfractions .15 .70
10290 @item @var{MATRIX} @tab Shall be an array of any type and have a rank of two.
10291 @end multitable
10292
10293 @item @emph{Return value}:
10294 The result has the the same type as @var{MATRIX}, and has shape
10295 @code{(/ m, n /)} if @var{MATRIX} has shape @code{(/ n, m /)}.
10296 @end table
10297
10298
10299
10300 @node TRIM
10301 @section @code{TRIM} --- Remove trailing blank characters of a string
10302 @fnindex TRIM
10303 @cindex string, remove trailing whitespace
10304
10305 @table @asis
10306 @item @emph{Description}:
10307 Removes trailing blank characters of a string.
10308
10309 @item @emph{Standard}:
10310 F95 and later
10311
10312 @item @emph{Class}:
10313 Transformational function
10314
10315 @item @emph{Syntax}:
10316 @code{RESULT = TRIM(STRING)}
10317
10318 @item @emph{Arguments}:
10319 @multitable @columnfractions .15 .70
10320 @item @var{STRING} @tab Shall be a scalar of type @code{CHARACTER(*)}.
10321 @end multitable
10322
10323 @item @emph{Return value}:
10324 A scalar of type @code{CHARACTER(*)} which length is that of @var{STRING}
10325 less the number of trailing blanks.
10326
10327 @item @emph{Example}:
10328 @smallexample
10329 PROGRAM test_trim
10330 CHARACTER(len=10), PARAMETER :: s = "GFORTRAN "
10331 WRITE(*,*) LEN(s), LEN(TRIM(s)) ! "10 8", with/without trailing blanks
10332 END PROGRAM
10333 @end smallexample
10334
10335 @item @emph{See also}:
10336 @ref{ADJUSTL}, @ref{ADJUSTR}
10337 @end table
10338
10339
10340
10341 @node TTYNAM
10342 @section @code{TTYNAM} --- Get the name of a terminal device.
10343 @fnindex TTYNAM
10344 @cindex system, terminal
10345
10346 @table @asis
10347 @item @emph{Description}:
10348 Get the name of a terminal device. For more information,
10349 see @code{ttyname(3)}.
10350
10351 This intrinsic is provided in both subroutine and function forms;
10352 however, only one form can be used in any given program unit.
10353
10354 @item @emph{Standard}:
10355 GNU extension
10356
10357 @item @emph{Class}:
10358 Subroutine, function
10359
10360 @item @emph{Syntax}:
10361 @multitable @columnfractions .80
10362 @item @code{CALL TTYNAM(UNIT, NAME)}
10363 @item @code{NAME = TTYNAM(UNIT)}
10364 @end multitable
10365
10366 @item @emph{Arguments}:
10367 @multitable @columnfractions .15 .70
10368 @item @var{UNIT} @tab Shall be a scalar @code{INTEGER(*)}.
10369 @item @var{NAME} @tab Shall be of type @code{CHARACTER(*)}.
10370 @end multitable
10371
10372 @item @emph{Example}:
10373 @smallexample
10374 PROGRAM test_ttynam
10375 INTEGER :: unit
10376 DO unit = 1, 10
10377 IF (isatty(unit=unit)) write(*,*) ttynam(unit)
10378 END DO
10379 END PROGRAM
10380 @end smallexample
10381
10382 @item @emph{See also}:
10383 @ref{ISATTY}
10384 @end table
10385
10386
10387
10388 @node UBOUND
10389 @section @code{UBOUND} --- Upper dimension bounds of an array
10390 @fnindex UBOUND
10391 @cindex array, upper bound
10392
10393 @table @asis
10394 @item @emph{Description}:
10395 Returns the upper bounds of an array, or a single upper bound
10396 along the @var{DIM} dimension.
10397 @item @emph{Standard}:
10398 F95 and later
10399
10400 @item @emph{Class}:
10401 Inquiry function
10402
10403 @item @emph{Syntax}:
10404 @code{RESULT = UBOUND(ARRAY [, DIM [, KIND]])}
10405
10406 @item @emph{Arguments}:
10407 @multitable @columnfractions .15 .70
10408 @item @var{ARRAY} @tab Shall be an array, of any type.
10409 @item @var{DIM} @tab (Optional) Shall be a scalar @code{INTEGER(*)}.
10410 @item @var{KIND}@tab (Optional) An @code{INTEGER} initialization
10411 expression indicating the kind parameter of
10412 the result.
10413 @end multitable
10414
10415 @item @emph{Return value}:
10416 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
10417 @var{KIND} is absent, the return value is of default integer kind.
10418 If @var{DIM} is absent, the result is an array of the upper bounds of
10419 @var{ARRAY}. If @var{DIM} is present, the result is a scalar
10420 corresponding to the upper bound of the array along that dimension. If
10421 @var{ARRAY} is an expression rather than a whole array or array
10422 structure component, or if it has a zero extent along the relevant
10423 dimension, the upper bound is taken to be the number of elements along
10424 the relevant dimension.
10425
10426 @item @emph{See also}:
10427 @ref{LBOUND}
10428 @end table
10429
10430
10431
10432 @node UMASK
10433 @section @code{UMASK} --- Set the file creation mask
10434 @fnindex UMASK
10435 @cindex file system, file creation mask
10436
10437 @table @asis
10438 @item @emph{Description}:
10439 Sets the file creation mask to @var{MASK} and returns the old value in
10440 argument @var{OLD} if it is supplied. See @code{umask(2)}.
10441
10442 @item @emph{Standard}:
10443 GNU extension
10444
10445 @item @emph{Class}:
10446 Subroutine
10447
10448 @item @emph{Syntax}:
10449 @code{CALL UMASK(MASK [, OLD])}
10450
10451 @item @emph{Arguments}:
10452 @multitable @columnfractions .15 .70
10453 @item @var{MASK} @tab Shall be a scalar of type @code{INTEGER(*)}.
10454 @item @var{MASK} @tab (Optional) Shall be a scalar of type
10455 @code{INTEGER(*)}.
10456 @end multitable
10457
10458 @end table
10459
10460
10461
10462 @node UNLINK
10463 @section @code{UNLINK} --- Remove a file from the file system
10464 @fnindex UNLINK
10465 @cindex file system, remove file
10466
10467 @table @asis
10468 @item @emph{Description}:
10469 Unlinks the file @var{PATH}. A null character (@code{CHAR(0)}) can be
10470 used to mark the end of the name in @var{PATH}; otherwise, trailing
10471 blanks in the file name are ignored. If the @var{STATUS} argument is
10472 supplied, it contains 0 on success or a nonzero error code upon return;
10473 see @code{unlink(2)}.
10474
10475 This intrinsic is provided in both subroutine and function forms;
10476 however, only one form can be used in any given program unit.
10477
10478 @item @emph{Standard}:
10479 GNU extension
10480
10481 @item @emph{Class}:
10482 Subroutine, function
10483
10484 @item @emph{Syntax}:
10485 @multitable @columnfractions .80
10486 @item @code{CALL UNLINK(PATH [, STATUS])}
10487 @item @code{STATUS = UNLINK(PATH)}
10488 @end multitable
10489
10490 @item @emph{Arguments}:
10491 @multitable @columnfractions .15 .70
10492 @item @var{PATH} @tab Shall be of default @code{CHARACTER} type.
10493 @item @var{STATUS} @tab (Optional) Shall be of default @code{INTEGER} type.
10494 @end multitable
10495
10496 @item @emph{See also}:
10497 @ref{LINK}, @ref{SYMLNK}
10498 @end table
10499
10500
10501
10502 @node UNPACK
10503 @section @code{UNPACK} --- Unpack an array of rank one into an array
10504 @fnindex UNPACK
10505 @cindex array, unpacking
10506 @cindex array, increase dimension
10507 @cindex array, scatter elements
10508
10509 @table @asis
10510 @item @emph{Description}:
10511 Store the elements of @var{VECTOR} in an array of higher rank.
10512
10513 @item @emph{Standard}:
10514 F95 and later
10515
10516 @item @emph{Class}:
10517 Transformational function
10518
10519 @item @emph{Syntax}:
10520 @code{RESULT = UNPACK(VECTOR, MASK, FIELD)}
10521
10522 @item @emph{Arguments}:
10523 @multitable @columnfractions .15 .70
10524 @item @var{VECTOR} @tab Shall be an array of any type and rank one. It
10525 shall have at least as many elements as @var{MASK} has @code{TRUE} values.
10526 @item @var{MASK} @tab Shall be an array of type @code{LOGICAL}.
10527 @item @var{FIELD} @tab Shall be of the sam type as @var{VECTOR} and have
10528 the same shape as @var{MASK}.
10529 @end multitable
10530
10531 @item @emph{Return value}:
10532 The resulting array corresponds to @var{FIELD} with @code{TRUE} elements
10533 of @var{MASK} replaced by values from @var{VECTOR} in array element order.
10534
10535 @item @emph{Example}:
10536 @smallexample
10537 PROGRAM test_unpack
10538 integer :: vector(2) = (/1,1/)
10539 logical :: mask(4) = (/ .TRUE., .FALSE., .FALSE., .TRUE. /)
10540 integer :: field(2,2) = 0, unity(2,2)
10541
10542 ! result: unity matrix
10543 unity = unpack(vector, reshape(mask, (/2,2/)), field)
10544 END PROGRAM
10545 @end smallexample
10546
10547 @item @emph{See also}:
10548 @ref{PACK}, @ref{SPREAD}
10549 @end table
10550
10551
10552
10553 @node VERIFY
10554 @section @code{VERIFY} --- Scan a string for the absence of a set of characters
10555 @fnindex VERIFY
10556 @cindex string, find missing set
10557
10558 @table @asis
10559 @item @emph{Description}:
10560 Verifies that all the characters in a @var{SET} are present in a @var{STRING}.
10561
10562 If @var{BACK} is either absent or equals @code{FALSE}, this function
10563 returns the position of the leftmost character of @var{STRING} that is
10564 not in @var{SET}. If @var{BACK} equals @code{TRUE}, the rightmost position
10565 is returned. If all characters of @var{SET} are found in @var{STRING}, the
10566 result is zero.
10567
10568 @item @emph{Standard}:
10569 F95 and later
10570
10571 @item @emph{Class}:
10572 Elemental function
10573
10574 @item @emph{Syntax}:
10575 @code{RESULT = VERIFY(STRING, SET[, BACK [, KIND]])}
10576
10577 @item @emph{Arguments}:
10578 @multitable @columnfractions .15 .70
10579 @item @var{STRING} @tab Shall be of type @code{CHARACTER(*)}.
10580 @item @var{SET} @tab Shall be of type @code{CHARACTER(*)}.
10581 @item @var{BACK} @tab (Optional) shall be of type @code{LOGICAL}.
10582 @item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
10583 expression indicating the kind parameter of
10584 the result.
10585 @end multitable
10586
10587 @item @emph{Return value}:
10588 The return value is of type @code{INTEGER} and of kind @var{KIND}. If
10589 @var{KIND} is absent, the return value is of default integer kind.
10590
10591 @item @emph{Example}:
10592 @smallexample
10593 PROGRAM test_verify
10594 WRITE(*,*) VERIFY("FORTRAN", "AO") ! 1, found 'F'
10595 WRITE(*,*) VERIFY("FORTRAN", "FOO") ! 3, found 'R'
10596 WRITE(*,*) VERIFY("FORTRAN", "C++") ! 1, found 'F'
10597 WRITE(*,*) VERIFY("FORTRAN", "C++", .TRUE.) ! 7, found 'N'
10598 WRITE(*,*) VERIFY("FORTRAN", "FORTRAN") ! 0' found none
10599 END PROGRAM
10600 @end smallexample
10601
10602 @item @emph{See also}:
10603 @ref{SCAN}, @ref{INDEX}
10604 @end table
10605
10606
10607
10608 @node XOR
10609 @section @code{XOR} --- Bitwise logical exclusive OR
10610 @fnindex XOR
10611 @cindex bitwise logical exclusive or
10612 @cindex logical exclusive or, bitwise
10613
10614 @table @asis
10615 @item @emph{Description}:
10616 Bitwise logical exclusive or.
10617
10618 This intrinsic routine is provided for backwards compatibility with
10619 GNU Fortran 77. For integer arguments, programmers should consider
10620 the use of the @ref{IEOR} intrinsic defined by the Fortran standard.
10621
10622 @item @emph{Standard}:
10623 GNU extension
10624
10625 @item @emph{Class}:
10626 Function
10627
10628 @item @emph{Syntax}:
10629 @code{RESULT = XOR(X, Y)}
10630
10631 @item @emph{Arguments}:
10632 @multitable @columnfractions .15 .70
10633 @item @var{X} @tab The type shall be either @code{INTEGER(*)} or @code{LOGICAL}.
10634 @item @var{Y} @tab The type shall be either @code{INTEGER(*)} or @code{LOGICAL}.
10635 @end multitable
10636
10637 @item @emph{Return value}:
10638 The return type is either @code{INTEGER(*)} or @code{LOGICAL}
10639 after cross-promotion of the arguments.
10640
10641 @item @emph{Example}:
10642 @smallexample
10643 PROGRAM test_xor
10644 LOGICAL :: T = .TRUE., F = .FALSE.
10645 INTEGER :: a, b
10646 DATA a / Z'F' /, b / Z'3' /
10647
10648 WRITE (*,*) XOR(T, T), XOR(T, F), XOR(F, T), XOR(F, F)
10649 WRITE (*,*) XOR(a, b)
10650 END PROGRAM
10651 @end smallexample
10652
10653 @item @emph{See also}:
10654 F95 elemental function: @ref{IEOR}
10655 @end table
10656
10657