How to Upgrade Your UNIX/Linux or Windows Numerical Recipes Release from Version 2.08 to Version 2.10 by the Text Patch Method

Also, How to Upgrade Your C++ Version 2.10 to C++ Version 2.11

This is the preferred upgrade method for all UNIX and Linux users. For Windows users, this is the alternative method to the preferred Numerical Recipes Upgrade Engine approach.

Macintosh users, please note: We regret that we are unable to provide an automated method for your free upgrades. You can read the patch files linked below as plain text files, and use their contents to make hand edits in the affected files, or you may be able to find a UNIX/Linux-emulating patch program (particularly under Mac OS X, which has many UNIX features).

To upgrade C or Fortran to Version 2.10 (the latest release), you must start with text (source) files of Version 2.08 Numerical Recipes code. If you first need to upgrade from 2.06 to 2.08, look here. If you first need to upgrade from an earlier 2.0x to 2.06, look here. There is no upgrade path from Version 1.xx to Version 2.xx, except to purchase a new download.

For C++, Version 2.10 was the earliest version released, so the upgrade from 2.10 to 2.11 is the only needed upgrade.

The detailed instructions for UNIX/Linux users and for Windows users are similar, but we here spell them out separately.

Detailed UNIX/Linux Instructions

Step 1: Get "patch" program

You need to get a recent version of the celebrated Larry Wall "GNU patch" program. We use version 2.5. Earlier versions might also be fine, but no guarantees. Later versions should be fine.

Most Linux, and many UNIX, installations have this program already installed. Try the command which patch to see if it is in your path. If you don't have it, go to the FSF GNU site or otherwise search the web for "GNU patch".

Step 2: Organize your Numerical Recipes files

Your Numerical Recipes source files need to be organized in exactly the following file tree, with exactly the directory names shown. This is how the source files come packaged in the tar distributions, so if you simply unpacked the tars, you shouldn't have to change anything. (If you don't have all the language versions, you can omit parts of the tree.)

recipes_cpp -- ----+---- recipes [contains *.cpp recipes files]
                   +---- demo ----+---- src [contains x*.cpp examples files]
                   |              +---- ...
                   +---- misc [contains a few utility files]
                   +---- ...
      
recipes_c-ansi ----+---- recipes [contains *.c recipes files]
                   +---- demo ----+---- src [contains x*.c examples files]
                   |              +---- ...
                   +---- misc [contains *.c utility files]
                   +---- ...
      
recipes_c-kr ------+---- recipes [contains *.c recipes files]
                   +---- demo ----+---- src [contains x*.c examples files]
                   |              +---- ...
                   +---- misc [contains *.c utility files]
                   +---- ...      

recipes_f ---------+---- recipes [contains *.f recipes files]
                   +---- demo ----+---- src [contains x*.f examples files]
                   |              +---- ...
                   +---- ...      

recipes_f-90 ------+---- recipes [contains *.f90 recipes files]
                   +---- demo ----+---- src [contains x*.f90 examples files]
                   |              +---- ...
                   +---- ...      
Be sure to keep a backup copy of all your Numerical Recipes files somewhere outside of this tree, in case something goes wrong! (It can happen.)

Step 3: Download patch files into the appropriate directories

Using the following table as a guide, download the appropriate patch data files into their correct directories (in the tree shown above). Be sure that you achieve an exact copy of the downloaded data files. You probably want to shift-click on the links (Netscape) or right-mouse-button-click (Microsoft Internet Explorer) and choose "Save target as...". See troubleshooting for some things that can go wrong.

Note that the last file listed upgrades C++ from 2.10 (its original release version) to 2.11. Also note that version 2.10 is the latest release of all versions except C++.

Download LinkDestination Directory
U208210c-ansi.txt recipes_c-ansi
U208210c-kr.txt recipes_c-kr
U208210f.txt recipes_f
U208210f-90.txt recipes_f-90
U210211cpp.txt recipes_cpp

Step 4 (last step): Run patch

You must now run patch in each of the directories into which you downloaded a patch data file. You must be in the correct working directory. Therefore, the commands are something like:
      cd [...whatever...]/recipes_cpp
      patch -p1 < U210211cpp.txt
for updating C++ from 2.10 to 2.11, or,
      cd [...whatever...]/recipes_c-ansi
      patch -p1 < U208210c-ansi.txt

      cd [...whatever...]/recipes_c-kr
      patch -p1 < U208210c-kr.txt

      cd [...whatever...]/recipes_f
      patch -p1 < U208210f.txt

      cd [...whatever...]/recipes_f-90
      patch -p1 < U208210f-90.txt
for updating C or Fortran from 2.08 to 2.10.

You should get a series of informative messages from the patch program. At the end of the process, your files will have been upgraded to Version 2.10 (C++ to Version 2.11). In upgrading C++, it is possible that you will see a small number of messages stating that the patch is already applied; this means that your starting C++ version was actually Version 2.10a, a minor maintenance release. If you see such messages for all the patches, it is possible that you are mistakenly attempting to apply the patches in reverse, or (for C or Fortran) that you already have the latest version, 2.10.

Detailed Windows Instructions

Step 1: Get "patch" program

You need to get a recent version of the celebrated Larry Wall "GNU patch" program as ported to Windows. We recommend (but have no responsibility for) a port by Karl M. Syring in his nice UnxUtils package. You can also download the executable using the following link

Step 2: Organize your Numerical Recipes files

Your Numerical Recipes source files need to be organized in exactly the following file tree, with exactly the directory names shown. This is how the source files come on the Windows CDROM; if you have the Numerical Recipes WinHelp product, or the files in some other form, you will have to create the directories shown, and move the files into them. (If you don't have all the language versions, you can omit parts of the tree.)

cpp --------+---- recipes [contains *.cpp C++ recipes files]
            +---- examples [contains x*.cpp C++ examples files]
            +---- other [contains *.h and *.c C++ miscellaneous files]

ansi -------+---- recipes [contains *.c ANSI C recipes files]
            +---- examples [contains x*.c ANSI C examples files]
            +---- other [contains *.h and *.c ANSI C miscellaneous files]

k_and_r ----+---- recipes [contains *.c K&R C recipes files]
            +---- examples [contains x*.c K&R C examples files]
            +---- other [contains *.h K&R C miscellaneous files]

f77 --------+---- recipes [contains *.for Fortran 77 recipes files]
            +---- examples [contains x*.for Fortran 77 examples files]
            +---- other [contains nr2dp.dat]

f90 --------+---- recipes [contains *.f90 Fortran 90 recipes files]
            +---- examples [contains x*.f90 Fortran 90 examples files]
            +---- other [contains nr.f90, nrtype.f90, and nrutil.f90]
Be sure to keep a backup copy of all your Numerical Recipes files somewhere outside of this tree, in case something goes wrong! (It can happen.)

Step 3: Download patch files into the appropriate directories

Using the following table as a guide, download the appropriate patch data files into their correct directories (in the tree shown above). Be sure that you achieve an exact copy of the downloaded data files. You probably want to shift-click on the links (Netscape) or right-mouse-button-click (Microsoft Internet Explorer) and choose "Save target as...". See troubleshooting for some things that can go wrong.

Note that the last file listed upgrades C++ from 2.10 (its original release version) to 2.11. Also note that version 2.10 is the latest release of all versions except C++.

Download LinkDestination Directory
W208210ansi.txt ansi
W208210k_and_r.txt k_and_r
W208210f77.txt f77
W208210f90.txt f90
W210211cpp.txt cpp

Step 4 (last step): Run patch

You must now run patch in each of the directories into which you downloaded a patch data file. You must be in the correct working directory. Therefore, the commands are something like:
      cd [...whatever...]\cpp
      patch -p1 < W210211cpp.txt
for updating C++ from 2.10 to 2.11, or,
      cd [...whatever...]\ansi
      patch -p1 < W208210ansi.txt

      cd [...whatever...]\recipes_c-kr
      patch -p1 < W208210k_and_r.txt

      cd [...whatever...]\f77
      patch -p1 < W208210f77.txt

      cd [...whatever...]\f90
      patch -p1 < W208210f90.txt
for updating C or Fortran from 2.08 to 2.10.

You should get a series of informative messages from the patch program. At the end of the process, your files will have been upgraded to Version 2.10 (C++ to Version 2.11). In upgrading C++, it is possible that you will see a small number of messages stating that the patch is already applied; this means that your starting C++ version was actually Version 2.10a, a minor maintenance release. If you see such messages for all the patches, it is possible that you are mistakenly attempting to apply the patches in reverse, or (for C or Fortran) that you already have the latest version, 2.10.

Troubleshooting

1. By far the most common problem has to do with end-of-line (EOL) conventions, and difficulties with preserving the proper EOL convention when downloading the patch data files.

The UNIX/Linux patch data files (U208210*.txt) are in the UNIX EOL convention that lines end with ^J. It is assumed that all the files in the UNIX/Linux directory tree described in Step 2 above are also in this convention. If you have files that have been altered or moved between a Windows and a UNIX/Linux platform, this can cause big problems!

The Windows patch data files (W208210*.txt) are in the Windows/DOS convention that lines end with ^M^J. It is assumed that all the files in the Windows directory tree described in Step 2 above are also in this convention.

If you downloaded the patch data files by displaying them in your browser and then either copying them to the clipboard or doing a "save as", there is a chance that the EOL convention was not properly preserved. Instead, you should force a save-to-disk by backing up to the link to the file, and then either shift-clicking it (for Netscape) or right-mouse-button clicking it (for Microsoft Internet Explorer) and choosing "save target as...".

If all else fails, and you still have files with the wrong EOL convention, and if you can run Perl on your Windows or UNIX/Linux machine, you are welcome to experiment with this Perl script or else try this C program (compiled here for Windows/DOS) for changing EOL conventions in files. A readme file gives further information. We use the Perl script extensively, but we offer it as an unsupported product with no guarantees that it will work for you. You can of course also go into a text editor and change the lines in a file one at a time.

2. The second most common problem is failure to set up the directory structure exactly as indicated in Step 2 above. If the patch program gives messages about unable to find files (other than relating to files that you have chosen not to put in the directory tree), you can usually figure out what is wrong by looking at the lines in the patch data file showing what path is expected to the file in question. For example, if the patch data file has the lines

diff -r -b -B -c1 ansi\recipes\broydn.c ..\ansi\recipes\broydn.c
*** ansi\recipes\broydn.c       Sat Dec 22 12:44:44 2001
--- ..\ansi\recipes\broydn.c    Sat Dec 01 18:03:02 2001
and is run with the -p1 switch (as was shown in Step 4 above), then the first element ("ansi") in the line starting with *** is stripped off, leaving the file name recipes\broydn.c . The patch program expects to find the file at this location relative to the directory in which it is executing. If it is not finding it, then you have set up the directories wrong.

3. The third most common problem is use of an outdated version of the patch program. Be sure that you have a version of GNU patch that is at 2.5 or later.