Sei sulla pagina 1di 8

**************************************************************************

Installation instructions for Windows Users

Created by

Vaughan Griffiths

Colorado School of Mines


May 2014

**************************************************************************

The following instructions explain how you can download and run the
programs and subroutines as described in detail in the text:

"Numerical methods for Engineers (2nd edition)"


by
D.V. Griffiths and I.M. Smith
Chapman & Hall/CRC 2006

This NM_readme.rtf file is in four parts as follows:

A) Downloading the programs and library routines.

B) Downloading a free Fortran 95 compiler.

C) Building the numerical methods library

D) Running the numerical methods programs.

***************************************************************************

A) Downloading the programs and library routines.

Go to web site http://www.mines.edu/~vgriffit/NM/Software


Click on NM.exe, select "Run", select "Run" again, choose the
folder you want to Unzip to (recommend c:\NM),
click "Unzip".

In either case When it has finished it should say "140 files unzipped
successfully".

Click on "OK" and "Close" the WinZip Self-Extractor window.

***************************************************************************
B) Instructions for downloading a free Fortran 95 compiler.

Go to web site http://www.mines.edu/~vgriffit /NM/Software.

Click on g95-MinGW.exe

Click on "Run", Click on "Yes", choose the folder you want to Unzip to
(recommend c:\g95).

Accept all the defaults

The following instructions assume you installed the numerical method


programs in c:\NM and the compiler in c:\g95.

***************************************************************************

C) Building the numerical methods library.

In Windows Explorer go to folder c:\NM\nm_lib and double-click on build_lib

***************************************************************************

D) Running the numerical methods programs.

To compile and run a numerical methods program, say nm46.f95 from Chapter 4
in the book with a sample data, say nm46.dat, open up a "Command Prompt"
window (black window), go to folder c:\NM\chap04 by typing,

cd c:\NM\chap04

and then type,

run2 nm46 nm46 followed by "Enter".

run2.bat is an executable file located in each of the


c:\NM\chap* folders and looks like this:

echo off
rem ******EDIT THE NEXT TWO LINES IF NECESSARY******
set ED2=c:\NM
set G95=c:\g95
rem ************************************************
set NML=%ED2%\nm_lib
set PATH=%G95%\BIN
g95 %1.f95 -o %1.exe -I %NML% %NML%\nm_lib.a
copy %2.dat nm95.dat
%1
move nm95.dat %2.dat
move nm95.res %2.res
del %1.exe nm95.dat
Before running run2.bat, the environment variables ED2 and G95 may need
editing to ensure they point to the correct installation folder
for NM and g95.

run2 is always followed by two arguments as shown above. The first


argument is the basename of the source program (must have extension .f95)
and the second argument is the basename of the data file (must have
extension .dat).

DO NOT TYPE THE EXTENSIONS WHEN USING run2

If the program executes successfully, the results file is


given the same name as the data file but with the extension
*.res

In the above example, the results will be held in nm46.res

If for example you want to run program nm21.f95 with your own data,
go to folder c:\NM\chap02 by typing:

cd c:\NM\chap02

Make a copy of the example data that goes with the program by typing:

copy nm21.dat fred.dat

Edit fred.dat to reflect the requirements of your particular analysis


using any suitable text editor (e.g. Notepad, WordPad).

Execute the program with your data by typing:

run2 nm21 fred

If the program executes successfully, the results will be held in


the file fred.res

***************************************************************************
c

100

110

120

140

PROGRAM PRcm 9

'PHIS PROGRAM SOLVES A SYSTEM OF N FIRST ORDER DIFFENTIAL

EQUATIONS BY THE RUNGE-KUTTA FOURTH ORDER METHOD.

THE EQUATIONS ARE OF THE FORM DXI/DT = FI (X, T)


ETC.

XEND

TF

A SUBROUTINE THAT CALCULATES VALUES OF THE

N DERIVATIVES. IT IS INVOKED BY THE STATEMENT

CALL DERIVS (X, T, F, N)

INITIAL VALUE OF THE INDEPENDENT VARIABLE.

THE STEP SIZE, THE INCREMENT TO TO.

THE ARRA'} THAT HOLDS THE INITIAL VALUES OF THE

FUNCTIONS.

AN ARRAY THAT RETURNS THE FINAL VALUES OF THE

FUNCTIONS .

AN ARRAY USED TO HOLD INTERMEDIATE VALUES DURING

CALCULATION. IT MUST BE DIMENSIONED OF SIZE

4 X N IN THE MAIN PROGRAM.

THE NUMBER OF EQUATIONS IN THE PROGRAM.

AN ARRAY THAT HOLDS VALUES OF THE DERIVATIVES.

FINAL VALUE OF THE INDEPENDENT VARIABLE.

EXTERNAL DERIVS

DIMENSION

REAL Kl, K2, K3, K4, K5

COMMON/DATAI/XO

COh0fON/DATA2/K1 , K2 , K3 , K4 , K5

COMMON/DATA3/TF

DATA N,TF/4, 10.0/

OPEN (UNIT=I, FILE='PRN')

WRITE (1, 100)

FORMAT (15X, 'RUNGE-KUTTA FOURTH ORDER METHOD FOR A SYSTEM OF')


WRITE (1, 110)

FORMAT (25X, 'ORDINARY DIFFERENTIAL EQUATIONS' , / ,5X, 74 (IH*) , // )

WRITE (1, 120)

FORMAT (18X, 'TIME' ,3X, 'CONC. CA',3X, 'CONC.

ax, 'CONC. CD' ,/5X, 74(1H-) , / )

TO = 0.0

H = 0.5

WRITE (1, 140) TO, (XO(I), 1 =

FORMAT (14X, F8.2, 5X, 4(F6.2, 5X))

CALL RKSYST (DERIVS, TO, H, XO, XEND,

DO 1 =

XO(I) = XEND(I)

END DO

100

CB' ,3X, 'CONC. CC'


150
160
c
c
c
c
WRITE (1, 150) TO, (XO(I), 1, N)
FORMAT (14X, F8.2, 5X, 4(F6.2, 5X))
IF (TO .LT. TF) THEN
ELSE
ENDIF
WRvrE (1, 160)
FORMAT (5X, 74(1H-))
FORM FEED THE PRINTING PAPER TO TOP OF THE NEXT PACE.
WRITE (1, CHAR(12)
CLOSE (UNIT = 1)
STOP
END
THIS PROGRAM SOLVES A SYSTEM OF N FIRST ORDER DIFFERENTIA&
EQUATIONS BY THE RUNGE-KUTTA FOURTH ORDER METHOD.
SUBROUTINE RKSYST (DERIVS, 'ro, H, XO, XEND, XWRK, F, N)
DIMENSION XO(I:N),
COMMON / DATA3 /TF
CALCULATE THE FIRST ESTIMATE OF THE DATA X' s
CALL DERIVS ( XO, TO, F, N)
DO I
= H * F(l)
= XO(I) +
XEND(I)
END DO
CALCULATE THE SECOND ESTIMATE , THE XEND VECTOR
HOLDS THE X-VALUES
CALL DERIVS (XEND, TO+H/2.O, F, N)
DO r
XO(I) +
END DO
CALCULATE THE THIRD ESTIMATE
CALL DERIVS (XEND, TO+H/2.O, F, N)
DO
XEND(I) = XO(I) +
END DO
CALCULATE THE FOURTH ESTIMATE
101

CALL DERIVS (XEND, TO+H,

DO 1=1, N

= H * F(l)

END DO

COMPUTE THE X VALUES AT THE END OF THE INTERVAL FROM A

WEIGHTED AVERAGE OF THE FOURTH ESTIMATES.

DO

XEND(

END DO

RETURN

END

THIS PROGRAM DEFINES THE FUNCTIONS OF THE ORDINARY DIFFERENTIAL

EQUATIONS IN TERMS OF THE F' s AND THE X'S.

SUBROUTINE DERIVS (X, T, F, N)

DIMENSION

COt.MON/DATA2/K1 , K2 , K3 , K4 , K5

REAL

RETURN
END

THIS STORES THE DATA FOR THE RATE CONSTANTS AND THE INITIAL

STARTING VALUES OF THE CONCENTRATIONS.

BLOCK DATA

DIMENSION XO(4)

COI.MON/DATAI/XO

C020fON/DATA2/K1 , K2 , K3 , K4 , K5

REAL

DATA

DATA Kl/O.4/ ,K5/O.10/

END

Potrebbero piacerti anche