HP Fortran Programmer's Guide (March 2010)
Using the ON statement
Trapping +Ctrl-C trap interrupts
Chapter 5140
Trapping +Ctrl-C trap interrupts
A +Ctrl-C interrupt can occur during the following circumstances:
• When the user enters the interrupt code from the terminal while the program is running
or awaiting input
• During the execution of a PAUSE statement
The trap procedure for a +Ctrl-C interrupt must have no formal arguments. The interrupt
code is the character defined by the HP-UX stty(1) command for the intr parameter. The
system default for intr is +Ctrl-C.
You can use the +Ctrl-C form of the ON statement to handle the interrupt signal 2. In the
following example, when an interrupt occurs, the program reports status information on
standard output, assuring the user that the program is still at work in the DO loop. The
program uses the ON statement to set the action for a +Ctrl-C interrupt to be the call to the
trap handler status:
PROGRAM main
COMMON i
ON CONTROLC CALL status
DO i = 1, 100000
... ! Long computation
END DO
END
SUBROUTINE status
COMMON i
PRINT *, 'Currently on iteration ', i
END SUBROUTINE status
When this program is run, a +Ctrl-C interrupt causes the status routine to be called, which
prints the iteration count. The program then resumes executing the DO loop.