[Rd] Fortran coding standards

Vivek Rao rvivekrao at yahoo.com
Wed Apr 11 15:28:53 CEST 2007


I have some comments on the Fortran code in the
fseries package in file 4A-GarchModelling.f ,
especially the subroutine GARCHFIT and function
DSNORM.
I appended the code to the end of an earlier message,
but it was rejected by some rule. Let me first say
that I am grateful that packages for financial
econometrics exist in R.

Fortran 77 had PARAMETERs, and PARAMETERs equal to
99999 and 200 should have been defined instead of
repeatedly using "magic numbers". More importantly,
the code will fail if NN exceeds 99999, but the code
does not check for this. I hope someone will fix this.

In the code dsged the variables half, one, two should
be made parameters, and instead of 

      IMPLICIT DOUBLE PRECISION (A-H, O-Z)

      IMPLICIT NONE 

should be used and all variables declared. Although
IMPLICIT NONE is not standard Fortran 77, it is
standard Fortran 90 and is supported by g77.
Experienced Fortranners know that IMPLICIT NONE
catches errors. Another defect is the use of specific
intrinsic functions such as DSQRT. There is no need to
use this, since the SQRT function is generic, handling
both single and double precision arguments.

Maybe there should R coding standards to address such
issues. I hope that eventually the Fortran code in R
will use the modern features of Fortran 90 and later
standards, using the gfortran compiler. However, with
a little effort one can still write clean code in
Fortran 77 that also conforms to later standards.

Vivek Rao


       
____________________________________________________________________________________
It's here! Your new message!  
Get new email alerts with the free Yahoo! Toolbar.



More information about the R-devel mailing list