Sorry about the length of this!
This is a program that I was asked to write. I have the code that I have done so far below this. When I run it I get no errors, but I also donít get any screen asking me to input values (see program for more info). Please take a look at my code someone and help me with it if possible. Thank you in advance everyone! Here is the Ďbriefí I was given for the program:
Write pseudocode, draw flowcharts and write C code for a program that reads seismometer data from a data (text) file named seismic.dat, determines whether seismic events have occurred and reports the findings to the screen in text and graphic format.
The first line of the file contains two values: the number of data elements or readings and the time interval in seconds that occurred between consecutive measurements. The time interval is a floating point value and it may be assumed that all the measurements were taken with the same time interval between them. After reading the data measurements the program should identify possible earthquakes or seismic events using a power ratio.
The data window length (number of measurements) for short-time power and long-time power are to be read from the keyboard as in the threshold value.
The inputs to this program are:
the data (text) file named seismic.dat, the number of measurements to use for short time power and long time power, and the threshold value.
The outputs are:
A screen report giving the times of potential seismic events the corresponding short-time to long-time power ratio and threshold employed;
And a data file containing the times of potential seismic events, the corresponding short-time to long-time power ratio and threshold employed
Here is my code so far:
#define FILENAME "seismic.dat"
#define MAX_SIZE 1000
#define THRESHOLD 1.5
/* Declare variables and function prototypes. */
int k, npts, short_window, long_window;
double sensor[MAX_SIZE], time_incr, short_power,
double power_w(double x, int length, int n);
/* Read data file. */
file_ptr = fopen(FILENAME,"r");
if (npts > MAX_SIZE)
printf("Data file too large for array. \n");
/* Read data into an array. */
for (k=0; k<=npts-1; k++)
/* Read window sizes from the keyboard. */
printf("Enter number of points for short-window: \n");
printf("Enter number of points for long-window: \n");
/* Compute power ratios and search for events. */
for (k=long_window-1; k<=npts-1; k++)
short_power = power_w(sensor,short_window,k);
long_power = power_w(sensor,long_window,k);
ratio = short_power/long_power;
if (ratio > THRESHOLD)
printf("Possible event at %f seconds \n",
/* Close file and exit program. */
/* This function computes the average power in a */
/* specified window of a double array. */
double power_w(double x, int length, int n)
/* Declare and initialize variables. */
/* Compute sum of values squared in the array x. */
for (k=n; k>=n-length+1; k--)
xsquare += x[k]*x[k];
/* Return the average squared value. */