javijerome
Programmer
Does fortran95 have some error handling techniques like the "try" statement of Visual Basic 2008?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
...
integer stat
...
! open file
open (1, file='csv_file.csv', status='old', iostat=stat)
if (stat .ne. 0) then
write(*,*) 'File cannot be opened !'
go to 99
end if
...
! close file
99 continue
close(1)
[COLOR=#a020f0]program[/color] exception
[COLOR=#a020f0]use[/color] ieee_arithmetic
[COLOR=#2e8b57][b]implicit[/b][/color] [COLOR=#2e8b57][b]none[/b][/color]
[COLOR=#2e8b57][b]integer[/b][/color], [COLOR=#2e8b57][b]parameter[/b][/color] :: n[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]2[/color]
[COLOR=#2e8b57][b]integer[/b][/color] :: k
[COLOR=#2e8b57][b]real[/b][/color] :: x, y(n), z
x [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]1.0[/color]
y [COLOR=#804040][b]=[/b][/color] ([COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]5.0[/color], [COLOR=#ff00ff]0.0[/color][COLOR=#804040][b]/[/b][/color])
[COLOR=#804040][b]do[/b][/color] k [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]1[/color], n
z [COLOR=#804040][b]=[/b][/color] x[COLOR=#804040][b]/[/b][/color]y(k)
[COLOR=#804040][b]if[/b][/color] (ieee_is_finite(z)) [COLOR=#804040][b]then[/b][/color]
[COLOR=#804040][b]print[/b][/color] [COLOR=#804040][b]*[/b][/color], [COLOR=#ff00ff]"Z = "[/color], z
[COLOR=#804040][b]else[/b][/color]
[COLOR=#804040][b]print[/b][/color] [COLOR=#804040][b]*[/b][/color], [COLOR=#ff00ff]"Error: Z is infinite!"[/color]
[COLOR=#804040][b]end if[/b][/color]
[COLOR=#804040][b]end do[/b][/color]
[COLOR=#a020f0]end program[/color] exception
$ g95 exception.f95 -o exception
$ exception
Z = 0.2
Error: Z is infinite!
$ gfortran exception.f95 -o exception
exception.f95:2.19:
use ieee_arithmetic
1
Fatal Error: Can't open module file 'ieee_arithmetic.mod' for reading at (1): No such file or directory
gfortran.exe: Internal error: Aborted (program f951)
Please submit a full bug report.
See <[URL unfurl="true"]http://gcc.gnu.org/bugs.html>[/URL] for instructions.
However, I don't know how wide ieee_arithmetic is supported by several compilers, because the above code doesn't compile with gfortran