NewsEtc

Dec., 1998
Steven Jacques
Oregon Medical Laser Center

Monte Carlo: Header for "mc321.c"


This header section of the program lists various details necessary for a C program to run. It's not so interesting and you can skip ahead to the next section unless you really want to read the details.

"mc321" is the minimal core of prior Monte Carlo programs developed in collaboration with Lihong Wang, Scott Prahl, and Marleen Keijzer.

/********************************************
 *  mc321.c    , in ANSI Standard C programing language
 *
 *  Monte Carlo simulation yielding spherical, cylindrical, and planar 
 *    responses to an isotropic point source in an infinite homogeneous 
 *    medium with no boundaries. This program is a minimal Monte Carlo 
 *    program scoring photon distributions in spherical, cylindrical, 
 *    and planar shells.
 *
 *  A published report illustrates use of the program:
 *    S. L. Jacques: "Light distributions from point, line, and plane 
 *    sources for photochemical reactions and fluorescence in turbid 
 *    biological tissues," Photochem. Photobiol. 67:23-32, 1998. 
 *
 *  by Steven L. Jacques based on prior collaborative work 
 *    with Lihong Wang, Scott Prahl, and Marleen Keijzer.
 *    partially funded by the NIH (R29-HL45045, 1991-1997) and  
 *    the DOE (DE-FG05-91ER617226, DE-FG03-95ER61971, 1991-1999).
 **********/

The "include" statements incorporate standard subroutine libraries available with any ANSI standard C compiler.

#include <math.h>
#include <stdio.h>

The "define" statements make global substitutions throughout the program before compiling the program. Hence the progam source code can use simpler names like PI, ALIVE, ONE_MINUS_COSZERO, for easier reading.

A subroutine called RandomGen() is used to generate random numbers between 0 and 1 inclusive. "InitRandomGen" is substituted by a call to RandomGen(0, 1, NULL) which initializes the seed for the random number generator subroutine. "RandomNum" is substituted by a call to RandomGen(1, 0, NULL) which calls for a random number. The function "RandomGen()" is declared, and is listed at the end of the program. In the main program, "InitRandomGen" initializes RandomGen(), and subsequent uses of "RandomNum" calls for a random number from RandomGen().

#define	PI          3.1415926
#define ALIVE       1   		/* if photon not yet terminated */
#define DEAD        0    		/* if photon is to be terminated */
#define THRESHOLD   0.01		/* used in roulette */
#define CHANCE      0.1  		/* used in roulette */
#define COS90D      1.0E-6
     /* If cos(theta) <= COS90D, theta >= PI/2 - 1e-6 rad. */
#define ONE_MINUS_COSZERO 1.0E-12
     /* If 1-cos(theta) <= ONE_MINUS_COSZERO, fabs(theta) <= 1e-6 rad. */
     /* If 1+cos(theta) <= ONE_MINUS_COSZERO, fabs(PI-theta) <= 1e-6 rad. */
#define SIGN(x)           ((x)>=0 ? 1:-1)
#define InitRandomGen    (double) RandomGen(0, 1, NULL)
     /* Initializes the seed for the random number generator. */     
#define RandomNum        (double) RandomGen(1, 0, NULL)
     /* Calls for a random number from the randum number generator. */

/* DECLARE FUNCTION */
double RandomGen(char Type, long Seed, long *Status);  
     /* Random number generator */

The main program is contained with a section called "main()". Following "main()", the function RandomGen() is listed.

main() {

/**** PROGRAM SITS HERE ****/

}

/* FUNCTION */

/**** RandomGen() function listed here ****/

next | first page



© 1998, Steven L. Jacques & Scott A. Prahl