Writing data with Format

Writing data with Format

I have declared variable as double precision and I would like to write them with format. 

Which descriptor should I use to write data, F or D? For example F22.14 or D22.14.

It is mentioned that I am writing Fortran90 language.

Can any body help me in this regard?

publicaciones de 7 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.
Imagen de Steve Lionel (Intel)

It would depend on the range of values you expect. With F22.14, you'd not be able to represent values higher than 999999 without possibly overflowing the field. Using D (or better, E) format would not have this limitation. Let me suggest you try G format instead, though.

As for "Fortran 90", is there some reason you want to restrict yourself to that?

Steve

Thanks Steve! There is no restrictions. Just I want to read and write datas to files, and want to get more accuracy.

Imagen de Steve Lionel (Intel)

Displaying more digits does not give you more accuracy. It does give you more precision, but it can be misleading if the input values are significantly lower precision and if you haven't done a rigorous computational mathematics analysis of the algorithm. The question to ask yourself is if all those digits are meaningful.

Steve

Again, thanks Steve. I got some valuable informations through your writings.

Actually, I am creating data by y(x)=1+a*sin(2*pi*x/l) for some values of a, l and x, and storing x & y in a file by using Format(2F22.14). Again, I am reading the stored data (x and y) from the file in another program using the same Format(2F22.14) and doing calculations, and then storing the final result in another file.

Is there any mistake?

Imagen de Steve Lionel (Intel)

Well, one "mistake" is that if you use F format, you are potentially representing more digits than are valid for double precision. Another is that you're converting the values twice, potentially introducing roundoff error. I would recommend the use of unformatted I/O to write and read intermediate data, thus eliminating the extra conversions.

Steve

Thanks, Steve. This will be the best way to do it, what I was looking for.

Inicie sesión para dejar un comentario.