Having received a command, the application might not wish to complete immediately, but may want to wait for something to happen. The simplest thing to wait for is the passing of a timed interval. This is set up by using TASK_PUT_REQUEST(ACT__WAIT,STATUS) to tell the fixed-part a timer is required and using TASK_PUT_DELAY to tell the system how long a time is required. Note that your code has to find out whether it is being called for the first time or not by inquiring the sequence number SEQ.
interface timer action WAIT obey endobey endaction endinterface SUBROUTINE TIMER ( STATUS ) IMPLICIT NONE INCLUDE 'SAE_PAR' INCLUDE 'ACT_ERR' INTEGER STATUS INTEGER SEQ IF ( STATUS .NE. SAI__OK ) RETURN CALL TASK_GET_SEQ ( SEQ, STATUS ) IF ( SEQ .EQ. 0 ) THEN * first-time, request 100 millisecond wait CALL TASK_PUT_DELAY ( 100, STATUS ) CALL TASK_PUT_REQUEST ( ACT__WAIT, STATUS ) ELSE * next time in, finished CALL MSG_OUT ( ' ', 'finished', STATUS ) ENDIF END
The time delay can also be used as a timeout facility in conjunction with waiting for input or message receipt.
It is possible to have several actions active at once, each waiting to be called by the fixed-part. Here is a simple example of two actions, each doing a timed reschedule.
SUBROUTINE TIMER ( STATUS ) IMPLICIT NONE INCLUDE 'SAE_PAR' INCLUDE 'ACT_ERR' INTEGER STATUS INTEGER SEQ CHARACTER*(PAR__SZNAM) NAME IF ( STATUS .NE. SAI__OK ) RETURN CALL TASK_GET_SEQ ( SEQ, STATUS ) CALL TASK_GET_NAME ( NAME, STATUS ) IF ( SEQ .EQ. 0 ) THEN IF ( NAME .EQ. 'WAIT' ) THEN CALL TASK_PUT_DELAY ( 5000, STATUS ) CALL TASK_PUT_REQUEST ( ACT__WAIT, STATUS ) ELSE IF ( NAME .EQ. 'WAIT1' ) THEN CALL TASK_PUT_DELAY ( 1000, STATUS ) CALL TASK_PUT_REQUEST ( ACT__WAIT, STATUS ) ENDIF ELSE IF ( NAME .EQ. 'WAIT' ) THEN CALL MSG_OUT ( ' ', 'WAIT has rescheduled', STATUS ) CALL TASK_PUT_DELAY ( 5000, STATUS ) CALL TASK_PUT_REQUEST ( ACT__WAIT, STATUS ) ELSE IF ( NAME .EQ. 'WAIT1' ) THEN CALL MSG_OUT ( ' ', 'WAIT1 has rescheduled', STATUS ) CALL TASK_PUT_DELAY ( 1000, STATUS ) CALL TASK_PUT_REQUEST ( ACT__WAIT, STATUS ) ENDIF ENDIF END
Obviously, this application never terminates, but will put out the WAIT message every 5 seconds and the WAIT1 message every 1 second.
ADAM Guide to Writing Instrumentation Tasks