# PHYS-4007/5007 Useful Fortran 77 Subroutine and Functions Web Page

This web page contains the links of the various files that contain useful Fortran 77 subroutines and functions needed for PHYS-4007/5007 Computational Physics. There are two sets of files below. The first to solve ordinary differential equations and the second to carry out linear least squares fitting of data. All of the files here are in standard ASCII (text) format so that when you click on the link, the code will appear in your web browser. Follow these steps to save these files on your Linux machine.
• Note the name of the file on the Course Fortran 77 Web Page (e.g., rk4.f).
• Open a Terminal window on your Linux account. Change directory to your Fortran subdirectory (e.g., cd fortran).
• Start the emacs editor from the terminal window using the filename of a given file (e.g., emacs rk4.f).
• When the text in the file appears highlight all of the text on the screen using the "Edit" pull-down menu and clicking "Select All."
• Go back to the "Edit" pull-down menu and select "Copy."
• Go to the emacs editor window and select the "Edit" pull-down menu and select "Paste."
• From the emacs window, click the 'Save File' icon and then exit emacs.

## Numerical Ordinary Differential Equations (ODE) Files

The following is a list of useful Fortran 77 subroutines and functions use to numerically solve ordinary differential equations. Feel free to use them if you need them in your work.

 rk4.f Fortran 77 subroutines using the 4th-order Runge-Kutta technique for ODEs. ode.f Fortran 77 subroutines using the Adams method for ODEs. Note that this     file also contains the DE, STEP, and INTRP subroutines. de.f Fortran 77 subroutine of Adams method for ODEs. intrp.f Fortran 77 subroutine called by de.f. step.f Fortran 77 subroutine called by de.f. machin.f Fortran 77 program to calculate data for ode.f and de.f. f.f Sample Fortran 77 subroutine containing the differential equations that     ode.f and de.f are asked to solve.

## Numerical Linear Least-Squares Fitting Files

The following is a list of useful Fortran 77 subroutines and functions use to numerically solve ordinary differential equations. Feel free to use them if you need them in your work.

 fit.f Fortran 77 subroutine to fit data to a straight line using the linear least-squares     fitting technique. gammq.f Fortran 77 function to calculate the complement of the incomplete gamma     function, Q(a, x) = 1 - P(a, x), where P(a, x) is the incomplete gamma function. gser.f Fortran 77 subroutine to calculate the incomplete gamma function using a     series solution. gcf.f Fortran 77 subroutine to calculate the incomplete gamma function using a     continued fraction technique. gammln.f Fortran 77 function to calculate the natural log of the gamma function.

Let say we have a Fortran 77 program that contains data representative of a linear function called mylinfit.f and we wish to carry out a linear least-squares fit to this data and print out the parameters of this straight line fit. Once we are in an appropriate subdirectory of a Linux computer, we then issue the following command to compile and link our files into an executable file using

gfortran   -o mylinfit.exe   mylinfit.f   fit.f   gammq.f   gser.f   gcf.f   gammln.f

We then run this program using

./mylinfit.exe