- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve! There is no restrictions. Just I want to read and write datas to files, and want to get more accuracy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, Steve. This will be the best way to do it, what I was looking for.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page