Listing for BESSEL.H
/* BESSEL.H */
/* Written by Gan Seum-Lim.
This include file has a routine that calculates the
Bessel function of the first kind
n = infinity
___
J(p,x) = \ (-1)^n * (x/2)^(2n+p)
/___ ---------------------------
n=0 n! (p + n)!
*/
/* */
double power(double base,double exponent)
{
double temp1Double;
if ((exponent == 0.0) || (base == 0.0 && exponent == 0.0))
{
temp1Double = 1.0;
}
else
{
temp1Double = pow(base,exponent);
}
return (temp1Double);
}
/* function to calculate the factorial of a number */
double factorial(unsigned int arg1)
{
unsigned int index;
double temp1Double;
temp1Double = 1.0;
if (arg1 >= 2)
{
for (index = arg1; index >= 2; index--)
{
temp1Double = temp1Double * (double) index;
}
}
return (temp1Double);
}
/* function to calculate the bessel function using a finite series */
double bessel1(int n,double x)
{
int r,newN,temp1Int,temp2Int,temp3Int;
double temp1Double,temp2Double,temp3Double,temp4Double;
temp1Double = 0.0;
newN = (n >= 0) ? n : -n;
temp4Double = x/2.0;
for (r = 0; r <= 150; r++)
{
temp2Double = power(-1.0,(double) r) * power(temp4Double,(double) (2*r+newN));
temp3Double = factorial(r) * factorial(newN+r);
temp1Double = temp1Double + temp2Double/temp3Double;
}
if (n >= 0)
{
return (temp1Double);
}
else
{
temp2Double = power(-1.0,(double) newN) * temp1Double;
return (temp2Double);
}
}
Listing for BESSEL1.C
/* BESSEL1.C */
/* This program calculates the bessel function of the first kind
and store them in a file for look up by other programs.
*/
#include <math.h>
#include <stdio.h>
/* MS-DOS includes */
/*
#include <dos.h>
#include <bessel1b.h>
*/
/* End of MS-DOS includes */
/* IRIS includes */
#include </usr/people/postgd/gansl/C_INCLUDE/bessel1b.h>
/* End of IRIS includes */
void main()
{
#define BesselOrderMin -14
#define BesselOrderMax 14
#define BesselIndexMin 0.0
#define BesselIndexMax 15.0
#define BesselIndexInc 0.01
FILE *storeFile1;
int besselOrder,file1Open=0;
double besselIndex;
float temp1Float;
if ((storeFile1 = fopen("bessel1.bin","wb")) == NULL)
{
printf("Cannot Open bessel1.bin for writing binary data\a\n");
printf("Aborting now !\n");
}
else
{
printf("File bessel1.bin successfully opened for writing\a\n\n");
file1Open = 1;
}
if (file1Open == 1)
{
printf("Calculating bessel1 function from n = 0 to n = 150\n\n");
for (besselOrder = BesselOrderMin; besselOrder <= BesselOrderMax; besselOrder++)
{
printf("Bessel1 function order = %d\n",besselOrder);
for (besselIndex = BesselIndexMin; besselIndex <= BesselIndexMax; besselIndex = besselIndex + BesselIndexInc)
{
temp1Float = (float) bessel1(besselOrder,besselIndex);
fwrite(&temp1Float,sizeof(float),1,storeFile1);
}
}
fclose(storeFile1);
}
}
Listing for TEK4014.H
/* TEK4014.H */
/*
Written by : Gan Seum-Lim
Department of Physics
National University of Singapore.
Date : 21st May 1991
Usage : Any machines supporting the C langauge and connected to
any Tektronix 4000 series graphic terminals or
any Tektronix 4000 series emulated terminals.
-This file defines the basic and essential tek4014 codes for plotting on
the tek4014 screen. Printing of letters and numbers are not supported.
-The tek4014 screen size is 4096x3200.
-The X-axis is from 0 to 4095 (left to right) and
the Y-axis is from 0 to 3119 (bottom to top).
-16 colors are available through PC or Mac emulated Tektronix 4000 series.
-The emulated Tektronix on the Mac looks kind of funny in NCSA Telnet
but on the PC, it looks fine.
*/
/*
#include <stdio.h>
*/
/* to open and initialize the tek4014 graphics window */
void TEKinit()
{
printf("%c%c",0x1B,0x0C);
}
/* to switch the screen to VT mode */
/* this works only on a Tektronix color graphics terminal
/* this does not work for TCP/IP TEK4014 emulation */
void TEKtoVT()
{
printf("%c%c%c%c",0x1B,0x25,0x21,0x33);
}
/* to encode an integer into several ASCII characters depending on the value */
void TEKencodeInt(int value,unsigned char tekAscii[])
{
unsigned char signbit=0x00;
if (value >= 0)
signbit = 0x10;
tekAscii[0] = 0x20 | signbit | (value & 0x0F); /* lo-I */
tekAscii[1] = 0x40 | ((value & 0x3F0) >> 4); /* Hi-I */
tekAscii[2] = 0x40 | ((value & 0x7C00) >> 10); /* Hi-I */
}
/* to encode the x and y coordinates into 5 ASCII characters */
void TEKencodeXY(unsigned int x,unsigned int y,unsigned char tekAscii[])
{
tekAscii[0] = 0x40 | ((x & 0x7C) >> 2); /* loX */
tekAscii[1] = 0x20 | (x >> 7); /* hiX */
tekAscii[2] = 0x60 | ((y & 0x7C) >> 2); /* loY */
tekAscii[3] = 0x60 | ((y & 0x03) << 2) | (x & 0x03); /* extra */
tekAscii[4] = 0x20 | (y >> 7); /* hiY */
}
/* to move the pixel pointer to location x,y */
void TEKmoveTo(unsigned x,unsigned y)
{
unsigned char tekAscii[5];
TEKencodeXY(x,y,tekAscii);
printf("%c%c%c%c%c%c%c%c",0x1B,0x4C,0x46,tekAscii[4],tekAscii[3],tekAscii[2],tekAscii[1],tekAscii[0]);
}
/* to draw a line from x1,y1 to x2,y2 */
void TEKdrawLine(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
unsigned char tekAscii[5];
/* TEKmoveTo is not used here. Instead, a direct printf to move the pointer
in the procedure itself is faster */
TEKencodeXY(x1,y1,tekAscii);
printf("%c%c%c%c%c%c%c%c",0x1B,0x4C,0x46,tekAscii[4],tekAscii[3],tekAscii[2],tekAscii[1],tekAscii[0]);
TEKencodeXY(x2,y2,tekAscii);
printf("%c%c%c%c%c%c%c%c",0x1B,0x4C,0x47,tekAscii[4],tekAscii[3],tekAscii[2],tekAscii[1],tekAscii[0]);
}
/* to draw a line from the current position to x,y */
void TEKdrawLineTo(unsigned int x, unsigned int y)
{
unsigned char tekAscii[5];
TEKencodeXY(x,y,tekAscii);
printf("%c%c%c%c%c%c%c%c",0x1B,0x4C,0x47,tekAscii[4],tekAscii[3],tekAscii[2],tekAscii[1],tekAscii[0]);
}
/* to plot a pixel at location x,y */
void TEKplotPixel(unsigned int x,unsigned int y)
{
unsigned char tekAscii[5];
/* TEKmoveTo is not used here. Instead, a direct printf to move the pointer
in the procedure itself is faster */
TEKencodeXY(x,y,tekAscii);
printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",0x1B,0x4C,0x46,tekAscii[4],tekAscii[3],tekAscii[2],tekAscii[1],tekAscii[0],0x1B,0x4C,0x47,tekAscii[4],tekAscii[3],tekAscii[2],tekAscii[1],tekAscii[0]);
}
/* to set the color index of the line to be drawn */
/* colorIndex = 0 to 32767 */
/* Only 16 colors with TEKTRONIX emulation on PC */
/* 0=black,1=blue,2=green,3=cyan,4=red,5=magenta,6=brown,7=lightgray
8=darkgray,9=lightblue,10=lightgreen,11=lightcyan,12=lightred,
13=lightmagenta,14=yellow,15=white */
void TEKcolorIndex(unsigned int colorIndex)
{
unsigned char tekAscii[3];
TEKencodeInt(colorIndex,tekAscii);
printf("%c%c%c%c%c%c",0x1B,0x4D,0x4C,tekAscii[2],tekAscii[1],tekAscii[0]);
}
/* to set the color mode for the terminal */
/* this routine has not been tested, so I don't know if it works */
void TEKcolorMode(int mode, int overlay, int gray)
{
/*
mode = 0 No Change
= 1 RGB (Red,Green,Blue)
= 2 CMY (Cyan,Magenta,Yellow)
= 3 HLS (Hue,Lightness,Saturation) (default)
overlay = 0 No Change
= 1 Opaque (default)
= 2 Subtractive
= 3 Additive
gray = 0 No Change
= 1 Normal Color Operation (default)
*/
unsigned char tekAscii1[3],tekAscii2[3],tekAscii3[3];
TEKencodeInt(mode,tekAscii1);
TEKencodeInt(overlay,tekAscii2);
TEKencodeInt(gray,tekAscii3);
printf("%c%c%c%c%c%c%c%c%c%c%c%c",0x1B,0x54,0x4D,tekAscii1[2],tekAscii1[1],tekAscii1[0],tekAscii2[2],tekAscii2[1],tekAscii2[0],tekAscii3[2],tekAscii3[1],tekAscii3[0]);
}