Re: FORTRAN "Source Code to Flow Chart Converter" Available
beliavsky_at_aol.com
Date: 08/04/04
- Next message: Kamaraju Kusumanchi: "Is it possible to have multiple strides, dists in fftw3"
- Previous message: *** Hendrickson: "Re: FORMAT in F77"
- In reply to: Paul Van Delst: "Re: FORTRAN "Source Code to Flow Chart Converter" Available"
- Next in thread: Paul Van Delst: "Re: FORTRAN "Source Code to Flow Chart Converter" Available"
- Reply: Paul Van Delst: "Re: FORTRAN "Source Code to Flow Chart Converter" Available"
- Reply: Richard Maine: "Re: FORTRAN "Source Code to Flow Chart Converter" Available"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 4 Aug 2004 10:22:44 -0700
Paul Van Delst <paul.vandelst@noaa.gov> wrote in message news:<celid3$q9e$1@news.nems.noaa.gov>...
> > I have not seen the need for an explicit GOTO in Fortran 95 code. One
> > can EXIT a loop, possibly using a labelled DO loop when loops are
> > nested. CYCLE is also useful within loops. Fortran allows multiple
> > RETURN statements, so one need not GOTO the last line of a procedure
> > to exit it. Internal subroutines can replace GOTO's in some cases. Can
> > someone give an example where a GOTO is the cleanest solution in a
> > Fortran 95 code?
>
> When I encounter an error usually I have to a) create an error message, b) close file(s),
> c) deallocate various arrays, and/or d) deallocate pointer components of various derived
> types. Something like the following:
>
> IF ( Error ) THEN
> Message = 'Error message #1'
> CLOSE( File_ID1 )
> CLOSE( File_ID2 )
> DEALLOCATE( Local_Array, STAT = Allocate_Status )
> IF ( Allocate_Status /= 0 ) THEN
> ...handle this error...
> END IF
> Error_Status = Destroy_MyType1( MyType1 )
> IF ( Error_Status /= SUCCESS ) THEN
> ...handle this error...
> END IF
> Error_Status = Destroy_MyType2( MyType2 )
> IF ( Error_Status /= SUCCESS ) THEN
> ...handle this error...
> END IF
> ...etc...
> RETURN
> END IF
>
> I don't want to have to code all that at every point I check an error status (whihc could
> easily be 10's of times). I simply do:
>
> IF ( Error1 ) THEN
> Message = 'Error message #1'
> GOTO 1000
> END IF
> ....
> IF ( Error2 ) THEN
> Message = 'Error message #2'
> GOTO 1000
> END IF
> ....etc....
> RETURN
>
> ! -- Clean up after errors
> 1000 CONTINUE
> CLOSE( File_ID1 )
> CLOSE( File_ID2 )
> DEALLOCATE( Local_Array, STAT = Allocate_Status )
> IF ( Allocate_Status /= 0 ) THEN
> ...handle this error...
> END IF
> Error_Status = Destroy_MyType1( MyType1 )
> IF ( Error_Status /= SUCCESS ) THEN
> ...handle this with a WARNING...
> END IF
> Error_Status = Destroy_MyType2( MyType2 )
> IF ( Error_Status /= SUCCESS ) THEN
> ...handle this with a WARNING...
> END IF
>
> It's made some of my code much shorted and easier to read. Keep in mind, though, that I'm
> the type of person who, if a STAT or IOSTAT specifier exists, I check it. In production
> code, I'd even have IOSTAT checks on the CLOSE() statements above.
>
> Maybe it seems like overkill, but these error traps have proven very useful in the past in
> tracking down code and compiler errors.
I think I would write similar code but put the code block after
1000 CONTINUE
in an internal subroutine called something like "handle_errors". This
would make clear that the code is not reached UNLESS an error is
encountered. I admit it is a matter of taste.
- Next message: Kamaraju Kusumanchi: "Is it possible to have multiple strides, dists in fftw3"
- Previous message: *** Hendrickson: "Re: FORMAT in F77"
- In reply to: Paul Van Delst: "Re: FORTRAN "Source Code to Flow Chart Converter" Available"
- Next in thread: Paul Van Delst: "Re: FORTRAN "Source Code to Flow Chart Converter" Available"
- Reply: Paul Van Delst: "Re: FORTRAN "Source Code to Flow Chart Converter" Available"
- Reply: Richard Maine: "Re: FORTRAN "Source Code to Flow Chart Converter" Available"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]