Final Report Appendix A  Appendix B  Appendix D

Appendix C - Computer Program Source Code

Main Program

#include <stdio.h>

#include <math.h>

#include <conio.h>

#include <stdlib.h>

#include "globals.h"

int main ()

{

int Escape;

int Status;

char City[50];

char Scenario[256];

char Outfile[20];

FILE *Batch_file;

FILE *Output_file;

pi = 3.141592654;

while (Escape != 27)

{

textbackground ( BLUE );

clrscr ();

/* Process either a batch file of scenarios, or input one

scenario at a time */

printf ("\n\nSelect batch file or single processing (b or s)");

scanf ("%c", &Select);

if (Select == 's' || Select == 'S')

{

/* Call menu to enter input parameters */

}

else if ( Select == 'b' || Select == 'B')

{

printf ("\n\nEnter name for output file (max 20 char) ");

scanf ("%s", &Outfile);

/* Open the output file and write the header record */

fprintf (Output_file, "City tlat tlon slat slon ilat ilon \ Status = fscanf (Batch_file, "%[^\n]\n", &Scenario); /* Read new scenarios from the batch file, process the

scenarios, and write out the results of the scenarios

until the scenarios run out in the batch file */

Status = fscanf (Batch_file, "%[^\n]\n", &Scenario);

while (Status != EOF)

{

Parse (Scenario, City);

Phase1 ();

Phase2 ();

Phase3 ();

fprintf (Output_file, "%s %.3f %.3f %.3f %.3f %.3f %.3f \

%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f\n", \

Slongitude, Ilatitude, Ilongitude, Inland, Distancein, \

Flood, Depths, Distance, Depth, Waveamp, Peakamp, \

Kout, MassA, VolumeA, VelocityA, RadiusA, DensityA);

Status = fscanf (Batch_file, "%[^\n]\n", &Scenario);

}

}

else

;

Escape = getch ();

}

}

Input Routine

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <conio.h>

#include "globals.h"

/* Strip the color information out of the string retrieved from the

console. For each string byte, the next byte is a color byte. */

void Strip_color (Color, String)

char Color[16];

char String[8];

{

int Step;

int Next;

for (Step = 0; Step <= 7; Step = Step + 1)

String[Step] = 32;

Next = 0;

for (Step = 0; Step <=15; Step = Step + 1)

{

Inputc = Color[Step];

if ( (Inputc <= 59 && Inputc >= 48) || Inputc == 43 || Inputc == 45\

|| Inputc == 46)

{

String[Next] = Color[Step];

Next = Next + 1;

}

}

}

/* Input initialization parameters using a simple screen editor */

int Input_screen ()

{

int Column;

int Row;

int Field;

int Step;

int Next;

int More;

int Status;

int Fields[9][2] = {{ 10, 9 },

{ 28, 9 },

char cValue[16];

char Value[8];

char Parameters[80];

char *End;

textbackground ( BLUE );

clrscr ();

gotoxy ( 31, 2 );

cputs ( "IMPACT!!!" );

gotoxy ( 20, 4 );

cputs ( "use TAB to scroll through fields" );

gotoxy ( 26, 6 );

cputs ( "Asteroid Parameters" );

gotoxy ( 10, 8 );

cputs ( "Radius (m)" );

gotoxy ( 28, 8 );

cputs ( "Density (kg/cu m)" );

gotoxy ( 51, 8 );

cputs ( "Velocity (m/sec)" );

gotoxy ( 8, 11 );

cputs ( "Impact Location" );

gotoxy ( 26, 11 );

cputs ( "Shoreline Location" );

gotoxy ( 48, 11 );

cputs ( "Tsunami Location");

gotoxy ( 9, 12 );

cputs ( "Latitude (deg)" );

gotoxy ( 9, 15 );

cputs ( "Longitude (deg)" );

gotoxy ( 28, 12 );

cputs ( "Latitude (deg)" );

gotoxy ( 28, 15 );

cputs ( "Longitude (deg)" );

gotoxy ( 49, 12 );

cputs ( "Latitude (deg)" );

gotoxy ( 49, 15 );

cputs ( "Longitude (deg)" );

/* Enter default values for each field */

Next = 0;

for (Step = 0; Step <= 8; Step = Step + 1)

{

gotoxy (Fields[Step][0], Fields[Step][1]);

for (More = 0; More <= 7; More = More + 1)

Value[More] = 32;

More = 0;

while (Parameters[Next] != 0 && Parameters[Next] != 32 && \

Parameters[Next] != 10)

{

Value[More] = Parameters[Next];

Next = Next + 1;

More = More + 1;

}

while (Parameters[Next] == 0 || Parameters[Next] == 32)

Next = Next + 1;

for (More = 0; More <= 7; More = More + 1)

putch ( Value[More] );

}

gotoxy ( 14,19);

cputs ( "Press ENTER to confirm parameters and continue");

/* Fill in the fields using TAB to space between fields

Detect ENTER to finish */

Next = 0;

Field = 0;

Column = Fields[Next][0];

Row = Fields[Next][1];

while (Inputc != 13)

{

/* if the character input is a number, +, -, or ., send it to

the screen */

gotoxy ( Column, Row );

Inputc = getch ();

if ( (Inputc <= 59 && Inputc >= 48) || Inputc == 43 || Inputc == 45\

|| Inputc == 46)

{

Column = Column + 1;

Field = Field + 1;

}

/* if at the end of a field or a TAB is entered, go to the next

field */

if (Field > 7 || Inputc == 9)

{

if (Next < 8)

Next = Next + 1;

else

Next = 0;

Field = 0;

Row = Fields[Next][1];

Column = Fields[Next][0];

}

/* if BS, move back to overwrite */

if (Inputc == 8 && Field > 0)

{

Field = Field - 1;

Column = Column - 1;

}

/* Read each parameter value and convert to a double precision value */

gettext ( 10, 9, 17, 9, &cValue);

Strip_color (cValue, Value);

RadiusA = strtod (&Value[0], &End); /* Asteroid Radius */

gettext ( 28, 9, 35, 9, &cValue);

Strip_color (cValue, Value);

DensityA = strtod (&Value[0], &End); /* Asteroid Density */

gettext ( 51, 9, 58, 9, &cValue);

Strip_color (cValue, Value);

VelocityA = strtod (&Value[0], &End); /* Asteroid Initial Velocity */

gettext ( 9, 13, 16, 13, &cValue);

Strip_color (cValue, Value);

Ilatitude = strtod (&Value[0], &End); /* Impact Latitude */

gettext ( 9, 16, 16, 16, &cValue);

Strip_color (cValue, Value);

Ilongitude = strtod (&Value[0], &End); /* Impact Longitude */

gettext ( 28, 13, 35, 13, &cValue);

Strip_color (cValue, Value);

Slatitude = strtod (&Value[0], &End); /* Shoreline Latitude */

gettext ( 28, 16, 35, 16, &cValue);

Strip_color (cValue, Value);

Slongitude = strtod (&Value[0], &End); /* Shoreline Longitude */

gettext ( 49, 13, 56, 13, &cValue);

Strip_color (cValue, Value);

Tlatitude = strtod (&Value[0], &End); /* Tsunami Latitude */

gettext ( 49, 16, 56, 16, &cValue);

Strip_color (cValue, Value);

Tlongitude = strtod (&Value[0], &End); /* Tsunami Longitude */

clrscr ();

}

Phase I Pre-Collision

#include <stdio.h>

#include <math.h>

#include <conio.h>

#include <stdlib.h>

#include "globals.h"

/* Phase1 function - asteroid enters and traverses atmosphere, and impacts

the earth */

void Phase1 ()

{

/* atmospheric energy absorbtion */ return;

}

Phase II Collision

#include <stdio.h>

#include <math.h>

#include <conio.h>

#include <stdlib.h>

#include "globals.h"

/* Phase2 function - impact creates surface wave which propagates

outward */

void Phase2 ()

and asteroid radius */

{

double dlon;

double dlat;

double flon;

double flat;

double a;

double c;

double d;

Depth = Etopo_read (Outlatitude, Outlongitude); dlon = Slongitude - Outlongitude; cos(Outlatitude * d) * cos(Slatitude * d) * pow(sin(flon / 2.0),2.0); }

Phase III Post-Collsion

#include <stdio.h>

#include <math.h>

#include <conio.h>

#include <stdlib.h>

#include "globals.h"

/* Phase3 function - surface wave reaches shore, creating a tsunami */

void Phase3 ()

{ double glat;

double glon;

double jlon;

double jlat;

double h;

double j;

double i;

glon = Tlongitude - Slongitude;

glat = Tlatitude - Slatitude;

h = pow(sin(jlat / 2.0),2.0) + \

cos(Slatitude * i) * cos(Tlatitude * i) * pow(sin(jlon / 2.0),2.0);

Distancein = j * 6367.0; if (Distancein < Inland) else

Flood = 0.0;

}