Converting a working code from double-precision to quadruple-precision: How to read quadruple-precision numbers in FORTRAN from an input file

自作多情 提交于 2019-12-05 13:48:17

Almost all of this is already in comments by @IanH and @Vladimi.

I suggest mixing in a little Fortran 90 into your FORTRAN 77 code.

Write all of your numbers with "E". Change your other program to write the data this way. Don't bother with "D" and don't try to use the infrequently supported "Q". (Using "Q" in constants in source code is an extension of gfortran -- see 6.1.8 in manual.)

Since you want the same source code to support two precisions, at the top of the program, have:

use ISO_FORTRAN_ENV
WP = real128

or

use ISO_FORTRAN_ENV
WP = real64

as the variation that changes whether your code is using double or quadruple precision. This is using the ISO Fortran Environment to select the types by their number of bits. (use needs to between program and implicit none; the assignment statement after implicit none.)

Then declare your real variables via:

real (WP) :: MyVar

In source code, write real constants as 1.23456789012345E+12_WP. The _type is the Fortran 90 way of specifying the type of a constant. This way you can go back and forth between double and quadruple precision by only changing the single line defining WP

WP == Working Precision.

Just use "E" in input files. Fortran will read according to the type of the variable.

Why not write a tiny test program to try it out?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!