- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
im storing data in a file that is real*8, but when i open the file it retrieves me real*4, how can i store real*8 types in a file?
Thanks
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Supposing that you use unformatted write, the data stored in the file will be the same size as the data type you write from. Then, you would be able to read back correctlyonly into the same size data type. So, it seems there is something inconsistent.
If you used formatted write, you would require a format with a precision field of 17, and typically 25 bytes total written to the file, to preserve full double precision accuracy. You could read back into either a single or double precision variable as you choose.
An example would help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, is unformated. i Know is somting rare, but for example when i store 4.000000000000000000, it retrieves me 4.00000000001246586734. So the last bytes are filled whit strange numbers. I think the problem is with the record size in my file. Ie:
!subroutine to write in the file
...
real*8 tendones
OPEN(20,file=filename,ACTION='WRITE', FORM='UNFORMATTED', STATUS='UNKNOWN' )
write(20) TENDONES
....
!sub to read
...
real*8 tendones
OPEN(20,file=filename,ACTION='read', FORM='UNFORMATTED', STATUS='OLD' )
write(20) TENDONES
...
!Tthen if tendones was stored as 4.0000000000000000, gives 4.000000001235637645
- 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
- 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
I am taking a guess here but when youmake assigment are you using0.4d0? If you use just 0.4 or 0.4e0, you will get those "extra digits". For example, the snippet below will produce: 0.100000001490166, 0.100000000000000.
Abhi
----------
Program Test_Precision
Implicit None
Real(8) :: b1, b2
b1 = 0.1
b2 = 0.1d0
print *, b1, b2
End Program Test_Precision

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