Re: Fortran Error Problem
- From: nospam@xxxxxxxxxxxxx (Richard Maine)
- Date: Tue, 28 Nov 2006 09:52:36 -0800
David Flower <DavJFlower@xxxxxxx> wrote:
Your program references X(9) etc. From the line containing the
reference to X(9), the compiler cannot tell whether it is:
1) The 9th element of the array X or
2) A reference to an external function X
The way it decides is to look for the type statement associated with X.
If the type statement assigns (a) dimension(s) to X, then the compiler
knows X is an array.
Otherwise, including no type statement, when X defaults to REAL, X is
assumed to be an external FUNCTION.
Well, yes, except for a slight nitpick. The dimension information can be
in multiple places, not just on a type declaration statement. My
personal style is to always put it in the type declaration statement.
The compiler can find the information in any of several places... but
the human reader might well use exactly the method you described, and
thus overlook those other places. That's part of why I personally always
put it in the type declaration statement.
Another comment on the OP's program. This isn't in response to David,
but I'll put it here instead of making a 2rd post to the thread.
In addition to not being dimensioned, X is never assigned a value.
That's the next problem you will run into. Presumably you either forgot
about that part or just haven'ty gotten to it yet (as you say the code
is in development). But nothing good can come from trying to use the
values in X in the very first line without them ever having been
defined.
I'm surprised that nobody has yet mentioned IMPLICIT NONE. I generally
recommend its use. It would have caused a better error message for this
code, directly calling attention to the fact that X was not declared. Of
course, you also have a bunchj of other undeclared variables. You appear
to have declared only the arrays. I personally think that a undesirable
and error-prone style.
Hmm. And speaking of declarations, I see that you use some double
precision constants (36.d6 and 2.d0) and the double precision dsqrt.
While that is valid, it doesn't achieve anything useful because you put
the results in single precision variables; they are single precision
because you haven't declared them. Declarations are an important part of
the code. Paying inadequate attention to them is a common source of
errors.
I have several other stylistic comments about the code, but I'll
withhold them so as to not "pile on" and sound too critical. Although
you are obviously using an f90/f95 compiler, the general coding style
looks very much like f77 (and early f77 at that). If you are new to the
language, this makes me suspect that you either have an old Fortran text
or are otherwise learning it from old examples. There's nothing
concretely wrong with that, but I think you would be well advised to
seek some newer reference materials.
Ok, just to briefly mention the stylistic things, without belaboring
them.... monocase, lack of indentation, do/continue (though I see
do/enddo also used). And two things that are more f66 style: dsqrt
instead of the generic sqrt, and use of arithmetic IF (particularly in
the cases where it has only 2 distinct branches). None of these are
wrong per se, but they are recognizably styles from 25-30 years ago.
While some of the style changes over the years might be views as just
"fashion", many of them reflect matters of code readability and
maintainability and thus merit more serious attention. (If you saw how I
dressed and cut my hair, you'd know that I am no big fan of fleeting
fashion. :-))
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.
- References:
- Fortran Error Problem
- From: engrzia76
- Re: Fortran Error Problem
- From: engrzia76
- Re: Fortran Error Problem
- From: David Flower
- Fortran Error Problem
- Prev by Date: Re: Fortran Error Problem
- Next by Date: Re: defining an arbitrary type in your newer Fortrans
- Previous by thread: Re: Fortran Error Problem
- Next by thread: elemental function versus loop over function
- Index(es):
Relevant Pages
|