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.
>>-ALINKHISTART ASSOCIATE_statement-----------------------------------------><
>>-ASSOCIATE_statement_block-----------------------------------><
>>-ALINKHISTART END_ASSOCIATE_statement-------------------------------------><
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.
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