Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

store real*8 in files

kooka
Beginner
895 Views

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

0 Kudos
6 Replies
TimP
Honored Contributor III
895 Views

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.

0 Kudos
kooka
Beginner
895 Views

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

0 Kudos
anthonyrichards
New Contributor III
895 Views
How do you 'know' that the value you store is actually "4.0000000000000000"?
0 Kudos
TimP
Honored Contributor III
895 Views
Assuming you meant READ(20) the last time, you would still have to show us how you set and displayed the value. If the problem is not in the way you set the value, or formatted the display, this effect is more likely to be produced by an accidental over-write of your data in memory. This could be a program or compiler error.We did see recently on one of these forums a case where a no longer current compiler version apparently had a bug with overlapping assignments to 64-bit variables on stack.
0 Kudos
kooka
Beginner
895 Views
yes, was read(20). I still dont know the problem. I write from memory .400000000000, and i read .400000004656... back in memory , its not much a loose of precition until i use big units, but its wrong
0 Kudos
abhimodak
New Contributor I
895 Views

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

0 Kudos
Reply