A question on reading data from a file

A question on reading data from a file

Hi everyone,

I know this is basic, yet I would like to know the reason why this happens.

I'm playing with fortran doing the standard, suppose I have a initial condition between [0:2pi]

with a chaoticity parameter K=1.0. If I want to repeat the experiment numerically I read from

a file the initial condition that I use in the first experiment. I check the results by looking at it

and I notice that although I read and start with the same number (e.g. 0.475265000237136  2.58735041435918)

after 3 or 5 steps of applying the map over this initial conditions I see differences in the numerical results.

This obviously says that there's something different between the data read from a file and the data that one

creates to to calculations on the fly. Why is that?



7 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione

When you read the data from a file, are the values stored as formatted text in the file, or are you using UNFORMATTED files? Does the precision of the variables in memory match the precision of the values written into the file?

I write the data on a file in this way:

Write(names,*) theta_init(control), I_init(control)

And I read it in similar fashion:

Read(names,*) theta_init(control), I_init(control)

If I look both results on screen they give me the same numerical value, for instance,

0.475265000237136  2.58735041435918



What are the declared types of variables control, theta_init and I_init? The binary representations of the values of REAL variables may become altered in the least significant bit after writing and reading back. WIth a chaotic map, such a change can quickly lead to noticeable differences with fewer applications of the map than if the variables had been DOUBLE PRECISION type..

Open the files with FORT='UNFORMATTED' or FORM='BINARY' to write and read the full binary format of the internal variable values (this file will not be readable using an editor).

Jim Dempsey


my arrays are declared as follows 

Real(r8), Allocatable              :: I_init(:), theta_init(:)

so they're double precision variables. I will try the binary or unformatted options.

This is interesting, which is the philosophycal reason that the actual values are modify 

if one write and read in a certain format?




jimdempseyatthecove ha scritto:

Open the files with FORT='UNFORMATTED' or FORM='BINARY' to write and read the full binary format of the internal variable values (this file will not be readable using an editor).

Jim Dempsey

access='stream' (supported by most currently maintained Fortran compilers) is the standard version of the legacy 'binary' options available in several compilers.  The literature seems to indicate this was adopted more to afford inte-language compatibility than for performance.  form="UNFORMATTED" goes back to F77 ahd beyond but the file formats may not work among compilers.

"most" current compilers (and their run-time libraries) adhere to the (somewhat complicated)  IEEE rules for formatted data.  By writing a sufficient number of decimal significant figures (9 for 32-bit single precision, 17 for 64-bit double), loss-less reversible conversions may be maintained to the extent they are feasible.  Needless to say, following such prescriptions implies a penalty in performance and file size.

The standards don't require list-directed formatting to use enough decimals to accomplish such goals.  In the likely case where it's important to you, specific formatting is indicated.

Lascia un commento

Eseguire l'accesso per aggiungere un commento. Non siete membri? Iscriviti oggi