home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / fortran / 4844 < prev    next >
Encoding:
Internet Message Format  |  1992-12-23  |  3.2 KB

  1. 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
  2. From: iversen@dsfys1.fi.uib.no (Per Steinar Iversen)
  3. Newsgroups: comp.lang.fortran
  4. Subject: Re: How to detect format overflow
  5. Message-ID: <1992Dec23.062647.16470@alf.uib.no>
  6. Date: 23 Dec 92 06:26:47 GMT
  7. References: <1992Dec22.140111.5270@statoil.no>
  8. Sender: iversen@vsfys1.fi.uib.no (Per Steinar Iversen)
  9. Reply-To: iversen@vsfys1.fi.uib.no
  10. Organization: Department of Physics, University of Bergen, Norway
  11. Lines: 91
  12.  
  13.  
  14. In article <1992Dec22.140111.5270@statoil.no>, c79057@petek.tek.st.statoil.no (Joergen Leiknes) writes:
  15.  
  16. >I want to detect overflow in format statements, to avoid to have
  17. >asterisks in the produced output. (Yes,I know that it is possible
  18. >to have larger fields for each variable, but it would be nice to
  19. >have an error jump when such things occur)
  20. >
  21. >In the little test program below:
  22. >      PROGRAM IOTEST
  23. >      INTEGER ISTAT, I
  24. >      REAL X
  25. >      X = 123123.3
  26. >      I = -123123
  27. >      WRITE(*,700,ERR=900, IOSTAT= ISTAT) X, I
  28. >700   FORMAT(' X is ',F6.3,' I is ',I6)
  29. >      GOTO 999
  30. >
  31. >900   CONTINUE
  32. >      WRITE(*,*) ' IOERROR no. ', ISTAT
  33. >      GOTO 999
  34. >
  35. >999   CONTINUE
  36. >      END
  37. >
  38. >Gives this output:
  39. > X is ****** I is ******
  40. >
  41. >and no error is catched.
  42. >
  43. >I would like to know if it is possible according to f77 or f90 standard
  44. >to catch such overflows.
  45. >
  46. >Thanks in advance
  47. >Jorgen Leiknes, Statoil NORWAY
  48.  
  49. This would seem to depend on your compiler:
  50.  
  51. -With DEC Fortran 3.2 under Ultrix 4.2 I get:
  52.  
  53.  X is ****** I is ******
  54.   IOERROR no.           63
  55.  
  56. -With VAX Fortran 5.8 under VMS 5.5 I get:
  57. X is ****** I is ******
  58.  IOERROR no.           63
  59.  
  60. The DEC manuals lists Fortran error 63 as "Output conversion error".
  61.  
  62. -On an HP 425e I did not get any error...
  63.  
  64. I think it is rather nasty not to detect or flag this error condition. You
  65. can get around the problem by first doing an internal write to a character 
  66. string, check for *'s in the right/wrong places and then act on that before
  67. final output. The following piece of (very ugly) code work on both Ultrix,
  68. VMS and HP: 
  69.  
  70.       PROGRAM IOTEST
  71.       INTEGER ISTAT, I
  72.       REAL X
  73.       CHARACTER*6 XCH, ICH
  74.       X   =  123123.3
  75.       I   = -123123
  76.       XCH = '******'
  77.       WRITE(XCH,'(F6.3)',ERR=100) X
  78. 100   IF ( XCH .EQ. '******') GOTO 900
  79.       ICH = '******'
  80.       WRITE(ICH,'(F6.3)',ERR=110) I
  81. 110   IF ( ICH .EQ. '******') GOTO 900
  82.       WRITE(*,700) XCH, ICH
  83. 700   FORMAT(' X is ',A,' I is ',A)
  84.       GOTO 999
  85.  
  86. 900   CONTINUE
  87.       WRITE(*,*) ' IOERROR...'
  88.       GOTO 999
  89.  
  90. 999   CONTINUE
  91.       END
  92.  
  93.  
  94. -psi
  95.  
  96. +------------------------------------------------------------------------------+
  97. ! Per Steinar Iversen    ! Internet:     iversen@vsfys1.fi.uib.no              !
  98. ! Fysisk Institutt       ! BITnet:       iversen@cernvm.bitnet                 !
  99. ! Universitetet i Bergen ! HEPnet:       VSFYS::IVERSEN (VSFYS=21.341=21845)   !
  100. ! Allegaten 55           ! Phone:       +47 5212770                            !
  101. ! N-5007 Bergen          ! Fax:         +47 5318334                            !
  102. ! NORWAY                 !                                                     !
  103. +------------------------------------------------------------------------------+
  104.