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 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 */
/* Derive kinetic energy of impact from phase 1 */
Phase1 ();
/* Derive wave amplitude from phase 2 */
Phase2 ();
/* Derive tsunami destructive effects */
Phase3 ();
printf ("radius = %f m\ndensity = %f kg/cu\n" , RadiusA, DensityA);
printf ("velocity = %f m/sec\n" , VelocityA);
printf ("impact lat = %f deg\nimpact lon = %f deg\n" , Ilatitude, Ilongitude);
printf ("shore lat = %f deg\nshore lon = %f deg\n" , Slatitude, Slongitude);
printf ("tsunami lat = %f deg\ntsunami lon = %f deg\n" , Tlatitude, Tlongitude);
printf ("Kout = %f Gigaton\nmass = %f kg\nvolume = %f cubic m\n" , Kout, MassA, VolumeA);
printf ("ocean depth = %f meters\ndistance = %f km\nwave amplitude = %f meters\n" , Depth, Distance, Waveamp);
printf ("Distance = %f\nShoreline Depth = %f\nWave height in city = %f\nfarthest inland point = %f\n" , Distancein, Depths, Flood , Inland);
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 */
mass vol vel rad den\n");
/* Open the batch file and read the header record */
Batch_file = fopen ("impact.bat", "r");
if (Batch_file == NULL)
printf ("batch file missing");
printf ("read was unsuccessful");
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", \
Flood, Depths, Distance, Depth, Waveamp, Peakamp, \
Kout, MassA, VolumeA, VelocityA, RadiusA, DensityA);
Status = fscanf (Batch_file, "%[^\n]\n", &Scenario);
}
if (Status != 0)
printf ("file was not closed successfully");
Status = fclose (Output_file);
if (Status != 0)
printf ("file was not closed successfully");
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 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 Row;
int Field;
int Step;
int Next;
int More;
int Status;
int Fields[9][2] = {{ 10, 9 },
{ 28, 9 },
{ 9, 13 },
{ 9, 16 },
{ 28, 13 },
{ 28, 16 },
{ 49, 13 },
{ 49, 16 } };
char Value[8];
char Parameters[80];
char *End;
/* Enter the names of the input parameters on the screen */
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)" );
default_file = fopen ("impact.ini", "r");
if (default_file == NULL)
printf ("default parameter file missing");
fseek (default_file, 1, 0);
Status = fread (&Parameters, 80, 1, default_file);
if (Status == 0)
printf ("read was unsuccessful");
Status = fclose (default_file);
if (Status != 0)
printf ("file was not closed successfully");
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)
{
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;
}
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 ()
{
double KineticA;
/* Compute volume of asteroid */
VolumeA = (4.0 / 3.0) * pi * pow(RadiusA,3.0);
/* Compute mass of asteroid */
MassA = VolumeA * DensityA;
/* Compute kinetic energy of asteroid */
KineticA = 1.0 / 2.0 * MassA * pow(VelocityA,2.0);
Kout = KineticA;
else
Kout = KineticA;
/* Convert impact kinetic energy from joules to Gigaton TNT */
Kout = Kout / 4.2511e18;
}
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 ()
{
distance from collision,
local ocean depth,
and peak amplitude of wave */
double Outlatitude;
double Outlongitude;
double dlat;
double flon;
double flat;
double a;
double c;
double d;
double Etopo_read ();
/* Get ocean depth from Etopo5 */
Outlatitude = Closest_5min (Ilatitude);
Outlongitude = Closest_5min (Ilongitude);
d = pi / 180.0;
flon = (d * dlon);
flat = (d * dlat);
a = pow(sin(flat / 2.0),2.0) + \
Distance = c * 6367.0;
/* Calculate peak-to-peak amplitude of wave */
if (RadiusA * 2.0 * 12.0 < abs(Depth))
Peakamp = (6.5 * pow(Kout, 0.54)) * (1000 / Distance);
else
Peakamp = 1.450 * (abs(Depth) / Distance) * pow(Kout, 0.25);
/* Calculate peak amplitude of surface wave */
Waveamp = (1.0 / 2.0) * Peakamp;
return;
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 ()
tsunami runup factor,
flood depth,
distance inland water is,
maximum distance inland water will surge */
double Runup;
double glon;
double jlon;
double jlat;
double h;
double j;
double i;
Runup = 10.0;
/* Input distance inland wave is */
glat = Tlatitude - Slatitude;
jlon = (i * glon);
jlat = (i * glat);
cos(Slatitude * i) * cos(Tlatitude * i) * pow(sin(jlon / 2.0),2.0);
Depths = Runup * Waveamp;
/* Calculate maximum distance inland wave will travel */
Inland = 1.4 * pow((Depths / 10.0), 1.33);
/* Calculate flood depth of wave */
Flood = 0.0;