To correct this problem, exit the program (usually by hitting "[CONTROL] C") then execute the program again, this time entering the correct responses. The code needed to check for errors of this nature would have introduced unnecessary overhead and would have made the programs less readable.
7. Useful Utilities
The utilities listed below are found in the UTIL sub-directory on the distribution diskettes. None of these utilities are absolutely necessary, but they may make life easier on your part if you use them. "Convert.c" will make the algorithms have respectable looking output if uploaded to non-MS-DOS computer systems. "List.com" is a handy tool for quickly viewing the output files created by these programs. Several files are also included to make compiling and running these algorithms a little easier.
7.1 Convert.c - Converting Files from Extended ASCII to Standard ASCII
Past versions of "Numerical Analysis Algorithms in C" came in an extended ASCII version (v4.1) and a standard ASCII version (v4.11). "Convert.c" was written to eliminate the need for having two different versions. Macintosh disks ship with standard ASCII only.
7.1.1 Why Convert.c is Needed
Many programs use the extended ASCII character set available on MS‑DOS computers. These extra 128 characters may translate into garbage when uploading files onto UNIX or VAX computers. Standard ASCII uses 7‑bits per character while extended ASCII uses 8‑bits per character. When extended ASCII characters are uploaded to standard-ASCII‑only platforms, the 8th bit is masked off (set to zero) converting them into 7‑bit ASCII characters. To avoid the ill effects of this masking, this program has been provided. It converts any MS‑DOS text file into standard-ASCII‑only files, making the appropriate character substitutions.
Failure to use "convert.c" may produce results like those shown below after the files are uploaded to a non-MS-DOS platform:
normal w/ convert.c w/out convert.c w/out convert.c
7‑bit ASCII 8‑bit ASCII
[ PI t c \364 \343
f(x) | f(x) 3 f(x) \263 f(x)
] alpha u ` \365 \340
(in octal)
See the Examples Book for the C source code for "convert.c." This file contains a table called ASCIIlist[] which contains the extended ASCII characters and their suggested standard ASCII substitutions. This table can be easily modified by the user, but doing so requires "convert.c" to be recompiled. "Convert.c" has been compiled into "convert.exe" for MS-DOS computers and is shipped with the distribution diskettes.
The advantages of running the files through convert is that they can be ported to any machine, especially UNIX systems, with terminals only capable of displaying standard ASCII. The disadvantages are that you no longer have the proper symbols like those used in chapter 4 of the text for integration, or , , x², and numerous Greek symbols often used in mathematics.
Examples of the most commonly used extended ASCII characters and their closest substitutions are shown below:
ASCII ASCII
Number Char Substitute Number Char Substitute
129 ü u 238 E or epsilon
179 | 240 =
224 alpha 241 ± +/-
225 ß beta 242 >=
227 PI 243 <=
228 Summation of 244 [
230 µ mu 245 ]
232 phi 247 =
235 d or delta 253 ² ^2
236 oo or infinity
7.1.2 How to Use Convert.c
Before using the convert program, MAKE A SET OF BACKUP DISKETTES for "Numerical Analysis Algorithms in C"! Convert over-writes the original files with the newly converted files. Failure to make a set of backup diskettes will remove the option of ever going back to the extended ASCII version of the files. In other words, convert is one-way.
"Convert.c" will convert a single file or a list of files. To convert a single file, type:
C:\> CONVERT FILE_NAME
where "file_name" is the name of the desired file, such as "041.c." To convert a list of files, first create a list using a standard text editor ("file_name [ENTER]" format), then type:
C:\> CONVERT ‑L FILE_NAME_LIST
where "file_name_list" is the name of the file containing a list of file names you desire to convert.
For your convenience, two lists are provided: "LISTALL" and "LISTOUT." "LISTALL" is a file name list which contains all of the algorithms, support files, and documentation (except "convert.c"). "LISTOUT" is a file name list containing all of the algorithm output file names in the OUT sub-directory. Together these two file will convert all of the necessary "Numerical Analysis Algorithms in C" files into standard ASCII files.
To create a standard ASCII set of files, do the following:
1. Make a set of backup disks. See your operating system manual for specifics.
2. Change to the directory containing the algorithms (assume C:\NAA42 in this example). For example:
C:\> CD \NAA42
3. Convert all of the files inside the main directory. Do this by typing:
C:\NAA42> UTIL\CONVERT -L UTIL\LISTALL
Wait a few minutes until the conversion is finished.
4. Now convert all of the files inside the OUT sub-directory. This step is optional. Do this by typing:
C:\NAA42\> CD OUT
C:\NAA42\OUT> ..\UTIL\CONVERT -L ..\UTIL\LISTOUT
NOTE: The above steps can be done on a non-MS-DOS computer if the files are transferred as binary files. See Section 2.1 - "Uploading to Mainframe Computers" and use the "SET BINARY" option of KERMIT. "Convert.c" will naturally need to be recompiled on the new host computer.
7.2 List.com - A Better TYPE Command
"List.com" is an MS-DOS program which acts as a better "TYPE" command. It uses the arrow keys and other editing keys to view text files. "List.com" does not allow you to edit files, just view them. It is a public domain program.
To use "list.com" to view the output of Algorithm 4.1, type:
C:\> LIST 041.OUT
To scroll the text left, right, up or down, use the arrow keys. Typing 'X' exits "list.com." Typing '?' brings up a help menu. These commands and more are shown at the bottom of the "list.com" screen.
7.3 Time-Saving Batch, Script and Command Files
The files below can be use to simplify how you compile and run these algorithms. One is included for Microsoft C 5.0 on an IBM PC, one for UNIX, and one for VMS on a VAX. The actual commented files are also listed below:
7.3.1 CC.BAT
The batch file "cc.bat" can be used in place of the Microsoft C 5.0 "CL" command under MS-DOS. It contains the following:
CL /Od /qc %1.c
IF ERRORLEVEL 1 GOTO END
%1
LIST %1.OUT
:END
To use it, type: "C:\> CC 041" where 041 is an algorithm file name. Be sure to leave off the ".c" extension. "Cc.bat" will do the compiling, running, and will list the output file.
Commands are also listed to produce and use "naautil.c" as object code. Read the comments in this batch file for further instructions or see Section 6.6 - "Using Naautil.c as Object Code".
Below is a listing of the "cc.bat" batch file:
:*********************************************************************
: Program: CC.BAT (MS‑DOS batch file)
:
: Purpose:
: Cc.bat is an MS‑DOS batch file used for compiling, running and
: viewing a Microsoft C 5.0 program. It can be easily altered to
: allow for linking to "NAAUTIL.OBJ" (with or without "EQEVAL.C"),
: speeding up the compile time. Can also be altered to increase
: the stack size of a program.
:
: Written By: Harold A. Toomey
: Date: 21 Aug 1991
:
: Example: C:\> CC 041 where "041.C" is the file name.
: (Leave off the .C extension)
:*********************************************************************
:
: Do a compile and link (CL), disabling optimization (/Od) and
: invoke the QuickC compiler option (/qc) to shorten the compile
: time.
:
CL /Od /qc %1.c
:
: Replace the main line above with the line below if a larger stack
: is needed. This allows for a stack size of 4K bytes (/link
: /ST:4096). A MUST when compiling algorithms 2.8A, 5.6 and 8.1.
:
: CL /Od %1.c /link /ST:4096
:
: Replace the main line above with the two lines below if
: "NAAUTIL.C" has been compiled and exists as object code
: ("NAAUTIL.OBJ"). The first line creates %1.OBJ while the second
: line links %1.OBJ to "NAAUTIL.OBJ" to form %1.EXE. (Most
: flexible)
:
: CL /Od /c %1.c
: CL %1 NAAUTIL
:
:
: Create "NAAUTIL.OBJ" object code by running the below step once.
: Remember to re‑compile "NAAUTIL.C" every time one of its flags
: are changed.
:
: CL /c NAAUTIL.C
:
:
: If the program compiled correctly, then run it. If not, exit
: this batch file. Replace "%1" with "%1 < IN\%1.IN" if using the
: input file for initial testing.
IF ERRORLEVEL 1 GOTO END
%1
:
: View the program's output file using "LIST.COM". You may
: substitute DOS's TYPE command for "LIST.COM."
LIST %1.OUT
:END
:*********************************************************************
7.3.2 CCC
The script file "ccc" can be used in place of the "cc" command under UNIX. It contains the following:
cc $1.c -o $1 -lm
$1
more %1.out
To use it, type: "% ccc 041" where 041 is an algorithm file name. Be sure to leave off the ".c" extension. "Ccc" will do the compiling, running, and will list the output file. You may want to make "ccc" a UNIX (csh) script file. To do this, type "% chmod +x ccc" only once. The alternative is to type "% source ccc 041" every time you use "ccc".
Commands are also listed to produce and use "naautil.c" as object code. Read the comments in this script file for further instructions or see Section 6.6 - "Using Naautil.c as Object Code".
Below is a listing of the "ccc" script file:
#*********************************************************************
# Program: ccc (UNIX script file)
#
# Purpose:
# Ccc is a UNIX script file used for compiling, running, and
# viewing a mathematical C program. It can be easily altered to
* allow for linking to "naautil.o" (with or without "eqeval.c"),
# speeding up the compile time.
#
# Written By: Harold A. Toomey
# Date: 21 Aug 1991
#
# Example: % ccc 041 where "041.c" is the file name.
# (Leave off the .c extension)
#*********************************************************************
echo Compiling $1.c
# Compile the program and name the
executable the same as the
# original file except with no extension. Links to the math library
# (located in /usr/lib/libm.a).
cc $1.c ‑o $1 ‑lm
# Replace the above "cc" line with the below "cc" line to link to
# the pre‑compiled "naautil.c" object code file.
#
# cc $1.c ‑o $1 naautil.o ‑lm
#
#
# Create "naautil.o" object code by running the below step once.
# Remember to re‑compile "naautil.c" every time one of its flags
# are changed.
#
# cc ‑c naautil.c
#
# Run the program
$1
# View the program's output file
more $1.out
#*********************************************************************
7.3.3 VAXCC.COM
The command file "vaxcc.com" can be used in place of the VAX "CC" and "LINK" commands under VAX/VMS. It contains the following:
$ DEFINE LNK$LIBRARY SYS$LIBRARY:VAXCRTLG
$ DEFINE LNK$LIBRARY_1 SYS$LIBRARY:VAXCRTL
$ CC /G_FLOAT 'P1'.C
$ LINK 'P1', LNK$LIBRARY/LIB, LNK$LIBRARY_1/LIB
To use it, type: "$ @VAXCC 041" where 041 is an algorithm file name. Be sure to leave off the ".c" extension. "Vaxcc.com" will do the compiling and linking as a single command. The '@' character tells VMS that "vaxcc.com" is a command file.
Commands are also listed to produce and use "naautil.c" as object code. Read the comments in this command file for further instructions or see Section 6.6 - "Using Naautil.c as Object Code".
Below is a listing of the "vaxcc.com" command file:
$! *******************************************************************
$! Program: VAXCC.COM (VAX command file)
$!
$! Purpose:
$! VAXCC.COM is a VAX command file used for compiling and linking
$! a mathematical C program. It can be easily altered to allow
$! for linking to "NAAUTIL.OBJ" (with or without "EQEVAL.OBJ"),
$! speeding up the compile time.
$!
$! Written By: Harold A. Toomey
$! Date: 21 August 1991
$!
$! Example: $ @VAXCC 041 where "041.C" is the file name.
$! (Leave off the .C extension)
$! *******************************************************************
$!
$! Define the link libraries to allow the use of the /G_FLOAT
$! qualifier but not the use of Curses. These two defines may be
$! placed into your "LOGIN.COM" file to be performed once at login
$! time.
$!
$ DEFINE LNK$LIBRARY SYS$LIBRARY:VAXCRTLG
$ DEFINE LNK$LIBRARY_1 SYS$LIBRARY:VAXCRTL
$!
$! Compile the program with the floating‑point qualifier to create
$! an .OBJ object file. Link the object file to create the
$! executable.
$!
$ CC /G_FLOAT 'P1'.C
$ LINK 'P1', LNK$LIBRARY/LIB, LNK$LIBRARY_1/LIB
$!
$! *******************************************************************
$! Replace the above "LINK" line with the below "LINK"
line to link
$! to the pre‑compiled "NAAUTIL.C" object code file.
$!
$! LINK 'P1', NAAUTIL, LNK$LIBRARY/LIB, LNK$LIBRARY_1/LIB
$!
$! *******************************************************************
$! Create "NAAUTIL.OBJ" object code by running the below step once.
$! Rember to re‑compile "NAAUTIL.C" every time one of its flags
$! are changed.
$!
$! CC /G_FLOAT NAAUTIL.C
$!
$! *******************************************************************