MS250

Programs and Routines


Numerical Recipes Online is available here. As the note says there, it is not instead of a license for using their routines.

Sample programs are available from the author of Computational Physics (J.M. Thijssen). Please do not plan on using these instead of  writing your code (that will be pretty obvious!) but they can be useful checks, and can help show you what to do if you are stuck.

Simple spherical bessel function routine from Thijssen.


Note: I recommend using double precision (Real*8 in FORTRAN, and double in C). The reason for this is that the course is oriented towards first-principles computation of materials properties, and extremely high accuracy is needed to compute chemically or mechanically important energies. Sometimes the important contributions are in the 10th or 12th significant figure of the total energy. Numerical Recipes routines are in single precision, and must be modified for double. They advocate single precision, because that is suitable for many applications, and points out to the student more clearly when their algorithm is unstable. If you are using FORTRAN 90, a single change I found is to change the lines in NRTYPE.F90 to:

   INTEGER, PARAMETER :: SP = KIND(1.0D0)
   INTEGER, PARAMETER :: DP = KIND(1.0)

which switches double and single! Another reason to always use double, is to avoid incompatibilities in functions and subroutines, and save time in debugging. 


html and Mathematica notebooks for exercise 2.5

Explicit determinantion of each Smn and Hmn for m,n=1-4

General formulae for Smn and Hmn


How to call Fortran from C (thanks to Matthew Fago)

  1. Add an underscore to the routine name in lower case (compiler dependant?). So "CALL DSYGV(...)" -> "dsygv_(...)
  2. All variables MUST be passed as pointers (except arrays since they "are pointers").
  3. Declare function appropriately, for example
 extern void dsygv_(int *,char [],char [],int *,double *,int *,
                     double *,int *,double *,double *,int *,int *);
  1. Remember that in Fortran arrays are stored in column order, but are in row order in C. Arrays from C must be stored contiguously in memory.
  2. Link program with liblapack.a and libblas.a (depends on platform).
  3. Common variables may need to be passed as arguments to a dummy Fortran routine that sets them up.
  4. You must compile each source code into an object file with the appropriate compiler and then link them
    all together correctly (in linux, you need the g2c library to link fortran and c with gcc). A makefile is very useful for this.

C routines for generalized eigenproblem (Thanks to Peter Bogdanoff)


APW program from Thjissen and potential for Cu 11/22/00