.. _fortran_software: ============================================================= Fortran Software Packages ============================================================= Fortran has many basic mathematical functions as built-in (intrinsic) functions, standard math functions like `sqrt`, `sin`, `exp`, etc. (see :ref:`fortran_intrinsic`) and also matrix operations such as `transpose` and `matmul` (see :ref:`fortran_arrays`). To solve more complex mathematical problems it is generally necessary to either use some *software package* or write your own code from scratch. In general it is best to use high-quality software as much as possible, for several reasons: * It will take less time to figure out how to use the software than to write your own version. (Assuming it's well documented!) * Good general software has been extensively tested on a wide variety of problems. * Often general software is much more sophisticated that what you might write yourself, for example it may provide error estimates automatically, or it may be optimized to run fast. You will probably need to write a main program to call the software, and often auxiliary functions to describe your problem. Some software consists of a single subroutine or function that you can easily download and compile with the rest of your code. Other software is in the form of a large package that must be installed in some manner before use. Often large collections of subroutines are organized into *libraries* that can be compiled once and stored in a manner that makes it easier to use by simply *linking* your `.o` files to the library, which automatically pulls out the object code for the particular library routines you use in the program. This frees the user from having to figure out what set of `.o` or `.f` files are required from the software package for each application of the software. For examples of this, see the sections on :ref:`linalg`. `zeroin` software ----------------- As a very simple example of a single-function piece of software, see the directory `$CLASSHG/codes/fortran/zeroin `_ This contains code to compute the `n`'th root of `a` by finding a zero of the function :math:`f(x) = x^n - a` as in :ref:`homework3`. But instead implementing Newton's method as described in :ref:`special_functions`, the function `zeroin` is used, which was obtained from `Netlib `_, a repository of mathematical software. The version of `zeroin` used is a slight modification of the Netlib version ``_, modified to remove the dependence on `d1mach`.