Re: Avoiding nested IF conditionals,and STOP statement



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

.



Relevant Pages

  • Re: Avoiding nested IF conditionals,and STOP statement
    ... I'm writing a program in Fortran 95 and reading S. Chapman's "Fortran ... conditional termination of my program. ... then I want to terminate the program. ... avoiding the STOP statement. ...
    (comp.lang.fortran)
  • Avoiding nested IF conditionals,and STOP statement
    ... I'm writing a program in Fortran 95 and reading S. Chapman's "Fortran ... conditional termination of my program. ... then I want to terminate the program. ... avoiding the STOP statement. ...
    (comp.lang.fortran)
  • Alternative to the STOP statement?
    ... I'm writing a program in Fortran 95 and reading S. Chapman's "Fortran ... conditional termination of my program. ... then I want to terminate the program. ... avoiding the STOP statement. ...
    (comp.lang.fortran)
  • Re: he will counter once, load somehow, then aim as to the resignation out of the ward
    ... They are avoiding in line with the garden now, ... bind modes later. ... As within as Mhammed defeats, you can attack the agreement much more ... terminate them behind you. ...
    (sci.crypt)
  • Re: Avoiding nested IF conditionals,and STOP statement
    ... then I want to terminate the program. ... opening a number of files, at each one I want to exit the program if ... avoiding the STOP statement. ... If there are many and a pattern is present, perhaps wrap in a subroutine that can be called would be an option. ...
    (comp.lang.fortran)