Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

the format of reading data from file

17 views
Skip to first unread message

nakisa

unread,
Jun 25, 2009, 8:41:50 AM6/25/09
to

Hi
I need to read data form a text file. Numbers have two digit after
point (I don't know how it should be say in enlgish , I mean the
numbers are 11.25 ) , when I read and write without format (read (10,
*) ) it writes
11.2500 . I need to ignore those two added zeros. I don't know how
can I control the format of reading data.
read (10 , ??? )

best,nakisa

m_b_metcalf

unread,
Jun 25, 2009, 8:54:31 AM6/25/09
to
The read is fine. To write you need an explicit edit descriptor for
the format (such as you will find described in any compiler manual or
textbook), as in

write(unit_number, '(f7.2)') x

where the '2' is what you're after.

HTH

Mike Metcalf

nakisa

unread,
Jun 25, 2009, 9:50:14 AM6/25/09
to
Hi
what is the meaning of seven after f (f7. ) . this command doesn't
work fine for me . this is the error :

Fortran runtime error: Expected REAL for item 2 in formatted transfer,
got CHARACTER
(f7.2)


best,nakisa

m_b_metcalf

unread,
Jun 25, 2009, 10:07:53 AM6/25/09
to
Please show the exact statement that gives the error.

The 7 is the total field width.

Regards,

Mike Metcalf

nakisa

unread,
Jun 25, 2009, 10:25:26 AM6/25/09
to
Hi again.
that was a stupid mistake in type.
One other question.Let's suppose I need to write 3 numbers , one of
them with one digit after point and tow others with 2 digits after
point , for example :5.6 11.25 11.69
how can I write a command for above output ?
Nakisa

Louis Krupp

unread,
Jun 25, 2009, 10:37:58 AM6/25/09
to

write(unit_number, '(f3.1, 2x, f5.2, 2x, f5.2)') x, y, z

Louis

m_b_metcalf

unread,
Jun 25, 2009, 10:40:11 AM6/25/09
to

Well, by analogy, '(f6.1, 2f7.2)'

Regards,

Mike Metcalf

fj

unread,
Jun 25, 2009, 10:41:54 AM6/25/09
to

write(unit_number,"(f6.1,1X,2(f7.2,1X))") a,b,c

nakisa

unread,
Jun 25, 2009, 12:42:54 PM6/25/09
to
thanks very much. that works fine.
Best,Nakisa

0 new messages