Re: Avoiding nested IF conditionals,and STOP statement
- From: e p chandler <epc8@xxxxxxxx>
- Date: Wed, 24 Sep 2008 14:02:28 -0700 (PDT)
On Sep 24, 3:13 pm, s_siouris <s_siou...@xxxxxxxxxxx> wrote:
Hi all,
I'm writing a program in Fortran 95 and reading S. Chapman's "Fortran
90/95 for Scientists and Engineers" and I have a problem concerning
conditional termination of my program.
There are a few points in my program where if the input is not
suitable, then I want to terminate the program. For example, if I am
opening a number of files, at each one I want to exit the program if
the file hasn't opened correctly. Chapman's style is to put IF
conditionals one inside the other, avoiding the STOP statement. I find
these nested IF's a little bit too much if there are a lot of cases
where I want to terminate the program prematurely, so I would like
some advice on how to approach this, avoiding the nested IF's, and
also avoiding the STOP statements.
How can you program this elegantly?
Thanks
Spiros
You could try IF .. THEN .. ELSE IF ...
Or you could have the "inner loop" return a flag variable. Then the
next loop tests that flag.
Or you could put some of the code into subroutines.
But I don't see anything wrong with using STOP. It's clear and simple,
particularly if used in a main program.
For example:
IF (ierr /= 0) THEN
WRITE(*,*) 'Failed to open first data file.'
STOP
END IF
IMO you should reserve your concern for "elegance" for something more
important.
- e
.
- References:
- Avoiding nested IF conditionals,and STOP statement
- From: s_siouris
- Avoiding nested IF conditionals,and STOP statement
- Prev by Date: IEEE 754r published (Was: Re: rounding mode)
- Next by Date: Re: Avoiding nested IF conditionals,and STOP statement
- Previous by thread: Re: Avoiding nested IF conditionals,and STOP statement
- Next by thread: Re: Avoiding nested IF conditionals,and STOP statement
- Index(es):
Relevant Pages
|
|