>>>>> John Venier writes:
John> Van Snyder sent the indented text:
>>
John> [...]
>>
>> 1. In languages that support coroutines, there are typically two additional
>> procedure invocation-related statements. In a Fortran extension, these
>> might be COCALL and CORETURN. COCALL acts like a CALL if the procedure
>> has never been called, or if it most recently returned by an ordinary
>> RETURN statement. If it returned by a CORETURN statement, COCALL
>> returns control to the procedure at the statement after the CORETURN
>> statement. CALL always sends control to the first statement of the
>> procedure.
>>
>> Best regards,
>> Van Snyder
>>
John> This is a great idea! We use reverse communication extensively, and
John> such a facility would make it much easier. I take it that coroutines
John> are not a new idea, but this is the first I've heard of them; I came
John> to computer programming through statistics. Anyhow, I like it!
Oddly enough, support for this structure has been available in Fortran for a
long time. I don't know if it is now obsolete, but for certain very large
legacy codes, support for it is essential. It is the alternate return syntax:
CALL mysub( *100, *200, *300, normalarg1, normalarg2, ... )
! normal return
! ... do normal stuff ...
100 CONTINUE
! RETURN 1 comes here ...
200 CONTINUE
! RETURN 2 comes here ...
300 CONTINUE
! RETURN 3 comes here ...
! ............................................................
SUBROUTINE mysub( *, *, *, normalarg1, normalarg2, ... )
! ...
IF ( cond1 ) THEN
! Uh-oh, error condition 1 has popped up.
RETURN 1
END IF
IF ( cond2 ) THEN
! Uh-oh, error condition 2 has popped up.
RETURN 2
END IF
IF ( cond3 ) THEN
! Uh-oh, error condition 3 has popped up.
RETURN 3
END IF
END ! subroutine mysub
Obviously this is rife for abuse, and I've seen many horrid examples. But you
would be surprised how many compiler vendors still support it ...
--
Ted Stern Analysis/Porting/Tuning, Engineering Applications
Cray Inc. http://www.cray.com
411 First Avenue South, Suite 600 Direct 206-701-2182, Main 206-701-2000
Seattle, WA 98104-2860 FAX 206-701-2500
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|