Home > Archive > Fortran > June 2004 > [Q] FORMAT
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]
|
|
| Jaegu Lee 2004-06-25, 7:43 pm |
| Hello.
There was no probelm using " write( 10, * ) ( output(i), i=1,n,1 ) with
lahey fortran.
The output file must be written in one line regardless of 'n' to read with
'Tecplot'
'n' increases with iteration, and i don know how many iterations are
repeated. It depens on the cases
But if I use intel fortran the output file is not written in one line so I
have to use format statement.
Shoud i write like this? write( 10, '(10000E13.4)' ) ( output(i), i=1,n,1 )
I know the statement ' 100 format ( nE13.4 ) ' is not working.
Is there any other way?
| |
|
| On Mon, 21 Jun 2004 22:37:06 +0900, "Jaegu Lee" <gulee@postech.ac.kr>
wrote:
>Hello.
>
>There was no probelm using " write( 10, * ) ( output(i), i=1,n,1 ) with
>lahey fortran.
>
>The output file must be written in one line regardless of 'n' to read with
>'Tecplot'
>
>'n' increases with iteration, and i don know how many iterations are
>repeated. It depens on the cases
>
>But if I use intel fortran the output file is not written in one line so I
>have to use format statement.
>
>Shoud i write like this? write( 10, '(10000E13.4)' ) ( output(i), i=1,n,1 )
>
>I know the statement ' 100 format ( nE13.4 ) ' is not working.
>
>Is there any other way?
>
>
Perhaps something along this line:
program test
character*20 fmt
real a(10)
data a/10*10.0/
n=10
write(fmt,'(a,i4,a,a)') '(',n,'E13.4',')'
write(6,fmt) (a(i),i=1,n,1)
end
JMJ
Jens-Martin
jmj at elsam dash eng dot com
| |
| Steve Lionel 2004-06-25, 7:43 pm |
| On Mon, 21 Jun 2004 22:37:06 +0900, "Jaegu Lee" <gulee@postech.ac.kr> wrote:
>Shoud i write like this? write( 10, '(10000E13.4)' ) ( output(i), i=1,n,1 )
>
>I know the statement ' 100 format ( nE13.4 ) ' is not working.
>
>Is there any other way?
You could use an extension called Variable Format Expressions, for example:
write (10,'(<n>E13.4)') (output(i),i=1,n,1)
The use of 1000 will probably work too, if 1000 is known to be larger than the
dimension of the array.
Steve Lionel
Software Products Division
Intel Corporation
Nashua, NH
User communities for Intel Software Development Products
http://softwareforums.intel.com/
Intel Fortran Support
http://developer.intel.com/software/products/support/
| |
| Richard Maine 2004-06-25, 7:43 pm |
| "Jaegu Lee" <gulee@postech.ac.kr> writes:
> There was no probelm using " write( 10, * ) ( output(i), i=1,n,1 ) with
> lahey fortran.
>
> The output file must be written in one line regardless of 'n' to read with
> 'Tecplot'
The "*" format leaves it up to the compiler whether to write this all on
one line or not. If you need it all on one line, then you need to be
more specific about it by using an explicit format. Otherwise, your
program is not portable.
> Shoud i write like this? write( 10, '(10000E13.4)' ) ( output(i), i=1,n,1 )
This is a fairly requently asked question. Yes, something like that
would be my recommendation as the best choice. It is the simplest and
should work fine.
> I know the statement ' 100 format ( nE13.4 ) ' is not working.
Correct. That won't work.
> Is there any other way?
Yes. There are at least 2 other ways, but I recommend the one above
as the simplest. The other 2 choices are
2. Use nonadvancing I/O.
3. Use an internal write to generate an explicit format with the "n"
value substituted in.
I won't bother to write code samples for these because I think the answer
you already found is better. Besides, there were code samples for
this kind of thing just a w or two ago, so it shouldn't be hard
to find them if you really want. (I'd suggest searching for
"nonadvancing" or "internal" as keywords if you try.)
One could imagine other ways also, but the other ideas that occur to
me just add more complication for no obvious gain. (For example,
I suppose one could build the whole line in an internal character
buffer, but that just adds complications having to do with sizing
the buffer - doesn't seem like progress in the right direction.)
--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
| |
| Jaegu Lee 2004-06-25, 7:43 pm |
| The first method which Lionel talked about worked successfully in Lahey but
not Intel.
And the second, JMJ sugested, worked in Intel fortran.
Thanks a lot.
| |
| Steve Lionel 2004-06-25, 7:44 pm |
| On Tue, 22 Jun 2004 00:19:47 +0900, "Jaegu Lee" <gulee@postech.ac.kr> wrote:
>The first method which Lionel talked about worked successfully in Lahey but
>not Intel.
I find that difficult to believe, unless you're using a very old (as in years
old) Intel compiler....
Steve Lionel
Software Products Division
Intel Corporation
Nashua, NH
User communities for Intel Software Development Products
http://softwareforums.intel.com/
Intel Fortran Support
http://developer.intel.com/software/products/support/
| |
| Richard Maine 2004-06-25, 7:44 pm |
| Steve Lionel <Steve.Lionel@intel.com> writes:
> On Tue, 22 Jun 2004 00:19:47 +0900, "Jaegu Lee" <gulee@postech.ac.kr> wrote:
>
>
> I find that difficult to believe, unless you're using a very old (as in years
> old) Intel compiler....
I hadn't paid that much attention to which compilers he was claiming
did and didn't support it. I already knew that it was a nonstandard
feature (as you mentioned), which wasn't supported by all compilers.
But now that you point it out, it does seem amusing to suggest that
Intel Fortran might not support it, insomuch as Intel Fortran is now
in some ways the most direct descendant of DEC VAX Fortran. Isn't DEC
VAX Fortran where VFEs originated? I don't know that for sure, but it
would be my guess.
Of course, perhaps if the claim was about an old version of Intel
from before The Dec/Digital/Compaq team went to Intel, then it
might be less amusing.
--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
| |
| Steve Lionel 2004-06-25, 7:44 pm |
| On 21 Jun 2004 13:25:36 -0700, Richard Maine <nospam@see.signature> wrote:
>But now that you point it out, it does seem amusing to suggest that
>Intel Fortran might not support it, insomuch as Intel Fortran is now
>in some ways the most direct descendant of DEC VAX Fortran. Isn't DEC
>VAX Fortran where VFEs originated? I don't know that for sure, but it
>would be my guess.
>
>Of course, perhaps if the claim was about an old version of Intel
>from before The Dec/Digital/Compaq team went to Intel, then it
>might be less amusing.
VFEs first appeared in DEC PDP-11 FORTRAN-IV-PLUS, but they became popularized
by VAX Fortran. Intel Fortran 7 was supposed to implement them, though there
may have been bugs here and there. Intel Fortran 8, the first that is
directly derived from DEC Fortran, definitely supports them.
VFEs are a simple-sounding feature that are extremely difficult to implement
properly. We've been cursed by other vendors through the years for it, and
had no lack of problems getting it right ourselves in various iterations of
the compilers.
Steve Lionel
Software Products Division
Intel Corporation
Nashua, NH
User communities for Intel Software Development Products
http://softwareforums.intel.com/
Intel Fortran Support
http://developer.intel.com/software/products/support/
|
|
|
|
|