Home > Archive > Fortran > September 2006 > Q: An Fortran 90 Equivalent of 77?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Q: An Fortran 90 Equivalent of 77?
|
|
| qquito 2006-09-28, 9:59 pm |
| Hello, All:
In Fortran 77, I can write
parameter(nd=30)
real a(nd)
......
write(*, 100) a
100 format(<nd>(1x, f6.2))
......
The point is that I can use "<nd>" in the format statement in place of
a specific number, and this is a feature I use frequently.
I found, however, in Fortran 90, this method does NOT work, and I have
to use 30(1x, f6.2) in format.
The question: What is the Fortran 90 equivalent of the above format
which allows a parameter or a variable?
Thanks for reading and replying.
--Roland
| |
| Brooks Moses 2006-09-28, 9:59 pm |
| qquito wrote:
> In Fortran 77, I can write
>
> parameter(nd=30)
> real a(nd)
> ......
> write(*, 100) a
> 100 format(<nd>(1x, f6.2))
> ......
>
> The point is that I can use "<nd>" in the format statement in place of
> a specific number, and this is a feature I use frequently.
>
> I found, however, in Fortran 90, this method does NOT work, and I have
> to use 30(1x, f6.2) in format.
This feature you mention does not work in standard Fortran 77, either.
It's a compiler-specific extension.
> The question: What is the Fortran 90 equivalent of the above format
> which allows a parameter or a variable?
First off, in the example you give, a format of 999(1x, f6.2) will work
exactly the same, so long as nd is less than 999. In a lot of cases,
that will do exactly what you want, and is by far the easiest solution.
If that doesn't work, you have to construct the format string by normal
string operations. An internal write is probably the easiest way:
parameter(nd=30)
real a(nd)
character(25) myformat
......
write(mformat, '(A,I0,A)') '(', nd, '(1x, f6.2))'
write(*, myformat) a
......
Note that this is not only a Fortran 90-and-up solution; it's also
perfectly standard F77, without requiring use of the compiler extension
that you're currently using.
- Brooks
--
The "bmoses-nospam" address is valid; no unmunging needed.
| |
| Richard Maine 2006-09-29, 4:03 am |
| qquito <qquito@hotmail.com> wrote:
> In Fortran 77, I can write
[elided example of a VFE]
No you can't. You can do that in some, but not all, particular Fortran
77 compilers. It is not part of the Fortran 77 language. You can also do
the same thing in some, but not all, Fortran 90 compilers. You are
confusing the language with particular compilers. The question actually
has nothing at all to do with f77 versus f90.
Brooks gave the two simplest standard-conforming solutions, which are
part of f77 and all subsequent versions of the standard. I just thought
I'd elaborate slightly on the above for emphasis.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
| |
| qquito 2006-09-29, 7:01 pm |
| Thanks, Richard and Brooks, for your replies. What Brooks suggested was
only what I could think of, but felt it was not as straightforward as
the one I gave in my example code.
--Roland
Richard Maine wrote:
> qquito <qquito@hotmail.com> wrote:
>
> [elided example of a VFE]
>
> No you can't. You can do that in some, but not all, particular Fortran
> ......
|
|
|
|
|