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

Writing data with Format

Nazmul_I_1
Beginner
408 Views

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?

0 Kudos
6 Replies
Steven_L_Intel1
Employee
408 Views

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?

0 Kudos
Nazmul_I_1
Beginner
408 Views

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

0 Kudos
Steven_L_Intel1
Employee
408 Views

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.

0 Kudos
Nazmul_I_1
Beginner
408 Views

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?

0 Kudos
Steven_L_Intel1
Employee
408 Views

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.

0 Kudos
Nazmul_I_1
Beginner
408 Views

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

0 Kudos
Reply