+------------------------Fortran 2003 Draft Standard-------------------------+
The ASSOCIATE construct associates an entity with a variable or the value of an expression during the execution of the construct.
Execution of an ASSOCIATE construct causes execution of its ASSOCIATE_statement followed by execution of its block. During execution of that block, each associate name identifies an entity, which is associated with the corresponding selector. The associating entity assumes the declared type and type parameters of the selector.
Syntax
>>-ASSOCIATE_statement----------------------------------------->< >>-ASSOCIATE_statement_block----------------------------------->< >>-END_ASSOCIATE_statement------------------------------------->< |
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 in the value of the variable MYREAL within the construct 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 MYREAL = MYREAL * 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 Draft Standard---------------------+