• Aucun résultat trouvé

INTEGER*2 ICW87 CALL STCW87(ICW87)

Dans le document FORTRAN-a6 USER'S GUIDE (Page 73-79)

ICW87 ICW87 .AND. #FF7DH CALL LDCW87 (I CW87)

See Figure 6-1 for an overview and explanation of the 8087 control word. Other control-word changes can be done in a similar manner.

STORE 8087 Status Word. STSW87 returns the current exception status of the floating-point processor in the form of an INTEGER *2 bit string (see Figure 6-2), and clears the 8087 exception flags. The 8087 status word represents an accumula-tion of all masked floating-point excepaccumula-tions that have occurred since execuaccumula-tion of the

6-21

Subprograms

6-22

15

I

I EXCEPTION FLAGS

(1 = EXCEPTION HAS OCCURRED) INVALID OPERATION

'----ZERO DIVIDE '---OVERFLOW '---UNDERFLOW L---PRECISION

Figure 6-2. 8087 Status-Word Format for Fortran-86 (STSW87) 121570-5

program began or since the last time STSW87 was executed. The following example tests to see if a masked overflow exception has occurred, and illustrates the use of this intrinsic:

INTEGER*2 ISW87 CALL STW87(ISW87)

IF (ISW87 .AND. 00008H) 20,10,20 20 (exception has occurred)

1 0

SAVE/RESTORE 8087 State. SA V87 and RST87 transfer the state of the 8087 Numeric Data Processor to and from memory. These functions are useful for preserv-ing the context of the processor for reentrancy, or for determinpreserv-ing the cause of a floating-point exception and recovering from it. Both intrinsics operate on a 47-word buffer in memory. The format of the 8087 state information present in that buffer is defined in the 8087 Numeric Supplement. The following is an example of these functions:

CHARACTER*94 STATE CALL SAVE87(STATE)

CALL RST87(STATE)

6.3 .2 . 11 8086 Interrupt Control Intrinsics

SETINT establishes a current interrupt procedure and associates it with an interrupt number. Its syntax is as follows:

CAL L SET I N T ( num , name) where

num name

is an integer expression that is the interrupt number.

is the name of the external procedure.

Interrupt procedures may be written in any language that supports 8086 interrupts.

See Chapter 11 for more information on the INTERRUPT compiler control.

Fortran-86

Fortran-86

Example:

SINTERRUPT

SUBROUTINE INTRPT

(INTERRUPT PROCESSING CODE)

RETURN END

PROGRAM main EXTERNAL INTRPT

CALL SETINT(8, INTRPT)

When an interrupt occurs, the hardware automatically disables further interrupts, and enables them again at termination of the procedure. ENABLE/DSABLE provide the user with additional flexibility both within and outside of interrupt procedures.

DSABLE

CALL DSABLE

DSABLE disables the 8086 interrupt mechanism (prevents interrupts from occur-ring) until it is ENABLEd again.

ENABLE

CALL ENABLE

ENABLE enables the 8086 interrupt mechanism.

NOTE

Do not use the interrupt procedures in any program that will run in an iRMX 86 environment. Instead use the iRMX 86 system calls to set up interrupt processing routines.

6.3.3

Statement FUlIlctions

A statement function is a user-defined internal function that calculates a mathemat-ical value. All statement-function definitions must follow all specification statements and must precede all executable statements. Its syntax is as follows:

nameC[arg, [arg, ... ]]) = exp where

name arg exp

is the symbolic name you give your statement function.

is a dummy argument that becomes associated with an actual argument when the function is referenced.

is an expression.

Subprograms

6-23

Subprograms

6-24

The statement-function name and its expression can be of different result types. Table 6-12 shows the implicit type conversions of statement functions.

Each operand in the statement-function expression must be one of the following:

• One of the dummy arguments, arg A constant

• A variable reference

• An array-element reference

• An intrinsic-function reference

• A statement-function reference

• An external-function reference

• A dummy-procedure reference

The symbolic name of a statement function is local and cannot be a symbolic name in any specification statement, except a type statement. You cannot use the name in an EXTERNAL statement or as an actual argument.

The dummy argument list indicates the order, number and type of arguments for the statement function. These dummy argument names have the scope of the statement function only, and each name can appear only once in the dummy argument list. The type of the dummy argument name is the same as it would be if you used it outside the statement function.

You can use the dummy argument name to identify other dummy arguments of the same type in other statement-function statements. You can also use it to identify a variable of the same type within the same program unit, but they have no other relationship.

You reference a statement function by specifying its symbolic name, with all required actual arguments. For example:

DATA A,B,C/10.0,10.0,3.81 FSUMeX)-A * eXt'*2) + B*X+C TOTAL - 33.0 + FSUMe3.0)

Table 6-12. Implicit Type Conversions in Statement Functions

Statement Function Type Type Conversion

INTEGER INTEGER INT(exp)

INTEGER*1 INT1(exp)

INTEGER*2 INT2(exp)

INTEGER*4 INT4(exp)

REAL REAL REAL(exp)

REAL*4 REAL(exp)

REAL*8 DBL(exp)

DOUBLE DOUBLE DBLE(exp)

PRECISION PRECISION

TEMPREAL TEMPREAL TREAL(exp)

Complex COMPLEX*8 CMPLX(e)

COMPLEX*16 DCMPLX(e)

COMPLEX CMPLX(e)

Fortran-86

Fortran-86

In this example, Fortran substitutes the value 3.0 for every occurrence of X in the function definition. At the end of the operation, the value of TOTAL is 156.8.

You can reference a statement function only in the program unit where you defined it. A statement function in a FUNCTION subprogram cannot reference the name of the subprogram. A reference to an external function in the expression of a statement function must not cause a dummy argument of the statement function to become undefined or redefined.

6.3.4 The % VAL Function

The % VAL function is a Fortran-86 extension which enables parameter passing by value for program linkage with non-Fortran programs. It can appear only as an actual argument in external function or subroutine references, or as a dummy argument in SUBROUTINE or FUNCTION statements. The % VAL function accepts only one actual argument, which must be a constant, variable, array element, or expression of type INTEGER or LOGICAL.

For INTEGER arguments passed to a subroutine or function, the length of the argument passed is determined by the argument length, not by the default length.

This allows you to explicitly control the argument length using the functions INT 1, INT2, or INT 4.

For variables, function reft~rences, and symbolic constants, the length is the explicitly or implicitly defined length of the name. For numeric constants, the length is the minimum length required to contain the valut~.

6.4 BLOCK OAT A Subprograms

A BLOCK DATA subprogram initializes variables and array elements in named COMMON blocks using DATA statements. The first statement of any BLOCK DATA subprogram must be a BLOCK DATA statement (see Section 4.2.4). The last statement must be the END statement. You can use only IMPLICIT, DIMEN-SION, named COMMON, SAVE, EQUIVALENCE, DATA, and type statements in a BLOCK DATA subprogram.

The name of a BLOCK DATA subprogram is optional. If you do name the subpro-gram, that name is global and cannot be the same as the name of any external proce-dure, main program, COMMON block, or other BLOCK DATA subprogram. You can have at most one unnamed BLOCK DATA subprogram per executable program.

Only variables appearing in named COMMON statements can appear in a DIMEN-SION, EQUIVALENCE, DATA, SAVE, or type statement in a BLOCK DATA subprogram.

If you initialize a named COMMON block, you must Ijst all the variables in that block even if you are not initializing all of them. You can initialize variables in more than one named COMMON block in a single BLOCK DATA subprogram, but you cannot specify the same named COMMON block in more than one BLOCK DATA subprogram.

Subprograms

6-25

CHAPTER 7 EXPRESSIONS

Expressions in Fortran consist of symbols, constants, and operators (including paren-theses) which perform spe:cified operations. There are four types of expressions in Fortran:

• Arithmetic

• Relational

• Logical

• Character

Dans le document FORTRAN-a6 USER'S GUIDE (Page 73-79)