home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!wupost!howland.reston.ans.net!usc!enterpoop.mit.edu!eru.mt.luth.se!lunic!sunic!ugle.unit.no!alf.uib.no!dsfys1.fi.uib.no!iversen
- From: iversen@dsfys1.fi.uib.no (Per Steinar Iversen)
- Newsgroups: comp.lang.fortran
- Subject: Re: How to detect format overflow
- Message-ID: <1992Dec23.062647.16470@alf.uib.no>
- Date: 23 Dec 92 06:26:47 GMT
- References: <1992Dec22.140111.5270@statoil.no>
- Sender: iversen@vsfys1.fi.uib.no (Per Steinar Iversen)
- Reply-To: iversen@vsfys1.fi.uib.no
- Organization: Department of Physics, University of Bergen, Norway
- Lines: 91
-
-
- In article <1992Dec22.140111.5270@statoil.no>, c79057@petek.tek.st.statoil.no (Joergen Leiknes) writes:
-
- >I want to detect overflow in format statements, to avoid to have
- >asterisks in the produced output. (Yes,I know that it is possible
- >to have larger fields for each variable, but it would be nice to
- >have an error jump when such things occur)
- >
- >In the little test program below:
- > PROGRAM IOTEST
- > INTEGER ISTAT, I
- > REAL X
- > X = 123123.3
- > I = -123123
- > WRITE(*,700,ERR=900, IOSTAT= ISTAT) X, I
- >700 FORMAT(' X is ',F6.3,' I is ',I6)
- > GOTO 999
- >
- >900 CONTINUE
- > WRITE(*,*) ' IOERROR no. ', ISTAT
- > GOTO 999
- >
- >999 CONTINUE
- > END
- >
- >Gives this output:
- > X is ****** I is ******
- >
- >and no error is catched.
- >
- >I would like to know if it is possible according to f77 or f90 standard
- >to catch such overflows.
- >
- >Thanks in advance
- >Jorgen Leiknes, Statoil NORWAY
-
- This would seem to depend on your compiler:
-
- -With DEC Fortran 3.2 under Ultrix 4.2 I get:
-
- X is ****** I is ******
- IOERROR no. 63
-
- -With VAX Fortran 5.8 under VMS 5.5 I get:
- X is ****** I is ******
- IOERROR no. 63
-
- The DEC manuals lists Fortran error 63 as "Output conversion error".
-
- -On an HP 425e I did not get any error...
-
- I think it is rather nasty not to detect or flag this error condition. You
- can get around the problem by first doing an internal write to a character
- string, check for *'s in the right/wrong places and then act on that before
- final output. The following piece of (very ugly) code work on both Ultrix,
- VMS and HP:
-
- PROGRAM IOTEST
- INTEGER ISTAT, I
- REAL X
- CHARACTER*6 XCH, ICH
- X = 123123.3
- I = -123123
- XCH = '******'
- WRITE(XCH,'(F6.3)',ERR=100) X
- 100 IF ( XCH .EQ. '******') GOTO 900
- ICH = '******'
- WRITE(ICH,'(F6.3)',ERR=110) I
- 110 IF ( ICH .EQ. '******') GOTO 900
- WRITE(*,700) XCH, ICH
- 700 FORMAT(' X is ',A,' I is ',A)
- GOTO 999
-
- 900 CONTINUE
- WRITE(*,*) ' IOERROR...'
- GOTO 999
-
- 999 CONTINUE
- END
-
-
- -psi
-
- +------------------------------------------------------------------------------+
- ! Per Steinar Iversen ! Internet: iversen@vsfys1.fi.uib.no !
- ! Fysisk Institutt ! BITnet: iversen@cernvm.bitnet !
- ! Universitetet i Bergen ! HEPnet: VSFYS::IVERSEN (VSFYS=21.341=21845) !
- ! Allegaten 55 ! Phone: +47 5212770 !
- ! N-5007 Bergen ! Fax: +47 5318334 !
- ! NORWAY ! !
- +------------------------------------------------------------------------------+
-