Fortran 2003 Standard

ASSOCIATE Construct

The ASSOCIATE construct creates an association between an identifier and a variable, or the value of an expression, during the execution of that construct. The identifier you specify in an ASSOCIATE construct becomes an associating entity. You can create multiple associating entities inside a single ASSOCIATE construct.

Syntax

Read syntax diagramSkip visual syntax diagram>>-ALINKHISTART ASSOCIATE_statement-----------------------------------------><
 
Read syntax diagramSkip visual syntax diagram>>-ASSOCIATE_statement_block-----------------------------------><
 
Read syntax diagramSkip visual syntax diagram>>-ALINKHISTART END_ASSOCIATE_statement-------------------------------------><
 
ASSOCIATE_statement
See ASSOCIATE for syntax details
END_ASSOCIATE_statement
See END (Construct) for syntax details

Execution of an ASSOCIATE construct causes execution of an ASSOCIATE_statement followed by the ASSOCIATE_statement_block. During execution of that block, the construct creates an association with an identifier and the corresponding selector. The associating entity assumes the declared type and type parameters of the selector.

Examples

The following example uses the ASSOCIATE construct as a shorthand for a complex expression and renames an existing variable, MYREAL. After the end of the ASSOCIATE construct, any change within the construct to the value of the associating entity that associates with MYREAL is reflected.

      PROGRAM ASSOCIATE_EXAMPLE

        REAL :: MYREAL, X, Y, THETA, A
        X = 0.42
        Y = 0.35
        MYREAL = 9.1
        THETA = 1.5
        A = 0.4

        ASSOCIATE ( Z => EXP(-(X**2+Y**2)) * COS(THETA), V => MYREAL)
          PRINT *, A+Z, A-Z, V
          V = V * 4.6
        END ASSOCIATE

        PRINT *, MYREAL

      END PROGRAM ASSOCIATE_EXAMPLE

The expected output is.

0.4524610937 0.3475389183 9.100000381

41.86000061
End of Fortran 2003 Standard