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.
.



Relevant Pages

  • Re: Problem writing code to go to a label after calling a procedure
    ... >>I first tried to create procedures for parts of the program to avoid ... Thanks for the advice J French. ... I know a good program structure avoids many goto ... subroutine, this is somthing I found that Visual Basic can't do. ...
    (comp.lang.basic.visual.misc)
  • Re: Programming languages
    ... pipeline to be flushed. ... Subroutine calls are interruptions of an orderly flow, ... The compiler may even inline the function if it's small. ... the target of a goto, the compiler has to discard all cache and register ...
    (sci.lang)
  • Re: FORSTY - The Fortran Styler :-)
    ... What's wrong with a subroutine call? ... you *CAN* get by without the goto. ... You artifically put a loop around all the executable code in the ... but just because Fortran has a loop exit construct. ...
    (comp.lang.fortran)
  • Re: FORSTY - The Fortran Styler :-)
    ... I've got a subroutine like that. ... you *CAN* get by without the goto. ... You artifically put a loop around all the executable code in the ... but just because Fortran has a loop exit construct. ...
    (comp.lang.fortran)
  • Re: Programming languages
    ... they constitute unpredictable interruptions of what ... Subroutine calls are interruptions of an orderly flow, ... the target of a goto, the compiler has to discard all cache and register ... which requires the pipeline to be flushed. ...
    (sci.lang)