For Programmers: Free Programming Magazines  


Home > Archive > Fortran > April 2006 > rookie question









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 rookie question
morten.langer@gmail.com

2006-04-25, 7:10 pm

Hi NG,

I have a file containing numbers that looks like this:

7.14344E-11
9.32523E-11
1.02323E-10
..
..


How do I read that into a dimensioned array and write them back out? I
have trouble with the formatting.. I have tried this in a loop:

read(numberOfFile,"(e12.6)") array(i)

and

read(numberOfFile,"(f32.16)") array(i)

but I don't seem to get any values into the array? What is the correct
formatting statement?

Thanks!

Best,

M.L.

Richard Maine

2006-04-25, 7:10 pm

<morten.langer@gmail.com> wrote:

> How do I read that into a dimensioned array and write them back out? I
> have trouble with the formatting.. I have tried this in a loop:
>
> read(numberOfFile,"(e12.6)") array(i)
>
> and
>
> read(numberOfFile,"(f32.16)") array(i)
>
> but I don't seem to get any values into the array? What is the correct
> formatting statement?


Either is fine. I woukd say that your conclusion about the nature of the
problem is incorrect. I doubt that it has anything to do with the
formatting. I suggest showing moe context about what you are doing and
what theproblem symptoms are. You are telling us conclusions rather than
raw data. Your conclusions are that you have trouble with the formatting
and that you "don't seem to get any values into the array", whatever
that means.

I suggest showing complete code. That includes the declaration of the
array, the OPEN statement, the loop, and whatever lead you to conclude
that there is no data in the array. I can't tell what of them would be
the problem. The statements that you do show are perfectly fine. I don't
have enough data to guess where else you might have gone wrong. I could
imagine things such as your loop running for zero iterations - that
would do it.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
beliavsky@aol.com

2006-04-25, 7:10 pm


morten.langer@gmail.com wrote:
> Hi NG,
>
> I have a file containing numbers that looks like this:
>
> 7.14344E-11
> 9.32523E-11
> 1.02323E-10
> .
> .
>
>
> How do I read that into a dimensioned array and write them back out? I
> have trouble with the formatting..


Are you aware of list-directed formatting? If you want to read an array
X of reals, simply

read (file_unit,*) X

should do the trick, given the file format you have shown. Fortran
"knows" to read as many of the lines of the file as necessary to fill
array X.

Herman D. Knoble

2006-04-25, 7:10 pm

M.L.

If you cannot use free format, like READ(unit,fmt=*), try the
format item: F12.0

Skip Knoble

On 23 Apr 2006 15:20:05 -0700, morten.langer@gmail.com wrote:

-|Hi NG,
-|
-|I have a file containing numbers that looks like this:
-|
-|7.14344E-11
-|9.32523E-11
-|1.02323E-10
-|.
-|.
-|
-|
-|How do I read that into a dimensioned array and write them back out? I
-|have trouble with the formatting.. I have tried this in a loop:
-|
-|read(numberOfFile,"(e12.6)") array(i)
-|
-|and
-|
-|read(numberOfFile,"(f32.16)") array(i)
-|
-|but I don't seem to get any values into the array? What is the correct
-|formatting statement?
-|
-|Thanks!
-|
-|Best,
-|
-|M.L.

Richard E Maine

2006-04-25, 7:10 pm

Herman D. Knoble <SkipKnobleLESS@SPAMpsu.DOT.edu> wrote:

> If you cannot use free format, like READ(unit,fmt=*), try the
> format item: F12.0


I cannot imagine any situations in which either free format or F12.0
would help the OP's problem as stated. Admitedly, the problem statement
was vague, but I just don't see these suggestions as being in a
plausible direction. Fiddling with the format just isn't likely to help.
The OP's formats should have worked fine. I could propose almost an
infinite number of other formats that would also work fine, but that
doesn't seem likely to help. F12.0 is certainly valid, but why would it
be any different from the E12.6 that the OP claimed to have tried? Do
note that this is for input data with explicit decimal points. Output
would, of course, be different. And things can get messy for input data
without decimal points. But those would all be different questions.

--
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
meek@skyway.usask.ca

2006-04-25, 7:10 pm

In a previous article, morten.langer@gmail.com wrote:
>Hi NG,
>
>I have a file containing numbers that looks like this:
>
>7.14344E-11
>9.32523E-11
>1.02323E-10
>.
>.
>
>
>How do I read that into a dimensioned array and write them back out? I
>have trouble with the formatting.. I have tried this in a loop:
>
>read(numberOfFile,"(e12.6)") array(i)
>


As other posters have said .. that should work.
Was the data file produced on the same system?
I have tripped over unix/windows format problems
in the past e.g. unix ends with LF only whereas
windows compilers use CRLF --- or vice versa.
Specific keywords had to be used in the open statement
for a successful read.
The only way to be sure is to look at the file
by binary dump ... a suggestion which doesn't help if your
compiler can't do that.
So just try all possible (formatted) keywords in your open
statement.
Chris
<snip>
Herman D. Knoble

2006-04-25, 7:10 pm

Richard: Thanks for the poster's sake. I read it bug didn't read it,
if you know what I mean.
Skip

On Mon, 24 Apr 2006 08:49:33 -0700, nospam@see.signature (Richard E Maine) wrote:

-|Herman D. Knoble <SkipKnobleLESS@SPAMpsu.DOT.edu> wrote:
-|
-|> If you cannot use free format, like READ(unit,fmt=*), try the
-|> format item: F12.0
-|
-|I cannot imagine any situations in which either free format or F12.0
-|would help the OP's problem as stated. Admitedly, the problem statement
-|was vague, but I just don't see these suggestions as being in a
-|plausible direction. Fiddling with the format just isn't likely to help.
-|The OP's formats should have worked fine. I could propose almost an
-|infinite number of other formats that would also work fine, but that
-|doesn't seem likely to help. F12.0 is certainly valid, but why would it
-|be any different from the E12.6 that the OP claimed to have tried? Do
-|note that this is for input data with explicit decimal points. Output
-|would, of course, be different. And things can get messy for input data
-|without decimal points. But those would all be different questions.

Richard E Maine

2006-04-25, 7:10 pm

Herman D. Knoble <SkipKnobleLESS@SPAMpsu.DOT.edu> wrote:

> Richard: Thanks for the poster's sake. I read it bug didn't read it,
> if you know what I mean.


Yes. Been there. Done that.

--
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
morten.langer@gmail.com

2006-04-25, 7:11 pm

Hi all,

Thanks for your input - i manged to get it solved, so now I am on to my
next problem :o) I appreciate the help - thanks again.

Best,

M.L.

glen herrmannsfeldt

2006-04-25, 7:11 pm

morten.langer@gmail.com wrote:

> Thanks for your input - i manged to get it solved, so now I am on to my
> next problem :o) I appreciate the help - thanks again.



When you find the answer it is nice to post it.
That way everyone will learn which solution was right.
It can be useful if a similar question comes up later.

thanks,

-- glen
morten.langer@gmail.com

2006-04-25, 7:11 pm

Oh - you have a point. In this case, though, the solution was just a
matter of looping correctly over the array. As one poster pointed out,
that might be the problem, and it was. So - nothing very sophisticated,
I am afraid.

Best,

M.L.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com