General-Purpose Math Intrinsics The intrinsics listed in table 9-2 perform "general" mathematical functions, such as square root, natural logarithm, and maximum number of listed values. None of the MIN or MAX intrinsics, nor the LOG10 or IMAG intrinsics can be passed as actual arguments. Also note the following: * All general-purpose math intrinsics are elemental. This means they can be used with array arguments. * In the following table, the superscript 1 indicates intrinsics that can be accessed only with the $HP9000_800 INTRINSICS compiler directive. Table 14-2. General-Purpose Math Intrinsics ------------------------------------------------------------------------------------------------------ | | | | | | | | Generic | Description | Args | Specific | Arg | Function | | Name | | | Name | Type | Type | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | ABS | Absolute value. | 1 | IABS | Integer*4 | Integer*4 | | | |a| | | JIABS | Integer*4 | Integer*4 | | | [See note 1] | | HABS | Integer*2 | Integer*2 | | | | | IIABS | Integer*2 | Integer*2 | | | | | BABS1 | Logical*1 | Logical*1 | | | | | ABS | Real | Real | | | | | DABS | Double | Double | | | | | CABS | Complex*8 | Real | | | | | ZABS | Complex*16 | Double | | | | | CDABS | Complex*16 | Double | | | | | QABS | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | AINT | Truncation. | 1 | AINT | Real | Real | | | | | DINT | Double | Double | | | | | DDINT | Double | Double | | | | | QINT | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | ANINT | Nearest Whole Number: | 1 | ANINT | Real | Real | | | AINT(a + .5) if a >= 0; | | DNINT | Double | Double | | | AINT(a - .5) if a < 0 | | QNINT | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | CONJG | Conjugate of a complex | 1 | CONJG | Complex | Complex | | | argument: (ar, -ai) | | DCONJG | Complex*16 | Complex*16 | | | [See note 2] | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | DIM | Positive difference: | 2 | IDIM | Integer*4 | Integer*4 | | | | | JIDIM | Integer*4 | Integer*4 | | | a - b if a > b; | | HDIM | Integer*2 | Integer*2 | | | 0 if a <= b | | IIDIM | Integer*2 | Integer*2 | | | | | BDIM1 | Logical*1 | Logical*1 | | | | | DIM | Real | Real | | | | | DDIM | Double | Double | | | | | QDIM | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ Table 14-2. General-Purpose Math Intrinsics (cont.) ------------------------------------------------------------------------------------------------------ | | | | | | | | Generic | Description | Args | Specific | Arg | Function | | Name | | | Name | Type | Type | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Double precision product: | 2 | DPROD | Real | Double | | | | | | | | | | a * b | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | REAL*16 product | 2 | QPROD | Double | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | EXP | Exponential: | 1 | EXP | Real | Real | | | | | DEXP | Double | Double | | | ea | | CEXP | Complex*8 | Complex*8 | | | | | ZEXP | Complex*16 | Complex*16 | | | | | CDEXP | Complex*16 | Complex*16 | | | | | QEXP | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | IABS | Integer absolute value. | 1 | IABS | Integer*4 | Integer*4 | | | |a| | | JIABS | Integer*4 | Integer*4 | | | | | HABS | Integer*2 | Integer*2 | | | | | IIABS | Integer*2 | Integer*2 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | IDIM | Integer positive difference: | 2 | IDIM | Integer*4 | Integer*4 | | | | | JIDIM | Integer*4 | Integer*4 | | | a - b if a > b; | | HDIM | Integer*2 | Integer*2 | | | 0 if a <= b | | IIDIM | Integer*2 | Integer*2 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | IMAG | Imaginary part of a complex | 1 | AIMAG | Complex*8 | Real | | | number: ai | | DIMAG | Complex*16 | Double | | | [See note 1] | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | ISIGN | Integer transfer of sign: | 2 | ISIGN | Integer*4 | Integer*4 | | | |a| if b >= 0; | | JISIGN | Integer*4 | Integer*4 | | | -|a| if b < 0 | | HSIGN | Integer*2 | Integer*2 | | | | | IISIGN | Integer*2 | Integer*2 | | | | | | | | ------------------------------------------------------------------------------------------------------ Table 14-2. General-Purpose Math Intrinsics (cont.) ------------------------------------------------------------------------------------------------------ | | | | | | | | Generic | Description | Args | Specific | Arg | Function | | Name | | | Name | Type | Type | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | LOG | Natural logarithm: | 1 | ALOG | Real | Real | | | ln a | | DLOG | Double | Double | | | | | CLOG | Complex | Complex | | | | | ZLOG | Complex*16 | Complex*16 | | | | | CDLOG | Complex*16 | Complex*16 | | | | | QLOG | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | LOG10 | Common logarithm: | 1 | ALOG10 | Real | Real | | | log10 a | | DLOG10 | Double | Double | | | | | QLOG10 | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | MAX | Return the largest value | >=2 | MAX0 | Integer | Integer | | | from a list of values: | | IMAX0 | Integer*2 | Integer*2 | | | max(a,b,...) | | JMAX0 | Integer*4 | Integer*4 | | | | | AMAX1 | Real | Real | | | | | DMAX1 | Double | Double | | | | | AMAX0 | Integer | Real | | | | | AIMAX0 | Integer*2 | Real | | | | | AJMAX0 | Integer*4 | Real | | | | | MAX1 | Real | Integer | | | | | IMAX1 | Real | Integer*2 | | | | | JMAX1 | Real | Integer*4 | | | | | QMAX1 | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | MIN | Return the smallest value | >=2 | MIN0 | Integer | Integer | | | from argument list: | | IMIN0 | Integer*2 | Integer*2 | | | min(a,b,...) | | JMIN0 | Integer*4 | Integer*4 | | | | | AMIN1 | Real | Real | | | | | DMIN1 | Double | Double | | | | | AMIN0 | Integer | Real | | | | | AIMIN0 | Integer*2 | Real | | | | | AJMIN0 | Integer*4 | Real | | | | | MIN1 | Real | Integer | | | | | IMIN1 | Real | Integer*2 | | | | | JMIN1 | Real | Integer*4 | | | | | QMIN1 | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ Table 14-2. General-Purpose Math Intrinsics (cont.) ------------------------------------------------------------------------------------------------------ | | | | | | | | Generic | Description | Args | Specific | Arg | Function | | Name | | | Name | Type | Type | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | MOD | Remainder: | 2 | MOD | Integer*4 | Integer*4 | | | | | JMOD | Integer*4 | Integer*4 | | | a - INT(a/b) * b | | HMOD | Integer*2 | Integer*2 | | | [See INT intrinsic description | | IMOD | Integer*2 | Integer*2 | | | under "Type Conversion | | BMOD1 | Logical*1 | Logical*1 | | | Intrinsics"] | | AMOD | Real | Real | | | | | DMOD | Double | Double | | | | | QMOD | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | NINT | Nearest integer: | 1 | NINT | Real | Integer | | | INT(a + .5) if a >= 0; | | ININT | Real | Integer*2 | | | INT(a - .5) if a < 0 | | JNINT | Real | Integer*4 | | | | | IDNINT | Double | Integer | | | | | IIDNNT | Double | Integer*2 | | | | | JIDNNT | Double | Integer*4 | | | | | IQNINT | Real*16 | Integer | | | | | IIQNNT | Real*16 | Integer*2 | | | | | JIQNNT | Real*16 | Integer*4 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | SIGN | Transfer of sign: | 2 | ISIGN | Integer*4 | Integer*4 | | | |a| if b >= 0; | | JISIGN | Integer*4 | Integer*4 | | | -|a| if b < 0 | | HSIGN | Integer*2 | Integer*2 | | | | | IISIGN | Integer*2 | Integer*2 | | | | | BSIGN1 | Logical*1 | Logical*1 | | | | | SIGN | Real | Real | | | | | DSIGN | Double | Double | | | | | QSIGN | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | SQRT | Square root | 1 | SQRT | Real | Real | | | | | DSQRT | Double | Double | | | | | CSQRT | Complex | Complex | | | | | ZSQRT | Complex*16 | Complex*16 | | | | | CDSQRT | Complex*16 | Complex*16 | | | | | QSQRT | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ Notes on General-Purpose Math Intrinsics 1. A complex value is expressed as an ordered pair of reals or doubles, (ar,ai), where ar is the real part and ai is the imaginary part. ABS or CABS is defined as: SQRT(ar2 + ai2) 2. CONJG is defined as (ar,-ai ); refer to note 1 above. Character Intrinsics Table 9-3 lists intrinsics used for character data manipulation. ________________________________________________________________________ NOTE The LGE, LGT, LLE, and LLT intrinsics cannot be passed as actual arguments. ________________________________________________________________________ Also, note the following: * All character intrinsics, except LEN are elemental intrinsics. This means they can be used with array arguments. * In the following table, the superscript 1 indicates intrinsics that can be accessed only with the $HP9000_800 INTRINSICS compiler directive. Table 14-3. Character Intrinsics ------------------------------------------------------------------------------------------------------ | | | | | | | | Generic | Description | Args | Specific | Arg | Function | | Name | | | Name | Type | Type | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Conversion from numeric | 1 | CHAR | Integer*4 | Character | | | to character. | | | Integer*2 | Character | | | | | | Logical*1 | Character | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Conversion to integer | 1 | ICHAR | Character | Integer | | | from character. | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Conversion to INTEGER*2 | 1 | INUM1 | Character | Integer*2 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Conversion to INTEGER*4. | 1 | JNUM1 | Character | Integer | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Conversion to real. | 1 | RNUM1 | Character | Real | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Conversion to double | 1 | DNUM1 | Character | Double | | | precision. | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Conversion to REAL*16. | 1 | QNUM1 | Character | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Location of substring b in | 2 | INDEX | Character | Integer | | | string a: index(a,b). | | | | | | | [See note 1] | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Length of character string. | 1 | LEN | Character | Integer | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Lexically greater than | 2 | LGE | Character | Logical | | | or equal to: a >= b | | | | | | | [See note 2] | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Lexically greater than: | 2 | LGT | Character | Logical | | | | | | | | | | a > b [See note 2] | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Lexically less than or equal | 2 | LLE | Character | Logical | | | to: a <= b [See note 2] | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Lexically less than: a b | 2 | LLT | Character | Logical | | | [See note 2] | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ Notes on Character Intrinsics 1. INDEX(a,b) returns an integer value representing the starting position within character string a of a substring identical to string b. If b occurs more than once within a, INDEX(a,b) returns the starting position of the first occurrence. If b does not occur in a, the value 0 is returned. If LEN(a) LT LEN(b), 0 is also returned. 2. LGE(a,b) returns the value .TRUE. if a is the same as b or if a follows b in ASCII collating sequence; otherwise it returns the value .FALSE.. LGT(a,b) returns the value .TRUE. if a follows b in ASCII collating sequence; otherwise it returns the value .FALSE.. LLE(a,b) returns the value .TRUE. if a is the same as b or if a precedes b in ASCII collating sequence; otherwise it returns the value .FALSE.. LLT(a,b) returns the value .TRUE. if a precedes b in ASCII collating sequence; otherwise it returns the value .FALSE.. If the operands for LGE, LGT, LLE, and LLT are of unequal length, the shorter operand is treated as if padded on the right with blanks to the length of the longer operand. In FORTRAN, LGE, LGT, LLE, and LLT behave exactly the same as .GE., .GT., .LE., and .LT., respectively, because HP9000 computers use the standard ASCII character set. The former group should be used for code that might be ported to another system, because they normally obey the ASCII collating sequence. The only time that LGE, LGT, LLE, and LLT do not obey the ASCII collating sequence is when another collating sequence has been selected with the $NLS or $NLS COMPARE directive. (For more information about these directives, see Chapter 20 .) Using the latter group on another system may produce different results. For example, the following is always true: LLT ('0','A') However, the following may be false on some systems: ('0' .LT. 'A') Trigonometric Intrinsics Table 9-4 lists all available intrinsics for performing trigonometric functions, such as sine, cosine, and tangent calculations. In general, these intrinsics compute values based on radian arguments. However, intrinsic names that end with the letter D compute values based on degrees. For example, SIN computes the sine of an argument expressed in radians. SIND computes the sine of an argument expressed in degrees. ________________________________________________________________________ NOTE The approximate limit for the values passed to sine and cosine intrinsics is 2.98E8 (2.98*108) for double precision values, and 1.29E4 (1.29*104) for real values. For tangent intrinsics, the limits are 1.49E8 (1.49*108) for double precision values, 6.43E3 (6.43*103) for real values. ________________________________________________________________________ Also note that all trigonometric intrinsics are elemental. This means they can be used with array arguments. Table 14-4. Trigonometric Intrinsics ------------------------------------------------------------------------------------------------------ | | | | | | | | Generic | Description | Args | Specific | Arg | Function | | Name | | | Name | Type | Type | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | ACOS | Arccosine in radians: | 1 | ACOS | Real | Real | | | arccos(a) | | DACOS | Double | Double | | | | | QACOS | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | ACOSD | Arccosine in degrees: | 1 | ACOSD | Real | Real | | | arccosd(a) | | DACOSD | Double | Double | | | | | QACOSD | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ Table 14-4. Trigonometric Intrinsics (cont.) ------------------------------------------------------------------------------------------------------ | | | | | | | | Generic | Description | Args | Specific | Arg | Function | | Name | | | Name | Type | Type | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | ACOSH | Hyperbolic arccosine of | 1 | ACOSH | Real | Real | | | radians: acosh(a) | | DACOSH | Double | Double | | | | | QACOSH | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | ASIN | Arcsine of radians: | 1 | ASIN | Real | Real | | | arcsin(a) | | DASIN | Double | Double | | | | | QASIN | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | ASIND | Arcsine of degrees: | 1 | ASIND | Real | Real | | | arcsind(a) | | DASIND | Double | Double | | | | | QASIND | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | ASINH | Hyperbolic arcsine of | 1 | ASINH | Real | Real | | | radians: asinh(a) | | DASINH | Double | Double | | | | | QASINH | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | ATAN | Arctangent of radians: | 1 | ATAN | Real | Real | | | arctan(a) | | DATAN | Double | Double | | | | | QATAN | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | ATAND | Arctangent of degrees: | 1 | ATAND | Real | Real | | | arctand(a) | | DATAND | Double | Double | | | | | QATAND | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | ATAN2 | Arctangent of a/b in | 2 | ATAN2 | Real | Real | | | radians: arctan(a/b) | | DATAN2 | Double | Double | | | | | QATAN2 | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | ATAN2D | Arctangent of a/b in | 2 | ATAN2D | Real | Real | | | degrees: arctand(a/b) | | DATAN2D | Double | Double | | | | | QATAN2D | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ Table 14-4. Trigonometric Intrinsics (cont.) ------------------------------------------------------------------------------------------------------ | | | | | | | | Generic | Description | Args | Specific | Arg | Function | | Name | | | Name | Type | Type | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | ATANH | Hyperbolic arctangent: | 1 | ATANH | Real | Real | | | arctan(a) | | DATANH | Double | Double | | | | | QATANH | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | COS | Cosine of radians: | 1 | COS | Real | Real | | | cos(a) | | DCOS | Double | Double | | | | | CCOS | Complex*8 | Complex*8 | | | | | ZCOS | Complex*16 | Complex*16 | | | | | CDCOS | Complex*16 | Complex*16 | | | | | QCOS | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | COSD | Cosine of degrees: | 1 | COSD | Real | Real | | | cosd(a) | | DCOSD | Double | Double | | | | | QCOSD | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | COSH | Hyperbolic cosine of radians: | 1 | COSH | Real | Real | | | cosh(a) | | DCOSH | Double | Double | | | | | QCOSH | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | SIN | Sine of radians: | 1 | SIN | Real | Real | | | sin(a) | | DSIN | Double | Double | | | | | CSIN | Complex*8 | Complex*8 | | | | | ZSIN | Complex*16 | Complex*16 | | | | | CDSIN | Complex*16 | Complex*16 | | | | | QSIN | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | SIND | Sine of degrees: | 1 | SIND | Real | Real | | | sind(a) | | DSIND | Double | Double | | | | | QSIND | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | SINH | Hyperbolic sine of radians: | 1 | SINH | Real | Real | | | sinh(a) | | DSINH | Double | Double | | | | | QSINH | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ Table 14-4. Trigonometric Intrinsics (cont.) ------------------------------------------------------------------------------------------------------ | | | | | | | | Generic | Description | Args | Specific | Arg | Function | | Name | | | Name | Type | Type | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | TAN | Tangent of radians: | 1 | TAN | Real | Real | | | tan(a) | | DTAN | Double | Double | | | | | CTAN | Complex*8 | Complex*8 | | | | | ZTAN | Complex*16 | Complex*16 | | | | | QTAN | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | TAND | Tangent of degrees: | 1 | TAND | Real | Real | | | tand(a) | | DTAND | Double | Double | | | | | QTAND | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | TANH | Hyperbolic tangent of | 1 | TANH | Real | Real | | | radians: tanh(a) | | DTANH | Double | Double | | | | | QTANH | Real*16 | Real*16 | | | | | | | | ------------------------------------------------------------------------------------------------------ HP-UX Intrinsics Table 14-8 lists intrinsics that are used to communicate with HP-UX. Specifically, these intrinsics can be used to get command line arguments from within a program or to do HP-UX stream input/output. In the following table, the superscript 1 indicates intrinsics that can be accessed only with the $HP9000_800 INTRINSICS compiler directive. Table 14-8. HP-UX Intrinsics ------------------------------------------------------------------------------------------------------ | | | | | | | | Generic | Description | Args | Specific | Arg | Function | | Name | | | Name | Type | Type | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Terminates a FORTRAN program. | 0 | ABORT1 | N/A | N/A | | | [See note 1] | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Get an HP-UX file descriptor. | 1 | FNUM | Integer | Integer | | | [See note 2] | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Attaches an HP-UX file | 3 | FSET1 | Integer | N/A | | | descriptor to a given unit. | | | | | | | [See note 3] | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Retrieve C-language FILE | 1 | FSTREAM | Integer | Integer*4 | | | stream pointer. [See note 4] | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Get number of arguments. [See | 2 | GETARG1 | N/A | Integer | | | note 5] | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ Table 14-8. HP-UX Intrinsics (cont.) ------------------------------------------------------------------------------------------------------ | | | | | | | | Generic | Description | Args | Specific | Arg | Function | | Name | | | Name | Type | Type | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Returns the value of the | 2 | GETENV | Character | Character | | | specified HP-UX environment | | | | | | | variable [See note 6]. | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Get number of arguments. [See | 0 | IARGC | N/A | Integer | | | note 7] | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Get command-line arguments. | 3 | IGETARG | [See note 7] | Integer | | | [See note 7] | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Free a block of memory. | 1 | FREE | FORTRAN | N/A | | | [See note 8] | | | pointer | | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Allocate a block of memory. | 1 | MALLOC | Integer*4 | FORTRAN | | | [See note 9] | | | | pointer | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Returns the time accounting | 0 | MCLOCK1 | N/A | Integer | | | for a FORTRAN program. | | | | | | | [See note 10] | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Issues a shell command from a | 1 | SYSTEM | Character | N/A | | | FORTRAN program. [See note | | | | | | | 11] | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ Notes on HP-UX Intrinsics 1. When ABORT terminates the program that calls it, all open files are closed, truncating them to the current position of the file pointer. In addition, the following message is printed to standard error output: FORTRAN abort routine called 2. For an open FORTRAN unit number u, FNUM(u) returns the system file descriptor associated with the FORTRAN unit number. When the unit number is not assigned to a file, FNUM returns the value -1. 3. The syntax of this intrinsic follows: CALL FSET(unit, newfd, oldfd) unit is the desired unit to be attached. newfd is the new HP-UX file descriptor number to attach. oldfd is an INTEGER*4 variable that contains the value of the old file descriptor, or 0 if there was no file descriptor. 4. For an open FORTRAN unit number u, FSTREAM(u) returns the C "FILE*" pointer associated with the FORTRAN unit number. When the unit number is not assigned to a file, FSTREAM returns the value -1. 5. GETARG is similar to IGETARG except that GETARG is called as a subroutine instead of as a function. It accepts two arguments: n and str. n is an integer specifying which command-line argument is requested. When n=1, it returns the program name (unlike IGETARG which returns the program name when n equals zero). str is a character variable that will contain the requested command-line argument, padded with blanks on the end. For details on the use of these intrinsics, see Chapter 10 of the HP FORTRAN/9000 Programmer's Guide. 6. GETENV returns the character-string value of its first argument (the environment variable) through the character variable of its second argument. The syntax for GETENV is: CHARACTER*n c CALL GETENV( "env_var_name", c) You must declare the second argument (c) with a large enough size (n) to hold the value of the environment variable. If the specified environment variable does not exist, GETENV returns all blanks. 7. IGETARG and IARGC can be used to retrieve arguments on the command line from which a program was invoked. _________________________________________________________________ NOTE The $HP9000_800 INTRINSICS ON directive changes the behavior of the intrinsic function IARGC. The function returns the number of command line arguments, counting the name of the program as argument one. Because of this difference, use the GETARG intrinsic instead of IGETARG when $HP9000_800 INTRINSICS is ON. _________________________________________________________________ 8. FREE is used to free a block of memory which was previously allocated with the MALLOC intrinsic. The argument to FREE must contain a value previously returned from a call to MALLOC. Once a block of memory has been freed, it must not be referenced again. The syntax of this intrinsic is: CALL FREE(pointer_var) _________________________________________________________________ NOTE Allocatable arrays can also be used to allocate blocks of memory. Where possible, it is recommended that you use allocatable arrays instead of the MALLOC and FREE routines. (For information about allocatable arrays, see Chapter 7 .) _________________________________________________________________ For more information on FORTRAN pointers, see Chapter 10 . 9. One method of associating memory with a FORTRAN pointer is to use the MALLOC intrinsic to allocate a block of memory. The argument to MALLOC is the number of bytes of memory you want to allocate. The function return value of MALLOC should be assigned to a FORTRAN pointer variable. If the request for memory cannot be honored for some reason, such as not enough memory available, then MALLOC will return the value 0. _________________________________________________________________ NOTE Allocatable arrays can also be used to allocate blocks of memory. Where possible, it is recommended that you use allocatable arrays instead of the MALLOC routine. (For information about allocatable arrays, see Chapter 7 .) _________________________________________________________________ For more information on FORTRAN pointers, see Chapter 10 . 10. The syntax for MCLOCK is: INTEGER i i = MCLOCK() The value returned, in units of microseconds, is the sum of the current process's user time and the user and system times of all of its child processes. MCLOCK can also be accessed when using the +800 compile-line option. 11. SYSTEM gives its character argument to the default shell (/bin/sh) as input, as if the string had been typed in at a terminal. When the shell has completed, the process continues. Miscellaneous Intrinsics Table 14-9 lists intrinsics that do not clearly fall into the other categories. They are used for compatibility with Series 600/800 FORTRAN and other vendors' versions of FORTRAN. In the following table, the superscript 1 indicates intrinsics that can be accessed only with the $HP9000_800 INTRINSICS compiler directive. The superscript 2 indicates intrinsics that can be accessed with the $NOSTANDARD SYSTEM directive. Table 14-9. Miscellaneous Intrinsics ------------------------------------------------------------------------------------------------------ | | | | | | | | Generic | Description | Args | Specific | Arg | Function | | Name | | | Name | Type | Type | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Returns the byte address of | 1 | BADDRESS1 | Any | Integer*4 | | | its argument. | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ | | | | | | | | -- | Returns the bytes of storage | 1 | SIZEOF1,2 | [See note 1] | Integer | | | used by the argument. | | | | | | | | | | | | ------------------------------------------------------------------------------------------------------ Notes on Miscellaneous Intrinsics 1. SIZEOF accepts any valid data type except assumed-size arrays or passed-length character arguments. Chapter 15 FORTRAN System Subroutines and Functions As a compatibility extension, FORTRAN provides the following system subroutines and functions: * DATE subroutine. * EXIT subroutine. * IDATE subroutine. * MVBITS subroutine. * RAN function. * SECNDS function. * TIME subroutine. ________________________________________________________________________ NOTE To call any of the routines or functions in this chapter, a program must be compiled with either the +e or +E1 option, or must contain the $NOSTANDARD INTRINSICS compiler directive. Also note that before using the +e option, you should be aware of its side-effects described in Chapter 19 . ________________________________________________________________________ DATE Subroutine The DATE subroutine returns the current system date. Syntax CALL DATE(datestr) datestr is a variable, character substring, array, or array element containing at least 9 bytes of storage. DATE fills the datestr storage with a 9-byte string: dd-mmm-yy dd is a two-digit representation of the day of the month, mmm is a three-character abbreviation for the current month (e.g., Jan, Feb, etc.), and yy is the last two digits of the current year. Example For example, if today's date is May 30, 1987, then the following code displays 30-May-87: CHARACTER*9 TODAY CALL DATE(TODAY) PRINT *,TODAY EXIT Subroutine The EXIT call terminates the program, closes all open files, and returns control to the HP-UX operating system. If specified, an optional exit status value can be returned to the environment from which the program was invoked. EXIT is similar in function to the exit system call, described on the exit(2) page of the HP-UX Reference. Syntax CALL EXIT[(exit_value)] exit_value is an integer value to return to the invoking environment. Example INTEGER*4 I LOGICAL L I=4 INQUIRE (FILE='/TMP/NOTHERE',EXIST=L) IF (.NOT. L) THEN PRINT *, 'FILE NOT FOUND' CALL EXIT (I) ENDIF If the file is not found, EXIT passes the value 4. To check the exit status of the previous command, use the HP-UX command echo $?. IDATE Subroutine The IDATE subroutine returns the month, day, and year of the current system date as three integers. Syntax CALL IDATE(month, day, year) month, day, and year are integer variables or array elements. Example For example, if the current date is December 1, 1987, then the following code sets MONTH to 12, IDAY to 1, and IYEAR to 87: CALL IDATE(MONTH, IDAY, IYEAR) MVBITS Subroutine MVBITS is a MIL-STD-1753 standard routine, in which bit positions are numbered from right to left with the rightmost (least significant) bit numbered 0. The MVBITS routine transfers a string of bits from one memory location to another location. It is identical in function to the MVBITS intrinsic. (For more details, see the discussion of MVBITS under "Bit Manipulation Intrinsics" .) Syntax CALL MVBITS (a,b,c,d,e) MVBITS(a,b,c,d, e), moves c bits from positions b through b+c-1 of argument a to positions e through e+c-1 of argument d. That is, c bits are moved from bit b of a to bit e of d. The portion of argument d not affected by the movement of bits remains unchanged. All arguments are integer expressions, except d, which must be a variable or array element. Arguments a and d are permitted to be the same numeric storage unit. The values of b+c and e+c must be less than or equal to the lengths of a and d, respectively. Both a and d must be INTEGER*4. Example I = 31 CALL MVBITS(54,12,2,I,0) IF (I .NE. 28) STOP 'FAIL' END RAN Function RAN returns a random (uniformly distributed) floating-point number between 0.0 inclusive and 1.0 exclusive using a multiplicative congruential random number generator. Syntax r = RAN(iseed) The argument iseed must be an integer (INTEGER, INTEGER*4) variable or array element. RAN stores a number in iseed to be used by the next call to RAN. iseed should initially be set to an odd number, preferably very large. Refer to the following example. Example ISEED = 425001 RND = RAN(ISEED) Notes To ensure different random values for each run of a program, iseed should be set to a different value each time the program is run. One way to implement this would be to have the user enter the seed at the start of the program. Another way would be to compute a value from the current year, day, and month (returned by IDATE) and the number of seconds since midnight (returned by SECNDS). SECNDS Function SECNDS returns the number of seconds that have elapsed since midnight, less the value of its argument. Syntax s = SECNDS(v) Example S = SECNDS(0.0) DO I = 1,10000000 J = J+1 END DO S = SECNDS(S) PRINT *, 'IT TOOK',S,'SECONDS TO RUN' Notes SECNDS returns a real value, and the v parameter must be of type real also. The value returned by SECNDS is accurate to one one-hundredth of a second (0.01). The SECNDS routine is useful for computing elapsed time of the execution of code. TIME Subroutine The TIME subroutine returns the current system time. Syntax CALL TIME(timestr) timestr is a variable, character substring, array, or array element containing at least 8 bytes of storage. TIME fills timestr with an 8-byte character string of the form: hh:mm:ss hh is a two-digit representation of the current hour, mm a two-digit representation of minutes past the hour, and ss the number of seconds past the minute. Example The following code displays the current date and time to standard output: CHARACTER*9 TODAY CHARACTER*8 TIMESTR : CALL DATE(TODAY) CALL TIME(TIMESTR) PRINT *,TODAY,TIMESTR Notes Do not confuse this TIME routine with the system call time, which performs a different function as described in section 2 of the HP-UX Reference.