Re: Fortran Features



Paul Van Delst wrote:
| I haven't needed to use a label (for GOTOing, END=, or ERR=) for years[*]. I
| can't think what else you'd need them for without a current f95 construct
| being more natural (although I haven't thought too hard about it).

Error handling. Consider:

open(somefile)
open(anotherfile)
allocate(someglobal)
allocate(anotherglobal)
allocate(bunchastuff)

do...
call foo(ierror)
if (ierror/=0) then
write(*,*) "Error code: ", ierror
close(somefile)
close(anotherfile)
deallocate(someglobal)
deallocate(anotherglobal)
deallocate(bunchastuff)
return
end if
call bar(ierror)
if (ierror/=0) then
write(*,*) "Error code: ", ierror
close(somefile)
close(anotherfile)
deallocate(someglobal)
deallocate(anotherglobal)
deallocate(bunchastuff)
return
end if
call baz(ierror)
if (ierror/=0) then
write(*,*) "Error code: ", ierror
close(somefile)
close(anotherfile)
deallocate(someglobal)
deallocate(anotherglobal)
deallocate(bunchastuff)
return
end if
...
end do

end subroutine

==========================================
compare with:

open(somefile)
open(anotherfile)
allocate(someglobal)
allocate(anotherglobal)
allocate(bunchastuff)

do...
call foo(ierror)
if (ierror/=0) goto 100
call bar(ierror)
if (ierror/=0) goto 100
call bar(ierror)
if (ierror/=0) goto 100
end do

return
100 continue
write(*,*) "Error code: ", ierror
close(somefile)
close(anotherfile)
deallocate(someglobal)
deallocate(anotherglobal)
deallocate(bunchastuff)

end subroutine

I think even Dijkstra would agree :-).

--
Jugoslav
___________
www.xeffort.com

Please reply to the newsgroup.
You can find my real e-mail on my home page above.
.