- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I paste the code first:
open(5,file='read-test.txt',status='old')
read(5,'(F8.2)') rd
write(6,'(F8.2)') rd
content in read-test.txt:
.0028 .0197 270.25 40.0
here's the question:
why the read command whose format is '(F8.2)', reads all 4bit fraction , while the write command strictly output only 2bit fraction? I'm confused by the different behaviors between read and write.
open(5,file='read-test.txt',status='old')
read(5,'(F8.2)') rd
write(6,'(F8.2)') rd
content in read-test.txt:
.0028 .0197 270.25 40.0
here's the question:
why the read command whose format is '(F8.2)', reads all 4bit fraction , while the write command strictly output only 2bit fraction? I'm confused by the different behaviors between read and write.
Link Copied
8 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You should read the section of the Compaq Fortran Language Reference Manual pertaining to F format (11.2.4.1)
Briefly, on input, the only effect the .2 has is if the input value has no decimal point - then it assumes the rightmost two digits are the fraction.
It is often the case that formats do different things on input and output. This is explained in the LRM.
Steve
Briefly, on input, the only effect the .2 has is if the input value has no decimal point - then it assumes the rightmost two digits are the fraction.
It is often the case that formats do different things on input and output. This is explained in the LRM.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thank you, steve
It's always a good time to post question here!
What LRM stands for?
It's always a good time to post question here!
What LRM stands for?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve pointed to chapter 11.2.4.1 (F editing) in Language Reference Manual (LRM). It's I/O formatting (pages 11-16 in the printed version or 291 in electronic version (pdf)). Examples from there (separated by semicolon)
Format; Input; Value
F8.5; 123456789; 123.45678
F8.5; -1234.567; -1234.56
F8.5; 24.77E+2; 2477.0
F5.2; 1234567.89; 123.45
Format; Value; Output
F8.5; 2.3547188; ^2.35472
F9.3; 8789.7361; ^8789.736
F2.1; 51.44; **
F10.4; -23.24352; ^^-23.2435
F5.2; 325.013; ******
F5.2; -.2; -0.20
A.
Format; Input; Value
F8.5; 123456789; 123.45678
F8.5; -1234.567; -1234.56
F8.5; 24.77E+2; 2477.0
F5.2; 1234567.89; 123.45
Format; Value; Output
F8.5; 2.3547188; ^2.35472
F9.3; 8789.7361; ^8789.736
F2.1; 51.44; **
F10.4; -23.24352; ^^-23.2435
F5.2; 325.013; ******
F5.2; -.2; -0.20
A.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hmm - the examples in the manual don't seem to have taken rounding into account. I'll look into that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
I checked it, it's OK (I mean LRM) for double precision - 1234.45678 (no rounding) while for single it's rounded to 123.4568.
A.
I checked it, it's OK (I mean LRM) for double precision - 1234.45678 (no rounding) while for single it's rounded to 123.4568.
A.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks, arturguzik, I finally found the topic in Online Document(with this keyword F8.5). I didnt find LRM's pdf file.
I think, it is not necessary for read to take rounding into account, but it is necessary for write.
I think, it is not necessary for read to take rounding into account, but it is necessary for write.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Read rounds the value to the closest representable value - the .n part of the format doesn't matter for this.
Steve
Steve
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page