.TI F77/TO_DOUBLE "Sep. 4, 1985"
Converting Programs to Double Precision

On VAXs, single precision provides about 6-7 digits of accuracy while
double precision provides about 15-16 digits of accuracy.
Many mathematical subroutine libraries assume
double precision arguments.
If you have a program written in single precision which needs to be
run in double precision, you can either use f77's -r8 flag
to compile it as if it were written in double precision,
or follow the following steps to convert the source.
If you use the -r8 flag, you still must check equivalences and
common blocks as described in paragraph 9 below.

To convert a program from single to double precision:

.IP 1.
Add 'implicit double precision (a-h,o-z)'
as the first line of the main program (second line if you have
a 'program' statement) and as the second line of all other 
subprograms (subroutines, functions, and block data subprograms).

.IP 2.
Change all 'real' or 'real*4' declarations to 'double precision'.

.IP 3.
Change single precision floating point constants to double precision,
either by adding 'd0' or changing an 'e' exponent term to 'd', e.g.:
.nf
		1.2    becomes 1.2d0
		3.2e-5 becomes 3.2d-5
.fi

.IP 4.
Change 'complex' or 'complex*8' declarations to 'double complex'.

.IP 5.
Formats do not need to be changed.

.IP 6.
Change single precision intrinsic functions to double.  Because of the
generic function names in f77, the only ones you need to actually change are:

.nf
	single version:		double or generic version:
	   ifix()			int()
	   sngl()			dble()
	   real()			dble()
	   float()			dble()
	   amax1()			max()
	   amin1()			min()
	   amod()			mod()
	   alog()			log()
	   alog10()			log10()
.fi

.IP 7.
Change complex intrinsic functions to double complex.

.nf
	complex version:	double complex or generic version:
	   cmplx()			dcmplx()
	   aimag()			imag()
	   csqrt()			sqrt()
	   cexp()			exp()
	   clog()			log()
	   ccos()			cos()
	   csin()			sin()
	   cabs()			abs()
.fi

.IP 8.
If you are passing functions as arguments to other subroutines,
you need to change all function names to specific functions.
For example:

.nf
		x1 = sqrt(x2)
		c1 = abs(c2)
.fi

works fine when x1 and x2 are double and c1 and c2 are double complex.
However, if the computation is being done in a subroutine,

.nf
		external sqrt, cabs
		call subr( x1, x2, sqrt, c1, c2, cabs )
.fi

it must be changed to:

.nf
		external dsqrt, cdabs
		call subr( x1, x2, dsqrt, c1, c2, cdabs )
.fi

.IP 9.
Check equivalences common blocks, and dynamic memory allocation.
Often these implicitly assume that floating point and integer values
use the same amount of storage.
For example, if one subroutine declares:

		common /abc/ key1,vec(5),ival

and another declares:

		common /abc/ dummy(6), ival

then the two instances of 'ival' match.  If you change 'dummy'
and 'vec' from single precision to double precision (either
explicitly or via the -r8 flag), the two
instances of 'ival' will no longer correspond.
