- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
0.0 1030.7
1.0 1055.2
2.0 1081.9
...
I defined two double precision arrays to accept the data
REAL*8 AngDat(0:800),GasDat(0:800)
When Iused the following statement to read
do j=0,800
read (GASF,*) AngDat(j),GasDat(j)
enddo
I found that AngDat is no problem while GasDat adding so many random numbers after the 18th digits. Can anybody explain that why the first one is no problem while the second one is not exactly correct by using this "*" format? While, inside the whole array GasDat, I also found that some values are exactly correct while the mostare not. Can anybody explain on that? Is that a defect of IVF?
Because the data format inside the file could change like
0.00000 1030.7
0.0 1030.700000
0.0E5 1030.7
0.0E5 1030.7D0
...
But theygenerally spaced by a space or spaces. These kind of formatis so common in the real practice.Is there any format I can use toread the data correctly? If not, can you guys develop one for that? Or can you guys give a code for that?
Link Copied
- 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
In last thread I found that in double precision, numbers could be as small as 2.0D-308. So I have to change all real*8 to double precision?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In last thread I found that in double precision, numbers could be as small as 2.0D-308. So I have to change all real*8 to double precision?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The answer to your original question has little to do with precision. Nor does is the use of list-directed input the problem.
The numbers in the first column, to the extent that you showed, are small integers, and when stored in REAL*8 IEEE form, are represented exactly. The numbers in the second colum, however, cannot be represented exactly in REAL*8 form. When converted back to decimal, the digits that you see beyond the 16th are of no significance, and you should conclude nothing from them.
Even a "simple" number such as 0.1 cannot be represented exactly in internal IEEE form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Suggest you readhttp://en.wikipedia.org/wiki/Floating_point or similar articles.
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
implicit none
! Variables
Real*8 xeight,yeight
Real xfour,yfour
! Body of RealEight
print *, 'Hello World'
open(unit=10,file='datain.txt',status="old")
read(10,*) xeight,yeight
read(10,*) xfour, yfour
write(6,*) xeight,yeight
write(6,*) xfour, yfour
end program RealEight
Input file looked like this:
1.0 2345.678901
2.0 9876.543210
output to the console looked like this
Hello World
1.00000000000000 2345.67890100000
2.000000 9876.543
So, maybe there are some project settings that force the real*8 to pad with zeros.
Rich

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page