08-173 To: J3 From: Malcolm Cohen Subject: Reconsideration of interp F90/000209. Date: 2008 May 13 ---------------------------------------------------------------------- NUMBER: TITLE: STOP executed via function in input/output list KEYWORDS: STOP DEFECT TYPE: Erratum STATUS: J3 consideration in progress. QUESTION: Interpretation F90/000209 considered the question Section 9.7. May a function referenced in an I/O statement execute a STOP or PAUSE statement? If STOP statements are permitted, what is the state of the file at the end of execution? The answer (w.r.t. STOP), included in F95 corrigendum 2, replied No, a STOP statement may not be executed in this situation. Executing a STOP statement causes normal termination of execution, which closes all files (9.3.5), and this is equivalent to executing a CLOSE statement, which is prohibited by 9.7. A clarifying edit is supplied. This answer was reasonable for Fortran 90/95, but the reasoning is defective when applied to Fortran 2003. Fortran 2003 allows execution of a CLOSE statement for any external file during the execution of an internal i/o statement (so-called "recursive i/o"). It seems that this consideration was overlooked for Fortran 2003. However, on further consideration of the reasoning behind this answer, it seems unhelpful to rule out STOP, which is often used for user signalling of error conditions, during i/o operations. For one thing, if the data transfer statement being executed is READ, the question about file state has a very straightforward answer. It might also be considered unhelpful in the WRITE case for STOP to cause the user's entire file system to be potentially reformatted instead of just making the contents of the relevant file undefined. Furthermore, the user who wants to signal an error can cause error termination via one of the "approved" methods such as DEALLOCATE of an unallocated array. It seems less than unhelpful to force the user to use such a circumlocution simply for standards conformance, and the question about file state can equally be asked of this situation. Q1. Is execution of a STOP statement during internal i/o allowed? Q2. Is execution of a STOP statement during a READ statement allowed? Q3. Is execution of a STOP statement during a WRITE statement allowed? Q4. What is the effect on the file state of executing the following code fragment during a WRITE statement to an external file: REAL,ALLOCATABLE :: array(:) DEALLOCATE(array) (And if the answer to Q3 is yes, does a STOP statement have the same effect.) ANSWER: The answer to the first three questions is yes, this should have been allowed. An edit is provided to correct the standard. The answer to Q4 is that the effects on the file currently being written by that WRITE statement are not standardised. (This was, in fact, the situation before the adoption of the previous interp answer.) A clarifying edit is provided to indicate that the contents of the file become undefined. EDITS: In 9.5.3 "Execution of a data transfer input/output statement", immediately before Note 9.38 insert a new paragraph "If execution of the program is terminated during execution of a WRITE or PRINT statement, the contents of the file become undefined." Delete [219:30] the last paragraph of 9.11 which currently reads "A STOP statement shall not be executed during execution of an input/output statement." SUBMITTED BY: Malcolm Cohen. HISTORY: 08-173 m184 Submitted. ----------------------------------------------------------------------